@@ -22,6 +22,13 @@ import 'package:webview_flutter_platform_interface/webview_flutter_platform_inte
2222void main () {
2323 IntegrationTestWidgetsFlutterBinding .ensureInitialized ();
2424
25+ // URLs to navigate to in tests. These need to be URLs that we are confident will
26+ // always be accessible, and won't do redirection. (E.g., just
27+ // 'https://www.google.com/' will sometimes redirect traffic that looks
28+ // like it's coming from a bot, which is true of these tests).
29+ const String primaryUrl = 'https://flutter.dev/' ;
30+ const String secondaryUrl = 'https://www.google.com/robots.txt' ;
31+
2532 const bool _skipDueToIssue86757 = true ;
2633
2734 // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
@@ -34,7 +41,7 @@ void main() {
3441 textDirection: TextDirection .ltr,
3542 child: WebView (
3643 key: GlobalKey (),
37- initialUrl: 'https://flutter.dev/' ,
44+ initialUrl: primaryUrl ,
3845 onWebViewCreated: (WebViewController controller) {
3946 controllerCompleter.complete (controller);
4047 },
@@ -44,7 +51,7 @@ void main() {
4451 );
4552 final WebViewController controller = await controllerCompleter.future;
4653 final String ? currentUrl = await controller.currentUrl ();
47- expect (currentUrl, 'https://flutter.dev/' );
54+ expect (currentUrl, primaryUrl );
4855 }, skip: _skipDueToIssue86757);
4956
5057 // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
@@ -56,17 +63,17 @@ void main() {
5663 textDirection: TextDirection .ltr,
5764 child: WebView (
5865 key: GlobalKey (),
59- initialUrl: 'https://flutter.dev/' ,
66+ initialUrl: primaryUrl ,
6067 onWebViewCreated: (WebViewController controller) {
6168 controllerCompleter.complete (controller);
6269 },
6370 ),
6471 ),
6572 );
6673 final WebViewController controller = await controllerCompleter.future;
67- await controller.loadUrl ('https://www.example.com/' );
74+ await controller.loadUrl (secondaryUrl );
6875 final String ? currentUrl = await controller.currentUrl ();
69- expect (currentUrl, 'https://www.example.com/' );
76+ expect (currentUrl, secondaryUrl );
7077 }, skip: _skipDueToIssue86757);
7178
7279 // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
@@ -80,7 +87,7 @@ void main() {
8087 textDirection: TextDirection .ltr,
8188 child: WebView (
8289 key: GlobalKey (),
83- initialUrl: 'https://flutter.dev/' ,
90+ initialUrl: primaryUrl ,
8491 onWebViewCreated: (WebViewController controller) {
8592 controllerCompleter.complete (controller);
8693 },
@@ -298,7 +305,7 @@ void main() {
298305 textDirection: TextDirection .ltr,
299306 child: WebView (
300307 key: _globalKey,
301- initialUrl: 'https://flutter.dev/' ,
308+ initialUrl: primaryUrl ,
302309 javascriptMode: JavascriptMode .unrestricted,
303310 onWebViewCreated: (WebViewController controller) {
304311 controllerCompleter.complete (controller);
@@ -1053,12 +1060,11 @@ void main() {
10531060
10541061 await pageLoads.stream.first; // Wait for initial page load.
10551062 final WebViewController controller = await controllerCompleter.future;
1056- await controller
1057- .evaluateJavascript ('location.href = "https://www.example.com/"' );
1063+ await controller.evaluateJavascript ('location.href = "$secondaryUrl "' );
10581064
10591065 await pageLoads.stream.first; // Wait for the next page load.
10601066 final String ? currentUrl = await controller.currentUrl ();
1061- expect (currentUrl, 'https://www.example.com/' );
1067+ expect (currentUrl, secondaryUrl );
10621068 });
10631069
10641070 testWidgets ('onWebResourceError' , (WidgetTester tester) async {
@@ -1220,12 +1226,11 @@ void main() {
12201226
12211227 await pageLoads.stream.first; // Wait for initial page load.
12221228 final WebViewController controller = await controllerCompleter.future;
1223- await controller
1224- .evaluateJavascript ('location.href = "https://www.example.com"' );
1229+ await controller.evaluateJavascript ('location.href = "$secondaryUrl "' );
12251230
12261231 await pageLoads.stream.first; // Wait for second page to load.
12271232 final String ? currentUrl = await controller.currentUrl ();
1228- expect (currentUrl, 'https://www.example.com/' );
1233+ expect (currentUrl, secondaryUrl );
12291234 });
12301235 });
12311236
@@ -1241,7 +1246,7 @@ void main() {
12411246 height: 300 ,
12421247 child: WebView (
12431248 key: GlobalKey (),
1244- initialUrl: 'https://flutter.dev/' ,
1249+ initialUrl: primaryUrl ,
12451250 gestureNavigationEnabled: true ,
12461251 onWebViewCreated: (WebViewController controller) {
12471252 controllerCompleter.complete (controller);
@@ -1252,7 +1257,7 @@ void main() {
12521257 );
12531258 final WebViewController controller = await controllerCompleter.future;
12541259 final String ? currentUrl = await controller.currentUrl ();
1255- expect (currentUrl, 'https://flutter.dev/' );
1260+ expect (currentUrl, primaryUrl );
12561261 });
12571262
12581263 testWidgets ('target _blank opens in same window' ,
@@ -1276,11 +1281,10 @@ void main() {
12761281 ),
12771282 );
12781283 final WebViewController controller = await controllerCompleter.future;
1279- await controller
1280- .evaluateJavascript ('window.open("https://flutter.dev/", "_blank")' );
1284+ await controller.evaluateJavascript ('window.open("$primaryUrl ", "_blank")' );
12811285 await pageLoaded.future;
12821286 final String ? currentUrl = await controller.currentUrl ();
1283- expect (currentUrl, 'https://flutter.dev/' );
1287+ expect (currentUrl, primaryUrl );
12841288 },
12851289 // Flaky on Android: https://github.com/flutter/flutter/issues/86757
12861290 skip: _skipDueToIssue86757);
@@ -1304,25 +1308,24 @@ void main() {
13041308 onPageFinished: (String url) {
13051309 pageLoaded.complete ();
13061310 },
1307- initialUrl: 'https://flutter.dev' ,
1311+ initialUrl: primaryUrl ,
13081312 ),
13091313 ),
13101314 );
13111315 final WebViewController controller = await controllerCompleter.future;
1312- expect (controller.currentUrl (), completion ('https://flutter.dev/' ));
1316+ expect (controller.currentUrl (), completion (primaryUrl ));
13131317 await pageLoaded.future;
13141318 pageLoaded = Completer <void >();
13151319
1316- await controller
1317- .evaluateJavascript ('window.open("https://www.example.com/")' );
1320+ await controller.evaluateJavascript ('window.open("$secondaryUrl ")' );
13181321 await pageLoaded.future;
13191322 pageLoaded = Completer <void >();
1320- expect (controller.currentUrl (), completion ('https://www.example.com/' ));
1323+ expect (controller.currentUrl (), completion (secondaryUrl ));
13211324
13221325 expect (controller.canGoBack (), completion (true ));
13231326 await controller.goBack ();
13241327 await pageLoaded.future;
1325- expect (controller.currentUrl (), completion ('https://flutter.dev/' ));
1328+ expect (controller.currentUrl (), completion (primaryUrl ));
13261329 },
13271330 skip: _skipDueToIssue86757,
13281331 );
0 commit comments