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' ;
7
11
import 'dart:io' ;
@@ -16,19 +20,32 @@ import 'package:integration_test/integration_test.dart';
16
20
import 'package:webview_flutter/platform_interface.dart' ;
17
21
import 'package:webview_flutter/webview_flutter.dart' ;
18
22
19
- void main () {
23
+ Future < void > main () async {
20
24
IntegrationTestWidgetsFlutterBinding .ensureInitialized ();
21
25
22
- // URLs to navigate to in tests. These need to be URLs that we are confident will
23
- // always be accessible, and won't do redirection. (E.g., just
24
- // 'https://www.google.com/' will sometimes redirect traffic that looks
25
- // like it's coming from a bot, which is true of these tests).
26
- const String primaryUrl = 'https://flutter.dev/' ;
27
- const String secondaryUrl = 'https://www.google.com/robots.txt' ;
28
-
29
26
const bool _skipDueToIssue86757 = true ;
30
27
31
- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
28
+ final HttpServer server = await HttpServer .bind (InternetAddress .anyIPv4, 0 );
29
+ server.forEach ((HttpRequest request) {
30
+ if (request.uri.path == '/hello.txt' ) {
31
+ request.response.writeln ('Hello, world.' );
32
+ } else if (request.uri.path == '/secondary.txt' ) {
33
+ request.response.writeln ('How are you today?' );
34
+ } else if (request.uri.path == '/headers' ) {
35
+ request.response.writeln ('${request .headers }' );
36
+ } else if (request.uri.path == '/favicon.ico' ) {
37
+ request.response.statusCode = HttpStatus .notFound;
38
+ } else {
39
+ fail ('unexpected request: ${request .method } ${request .uri }' );
40
+ }
41
+ request.response.close ();
42
+ });
43
+ final String prefixUrl = 'http://${server .address .address }:${server .port }' ;
44
+ final String primaryUrl = '$prefixUrl /hello.txt' ;
45
+ final String secondaryUrl = '$prefixUrl /secondary.txt' ;
46
+ final String headersUrl = '$prefixUrl /headers' ;
47
+
48
+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
32
49
testWidgets ('initialUrl' , (WidgetTester tester) async {
33
50
final Completer <WebViewController > controllerCompleter =
34
51
Completer <WebViewController >();
@@ -49,7 +66,7 @@ void main() {
49
66
expect (currentUrl, primaryUrl);
50
67
}, skip: _skipDueToIssue86757);
51
68
52
- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
69
+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
53
70
testWidgets ('loadUrl' , (WidgetTester tester) async {
54
71
final Completer <WebViewController > controllerCompleter =
55
72
Completer <WebViewController >();
@@ -93,7 +110,7 @@ void main() {
93
110
expect (result, equals ('2' ));
94
111
});
95
112
96
- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
113
+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
97
114
testWidgets ('loadUrl with headers' , (WidgetTester tester) async {
98
115
final Completer <WebViewController > controllerCompleter =
99
116
Completer <WebViewController >();
@@ -122,10 +139,9 @@ void main() {
122
139
final Map <String , String > headers = < String , String > {
123
140
'test_header' : 'flutter_test_header'
124
141
};
125
- await controller.loadUrl ('https://flutter-header-echo.herokuapp.com/' ,
126
- headers: headers);
142
+ await controller.loadUrl (headersUrl, headers: headers);
127
143
final String ? currentUrl = await controller.currentUrl ();
128
- expect (currentUrl, 'https://flutter-header-echo.herokuapp.com/' );
144
+ expect (currentUrl, headersUrl );
129
145
130
146
await pageStarts.stream.firstWhere ((String url) => url == currentUrl);
131
147
await pageLoads.stream.firstWhere ((String url) => url == currentUrl);
@@ -135,7 +151,7 @@ void main() {
135
151
expect (content.contains ('flutter_test_header' ), isTrue);
136
152
}, skip: Platform .isAndroid && _skipDueToIssue86757);
137
153
138
- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
154
+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
139
155
testWidgets ('JavascriptChannel' , (WidgetTester tester) async {
140
156
final Completer <WebViewController > controllerCompleter =
141
157
Completer <WebViewController >();
@@ -247,7 +263,7 @@ void main() {
247
263
expect (customUserAgent2, 'Custom_User_Agent2' );
248
264
});
249
265
250
- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
266
+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
251
267
testWidgets ('use default platform userAgent after webView is rebuilt' ,
252
268
(WidgetTester tester) async {
253
269
final Completer <WebViewController > controllerCompleter =
@@ -782,7 +798,7 @@ void main() {
782
798
});
783
799
784
800
group ('Programmatic Scroll' , () {
785
- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
801
+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
786
802
testWidgets ('setAndGetScrollPosition' , (WidgetTester tester) async {
787
803
const String scrollTestPage = '''
788
804
<!DOCTYPE html>
@@ -1133,6 +1149,7 @@ void main() {
1133
1149
expect (currentUrl, primaryUrl);
1134
1150
});
1135
1151
1152
+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
1136
1153
testWidgets ('target _blank opens in same window' ,
1137
1154
(WidgetTester tester) async {
1138
1155
final Completer <WebViewController > controllerCompleter =
@@ -1158,11 +1175,9 @@ void main() {
1158
1175
await pageLoaded.future;
1159
1176
final String ? currentUrl = await controller.currentUrl ();
1160
1177
expect (currentUrl, primaryUrl);
1161
- },
1162
- // Flaky on Android: https://github.com/flutter/flutter/issues/86757
1163
- skip: Platform .isAndroid && _skipDueToIssue86757);
1178
+ }, skip: Platform .isAndroid && _skipDueToIssue86757);
1164
1179
1165
- // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
1180
+ // TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
1166
1181
testWidgets (
1167
1182
'can open new window and go back' ,
1168
1183
(WidgetTester tester) async {
0 commit comments