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,11 +6,12 @@ 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.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('Apple Pay API enabled', (WidgetTester tester) async { testWidgets('Apple Pay API enabled', (WidgetTester tester) async {
final Completer<void> pageLoaded = Completer<void>(); final Completer<void> pageLoaded = Completer<void>();

View File

@ -8,22 +8,22 @@ 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
TargetPlatform.android, ? true
TargetPlatform.iOS, : ![
TargetPlatform.macOS, TargetPlatform.android,
].contains(defaultTargetPlatform); TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('Audio playback policy', () { group('Audio playback policy', () {
String audioTestBase64 = ""; String audioTestBase64 = "";
setUpAll(() async { setUpAll(() async {
final ByteData audioData = final ByteData audioData =
await rootBundle.load('test_assets/sample_audio.ogg'); await rootBundle.load('test_assets/sample_audio.ogg');
final String base64AudioData = final String base64AudioData =
base64Encode(Uint8List.view(audioData.buffer)); base64Encode(Uint8List.view(audioData.buffer));
final String audioTest = ''' final String audioTest = '''
<!DOCTYPE html><html> <!DOCTYPE html><html>
<head><title>Audio auto play</title> <head><title>Audio auto play</title>
@ -50,7 +50,7 @@ void audioPlaybackPolicy() {
testWidgets('Auto media playback', (WidgetTester tester) async { testWidgets('Auto media playback', (WidgetTester tester) async {
Completer<InAppWebViewController> controllerCompleter = Completer<InAppWebViewController> controllerCompleter =
Completer<InAppWebViewController>(); Completer<InAppWebViewController>();
Completer<void> pageStarted = Completer<void>(); Completer<void> pageStarted = Completer<void>();
Completer<void> pageLoaded = Completer<void>(); Completer<void> pageLoaded = Completer<void>();
@ -66,8 +66,8 @@ void audioPlaybackPolicy() {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
initialSettings: InAppWebViewSettings( initialSettings: InAppWebViewSettings(
javaScriptEnabled: true, javaScriptEnabled: true,
mediaPlaybackRequiresUserGesture: false), mediaPlaybackRequiresUserGesture: false),
onLoadStart: (controller, url) { onLoadStart: (controller, url) {
pageStarted.complete(); pageStarted.complete();
}, },
@ -82,7 +82,7 @@ void audioPlaybackPolicy() {
await pageLoaded.future; await pageLoaded.future;
bool isPaused = bool isPaused =
await controller.evaluateJavascript(source: 'isPaused();'); await controller.evaluateJavascript(source: 'isPaused();');
expect(isPaused, false); expect(isPaused, false);
controllerCompleter = Completer<InAppWebViewController>(); controllerCompleter = Completer<InAppWebViewController>();
@ -122,4 +122,4 @@ void audioPlaybackPolicy() {
expect(isPaused, true); expect(isPaused, true);
}); });
}, skip: shouldSkip); }, skip: shouldSkip);
} }

View File

@ -8,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('clearCache', (WidgetTester tester) async { testWidgets('clearCache', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -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, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].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,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('clearFocus', (WidgetTester tester) async { testWidgets('clearFocus', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -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, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].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,11 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void contentBlocker() { void contentBlocker() {
final shouldSkip = kIsWeb || ![ final shouldSkip = kIsWeb
TargetPlatform.android, ? true
TargetPlatform.iOS, : ![
TargetPlatform.macOS, TargetPlatform.android,
].contains(defaultTargetPlatform); TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('Content Blocker', (WidgetTester tester) async { testWidgets('Content Blocker', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -22,23 +24,22 @@ 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:
ContentBlocker( InAppWebViewSettings(clearCache: true, contentBlockers: [
trigger: ContentBlocker(
ContentBlockerTrigger(urlFilter: ".*", resourceType: [ trigger: 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();
}, },
@ -47,4 +48,4 @@ void contentBlocker() {
); );
await expectLater(pageLoaded.future, completes); await expectLater(pageLoaded.future, completes);
}, skip: shouldSkip); }, skip: shouldSkip);
} }

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.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].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,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('getCertificate', (WidgetTester tester) async { testWidgets('getCertificate', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -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,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1;
@ -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,13 +1,13 @@
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, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].contains(defaultTargetPlatform);
test('getCurrentWebViewPackage', () async { test('getCurrentWebViewPackage', () async {
expect(await InAppWebViewController.getCurrentWebViewPackage(), isNotNull); expect(await InAppWebViewController.getCurrentWebViewPackage(), isNotNull);

View File

@ -4,12 +4,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
test('getDefaultUserAgent', () async { test('getDefaultUserAgent', () async {
expect(await InAppWebViewController.getDefaultUserAgent(), isNotNull); expect(await InAppWebViewController.getDefaultUserAgent(), isNotNull);

View File

@ -8,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1;
@ -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,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1;
@ -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,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1;
@ -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,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1;
@ -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,18 +8,18 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
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,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('getProgress', (WidgetTester tester) async { testWidgets('getProgress', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -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,11 +9,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void getTitle() { void getTitle() {
final shouldSkip = !kIsWeb || ![ final shouldSkip = kIsWeb
TargetPlatform.android, ? false
TargetPlatform.iOS, : ![
TargetPlatform.macOS, TargetPlatform.android,
].contains(defaultTargetPlatform); TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final String getTitleTest = ''' final String getTitleTest = '''
<!DOCTYPE html><html> <!DOCTYPE html><html>
@ -24,15 +26,14 @@ void getTitle() {
</html> </html>
'''; ''';
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,12 +56,11 @@ 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;
final String? title = await controller.getTitle(); final String? title = await controller.getTitle();
expect(title, expectedValue); expect(title, expectedValue);
}, skip: shouldSkip); }, skip: shouldSkip);
} }

View File

@ -3,11 +3,12 @@ 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.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
test('handlesURLScheme', () async { test('handlesURLScheme', () async {
expect(await InAppWebViewController.handlesURLScheme("http"), true); expect(await InAppWebViewController.handlesURLScheme("http"), true);

View File

@ -8,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('Http Auth Credential Database', () { group('Http Auth Credential Database', () {
testWidgets('use saved credentials', (WidgetTester tester) async { testWidgets('use saved credentials', (WidgetTester tester) async {

View File

@ -8,21 +8,23 @@ 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.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('initial url request', () {
final shouldSkipTest1 = !kIsWeb ||
![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
group('initial url request', () {
final shouldSkipTest1 = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('basic', (WidgetTester tester) async { testWidgets('basic', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
await tester.pumpWidget( await tester.pumpWidget(
@ -45,11 +47,12 @@ 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.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('launches with allowsBackForwardNavigationGestures true', testWidgets('launches with allowsBackForwardNavigationGestures true',
(WidgetTester tester) async { (WidgetTester tester) async {
@ -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,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_URL_ABOUT_BLANK : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_URL_ABOUT_BLANK : TEST_WEB_PLATFORM_URL_1;
@ -39,7 +40,7 @@ void injectCSS() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await controller.injectCSSCode(source: """ await controller.injectCSSCode(source: """
@ -77,7 +78,7 @@ void injectCSS() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await controller.injectCSSFileFromUrl( await controller.injectCSSFileFromUrl(
@ -112,7 +113,7 @@ void injectCSS() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await controller.injectCSSFileFromAsset( await controller.injectCSSFileFromAsset(

View File

@ -8,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_URL_ABOUT_BLANK : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_URL_ABOUT_BLANK : TEST_WEB_PLATFORM_URL_1;
@ -41,12 +42,12 @@ void injectJavascriptFile() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await controller.injectJavascriptFileFromUrl( await controller.injectJavascriptFileFromUrl(
urlFile: urlFile:
Uri.parse('https://www.notawebsite..com/jquery-3.3.1.min.js'), Uri.parse('https://www.notawebsite..com/jquery-3.3.1.min.js'),
scriptHtmlTagAttributes: ScriptHtmlTagAttributes( scriptHtmlTagAttributes: ScriptHtmlTagAttributes(
id: 'jquery-error', id: 'jquery-error',
onError: () { onError: () {
@ -101,7 +102,7 @@ void injectJavascriptFile() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await controller.injectJavascriptFileFromAsset( await controller.injectJavascriptFileFromAsset(

View File

@ -9,12 +9,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('intercept ajax request', () { group('intercept ajax request', () {
testWidgets('send string data', (WidgetTester tester) async { testWidgets('send string data', (WidgetTester tester) async {

View File

@ -9,12 +9,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('intercept fetch request', () { group('intercept fetch request', () {
testWidgets('send string data', (WidgetTester tester) async { testWidgets('send string data', (WidgetTester tester) async {

View File

@ -8,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('isLoading', (WidgetTester tester) async { testWidgets('isLoading', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -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,27 +8,27 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1;
testWidgets('isSecureContext', (WidgetTester tester) async { testWidgets('isSecureContext', (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();
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: 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,21 +8,23 @@ 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.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('javascript code evaluation', () {
final shouldSkipTest1 = !kIsWeb ||
![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
group('javascript code evaluation', () {
final shouldSkipTest1 = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('evaluateJavascript', (WidgetTester tester) async { testWidgets('evaluateJavascript', (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>();
@ -57,12 +59,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('evaluateJavascript with content world', testWidgets('evaluateJavascript with content world',
(WidgetTester tester) async { (WidgetTester tester) async {
@ -100,12 +103,13 @@ void javascriptCodeEvaluation() {
expect(result, 49); expect(result, 49);
}, skip: shouldSkipTest2); }, skip: shouldSkipTest2);
final shouldSkipTest3 = kIsWeb || final shouldSkipTest3 = kIsWeb
![ ? true
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('callAsyncJavaScript', (WidgetTester tester) async { testWidgets('callAsyncJavaScript', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -159,12 +163,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('callAsyncJavaScript with content world', testWidgets('callAsyncJavaScript with content world',
(WidgetTester tester) async { (WidgetTester tester) async {

View File

@ -5,15 +5,14 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('javascript dialogs', (WidgetTester tester) async { testWidgets('javascript dialogs', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();

View File

@ -8,11 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../util.dart'; import '../util.dart';
void javascriptHandler() { void javascriptHandler() {
final shouldSkip = kIsWeb || ![ final shouldSkip = kIsWeb
TargetPlatform.android, ? true
TargetPlatform.iOS, : ![
TargetPlatform.macOS, TargetPlatform.android,
].contains(defaultTargetPlatform); TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('JavaScript Handler', (WidgetTester tester) async { testWidgets('JavaScript Handler', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -27,7 +29,7 @@ void javascriptHandler() {
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialFile: initialFile:
"test_assets/in_app_webview_javascript_handler_test.html", "test_assets/in_app_webview_javascript_handler_test.html",
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
@ -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,12 +71,11 @@ 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(
messagesReceived[4], {"bar": "bar_value", "baz": "baz_value"}), messagesReceived[4], {"bar": "bar_value", "baz": "baz_value"}),
true); true);
}, skip: shouldSkip); }, skip: shouldSkip);
} }

View File

@ -8,17 +8,18 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('loadData', (WidgetTester tester) async { testWidgets('loadData', (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();
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
@ -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,17 +8,18 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('loadFile', (WidgetTester tester) async { testWidgets('loadFile', (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();
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
@ -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,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('onConsoleMessage', (WidgetTester tester) async { testWidgets('onConsoleMessage', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();

View File

@ -8,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('onDownloadStartRequest', (WidgetTester tester) async { testWidgets('onDownloadStartRequest', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();

View File

@ -8,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('onFindResultReceived', (WidgetTester tester) async { testWidgets('onFindResultReceived', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();

View File

@ -8,10 +8,11 @@ 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, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].contains(defaultTargetPlatform);
testWidgets('onJsBeforeUnload', (WidgetTester tester) async { testWidgets('onJsBeforeUnload', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -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,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('onLoadError', () { group('onLoadError', () {
testWidgets('invalid url', (WidgetTester tester) async { testWidgets('invalid url', (WidgetTester tester) async {

View File

@ -8,11 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void onLoadHttpError() { void onLoadHttpError() {
final shouldSkip = kIsWeb || ![ final shouldSkip = kIsWeb
TargetPlatform.android, ? true
TargetPlatform.iOS, : ![
TargetPlatform.macOS, TargetPlatform.android,
].contains(defaultTargetPlatform); TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('onLoadHttpError', (WidgetTester tester) async { testWidgets('onLoadHttpError', (WidgetTester tester) async {
final Completer<String> errorUrlCompleter = Completer<String>(); final Completer<String> errorUrlCompleter = Completer<String>();
@ -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);
@ -39,4 +40,4 @@ void onLoadHttpError() {
expect(url, TEST_URL_404.toString()); expect(url, TEST_URL_404.toString());
expect(code, 404); expect(code, 404);
}, skip: shouldSkip); }, skip: shouldSkip);
} }

View File

@ -5,15 +5,14 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('onLoadResource', (WidgetTester tester) async { testWidgets('onLoadResource', (WidgetTester tester) async {
List<String> resourceList = [ List<String> resourceList = [

View File

@ -7,12 +7,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('onLoadResourceCustomScheme', (WidgetTester tester) async { testWidgets('onLoadResourceCustomScheme', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();

View File

@ -8,11 +8,12 @@ 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.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group("onNavigationResponse", () { group("onNavigationResponse", () {
testWidgets('allow navigation', (WidgetTester tester) async { testWidgets('allow navigation', (WidgetTester tester) async {
@ -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,25 +8,24 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
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,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var expectedValue = []; var expectedValue = [];
if (defaultTargetPlatform == TargetPlatform.android) { if (defaultTargetPlatform == TargetPlatform.android) {
@ -27,7 +28,7 @@ void onPermissionRequest() {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>(); final Completer<void> pageLoaded = Completer<void>();
final Completer<List<PermissionResourceType>> onPermissionRequestCompleter = final Completer<List<PermissionResourceType>> onPermissionRequestCompleter =
Completer<List<PermissionResourceType>>(); Completer<List<PermissionResourceType>>();
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
@ -44,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);
}, },
), ),
@ -57,7 +59,7 @@ void onPermissionRequest() {
source: "document.querySelector('#camera').click();"); source: "document.querySelector('#camera').click();");
await tester.pump(); await tester.pump();
final List<PermissionResourceType> resources = final List<PermissionResourceType> resources =
await onPermissionRequestCompleter.future; await onPermissionRequestCompleter.future;
expect(listEquals(resources, expectedValue), true); expect(listEquals(resources, expectedValue), true);
}, skip: shouldSkip); }, skip: shouldSkip);

View File

@ -8,11 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void onPrint() { void onPrint() {
final shouldSkip = !kIsWeb || ![ final shouldSkip = kIsWeb
TargetPlatform.android, ? false
TargetPlatform.iOS, : ![
TargetPlatform.macOS, TargetPlatform.android,
].contains(defaultTargetPlatform); TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1;
@ -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();");
}, },
@ -38,4 +39,4 @@ void onPrint() {
final String printUrl = await onPrintCompleter.future; final String printUrl = await onPrintCompleter.future;
expect(printUrl, url.toString()); expect(printUrl, url.toString());
}, skip: shouldSkip); }, skip: shouldSkip);
} }

View File

@ -8,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('onProgressChanged', (WidgetTester tester) async { testWidgets('onProgressChanged', (WidgetTester tester) async {
final Completer<void> onProgressChangedCompleter = Completer<void>(); final Completer<void> onProgressChangedCompleter = Completer<void>();
@ -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, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].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,13 +5,12 @@ 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, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].contains(defaultTargetPlatform);
testWidgets('onReceivedTouchIconUrl', (WidgetTester tester) async { testWidgets('onReceivedTouchIconUrl', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();

View File

@ -8,11 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void onScrollChanged() { void onScrollChanged() {
final shouldSkip = !kIsWeb || ![ final shouldSkip = kIsWeb
TargetPlatform.android, ? false
TargetPlatform.iOS, : ![
TargetPlatform.macOS, TargetPlatform.android,
].contains(defaultTargetPlatform); TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1;
@ -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);
@ -51,4 +51,4 @@ void onScrollChanged() {
await expectLater(onScrollChangedCompleter.future, completes); await expectLater(onScrollChangedCompleter.future, completes);
}, skip: shouldSkip); }, skip: shouldSkip);
} }

View File

@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void onTitleChanged() { void onTitleChanged() {
final shouldSkip = !kIsWeb || final shouldSkip = kIsWeb
![ ? false
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1;
@ -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,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1;

View File

@ -8,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1;

View File

@ -8,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1;

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, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].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, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].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,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('pause/resume timers', (WidgetTester tester) async { testWidgets('pause/resume timers', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -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,17 +10,17 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
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);
}, },
@ -47,12 +45,12 @@ void postRequests() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
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(
@ -83,7 +80,7 @@ void postRequests() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
var postData = Uint8List.fromList(utf8.encode("name=FooBar")); var postData = Uint8List.fromList(utf8.encode("name=FooBar"));
await controller.loadUrl( await controller.loadUrl(
@ -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(
@ -131,7 +125,7 @@ void postRequests() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
var postData = Uint8List.fromList(utf8.encode("name=FooBar")); var postData = Uint8List.fromList(utf8.encode("name=FooBar"));
await controller.postUrl( await controller.postUrl(
@ -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,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1; var url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1;
@ -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,18 +9,22 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void programmaticScroll() { void programmaticScroll() {
final shouldSkip = !kIsWeb || ![ final shouldSkip = kIsWeb
TargetPlatform.android, ? false
TargetPlatform.iOS, : ![
TargetPlatform.macOS, TargetPlatform.android,
].contains(defaultTargetPlatform); TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('Programmatic Scroll', () { group('Programmatic Scroll', () {
final shouldSkipTest1 = !kIsWeb || ![ final shouldSkipTest1 = kIsWeb
TargetPlatform.android, ? false
TargetPlatform.iOS, : ![
TargetPlatform.macOS, TargetPlatform.android,
].contains(defaultTargetPlatform); TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('set and get scroll position', (WidgetTester tester) async { testWidgets('set and get scroll position', (WidgetTester tester) async {
final String scrollTestPage = ''' final String scrollTestPage = '''
@ -45,22 +49,21 @@ 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);
}, },
@ -72,7 +75,7 @@ void programmaticScroll() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await controller.scrollTo(x: 0, y: 0); await controller.scrollTo(x: 0, y: 0);
@ -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>
@ -121,11 +132,10 @@ void programmaticScroll() {
'''; ''';
final String scrollTestPageBase64 = final String scrollTestPageBase64 =
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();
}, },
@ -147,7 +156,7 @@ void programmaticScroll() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await controller.scrollTo(x: 0, y: 0); await controller.scrollTo(x: 0, y: 0);
@ -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.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('programmatic zoom scale', () {
final shouldSkipTest1 = kIsWeb ||
![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
group('programmatic zoom scale', () {
final shouldSkipTest1 = kIsWeb
? true
: ![
TargetPlatform.android,
].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);
}, },
@ -44,7 +44,7 @@ void programmaticZoomScale() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
expect(await controller.zoomIn(), true); expect(await controller.zoomIn(), true);
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));
@ -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);
}, },
@ -81,7 +80,7 @@ void programmaticZoomScale() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
listenForScaleChange = true; listenForScaleChange = true;
@ -100,7 +99,7 @@ void programmaticZoomScale() {
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest:
URLRequest(url: Uri.parse('https://flutter.dev')), URLRequest(url: Uri.parse('https://flutter.dev')),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -112,7 +111,7 @@ void programmaticZoomScale() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await expectLater( await expectLater(
@ -129,7 +128,7 @@ void programmaticZoomScale() {
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest:
URLRequest(url: Uri.parse('https://flutter.dev')), URLRequest(url: Uri.parse('https://flutter.dev')),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -141,7 +140,7 @@ void programmaticZoomScale() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
final scale = await controller.getZoomScale(); final scale = await controller.getZoomScale();

View File

@ -9,12 +9,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('launches with pull-to-refresh feature', testWidgets('launches with pull-to-refresh feature',
(WidgetTester tester) async { (WidgetTester tester) async {
@ -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,21 +8,23 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
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.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('reload from origin', (WidgetTester tester) async { testWidgets('reload from origin', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();

View File

@ -8,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('requestFocusNodeHref', (WidgetTester tester) async { testWidgets('requestFocusNodeHref', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -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,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('requestImageRef', (WidgetTester tester) async { testWidgets('requestImageRef', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -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,14 +6,14 @@ 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
TargetPlatform.android, ? true
TargetPlatform.iOS, : ![
TargetPlatform.macOS, TargetPlatform.android,
].contains(defaultTargetPlatform); TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('resize webview', (WidgetTester tester) async { testWidgets('resize webview', (WidgetTester tester) async {
final String resizeTest = ''' final String resizeTest = '''
@ -33,7 +33,7 @@ void resizeWebView() {
</html> </html>
'''; ''';
final String resizeTestBase64 = final String resizeTestBase64 =
base64Encode(const Utf8Encoder().convert(resizeTest)); base64Encode(const Utf8Encoder().convert(resizeTest));
final Completer<void> resizeCompleter = Completer<void>(); final Completer<void> resizeCompleter = Completer<void>();
final Completer<void> pageStarted = Completer<void>(); final Completer<void> pageStarted = Completer<void>();
final Completer<void> pageLoaded = Completer<void>(); final Completer<void> pageLoaded = Completer<void>();
@ -101,4 +101,4 @@ void resizeWebView() {
await resizeCompleter.future; await resizeCompleter.future;
}, skip: shouldSkip); }, skip: shouldSkip);
} }

View File

@ -8,10 +8,11 @@ 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, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].contains(defaultTargetPlatform);
group('safe browsing', () { group('safe browsing', () {
testWidgets('onSafeBrowsingHit', (WidgetTester tester) async { testWidgets('onSafeBrowsingHit', (WidgetTester tester) async {

View File

@ -8,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('set custom userAgent', (WidgetTester tester) async { testWidgets('set custom userAgent', (WidgetTester tester) async {
final Completer controllerCompleter1 = Completer<InAppWebViewController>(); final Completer controllerCompleter1 = Completer<InAppWebViewController>();

View File

@ -8,11 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart'; import '../constants.dart';
void setGetSettings() { void setGetSettings() {
final shouldSkip = !kIsWeb || ![ final shouldSkip = kIsWeb
TargetPlatform.android, ? false
TargetPlatform.iOS, : ![
TargetPlatform.macOS, TargetPlatform.android,
].contains(defaultTargetPlatform); TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1; final url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1;
@ -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);
@ -64,4 +62,4 @@ void setGetSettings() {
expect(settings.iframeSandbox!.contains(Sandbox.ALLOW_SCRIPTS), true); expect(settings.iframeSandbox!.contains(Sandbox.ALLOW_SCRIPTS), true);
} }
}, skip: shouldSkip); }, skip: shouldSkip);
} }

View File

@ -1,13 +1,13 @@
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, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].contains(defaultTargetPlatform);
test('setWebContentsDebuggingEnabled', () async { test('setWebContentsDebuggingEnabled', () async {
expect( expect(

View File

@ -6,10 +6,11 @@ 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, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].contains(defaultTargetPlatform);
testWidgets('shouldInterceptRequest', (WidgetTester tester) async { testWidgets('shouldInterceptRequest', (WidgetTester tester) async {
List<String> resourceList = [ List<String> resourceList = [

View File

@ -9,12 +9,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('shouldOverrideUrlLoading', () { group('shouldOverrideUrlLoading', () {
final String page = final String page =
@ -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,13 +64,14 @@ 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.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets( testWidgets(
'allow requests on iOS only if navigationType == NavigationType.LINK_ACTIVATED', 'allow requests on iOS only if navigationType == NavigationType.LINK_ACTIVATED',
@ -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,11 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../.env.dart'; import '../.env.dart';
void sslRequest() { void sslRequest() {
final shouldSkip = kIsWeb || ![ final shouldSkip = kIsWeb
TargetPlatform.android, ? true
TargetPlatform.iOS, : ![
TargetPlatform.macOS, TargetPlatform.android,
].contains(defaultTargetPlatform); TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('SSL request', (WidgetTester tester) async { testWidgets('SSL request', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -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,12 +46,11 @@ 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(
source: "document.body.querySelector('h1').textContent"); source: "document.body.querySelector('h1').textContent");
expect(h1Content, "Authorized"); expect(h1Content, "Authorized");
}, skip: shouldSkip); }, skip: shouldSkip);
} }

View File

@ -9,12 +9,13 @@ import '../constants.dart';
import '../util.dart'; import '../util.dart';
void stopLoading() { void stopLoading() {
final shouldSkip = kIsWeb || final shouldSkip = kIsWeb
![ ? true
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('stopLoading', (WidgetTester tester) async { testWidgets('stopLoading', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();

View File

@ -8,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('T-Rex Runner game', (WidgetTester tester) async { testWidgets('T-Rex Runner game', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -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,12 +9,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('user scripts', () { group('user scripts', () {
testWidgets('initialUserScripts', (WidgetTester tester) async { testWidgets('initialUserScripts', (WidgetTester tester) async {

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.iOS, TargetPlatform.android,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('web archive', () {
final shouldSkipTest1 = kIsWeb ||
![
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
group('web archive', () {
final shouldSkipTest1 = kIsWeb
? true
: ![
TargetPlatform.iOS,
TargetPlatform.macOS,
].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);
}, },
@ -48,7 +47,7 @@ void webArchive() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
expect(await controller.createWebArchiveData(), isNotNull); expect(await controller.createWebArchiveData(), isNotNull);
@ -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);
}, },
@ -76,7 +74,7 @@ void webArchive() {
); );
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
// wait a little bit after page load otherwise Android will not save the web archive // wait a little bit after page load otherwise Android will not save the web archive

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.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('web history', () {
final shouldSkipTest1 = kIsWeb ||
![
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 { group('web history', () {
final shouldSkipTest1 = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
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);
@ -118,7 +126,7 @@ void webHistory() {
testWidgets('go back/forward on web platform', (WidgetTester tester) async { testWidgets('go back/forward on web platform', (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();
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
@ -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,24 +173,23 @@ void webHistory() {
pageLoads.close(); pageLoads.close();
}, skip: shouldSkipTest2); }, skip: shouldSkipTest2);
final shouldSkipTest3 = kIsWeb || final shouldSkipTest3 = kIsWeb
![ ? true
TargetPlatform.android, : ![
].contains(defaultTargetPlatform); TargetPlatform.android,
].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();
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_CROSS_PLATFORM_URL_1),
URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -193,11 +201,9 @@ 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,12 +8,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('WebMessage', () { group('WebMessage', () {
testWidgets('WebMessageChannel', (WidgetTester tester) async { testWidgets('WebMessageChannel', (WidgetTester tester) async {

View File

@ -9,21 +9,23 @@ 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.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group("WebView Windows", () {
final shouldSkipTest1 = kIsWeb ||
![
TargetPlatform.android, TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
group("WebView Windows", () {
final shouldSkipTest1 = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('onCreateWindow return false', (WidgetTester tester) async { testWidgets('onCreateWindow return false', (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>();
@ -57,12 +59,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('onCreateWindow return true', (WidgetTester tester) async { testWidgets('onCreateWindow return true', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -127,12 +130,13 @@ 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.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('window.open() with target _blank opens in same window', testWidgets('window.open() with target _blank opens in same window',
(WidgetTester tester) async { (WidgetTester tester) async {
@ -170,70 +174,68 @@ void webViewWindows() {
pageLoads.close(); pageLoads.close();
}, skip: shouldSkipTest3); }, skip: shouldSkipTest3);
final shouldSkipTest4 = kIsWeb || final shouldSkipTest4 = kIsWeb
![ ? true
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].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 StreamController<String> pageLoads =
final Completer controllerCompleter = StreamController<String>.broadcast();
Completer<InAppWebViewController>(); await tester.pumpWidget(
final StreamController<String> pageLoads = Directionality(
StreamController<String>.broadcast(); textDirection: TextDirection.ltr,
await tester.pumpWidget( child: InAppWebView(
Directionality( key: GlobalKey(),
textDirection: TextDirection.ltr, initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
child: InAppWebView( onWebViewCreated: (controller) {
key: GlobalKey(), controllerCompleter.complete(controller);
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1), },
onWebViewCreated: (controller) { initialSettings: InAppWebViewSettings(
controllerCompleter.complete(controller); javaScriptEnabled: true,
}, javaScriptCanOpenWindowsAutomatically: true,
initialSettings: InAppWebViewSettings(
javaScriptEnabled: true,
javaScriptCanOpenWindowsAutomatically: true,
),
onLoadStop: (controller, url) {
pageLoads.add(url!.toString());
},
), ),
onLoadStop: (controller, url) {
pageLoads.add(url!.toString());
},
), ),
); ),
await pageLoads.stream.first; );
final InAppWebViewController controller = await pageLoads.stream.first;
await controllerCompleter.future; final InAppWebViewController controller =
await controllerCompleter.future;
await tester.pump(); await tester.pump();
await controller.evaluateJavascript( await controller.evaluateJavascript(
source: 'window.open("$TEST_URL_1");'); source: 'window.open("$TEST_URL_1");');
await pageLoads.stream.first; await pageLoads.stream.first;
expect( expect(
(await controller.getUrl())?.toString(), contains(TEST_URL_1.host)); (await controller.getUrl())?.toString(), contains(TEST_URL_1.host));
await controller.goBack(); await controller.goBack();
await pageLoads.stream.first; await pageLoads.stream.first;
expect((await controller.getUrl())?.toString(), expect((await controller.getUrl())?.toString(),
contains(TEST_CROSS_PLATFORM_URL_1.host)); contains(TEST_CROSS_PLATFORM_URL_1.host));
pageLoads.close(); pageLoads.close();
}, skip: shouldSkipTest4); }, skip: shouldSkipTest4);
final shouldSkipTest5 = kIsWeb || final shouldSkipTest5 = kIsWeb
![ ? true
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].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>
<script> <script>
window.onload = () => { window.onload = () => {
@ -245,10 +247,10 @@ void webViewWindows() {
}; };
</script> </script>
'''; ''';
final String iframeTestBase64 = final String iframeTestBase64 =
base64Encode(const Utf8Encoder().convert(iframe)); base64Encode(const Utf8Encoder().convert(iframe));
final String openWindowTest = ''' final String openWindowTest = '''
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@ -261,47 +263,46 @@ void webViewWindows() {
</body> </body>
</html> </html>
'''; ''';
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(
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: URLRequest( initialUrlRequest: URLRequest(
url: Uri.parse( url: Uri.parse(
'data:text/html;charset=utf-8;base64,$openWindowTestBase64')), 'data:text/html;charset=utf-8;base64,$openWindowTestBase64')),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
initialSettings: InAppWebViewSettings( initialSettings: InAppWebViewSettings(
javaScriptEnabled: true, javaScriptEnabled: true,
javaScriptCanOpenWindowsAutomatically: true, javaScriptCanOpenWindowsAutomatically: true,
),
onLoadStop: (controller, url) {
pageLoadCompleter.complete();
},
), ),
onLoadStop: (controller, url) {
pageLoadCompleter.complete();
},
), ),
); ),
);
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
await pageLoadCompleter.future; await pageLoadCompleter.future;
expect(controller.evaluateJavascript(source: 'iframeLoaded'), expect(controller.evaluateJavascript(source: 'iframeLoaded'),
completion(true)); completion(true));
expect( expect(
controller.evaluateJavascript( controller.evaluateJavascript(
source: source:
'document.querySelector("p") && document.querySelector("p").textContent'), 'document.querySelector("p") && document.querySelector("p").textContent'),
completion(null), completion(null),
); );
}, skip: shouldSkipTest5); }, skip: shouldSkipTest5);
final shouldSkipTest6 = !kIsWeb; final shouldSkipTest6 = !kIsWeb;
@ -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';