updated tests

This commit is contained in:
Lorenzo Pichilli 2022-04-29 13:39:28 +02:00
parent a8593f557e
commit 96259a782e
86 changed files with 967 additions and 964 deletions

View File

@ -6,8 +6,9 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void applePayAPI() { void applePayAPI() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);

View File

@ -8,10 +8,10 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void audioPlaybackPolicy() { void audioPlaybackPolicy() {
final shouldSkip = kIsWeb || ![ final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void clearCache() { void clearCache() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -24,8 +25,7 @@ void clearCache() {
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 clearCache() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await expectLater(controller.clearCache(), completes); await expectLater(controller.clearCache(), completes);
}, skip: shouldSkip); }, skip: shouldSkip);

View File

@ -1,17 +1,16 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void clearClientCertPreferences() { void clearClientCertPreferences() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
test('clearClientCertPreferences', () async { test('clearClientCertPreferences', () async {
await expectLater( await expectLater(
InAppWebViewController.clearClientCertPreferences(), InAppWebViewController.clearClientCertPreferences(), completes);
completes);
}, skip: shouldSkip); }, skip: shouldSkip);
} }

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void clearFocus() { void clearFocus() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -24,8 +25,7 @@ void clearFocus() {
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 clearFocus() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await expectLater(controller.clearFocus(), completes); await expectLater(controller.clearFocus(), completes);

View File

@ -8,14 +8,14 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void clearSslPreferences() { void clearSslPreferences() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
testWidgets('clearSslPreferences', (WidgetTester tester) async { testWidgets('clearSslPreferences', (WidgetTester tester) async {
final Completer controllerCompleter = final Completer controllerCompleter = Completer<InAppWebViewController>();
Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>(); final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget( await tester.pumpWidget(
@ -23,8 +23,7 @@ void clearSslPreferences() {
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);
}, },
@ -35,8 +34,7 @@ void clearSslPreferences() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await expectLater(controller.clearSslPreferences(), completes); await expectLater(controller.clearSslPreferences(), completes);
}, skip: shouldSkip); }, skip: shouldSkip);

View File

@ -8,7 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void contentBlocker() { void contentBlocker() {
final shouldSkip = kIsWeb || ![ final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -22,22 +24,21 @@ void contentBlocker() {
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);
}, },
initialSettings: InAppWebViewSettings(clearCache: true, contentBlockers: [ initialSettings:
InAppWebViewSettings(clearCache: true, contentBlockers: [
ContentBlocker( ContentBlocker(
trigger: trigger: ContentBlockerTrigger(urlFilter: ".*", resourceType: [
ContentBlockerTrigger(urlFilter: ".*", resourceType: [
ContentBlockerTriggerResourceType.IMAGE, ContentBlockerTriggerResourceType.IMAGE,
ContentBlockerTriggerResourceType.STYLE_SHEET ContentBlockerTriggerResourceType.STYLE_SHEET
], ifTopUrl: [ ], ifTopUrl: [
TEST_CROSS_PLATFORM_URL_1.toString() TEST_CROSS_PLATFORM_URL_1.toString()
]), ]),
action: ContentBlockerAction( action:
type: ContentBlockerActionType.BLOCK)) ContentBlockerAction(type: ContentBlockerActionType.BLOCK))
]), ]),
onLoadStop: (controller, url) { onLoadStop: (controller, url) {
pageLoaded.complete(); pageLoaded.complete();

View File

@ -8,15 +8,15 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void createPdf() { void createPdf() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
testWidgets('createPdf', (WidgetTester tester) async { testWidgets('createPdf', (WidgetTester tester) async {
final Completer controllerCompleter = final Completer controllerCompleter = Completer<InAppWebViewController>();
Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>(); final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget( await tester.pumpWidget(
@ -24,8 +24,7 @@ void createPdf() {
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 +35,7 @@ void createPdf() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
var pdfConfiguration = PDFConfiguration( var pdfConfiguration = PDFConfiguration(

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void getCertificate() { void getCertificate() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -24,8 +25,7 @@ void getCertificate() {
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 getCertificate() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
var sslCertificate = await controller.getCertificate(); var sslCertificate = await controller.getCertificate();

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void getContentHeight() { void getContentHeight() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -26,8 +27,7 @@ void getContentHeight() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: url),
URLRequest(url: url),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -38,8 +38,7 @@ void getContentHeight() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
final contentHeight = await controller.getContentHeight(); final contentHeight = await controller.getContentHeight();

View File

@ -1,11 +1,11 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void getCurrentWebViewPackage() { void getCurrentWebViewPackage() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);

View File

@ -4,8 +4,9 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void getDefaultUserAgent() { void getDefaultUserAgent() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void getFavicons() { void getFavicons() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -26,8 +27,7 @@ void getFavicons() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: url),
URLRequest(url: url),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -38,8 +38,7 @@ void getFavicons() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
final List<Favicon>? favicons = await controller.getFavicons(); final List<Favicon>? favicons = await controller.getFavicons();

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void getHtml() { void getHtml() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -26,8 +27,7 @@ void getHtml() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: url),
URLRequest(url: url),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -38,8 +38,7 @@ void getHtml() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
final String? html = await controller.getHtml(); final String? html = await controller.getHtml();

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void getMetaTags() { void getMetaTags() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -26,8 +27,7 @@ void getMetaTags() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: url),
URLRequest(url: url),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -38,8 +38,7 @@ void getMetaTags() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
List<MetaTag> metaTags = await controller.getMetaTags(); List<MetaTag> metaTags = await controller.getMetaTags();

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void getMetaThemeColor() { void getMetaThemeColor() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -37,8 +38,7 @@ void getMetaThemeColor() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
expect(await controller.getMetaThemeColor(), isNotNull); expect(await controller.getMetaThemeColor(), isNotNull);

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void getOriginalUrl() { void getOriginalUrl() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -18,8 +19,7 @@ void getOriginalUrl() {
var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1;
testWidgets('getOriginalUrl', (WidgetTester tester) async { testWidgets('getOriginalUrl', (WidgetTester tester) async {
final Completer controllerCompleter = final Completer controllerCompleter = Completer<InAppWebViewController>();
Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>(); final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget( await tester.pumpWidget(
@ -27,8 +27,7 @@ void getOriginalUrl() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: url),
URLRequest(url: url),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -39,8 +38,7 @@ void getOriginalUrl() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
var originUrl = (await controller.getOriginalUrl())?.toString(); var originUrl = (await controller.getOriginalUrl())?.toString();
expect(originUrl, url.toString()); expect(originUrl, url.toString());

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void getProgress() { void getProgress() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -24,8 +25,7 @@ void getProgress() {
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 getProgress() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
final int? progress = await controller.getProgress(); final int? progress = await controller.getProgress();

View File

@ -9,7 +9,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void getTitle() { void getTitle() {
final shouldSkip = !kIsWeb || ![ final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -26,13 +28,12 @@ void getTitle() {
final String getTitleTestBase64 = final String getTitleTestBase64 =
base64Encode(const Utf8Encoder().convert(getTitleTest)); base64Encode(const Utf8Encoder().convert(getTitleTest));
var url = !kIsWeb ? Uri.parse( var url = !kIsWeb
'data:text/html;charset=utf-8;base64,$getTitleTestBase64') : ? Uri.parse('data:text/html;charset=utf-8;base64,$getTitleTestBase64')
TEST_WEB_PLATFORM_URL_1; : TEST_WEB_PLATFORM_URL_1;
var expectedValue = !kIsWeb ? 'Some title' : 'page'; var expectedValue = !kIsWeb ? 'Some title' : 'page';
testWidgets('getTitle', (WidgetTester tester) async { testWidgets('getTitle', (WidgetTester tester) async {
final Completer<void> pageStarted = Completer<void>(); final Completer<void> pageStarted = Completer<void>();
final Completer<void> pageLoaded = Completer<void>(); final Completer<void> pageLoaded = Completer<void>();
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -41,8 +42,7 @@ void getTitle() {
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
initialUrlRequest: URLRequest( initialUrlRequest: URLRequest(url: url),
url: url),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -56,8 +56,7 @@ void getTitle() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageStarted.future; await pageStarted.future;
await pageLoaded.future; await pageLoaded.future;

View File

@ -3,8 +3,9 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void handlesURLScheme() { void handlesURLScheme() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../.env.dart'; import '../.env.dart';
void httpAuthCredentialDatabase() { void httpAuthCredentialDatabase() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -8,16 +8,18 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void initialUrlRequest() { void initialUrlRequest() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
group('initial url request', () { group('initial url request', () {
final shouldSkipTest1 = !kIsWeb || final shouldSkipTest1 = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -45,8 +47,9 @@ void initialUrlRequest() {
expect(currentUrl, TEST_CROSS_PLATFORM_URL_1.toString()); expect(currentUrl, TEST_CROSS_PLATFORM_URL_1.toString());
}, skip: shouldSkipTest1); }, skip: shouldSkipTest1);
final shouldSkipTest2 = kIsWeb || final shouldSkipTest2 = kIsWeb
![ ? true
: ![
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
@ -62,8 +65,7 @@ void initialUrlRequest() {
height: 300, height: 300,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: TEST_URL_1),
URLRequest(url: TEST_URL_1),
initialSettings: InAppWebViewSettings( initialSettings: InAppWebViewSettings(
allowsBackForwardNavigationGestures: true), allowsBackForwardNavigationGestures: true),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {

View File

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

View File

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

View File

@ -9,8 +9,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../.env.dart'; import '../.env.dart';
void interceptAjaxRequest() { void interceptAjaxRequest() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -9,8 +9,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../.env.dart'; import '../.env.dart';
void interceptFetchRequest() { void interceptFetchRequest() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void isLoading() { void isLoading() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -25,8 +26,7 @@ void isLoading() {
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),
initialSettings: InAppWebViewSettings(clearCache: true), initialSettings: InAppWebViewSettings(clearCache: true),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
@ -41,8 +41,7 @@ void isLoading() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageStarted.future; await pageStarted.future;
expect(await controller.isLoading(), true); expect(await controller.isLoading(), true);

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void isSecureContext() { void isSecureContext() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -27,8 +28,7 @@ void isSecureContext() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: url),
URLRequest(url: url),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -39,8 +39,7 @@ void isSecureContext() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoads.stream.first; await pageLoads.stream.first;
expect(await controller.isSecureContext(), true); expect(await controller.isSecureContext(), true);

View File

@ -8,16 +8,18 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void javascriptCodeEvaluation() { void javascriptCodeEvaluation() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
group('javascript code evaluation', () { group('javascript code evaluation', () {
final shouldSkipTest1 = !kIsWeb || final shouldSkipTest1 = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -57,8 +59,9 @@ void javascriptCodeEvaluation() {
mapEquals(result[3]?.cast<String, String>(), {"foo": "baz"}), true); mapEquals(result[3]?.cast<String, String>(), {"foo": "baz"}), true);
}, skip: shouldSkipTest1); }, skip: shouldSkipTest1);
final shouldSkipTest2 = kIsWeb || final shouldSkipTest2 = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -100,8 +103,9 @@ void javascriptCodeEvaluation() {
expect(result, 49); expect(result, 49);
}, skip: shouldSkipTest2); }, skip: shouldSkipTest2);
final shouldSkipTest3 = kIsWeb || final shouldSkipTest3 = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -159,8 +163,9 @@ void javascriptCodeEvaluation() {
expect(result.error, 'error message'); expect(result.error, 'error message');
}, skip: shouldSkipTest3); }, skip: shouldSkipTest3);
final shouldSkipTest4 = kIsWeb || final shouldSkipTest4 = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -5,11 +5,10 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void javascriptDialogs() { void javascriptDialogs() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -8,7 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../util.dart'; import '../util.dart';
void javascriptHandler() { void javascriptHandler() {
final shouldSkip = kIsWeb || ![ final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -44,10 +46,10 @@ void javascriptHandler() {
messagesReceived.add(args[0] as int); messagesReceived.add(args[0] as int);
messagesReceived.add(args[1] as bool); messagesReceived.add(args[1] as bool);
messagesReceived.add(args[2] as List<dynamic>?); messagesReceived.add(args[2] as List<dynamic>?);
messagesReceived.add(args[3]?.cast<String, String>() messagesReceived.add(
as Map<String, String>?); args[3]?.cast<String, String>() as Map<String, String>?);
messagesReceived.add(args[4]?.cast<String, String>() messagesReceived.add(
as Map<String, String>?); args[4]?.cast<String, String>() as Map<String, String>?);
handlerFooWithArgs.complete(); handlerFooWithArgs.complete();
}); });
}, },
@ -69,8 +71,7 @@ void javascriptHandler() {
expect(messagesReceived[0], 1); expect(messagesReceived[0], 1);
expect(messagesReceived[1], true); expect(messagesReceived[1], true);
expect( expect(listEquals(messagesReceived[2] as List<dynamic>?, ["bar", 5]), true);
listEquals(messagesReceived[2] as List<dynamic>?, ["bar", 5]), true);
expect(mapEquals(messagesReceived[3], {"foo": "baz"}), true); expect(mapEquals(messagesReceived[3], {"foo": "baz"}), true);
expect( expect(
mapEquals( mapEquals(

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void loadData() { void loadData() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -36,8 +37,7 @@ void loadData() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoads.stream.first; await pageLoads.stream.first;
final data = """ final data = """
@ -70,7 +70,7 @@ void loadData() {
if (!kIsWeb) { if (!kIsWeb) {
expect(currentUrl, TEST_CROSS_PLATFORM_URL_1.toString()); expect(currentUrl, TEST_CROSS_PLATFORM_URL_1.toString());
} else { } else {
expect(currentUrl, 'data:$mimeType,' + Uri.encodeFull(data)) ; expect(currentUrl, 'data:$mimeType,' + Uri.encodeFull(data));
} }
pageLoads.close(); pageLoads.close();

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void loadFile() { void loadFile() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -36,8 +37,7 @@ void loadFile() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoads.stream.first; await pageLoads.stream.first;
await controller.loadFile( await controller.loadFile(

View File

@ -8,7 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
void loadFileUrl() { void loadFileUrl() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb ? true :
![ ![
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -8,14 +8,14 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void loadUrl() { void loadUrl() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb ? false :
![ ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
testWidgets('reload', (WidgetTester tester) async { testWidgets('loadUrl', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
final StreamController<String> pageLoads = final StreamController<String> pageLoads =
StreamController<String>.broadcast(); StreamController<String>.broadcast();
@ -26,7 +26,7 @@ void loadUrl() {
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest:
URLRequest(url: Uri.parse('https://github.com/flutter')), URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -38,13 +38,14 @@ void loadUrl() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
String? url = await pageLoads.stream.first; var url = await pageLoads.stream.first;
expect(url, 'https://github.com/flutter'); expect(url, TEST_CROSS_PLATFORM_URL_1.toString());
await controller.reload(); await controller.loadUrl(
urlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_2));
url = await pageLoads.stream.first; url = await pageLoads.stream.first;
expect(url, 'https://github.com/flutter'); expect(url, TEST_CROSS_PLATFORM_URL_2.toString());
pageLoads.close(); pageLoads.close();
}); }, skip: shouldSkip);
} }

View File

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

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../.env.dart'; import '../.env.dart';
void onDownloadStartRequest() { void onDownloadStartRequest() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void onFindResultReceived() { void onFindResultReceived() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void onJsBeforeUnload() { void onJsBeforeUnload() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
@ -23,8 +24,7 @@ void onJsBeforeUnload() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: TEST_URL_1),
URLRequest(url: TEST_URL_1),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -48,8 +48,7 @@ void onJsBeforeUnload() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await controller.evaluateJavascript( await controller.evaluateJavascript(
source: "window.location.href = '$TEST_URL_1';"); source: "window.location.href = '$TEST_URL_1';");

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void onLoadError() { void onLoadError() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -8,7 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void onLoadHttpError() { void onLoadHttpError() {
final shouldSkip = kIsWeb || ![ final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -23,8 +25,7 @@ void onLoadHttpError() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: TEST_URL_404),
URLRequest(url: TEST_URL_404),
onLoadHttpError: (controller, url, statusCode, description) async { onLoadHttpError: (controller, url, statusCode, description) async {
errorUrlCompleter.complete(url.toString()); errorUrlCompleter.complete(url.toString());
statusCodeCompleter.complete(statusCode); statusCodeCompleter.complete(statusCode);

View File

@ -5,11 +5,10 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void onLoadResource() { void onLoadResource() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -7,8 +7,9 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void onLoadResourceCustomScheme() { void onLoadResourceCustomScheme() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void onNavigationResponse() { void onNavigationResponse() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
@ -26,8 +27,7 @@ void onNavigationResponse() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: TEST_URL_1),
URLRequest(url: TEST_URL_1),
initialSettings: initialSettings:
InAppWebViewSettings(useOnNavigationResponse: true), InAppWebViewSettings(useOnNavigationResponse: true),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
@ -61,8 +61,7 @@ void onNavigationResponse() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: TEST_URL_1),
URLRequest(url: TEST_URL_1),
initialSettings: initialSettings:
InAppWebViewSettings(useOnNavigationResponse: true), InAppWebViewSettings(useOnNavigationResponse: true),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void onPageCommitVisible() { void onPageCommitVisible() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -17,16 +18,14 @@ void onPageCommitVisible() {
testWidgets('onPageCommitVisible', (WidgetTester tester) async { testWidgets('onPageCommitVisible', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<String> onPageCommitVisibleCompleter = final Completer<String> onPageCommitVisibleCompleter = Completer<String>();
Completer<String>();
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: TEST_URL_1),
URLRequest(url: TEST_URL_1),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void onPermissionRequest() { void onPermissionRequest() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -44,7 +45,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, return PermissionResponse(
resources: permissionRequest.resources,
action: PermissionResponseAction.GRANT); action: PermissionResponseAction.GRANT);
}, },
), ),

View File

@ -8,7 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void onPrint() { void onPrint() {
final shouldSkip = !kIsWeb || ![ final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -23,8 +25,7 @@ void onPrint() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: url),
URLRequest(url: url),
onLoadStop: (controller, url) async { onLoadStop: (controller, url) async {
await controller.evaluateJavascript(source: "window.print();"); await controller.evaluateJavascript(source: "window.print();");
}, },

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void onProgressChanged() { void onProgressChanged() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -22,8 +23,7 @@ void onProgressChanged() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: TEST_URL_1),
URLRequest(url: TEST_URL_1),
initialSettings: InAppWebViewSettings( initialSettings: InAppWebViewSettings(
clearCache: true, clearCache: true,
), ),

View File

@ -9,24 +9,23 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void onReceivedIcon() { void onReceivedIcon() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
testWidgets('onReceivedIcon', (WidgetTester tester) async { testWidgets('onReceivedIcon', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>(); final Completer<void> pageLoaded = Completer<void>();
final Completer<Uint8List> onReceivedIconCompleter = final Completer<Uint8List> onReceivedIconCompleter = Completer<Uint8List>();
Completer<Uint8List>();
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: TEST_URL_1),
URLRequest(url: TEST_URL_1),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },

View File

@ -5,11 +5,10 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void onReceivedTouchIconUrl() { void onReceivedTouchIconUrl() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);

View File

@ -8,7 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void onScrollChanged() { void onScrollChanged() {
final shouldSkip = !kIsWeb || ![ final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -25,8 +27,7 @@ void onScrollChanged() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: url),
URLRequest(url: url),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -42,8 +43,7 @@ void onScrollChanged() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
controller.scrollTo(x: 0, y: 500); controller.scrollTo(x: 0, y: 500);

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void onTitleChanged() { void onTitleChanged() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -27,8 +28,7 @@ void onTitleChanged() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: url),
URLRequest(url: url),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -44,8 +44,7 @@ void onTitleChanged() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await controller.evaluateJavascript( await controller.evaluateJavascript(
source: "document.title = 'title test';"); source: "document.title = 'title test';");

View File

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

View File

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

View File

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

View File

@ -8,14 +8,14 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void pageDownUp() { void pageDownUp() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
testWidgets('pageDown/pageUp', (WidgetTester tester) async { testWidgets('pageDown/pageUp', (WidgetTester tester) async {
final Completer controllerCompleter = final Completer controllerCompleter = Completer<InAppWebViewController>();
Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>(); final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget( await tester.pumpWidget(
@ -23,8 +23,7 @@ void pageDownUp() {
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);
}, },
@ -35,8 +34,7 @@ void pageDownUp() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
expect(await controller.pageDown(bottom: false), true); expect(await controller.pageDown(bottom: false), true);
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));

View File

@ -8,14 +8,14 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void pauseResume() { void pauseResume() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
testWidgets('pause/resume', (WidgetTester tester) async { testWidgets('pause/resume', (WidgetTester tester) async {
final Completer controllerCompleter = final Completer controllerCompleter = Completer<InAppWebViewController>();
Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>(); final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget( await tester.pumpWidget(
@ -23,8 +23,7 @@ void pauseResume() {
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);
}, },
@ -35,8 +34,7 @@ void pauseResume() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await expectLater(controller.pause(), completes); await expectLater(controller.pause(), completes);
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void pauseResumeTimers() { void pauseResumeTimers() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -35,8 +36,7 @@ void pauseResumeTimers() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await controller.evaluateJavascript(source: """ await controller.evaluateJavascript(source: """
@ -49,10 +49,9 @@ void pauseResumeTimers() {
await controller.pauseTimers(); await controller.pauseTimers();
await Future.delayed(Duration(seconds: 2)); await Future.delayed(Duration(seconds: 2));
await controller.resumeTimers(); await controller.resumeTimers();
expect( expect(await controller.evaluateJavascript(source: "count;"), lessThan(50));
await controller.evaluateJavascript(source: "count;"), lessThan(50));
await Future.delayed(Duration(seconds: 4)); await Future.delayed(Duration(seconds: 4));
expect(await controller.evaluateJavascript(source: "count;"), expect(
greaterThan(50)); await controller.evaluateJavascript(source: "count;"), greaterThan(50));
}, skip: shouldSkip); }, skip: shouldSkip);
} }

View File

@ -10,8 +10,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../.env.dart'; import '../.env.dart';
void postRequests() { void postRequests() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -19,8 +20,7 @@ void postRequests() {
group('POST requests', () { group('POST requests', () {
testWidgets('initialUrlRequest', (WidgetTester tester) async { testWidgets('initialUrlRequest', (WidgetTester tester) async {
final Completer controllerCompleter = final Completer controllerCompleter = Completer<InAppWebViewController>();
Completer<InAppWebViewController>();
final Completer<void> postPageLoaded = Completer<void>(); final Completer<void> postPageLoaded = Completer<void>();
await tester.pumpWidget( await tester.pumpWidget(
@ -33,9 +33,7 @@ void postRequests() {
"http://${environment["NODE_SERVER_IP"]}:8082/test-post"), "http://${environment["NODE_SERVER_IP"]}:8082/test-post"),
method: 'POST', method: 'POST',
body: Uint8List.fromList(utf8.encode("name=FooBar")), body: Uint8List.fromList(utf8.encode("name=FooBar")),
headers: { headers: {'Content-Type': 'application/x-www-form-urlencoded'}),
'Content-Type': 'application/x-www-form-urlencoded'
}),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -51,8 +49,8 @@ void postRequests() {
await postPageLoaded.future; await postPageLoaded.future;
final String? currentUrl = (await controller.getUrl())?.toString(); final String? currentUrl = (await controller.getUrl())?.toString();
expect(currentUrl, expect(
'http://${environment["NODE_SERVER_IP"]}:8082/test-post'); currentUrl, 'http://${environment["NODE_SERVER_IP"]}:8082/test-post');
final String? pContent = await controller.evaluateJavascript( final String? pContent = await controller.evaluateJavascript(
source: "document.querySelector('p').innerHTML;"); source: "document.querySelector('p').innerHTML;");
@ -60,8 +58,7 @@ void postRequests() {
}); });
testWidgets('loadUrl', (WidgetTester tester) async { testWidgets('loadUrl', (WidgetTester tester) async {
final Completer controllerCompleter = final Completer controllerCompleter = Completer<InAppWebViewController>();
Completer<InAppWebViewController>();
final Completer<void> postPageLoaded = Completer<void>(); final Completer<void> postPageLoaded = Completer<void>();
await tester.pumpWidget( await tester.pumpWidget(
@ -92,15 +89,13 @@ void postRequests() {
"http://${environment["NODE_SERVER_IP"]}:8082/test-post"), "http://${environment["NODE_SERVER_IP"]}:8082/test-post"),
method: 'POST', method: 'POST',
body: postData, body: postData,
headers: { headers: {'Content-Type': 'application/x-www-form-urlencoded'}));
'Content-Type': 'application/x-www-form-urlencoded'
}));
await postPageLoaded.future; await postPageLoaded.future;
final String? currentUrl = (await controller.getUrl())?.toString(); final String? currentUrl = (await controller.getUrl())?.toString();
expect(currentUrl, expect(
'http://${environment["NODE_SERVER_IP"]}:8082/test-post'); currentUrl, 'http://${environment["NODE_SERVER_IP"]}:8082/test-post');
final String? pContent = await controller.evaluateJavascript( final String? pContent = await controller.evaluateJavascript(
source: "document.querySelector('p').innerHTML;"); source: "document.querySelector('p').innerHTML;");
@ -108,8 +103,7 @@ void postRequests() {
}); });
testWidgets('postUrl', (WidgetTester tester) async { testWidgets('postUrl', (WidgetTester tester) async {
final Completer controllerCompleter = final Completer controllerCompleter = Completer<InAppWebViewController>();
Completer<InAppWebViewController>();
final Completer<void> postPageLoaded = Completer<void>(); final Completer<void> postPageLoaded = Completer<void>();
await tester.pumpWidget( await tester.pumpWidget(
@ -142,8 +136,8 @@ void postRequests() {
await postPageLoaded.future; await postPageLoaded.future;
final String? currentUrl = (await controller.getUrl())?.toString(); final String? currentUrl = (await controller.getUrl())?.toString();
expect(currentUrl, expect(
'http://${environment["NODE_SERVER_IP"]}:8082/test-post'); currentUrl, 'http://${environment["NODE_SERVER_IP"]}:8082/test-post');
final String? pContent = await controller.evaluateJavascript( final String? pContent = await controller.evaluateJavascript(
source: "document.querySelector('p').innerHTML;"); source: "document.querySelector('p').innerHTML;");

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void printCurrentPage() { void printCurrentPage() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -26,8 +27,7 @@ void printCurrentPage() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: url),
URLRequest(url: url),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -38,8 +38,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 tester.pump();
await expectLater(controller.printCurrentPage(), completes); await expectLater(controller.printCurrentPage(), completes);

View File

@ -9,14 +9,18 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void programmaticScroll() { void programmaticScroll() {
final shouldSkip = !kIsWeb || ![ final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
group('Programmatic Scroll', () { group('Programmatic Scroll', () {
final shouldSkipTest1 = !kIsWeb || ![ final shouldSkipTest1 = kIsWeb
? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -47,20 +51,19 @@ void programmaticScroll() {
final String scrollTestPageBase64 = final String scrollTestPageBase64 =
base64Encode(const Utf8Encoder().convert(scrollTestPage)); base64Encode(const Utf8Encoder().convert(scrollTestPage));
var url = !kIsWeb ? Uri.parse( var url = !kIsWeb
'data:text/html;charset=utf-8;base64,$scrollTestPageBase64') : ? Uri.parse(
TEST_WEB_PLATFORM_URL_1; 'data:text/html;charset=utf-8;base64,$scrollTestPageBase64')
: TEST_WEB_PLATFORM_URL_1;
final Completer<void> pageLoaded = Completer<void>(); final Completer<void> pageLoaded = Completer<void>();
final Completer controllerCompleter = final Completer controllerCompleter = Completer<InAppWebViewController>();
Completer<InAppWebViewController>();
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
initialUrlRequest: URLRequest( initialUrlRequest: URLRequest(url: url),
url: url),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -98,7 +101,15 @@ void programmaticScroll() {
expect(scrollPosY, Y_SCROLL * 2); expect(scrollPosY, Y_SCROLL * 2);
}, skip: shouldSkipTest1); }, skip: shouldSkipTest1);
testWidgets('set and get scroll position on Android without Hybrid Composition', (WidgetTester tester) async { final shouldSkipTest2 = kIsWeb
? true
: ![
TargetPlatform.android,
].contains(defaultTargetPlatform);
testWidgets(
'set and get scroll position on Android without Hybrid Composition',
(WidgetTester tester) async {
final String scrollTestPage = ''' final String scrollTestPage = '''
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@ -124,8 +135,7 @@ void programmaticScroll() {
base64Encode(const Utf8Encoder().convert(scrollTestPage)); base64Encode(const Utf8Encoder().convert(scrollTestPage));
final Completer<void> pageLoaded = Completer<void>(); final Completer<void> pageLoaded = Completer<void>();
final Completer controllerCompleter = final Completer controllerCompleter = Completer<InAppWebViewController>();
Completer<InAppWebViewController>();
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
@ -137,8 +147,7 @@ void programmaticScroll() {
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
initialSettings: InAppWebViewSettings( initialSettings: InAppWebViewSettings(useHybridComposition: false),
useHybridComposition: false),
onLoadStop: (controller, url) { onLoadStop: (controller, url) {
pageLoaded.complete(); pageLoaded.complete();
}, },
@ -171,6 +180,6 @@ void programmaticScroll() {
scrollPosY = await controller.getScrollY(); scrollPosY = await controller.getScrollY();
expect(scrollPosX, X_SCROLL * 2); expect(scrollPosX, X_SCROLL * 2);
expect(scrollPosY, Y_SCROLL * 2); expect(scrollPosY, Y_SCROLL * 2);
}, skip: defaultTargetPlatform != TargetPlatform.android); }, skip: shouldSkipTest2);
}, skip: shouldSkip); }, skip: shouldSkip);
} }

View File

@ -8,22 +8,23 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void programmaticZoomScale() { void programmaticZoomScale() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
group('programmatic zoom scale', () { group('programmatic zoom scale', () {
final shouldSkipTest1 = kIsWeb || final shouldSkipTest1 = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
testWidgets('zoomIn/zoomOut', (WidgetTester tester) async { testWidgets('zoomIn/zoomOut', (WidgetTester tester) async {
final Completer controllerCompleter = final Completer controllerCompleter = Completer<InAppWebViewController>();
Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>(); final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget( await tester.pumpWidget(
@ -31,8 +32,7 @@ void programmaticZoomScale() {
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);
}, },
@ -63,8 +63,7 @@ void programmaticZoomScale() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: TEST_URL_1),
URLRequest(url: TEST_URL_1),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },

View File

@ -9,8 +9,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void pullToRefresh() { void pullToRefresh() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -36,8 +37,7 @@ void pullToRefresh() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: TEST_URL_1),
URLRequest(url: TEST_URL_1),
pullToRefreshController: pullToRefreshController, pullToRefreshController: pullToRefreshController,
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void reload() { void reload() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -18,8 +19,9 @@ void reload() {
var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1;
group('reload', () { group('reload', () {
final shouldSkipTest1 = kIsWeb || final shouldSkipTest1 = kIsWeb
![ ? true
: ![
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void requestFocusNodeHref() { void requestFocusNodeHref() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -24,8 +25,7 @@ void requestFocusNodeHref() {
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 requestFocusNodeHref() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await expectLater(controller.requestFocusNodeHref(), completes); await expectLater(controller.requestFocusNodeHref(), completes);

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void requestImageRef() { void requestImageRef() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -24,8 +25,7 @@ void requestImageRef() {
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 requestImageRef() {
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await expectLater(controller.requestImageRef(), completes); await expectLater(controller.requestImageRef(), completes);

View File

@ -6,10 +6,10 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void resizeWebView() { void resizeWebView() {
final shouldSkip = kIsWeb || ![ final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void safeBrowsing() { void safeBrowsing() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void setCustomUserAgent() { void setCustomUserAgent() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -8,7 +8,9 @@ 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.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -25,11 +27,8 @@ void setGetSettings() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: url),
URLRequest(url: url), initialSettings: InAppWebViewSettings(javaScriptEnabled: false),
initialSettings: InAppWebViewSettings(
javaScriptEnabled: false
),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -39,8 +38,7 @@ void setGetSettings() {
), ),
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
InAppWebViewSettings? settings = await controller.getSettings(); InAppWebViewSettings? settings = await controller.getSettings();
@ -52,8 +50,8 @@ void setGetSettings() {
expect(settings.iframeSandbox!.contains(Sandbox.ALLOW_SCRIPTS), false); expect(settings.iframeSandbox!.contains(Sandbox.ALLOW_SCRIPTS), false);
} }
await controller.setSettings(settings: InAppWebViewSettings( await controller.setSettings(
javaScriptEnabled: true)); settings: InAppWebViewSettings(javaScriptEnabled: true));
settings = await controller.getSettings(); settings = await controller.getSettings();
expect(settings, isNotNull); expect(settings, isNotNull);

View File

@ -1,11 +1,11 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void setWebContentsDebuggingEnabled() { void setWebContentsDebuggingEnabled() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);

View File

@ -6,8 +6,9 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void shouldInterceptRequest() { void shouldInterceptRequest() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);

View File

@ -9,8 +9,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void shouldOverrideUrlLoading() { void shouldOverrideUrlLoading() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -22,13 +23,6 @@ void shouldOverrideUrlLoading() {
final String pageEncoded = 'data:text/html;charset=utf-8;base64,' + final String pageEncoded = 'data:text/html;charset=utf-8;base64,' +
base64Encode(const Utf8Encoder().convert(page)); base64Encode(const Utf8Encoder().convert(page));
final shouldSkipTest1 = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('can allow requests', (WidgetTester tester) async { testWidgets('can allow requests', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
final StreamController<String> pageLoads = final StreamController<String> pageLoads =
@ -70,10 +64,11 @@ void shouldOverrideUrlLoading() {
expect(currentUrl, TEST_URL_2.toString()); expect(currentUrl, TEST_URL_2.toString());
pageLoads.close(); pageLoads.close();
}, skip: shouldSkipTest1); });
final shouldSkipTest2 = kIsWeb || final shouldSkipTest2 = kIsWeb
![ ? true
: ![
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
@ -138,13 +133,6 @@ void shouldOverrideUrlLoading() {
pageLoads.close(); pageLoads.close();
}, skip: shouldSkipTest2); }, skip: shouldSkipTest2);
final shouldSkipTest3 = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('can block requests', (WidgetTester tester) async { testWidgets('can block requests', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
final StreamController<String> pageLoads = final StreamController<String> pageLoads =
@ -194,14 +182,7 @@ void shouldOverrideUrlLoading() {
currentUrl, isNot(contains(TEST_URL_4.host.replaceAll("www.", "")))); currentUrl, isNot(contains(TEST_URL_4.host.replaceAll("www.", ""))));
pageLoads.close(); pageLoads.close();
}, skip: shouldSkipTest3); });
final shouldSkipTest4 = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('supports asynchronous decisions', (WidgetTester tester) async { testWidgets('supports asynchronous decisions', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -245,6 +226,6 @@ void shouldOverrideUrlLoading() {
expect(currentUrl, TEST_URL_2.toString()); expect(currentUrl, TEST_URL_2.toString());
pageLoads.close(); pageLoads.close();
}, skip: shouldSkipTest4); });
}, skip: shouldSkip); }, skip: shouldSkip);
} }

View File

@ -8,7 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../.env.dart'; import '../.env.dart';
void sslRequest() { void sslRequest() {
final shouldSkip = kIsWeb || ![ final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -23,8 +25,7 @@ void sslRequest() {
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: URLRequest( initialUrlRequest: URLRequest(
url: Uri.parse( url: Uri.parse("https://${environment["NODE_SERVER_IP"]}:4433/")),
"https://${environment["NODE_SERVER_IP"]}:4433/")),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -45,8 +46,7 @@ void sslRequest() {
), ),
), ),
); );
final InAppWebViewController controller = final InAppWebViewController controller = await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
final String h1Content = await controller.evaluateJavascript( final String h1Content = await controller.evaluateJavascript(

View File

@ -9,8 +9,9 @@ import '../constants.dart';
import '../util.dart'; import '../util.dart';
void stopLoading() { void stopLoading() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void tRexRunnerGame() { void tRexRunnerGame() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -35,12 +36,11 @@ void tRexRunnerGame() {
), ),
); );
final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
var html = await controller.getTRexRunnerHtml(); var html = await InAppWebViewController.tRexRunnerHtml;
var css = await controller.getTRexRunnerCss(); var css = await InAppWebViewController.tRexRunnerCss;
expect(html, isNotNull); expect(html, isNotNull);
expect(css, isNotNull); expect(css, isNotNull);

View File

@ -9,8 +9,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void userScripts() { void userScripts() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

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

View File

@ -10,24 +10,24 @@ import 'package:path_provider/path_provider.dart';
import '../constants.dart'; import '../constants.dart';
void webArchive() { void webArchive() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
group('web archive', () { group('web archive', () {
final shouldSkipTest1 = kIsWeb
final shouldSkipTest1 = kIsWeb || ? true
![ : ![
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
testWidgets('create data', (WidgetTester tester) async { testWidgets('create data', (WidgetTester tester) async {
final Completer controllerCompleter = final Completer controllerCompleter = Completer<InAppWebViewController>();
Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>(); final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget( await tester.pumpWidget(
@ -35,8 +35,7 @@ void webArchive() {
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);
}, },
@ -63,8 +62,7 @@ void webArchive() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest: URLRequest(url: TEST_URL_1),
URLRequest(url: TEST_URL_1),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },

View File

@ -8,22 +8,25 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void webHistory() { void webHistory() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
group('web history', () { group('web history', () {
final shouldSkipTest1 = kIsWeb || final shouldSkipTest1 = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
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>();
await tester.pumpWidget( await tester.pumpWidget(
@ -42,7 +45,8 @@ void webHistory() {
), ),
); );
final InAppWebViewController controller = await controllerCompleter.future; final InAppWebViewController controller =
await controllerCompleter.future;
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));
var url = (await controller.getUrl()).toString(); var url = (await controller.getUrl()).toString();
@ -50,10 +54,10 @@ void webHistory() {
expect(url, TEST_CROSS_PLATFORM_URL_1.toString()); expect(url, TEST_CROSS_PLATFORM_URL_1.toString());
expect(webHistory!.currentIndex, 0); expect(webHistory!.currentIndex, 0);
expect(webHistory.list!.length, 1); expect(webHistory.list!.length, 1);
expect(webHistory.list![0].url.toString(), TEST_CROSS_PLATFORM_URL_1.toString()); expect(webHistory.list![0].url.toString(),
TEST_CROSS_PLATFORM_URL_1.toString());
await controller.loadUrl( await controller.loadUrl(urlRequest: URLRequest(url: TEST_URL_1));
urlRequest: URLRequest(url: TEST_URL_1));
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));
url = (await controller.getUrl()).toString(); url = (await controller.getUrl()).toString();
webHistory = await controller.getCopyBackForwardList(); webHistory = await controller.getCopyBackForwardList();
@ -64,7 +68,8 @@ void webHistory() {
expect(await controller.canGoBackOrForward(steps: 1), false); expect(await controller.canGoBackOrForward(steps: 1), false);
expect(webHistory!.currentIndex, 1); expect(webHistory!.currentIndex, 1);
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());
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));
@ -79,7 +84,8 @@ void webHistory() {
expect(await controller.canGoBackOrForward(steps: 1), true); expect(await controller.canGoBackOrForward(steps: 1), true);
expect(webHistory!.currentIndex, 0); expect(webHistory!.currentIndex, 0);
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());
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));
@ -94,7 +100,8 @@ void webHistory() {
expect(await controller.canGoBackOrForward(steps: 1), false); expect(await controller.canGoBackOrForward(steps: 1), false);
expect(webHistory!.currentIndex, 1); expect(webHistory!.currentIndex, 1);
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());
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));
@ -109,7 +116,8 @@ void webHistory() {
expect(await controller.canGoBackOrForward(steps: 1), true); expect(await controller.canGoBackOrForward(steps: 1), true);
expect(webHistory!.currentIndex, 0); expect(webHistory!.currentIndex, 0);
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());
}, skip: shouldSkipTest1); }, skip: shouldSkipTest1);
@ -136,7 +144,8 @@ void webHistory() {
), ),
); );
final InAppWebViewController controller = await controllerCompleter.future; final InAppWebViewController controller =
await controllerCompleter.future;
var url = await pageLoads.stream.first; var url = await pageLoads.stream.first;
expect(url, TEST_WEB_PLATFORM_URL_1.toString()); expect(url, TEST_WEB_PLATFORM_URL_1.toString());
@ -164,14 +173,14 @@ void webHistory() {
pageLoads.close(); pageLoads.close();
}, skip: shouldSkipTest2); }, skip: shouldSkipTest2);
final shouldSkipTest3 = kIsWeb || final shouldSkipTest3 = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
testWidgets('clearHistory', (WidgetTester tester) async { testWidgets('clearHistory', (WidgetTester tester) async {
final Completer controllerCompleter = final Completer controllerCompleter = Completer<InAppWebViewController>();
Completer<InAppWebViewController>();
final StreamController<String> pageLoads = final StreamController<String> pageLoads =
StreamController<String>.broadcast(); StreamController<String>.broadcast();
@ -180,8 +189,7 @@ void webHistory() {
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);
}, },
@ -195,9 +203,7 @@ void webHistory() {
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoads.stream.first; await pageLoads.stream.first;
await controller.loadUrl( await controller.loadUrl(urlRequest: URLRequest(url: TEST_URL_1));
urlRequest:
URLRequest(url: TEST_URL_1));
await pageLoads.stream.first; await pageLoads.stream.first;
var webHistory = await controller.getCopyBackForwardList(); var webHistory = await controller.getCopyBackForwardList();

View File

@ -8,8 +8,9 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void webMessage() { void webMessage() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,

View File

@ -9,16 +9,18 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void webViewWindows() { void webViewWindows() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
group("WebView Windows", () { group("WebView Windows", () {
final shouldSkipTest1 = kIsWeb || final shouldSkipTest1 = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -57,8 +59,9 @@ void webViewWindows() {
await expectLater(pageLoaded.future, completes); await expectLater(pageLoaded.future, completes);
}, skip: shouldSkipTest1); }, skip: shouldSkipTest1);
final shouldSkipTest2 = kIsWeb || final shouldSkipTest2 = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -127,8 +130,9 @@ void webViewWindows() {
await expectLater(onCloseWindowCompleter.future, completes); await expectLater(onCloseWindowCompleter.future, completes);
}, skip: shouldSkipTest2); }, skip: shouldSkipTest2);
final shouldSkipTest3 = kIsWeb || final shouldSkipTest3 = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
@ -170,18 +174,16 @@ void webViewWindows() {
pageLoads.close(); pageLoads.close();
}, skip: shouldSkipTest3); }, skip: shouldSkipTest3);
final shouldSkipTest4 = kIsWeb || final shouldSkipTest4 = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
testWidgets( testWidgets('can open new window and go back', (WidgetTester tester) async {
'can open new window and go back', final Completer controllerCompleter = Completer<InAppWebViewController>();
(WidgetTester tester) async {
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final StreamController<String> pageLoads = final StreamController<String> pageLoads =
StreamController<String>.broadcast(); StreamController<String>.broadcast();
await tester.pumpWidget( await tester.pumpWidget(
@ -223,15 +225,15 @@ void webViewWindows() {
pageLoads.close(); pageLoads.close();
}, skip: shouldSkipTest4); }, skip: shouldSkipTest4);
final shouldSkipTest5 = kIsWeb || final shouldSkipTest5 = kIsWeb
![ ? true
: ![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
testWidgets( testWidgets('javascript does not run in parent window',
'javascript does not run in parent window',
(WidgetTester tester) async { (WidgetTester tester) async {
final String iframe = ''' final String iframe = '''
<!DOCTYPE html> <!DOCTYPE html>
@ -263,8 +265,7 @@ void webViewWindows() {
'''; ''';
final String openWindowTestBase64 = final String openWindowTestBase64 =
base64Encode(const Utf8Encoder().convert(openWindowTest)); base64Encode(const Utf8Encoder().convert(openWindowTest));
final Completer controllerCompleter = final Completer controllerCompleter = Completer<InAppWebViewController>();
Completer<InAppWebViewController>();
final Completer<void> pageLoadCompleter = Completer<void>(); final Completer<void> pageLoadCompleter = Completer<void>();
await tester.pumpWidget( await tester.pumpWidget(
@ -322,15 +323,18 @@ void webViewWindows() {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
onCreateWindow: (controller, createNavigationAction) async { onCreateWindow: (controller, createNavigationAction) async {
onCreateWindowCalled.complete(createNavigationAction.request.url.toString()); onCreateWindowCalled
.complete(createNavigationAction.request.url.toString());
return false; return false;
}, },
), ),
), ),
); );
final InAppWebViewController controller = await controllerCompleter.future; final InAppWebViewController controller =
await controller.evaluateJavascript(source: "window.open('$TEST_CROSS_PLATFORM_URL_1')"); await controllerCompleter.future;
await controller.evaluateJavascript(
source: "window.open('$TEST_CROSS_PLATFORM_URL_1')");
var url = await onCreateWindowCalled.future; var url = await onCreateWindowCalled.future;
expect(url, TEST_CROSS_PLATFORM_URL_1.toString()); expect(url, TEST_CROSS_PLATFORM_URL_1.toString());

View File

@ -3,11 +3,11 @@
export "FLUTTER_ROOT=/Users/lorenzopichilli/fvm/versions/2.10.4" export "FLUTTER_ROOT=/Users/lorenzopichilli/fvm/versions/2.10.4"
export "FLUTTER_APPLICATION_PATH=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example" export "FLUTTER_APPLICATION_PATH=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true" export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example/lib/main.dart" export "FLUTTER_TARGET=integration_test/webview_flutter_test.dart"
export "FLUTTER_BUILD_DIR=build" export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1" export "FLUTTER_BUILD_NUMBER=1"
export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==" export "DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
export "DART_OBFUSCATION=false" export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true" export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false" export "TREE_SHAKE_ICONS=false"

View File

@ -23,8 +23,11 @@ class ServiceWorkerController {
ServiceWorkerClient? get serviceWorkerClient => _serviceWorkerClient; ServiceWorkerClient? get serviceWorkerClient => _serviceWorkerClient;
///Sets the service worker client ///Sets the service worker client.
setServiceWorkerClient(ServiceWorkerClient? value) async { ///
///**Supported Platforms/Implementations**:
///- Android native WebView ([Official API - ServiceWorkerControllerCompat.setServiceWorkerClient](https://developer.android.com/reference/androidx/webkit/ServiceWorkerControllerCompat#setServiceWorkerClient(androidx.webkit.ServiceWorkerClientCompat)))
Future<void> setServiceWorkerClient(ServiceWorkerClient? value) async {
Map<String, dynamic> args = <String, dynamic>{}; Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('isNull', () => value == null); args.putIfAbsent('isNull', () => value == null);
await _channel.invokeMethod("setServiceWorkerClient", args); await _channel.invokeMethod("setServiceWorkerClient", args);

View File

@ -2090,24 +2090,16 @@ class InAppWebViewController
await _channel.invokeMethod('clearMatches', args); await _channel.invokeMethod('clearMatches', args);
} }
///Gets the html (with javascript) of the Chromium's t-rex runner game. Used in combination with [getTRexRunnerCss]. ///Use [tRexRunnerHtml] instead.
/// @Deprecated("Use tRexRunnerHtml instead")
///**Supported Platforms/Implementations**:
///- Android native WebView
///- iOS
Future<String> getTRexRunnerHtml() async { Future<String> getTRexRunnerHtml() async {
return await rootBundle.loadString( return await InAppWebViewController.tRexRunnerHtml;
"packages/flutter_inappwebview/assets/t_rex_runner/t-rex.html");
} }
///Gets the css of the Chromium's t-rex runner game. Used in combination with [getTRexRunnerHtml]. ///Use [tRexRunnerCss] instead.
/// @Deprecated("Use tRexRunnerCss instead")
///**Supported Platforms/Implementations**:
///- Android native WebView
///- iOS
Future<String> getTRexRunnerCss() async { Future<String> getTRexRunnerCss() async {
return await rootBundle.loadString( return await InAppWebViewController.tRexRunnerCss;
"packages/flutter_inappwebview/assets/t_rex_runner/t-rex.css");
} }
///Scrolls the WebView to the position. ///Scrolls the WebView to the position.
@ -3116,6 +3108,22 @@ class InAppWebViewController
return await _staticChannel.invokeMethod('handlesURLScheme', args); return await _staticChannel.invokeMethod('handlesURLScheme', args);
} }
///Gets the html (with javascript) of the Chromium's t-rex runner game. Used in combination with [getTRexRunnerCss].
///
///**Supported Platforms/Implementations**:
///- Android native WebView
///- iOS
static Future<String> get tRexRunnerHtml async => await rootBundle.loadString(
'packages/flutter_inappwebview/assets/t_rex_runner/t-rex.html');
///Gets the css of the Chromium's t-rex runner game. Used in combination with [getTRexRunnerHtml].
///
///**Supported Platforms/Implementations**:
///- Android native WebView
///- iOS
static Future<String> get tRexRunnerCss async => await rootBundle.loadString(
'packages/flutter_inappwebview/assets/t_rex_runner/t-rex.css');
///Used internally. ///Used internally.
MethodChannel getChannel() { MethodChannel getChannel() {
return _channel; return _channel;

View File

@ -2,7 +2,6 @@ import 'dart:collection';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter_inappwebview/flutter_inappwebview_web.dart';
import '../pull_to_refresh/pull_to_refresh_controller.dart'; import '../pull_to_refresh/pull_to_refresh_controller.dart';