Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit c254963

Browse files
authored
[webview_flutter] Adjust test URLs again (#4407)
1 parent 5117a3f commit c254963

File tree

3 files changed

+81
-72
lines changed

3 files changed

+81
-72
lines changed

packages/webview_flutter/webview_flutter/example/integration_test/webview_flutter_test.dart

+27-24
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ import 'package:integration_test/integration_test.dart';
1818
void main() {
1919
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
2020

21+
// URLs to navigate to in tests. These need to be URLs that we are confident will
22+
// always be accessible, and won't do redirection. (E.g., just
23+
// 'https://www.google.com/' will sometimes redirect traffic that looks
24+
// like it's coming from a bot, which is true of these tests).
25+
const String primaryUrl = 'https://flutter.dev/';
26+
const String secondaryUrl = 'https://www.google.com/robots.txt';
27+
2128
const bool _skipDueToIssue86757 = true;
2229

2330
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
@@ -29,7 +36,7 @@ void main() {
2936
textDirection: TextDirection.ltr,
3037
child: WebView(
3138
key: GlobalKey(),
32-
initialUrl: 'https://flutter.dev/',
39+
initialUrl: primaryUrl,
3340
onWebViewCreated: (WebViewController controller) {
3441
controllerCompleter.complete(controller);
3542
},
@@ -38,7 +45,7 @@ void main() {
3845
);
3946
final WebViewController controller = await controllerCompleter.future;
4047
final String? currentUrl = await controller.currentUrl();
41-
expect(currentUrl, 'https://flutter.dev/');
48+
expect(currentUrl, primaryUrl);
4249
}, skip: _skipDueToIssue86757);
4350

4451
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
@@ -50,17 +57,17 @@ void main() {
5057
textDirection: TextDirection.ltr,
5158
child: WebView(
5259
key: GlobalKey(),
53-
initialUrl: 'https://flutter.dev/',
60+
initialUrl: primaryUrl,
5461
onWebViewCreated: (WebViewController controller) {
5562
controllerCompleter.complete(controller);
5663
},
5764
),
5865
),
5966
);
6067
final WebViewController controller = await controllerCompleter.future;
61-
await controller.loadUrl('https://www.example.com/');
68+
await controller.loadUrl(secondaryUrl);
6269
final String? currentUrl = await controller.currentUrl();
63-
expect(currentUrl, 'https://www.example.com/');
70+
expect(currentUrl, secondaryUrl);
6471
}, skip: _skipDueToIssue86757);
6572

6673
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
@@ -74,7 +81,7 @@ void main() {
7481
textDirection: TextDirection.ltr,
7582
child: WebView(
7683
key: GlobalKey(),
77-
initialUrl: 'https://flutter.dev/',
84+
initialUrl: primaryUrl,
7885
onWebViewCreated: (WebViewController controller) {
7986
controllerCompleter.complete(controller);
8087
},
@@ -292,7 +299,7 @@ void main() {
292299
textDirection: TextDirection.ltr,
293300
child: WebView(
294301
key: _globalKey,
295-
initialUrl: 'https://flutter.dev/',
302+
initialUrl: primaryUrl,
296303
javascriptMode: JavascriptMode.unrestricted,
297304
onWebViewCreated: (WebViewController controller) {
298305
controllerCompleter.complete(controller);
@@ -1099,12 +1106,11 @@ void main() {
10991106

11001107
await pageLoads.stream.first; // Wait for initial page load.
11011108
final WebViewController controller = await controllerCompleter.future;
1102-
await controller
1103-
.evaluateJavascript('location.href = "https://www.example.com/"');
1109+
await controller.evaluateJavascript('location.href = "$secondaryUrl"');
11041110

11051111
await pageLoads.stream.first; // Wait for the next page load.
11061112
final String? currentUrl = await controller.currentUrl();
1107-
expect(currentUrl, 'https://www.example.com/');
1113+
expect(currentUrl, secondaryUrl);
11081114
});
11091115

11101116
testWidgets('onWebResourceError', (WidgetTester tester) async {
@@ -1271,12 +1277,11 @@ void main() {
12711277

12721278
await pageLoads.stream.first; // Wait for initial page load.
12731279
final WebViewController controller = await controllerCompleter.future;
1274-
await controller
1275-
.evaluateJavascript('location.href = "https://www.example.com"');
1280+
await controller.evaluateJavascript('location.href = "$secondaryUrl"');
12761281

12771282
await pageLoads.stream.first; // Wait for second page to load.
12781283
final String? currentUrl = await controller.currentUrl();
1279-
expect(currentUrl, 'https://www.example.com/');
1284+
expect(currentUrl, secondaryUrl);
12801285
});
12811286
});
12821287

@@ -1292,7 +1297,7 @@ void main() {
12921297
height: 300,
12931298
child: WebView(
12941299
key: GlobalKey(),
1295-
initialUrl: 'https://flutter.dev/',
1300+
initialUrl: primaryUrl,
12961301
gestureNavigationEnabled: true,
12971302
onWebViewCreated: (WebViewController controller) {
12981303
controllerCompleter.complete(controller);
@@ -1303,7 +1308,7 @@ void main() {
13031308
);
13041309
final WebViewController controller = await controllerCompleter.future;
13051310
final String? currentUrl = await controller.currentUrl();
1306-
expect(currentUrl, 'https://flutter.dev/');
1311+
expect(currentUrl, primaryUrl);
13071312
});
13081313

13091314
testWidgets('target _blank opens in same window',
@@ -1327,11 +1332,10 @@ void main() {
13271332
),
13281333
);
13291334
final WebViewController controller = await controllerCompleter.future;
1330-
await controller
1331-
.evaluateJavascript('window.open("https://flutter.dev/", "_blank")');
1335+
await controller.evaluateJavascript('window.open("$primaryUrl", "_blank")');
13321336
await pageLoaded.future;
13331337
final String? currentUrl = await controller.currentUrl();
1334-
expect(currentUrl, 'https://flutter.dev/');
1338+
expect(currentUrl, primaryUrl);
13351339
},
13361340
// Flaky on Android: https://github.com/flutter/flutter/issues/86757
13371341
skip: Platform.isAndroid && _skipDueToIssue86757);
@@ -1355,25 +1359,24 @@ void main() {
13551359
onPageFinished: (String url) {
13561360
pageLoaded.complete();
13571361
},
1358-
initialUrl: 'https://flutter.dev',
1362+
initialUrl: primaryUrl,
13591363
),
13601364
),
13611365
);
13621366
final WebViewController controller = await controllerCompleter.future;
1363-
expect(controller.currentUrl(), completion('https://flutter.dev/'));
1367+
expect(controller.currentUrl(), completion(primaryUrl));
13641368
await pageLoaded.future;
13651369
pageLoaded = Completer<void>();
13661370

1367-
await controller
1368-
.evaluateJavascript('window.open("https://www.example.com/")');
1371+
await controller.evaluateJavascript('window.open("$secondaryUrl")');
13691372
await pageLoaded.future;
13701373
pageLoaded = Completer<void>();
1371-
expect(controller.currentUrl(), completion('https://www.example.com/'));
1374+
expect(controller.currentUrl(), completion(secondaryUrl));
13721375

13731376
expect(controller.canGoBack(), completion(true));
13741377
await controller.goBack();
13751378
await pageLoaded.future;
1376-
expect(controller.currentUrl(), completion('https://flutter.dev/'));
1379+
expect(controller.currentUrl(), completion(primaryUrl));
13771380
},
13781381
skip: _skipDueToIssue86757,
13791382
);

packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test.dart

+27-24
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ import 'package:webview_flutter_platform_interface/webview_flutter_platform_inte
2222
void 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

Comments
 (0)