2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
+ // This test is run using `flutter drive` by the CI (see /script/tool/README.md
6
+ // in this repository for details on driving that tooling manually), but can
7
+ // also be run using `flutter test` directly during development.
8
+
5
9
import 'dart:async' ;
6
10
import 'dart:convert' ;
11
+ import 'dart:io' ;
7
12
import 'dart:typed_data' ;
8
13
9
14
import 'package:flutter/foundation.dart' ;
@@ -19,19 +24,31 @@ import 'package:webview_flutter_android_example/navigation_request.dart';
19
24
import 'package:webview_flutter_android_example/web_view.dart' ;
20
25
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart' ;
21
26
22
- void main () {
27
+ Future < void > main () async {
23
28
IntegrationTestWidgetsFlutterBinding .ensureInitialized ();
24
29
25
- // URLs to navigate to in tests. These need to be URLs that we are confident will
26
- // always be accessible, and won't do redirection. (E.g., just
27
- // 'https://www.google.com/' will sometimes redirect traffic that looks
28
- // like it's coming from a bot, which is true of these tests).
29
- const String primaryUrl = 'https://flutter.dev/' ;
30
- const String secondaryUrl = 'https://www.google.com/robots.txt' ;
31
-
32
30
const bool _skipDueToIssue86757 = true ;
33
31
34
- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
32
+ final HttpServer server = await HttpServer .bind (InternetAddress .anyIPv4, 0 );
33
+ server.forEach ((HttpRequest request) {
34
+ if (request.uri.path == '/hello.txt' ) {
35
+ request.response.writeln ('Hello, world.' );
36
+ } else if (request.uri.path == '/secondary.txt' ) {
37
+ request.response.writeln ('How are you today?' );
38
+ } else if (request.uri.path == '/headers' ) {
39
+ request.response.writeln ('${request .headers }' );
40
+ } else if (request.uri.path == '/favicon.ico' ) {
41
+ request.response.statusCode = HttpStatus .notFound;
42
+ } else {
43
+ fail ('unexpected request: ${request .method } ${request .uri }' );
44
+ }
45
+ request.response.close ();
46
+ });
47
+ final String prefixUrl = 'http://${server .address .address }:${server .port }' ;
48
+ final String primaryUrl = '$prefixUrl /hello.txt' ;
49
+ final String secondaryUrl = '$prefixUrl /secondary.txt' ;
50
+ final String headersUrl = '$prefixUrl /headers' ;
51
+
35
52
testWidgets ('initialUrl' , (WidgetTester tester) async {
36
53
final Completer <WebViewController > controllerCompleter =
37
54
Completer <WebViewController >();
@@ -54,7 +71,7 @@ void main() {
54
71
expect (currentUrl, primaryUrl);
55
72
}, skip: _skipDueToIssue86757);
56
73
57
- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
74
+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
58
75
testWidgets ('loadUrl' , (WidgetTester tester) async {
59
76
final Completer <WebViewController > controllerCompleter =
60
77
Completer <WebViewController >();
@@ -97,7 +114,7 @@ void main() {
97
114
expect (result, equals ('2' ));
98
115
});
99
116
100
- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
117
+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
101
118
testWidgets ('loadUrl with headers' , (WidgetTester tester) async {
102
119
final Completer <WebViewController > controllerCompleter =
103
120
Completer <WebViewController >();
@@ -126,10 +143,9 @@ void main() {
126
143
final Map <String , String > headers = < String , String > {
127
144
'test_header' : 'flutter_test_header'
128
145
};
129
- await controller.loadUrl ('https://flutter-header-echo.herokuapp.com/' ,
130
- headers: headers);
146
+ await controller.loadUrl (headersUrl, headers: headers);
131
147
final String ? currentUrl = await controller.currentUrl ();
132
- expect (currentUrl, 'https://flutter-header-echo.herokuapp.com/' );
148
+ expect (currentUrl, headersUrl );
133
149
134
150
await pageStarts.stream.firstWhere ((String url) => url == currentUrl);
135
151
await pageLoads.stream.firstWhere ((String url) => url == currentUrl);
@@ -139,7 +155,7 @@ void main() {
139
155
expect (content.contains ('flutter_test_header' ), isTrue);
140
156
}, skip: _skipDueToIssue86757);
141
157
142
- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
158
+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
143
159
testWidgets ('JavascriptChannel' , (WidgetTester tester) async {
144
160
final Completer <WebViewController > controllerCompleter =
145
161
Completer <WebViewController >();
@@ -251,7 +267,7 @@ void main() {
251
267
expect (customUserAgent2, 'Custom_User_Agent2' );
252
268
});
253
269
254
- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
270
+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
255
271
testWidgets ('use default platform userAgent after webView is rebuilt' ,
256
272
(WidgetTester tester) async {
257
273
final Completer <WebViewController > controllerCompleter =
@@ -727,7 +743,7 @@ void main() {
727
743
});
728
744
729
745
group ('Programmatic Scroll' , () {
730
- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
746
+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
731
747
testWidgets ('setAndGetScrollPosition' , (WidgetTester tester) async {
732
748
const String scrollTestPage = '''
733
749
<!DOCTYPE html>
@@ -814,7 +830,7 @@ void main() {
814
830
WebView .platform = AndroidWebView ();
815
831
});
816
832
817
- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
833
+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
818
834
testWidgets ('setAndGetScrollPosition' , (WidgetTester tester) async {
819
835
const String scrollTestPage = '''
820
836
<!DOCTYPE html>
@@ -883,7 +899,7 @@ void main() {
883
899
expect (Y_SCROLL * 2 , scrollPosY);
884
900
}, skip: _skipDueToIssue86757);
885
901
886
- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
902
+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
887
903
testWidgets ('inputs are scrolled into view when focused' ,
888
904
(WidgetTester tester) async {
889
905
const String scrollTestPage = '''
@@ -1253,7 +1269,7 @@ void main() {
1253
1269
// Flaky on Android: https://github.com/flutter/flutter/issues/86757
1254
1270
skip: _skipDueToIssue86757);
1255
1271
1256
- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
1272
+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
1257
1273
testWidgets (
1258
1274
'can open new window and go back' ,
1259
1275
(WidgetTester tester) async {
0 commit comments