@@ -22,6 +22,13 @@ import 'package:webview_flutter_platform_interface/webview_flutter_platform_inte
22
22
void main () {
23
23
IntegrationTestWidgetsFlutterBinding .ensureInitialized ();
24
24
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
+
25
32
const bool _skipDueToIssue86757 = true ;
26
33
27
34
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
@@ -34,7 +41,7 @@ void main() {
34
41
textDirection: TextDirection .ltr,
35
42
child: WebView (
36
43
key: GlobalKey (),
37
- initialUrl: 'https://flutter.dev/' ,
44
+ initialUrl: primaryUrl ,
38
45
onWebViewCreated: (WebViewController controller) {
39
46
controllerCompleter.complete (controller);
40
47
},
@@ -44,7 +51,7 @@ void main() {
44
51
);
45
52
final WebViewController controller = await controllerCompleter.future;
46
53
final String ? currentUrl = await controller.currentUrl ();
47
- expect (currentUrl, 'https://flutter.dev/' );
54
+ expect (currentUrl, primaryUrl );
48
55
}, skip: _skipDueToIssue86757);
49
56
50
57
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
@@ -56,17 +63,17 @@ void main() {
56
63
textDirection: TextDirection .ltr,
57
64
child: WebView (
58
65
key: GlobalKey (),
59
- initialUrl: 'https://flutter.dev/' ,
66
+ initialUrl: primaryUrl ,
60
67
onWebViewCreated: (WebViewController controller) {
61
68
controllerCompleter.complete (controller);
62
69
},
63
70
),
64
71
),
65
72
);
66
73
final WebViewController controller = await controllerCompleter.future;
67
- await controller.loadUrl ('https://www.example.com/' );
74
+ await controller.loadUrl (secondaryUrl );
68
75
final String ? currentUrl = await controller.currentUrl ();
69
- expect (currentUrl, 'https://www.example.com/' );
76
+ expect (currentUrl, secondaryUrl );
70
77
}, skip: _skipDueToIssue86757);
71
78
72
79
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
@@ -80,7 +87,7 @@ void main() {
80
87
textDirection: TextDirection .ltr,
81
88
child: WebView (
82
89
key: GlobalKey (),
83
- initialUrl: 'https://flutter.dev/' ,
90
+ initialUrl: primaryUrl ,
84
91
onWebViewCreated: (WebViewController controller) {
85
92
controllerCompleter.complete (controller);
86
93
},
@@ -298,7 +305,7 @@ void main() {
298
305
textDirection: TextDirection .ltr,
299
306
child: WebView (
300
307
key: _globalKey,
301
- initialUrl: 'https://flutter.dev/' ,
308
+ initialUrl: primaryUrl ,
302
309
javascriptMode: JavascriptMode .unrestricted,
303
310
onWebViewCreated: (WebViewController controller) {
304
311
controllerCompleter.complete (controller);
@@ -1053,12 +1060,11 @@ void main() {
1053
1060
1054
1061
await pageLoads.stream.first; // Wait for initial page load.
1055
1062
final WebViewController controller = await controllerCompleter.future;
1056
- await controller
1057
- .evaluateJavascript ('location.href = "https://www.example.com/"' );
1063
+ await controller.evaluateJavascript ('location.href = "$secondaryUrl "' );
1058
1064
1059
1065
await pageLoads.stream.first; // Wait for the next page load.
1060
1066
final String ? currentUrl = await controller.currentUrl ();
1061
- expect (currentUrl, 'https://www.example.com/' );
1067
+ expect (currentUrl, secondaryUrl );
1062
1068
});
1063
1069
1064
1070
testWidgets ('onWebResourceError' , (WidgetTester tester) async {
@@ -1220,12 +1226,11 @@ void main() {
1220
1226
1221
1227
await pageLoads.stream.first; // Wait for initial page load.
1222
1228
final WebViewController controller = await controllerCompleter.future;
1223
- await controller
1224
- .evaluateJavascript ('location.href = "https://www.example.com"' );
1229
+ await controller.evaluateJavascript ('location.href = "$secondaryUrl "' );
1225
1230
1226
1231
await pageLoads.stream.first; // Wait for second page to load.
1227
1232
final String ? currentUrl = await controller.currentUrl ();
1228
- expect (currentUrl, 'https://www.example.com/' );
1233
+ expect (currentUrl, secondaryUrl );
1229
1234
});
1230
1235
});
1231
1236
@@ -1241,7 +1246,7 @@ void main() {
1241
1246
height: 300 ,
1242
1247
child: WebView (
1243
1248
key: GlobalKey (),
1244
- initialUrl: 'https://flutter.dev/' ,
1249
+ initialUrl: primaryUrl ,
1245
1250
gestureNavigationEnabled: true ,
1246
1251
onWebViewCreated: (WebViewController controller) {
1247
1252
controllerCompleter.complete (controller);
@@ -1252,7 +1257,7 @@ void main() {
1252
1257
);
1253
1258
final WebViewController controller = await controllerCompleter.future;
1254
1259
final String ? currentUrl = await controller.currentUrl ();
1255
- expect (currentUrl, 'https://flutter.dev/' );
1260
+ expect (currentUrl, primaryUrl );
1256
1261
});
1257
1262
1258
1263
testWidgets ('target _blank opens in same window' ,
@@ -1276,11 +1281,10 @@ void main() {
1276
1281
),
1277
1282
);
1278
1283
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")' );
1281
1285
await pageLoaded.future;
1282
1286
final String ? currentUrl = await controller.currentUrl ();
1283
- expect (currentUrl, 'https://flutter.dev/' );
1287
+ expect (currentUrl, primaryUrl );
1284
1288
},
1285
1289
// Flaky on Android: https://github.com/flutter/flutter/issues/86757
1286
1290
skip: _skipDueToIssue86757);
@@ -1304,25 +1308,24 @@ void main() {
1304
1308
onPageFinished: (String url) {
1305
1309
pageLoaded.complete ();
1306
1310
},
1307
- initialUrl: 'https://flutter.dev' ,
1311
+ initialUrl: primaryUrl ,
1308
1312
),
1309
1313
),
1310
1314
);
1311
1315
final WebViewController controller = await controllerCompleter.future;
1312
- expect (controller.currentUrl (), completion ('https://flutter.dev/' ));
1316
+ expect (controller.currentUrl (), completion (primaryUrl ));
1313
1317
await pageLoaded.future;
1314
1318
pageLoaded = Completer <void >();
1315
1319
1316
- await controller
1317
- .evaluateJavascript ('window.open("https://www.example.com/")' );
1320
+ await controller.evaluateJavascript ('window.open("$secondaryUrl ")' );
1318
1321
await pageLoaded.future;
1319
1322
pageLoaded = Completer <void >();
1320
- expect (controller.currentUrl (), completion ('https://www.example.com/' ));
1323
+ expect (controller.currentUrl (), completion (secondaryUrl ));
1321
1324
1322
1325
expect (controller.canGoBack (), completion (true ));
1323
1326
await controller.goBack ();
1324
1327
await pageLoaded.future;
1325
- expect (controller.currentUrl (), completion ('https://flutter.dev/' ));
1328
+ expect (controller.currentUrl (), completion (primaryUrl ));
1326
1329
},
1327
1330
skip: _skipDueToIssue86757,
1328
1331
);
0 commit comments