updated tests

This commit is contained in:
Lorenzo Pichilli 2022-04-29 02:07:01 +02:00
parent f45996e187
commit a8593f557e
28 changed files with 181 additions and 169 deletions

View File

@ -7,15 +7,16 @@ import '../constants.dart';
import '../util.dart'; import '../util.dart';
void customActionButton() { void customActionButton() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
TargetPlatform.android, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].contains(defaultTargetPlatform);
test('add custom action button', () async { test('add custom action button', () async {
var chromeSafariBrowser = new MyChromeSafariBrowser(); var chromeSafariBrowser = new MyChromeSafariBrowser();
var actionButtonIcon = var actionButtonIcon =
await rootBundle.load('test_assets/images/flutter-logo.png'); await rootBundle.load('test_assets/images/flutter-logo.png');
chromeSafariBrowser.setActionButton(ChromeSafariBrowserActionButton( chromeSafariBrowser.setActionButton(ChromeSafariBrowserActionButton(
id: 1, id: 1,
description: 'Action Button description', description: 'Action Button description',
@ -25,16 +26,14 @@ void customActionButton() {
})); }));
expect(chromeSafariBrowser.isOpened(), false); expect(chromeSafariBrowser.isOpened(), false);
await chromeSafariBrowser.open( await chromeSafariBrowser.open(url: TEST_URL_1);
url: TEST_URL_1);
await chromeSafariBrowser.browserCreated.future; await chromeSafariBrowser.browserCreated.future;
expect(chromeSafariBrowser.isOpened(), true); expect(chromeSafariBrowser.isOpened(), true);
expect(() async { expect(() async {
await chromeSafariBrowser.open(url: TEST_CROSS_PLATFORM_URL_1); await chromeSafariBrowser.open(url: TEST_CROSS_PLATFORM_URL_1);
}, throwsA(isInstanceOf<ChromeSafariBrowserAlreadyOpenedException>())); }, throwsA(isInstanceOf<ChromeSafariBrowserAlreadyOpenedException>()));
await expectLater( await expectLater(chromeSafariBrowser.firstPageLoaded.future, completes);
chromeSafariBrowser.firstPageLoaded.future, completes);
await chromeSafariBrowser.close(); await chromeSafariBrowser.close();
await chromeSafariBrowser.browserClosed.future; await chromeSafariBrowser.browserClosed.future;
expect(chromeSafariBrowser.isOpened(), false); expect(chromeSafariBrowser.isOpened(), false);

View File

@ -6,12 +6,13 @@ import '../constants.dart';
import '../util.dart'; import '../util.dart';
void customMenuItem() { void customMenuItem() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
test('add custom menu item', () async { test('add custom menu item', () async {
var chromeSafariBrowser = new MyChromeSafariBrowser(); var chromeSafariBrowser = new MyChromeSafariBrowser();
@ -23,8 +24,7 @@ void customMenuItem() {
})); }));
expect(chromeSafariBrowser.isOpened(), false); expect(chromeSafariBrowser.isOpened(), false);
await chromeSafariBrowser.open( await chromeSafariBrowser.open(url: TEST_URL_1);
url: TEST_URL_1);
await chromeSafariBrowser.browserCreated.future; await chromeSafariBrowser.browserCreated.future;
expect(chromeSafariBrowser.isOpened(), true); expect(chromeSafariBrowser.isOpened(), true);
expect(() async { expect(() async {

View File

@ -6,12 +6,13 @@ import '../constants.dart';
import '../util.dart'; import '../util.dart';
void customTabs() { void customTabs() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
TargetPlatform.android, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].contains(defaultTargetPlatform);
group('Custom Tabs', () async { group('Custom Tabs', () {
test('single instance', () async { test('single instance', () async {
var chromeSafariBrowser = new MyChromeSafariBrowser(); var chromeSafariBrowser = new MyChromeSafariBrowser();
expect(chromeSafariBrowser.isOpened(), false); expect(chromeSafariBrowser.isOpened(), false);

View File

@ -6,19 +6,19 @@ import '../constants.dart';
import '../util.dart'; import '../util.dart';
void openAndClose() { void openAndClose() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
test('open and close', () async { test('open and close', () async {
var chromeSafariBrowser = new MyChromeSafariBrowser(); var chromeSafariBrowser = new MyChromeSafariBrowser();
expect(chromeSafariBrowser.isOpened(), false); expect(chromeSafariBrowser.isOpened(), false);
await chromeSafariBrowser.open( await chromeSafariBrowser.open(url: TEST_URL_1);
url: TEST_URL_1);
await chromeSafariBrowser.browserCreated.future; await chromeSafariBrowser.browserCreated.future;
expect(chromeSafariBrowser.isOpened(), true); expect(chromeSafariBrowser.isOpened(), true);
expect(() async { expect(() async {

View File

@ -6,12 +6,13 @@ import '../constants.dart';
import '../util.dart'; import '../util.dart';
void trustedWebActivity() { void trustedWebActivity() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
TargetPlatform.android, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].contains(defaultTargetPlatform);
group('Trusted Web Activity', () async { group('Trusted Web Activity', () {
test('basic', () async { test('basic', () async {
var chromeSafariBrowser = new MyChromeSafariBrowser(); var chromeSafariBrowser = new MyChromeSafariBrowser();
expect(chromeSafariBrowser.isOpened(), false); expect(chromeSafariBrowser.isOpened(), false);

View File

@ -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_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_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_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_CHROME_SAFE_BROWSING_MALWARE = Uri.parse('chrome://safe-browsing/match?type=malware');
final TEST_PERMISSION_SITE = Uri.parse('https://permission.site/'); final TEST_PERMISSION_SITE = Uri.parse('https://permission.site/');
final TEST_SERVICE_WORKER_URL = Uri.parse('https://mdn.github.io/sw-test/'); final TEST_SERVICE_WORKER_URL = Uri.parse('https://mdn.github.io/sw-test/');

View File

@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void setGetDelete() { void setGetDelete() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('set, get, delete', (WidgetTester tester) async { testWidgets('set, get, delete', (WidgetTester tester) async {
CookieManager cookieManager = CookieManager.instance(); CookieManager cookieManager = CookieManager.instance();
@ -24,15 +25,13 @@ void setGetDelete() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
initialOptions: InAppWebViewGroupOptions( initialSettings: InAppWebViewSettings(
crossPlatform: InAppWebViewOptions( clearCache: true,
clearCache: true, ),
)),
onLoadStop: (controller, url) { onLoadStop: (controller, url) {
pageLoaded.complete(url!.toString()); pageLoaded.complete(url!.toString());
}, },
@ -42,13 +41,11 @@ void setGetDelete() {
final url = Uri.parse(await pageLoaded.future); final url = Uri.parse(await pageLoaded.future);
await cookieManager.setCookie( await cookieManager.setCookie(url: url, name: "myCookie", value: "myValue");
url: url, name: "myCookie", value: "myValue");
List<Cookie> cookies = await cookieManager.getCookies(url: url); List<Cookie> cookies = await cookieManager.getCookies(url: url);
expect(cookies, isNotEmpty); expect(cookies, isNotEmpty);
Cookie? cookie = Cookie? cookie = await cookieManager.getCookie(url: url, name: "myCookie");
await cookieManager.getCookie(url: url, name: "myCookie");
expect(cookie?.value.toString(), "myValue"); expect(cookie?.value.toString(), "myValue");
await cookieManager.deleteCookie(url: url, name: "myCookie"); await cookieManager.deleteCookie(url: url, name: "myCookie");

View File

@ -8,19 +8,19 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void customSize() { void customSize() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
test('set and get custom size', () async { test('set and get custom size', () async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
var headlessWebView = new HeadlessInAppWebView( var headlessWebView = new HeadlessInAppWebView(
initialUrlRequest: initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
initialSize: Size(600, 800), initialSize: Size(600, 800),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);

View File

@ -7,7 +7,7 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void runAndDispose() { void runAndDispose() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb ? false :
![ ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,

View File

@ -7,20 +7,20 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void setGetSettings() { void setGetSettings() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
test('set/get settings', () async { test('set/get settings', () async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>(); final Completer<void> pageLoaded = Completer<void>();
var headlessWebView = new HeadlessInAppWebView( var headlessWebView = new HeadlessInAppWebView(
initialUrlRequest: initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
initialSettings: InAppWebViewSettings(javaScriptEnabled: false), initialSettings: InAppWebViewSettings(javaScriptEnabled: false),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);

View File

@ -7,12 +7,13 @@ import '../constants.dart';
import '../util.dart'; import '../util.dart';
void openDataAndClose() { void openDataAndClose() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
test('open data and close', () async { test('open data and close', () async {
var inAppBrowser = new MyInAppBrowser(); var inAppBrowser = new MyInAppBrowser();
@ -45,8 +46,7 @@ void openDataAndClose() {
expect(inAppBrowser.isOpened(), true); expect(inAppBrowser.isOpened(), true);
expect(() async { expect(() async {
await inAppBrowser.openUrlRequest( await inAppBrowser.openUrlRequest(
urlRequest: urlRequest: URLRequest(url: TEST_URL_1));
URLRequest(url: TEST_URL_1));
}, throwsA(isInstanceOf<InAppBrowserAlreadyOpenedException>())); }, throwsA(isInstanceOf<InAppBrowserAlreadyOpenedException>()));
await inAppBrowser.firstPageLoaded.future; await inAppBrowser.firstPageLoaded.future;

View File

@ -7,12 +7,13 @@ import '../constants.dart';
import '../util.dart'; import '../util.dart';
void openFileAndClose() { void openFileAndClose() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
test('open file and close', () async { test('open file and close', () async {
var inAppBrowser = new MyInAppBrowser(); var inAppBrowser = new MyInAppBrowser();
@ -27,8 +28,7 @@ void openFileAndClose() {
expect(inAppBrowser.isOpened(), true); expect(inAppBrowser.isOpened(), true);
expect(() async { expect(() async {
await inAppBrowser.openUrlRequest( await inAppBrowser.openUrlRequest(
urlRequest: urlRequest: URLRequest(url: TEST_URL_1));
URLRequest(url: TEST_URL_1));
}, throwsA(isInstanceOf<InAppBrowserAlreadyOpenedException>())); }, throwsA(isInstanceOf<InAppBrowserAlreadyOpenedException>()));
await inAppBrowser.firstPageLoaded.future; await inAppBrowser.firstPageLoaded.future;

View File

@ -7,12 +7,13 @@ import '../constants.dart';
import '../util.dart'; import '../util.dart';
void openUrlAndClose() { void openUrlAndClose() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
test('open url and close', () async { test('open url and close', () async {
var inAppBrowser = new MyInAppBrowser(); var inAppBrowser = new MyInAppBrowser();
@ -21,8 +22,7 @@ void openUrlAndClose() {
await inAppBrowser.show(); await inAppBrowser.show();
}, throwsA(isInstanceOf<InAppBrowserNotOpenedException>())); }, throwsA(isInstanceOf<InAppBrowserNotOpenedException>()));
await inAppBrowser.openUrlRequest( await inAppBrowser.openUrlRequest(urlRequest: URLRequest(url: TEST_URL_1));
urlRequest: URLRequest(url: TEST_URL_1));
await inAppBrowser.browserCreated.future; await inAppBrowser.browserCreated.future;
expect(inAppBrowser.isOpened(), true); expect(inAppBrowser.isOpened(), true);
expect(() async { expect(() async {

View File

@ -6,12 +6,13 @@ import '../constants.dart';
import '../util.dart'; import '../util.dart';
void setGetSettings() { void setGetSettings() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
test('set/get settings', () async { test('set/get settings', () async {
var inAppBrowser = new MyInAppBrowser(); var inAppBrowser = new MyInAppBrowser();

View File

@ -6,12 +6,13 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void loadAssetFile(InAppLocalhostServer localhostServer) { void loadAssetFile(InAppLocalhostServer localhostServer) {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('load asset file', (WidgetTester tester) async { testWidgets('load asset file', (WidgetTester tester) async {
expect(localhostServer.isRunning(), true); expect(localhostServer.isRunning(), true);
@ -30,8 +31,7 @@ void loadAssetFile(InAppLocalhostServer localhostServer) {
), ),
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
final String? currentUrl = (await controller.getUrl())?.toString(); final String? currentUrl = (await controller.getUrl())?.toString();
expect(currentUrl, 'http://localhost:8080/test_assets/index.html'); expect(currentUrl, 'http://localhost:8080/test_assets/index.html');
}, skip: shouldSkip); }, skip: shouldSkip);

View File

@ -27,7 +27,7 @@ void onPermissionRequest() {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>(); final Completer<void> pageLoaded = Completer<void>();
final Completer<List<PermissionResourceType>> onPermissionRequestCompleter = final Completer<List<PermissionResourceType>> onPermissionRequestCompleter =
Completer<List<PermissionResourceType>>(); Completer<List<PermissionResourceType>>();
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
@ -44,6 +44,8 @@ void onPermissionRequest() {
onPermissionRequest: onPermissionRequest:
(controller, PermissionRequest permissionRequest) async { (controller, PermissionRequest permissionRequest) async {
onPermissionRequestCompleter.complete(permissionRequest.resources); onPermissionRequestCompleter.complete(permissionRequest.resources);
return PermissionResponse(resources: permissionRequest.resources,
action: PermissionResponseAction.GRANT);
}, },
), ),
), ),
@ -53,8 +55,9 @@ void onPermissionRequest() {
await pageLoaded.future; await pageLoaded.future;
await controller.evaluateJavascript( await controller.evaluateJavascript(
source: "document.querySelector('#camera').click();"); source: "document.querySelector('#camera').click();");
await tester.pump();
final List<PermissionResourceType> resources = final List<PermissionResourceType> resources =
await onPermissionRequestCompleter.future; await onPermissionRequestCompleter.future;
expect(listEquals(resources, expectedValue), true); expect(listEquals(resources, expectedValue), true);
}, skip: shouldSkip); }, skip: shouldSkip);

View File

@ -34,6 +34,7 @@ void onPrint() {
), ),
), ),
); );
await tester.pump();
final String printUrl = await onPrintCompleter.future; final String printUrl = await onPrintCompleter.future;
expect(printUrl, url.toString()); expect(printUrl, url.toString());
}, skip: shouldSkip); }, skip: shouldSkip);

View File

@ -41,7 +41,7 @@ void printCurrentPage() {
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await tester.pump();
await expectLater(controller.printCurrentPage(), completes); await expectLater(controller.printCurrentPage(), completes);
}, skip: shouldSkip); }, skip: shouldSkip);
} }

View File

@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void takeScreenshot() { void takeScreenshot() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('takeScreenshot', (WidgetTester tester) async { testWidgets('takeScreenshot', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -24,8 +25,7 @@ void takeScreenshot() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -36,8 +36,7 @@ void takeScreenshot() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
var screenshotConfiguration = ScreenshotConfiguration( var screenshotConfiguration = ScreenshotConfiguration(

View File

@ -190,6 +190,9 @@ void videoPlaybackPolicy() {
); );
await pageLoaded.future; await pageLoaded.future;
await tester.pump();
await expectLater(onEnterFullscreenCompleter.future, completes); await expectLater(onEnterFullscreenCompleter.future, completes);
}); });
@ -228,6 +231,7 @@ void videoPlaybackPolicy() {
await pageLoaded.future; await pageLoaded.future;
await Future.delayed(Duration(seconds: 2)); await Future.delayed(Duration(seconds: 2));
await tester.pump();
await controller.evaluateJavascript(source: "exitFullscreen();"); await controller.evaluateJavascript(source: "exitFullscreen();");
await expectLater(onExitFullscreenCompleter.future, completes); await expectLater(onExitFullscreenCompleter.future, completes);

View File

@ -25,8 +25,6 @@ void webHistory() {
testWidgets('get history list and go back/forward', (WidgetTester tester) async { testWidgets('get history list and go back/forward', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
final StreamController<String> pageLoads =
StreamController<String>.broadcast();
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
@ -37,8 +35,8 @@ void webHistory() {
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
onLoadStop: (controller, url) { onLoadStart: (controller, url) {
pageLoads.add(url!.toString()); // pageLoads.add(url!.toString());
}, },
), ),
), ),
@ -46,7 +44,8 @@ void webHistory() {
final InAppWebViewController controller = await controllerCompleter.future; 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(); var webHistory = await controller.getCopyBackForwardList();
expect(url, TEST_CROSS_PLATFORM_URL_1.toString()); expect(url, TEST_CROSS_PLATFORM_URL_1.toString());
expect(webHistory!.currentIndex, 0); expect(webHistory!.currentIndex, 0);
@ -55,7 +54,8 @@ void webHistory() {
await controller.loadUrl( await controller.loadUrl(
urlRequest: URLRequest(url: TEST_URL_1)); 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(); webHistory = await controller.getCopyBackForwardList();
expect(url, TEST_URL_1.toString()); expect(url, TEST_URL_1.toString());
expect(await controller.canGoBack(), true); expect(await controller.canGoBack(), true);
@ -69,7 +69,8 @@ void webHistory() {
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));
await controller.goBack(); await controller.goBack();
url = await pageLoads.stream.first; await Future.delayed(Duration(seconds: 1));
url = (await controller.getUrl()).toString();
webHistory = await controller.getCopyBackForwardList(); webHistory = await controller.getCopyBackForwardList();
expect(url, TEST_CROSS_PLATFORM_URL_1.toString()); expect(url, TEST_CROSS_PLATFORM_URL_1.toString());
expect(await controller.canGoBack(), false); expect(await controller.canGoBack(), false);
@ -83,7 +84,8 @@ void webHistory() {
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));
await controller.goForward(); await controller.goForward();
url = await pageLoads.stream.first; await Future.delayed(Duration(seconds: 1));
url = (await controller.getUrl()).toString();
webHistory = await controller.getCopyBackForwardList(); webHistory = await controller.getCopyBackForwardList();
expect(url, TEST_URL_1.toString()); expect(url, TEST_URL_1.toString());
expect(await controller.canGoBack(), true); expect(await controller.canGoBack(), true);
@ -97,7 +99,8 @@ void webHistory() {
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));
await controller.goTo(historyItem: webHistory.list![0]); 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(); webHistory = await controller.getCopyBackForwardList();
expect(url, TEST_CROSS_PLATFORM_URL_1.toString()); expect(url, TEST_CROSS_PLATFORM_URL_1.toString());
expect(await controller.canGoBack(), false); expect(await controller.canGoBack(), false);
@ -108,8 +111,6 @@ void webHistory() {
expect(webHistory.list!.length, 2); expect(webHistory.list!.length, 2);
expect(webHistory.list![0].url.toString(), TEST_CROSS_PLATFORM_URL_1.toString()); expect(webHistory.list![0].url.toString(), TEST_CROSS_PLATFORM_URL_1.toString());
expect(webHistory.list![1].url.toString(), TEST_URL_1.toString()); expect(webHistory.list![1].url.toString(), TEST_URL_1.toString());
pageLoads.close();
}, skip: shouldSkipTest1); }, skip: shouldSkipTest1);
final shouldSkipTest2 = !kIsWeb; final shouldSkipTest2 = !kIsWeb;

View File

@ -98,19 +98,23 @@ void webMessage() {
allowedOriginRules: Set.from(["https://*.example.com"]), allowedOriginRules: Set.from(["https://*.example.com"]),
onPostMessage: onPostMessage:
(message, sourceOrigin, isMainFrame, replyProxy) { (message, sourceOrigin, isMainFrame, replyProxy) {
assert( if (isMainFrame &&
sourceOrigin.toString() == TEST_URL_EXAMPLE.toString()); (sourceOrigin.toString() + '/') ==
assert(isMainFrame); TEST_URL_EXAMPLE.toString()) {
replyProxy.postMessage(message! + " and back");
replyProxy.postMessage(message! + " and back"); } else {
replyProxy.postMessage("Nope");
}
}, },
)); ));
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
onConsoleMessage: (controller, consoleMessage) { onConsoleMessage: (controller, consoleMessage) {
print(consoleMessage);
webMessageCompleter.complete(consoleMessage.message); webMessageCompleter.complete(consoleMessage.message);
}, },
onLoadStop: (controller, url) async { onLoadStop: (controller, url) async {
print(url);
if (url.toString() == TEST_URL_EXAMPLE.toString()) { if (url.toString() == TEST_URL_EXAMPLE.toString()) {
pageLoaded.complete(); pageLoaded.complete();
} }

View File

@ -207,6 +207,8 @@ void webViewWindows() {
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await tester.pump();
await controller.evaluateJavascript( await controller.evaluateJavascript(
source: 'window.open("$TEST_URL_1");'); source: 'window.open("$TEST_URL_1");');
await pageLoads.stream.first; await pageLoads.stream.first;

View File

@ -8,10 +8,11 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void setServiceWorkerClient() { void setServiceWorkerClient() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
TargetPlatform.android, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].contains(defaultTargetPlatform);
testWidgets('setServiceWorkerClient to null', (WidgetTester tester) async { testWidgets('setServiceWorkerClient to null', (WidgetTester tester) async {
final Completer<String> pageLoaded = Completer<String>(); final Completer<String> pageLoaded = Completer<String>();
@ -33,8 +34,7 @@ void setServiceWorkerClient() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: TEST_SERVICE_WORKER_URL),
URLRequest(url: TEST_SERVICE_WORKER_URL),
onLoadStop: (controller, url) { onLoadStop: (controller, url) {
pageLoaded.complete(url!.toString()); pageLoaded.complete(url!.toString());
}, },

View File

@ -8,10 +8,11 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void shouldInterceptRequest() { void shouldInterceptRequest() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
TargetPlatform.android, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].contains(defaultTargetPlatform);
testWidgets('shouldInterceptRequest', (WidgetTester tester) async { testWidgets('shouldInterceptRequest', (WidgetTester tester) async {
final Completer completer = Completer(); final Completer completer = Completer();

View File

@ -56,29 +56,14 @@ flutter:
uses-material-design: true uses-material-design: true
assets: assets:
- assets/index.html - assets/
- assets/page-1.html
- assets/page-2.html
- assets/js/ - assets/js/
- assets/css/ - assets/css/
- assets/images/ - assets/images/
- assets/favicon.ico - test_assets/
- 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/js/ - test_assets/js/
- test_assets/css/ - test_assets/css/
- test_assets/images/ - 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: # To add assets to your application, add an assets section, like this:
# assets: # assets:

View File

@ -529,7 +529,7 @@ class InAppWebView extends StatefulWidget implements WebView {
} }
class _InAppWebViewState extends State<InAppWebView> { class _InAppWebViewState extends State<InAppWebView> {
late InAppWebViewController _controller; InAppWebViewController? _controller;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -663,18 +663,19 @@ class _InAppWebViewState extends State<InAppWebView> {
@override @override
void dispose() { void dispose() {
dynamic viewId = _controller.getViewId(); dynamic viewId = _controller?.getViewId();
if (kIsWeb && WebPlatformManager.webViews.containsKey(viewId)) { if (viewId != null && kIsWeb && WebPlatformManager.webViews.containsKey(viewId)) {
WebPlatformManager.webViews.remove(viewId); WebPlatformManager.webViews.remove(viewId);
} }
super.dispose(); super.dispose();
_controller = null;
} }
void _onPlatformViewCreated(int id) { void _onPlatformViewCreated(int id) {
_controller = InAppWebViewController(id, widget); _controller = InAppWebViewController(id, widget);
widget.pullToRefreshController?.initMethodChannel(id); widget.pullToRefreshController?.initMethodChannel(id);
if (widget.onWebViewCreated != null) { if (widget.onWebViewCreated != null) {
widget.onWebViewCreated!(_controller); widget.onWebViewCreated!(_controller!);
} }
} }
} }

View File

@ -10,10 +10,22 @@ function error() {
# on macOS local IP can be found using something like $(ipconfig getifaddr en0) # 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}') # 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 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 PLATFORM=$2
FAILED=0 FAILED=0
if [ $PLATFORM = "web" ]; then if [ ! -z "$2" ] && [ $PLATFORM = "web" ]; then
$PROJECT_DIR/tool/chromedriver --port=4444 & $PROJECT_DIR/tool/chromedriver --port=4444 &
fi fi
@ -26,7 +38,7 @@ flutter --version
flutter clean flutter clean
cd $PROJECT_DIR/example cd $PROJECT_DIR/example
flutter clean 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 flutter driver --driver=test_driver/integration_test.dart --target=integration_test/webview_flutter_test.dart --device-id=chrome
else else
flutter driver --driver=test_driver/integration_test.dart --target=integration_test/webview_flutter_test.dart flutter driver --driver=test_driver/integration_test.dart --target=integration_test/webview_flutter_test.dart