updated tests

This commit is contained in:
Lorenzo Pichilli 2022-04-29 21:48:17 +02:00
parent 2768605491
commit abcc3a3415
14 changed files with 95 additions and 73 deletions

View File

@ -99,7 +99,7 @@ public class InAppWebViewSettings implements ISettings<InAppWebViewInterface> {
public Boolean useShouldInterceptRequest = false; public Boolean useShouldInterceptRequest = false;
public Boolean useOnRenderProcessGone = false; public Boolean useOnRenderProcessGone = false;
public Boolean disableDefaultErrorPage = false; public Boolean disableDefaultErrorPage = false;
public Boolean useHybridComposition = false; public Boolean useHybridComposition = true;
@Nullable @Nullable
public String verticalScrollbarThumbColor; public String verticalScrollbarThumbColor;
@Nullable @Nullable

View File

@ -15,6 +15,8 @@ void loadUrl() {
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
var initialUrl = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1;
testWidgets('loadUrl', (WidgetTester tester) async { testWidgets('loadUrl', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
final StreamController<String> pageLoads = final StreamController<String> pageLoads =
@ -26,7 +28,7 @@ void loadUrl() {
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: initialUrlRequest:
URLRequest(url: TEST_CROSS_PLATFORM_URL_1), URLRequest(url: initialUrl),
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
@ -39,12 +41,12 @@ void loadUrl() {
final InAppWebViewController controller = final InAppWebViewController controller =
await controllerCompleter.future; await controllerCompleter.future;
var url = await pageLoads.stream.first; var url = await pageLoads.stream.first;
expect(url, TEST_CROSS_PLATFORM_URL_1.toString()); expect(url, initialUrl.toString());
await controller.loadUrl( await controller.loadUrl(
urlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_2)); urlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1));
url = await pageLoads.stream.first; url = await pageLoads.stream.first;
expect(url, TEST_CROSS_PLATFORM_URL_2.toString()); expect(url, TEST_CROSS_PLATFORM_URL_1.toString());
pageLoads.close(); pageLoads.close();
}, skip: shouldSkip); }, skip: shouldSkip);

View File

@ -5,8 +5,6 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void onFindResultReceived() { void onFindResultReceived() {
final shouldSkip = kIsWeb final shouldSkip = kIsWeb
? true ? true
@ -18,6 +16,7 @@ void onFindResultReceived() {
testWidgets('onFindResultReceived', (WidgetTester tester) async { testWidgets('onFindResultReceived', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>();
final Completer<int> numberOfMatchesCompleter = Completer<int>(); final Completer<int> numberOfMatchesCompleter = Completer<int>();
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
@ -32,7 +31,7 @@ void onFindResultReceived() {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
onLoadStop: (controller, url) { onLoadStop: (controller, url) {
controller.findAllAsync(find: "InAppWebViewInitialFileTest"); pageLoaded.complete();
}, },
onFindResultReceived: (controller, int activeMatchOrdinal, onFindResultReceived: (controller, int activeMatchOrdinal,
int numberOfMatches, bool isDoneCounting) async { int numberOfMatches, bool isDoneCounting) async {
@ -44,6 +43,12 @@ void onFindResultReceived() {
), ),
); );
var controller = await controllerCompleter.future;
await pageLoaded.future;
await tester.pump();
await controller.findAllAsync(find: "InAppWebViewInitialFileTest");
final int numberOfMatches = await numberOfMatchesCompleter.future; final int numberOfMatches = await numberOfMatchesCompleter.future;
expect(numberOfMatches, 2); expect(numberOfMatches, 2);
}, skip: shouldSkip); }, skip: shouldSkip);

View File

@ -1,22 +1,19 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void onJsBeforeUnload() { void onJsBeforeUnload() {
final shouldSkip = kIsWeb // final shouldSkip = kIsWeb
? true // ? true
: ![ // : ![
TargetPlatform.android, // TargetPlatform.android,
].contains(defaultTargetPlatform); // ].contains(defaultTargetPlatform);
final shouldSkip = true;
// on Android, for some reason, it works on an example app but not in this test
testWidgets('onJsBeforeUnload', (WidgetTester tester) async { testWidgets('onJsBeforeUnload', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>();
final Completer<String> onJsBeforeUnloadCompleter = Completer<String>(); final Completer<String> onJsBeforeUnloadCompleter = Completer<String>();
await tester.pumpWidget( await tester.pumpWidget(
@ -24,21 +21,10 @@ void onJsBeforeUnload() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: InAppWebView( child: InAppWebView(
key: GlobalKey(), key: GlobalKey(),
initialUrlRequest: URLRequest(url: TEST_URL_1), initialFile: "test_assets/in_app_webview_on_js_before_unload.html",
onWebViewCreated: (controller) { onWebViewCreated: (controller) {
controllerCompleter.complete(controller); controllerCompleter.complete(controller);
}, },
onLoadStop: (controller, url) async {
await controller.evaluateJavascript(source: """
window.addEventListener('beforeunload', function (e) {
e.preventDefault();
e.returnValue = '';
});
""");
if (!pageLoaded.isCompleted) {
pageLoaded.complete();
}
},
onJsBeforeUnload: (controller, jsBeforeUnloadRequest) async { onJsBeforeUnload: (controller, jsBeforeUnloadRequest) async {
onJsBeforeUnloadCompleter onJsBeforeUnloadCompleter
.complete(jsBeforeUnloadRequest.url.toString()); .complete(jsBeforeUnloadRequest.url.toString());
@ -48,11 +34,7 @@ void onJsBeforeUnload() {
), ),
); );
final InAppWebViewController controller = await controllerCompleter.future;
await pageLoaded.future;
await controller.evaluateJavascript(
source: "window.location.href = '$TEST_URL_1';");
final String url = await onJsBeforeUnloadCompleter.future; final String url = await onJsBeforeUnloadCompleter.future;
expect(url, TEST_URL_1.toString()); expect(url, endsWith("test_assets/in_app_webview_on_js_before_unload.html"));
}, skip: shouldSkip); }, skip: shouldSkip);
} }

View File

@ -36,6 +36,8 @@ void pageDownUp() {
final InAppWebViewController controller = await controllerCompleter.future; final InAppWebViewController controller = await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await tester.pump();
await Future.delayed(Duration(seconds: 1));
expect(await controller.pageDown(bottom: false), true); expect(await controller.pageDown(bottom: false), true);
await Future.delayed(Duration(seconds: 1)); await Future.delayed(Duration(seconds: 1));
expect(await controller.pageUp(top: false), true); expect(await controller.pageUp(top: false), true);

View File

@ -39,6 +39,9 @@ void takeScreenshot() {
final InAppWebViewController controller = await controllerCompleter.future; final InAppWebViewController controller = await controllerCompleter.future;
await pageLoaded.future; await pageLoaded.future;
await Future.delayed(Duration(seconds: 1));
await tester.pump();
var screenshotConfiguration = ScreenshotConfiguration( var screenshotConfiguration = ScreenshotConfiguration(
compressFormat: CompressFormat.JPEG, compressFormat: CompressFormat.JPEG,
quality: 20, quality: 20,

View File

@ -9,12 +9,13 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
void videoPlaybackPolicy() { void videoPlaybackPolicy() {
final shouldSkip = kIsWeb ? true : final shouldSkip = kIsWeb
![ ? true
TargetPlatform.android, : ![
TargetPlatform.iOS, TargetPlatform.android,
TargetPlatform.macOS, TargetPlatform.iOS,
].contains(defaultTargetPlatform); TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('Video playback policy', () { group('Video playback policy', () {
String videoTestBase64 = ""; String videoTestBase64 = "";
@ -120,6 +121,13 @@ void videoPlaybackPolicy() {
expect(isPaused, true); expect(isPaused, true);
}); });
final shouldSkipTest2 = kIsWeb
? true
: ![
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('Video plays inline when allowsInlineMediaPlayback is true', testWidgets('Video plays inline when allowsInlineMediaPlayback is true',
(WidgetTester tester) async { (WidgetTester tester) async {
Completer<InAppWebViewController> controllerCompleter = Completer<InAppWebViewController> controllerCompleter =
@ -154,7 +162,14 @@ void videoPlaybackPolicy() {
await pageLoaded.future; await pageLoaded.future;
expect(onEnterFullscreenCompleter.future, doesNotComplete); expect(onEnterFullscreenCompleter.future, doesNotComplete);
}); }, skip: shouldSkipTest2);
final shouldSkipTest3 = kIsWeb
? true
: ![
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets( testWidgets(
'Video plays fullscreen when allowsInlineMediaPlayback is false', 'Video plays fullscreen when allowsInlineMediaPlayback is false',
@ -194,8 +209,15 @@ void videoPlaybackPolicy() {
await tester.pump(); await tester.pump();
await expectLater(onEnterFullscreenCompleter.future, completes); await expectLater(onEnterFullscreenCompleter.future, completes);
}); }, skip: shouldSkipTest3);
final shouldSkipTest4 = kIsWeb
? true
: ![
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
// on Android, entering fullscreen requires user interaction
testWidgets('exit fullscreen event', (WidgetTester tester) async { testWidgets('exit fullscreen event', (WidgetTester tester) async {
Completer<InAppWebViewController> controllerCompleter = Completer<InAppWebViewController> controllerCompleter =
Completer<InAppWebViewController>(); Completer<InAppWebViewController>();
@ -235,6 +257,6 @@ void videoPlaybackPolicy() {
await controller.evaluateJavascript(source: "exitFullscreen();"); await controller.evaluateJavascript(source: "exitFullscreen();");
await expectLater(onExitFullscreenCompleter.future, completes); await expectLater(onExitFullscreenCompleter.future, completes);
}); }, skip: shouldSkipTest4);
}, skip: shouldSkip); }, skip: shouldSkip);
} }

View File

@ -177,11 +177,10 @@ void webViewWindows() {
final shouldSkipTest4 = kIsWeb final shouldSkipTest4 = kIsWeb
? true ? true
: ![ : ![
TargetPlatform.android,
TargetPlatform.iOS, TargetPlatform.iOS,
TargetPlatform.macOS, TargetPlatform.macOS,
].contains(defaultTargetPlatform); ].contains(defaultTargetPlatform);
// on Android, for some reason, it works on an example app but not in this test
testWidgets('can open new window and go back', (WidgetTester tester) async { testWidgets('can open new window and go back', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>(); final Completer controllerCompleter = Completer<InAppWebViewController>();
final StreamController<String> pageLoads = final StreamController<String> pageLoads =

View File

@ -1,18 +0,0 @@
#
# NOTE: This podspec is NOT to be published. It is only used as a local source!
# This is a generated file; do not edit or check into version control.
#
Pod::Spec.new do |s|
s.name = 'Flutter'
s.version = '1.0.0'
s.summary = 'High-performance, high-fidelity mobile apps.'
s.homepage = 'https://flutter.io'
s.license = { :type => 'MIT' }
s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' }
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
s.ios.deployment_target = '9.0'
# Framework linking is handled by Flutter tooling, not CocoaPods.
# Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs.
s.vendored_frameworks = 'path/to/nothing'
end

View File

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

View File

@ -19,7 +19,6 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
InAppWebViewSettings settings = InAppWebViewSettings( InAppWebViewSettings settings = InAppWebViewSettings(
useShouldOverrideUrlLoading: true, useShouldOverrideUrlLoading: true,
mediaPlaybackRequiresUserGesture: false, mediaPlaybackRequiresUserGesture: false,
useHybridComposition: true,
allowsInlineMediaPlayback: true, allowsInlineMediaPlayback: true,
iframeAllow: "camera; microphone", iframeAllow: "camera; microphone",
iframeAllowFullscreen: true, iframeAllowFullscreen: true,
@ -216,7 +215,13 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
ElevatedButton( ElevatedButton(
child: Icon(Icons.refresh), child: Icon(Icons.refresh),
onPressed: () { onPressed: () {
webViewController?.reloadFromOrigin(); webViewController?.reload();
},
),
ElevatedButton(
child: Icon(Icons.refresh),
onPressed: () {
webViewController?.evaluateJavascript(source: "window.open('https://github.com/flutter');");
}, },
), ),
], ],

View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>InAppWebViewOnJsBeforeUnloadTest</title>
</head>
<body>
<h1>InAppWebViewOnJsBeforeUnloadTest</h1>
<script>
window.addEventListener('beforeunload', function (e) {
e.preventDefault();
e.returnValue = '';
});
setTimeout(function() {
window.location.href = 'https://flutter.dev';
}, 500);
</script>
</body>
</html>

View File

@ -166,7 +166,7 @@ class AndroidInAppWebViewOptions
///If the url request of a subframe matches the regular expression, then the request of that subframe is canceled. ///If the url request of a subframe matches the regular expression, then the request of that subframe is canceled.
String? regexToCancelSubFramesLoading; String? regexToCancelSubFramesLoading;
///Set to `true` to enable Flutter's new Hybrid Composition. The default value is `false`. ///Set to `false` to disable Flutter Hybrid Composition. The default value is `true`.
///Hybrid Composition is supported starting with Flutter v1.20+. ///Hybrid Composition is supported starting with Flutter v1.20+.
/// ///
///**NOTE**: It is recommended to use Hybrid Composition only on Android 10+ for a release app, ///**NOTE**: It is recommended to use Hybrid Composition only on Android 10+ for a release app,
@ -277,7 +277,7 @@ class AndroidInAppWebViewOptions
this.initialScale = 0, this.initialScale = 0,
this.supportMultipleWindows = false, this.supportMultipleWindows = false,
this.regexToCancelSubFramesLoading, this.regexToCancelSubFramesLoading,
this.useHybridComposition = false, this.useHybridComposition = true,
this.useShouldInterceptRequest = false, this.useShouldInterceptRequest = false,
this.useOnRenderProcessGone = false, this.useOnRenderProcessGone = false,
this.overScrollMode = AndroidOverScrollMode.OVER_SCROLL_IF_CONTENT_SCROLLS, this.overScrollMode = AndroidOverScrollMode.OVER_SCROLL_IF_CONTENT_SCROLLS,

View File

@ -564,7 +564,7 @@ class _InAppWebViewState extends State<InAppWebView> {
: :
// ignore: deprecated_member_use_from_same_package // ignore: deprecated_member_use_from_same_package
widget.initialOptions?.android.useHybridComposition) ?? widget.initialOptions?.android.useHybridComposition) ??
false; true;
if (!useHybridComposition && widget.pullToRefreshController != null) { if (!useHybridComposition && widget.pullToRefreshController != null) {
throw new Exception( throw new Exception(