Skip to content

Commit

Permalink
[webview_flutter] Adjust test URLs again (flutter#4407)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartmorgan authored Oct 8, 2021
1 parent 5117a3f commit c254963
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ import 'package:integration_test/integration_test.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

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

const bool _skipDueToIssue86757 = true;

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
Expand All @@ -29,7 +36,7 @@ void main() {
textDirection: TextDirection.ltr,
child: WebView(
key: GlobalKey(),
initialUrl: 'https://flutter.dev/',
initialUrl: primaryUrl,
onWebViewCreated: (WebViewController controller) {
controllerCompleter.complete(controller);
},
Expand All @@ -38,7 +45,7 @@ void main() {
);
final WebViewController controller = await controllerCompleter.future;
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://flutter.dev/');
expect(currentUrl, primaryUrl);
}, skip: _skipDueToIssue86757);

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
Expand All @@ -50,17 +57,17 @@ void main() {
textDirection: TextDirection.ltr,
child: WebView(
key: GlobalKey(),
initialUrl: 'https://flutter.dev/',
initialUrl: primaryUrl,
onWebViewCreated: (WebViewController controller) {
controllerCompleter.complete(controller);
},
),
),
);
final WebViewController controller = await controllerCompleter.future;
await controller.loadUrl('https://www.example.com/');
await controller.loadUrl(secondaryUrl);
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://www.example.com/');
expect(currentUrl, secondaryUrl);
}, skip: _skipDueToIssue86757);

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
Expand All @@ -74,7 +81,7 @@ void main() {
textDirection: TextDirection.ltr,
child: WebView(
key: GlobalKey(),
initialUrl: 'https://flutter.dev/',
initialUrl: primaryUrl,
onWebViewCreated: (WebViewController controller) {
controllerCompleter.complete(controller);
},
Expand Down Expand Up @@ -292,7 +299,7 @@ void main() {
textDirection: TextDirection.ltr,
child: WebView(
key: _globalKey,
initialUrl: 'https://flutter.dev/',
initialUrl: primaryUrl,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController controller) {
controllerCompleter.complete(controller);
Expand Down Expand Up @@ -1099,12 +1106,11 @@ void main() {

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

await pageLoads.stream.first; // Wait for the next page load.
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://www.example.com/');
expect(currentUrl, secondaryUrl);
});

testWidgets('onWebResourceError', (WidgetTester tester) async {
Expand Down Expand Up @@ -1271,12 +1277,11 @@ void main() {

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

await pageLoads.stream.first; // Wait for second page to load.
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://www.example.com/');
expect(currentUrl, secondaryUrl);
});
});

Expand All @@ -1292,7 +1297,7 @@ void main() {
height: 300,
child: WebView(
key: GlobalKey(),
initialUrl: 'https://flutter.dev/',
initialUrl: primaryUrl,
gestureNavigationEnabled: true,
onWebViewCreated: (WebViewController controller) {
controllerCompleter.complete(controller);
Expand All @@ -1303,7 +1308,7 @@ void main() {
);
final WebViewController controller = await controllerCompleter.future;
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://flutter.dev/');
expect(currentUrl, primaryUrl);
});

testWidgets('target _blank opens in same window',
Expand All @@ -1327,11 +1332,10 @@ void main() {
),
);
final WebViewController controller = await controllerCompleter.future;
await controller
.evaluateJavascript('window.open("https://flutter.dev/", "_blank")');
await controller.evaluateJavascript('window.open("$primaryUrl", "_blank")');
await pageLoaded.future;
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://flutter.dev/');
expect(currentUrl, primaryUrl);
},
// Flaky on Android: https://github.com/flutter/flutter/issues/86757
skip: Platform.isAndroid && _skipDueToIssue86757);
Expand All @@ -1355,25 +1359,24 @@ void main() {
onPageFinished: (String url) {
pageLoaded.complete();
},
initialUrl: 'https://flutter.dev',
initialUrl: primaryUrl,
),
),
);
final WebViewController controller = await controllerCompleter.future;
expect(controller.currentUrl(), completion('https://flutter.dev/'));
expect(controller.currentUrl(), completion(primaryUrl));
await pageLoaded.future;
pageLoaded = Completer<void>();

await controller
.evaluateJavascript('window.open("https://www.example.com/")');
await controller.evaluateJavascript('window.open("$secondaryUrl")');
await pageLoaded.future;
pageLoaded = Completer<void>();
expect(controller.currentUrl(), completion('https://www.example.com/'));
expect(controller.currentUrl(), completion(secondaryUrl));

expect(controller.canGoBack(), completion(true));
await controller.goBack();
await pageLoaded.future;
expect(controller.currentUrl(), completion('https://flutter.dev/'));
expect(controller.currentUrl(), completion(primaryUrl));
},
skip: _skipDueToIssue86757,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ import 'package:webview_flutter_platform_interface/webview_flutter_platform_inte
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

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

const bool _skipDueToIssue86757 = true;

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
Expand All @@ -34,7 +41,7 @@ void main() {
textDirection: TextDirection.ltr,
child: WebView(
key: GlobalKey(),
initialUrl: 'https://flutter.dev/',
initialUrl: primaryUrl,
onWebViewCreated: (WebViewController controller) {
controllerCompleter.complete(controller);
},
Expand All @@ -44,7 +51,7 @@ void main() {
);
final WebViewController controller = await controllerCompleter.future;
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://flutter.dev/');
expect(currentUrl, primaryUrl);
}, skip: _skipDueToIssue86757);

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
Expand All @@ -56,17 +63,17 @@ void main() {
textDirection: TextDirection.ltr,
child: WebView(
key: GlobalKey(),
initialUrl: 'https://flutter.dev/',
initialUrl: primaryUrl,
onWebViewCreated: (WebViewController controller) {
controllerCompleter.complete(controller);
},
),
),
);
final WebViewController controller = await controllerCompleter.future;
await controller.loadUrl('https://www.example.com/');
await controller.loadUrl(secondaryUrl);
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://www.example.com/');
expect(currentUrl, secondaryUrl);
}, skip: _skipDueToIssue86757);

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
Expand All @@ -80,7 +87,7 @@ void main() {
textDirection: TextDirection.ltr,
child: WebView(
key: GlobalKey(),
initialUrl: 'https://flutter.dev/',
initialUrl: primaryUrl,
onWebViewCreated: (WebViewController controller) {
controllerCompleter.complete(controller);
},
Expand Down Expand Up @@ -298,7 +305,7 @@ void main() {
textDirection: TextDirection.ltr,
child: WebView(
key: _globalKey,
initialUrl: 'https://flutter.dev/',
initialUrl: primaryUrl,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController controller) {
controllerCompleter.complete(controller);
Expand Down Expand Up @@ -1053,12 +1060,11 @@ void main() {

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

await pageLoads.stream.first; // Wait for the next page load.
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://www.example.com/');
expect(currentUrl, secondaryUrl);
});

testWidgets('onWebResourceError', (WidgetTester tester) async {
Expand Down Expand Up @@ -1220,12 +1226,11 @@ void main() {

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

await pageLoads.stream.first; // Wait for second page to load.
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://www.example.com/');
expect(currentUrl, secondaryUrl);
});
});

Expand All @@ -1241,7 +1246,7 @@ void main() {
height: 300,
child: WebView(
key: GlobalKey(),
initialUrl: 'https://flutter.dev/',
initialUrl: primaryUrl,
gestureNavigationEnabled: true,
onWebViewCreated: (WebViewController controller) {
controllerCompleter.complete(controller);
Expand All @@ -1252,7 +1257,7 @@ void main() {
);
final WebViewController controller = await controllerCompleter.future;
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://flutter.dev/');
expect(currentUrl, primaryUrl);
});

testWidgets('target _blank opens in same window',
Expand All @@ -1276,11 +1281,10 @@ void main() {
),
);
final WebViewController controller = await controllerCompleter.future;
await controller
.evaluateJavascript('window.open("https://flutter.dev/", "_blank")');
await controller.evaluateJavascript('window.open("$primaryUrl", "_blank")');
await pageLoaded.future;
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://flutter.dev/');
expect(currentUrl, primaryUrl);
},
// Flaky on Android: https://github.com/flutter/flutter/issues/86757
skip: _skipDueToIssue86757);
Expand All @@ -1304,25 +1308,24 @@ void main() {
onPageFinished: (String url) {
pageLoaded.complete();
},
initialUrl: 'https://flutter.dev',
initialUrl: primaryUrl,
),
),
);
final WebViewController controller = await controllerCompleter.future;
expect(controller.currentUrl(), completion('https://flutter.dev/'));
expect(controller.currentUrl(), completion(primaryUrl));
await pageLoaded.future;
pageLoaded = Completer<void>();

await controller
.evaluateJavascript('window.open("https://www.example.com/")');
await controller.evaluateJavascript('window.open("$secondaryUrl")');
await pageLoaded.future;
pageLoaded = Completer<void>();
expect(controller.currentUrl(), completion('https://www.example.com/'));
expect(controller.currentUrl(), completion(secondaryUrl));

expect(controller.canGoBack(), completion(true));
await controller.goBack();
await pageLoaded.future;
expect(controller.currentUrl(), completion('https://flutter.dev/'));
expect(controller.currentUrl(), completion(primaryUrl));
},
skip: _skipDueToIssue86757,
);
Expand Down
Loading

0 comments on commit c254963

Please sign in to comment.