44
55import 'dart:async' ;
66import 'dart:convert' ;
7- import 'dart:io' ;
87import 'dart:typed_data' ;
98
109import 'package:flutter/foundation.dart' ;
10+ import 'package:flutter/material.dart' ;
1111import 'package:flutter/services.dart' ;
1212import 'package:flutter/widgets.dart' ;
1313import 'package:flutter_test/flutter_test.dart' ;
14- import 'package:webview_flutter/platform_interface.dart' ;
15- import 'package:webview_flutter/webview_flutter.dart' ;
1614import 'package:integration_test/integration_test.dart' ;
15+ import 'package:webview_flutter_android/webview_android.dart' ;
16+ import 'package:webview_flutter_android/webview_surface_android.dart' ;
17+ import 'package:webview_flutter_example/main.dart' ;
18+ import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart' ;
1719
1820void main () {
1921 IntegrationTestWidgetsFlutterBinding .ensureInitialized ();
2022
23+ const bool _skipDueIssue86757 = false ;
24+
2125 // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
2226 testWidgets ('initialUrl' , (WidgetTester tester) async {
2327 final Completer <WebViewController > controllerCompleter =
2428 Completer <WebViewController >();
2529 await tester.pumpWidget (
26- Directionality (
27- textDirection: TextDirection .ltr,
28- child: WebView (
29- key: GlobalKey (),
30- initialUrl: 'https://flutter.dev/' ,
31- onWebViewCreated: (WebViewController controller) {
32- controllerCompleter.complete (controller);
33- },
30+ MaterialApp (
31+ home: Directionality (
32+ textDirection: TextDirection .ltr,
33+ child: WebView (
34+ key: GlobalKey (),
35+ initialUrl: 'https://flutter.dev/' ,
36+ onWebViewCreated: (WebViewController controller) {
37+ controllerCompleter.complete (controller);
38+ },
39+ ),
3440 ),
3541 ),
3642 );
3743 final WebViewController controller = await controllerCompleter.future;
3844 final String ? currentUrl = await controller.currentUrl ();
3945 expect (currentUrl, 'https://flutter.dev/' );
40- }, skip: true );
46+ }, skip: _skipDueIssue86757 );
4147
4248 // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
4349 testWidgets ('loadUrl' , (WidgetTester tester) async {
@@ -59,7 +65,7 @@ void main() {
5965 await controller.loadUrl ('https://www.google.com/' );
6066 final String ? currentUrl = await controller.currentUrl ();
6167 expect (currentUrl, 'https://www.google.com/' );
62- }, skip: true );
68+ }, skip: _skipDueIssue86757 );
6369
6470 // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
6571 testWidgets ('loadUrl with headers' , (WidgetTester tester) async {
@@ -101,7 +107,7 @@ void main() {
101107 final String content = await controller
102108 .evaluateJavascript ('document.documentElement.innerText' );
103109 expect (content.contains ('flutter_test_header' ), isTrue);
104- }, skip: Platform .isAndroid );
110+ }, skip: _skipDueIssue86757 );
105111
106112 // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
107113 testWidgets ('JavaScriptChannel' , (WidgetTester tester) async {
@@ -150,7 +156,7 @@ void main() {
150156 // https://github.com/flutter/flutter/issues/66318
151157 await controller.evaluateJavascript ('Echo.postMessage("hello");1;' );
152158 expect (messagesReceived, equals (< String > ['hello' ]));
153- }, skip: Platform .isAndroid );
159+ }, skip: _skipDueIssue86757 );
154160
155161 testWidgets ('resize webview' , (WidgetTester tester) async {
156162 final String resizeTest = '''
@@ -328,7 +334,7 @@ void main() {
328334
329335 final String customUserAgent2 = await _getUserAgent (controller);
330336 expect (customUserAgent2, defaultPlatformUserAgent);
331- }, skip: Platform .isAndroid );
337+ }, skip: _skipDueIssue86757 );
332338
333339 group ('Video playback policy' , () {
334340 late String videoTestBase64;
@@ -536,58 +542,6 @@ void main() {
536542 await controller.evaluateJavascript ('isFullScreen();' );
537543 expect (fullScreen, _webviewBool (false ));
538544 });
539-
540- // allowsInlineMediaPlayback is a noop on Android, so it is skipped.
541- testWidgets (
542- 'Video plays full screen when allowsInlineMediaPlayback is false' ,
543- (WidgetTester tester) async {
544- Completer <WebViewController > controllerCompleter =
545- Completer <WebViewController >();
546- Completer <void > pageLoaded = Completer <void >();
547- Completer <void > videoPlaying = Completer <void >();
548-
549- await tester.pumpWidget (
550- Directionality (
551- textDirection: TextDirection .ltr,
552- child: WebView (
553- initialUrl: 'data:text/html;charset=utf-8;base64,$videoTestBase64 ' ,
554- onWebViewCreated: (WebViewController controller) {
555- controllerCompleter.complete (controller);
556- },
557- javascriptMode: JavascriptMode .unrestricted,
558- javascriptChannels: < JavascriptChannel > {
559- JavascriptChannel (
560- name: 'VideoTestTime' ,
561- onMessageReceived: (JavascriptMessage message) {
562- final double currentTime = double .parse (message.message);
563- // Let it play for at least 1 second to make sure the related video's properties are set.
564- if (currentTime > 1 ) {
565- videoPlaying.complete (null );
566- }
567- },
568- ),
569- },
570- onPageFinished: (String url) {
571- pageLoaded.complete (null );
572- },
573- initialMediaPlaybackPolicy: AutoMediaPlaybackPolicy .always_allow,
574- allowsInlineMediaPlayback: false ,
575- ),
576- ),
577- );
578- WebViewController controller = await controllerCompleter.future;
579- await pageLoaded.future;
580-
581- // Pump once to trigger the video play.
582- await tester.pump ();
583-
584- // Makes sure we get the correct event that indicates the video is actually playing.
585- await videoPlaying.future;
586-
587- String fullScreen =
588- await controller.evaluateJavascript ('isFullScreen();' );
589- expect (fullScreen, _webviewBool (true ));
590- }, skip: Platform .isAndroid);
591545 });
592546
593547 group ('Audio playback policy' , () {
@@ -877,7 +831,7 @@ void main() {
877831 scrollPosY = await controller.getScrollY ();
878832 expect (scrollPosX, X_SCROLL * 2 );
879833 expect (scrollPosY, Y_SCROLL * 2 );
880- }, skip: Platform .isAndroid );
834+ }, skip: _skipDueIssue86757 );
881835 });
882836
883837 group ('SurfaceAndroidWebView' , () {
@@ -886,7 +840,7 @@ void main() {
886840 });
887841
888842 tearDownAll (() {
889- WebView .platform = null ;
843+ WebView .platform = AndroidWebView () ;
890844 });
891845
892846 // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
@@ -956,7 +910,7 @@ void main() {
956910 scrollPosY = await controller.getScrollY ();
957911 expect (X_SCROLL * 2 , scrollPosX);
958912 expect (Y_SCROLL * 2 , scrollPosY);
959- }, skip: true );
913+ }, skip: _skipDueIssue86757 );
960914
961915 // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
962916 testWidgets ('inputs are scrolled into view when focused' ,
@@ -1062,7 +1016,7 @@ void main() {
10621016 lastInputClientRectRelativeToViewport['right' ] <=
10631017 viewportRectRelativeToViewport['right' ],
10641018 isTrue);
1065- }, skip: true );
1019+ }, skip: _skipDueIssue86757 );
10661020 });
10671021
10681022 group ('NavigationDelegate' , () {
@@ -1125,14 +1079,9 @@ void main() {
11251079 final WebResourceError error = await errorCompleter.future;
11261080 expect (error, isNotNull);
11271081
1128- if (Platform .isIOS) {
1129- expect (error.domain, isNotNull);
1130- expect (error.failingUrl, isNull);
1131- } else if (Platform .isAndroid) {
1132- expect (error.errorType, isNotNull);
1133- expect (error.failingUrl? .startsWith ('https://www.notawebsite..com' ),
1134- isTrue);
1135- }
1082+ expect (error.errorType, isNotNull);
1083+ expect (
1084+ error.failingUrl? .startsWith ('https://www.notawebsite..com' ), isTrue);
11361085 });
11371086
11381087 testWidgets ('onWebResourceError is not called with valid url' ,
@@ -1332,7 +1281,7 @@ void main() {
13321281 expect (currentUrl, 'https://flutter.dev/' );
13331282 },
13341283 // Flaky on Android: https://github.com/flutter/flutter/issues/86757
1335- skip: Platform .isAndroid );
1284+ skip: _skipDueIssue86757 );
13361285
13371286 // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
13381287 testWidgets (
@@ -1373,7 +1322,7 @@ void main() {
13731322 await pageLoaded.future;
13741323 expect (controller.currentUrl (), completion ('https://flutter.dev/' ));
13751324 },
1376- skip: true ,
1325+ skip: _skipDueIssue86757 ,
13771326 );
13781327
13791328 testWidgets (
@@ -1441,7 +1390,6 @@ void main() {
14411390 completion ('null' ),
14421391 );
14431392 },
1444- skip: ! Platform .isAndroid,
14451393 );
14461394}
14471395
@@ -1461,8 +1409,5 @@ Future<String> _getUserAgent(WebViewController controller) async {
14611409
14621410Future <String > _evaluateJavascript (
14631411 WebViewController controller, String js) async {
1464- if (defaultTargetPlatform == TargetPlatform .iOS) {
1465- return await controller.evaluateJavascript (js);
1466- }
14671412 return jsonDecode (await controller.evaluateJavascript (js));
14681413}
0 commit comments