iosWebViewFix/example/integration_test/in_app_webview/web_history.dart

220 lines
8.1 KiB
Dart
Raw Normal View History

part of 'main.dart';
2022-04-28 21:23:38 +00:00
void webHistory() {
2022-04-29 11:39:28 +00:00
final shouldSkip = kIsWeb
? false
: ![
2022-04-28 21:23:38 +00:00
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
skippableGroup('web history', () {
2022-04-29 11:39:28 +00:00
final shouldSkipTest1 = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
skippableTestWidgets('get history list and go back/forward',
2022-04-29 11:39:28 +00:00
(WidgetTester tester) async {
final Completer<InAppWebViewController> controllerCompleter =
Completer<InAppWebViewController>();
2022-04-28 21:23:38 +00:00
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
2022-04-29 00:07:01 +00:00
onLoadStart: (controller, url) {
// pageLoads.add(url!.toString());
2022-04-28 21:23:38 +00:00
},
),
),
);
final InAppWebViewController controller =
2022-04-29 11:39:28 +00:00
await controllerCompleter.future;
2022-04-28 21:23:38 +00:00
2022-04-29 00:07:01 +00:00
await Future.delayed(Duration(seconds: 1));
var url = (await controller.getUrl()).toString();
2022-04-28 21:23:38 +00:00
var webHistory = await controller.getCopyBackForwardList();
expect(url, TEST_CROSS_PLATFORM_URL_1.toString());
expect(webHistory!.currentIndex, 0);
expect(webHistory.list!.length, 1);
2022-04-29 11:39:28 +00:00
expect(webHistory.list![0].url.toString(),
TEST_CROSS_PLATFORM_URL_1.toString());
2022-04-28 21:23:38 +00:00
2022-04-29 11:39:28 +00:00
await controller.loadUrl(urlRequest: URLRequest(url: TEST_URL_1));
2022-04-29 00:07:01 +00:00
await Future.delayed(Duration(seconds: 1));
url = (await controller.getUrl()).toString();
2022-04-28 21:23:38 +00:00
webHistory = await controller.getCopyBackForwardList();
expect(url, TEST_URL_1.toString());
expect(await controller.canGoBack(), true);
expect(await controller.canGoForward(), false);
expect(await controller.canGoBackOrForward(steps: -1), true);
expect(await controller.canGoBackOrForward(steps: 1), false);
expect(webHistory!.currentIndex, 1);
expect(webHistory.list!.length, 2);
2022-04-29 11:39:28 +00:00
expect(webHistory.list![0].url.toString(),
TEST_CROSS_PLATFORM_URL_1.toString());
2022-04-28 21:23:38 +00:00
expect(webHistory.list![1].url.toString(), TEST_URL_1.toString());
await Future.delayed(Duration(seconds: 1));
await controller.goBack();
2022-04-29 00:07:01 +00:00
await Future.delayed(Duration(seconds: 1));
url = (await controller.getUrl()).toString();
2022-04-28 21:23:38 +00:00
webHistory = await controller.getCopyBackForwardList();
expect(url, TEST_CROSS_PLATFORM_URL_1.toString());
expect(await controller.canGoBack(), false);
expect(await controller.canGoForward(), true);
expect(await controller.canGoBackOrForward(steps: -1), false);
expect(await controller.canGoBackOrForward(steps: 1), true);
expect(webHistory!.currentIndex, 0);
expect(webHistory.list!.length, 2);
2022-04-29 11:39:28 +00:00
expect(webHistory.list![0].url.toString(),
TEST_CROSS_PLATFORM_URL_1.toString());
2022-04-28 21:23:38 +00:00
expect(webHistory.list![1].url.toString(), TEST_URL_1.toString());
await Future.delayed(Duration(seconds: 1));
await controller.goForward();
2022-04-29 00:07:01 +00:00
await Future.delayed(Duration(seconds: 1));
url = (await controller.getUrl()).toString();
2022-04-28 21:23:38 +00:00
webHistory = await controller.getCopyBackForwardList();
expect(url, TEST_URL_1.toString());
expect(await controller.canGoBack(), true);
expect(await controller.canGoForward(), false);
expect(await controller.canGoBackOrForward(steps: -1), true);
expect(await controller.canGoBackOrForward(steps: 1), false);
expect(webHistory!.currentIndex, 1);
expect(webHistory.list!.length, 2);
2022-04-29 11:39:28 +00:00
expect(webHistory.list![0].url.toString(),
TEST_CROSS_PLATFORM_URL_1.toString());
2022-04-28 21:23:38 +00:00
expect(webHistory.list![1].url.toString(), TEST_URL_1.toString());
await Future.delayed(Duration(seconds: 1));
await controller.goTo(historyItem: webHistory.list![0]);
2022-04-29 00:07:01 +00:00
await Future.delayed(Duration(seconds: 1));
url = (await controller.getUrl()).toString();
2022-04-28 21:23:38 +00:00
webHistory = await controller.getCopyBackForwardList();
expect(url, TEST_CROSS_PLATFORM_URL_1.toString());
expect(await controller.canGoBack(), false);
expect(await controller.canGoForward(), true);
expect(await controller.canGoBackOrForward(steps: -1), false);
expect(await controller.canGoBackOrForward(steps: 1), true);
expect(webHistory!.currentIndex, 0);
expect(webHistory.list!.length, 2);
2022-04-29 11:39:28 +00:00
expect(webHistory.list![0].url.toString(),
TEST_CROSS_PLATFORM_URL_1.toString());
2022-04-28 21:23:38 +00:00
expect(webHistory.list![1].url.toString(), TEST_URL_1.toString());
}, skip: shouldSkipTest1);
final shouldSkipTest2 = !kIsWeb;
skippableTestWidgets('go back/forward on web platform',
(WidgetTester tester) async {
final Completer<InAppWebViewController> controllerCompleter =
Completer<InAppWebViewController>();
2022-04-28 21:23:38 +00:00
final StreamController<String> pageLoads =
2022-04-29 11:39:28 +00:00
StreamController<String>.broadcast();
2022-04-28 21:23:38 +00:00
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: TEST_WEB_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
onLoadStop: (controller, url) {
pageLoads.add(url!.toString());
},
),
),
);
final InAppWebViewController controller =
2022-04-29 11:39:28 +00:00
await controllerCompleter.future;
2022-04-28 21:23:38 +00:00
2022-04-30 19:22:31 +00:00
await tester.pump();
2022-04-28 21:23:38 +00:00
var url = await pageLoads.stream.first;
expect(url, TEST_WEB_PLATFORM_URL_1.toString());
2022-10-11 14:19:36 +00:00
await controller.evaluateJavascript(
source: "document.getElementById('link-page-2').click();");
2022-04-28 21:23:38 +00:00
url = await pageLoads.stream.first;
expect(url, TEST_WEB_PLATFORM_URL_2.toString());
await Future.delayed(Duration(seconds: 1));
await controller.goBack();
url = await pageLoads.stream.first;
expect(url, TEST_WEB_PLATFORM_URL_1.toString());
await Future.delayed(Duration(seconds: 1));
await controller.goForward();
url = await pageLoads.stream.first;
expect(url, TEST_WEB_PLATFORM_URL_2.toString());
await Future.delayed(Duration(seconds: 1));
await controller.goBackOrForward(steps: -1);
url = await pageLoads.stream.first;
expect(url, TEST_WEB_PLATFORM_URL_1.toString());
pageLoads.close();
}, skip: shouldSkipTest2);
2022-04-29 11:39:28 +00:00
final shouldSkipTest3 = kIsWeb
? true
: ![
TargetPlatform.android,
].contains(defaultTargetPlatform);
2022-04-28 21:23:38 +00:00
skippableTestWidgets('clearHistory', (WidgetTester tester) async {
final Completer<InAppWebViewController> controllerCompleter =
Completer<InAppWebViewController>();
2022-04-28 21:23:38 +00:00
final StreamController<String> pageLoads =
2022-04-29 11:39:28 +00:00
StreamController<String>.broadcast();
2022-04-28 21:23:38 +00:00
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
2022-04-29 11:39:28 +00:00
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
2022-04-28 21:23:38 +00:00
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
onLoadStop: (controller, url) {
pageLoads.add(url!.toString());
},
),
),
);
final InAppWebViewController controller =
2022-04-29 11:39:28 +00:00
await controllerCompleter.future;
2022-04-28 21:23:38 +00:00
await pageLoads.stream.first;
2022-04-29 11:39:28 +00:00
await controller.loadUrl(urlRequest: URLRequest(url: TEST_URL_1));
2022-04-28 21:23:38 +00:00
await pageLoads.stream.first;
var webHistory = await controller.getCopyBackForwardList();
expect(webHistory!.list!.length, 2);
await controller.clearHistory();
webHistory = await controller.getCopyBackForwardList();
expect(webHistory!.list!.length, 1);
pageLoads.close();
}, skip: shouldSkipTest3);
}, skip: shouldSkip);
}