Skip to content

Commit df0ed4c

Browse files
authored
Remove dependency on flutter.dev and google.com in native packages for Android and iOS (flutter#4707)
1 parent c27b257 commit df0ed4c

File tree

2 files changed

+62
-30
lines changed

2 files changed

+62
-30
lines changed

packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test.dart

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

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+
59
import 'dart:async';
610
import 'dart:convert';
11+
import 'dart:io';
712
import 'dart:typed_data';
813

914
import 'package:flutter/foundation.dart';
@@ -19,19 +24,31 @@ import 'package:webview_flutter_android_example/navigation_request.dart';
1924
import 'package:webview_flutter_android_example/web_view.dart';
2025
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';
2126

22-
void main() {
27+
Future<void> main() async {
2328
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
2429

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-
3230
const bool _skipDueToIssue86757 = true;
3331

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+
3552
testWidgets('initialUrl', (WidgetTester tester) async {
3653
final Completer<WebViewController> controllerCompleter =
3754
Completer<WebViewController>();
@@ -54,7 +71,7 @@ void main() {
5471
expect(currentUrl, primaryUrl);
5572
}, skip: _skipDueToIssue86757);
5673

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
5875
testWidgets('loadUrl', (WidgetTester tester) async {
5976
final Completer<WebViewController> controllerCompleter =
6077
Completer<WebViewController>();
@@ -97,7 +114,7 @@ void main() {
97114
expect(result, equals('2'));
98115
});
99116

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
101118
testWidgets('loadUrl with headers', (WidgetTester tester) async {
102119
final Completer<WebViewController> controllerCompleter =
103120
Completer<WebViewController>();
@@ -126,10 +143,9 @@ void main() {
126143
final Map<String, String> headers = <String, String>{
127144
'test_header': 'flutter_test_header'
128145
};
129-
await controller.loadUrl('https://flutter-header-echo.herokuapp.com/',
130-
headers: headers);
146+
await controller.loadUrl(headersUrl, headers: headers);
131147
final String? currentUrl = await controller.currentUrl();
132-
expect(currentUrl, 'https://flutter-header-echo.herokuapp.com/');
148+
expect(currentUrl, headersUrl);
133149

134150
await pageStarts.stream.firstWhere((String url) => url == currentUrl);
135151
await pageLoads.stream.firstWhere((String url) => url == currentUrl);
@@ -139,7 +155,7 @@ void main() {
139155
expect(content.contains('flutter_test_header'), isTrue);
140156
}, skip: _skipDueToIssue86757);
141157

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
143159
testWidgets('JavascriptChannel', (WidgetTester tester) async {
144160
final Completer<WebViewController> controllerCompleter =
145161
Completer<WebViewController>();
@@ -251,7 +267,7 @@ void main() {
251267
expect(customUserAgent2, 'Custom_User_Agent2');
252268
});
253269

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
255271
testWidgets('use default platform userAgent after webView is rebuilt',
256272
(WidgetTester tester) async {
257273
final Completer<WebViewController> controllerCompleter =
@@ -727,7 +743,7 @@ void main() {
727743
});
728744

729745
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
731747
testWidgets('setAndGetScrollPosition', (WidgetTester tester) async {
732748
const String scrollTestPage = '''
733749
<!DOCTYPE html>
@@ -814,7 +830,7 @@ void main() {
814830
WebView.platform = AndroidWebView();
815831
});
816832

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
818834
testWidgets('setAndGetScrollPosition', (WidgetTester tester) async {
819835
const String scrollTestPage = '''
820836
<!DOCTYPE html>
@@ -883,7 +899,7 @@ void main() {
883899
expect(Y_SCROLL * 2, scrollPosY);
884900
}, skip: _skipDueToIssue86757);
885901

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
887903
testWidgets('inputs are scrolled into view when focused',
888904
(WidgetTester tester) async {
889905
const String scrollTestPage = '''
@@ -1253,7 +1269,7 @@ void main() {
12531269
// Flaky on Android: https://github.com/flutter/flutter/issues/86757
12541270
skip: _skipDueToIssue86757);
12551271

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
12571273
testWidgets(
12581274
'can open new window and go back',
12591275
(WidgetTester tester) async {

packages/webview_flutter/webview_flutter_wkwebview/example/integration_test/webview_flutter_test.dart

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

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+
59
import 'dart:async';
610
import 'dart:convert';
711
import 'dart:io';
@@ -18,15 +22,28 @@ import 'package:webview_flutter_wkwebview_example/navigation_decision.dart';
1822
import 'package:webview_flutter_wkwebview_example/navigation_request.dart';
1923
import 'package:webview_flutter_wkwebview_example/web_view.dart';
2024

21-
void main() {
25+
Future<void> main() async {
2226
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
2327

24-
// URLs to navigate to in tests. These need to be URLs that we are confident will
25-
// always be accessible, and won't do redirection. (E.g., just
26-
// 'https://www.google.com/' will sometimes redirect traffic that looks
27-
// like it's coming from a bot, which is true of these tests).
28-
const String primaryUrl = 'https://flutter.dev/';
29-
const String secondaryUrl = 'https://www.google.com/robots.txt';
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';
3047

3148
testWidgets('initialUrl', (WidgetTester tester) async {
3249
final Completer<WebViewController> controllerCompleter =
@@ -118,10 +135,9 @@ void main() {
118135
final Map<String, String> headers = <String, String>{
119136
'test_header': 'flutter_test_header'
120137
};
121-
await controller.loadUrl('https://flutter-header-echo.herokuapp.com/',
122-
headers: headers);
138+
await controller.loadUrl(headersUrl, headers: headers);
123139
final String? currentUrl = await controller.currentUrl();
124-
expect(currentUrl, 'https://flutter-header-echo.herokuapp.com/');
140+
expect(currentUrl, headersUrl);
125141

126142
await pageStarts.stream.firstWhere((String url) => url == currentUrl);
127143
await pageLoads.stream.firstWhere((String url) => url == currentUrl);

0 commit comments

Comments
 (0)