From a8593f557eee92ac83a00d35a06be76479017d89 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Fri, 29 Apr 2022 02:07:01 +0200 Subject: [PATCH] updated tests --- .../custom_action_button.dart | 17 +++++------ .../custom_menu_item.dart | 16 +++++----- .../chrome_safari_browser/custom_tabs.dart | 11 +++---- .../chrome_safari_browser/open_and_close.dart | 16 +++++----- .../trusted_web_activity.dart | 11 +++---- example/integration_test/constants.dart | 2 +- .../cookie_manager/set_get_delete.dart | 29 +++++++++---------- .../headless_in_app_webview/custom_size.dart | 16 +++++----- .../run_and_dispose.dart | 2 +- .../set_get_settings.dart | 16 +++++----- .../in_app_browser/open_data_and_close.dart | 16 +++++----- .../in_app_browser/open_file_and_close.dart | 16 +++++----- .../in_app_browser/open_url_and_close.dart | 16 +++++----- .../in_app_browser/set_get_settings.dart | 13 +++++---- .../load_asset_file.dart | 16 +++++----- .../in_app_webview/on_permission_request.dart | 7 +++-- .../in_app_webview/on_print.dart | 1 + .../in_app_webview/print_current_page.dart | 2 +- .../in_app_webview/take_screenshot.dart | 19 ++++++------ .../in_app_webview/video_playback_policy.dart | 4 +++ .../in_app_webview/web_history.dart | 23 ++++++++------- .../in_app_webview/web_message.dart | 14 +++++---- .../in_app_webview/webview_windows.dart | 2 ++ .../set_service_worker_client.dart | 12 ++++---- .../should_intercept_request.dart | 9 +++--- example/pubspec.yaml | 19 ++---------- lib/src/in_app_webview/in_app_webview.dart | 9 +++--- scripts/test.sh | 16 ++++++++-- 28 files changed, 181 insertions(+), 169 deletions(-) diff --git a/example/integration_test/chrome_safari_browser/custom_action_button.dart b/example/integration_test/chrome_safari_browser/custom_action_button.dart index 1d65babd..2ace899d 100644 --- a/example/integration_test/chrome_safari_browser/custom_action_button.dart +++ b/example/integration_test/chrome_safari_browser/custom_action_button.dart @@ -7,15 +7,16 @@ import '../constants.dart'; import '../util.dart'; void customActionButton() { - final shouldSkip = kIsWeb || - ![ - TargetPlatform.android, - ].contains(defaultTargetPlatform); + final shouldSkip = kIsWeb + ? true + : ![ + TargetPlatform.android, + ].contains(defaultTargetPlatform); test('add custom action button', () async { var chromeSafariBrowser = new MyChromeSafariBrowser(); var actionButtonIcon = - await rootBundle.load('test_assets/images/flutter-logo.png'); + await rootBundle.load('test_assets/images/flutter-logo.png'); chromeSafariBrowser.setActionButton(ChromeSafariBrowserActionButton( id: 1, description: 'Action Button description', @@ -25,16 +26,14 @@ void customActionButton() { })); expect(chromeSafariBrowser.isOpened(), false); - await chromeSafariBrowser.open( - url: TEST_URL_1); + await chromeSafariBrowser.open(url: TEST_URL_1); await chromeSafariBrowser.browserCreated.future; expect(chromeSafariBrowser.isOpened(), true); expect(() async { await chromeSafariBrowser.open(url: TEST_CROSS_PLATFORM_URL_1); }, throwsA(isInstanceOf())); - await expectLater( - chromeSafariBrowser.firstPageLoaded.future, completes); + await expectLater(chromeSafariBrowser.firstPageLoaded.future, completes); await chromeSafariBrowser.close(); await chromeSafariBrowser.browserClosed.future; expect(chromeSafariBrowser.isOpened(), false); diff --git a/example/integration_test/chrome_safari_browser/custom_menu_item.dart b/example/integration_test/chrome_safari_browser/custom_menu_item.dart index 85238057..8fefd202 100644 --- a/example/integration_test/chrome_safari_browser/custom_menu_item.dart +++ b/example/integration_test/chrome_safari_browser/custom_menu_item.dart @@ -6,12 +6,13 @@ import '../constants.dart'; import '../util.dart'; void customMenuItem() { - final shouldSkip = kIsWeb || - ![ - TargetPlatform.android, - TargetPlatform.iOS, - TargetPlatform.macOS, - ].contains(defaultTargetPlatform); + final shouldSkip = kIsWeb + ? true + : ![ + TargetPlatform.android, + TargetPlatform.iOS, + TargetPlatform.macOS, + ].contains(defaultTargetPlatform); test('add custom menu item', () async { var chromeSafariBrowser = new MyChromeSafariBrowser(); @@ -23,8 +24,7 @@ void customMenuItem() { })); expect(chromeSafariBrowser.isOpened(), false); - await chromeSafariBrowser.open( - url: TEST_URL_1); + await chromeSafariBrowser.open(url: TEST_URL_1); await chromeSafariBrowser.browserCreated.future; expect(chromeSafariBrowser.isOpened(), true); expect(() async { diff --git a/example/integration_test/chrome_safari_browser/custom_tabs.dart b/example/integration_test/chrome_safari_browser/custom_tabs.dart index feb333f1..c658e621 100644 --- a/example/integration_test/chrome_safari_browser/custom_tabs.dart +++ b/example/integration_test/chrome_safari_browser/custom_tabs.dart @@ -6,12 +6,13 @@ import '../constants.dart'; import '../util.dart'; void customTabs() { - final shouldSkip = kIsWeb || - ![ - TargetPlatform.android, - ].contains(defaultTargetPlatform); + final shouldSkip = kIsWeb + ? true + : ![ + TargetPlatform.android, + ].contains(defaultTargetPlatform); - group('Custom Tabs', () async { + group('Custom Tabs', () { test('single instance', () async { var chromeSafariBrowser = new MyChromeSafariBrowser(); expect(chromeSafariBrowser.isOpened(), false); diff --git a/example/integration_test/chrome_safari_browser/open_and_close.dart b/example/integration_test/chrome_safari_browser/open_and_close.dart index 1b5a3040..decfe600 100644 --- a/example/integration_test/chrome_safari_browser/open_and_close.dart +++ b/example/integration_test/chrome_safari_browser/open_and_close.dart @@ -6,19 +6,19 @@ import '../constants.dart'; import '../util.dart'; void openAndClose() { - final shouldSkip = kIsWeb || - ![ - TargetPlatform.android, - TargetPlatform.iOS, - TargetPlatform.macOS, - ].contains(defaultTargetPlatform); + final shouldSkip = kIsWeb + ? true + : ![ + TargetPlatform.android, + TargetPlatform.iOS, + TargetPlatform.macOS, + ].contains(defaultTargetPlatform); test('open and close', () async { var chromeSafariBrowser = new MyChromeSafariBrowser(); expect(chromeSafariBrowser.isOpened(), false); - await chromeSafariBrowser.open( - url: TEST_URL_1); + await chromeSafariBrowser.open(url: TEST_URL_1); await chromeSafariBrowser.browserCreated.future; expect(chromeSafariBrowser.isOpened(), true); expect(() async { diff --git a/example/integration_test/chrome_safari_browser/trusted_web_activity.dart b/example/integration_test/chrome_safari_browser/trusted_web_activity.dart index 60eedc5d..35eee478 100644 --- a/example/integration_test/chrome_safari_browser/trusted_web_activity.dart +++ b/example/integration_test/chrome_safari_browser/trusted_web_activity.dart @@ -6,12 +6,13 @@ import '../constants.dart'; import '../util.dart'; void trustedWebActivity() { - final shouldSkip = kIsWeb || - ![ - TargetPlatform.android, - ].contains(defaultTargetPlatform); + final shouldSkip = kIsWeb + ? true + : ![ + TargetPlatform.android, + ].contains(defaultTargetPlatform); - group('Trusted Web Activity', () async { + group('Trusted Web Activity', () { test('basic', () async { var chromeSafariBrowser = new MyChromeSafariBrowser(); expect(chromeSafariBrowser.isOpened(), false); diff --git a/example/integration_test/constants.dart b/example/integration_test/constants.dart index 2c10848f..9cbf5f2b 100644 --- a/example/integration_test/constants.dart +++ b/example/integration_test/constants.dart @@ -11,7 +11,7 @@ final TEST_WEB_PLATFORM_BASE_URL = Uri.parse(Uri.base.toString().replaceFirst("/ final TEST_WEB_PLATFORM_URL_1 = Uri.parse(TEST_WEB_PLATFORM_BASE_URL.toString() + 'page.html'); final TEST_WEB_PLATFORM_URL_2 = Uri.parse(TEST_WEB_PLATFORM_BASE_URL.toString() + 'page-2.html'); final TEST_WEB_PLATFORM_URL_3 = Uri.parse(TEST_WEB_PLATFORM_BASE_URL.toString() + 'heavy-page.html'); -final TEST_NOT_A_WEBSITE_URL = Uri.parse('https://www.notawebsite..com'); +final TEST_NOT_A_WEBSITE_URL = Uri.parse('https://www.notawebsite..com/'); final TEST_CHROME_SAFE_BROWSING_MALWARE = Uri.parse('chrome://safe-browsing/match?type=malware'); final TEST_PERMISSION_SITE = Uri.parse('https://permission.site/'); final TEST_SERVICE_WORKER_URL = Uri.parse('https://mdn.github.io/sw-test/'); diff --git a/example/integration_test/cookie_manager/set_get_delete.dart b/example/integration_test/cookie_manager/set_get_delete.dart index e766e7ee..295acb1e 100644 --- a/example/integration_test/cookie_manager/set_get_delete.dart +++ b/example/integration_test/cookie_manager/set_get_delete.dart @@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart'; import '../constants.dart'; void setGetDelete() { - final shouldSkip = kIsWeb || - ![ - TargetPlatform.android, - TargetPlatform.iOS, - TargetPlatform.macOS, - ].contains(defaultTargetPlatform); + final shouldSkip = kIsWeb + ? true + : ![ + TargetPlatform.android, + TargetPlatform.iOS, + TargetPlatform.macOS, + ].contains(defaultTargetPlatform); testWidgets('set, get, delete', (WidgetTester tester) async { CookieManager cookieManager = CookieManager.instance(); @@ -24,15 +25,13 @@ void setGetDelete() { textDirection: TextDirection.ltr, child: InAppWebView( key: GlobalKey(), - initialUrlRequest: - URLRequest(url: TEST_CROSS_PLATFORM_URL_1), + initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1), onWebViewCreated: (controller) { controllerCompleter.complete(controller); }, - initialOptions: InAppWebViewGroupOptions( - crossPlatform: InAppWebViewOptions( - clearCache: true, - )), + initialSettings: InAppWebViewSettings( + clearCache: true, + ), onLoadStop: (controller, url) { pageLoaded.complete(url!.toString()); }, @@ -42,13 +41,11 @@ void setGetDelete() { final url = Uri.parse(await pageLoaded.future); - await cookieManager.setCookie( - url: url, name: "myCookie", value: "myValue"); + await cookieManager.setCookie(url: url, name: "myCookie", value: "myValue"); List cookies = await cookieManager.getCookies(url: url); expect(cookies, isNotEmpty); - Cookie? cookie = - await cookieManager.getCookie(url: url, name: "myCookie"); + Cookie? cookie = await cookieManager.getCookie(url: url, name: "myCookie"); expect(cookie?.value.toString(), "myValue"); await cookieManager.deleteCookie(url: url, name: "myCookie"); diff --git a/example/integration_test/headless_in_app_webview/custom_size.dart b/example/integration_test/headless_in_app_webview/custom_size.dart index ad0950eb..566fcc00 100644 --- a/example/integration_test/headless_in_app_webview/custom_size.dart +++ b/example/integration_test/headless_in_app_webview/custom_size.dart @@ -8,19 +8,19 @@ import 'package:flutter_test/flutter_test.dart'; import '../constants.dart'; void customSize() { - final shouldSkip = !kIsWeb || - ![ - TargetPlatform.android, - TargetPlatform.iOS, - TargetPlatform.macOS, - ].contains(defaultTargetPlatform); + final shouldSkip = kIsWeb + ? false + : ![ + TargetPlatform.android, + TargetPlatform.iOS, + TargetPlatform.macOS, + ].contains(defaultTargetPlatform); test('set and get custom size', () async { final Completer controllerCompleter = Completer(); var headlessWebView = new HeadlessInAppWebView( - initialUrlRequest: - URLRequest(url: TEST_CROSS_PLATFORM_URL_1), + initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1), initialSize: Size(600, 800), onWebViewCreated: (controller) { controllerCompleter.complete(controller); diff --git a/example/integration_test/headless_in_app_webview/run_and_dispose.dart b/example/integration_test/headless_in_app_webview/run_and_dispose.dart index c7fc01d2..0507be32 100644 --- a/example/integration_test/headless_in_app_webview/run_and_dispose.dart +++ b/example/integration_test/headless_in_app_webview/run_and_dispose.dart @@ -7,7 +7,7 @@ import 'package:flutter_test/flutter_test.dart'; import '../constants.dart'; void runAndDispose() { - final shouldSkip = !kIsWeb || + final shouldSkip = kIsWeb ? false : ![ TargetPlatform.android, TargetPlatform.iOS, diff --git a/example/integration_test/headless_in_app_webview/set_get_settings.dart b/example/integration_test/headless_in_app_webview/set_get_settings.dart index 3182f944..866f2f57 100644 --- a/example/integration_test/headless_in_app_webview/set_get_settings.dart +++ b/example/integration_test/headless_in_app_webview/set_get_settings.dart @@ -7,20 +7,20 @@ import 'package:flutter_test/flutter_test.dart'; import '../constants.dart'; void setGetSettings() { - final shouldSkip = !kIsWeb || - ![ - TargetPlatform.android, - TargetPlatform.iOS, - TargetPlatform.macOS, - ].contains(defaultTargetPlatform); + final shouldSkip = kIsWeb + ? false + : ![ + TargetPlatform.android, + TargetPlatform.iOS, + TargetPlatform.macOS, + ].contains(defaultTargetPlatform); test('set/get settings', () async { final Completer controllerCompleter = Completer(); final Completer pageLoaded = Completer(); var headlessWebView = new HeadlessInAppWebView( - initialUrlRequest: - URLRequest(url: TEST_CROSS_PLATFORM_URL_1), + initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1), initialSettings: InAppWebViewSettings(javaScriptEnabled: false), onWebViewCreated: (controller) { controllerCompleter.complete(controller); diff --git a/example/integration_test/in_app_browser/open_data_and_close.dart b/example/integration_test/in_app_browser/open_data_and_close.dart index 53d1968b..0fa26060 100644 --- a/example/integration_test/in_app_browser/open_data_and_close.dart +++ b/example/integration_test/in_app_browser/open_data_and_close.dart @@ -7,12 +7,13 @@ import '../constants.dart'; import '../util.dart'; void openDataAndClose() { - final shouldSkip = kIsWeb || - ![ - TargetPlatform.android, - TargetPlatform.iOS, - TargetPlatform.macOS, - ].contains(defaultTargetPlatform); + final shouldSkip = kIsWeb + ? true + : ![ + TargetPlatform.android, + TargetPlatform.iOS, + TargetPlatform.macOS, + ].contains(defaultTargetPlatform); test('open data and close', () async { var inAppBrowser = new MyInAppBrowser(); @@ -45,8 +46,7 @@ void openDataAndClose() { expect(inAppBrowser.isOpened(), true); expect(() async { await inAppBrowser.openUrlRequest( - urlRequest: - URLRequest(url: TEST_URL_1)); + urlRequest: URLRequest(url: TEST_URL_1)); }, throwsA(isInstanceOf())); await inAppBrowser.firstPageLoaded.future; diff --git a/example/integration_test/in_app_browser/open_file_and_close.dart b/example/integration_test/in_app_browser/open_file_and_close.dart index d455caa7..92da4c7b 100644 --- a/example/integration_test/in_app_browser/open_file_and_close.dart +++ b/example/integration_test/in_app_browser/open_file_and_close.dart @@ -7,12 +7,13 @@ import '../constants.dart'; import '../util.dart'; void openFileAndClose() { - final shouldSkip = kIsWeb || - ![ - TargetPlatform.android, - TargetPlatform.iOS, - TargetPlatform.macOS, - ].contains(defaultTargetPlatform); + final shouldSkip = kIsWeb + ? true + : ![ + TargetPlatform.android, + TargetPlatform.iOS, + TargetPlatform.macOS, + ].contains(defaultTargetPlatform); test('open file and close', () async { var inAppBrowser = new MyInAppBrowser(); @@ -27,8 +28,7 @@ void openFileAndClose() { expect(inAppBrowser.isOpened(), true); expect(() async { await inAppBrowser.openUrlRequest( - urlRequest: - URLRequest(url: TEST_URL_1)); + urlRequest: URLRequest(url: TEST_URL_1)); }, throwsA(isInstanceOf())); await inAppBrowser.firstPageLoaded.future; diff --git a/example/integration_test/in_app_browser/open_url_and_close.dart b/example/integration_test/in_app_browser/open_url_and_close.dart index add857f6..8f0659e5 100644 --- a/example/integration_test/in_app_browser/open_url_and_close.dart +++ b/example/integration_test/in_app_browser/open_url_and_close.dart @@ -7,12 +7,13 @@ import '../constants.dart'; import '../util.dart'; void openUrlAndClose() { - final shouldSkip = kIsWeb || - ![ - TargetPlatform.android, - TargetPlatform.iOS, - TargetPlatform.macOS, - ].contains(defaultTargetPlatform); + final shouldSkip = kIsWeb + ? true + : ![ + TargetPlatform.android, + TargetPlatform.iOS, + TargetPlatform.macOS, + ].contains(defaultTargetPlatform); test('open url and close', () async { var inAppBrowser = new MyInAppBrowser(); @@ -21,8 +22,7 @@ void openUrlAndClose() { await inAppBrowser.show(); }, throwsA(isInstanceOf())); - await inAppBrowser.openUrlRequest( - urlRequest: URLRequest(url: TEST_URL_1)); + await inAppBrowser.openUrlRequest(urlRequest: URLRequest(url: TEST_URL_1)); await inAppBrowser.browserCreated.future; expect(inAppBrowser.isOpened(), true); expect(() async { diff --git a/example/integration_test/in_app_browser/set_get_settings.dart b/example/integration_test/in_app_browser/set_get_settings.dart index 66741fac..82c824a3 100644 --- a/example/integration_test/in_app_browser/set_get_settings.dart +++ b/example/integration_test/in_app_browser/set_get_settings.dart @@ -6,12 +6,13 @@ import '../constants.dart'; import '../util.dart'; void setGetSettings() { - final shouldSkip = kIsWeb || - ![ - TargetPlatform.android, - TargetPlatform.iOS, - TargetPlatform.macOS, - ].contains(defaultTargetPlatform); + final shouldSkip = kIsWeb + ? true + : ![ + TargetPlatform.android, + TargetPlatform.iOS, + TargetPlatform.macOS, + ].contains(defaultTargetPlatform); test('set/get settings', () async { var inAppBrowser = new MyInAppBrowser(); diff --git a/example/integration_test/in_app_localhost_server/load_asset_file.dart b/example/integration_test/in_app_localhost_server/load_asset_file.dart index 5a834847..fe5ffa64 100644 --- a/example/integration_test/in_app_localhost_server/load_asset_file.dart +++ b/example/integration_test/in_app_localhost_server/load_asset_file.dart @@ -6,12 +6,13 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:flutter_test/flutter_test.dart'; void loadAssetFile(InAppLocalhostServer localhostServer) { - final shouldSkip = kIsWeb || - ![ - TargetPlatform.android, - TargetPlatform.iOS, - TargetPlatform.macOS, - ].contains(defaultTargetPlatform); + final shouldSkip = kIsWeb + ? true + : ![ + TargetPlatform.android, + TargetPlatform.iOS, + TargetPlatform.macOS, + ].contains(defaultTargetPlatform); testWidgets('load asset file', (WidgetTester tester) async { expect(localhostServer.isRunning(), true); @@ -30,8 +31,7 @@ void loadAssetFile(InAppLocalhostServer localhostServer) { ), ), ); - final InAppWebViewController controller = - await controllerCompleter.future; + final InAppWebViewController controller = await controllerCompleter.future; final String? currentUrl = (await controller.getUrl())?.toString(); expect(currentUrl, 'http://localhost:8080/test_assets/index.html'); }, skip: shouldSkip); diff --git a/example/integration_test/in_app_webview/on_permission_request.dart b/example/integration_test/in_app_webview/on_permission_request.dart index e9520d54..5fe1c7f0 100644 --- a/example/integration_test/in_app_webview/on_permission_request.dart +++ b/example/integration_test/in_app_webview/on_permission_request.dart @@ -27,7 +27,7 @@ void onPermissionRequest() { final Completer controllerCompleter = Completer(); final Completer pageLoaded = Completer(); final Completer> onPermissionRequestCompleter = - Completer>(); + Completer>(); await tester.pumpWidget( Directionality( @@ -44,6 +44,8 @@ void onPermissionRequest() { onPermissionRequest: (controller, PermissionRequest permissionRequest) async { onPermissionRequestCompleter.complete(permissionRequest.resources); + return PermissionResponse(resources: permissionRequest.resources, + action: PermissionResponseAction.GRANT); }, ), ), @@ -53,8 +55,9 @@ void onPermissionRequest() { await pageLoaded.future; await controller.evaluateJavascript( source: "document.querySelector('#camera').click();"); + await tester.pump(); final List resources = - await onPermissionRequestCompleter.future; + await onPermissionRequestCompleter.future; expect(listEquals(resources, expectedValue), true); }, skip: shouldSkip); diff --git a/example/integration_test/in_app_webview/on_print.dart b/example/integration_test/in_app_webview/on_print.dart index c4e19d36..71bf71ed 100644 --- a/example/integration_test/in_app_webview/on_print.dart +++ b/example/integration_test/in_app_webview/on_print.dart @@ -34,6 +34,7 @@ void onPrint() { ), ), ); + await tester.pump(); final String printUrl = await onPrintCompleter.future; expect(printUrl, url.toString()); }, skip: shouldSkip); diff --git a/example/integration_test/in_app_webview/print_current_page.dart b/example/integration_test/in_app_webview/print_current_page.dart index db200416..8f88e20f 100644 --- a/example/integration_test/in_app_webview/print_current_page.dart +++ b/example/integration_test/in_app_webview/print_current_page.dart @@ -41,7 +41,7 @@ void printCurrentPage() { final InAppWebViewController controller = await controllerCompleter.future; await pageLoaded.future; - + await tester.pump(); await expectLater(controller.printCurrentPage(), completes); }, skip: shouldSkip); } diff --git a/example/integration_test/in_app_webview/take_screenshot.dart b/example/integration_test/in_app_webview/take_screenshot.dart index b8b74874..6a5071a7 100644 --- a/example/integration_test/in_app_webview/take_screenshot.dart +++ b/example/integration_test/in_app_webview/take_screenshot.dart @@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart'; import '../constants.dart'; void takeScreenshot() { - final shouldSkip = kIsWeb || - ![ - TargetPlatform.android, - TargetPlatform.iOS, - TargetPlatform.macOS, - ].contains(defaultTargetPlatform); + final shouldSkip = kIsWeb + ? true + : ![ + TargetPlatform.android, + TargetPlatform.iOS, + TargetPlatform.macOS, + ].contains(defaultTargetPlatform); testWidgets('takeScreenshot', (WidgetTester tester) async { final Completer controllerCompleter = Completer(); @@ -24,8 +25,7 @@ void takeScreenshot() { textDirection: TextDirection.ltr, child: InAppWebView( key: GlobalKey(), - initialUrlRequest: - URLRequest(url: TEST_CROSS_PLATFORM_URL_1), + initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1), onWebViewCreated: (controller) { controllerCompleter.complete(controller); }, @@ -36,8 +36,7 @@ void takeScreenshot() { ), ); - final InAppWebViewController controller = - await controllerCompleter.future; + final InAppWebViewController controller = await controllerCompleter.future; await pageLoaded.future; var screenshotConfiguration = ScreenshotConfiguration( diff --git a/example/integration_test/in_app_webview/video_playback_policy.dart b/example/integration_test/in_app_webview/video_playback_policy.dart index d35ab163..4cb7f98c 100644 --- a/example/integration_test/in_app_webview/video_playback_policy.dart +++ b/example/integration_test/in_app_webview/video_playback_policy.dart @@ -190,6 +190,9 @@ void videoPlaybackPolicy() { ); await pageLoaded.future; + + await tester.pump(); + await expectLater(onEnterFullscreenCompleter.future, completes); }); @@ -228,6 +231,7 @@ void videoPlaybackPolicy() { await pageLoaded.future; await Future.delayed(Duration(seconds: 2)); + await tester.pump(); await controller.evaluateJavascript(source: "exitFullscreen();"); await expectLater(onExitFullscreenCompleter.future, completes); diff --git a/example/integration_test/in_app_webview/web_history.dart b/example/integration_test/in_app_webview/web_history.dart index 629fb2cd..b4283631 100644 --- a/example/integration_test/in_app_webview/web_history.dart +++ b/example/integration_test/in_app_webview/web_history.dart @@ -25,8 +25,6 @@ void webHistory() { testWidgets('get history list and go back/forward', (WidgetTester tester) async { final Completer controllerCompleter = Completer(); - final StreamController pageLoads = - StreamController.broadcast(); await tester.pumpWidget( Directionality( @@ -37,8 +35,8 @@ void webHistory() { onWebViewCreated: (controller) { controllerCompleter.complete(controller); }, - onLoadStop: (controller, url) { - pageLoads.add(url!.toString()); + onLoadStart: (controller, url) { + // pageLoads.add(url!.toString()); }, ), ), @@ -46,7 +44,8 @@ void webHistory() { final InAppWebViewController controller = await controllerCompleter.future; - var url = await pageLoads.stream.first; + await Future.delayed(Duration(seconds: 1)); + var url = (await controller.getUrl()).toString(); var webHistory = await controller.getCopyBackForwardList(); expect(url, TEST_CROSS_PLATFORM_URL_1.toString()); expect(webHistory!.currentIndex, 0); @@ -55,7 +54,8 @@ void webHistory() { await controller.loadUrl( urlRequest: URLRequest(url: TEST_URL_1)); - url = await pageLoads.stream.first; + await Future.delayed(Duration(seconds: 1)); + url = (await controller.getUrl()).toString(); webHistory = await controller.getCopyBackForwardList(); expect(url, TEST_URL_1.toString()); expect(await controller.canGoBack(), true); @@ -69,7 +69,8 @@ void webHistory() { await Future.delayed(Duration(seconds: 1)); await controller.goBack(); - url = await pageLoads.stream.first; + await Future.delayed(Duration(seconds: 1)); + url = (await controller.getUrl()).toString(); webHistory = await controller.getCopyBackForwardList(); expect(url, TEST_CROSS_PLATFORM_URL_1.toString()); expect(await controller.canGoBack(), false); @@ -83,7 +84,8 @@ void webHistory() { await Future.delayed(Duration(seconds: 1)); await controller.goForward(); - url = await pageLoads.stream.first; + await Future.delayed(Duration(seconds: 1)); + url = (await controller.getUrl()).toString(); webHistory = await controller.getCopyBackForwardList(); expect(url, TEST_URL_1.toString()); expect(await controller.canGoBack(), true); @@ -97,7 +99,8 @@ void webHistory() { await Future.delayed(Duration(seconds: 1)); await controller.goTo(historyItem: webHistory.list![0]); - url = await pageLoads.stream.first; + await Future.delayed(Duration(seconds: 1)); + url = (await controller.getUrl()).toString(); webHistory = await controller.getCopyBackForwardList(); expect(url, TEST_CROSS_PLATFORM_URL_1.toString()); expect(await controller.canGoBack(), false); @@ -108,8 +111,6 @@ void webHistory() { expect(webHistory.list!.length, 2); expect(webHistory.list![0].url.toString(), TEST_CROSS_PLATFORM_URL_1.toString()); expect(webHistory.list![1].url.toString(), TEST_URL_1.toString()); - - pageLoads.close(); }, skip: shouldSkipTest1); final shouldSkipTest2 = !kIsWeb; diff --git a/example/integration_test/in_app_webview/web_message.dart b/example/integration_test/in_app_webview/web_message.dart index 1edbcce2..3cd54e30 100644 --- a/example/integration_test/in_app_webview/web_message.dart +++ b/example/integration_test/in_app_webview/web_message.dart @@ -98,19 +98,23 @@ void webMessage() { allowedOriginRules: Set.from(["https://*.example.com"]), onPostMessage: (message, sourceOrigin, isMainFrame, replyProxy) { - assert( - sourceOrigin.toString() == TEST_URL_EXAMPLE.toString()); - assert(isMainFrame); - - replyProxy.postMessage(message! + " and back"); + if (isMainFrame && + (sourceOrigin.toString() + '/') == + TEST_URL_EXAMPLE.toString()) { + replyProxy.postMessage(message! + " and back"); + } else { + replyProxy.postMessage("Nope"); + } }, )); controllerCompleter.complete(controller); }, onConsoleMessage: (controller, consoleMessage) { + print(consoleMessage); webMessageCompleter.complete(consoleMessage.message); }, onLoadStop: (controller, url) async { + print(url); if (url.toString() == TEST_URL_EXAMPLE.toString()) { pageLoaded.complete(); } diff --git a/example/integration_test/in_app_webview/webview_windows.dart b/example/integration_test/in_app_webview/webview_windows.dart index 7f778bc1..9c267117 100644 --- a/example/integration_test/in_app_webview/webview_windows.dart +++ b/example/integration_test/in_app_webview/webview_windows.dart @@ -207,6 +207,8 @@ void webViewWindows() { final InAppWebViewController controller = await controllerCompleter.future; + await tester.pump(); + await controller.evaluateJavascript( source: 'window.open("$TEST_URL_1");'); await pageLoads.stream.first; diff --git a/example/integration_test/service_worker/set_service_worker_client.dart b/example/integration_test/service_worker/set_service_worker_client.dart index c880fd80..f17a57d8 100644 --- a/example/integration_test/service_worker/set_service_worker_client.dart +++ b/example/integration_test/service_worker/set_service_worker_client.dart @@ -8,10 +8,11 @@ import 'package:flutter_test/flutter_test.dart'; import '../constants.dart'; void setServiceWorkerClient() { - final shouldSkip = kIsWeb || - ![ - TargetPlatform.android, - ].contains(defaultTargetPlatform); + final shouldSkip = kIsWeb + ? true + : ![ + TargetPlatform.android, + ].contains(defaultTargetPlatform); testWidgets('setServiceWorkerClient to null', (WidgetTester tester) async { final Completer pageLoaded = Completer(); @@ -33,8 +34,7 @@ void setServiceWorkerClient() { textDirection: TextDirection.ltr, child: InAppWebView( key: GlobalKey(), - initialUrlRequest: - URLRequest(url: TEST_SERVICE_WORKER_URL), + initialUrlRequest: URLRequest(url: TEST_SERVICE_WORKER_URL), onLoadStop: (controller, url) { pageLoaded.complete(url!.toString()); }, diff --git a/example/integration_test/service_worker/should_intercept_request.dart b/example/integration_test/service_worker/should_intercept_request.dart index 915c1826..c501381b 100644 --- a/example/integration_test/service_worker/should_intercept_request.dart +++ b/example/integration_test/service_worker/should_intercept_request.dart @@ -8,10 +8,11 @@ import 'package:flutter_test/flutter_test.dart'; import '../constants.dart'; void shouldInterceptRequest() { - final shouldSkip = kIsWeb || - ![ - TargetPlatform.android, - ].contains(defaultTargetPlatform); + final shouldSkip = kIsWeb + ? true + : ![ + TargetPlatform.android, + ].contains(defaultTargetPlatform); testWidgets('shouldInterceptRequest', (WidgetTester tester) async { final Completer completer = Completer(); diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 7789db22..9ef5bfa2 100755 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -56,29 +56,14 @@ flutter: uses-material-design: true assets: - - assets/index.html - - assets/page-1.html - - assets/page-2.html + - assets/ - assets/js/ - assets/css/ - assets/images/ - - assets/favicon.ico - - assets/sample_audio.ogg - - assets/sample_video.mp4 - - test_assets/certificate.pfx - - test_assets/in_app_webview_initial_file_test.html - - test_assets/in_app_webview_on_load_resource_test.html - - test_assets/in_app_webview_javascript_handler_test.html - - test_assets/in_app_webview_on_load_resource_custom_scheme_test.html - - test_assets/in_app_webview_on_console_message_test.html - - test_assets/in_app_webview_on_create_window_test.html - - test_assets/in_app_webview_on_js_dialog_test.html + - test_assets/ - test_assets/js/ - test_assets/css/ - test_assets/images/ - - test_assets/favicon.ico - - test_assets/sample_audio.ogg - - test_assets/sample_video.mp4 # To add assets to your application, add an assets section, like this: # assets: diff --git a/lib/src/in_app_webview/in_app_webview.dart b/lib/src/in_app_webview/in_app_webview.dart index 85953a2b..befe944f 100755 --- a/lib/src/in_app_webview/in_app_webview.dart +++ b/lib/src/in_app_webview/in_app_webview.dart @@ -529,7 +529,7 @@ class InAppWebView extends StatefulWidget implements WebView { } class _InAppWebViewState extends State { - late InAppWebViewController _controller; + InAppWebViewController? _controller; @override Widget build(BuildContext context) { @@ -663,18 +663,19 @@ class _InAppWebViewState extends State { @override void dispose() { - dynamic viewId = _controller.getViewId(); - if (kIsWeb && WebPlatformManager.webViews.containsKey(viewId)) { + dynamic viewId = _controller?.getViewId(); + if (viewId != null && kIsWeb && WebPlatformManager.webViews.containsKey(viewId)) { WebPlatformManager.webViews.remove(viewId); } super.dispose(); + _controller = null; } void _onPlatformViewCreated(int id) { _controller = InAppWebViewController(id, widget); widget.pullToRefreshController?.initMethodChannel(id); if (widget.onWebViewCreated != null) { - widget.onWebViewCreated!(_controller); + widget.onWebViewCreated!(_controller!); } } } diff --git a/scripts/test.sh b/scripts/test.sh index a287a45b..51f1ec88 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -10,10 +10,22 @@ function error() { # on macOS local IP can be found using something like $(ipconfig getifaddr en0) # on linux local IP can be found using something like $(ifconfig en0 | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}') or $(ip route get 1 | awk '{print $NF;exit}') export NODE_SERVER_IP=$1 +if [ -z "$1" ]; then + export NODE_SERVER_IP=$(ipconfig getifaddr en0) +fi + +echo Node Server IP: $NODE_SERVER_IP + +if [ -z "$NODE_SERVER_IP" ]; then + echo No Server IP found + jobs -p | xargs kill + exit 1 +fi + PLATFORM=$2 FAILED=0 -if [ $PLATFORM = "web" ]; then +if [ ! -z "$2" ] && [ $PLATFORM = "web" ]; then $PROJECT_DIR/tool/chromedriver --port=4444 & fi @@ -26,7 +38,7 @@ flutter --version flutter clean cd $PROJECT_DIR/example flutter clean -if [ $PLATFORM = "web" ]; then +if [ ! -z "$2" ] && [ $PLATFORM = "web" ]; then flutter driver --driver=test_driver/integration_test.dart --target=integration_test/webview_flutter_test.dart --device-id=chrome else flutter driver --driver=test_driver/integration_test.dart --target=integration_test/webview_flutter_test.dart