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

View File

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

View File

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

View File

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

View File

@ -8,14 +8,14 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void clearSslPreferences() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
].contains(defaultTargetPlatform);
testWidgets('clearSslPreferences', (WidgetTester tester) async {
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget(
@ -23,8 +23,7 @@ void clearSslPreferences() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -35,8 +34,7 @@ void clearSslPreferences() {
),
);
final InAppWebViewController controller =
await controllerCompleter.future;
final InAppWebViewController controller = await controllerCompleter.future;
await pageLoaded.future;
await expectLater(controller.clearSslPreferences(), completes);
}, skip: shouldSkip);

View File

@ -8,11 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void contentBlocker() {
final shouldSkip = kIsWeb || ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('Content Blocker', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -22,23 +24,22 @@ void contentBlocker() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
initialSettings: InAppWebViewSettings(clearCache: true, contentBlockers: [
ContentBlocker(
trigger:
ContentBlockerTrigger(urlFilter: ".*", resourceType: [
ContentBlockerTriggerResourceType.IMAGE,
ContentBlockerTriggerResourceType.STYLE_SHEET
], ifTopUrl: [
TEST_CROSS_PLATFORM_URL_1.toString()
]),
action: ContentBlockerAction(
type: ContentBlockerActionType.BLOCK))
]),
initialSettings:
InAppWebViewSettings(clearCache: true, contentBlockers: [
ContentBlocker(
trigger: ContentBlockerTrigger(urlFilter: ".*", resourceType: [
ContentBlockerTriggerResourceType.IMAGE,
ContentBlockerTriggerResourceType.STYLE_SHEET
], ifTopUrl: [
TEST_CROSS_PLATFORM_URL_1.toString()
]),
action:
ContentBlockerAction(type: ContentBlockerActionType.BLOCK))
]),
onLoadStop: (controller, url) {
pageLoaded.complete();
},
@ -47,4 +48,4 @@ void contentBlocker() {
);
await expectLater(pageLoaded.future, completes);
}, skip: shouldSkip);
}
}

View File

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

View File

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

View File

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

View File

@ -1,13 +1,13 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart';
void getCurrentWebViewPackage() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
].contains(defaultTargetPlatform);
test('getCurrentWebViewPackage', () async {
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';
void getDefaultUserAgent() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
test('getDefaultUserAgent', () async {
expect(await InAppWebViewController.getDefaultUserAgent(), isNotNull);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,11 +3,12 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart';
void handlesURLScheme() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
test('handlesURLScheme', () async {
expect(await InAppWebViewController.handlesURLScheme("http"), true);

View File

@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../.env.dart';
void httpAuthCredentialDatabase() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('Http Auth Credential Database', () {
testWidgets('use saved credentials', (WidgetTester tester) async {

View File

@ -8,21 +8,23 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void initialUrlRequest() {
final shouldSkip = !kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('initial url request', () {
final shouldSkipTest1 = !kIsWeb ||
![
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('initial url request', () {
final shouldSkipTest1 = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('basic', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
await tester.pumpWidget(
@ -45,11 +47,12 @@ void initialUrlRequest() {
expect(currentUrl, TEST_CROSS_PLATFORM_URL_1.toString());
}, skip: shouldSkipTest1);
final shouldSkipTest2 = kIsWeb ||
![
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkipTest2 = kIsWeb
? true
: ![
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('launches with allowsBackForwardNavigationGestures true',
(WidgetTester tester) async {
@ -62,8 +65,7 @@ void initialUrlRequest() {
height: 300,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: TEST_URL_1),
initialUrlRequest: URLRequest(url: TEST_URL_1),
initialSettings: InAppWebViewSettings(
allowsBackForwardNavigationGestures: true),
onWebViewCreated: (controller) {

View File

@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void injectCSS() {
final shouldSkip = !kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_URL_ABOUT_BLANK : TEST_WEB_PLATFORM_URL_1;
@ -39,7 +40,7 @@ void injectCSS() {
);
final InAppWebViewController controller =
await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future;
await controller.injectCSSCode(source: """
@ -77,7 +78,7 @@ void injectCSS() {
);
final InAppWebViewController controller =
await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future;
await controller.injectCSSFileFromUrl(
@ -112,7 +113,7 @@ void injectCSS() {
);
final InAppWebViewController controller =
await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future;
await controller.injectCSSFileFromAsset(

View File

@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void injectJavascriptFile() {
final shouldSkip = !kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_URL_ABOUT_BLANK : TEST_WEB_PLATFORM_URL_1;
@ -41,12 +42,12 @@ void injectJavascriptFile() {
);
final InAppWebViewController controller =
await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future;
await controller.injectJavascriptFileFromUrl(
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(
id: 'jquery-error',
onError: () {
@ -101,7 +102,7 @@ void injectJavascriptFile() {
);
final InAppWebViewController controller =
await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future;
await controller.injectJavascriptFileFromAsset(

View File

@ -9,12 +9,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../.env.dart';
void interceptAjaxRequest() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('intercept ajax request', () {
testWidgets('send string data', (WidgetTester tester) async {

View File

@ -9,12 +9,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../.env.dart';
void interceptFetchRequest() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('intercept fetch request', () {
testWidgets('send string data', (WidgetTester tester) async {

View File

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

View File

@ -8,27 +8,27 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void isSecureContext() {
final shouldSkip = !kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1;
testWidgets('isSecureContext', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final StreamController<String> pageLoads =
StreamController<String>.broadcast();
StreamController<String>.broadcast();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: url),
initialUrlRequest: URLRequest(url: url),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -39,8 +39,7 @@ void isSecureContext() {
),
);
final InAppWebViewController controller =
await controllerCompleter.future;
final InAppWebViewController controller = await controllerCompleter.future;
await pageLoads.stream.first;
expect(await controller.isSecureContext(), true);

View File

@ -8,21 +8,23 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void javascriptCodeEvaluation() {
final shouldSkip = !kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('javascript code evaluation', () {
final shouldSkipTest1 = !kIsWeb ||
![
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('javascript code evaluation', () {
final shouldSkipTest1 = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('evaluateJavascript', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>();
@ -57,12 +59,13 @@ void javascriptCodeEvaluation() {
mapEquals(result[3]?.cast<String, String>(), {"foo": "baz"}), true);
}, skip: shouldSkipTest1);
final shouldSkipTest2 = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkipTest2 = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('evaluateJavascript with content world',
(WidgetTester tester) async {
@ -100,12 +103,13 @@ void javascriptCodeEvaluation() {
expect(result, 49);
}, skip: shouldSkipTest2);
final shouldSkipTest3 = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkipTest3 = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('callAsyncJavaScript', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -159,12 +163,13 @@ void javascriptCodeEvaluation() {
expect(result.error, 'error message');
}, skip: shouldSkipTest3);
final shouldSkipTest4 = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkipTest4 = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('callAsyncJavaScript with content world',
(WidgetTester tester) async {

View File

@ -5,15 +5,14 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void javascriptDialogs() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('javascript dialogs', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();

View File

@ -8,11 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../util.dart';
void javascriptHandler() {
final shouldSkip = kIsWeb || ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('JavaScript Handler', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -27,7 +29,7 @@ void javascriptHandler() {
child: InAppWebView(
key: GlobalKey(),
initialFile:
"test_assets/in_app_webview_javascript_handler_test.html",
"test_assets/in_app_webview_javascript_handler_test.html",
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
@ -44,10 +46,10 @@ void javascriptHandler() {
messagesReceived.add(args[0] as int);
messagesReceived.add(args[1] as bool);
messagesReceived.add(args[2] as List<dynamic>?);
messagesReceived.add(args[3]?.cast<String, String>()
as Map<String, String>?);
messagesReceived.add(args[4]?.cast<String, String>()
as Map<String, String>?);
messagesReceived.add(
args[3]?.cast<String, String>() as Map<String, String>?);
messagesReceived.add(
args[4]?.cast<String, String>() as Map<String, String>?);
handlerFooWithArgs.complete();
});
},
@ -69,12 +71,11 @@ void javascriptHandler() {
expect(messagesReceived[0], 1);
expect(messagesReceived[1], true);
expect(
listEquals(messagesReceived[2] as List<dynamic>?, ["bar", 5]), true);
expect(listEquals(messagesReceived[2] as List<dynamic>?, ["bar", 5]), true);
expect(mapEquals(messagesReceived[3], {"foo": "baz"}), true);
expect(
mapEquals(
messagesReceived[4], {"bar": "bar_value", "baz": "baz_value"}),
true);
}, skip: shouldSkip);
}
}

View File

@ -8,17 +8,18 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void loadData() {
final shouldSkip = !kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('loadData', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final StreamController<String> pageLoads =
StreamController<String>.broadcast();
StreamController<String>.broadcast();
await tester.pumpWidget(
Directionality(
@ -36,8 +37,7 @@ void loadData() {
),
);
final InAppWebViewController controller =
await controllerCompleter.future;
final InAppWebViewController controller = await controllerCompleter.future;
await pageLoads.stream.first;
final data = """
@ -70,7 +70,7 @@ void loadData() {
if (!kIsWeb) {
expect(currentUrl, TEST_CROSS_PLATFORM_URL_1.toString());
} else {
expect(currentUrl, 'data:$mimeType,' + Uri.encodeFull(data)) ;
expect(currentUrl, 'data:$mimeType,' + Uri.encodeFull(data));
}
pageLoads.close();

View File

@ -8,17 +8,18 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void loadFile() {
final shouldSkip = !kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('loadFile', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final StreamController<String> pageLoads =
StreamController<String>.broadcast();
StreamController<String>.broadcast();
await tester.pumpWidget(
Directionality(
@ -36,8 +37,7 @@ void loadFile() {
),
);
final InAppWebViewController controller =
await controllerCompleter.future;
final InAppWebViewController controller = await controllerCompleter.future;
await pageLoads.stream.first;
await controller.loadFile(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void onLoadError() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('onLoadError', () {
testWidgets('invalid url', (WidgetTester tester) async {

View File

@ -8,11 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void onLoadHttpError() {
final shouldSkip = kIsWeb || ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('onLoadHttpError', (WidgetTester tester) async {
final Completer<String> errorUrlCompleter = Completer<String>();
@ -23,8 +25,7 @@ void onLoadHttpError() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: TEST_URL_404),
initialUrlRequest: URLRequest(url: TEST_URL_404),
onLoadHttpError: (controller, url, statusCode, description) async {
errorUrlCompleter.complete(url.toString());
statusCodeCompleter.complete(statusCode);
@ -39,4 +40,4 @@ void onLoadHttpError() {
expect(url, TEST_URL_404.toString());
expect(code, 404);
}, skip: shouldSkip);
}
}

View File

@ -5,15 +5,14 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void onLoadResource() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('onLoadResource', (WidgetTester tester) async {
List<String> resourceList = [

View File

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

View File

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

View File

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

View File

@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void onPermissionRequest() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var expectedValue = [];
if (defaultTargetPlatform == TargetPlatform.android) {
@ -27,7 +28,7 @@ void onPermissionRequest() {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>();
final Completer<List<PermissionResourceType>> onPermissionRequestCompleter =
Completer<List<PermissionResourceType>>();
Completer<List<PermissionResourceType>>();
await tester.pumpWidget(
Directionality(
@ -44,7 +45,8 @@ void onPermissionRequest() {
onPermissionRequest:
(controller, PermissionRequest permissionRequest) async {
onPermissionRequestCompleter.complete(permissionRequest.resources);
return PermissionResponse(resources: permissionRequest.resources,
return PermissionResponse(
resources: permissionRequest.resources,
action: PermissionResponseAction.GRANT);
},
),
@ -57,7 +59,7 @@ void onPermissionRequest() {
source: "document.querySelector('#camera').click();");
await tester.pump();
final List<PermissionResourceType> resources =
await onPermissionRequestCompleter.future;
await onPermissionRequestCompleter.future;
expect(listEquals(resources, expectedValue), true);
}, skip: shouldSkip);

View File

@ -8,11 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void onPrint() {
final shouldSkip = !kIsWeb || ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1;
@ -23,8 +25,7 @@ void onPrint() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: url),
initialUrlRequest: URLRequest(url: url),
onLoadStop: (controller, url) async {
await controller.evaluateJavascript(source: "window.print();");
},
@ -38,4 +39,4 @@ void onPrint() {
final String printUrl = await onPrintCompleter.future;
expect(printUrl, url.toString());
}, skip: shouldSkip);
}
}

View File

@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void onProgressChanged() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('onProgressChanged', (WidgetTester tester) async {
final Completer<void> onProgressChangedCompleter = Completer<void>();
@ -22,8 +23,7 @@ void onProgressChanged() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: TEST_URL_1),
initialUrlRequest: URLRequest(url: TEST_URL_1),
initialSettings: InAppWebViewSettings(
clearCache: true,
),

View File

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

View File

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

View File

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

View File

@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void onUpdateVisitedHistory() {
final shouldSkip = !kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
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';
void onWindowBlur() {
final shouldSkip = !kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
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';
void onWindowFocus() {
final shouldSkip = !kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
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';
void pageDownUp() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
].contains(defaultTargetPlatform);
testWidgets('pageDown/pageUp', (WidgetTester tester) async {
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget(
@ -23,8 +23,7 @@ void pageDownUp() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -35,8 +34,7 @@ void pageDownUp() {
),
);
final InAppWebViewController controller =
await controllerCompleter.future;
final InAppWebViewController controller = await controllerCompleter.future;
await pageLoaded.future;
expect(await controller.pageDown(bottom: false), true);
await Future.delayed(Duration(seconds: 1));

View File

@ -8,14 +8,14 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void pauseResume() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
].contains(defaultTargetPlatform);
testWidgets('pause/resume', (WidgetTester tester) async {
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget(
@ -23,8 +23,7 @@ void pauseResume() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -35,8 +34,7 @@ void pauseResume() {
),
);
final InAppWebViewController controller =
await controllerCompleter.future;
final InAppWebViewController controller = await controllerCompleter.future;
await pageLoaded.future;
await expectLater(controller.pause(), completes);
await Future.delayed(Duration(seconds: 1));

View File

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

View File

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

View File

@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void printCurrentPage() {
final shouldSkip = !kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1;
@ -26,8 +27,7 @@ void printCurrentPage() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: url),
initialUrlRequest: URLRequest(url: url),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -38,8 +38,7 @@ void printCurrentPage() {
),
);
final InAppWebViewController controller =
await controllerCompleter.future;
final InAppWebViewController controller = await controllerCompleter.future;
await pageLoaded.future;
await tester.pump();
await expectLater(controller.printCurrentPage(), completes);

View File

@ -9,18 +9,22 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void programmaticScroll() {
final shouldSkip = !kIsWeb || ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('Programmatic Scroll', () {
final shouldSkipTest1 = !kIsWeb || ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkipTest1 = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('set and get scroll position', (WidgetTester tester) async {
final String scrollTestPage = '''
@ -45,22 +49,21 @@ void programmaticScroll() {
''';
final String scrollTestPageBase64 =
base64Encode(const Utf8Encoder().convert(scrollTestPage));
base64Encode(const Utf8Encoder().convert(scrollTestPage));
var url = !kIsWeb ? Uri.parse(
'data:text/html;charset=utf-8;base64,$scrollTestPageBase64') :
TEST_WEB_PLATFORM_URL_1;
var url = !kIsWeb
? Uri.parse(
'data:text/html;charset=utf-8;base64,$scrollTestPageBase64')
: TEST_WEB_PLATFORM_URL_1;
final Completer<void> pageLoaded = Completer<void>();
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer controllerCompleter = Completer<InAppWebViewController>();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
initialUrlRequest: URLRequest(
url: url),
initialUrlRequest: URLRequest(url: url),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -72,7 +75,7 @@ void programmaticScroll() {
);
final InAppWebViewController controller =
await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future;
await controller.scrollTo(x: 0, y: 0);
@ -98,7 +101,15 @@ void programmaticScroll() {
expect(scrollPosY, Y_SCROLL * 2);
}, 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 = '''
<!DOCTYPE html>
<html>
@ -121,11 +132,10 @@ void programmaticScroll() {
''';
final String scrollTestPageBase64 =
base64Encode(const Utf8Encoder().convert(scrollTestPage));
base64Encode(const Utf8Encoder().convert(scrollTestPage));
final Completer<void> pageLoaded = Completer<void>();
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer controllerCompleter = Completer<InAppWebViewController>();
await tester.pumpWidget(
Directionality(
@ -137,8 +147,7 @@ void programmaticScroll() {
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
initialSettings: InAppWebViewSettings(
useHybridComposition: false),
initialSettings: InAppWebViewSettings(useHybridComposition: false),
onLoadStop: (controller, url) {
pageLoaded.complete();
},
@ -147,7 +156,7 @@ void programmaticScroll() {
);
final InAppWebViewController controller =
await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future;
await controller.scrollTo(x: 0, y: 0);
@ -171,6 +180,6 @@ void programmaticScroll() {
scrollPosY = await controller.getScrollY();
expect(scrollPosX, X_SCROLL * 2);
expect(scrollPosY, Y_SCROLL * 2);
}, skip: defaultTargetPlatform != TargetPlatform.android);
}, skip: shouldSkipTest2);
}, skip: shouldSkip);
}
}

View File

@ -8,22 +8,23 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void programmaticZoomScale() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('programmatic zoom scale', () {
final shouldSkipTest1 = kIsWeb ||
![
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('programmatic zoom scale', () {
final shouldSkipTest1 = kIsWeb
? true
: ![
TargetPlatform.android,
].contains(defaultTargetPlatform);
testWidgets('zoomIn/zoomOut', (WidgetTester tester) async {
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget(
@ -31,8 +32,7 @@ void programmaticZoomScale() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -44,7 +44,7 @@ void programmaticZoomScale() {
);
final InAppWebViewController controller =
await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future;
expect(await controller.zoomIn(), true);
await Future.delayed(Duration(seconds: 1));
@ -63,8 +63,7 @@ void programmaticZoomScale() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: TEST_URL_1),
initialUrlRequest: URLRequest(url: TEST_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -81,7 +80,7 @@ void programmaticZoomScale() {
);
final InAppWebViewController controller =
await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future;
listenForScaleChange = true;
@ -100,7 +99,7 @@ void programmaticZoomScale() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: Uri.parse('https://flutter.dev')),
URLRequest(url: Uri.parse('https://flutter.dev')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -112,7 +111,7 @@ void programmaticZoomScale() {
);
final InAppWebViewController controller =
await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future;
await expectLater(
@ -129,7 +128,7 @@ void programmaticZoomScale() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: Uri.parse('https://flutter.dev')),
URLRequest(url: Uri.parse('https://flutter.dev')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -141,7 +140,7 @@ void programmaticZoomScale() {
);
final InAppWebViewController controller =
await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future;
final scale = await controller.getZoomScale();

View File

@ -9,12 +9,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void pullToRefresh() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('launches with pull-to-refresh feature',
(WidgetTester tester) async {
@ -36,8 +37,7 @@ void pullToRefresh() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: TEST_URL_1),
initialUrlRequest: URLRequest(url: TEST_URL_1),
pullToRefreshController: pullToRefreshController,
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);

View File

@ -8,21 +8,23 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void reload() {
final shouldSkip = !kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1;
group('reload', () {
final shouldSkipTest1 = kIsWeb ||
![
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkipTest1 = kIsWeb
? true
: ![
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('reload from origin', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();

View File

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

View File

@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void requestImageRef() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('requestImageRef', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -24,8 +25,7 @@ void requestImageRef() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -36,8 +36,7 @@ void requestImageRef() {
),
);
final InAppWebViewController controller =
await controllerCompleter.future;
final InAppWebViewController controller = await controllerCompleter.future;
await pageLoaded.future;
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_test/flutter_test.dart';
import '../constants.dart';
void resizeWebView() {
final shouldSkip = kIsWeb || ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('resize webview', (WidgetTester tester) async {
final String resizeTest = '''
@ -33,7 +33,7 @@ void resizeWebView() {
</html>
''';
final String resizeTestBase64 =
base64Encode(const Utf8Encoder().convert(resizeTest));
base64Encode(const Utf8Encoder().convert(resizeTest));
final Completer<void> resizeCompleter = Completer<void>();
final Completer<void> pageStarted = Completer<void>();
final Completer<void> pageLoaded = Completer<void>();
@ -101,4 +101,4 @@ void resizeWebView() {
await resizeCompleter.future;
}, skip: shouldSkip);
}
}

View File

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

View File

@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void setCustomUserAgent() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('set custom userAgent', (WidgetTester tester) async {
final Completer controllerCompleter1 = Completer<InAppWebViewController>();

View File

@ -8,11 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void setGetSettings() {
final shouldSkip = !kIsWeb || ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1;
@ -25,11 +27,8 @@ void setGetSettings() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: url),
initialSettings: InAppWebViewSettings(
javaScriptEnabled: false
),
initialUrlRequest: URLRequest(url: url),
initialSettings: InAppWebViewSettings(javaScriptEnabled: false),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -39,8 +38,7 @@ void setGetSettings() {
),
),
);
final InAppWebViewController controller =
await controllerCompleter.future;
final InAppWebViewController controller = await controllerCompleter.future;
await pageLoaded.future;
InAppWebViewSettings? settings = await controller.getSettings();
@ -52,8 +50,8 @@ void setGetSettings() {
expect(settings.iframeSandbox!.contains(Sandbox.ALLOW_SCRIPTS), false);
}
await controller.setSettings(settings: InAppWebViewSettings(
javaScriptEnabled: true));
await controller.setSettings(
settings: InAppWebViewSettings(javaScriptEnabled: true));
settings = await controller.getSettings();
expect(settings, isNotNull);
@ -64,4 +62,4 @@ void setGetSettings() {
expect(settings.iframeSandbox!.contains(Sandbox.ALLOW_SCRIPTS), true);
}
}, skip: shouldSkip);
}
}

View File

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

View File

@ -6,10 +6,11 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart';
void shouldInterceptRequest() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
].contains(defaultTargetPlatform);
testWidgets('shouldInterceptRequest', (WidgetTester tester) async {
List<String> resourceList = [

View File

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

View File

@ -8,11 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../.env.dart';
void sslRequest() {
final shouldSkip = kIsWeb || ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('SSL request', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -23,8 +25,7 @@ void sslRequest() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url: Uri.parse(
"https://${environment["NODE_SERVER_IP"]}:4433/")),
url: Uri.parse("https://${environment["NODE_SERVER_IP"]}:4433/")),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -45,12 +46,11 @@ void sslRequest() {
),
),
);
final InAppWebViewController controller =
await controllerCompleter.future;
final InAppWebViewController controller = await controllerCompleter.future;
await pageLoaded.future;
final String h1Content = await controller.evaluateJavascript(
source: "document.body.querySelector('h1').textContent");
expect(h1Content, "Authorized");
}, skip: shouldSkip);
}
}

View File

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

View File

@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void tRexRunnerGame() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('T-Rex Runner game', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -35,12 +36,11 @@ void tRexRunnerGame() {
),
);
final InAppWebViewController controller =
await controllerCompleter.future;
await pageLoaded.future;
var html = await controller.getTRexRunnerHtml();
var css = await controller.getTRexRunnerCss();
var html = await InAppWebViewController.tRexRunnerHtml;
var css = await InAppWebViewController.tRexRunnerCss;
expect(html, isNotNull);
expect(css, isNotNull);

View File

@ -9,12 +9,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void userScripts() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('user scripts', () {
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';
void videoPlaybackPolicy() {
final shouldSkip = kIsWeb ||
final shouldSkip = kIsWeb ? true :
![
TargetPlatform.android,
TargetPlatform.iOS,

View File

@ -10,24 +10,24 @@ import 'package:path_provider/path_provider.dart';
import '../constants.dart';
void webArchive() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('web archive', () {
final shouldSkipTest1 = kIsWeb ||
![
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('web archive', () {
final shouldSkipTest1 = kIsWeb
? true
: ![
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('create data', (WidgetTester tester) async {
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget(
@ -35,8 +35,7 @@ void webArchive() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -48,7 +47,7 @@ void webArchive() {
);
final InAppWebViewController controller =
await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future;
expect(await controller.createWebArchiveData(), isNotNull);
@ -63,8 +62,7 @@ void webArchive() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: TEST_URL_1),
initialUrlRequest: URLRequest(url: TEST_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -76,7 +74,7 @@ void webArchive() {
);
final InAppWebViewController controller =
await controllerCompleter.future;
await controllerCompleter.future;
await pageLoaded.future;
// 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';
void webHistory() {
final shouldSkip = !kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('web history', () {
final shouldSkipTest1 = kIsWeb ||
![
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].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>();
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));
var url = (await controller.getUrl()).toString();
@ -50,10 +54,10 @@ void webHistory() {
expect(url, TEST_CROSS_PLATFORM_URL_1.toString());
expect(webHistory!.currentIndex, 0);
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(
urlRequest: URLRequest(url: TEST_URL_1));
await controller.loadUrl(urlRequest: URLRequest(url: TEST_URL_1));
await Future.delayed(Duration(seconds: 1));
url = (await controller.getUrl()).toString();
webHistory = await controller.getCopyBackForwardList();
@ -64,7 +68,8 @@ void webHistory() {
expect(await controller.canGoBackOrForward(steps: 1), false);
expect(webHistory!.currentIndex, 1);
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());
await Future.delayed(Duration(seconds: 1));
@ -79,7 +84,8 @@ void webHistory() {
expect(await controller.canGoBackOrForward(steps: 1), true);
expect(webHistory!.currentIndex, 0);
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());
await Future.delayed(Duration(seconds: 1));
@ -94,7 +100,8 @@ void webHistory() {
expect(await controller.canGoBackOrForward(steps: 1), false);
expect(webHistory!.currentIndex, 1);
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());
await Future.delayed(Duration(seconds: 1));
@ -109,7 +116,8 @@ void webHistory() {
expect(await controller.canGoBackOrForward(steps: 1), true);
expect(webHistory!.currentIndex, 0);
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());
}, skip: shouldSkipTest1);
@ -118,7 +126,7 @@ void webHistory() {
testWidgets('go back/forward on web platform', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final StreamController<String> pageLoads =
StreamController<String>.broadcast();
StreamController<String>.broadcast();
await tester.pumpWidget(
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;
expect(url, TEST_WEB_PLATFORM_URL_1.toString());
@ -164,24 +173,23 @@ void webHistory() {
pageLoads.close();
}, skip: shouldSkipTest2);
final shouldSkipTest3 = kIsWeb ||
![
TargetPlatform.android,
].contains(defaultTargetPlatform);
final shouldSkipTest3 = kIsWeb
? true
: ![
TargetPlatform.android,
].contains(defaultTargetPlatform);
testWidgets('clearHistory', (WidgetTester tester) async {
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer controllerCompleter = Completer<InAppWebViewController>();
final StreamController<String> pageLoads =
StreamController<String>.broadcast();
StreamController<String>.broadcast();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -193,11 +201,9 @@ void webHistory() {
);
final InAppWebViewController controller =
await controllerCompleter.future;
await controllerCompleter.future;
await pageLoads.stream.first;
await controller.loadUrl(
urlRequest:
URLRequest(url: TEST_URL_1));
await controller.loadUrl(urlRequest: URLRequest(url: TEST_URL_1));
await pageLoads.stream.first;
var webHistory = await controller.getCopyBackForwardList();

View File

@ -8,12 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void webMessage() {
final shouldSkip = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('WebMessage', () {
testWidgets('WebMessageChannel', (WidgetTester tester) async {

View File

@ -9,21 +9,23 @@ import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void webViewWindows() {
final shouldSkip = !kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group("WebView Windows", () {
final shouldSkipTest1 = kIsWeb ||
![
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group("WebView Windows", () {
final shouldSkipTest1 = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('onCreateWindow return false', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>();
@ -57,12 +59,13 @@ void webViewWindows() {
await expectLater(pageLoaded.future, completes);
}, skip: shouldSkipTest1);
final shouldSkipTest2 = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkipTest2 = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('onCreateWindow return true', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
@ -127,12 +130,13 @@ void webViewWindows() {
await expectLater(onCloseWindowCompleter.future, completes);
}, skip: shouldSkipTest2);
final shouldSkipTest3 = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkipTest3 = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('window.open() with target _blank opens in same window',
(WidgetTester tester) async {
@ -170,70 +174,68 @@ void webViewWindows() {
pageLoads.close();
}, skip: shouldSkipTest3);
final shouldSkipTest4 = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkipTest4 = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets(
'can open new window and go back',
(WidgetTester tester) async {
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final StreamController<String> pageLoads =
StreamController<String>.broadcast();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
initialSettings: InAppWebViewSettings(
javaScriptEnabled: true,
javaScriptCanOpenWindowsAutomatically: true,
),
onLoadStop: (controller, url) {
pageLoads.add(url!.toString());
},
testWidgets('can open new window and go back', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final StreamController<String> pageLoads =
StreamController<String>.broadcast();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
initialSettings: InAppWebViewSettings(
javaScriptEnabled: true,
javaScriptCanOpenWindowsAutomatically: true,
),
onLoadStop: (controller, url) {
pageLoads.add(url!.toString());
},
),
);
await pageLoads.stream.first;
final InAppWebViewController controller =
await controllerCompleter.future;
),
);
await pageLoads.stream.first;
final InAppWebViewController controller =
await controllerCompleter.future;
await tester.pump();
await tester.pump();
await controller.evaluateJavascript(
source: 'window.open("$TEST_URL_1");');
await pageLoads.stream.first;
expect(
(await controller.getUrl())?.toString(), contains(TEST_URL_1.host));
await controller.evaluateJavascript(
source: 'window.open("$TEST_URL_1");');
await pageLoads.stream.first;
expect(
(await controller.getUrl())?.toString(), contains(TEST_URL_1.host));
await controller.goBack();
await pageLoads.stream.first;
expect((await controller.getUrl())?.toString(),
contains(TEST_CROSS_PLATFORM_URL_1.host));
await controller.goBack();
await pageLoads.stream.first;
expect((await controller.getUrl())?.toString(),
contains(TEST_CROSS_PLATFORM_URL_1.host));
pageLoads.close();
}, skip: shouldSkipTest4);
pageLoads.close();
}, skip: shouldSkipTest4);
final shouldSkipTest5 = kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
final shouldSkipTest5 = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets(
'javascript does not run in parent window',
(WidgetTester tester) async {
final String iframe = '''
testWidgets('javascript does not run in parent window',
(WidgetTester tester) async {
final String iframe = '''
<!DOCTYPE html>
<script>
window.onload = () => {
@ -245,10 +247,10 @@ void webViewWindows() {
};
</script>
''';
final String iframeTestBase64 =
base64Encode(const Utf8Encoder().convert(iframe));
final String iframeTestBase64 =
base64Encode(const Utf8Encoder().convert(iframe));
final String openWindowTest = '''
final String openWindowTest = '''
<!DOCTYPE html>
<html>
<head>
@ -261,47 +263,46 @@ void webViewWindows() {
</body>
</html>
''';
final String openWindowTestBase64 =
base64Encode(const Utf8Encoder().convert(openWindowTest));
final Completer controllerCompleter =
Completer<InAppWebViewController>();
final Completer<void> pageLoadCompleter = Completer<void>();
final String openWindowTestBase64 =
base64Encode(const Utf8Encoder().convert(openWindowTest));
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoadCompleter = Completer<void>();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url: Uri.parse(
'data:text/html;charset=utf-8;base64,$openWindowTestBase64')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
initialSettings: InAppWebViewSettings(
javaScriptEnabled: true,
javaScriptCanOpenWindowsAutomatically: true,
),
onLoadStop: (controller, url) {
pageLoadCompleter.complete();
},
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url: Uri.parse(
'data:text/html;charset=utf-8;base64,$openWindowTestBase64')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
initialSettings: InAppWebViewSettings(
javaScriptEnabled: true,
javaScriptCanOpenWindowsAutomatically: true,
),
onLoadStop: (controller, url) {
pageLoadCompleter.complete();
},
),
);
),
);
final InAppWebViewController controller =
await controllerCompleter.future;
await pageLoadCompleter.future;
final InAppWebViewController controller =
await controllerCompleter.future;
await pageLoadCompleter.future;
expect(controller.evaluateJavascript(source: 'iframeLoaded'),
completion(true));
expect(
controller.evaluateJavascript(
source:
'document.querySelector("p") && document.querySelector("p").textContent'),
completion(null),
);
}, skip: shouldSkipTest5);
expect(controller.evaluateJavascript(source: 'iframeLoaded'),
completion(true));
expect(
controller.evaluateJavascript(
source:
'document.querySelector("p") && document.querySelector("p").textContent'),
completion(null),
);
}, skip: shouldSkipTest5);
final shouldSkipTest6 = !kIsWeb;
@ -322,15 +323,18 @@ void webViewWindows() {
controllerCompleter.complete(controller);
},
onCreateWindow: (controller, createNavigationAction) async {
onCreateWindowCalled.complete(createNavigationAction.request.url.toString());
onCreateWindowCalled
.complete(createNavigationAction.request.url.toString());
return false;
},
),
),
);
final InAppWebViewController controller = await controllerCompleter.future;
await controller.evaluateJavascript(source: "window.open('$TEST_CROSS_PLATFORM_URL_1')");
final InAppWebViewController controller =
await controllerCompleter.future;
await controller.evaluateJavascript(
source: "window.open('$TEST_CROSS_PLATFORM_URL_1')");
var url = await onCreateWindowCalled.future;
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_APPLICATION_PATH=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example"
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_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
export "DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"

View File

@ -23,8 +23,11 @@ class ServiceWorkerController {
ServiceWorkerClient? get serviceWorkerClient => _serviceWorkerClient;
///Sets the service worker client
setServiceWorkerClient(ServiceWorkerClient? value) async {
///Sets the service worker client.
///
///**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>{};
args.putIfAbsent('isNull', () => value == null);
await _channel.invokeMethod("setServiceWorkerClient", args);

View File

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

View File

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