Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[webview_flutter] Remove dependency on flutter.dev and google.com #4691

Merged
merged 1 commit into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This test is run using `flutter drive` by the CI (see /script/tool/README.md
// in this repository for details on driving that tooling manually), but can
// also be run using `flutter test` directly during development.

import 'dart:async';
import 'dart:convert';
import 'dart:io';
Expand All @@ -16,19 +20,32 @@ import 'package:integration_test/integration_test.dart';
import 'package:webview_flutter/platform_interface.dart';
import 'package:webview_flutter/webview_flutter.dart';

void main() {
Future<void> main() async {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

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

const bool _skipDueToIssue86757 = true;

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
final HttpServer server = await HttpServer.bind(InternetAddress.anyIPv4, 0);
server.forEach((HttpRequest request) {
if (request.uri.path == '/hello.txt') {
request.response.writeln('Hello, world.');
} else if (request.uri.path == '/secondary.txt') {
request.response.writeln('How are you today?');
} else if (request.uri.path == '/headers') {
request.response.writeln('${request.headers}');
} else if (request.uri.path == '/favicon.ico') {
request.response.statusCode = HttpStatus.notFound;
} else {
fail('unexpected request: ${request.method} ${request.uri}');
}
request.response.close();
});
final String prefixUrl = 'http://${server.address.address}:${server.port}';
final String primaryUrl = '$prefixUrl/hello.txt';
final String secondaryUrl = '$prefixUrl/secondary.txt';
final String headersUrl = '$prefixUrl/headers';

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
testWidgets('initialUrl', (WidgetTester tester) async {
final Completer<WebViewController> controllerCompleter =
Completer<WebViewController>();
Expand All @@ -49,7 +66,7 @@ void main() {
expect(currentUrl, primaryUrl);
}, skip: _skipDueToIssue86757);

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
testWidgets('loadUrl', (WidgetTester tester) async {
final Completer<WebViewController> controllerCompleter =
Completer<WebViewController>();
Expand Down Expand Up @@ -93,7 +110,7 @@ void main() {
expect(result, equals('2'));
});

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
testWidgets('loadUrl with headers', (WidgetTester tester) async {
final Completer<WebViewController> controllerCompleter =
Completer<WebViewController>();
Expand Down Expand Up @@ -122,10 +139,9 @@ void main() {
final Map<String, String> headers = <String, String>{
'test_header': 'flutter_test_header'
};
await controller.loadUrl('https://flutter-header-echo.herokuapp.com/',
headers: headers);
await controller.loadUrl(headersUrl, headers: headers);
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://flutter-header-echo.herokuapp.com/');
expect(currentUrl, headersUrl);

await pageStarts.stream.firstWhere((String url) => url == currentUrl);
await pageLoads.stream.firstWhere((String url) => url == currentUrl);
Expand All @@ -135,7 +151,7 @@ void main() {
expect(content.contains('flutter_test_header'), isTrue);
}, skip: Platform.isAndroid && _skipDueToIssue86757);

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
testWidgets('JavascriptChannel', (WidgetTester tester) async {
final Completer<WebViewController> controllerCompleter =
Completer<WebViewController>();
Expand Down Expand Up @@ -247,7 +263,7 @@ void main() {
expect(customUserAgent2, 'Custom_User_Agent2');
});

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
testWidgets('use default platform userAgent after webView is rebuilt',
(WidgetTester tester) async {
final Completer<WebViewController> controllerCompleter =
Expand Down Expand Up @@ -782,7 +798,7 @@ void main() {
});

group('Programmatic Scroll', () {
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
testWidgets('setAndGetScrollPosition', (WidgetTester tester) async {
const String scrollTestPage = '''
<!DOCTYPE html>
Expand Down Expand Up @@ -1133,6 +1149,7 @@ void main() {
expect(currentUrl, primaryUrl);
});

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
testWidgets('target _blank opens in same window',
(WidgetTester tester) async {
final Completer<WebViewController> controllerCompleter =
Expand All @@ -1158,11 +1175,9 @@ void main() {
await pageLoaded.future;
final String? currentUrl = await controller.currentUrl();
expect(currentUrl, primaryUrl);
},
// Flaky on Android: https://github.com/flutter/flutter/issues/86757
skip: Platform.isAndroid && _skipDueToIssue86757);
}, skip: Platform.isAndroid && _skipDueToIssue86757);

// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757.
// TODO(bparrishMines): skipped due to https://github.com/flutter/flutter/issues/86757
testWidgets(
'can open new window and go back',
(WidgetTester tester) async {
Expand Down
7 changes: 5 additions & 2 deletions script/tool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ dart run ./script/tool/bin/flutter_plugin_tools.dart test --packages plugin_name

```sh
cd <repository root>
dart run ./script/tool/bin/flutter_plugin_tools.dart build-examples --packages plugin_name
dart run ./script/tool/bin/flutter_plugin_tools.dart drive-examples --packages plugin_name
dart run ./script/tool/bin/flutter_plugin_tools.dart build-examples --apk --packages plugin_name
dart run ./script/tool/bin/flutter_plugin_tools.dart drive-examples --android --packages plugin_name
```

Replace `--apk`/`--android` with the platform you want to test against
(omit it to get a list of valid options).

### Run Native Tests

`native-test` takes one or more platform flags to run tests for. By default it
Expand Down