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 useOnRenderProcessGone = false;
public Boolean disableDefaultErrorPage = false;
public Boolean useHybridComposition = false;
public Boolean useHybridComposition = true;
@Nullable
public String verticalScrollbarThumbColor;
@Nullable

View File

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

View File

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

View File

@ -1,22 +1,19 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void onJsBeforeUnload() {
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
].contains(defaultTargetPlatform);
// final shouldSkip = kIsWeb
// ? true
// : ![
// TargetPlatform.android,
// ].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 {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>();
final Completer<String> onJsBeforeUnloadCompleter = Completer<String>();
await tester.pumpWidget(
@ -24,21 +21,10 @@ void onJsBeforeUnload() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: TEST_URL_1),
initialFile: "test_assets/in_app_webview_on_js_before_unload.html",
onWebViewCreated: (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 {
onJsBeforeUnloadCompleter
.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;
expect(url, TEST_URL_1.toString());
expect(url, endsWith("test_assets/in_app_webview_on_js_before_unload.html"));
}, skip: shouldSkip);
}

View File

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

View File

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

View File

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

View File

@ -177,11 +177,10 @@ void webViewWindows() {
final shouldSkipTest4 = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].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 {
final Completer controllerCompleter = Completer<InAppWebViewController>();
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_APPLICATION_PATH=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example"
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_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TRACK_WIDGET_CREATION=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(
useShouldOverrideUrlLoading: true,
mediaPlaybackRequiresUserGesture: false,
useHybridComposition: true,
allowsInlineMediaPlayback: true,
iframeAllow: "camera; microphone",
iframeAllowFullscreen: true,
@ -216,7 +215,13 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
ElevatedButton(
child: Icon(Icons.refresh),
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.
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+.
///
///**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.supportMultipleWindows = false,
this.regexToCancelSubFramesLoading,
this.useHybridComposition = false,
this.useHybridComposition = true,
this.useShouldInterceptRequest = false,
this.useOnRenderProcessGone = false,
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
widget.initialOptions?.android.useHybridComposition) ??
false;
true;
if (!useHybridComposition && widget.pullToRefreshController != null) {
throw new Exception(