22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5+ // This test is run using `flutter drive` by the CI (see /script/tool/README.md
6+ // in this repository for details on driving that tooling manually), but can
7+ // also be run using `flutter test` directly during development.
8+
59import 'dart:async' ;
610import 'dart:convert' ;
711import 'dart:io' ;
@@ -16,19 +20,32 @@ import 'package:integration_test/integration_test.dart';
1620import 'package:webview_flutter/platform_interface.dart' ;
1721import 'package:webview_flutter/webview_flutter.dart' ;
1822
19- void main () {
23+ Future < void > main () async {
2024 IntegrationTestWidgetsFlutterBinding .ensureInitialized ();
2125
22- // URLs to navigate to in tests. These need to be URLs that we are confident will
23- // always be accessible, and won't do redirection. (E.g., just
24- // 'https://www.google.com/' will sometimes redirect traffic that looks
25- // like it's coming from a bot, which is true of these tests).
26- const String primaryUrl = 'https://flutter.dev/' ;
27- const String secondaryUrl = 'https://www.google.com/robots.txt' ;
28-
2926 const bool _skipDueToIssue86757 = true ;
3027
31- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
28+ final HttpServer server = await HttpServer .bind (InternetAddress .anyIPv4, 0 );
29+ server.forEach ((HttpRequest request) {
30+ if (request.uri.path == '/hello.txt' ) {
31+ request.response.writeln ('Hello, world.' );
32+ } else if (request.uri.path == '/secondary.txt' ) {
33+ request.response.writeln ('How are you today?' );
34+ } else if (request.uri.path == '/headers' ) {
35+ request.response.writeln ('${request .headers }' );
36+ } else if (request.uri.path == '/favicon.ico' ) {
37+ request.response.statusCode = HttpStatus .notFound;
38+ } else {
39+ fail ('unexpected request: ${request .method } ${request .uri }' );
40+ }
41+ request.response.close ();
42+ });
43+ final String prefixUrl = 'http://${server .address .address }:${server .port }' ;
44+ final String primaryUrl = '$prefixUrl /hello.txt' ;
45+ final String secondaryUrl = '$prefixUrl /secondary.txt' ;
46+ final String headersUrl = '$prefixUrl /headers' ;
47+
48+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
3249 testWidgets ('initialUrl' , (WidgetTester tester) async {
3350 final Completer <WebViewController > controllerCompleter =
3451 Completer <WebViewController >();
@@ -49,7 +66,7 @@ void main() {
4966 expect (currentUrl, primaryUrl);
5067 }, skip: _skipDueToIssue86757);
5168
52- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
69+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
5370 testWidgets ('loadUrl' , (WidgetTester tester) async {
5471 final Completer <WebViewController > controllerCompleter =
5572 Completer <WebViewController >();
@@ -93,7 +110,7 @@ void main() {
93110 expect (result, equals ('2' ));
94111 });
95112
96- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
113+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
97114 testWidgets ('loadUrl with headers' , (WidgetTester tester) async {
98115 final Completer <WebViewController > controllerCompleter =
99116 Completer <WebViewController >();
@@ -122,10 +139,9 @@ void main() {
122139 final Map <String , String > headers = < String , String > {
123140 'test_header' : 'flutter_test_header'
124141 };
125- await controller.loadUrl ('https://flutter-header-echo.herokuapp.com/' ,
126- headers: headers);
142+ await controller.loadUrl (headersUrl, headers: headers);
127143 final String ? currentUrl = await controller.currentUrl ();
128- expect (currentUrl, 'https://flutter-header-echo.herokuapp.com/' );
144+ expect (currentUrl, headersUrl );
129145
130146 await pageStarts.stream.firstWhere ((String url) => url == currentUrl);
131147 await pageLoads.stream.firstWhere ((String url) => url == currentUrl);
@@ -135,7 +151,7 @@ void main() {
135151 expect (content.contains ('flutter_test_header' ), isTrue);
136152 }, skip: Platform .isAndroid && _skipDueToIssue86757);
137153
138- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
154+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
139155 testWidgets ('JavascriptChannel' , (WidgetTester tester) async {
140156 final Completer <WebViewController > controllerCompleter =
141157 Completer <WebViewController >();
@@ -247,7 +263,7 @@ void main() {
247263 expect (customUserAgent2, 'Custom_User_Agent2' );
248264 });
249265
250- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
266+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
251267 testWidgets ('use default platform userAgent after webView is rebuilt' ,
252268 (WidgetTester tester) async {
253269 final Completer <WebViewController > controllerCompleter =
@@ -782,7 +798,7 @@ void main() {
782798 });
783799
784800 group ('Programmatic Scroll' , () {
785- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
801+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
786802 testWidgets ('setAndGetScrollPosition' , (WidgetTester tester) async {
787803 const String scrollTestPage = '''
788804 <!DOCTYPE html>
@@ -1133,6 +1149,7 @@ void main() {
11331149 expect (currentUrl, primaryUrl);
11341150 });
11351151
1152+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
11361153 testWidgets ('target _blank opens in same window' ,
11371154 (WidgetTester tester) async {
11381155 final Completer <WebViewController > controllerCompleter =
@@ -1158,11 +1175,9 @@ void main() {
11581175 await pageLoaded.future;
11591176 final String ? currentUrl = await controller.currentUrl ();
11601177 expect (currentUrl, primaryUrl);
1161- },
1162- // Flaky on Android: https://github.com/flutter/flutter/issues/86757
1163- skip: Platform .isAndroid && _skipDueToIssue86757);
1178+ }, skip: Platform .isAndroid && _skipDueToIssue86757);
11641179
1165- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
1180+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
11661181 testWidgets (
11671182 'can open new window and go back' ,
11681183 (WidgetTester tester) async {
0 commit comments