4
4
5
5
import 'dart:async' ;
6
6
import 'dart:convert' ;
7
- import 'dart:io' ;
8
7
import 'dart:typed_data' ;
9
8
10
9
import 'package:flutter/foundation.dart' ;
10
+ import 'package:flutter/material.dart' ;
11
11
import 'package:flutter/services.dart' ;
12
12
import 'package:flutter/widgets.dart' ;
13
13
import 'package:flutter_test/flutter_test.dart' ;
14
- import 'package:webview_flutter/platform_interface.dart' ;
15
- import 'package:webview_flutter/webview_flutter.dart' ;
16
14
import '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' ;
17
19
18
20
void main () {
19
21
IntegrationTestWidgetsFlutterBinding .ensureInitialized ();
20
22
23
+ const bool _skipDueIssue86757 = false ;
24
+
21
25
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
22
26
testWidgets ('initialUrl' , (WidgetTester tester) async {
23
27
final Completer <WebViewController > controllerCompleter =
24
28
Completer <WebViewController >();
25
29
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
+ ),
34
40
),
35
41
),
36
42
);
37
43
final WebViewController controller = await controllerCompleter.future;
38
44
final String ? currentUrl = await controller.currentUrl ();
39
45
expect (currentUrl, 'https://flutter.dev/' );
40
- }, skip: true );
46
+ }, skip: _skipDueIssue86757 );
41
47
42
48
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
43
49
testWidgets ('loadUrl' , (WidgetTester tester) async {
@@ -59,7 +65,7 @@ void main() {
59
65
await controller.loadUrl ('https://www.google.com/' );
60
66
final String ? currentUrl = await controller.currentUrl ();
61
67
expect (currentUrl, 'https://www.google.com/' );
62
- }, skip: true );
68
+ }, skip: _skipDueIssue86757 );
63
69
64
70
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
65
71
testWidgets ('loadUrl with headers' , (WidgetTester tester) async {
@@ -101,7 +107,7 @@ void main() {
101
107
final String content = await controller
102
108
.evaluateJavascript ('document.documentElement.innerText' );
103
109
expect (content.contains ('flutter_test_header' ), isTrue);
104
- }, skip: Platform .isAndroid );
110
+ }, skip: _skipDueIssue86757 );
105
111
106
112
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
107
113
testWidgets ('JavaScriptChannel' , (WidgetTester tester) async {
@@ -150,7 +156,7 @@ void main() {
150
156
// https://github.com/flutter/flutter/issues/66318
151
157
await controller.evaluateJavascript ('Echo.postMessage("hello");1;' );
152
158
expect (messagesReceived, equals (< String > ['hello' ]));
153
- }, skip: Platform .isAndroid );
159
+ }, skip: _skipDueIssue86757 );
154
160
155
161
testWidgets ('resize webview' , (WidgetTester tester) async {
156
162
final String resizeTest = '''
@@ -328,7 +334,7 @@ void main() {
328
334
329
335
final String customUserAgent2 = await _getUserAgent (controller);
330
336
expect (customUserAgent2, defaultPlatformUserAgent);
331
- }, skip: Platform .isAndroid );
337
+ }, skip: _skipDueIssue86757 );
332
338
333
339
group ('Video playback policy' , () {
334
340
late String videoTestBase64;
@@ -536,58 +542,6 @@ void main() {
536
542
await controller.evaluateJavascript ('isFullScreen();' );
537
543
expect (fullScreen, _webviewBool (false ));
538
544
});
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);
591
545
});
592
546
593
547
group ('Audio playback policy' , () {
@@ -877,7 +831,7 @@ void main() {
877
831
scrollPosY = await controller.getScrollY ();
878
832
expect (scrollPosX, X_SCROLL * 2 );
879
833
expect (scrollPosY, Y_SCROLL * 2 );
880
- }, skip: Platform .isAndroid );
834
+ }, skip: _skipDueIssue86757 );
881
835
});
882
836
883
837
group ('SurfaceAndroidWebView' , () {
@@ -886,7 +840,7 @@ void main() {
886
840
});
887
841
888
842
tearDownAll (() {
889
- WebView .platform = null ;
843
+ WebView .platform = AndroidWebView () ;
890
844
});
891
845
892
846
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
@@ -956,7 +910,7 @@ void main() {
956
910
scrollPosY = await controller.getScrollY ();
957
911
expect (X_SCROLL * 2 , scrollPosX);
958
912
expect (Y_SCROLL * 2 , scrollPosY);
959
- }, skip: true );
913
+ }, skip: _skipDueIssue86757 );
960
914
961
915
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
962
916
testWidgets ('inputs are scrolled into view when focused' ,
@@ -1062,7 +1016,7 @@ void main() {
1062
1016
lastInputClientRectRelativeToViewport['right' ] <=
1063
1017
viewportRectRelativeToViewport['right' ],
1064
1018
isTrue);
1065
- }, skip: true );
1019
+ }, skip: _skipDueIssue86757 );
1066
1020
});
1067
1021
1068
1022
group ('NavigationDelegate' , () {
@@ -1125,14 +1079,9 @@ void main() {
1125
1079
final WebResourceError error = await errorCompleter.future;
1126
1080
expect (error, isNotNull);
1127
1081
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);
1136
1085
});
1137
1086
1138
1087
testWidgets ('onWebResourceError is not called with valid url' ,
@@ -1332,7 +1281,7 @@ void main() {
1332
1281
expect (currentUrl, 'https://flutter.dev/' );
1333
1282
},
1334
1283
// Flaky on Android: https://github.com/flutter/flutter/issues/86757
1335
- skip: Platform .isAndroid );
1284
+ skip: _skipDueIssue86757 );
1336
1285
1337
1286
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
1338
1287
testWidgets (
@@ -1373,7 +1322,7 @@ void main() {
1373
1322
await pageLoaded.future;
1374
1323
expect (controller.currentUrl (), completion ('https://flutter.dev/' ));
1375
1324
},
1376
- skip: true ,
1325
+ skip: _skipDueIssue86757 ,
1377
1326
);
1378
1327
1379
1328
testWidgets (
@@ -1441,7 +1390,6 @@ void main() {
1441
1390
completion ('null' ),
1442
1391
);
1443
1392
},
1444
- skip: ! Platform .isAndroid,
1445
1393
);
1446
1394
}
1447
1395
@@ -1461,8 +1409,5 @@ Future<String> _getUserAgent(WebViewController controller) async {
1461
1409
1462
1410
Future <String > _evaluateJavascript (
1463
1411
WebViewController controller, String js) async {
1464
- if (defaultTargetPlatform == TargetPlatform .iOS) {
1465
- return await controller.evaluateJavascript (js);
1466
- }
1467
1412
return jsonDecode (await controller.evaluateJavascript (js));
1468
1413
}
0 commit comments