mirror of
https://github.com/flutter/packages.git
synced 2025-07-04 17:49:50 +08:00
[webview_flutter] Use a local web server for legacy web integration tests (#5956)
Use a local web server for the legacy test, just as for the non-legacy version. Also updates the repo tooling to ensure that this test file is found, so it's run regardless of whether tests are run by directory or by individual path. Part of https://github.com/flutter/flutter/issues/95420
This commit is contained in:
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:html' as html;
|
import 'dart:html' as html;
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
@ -11,15 +12,27 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
import 'package:integration_test/integration_test.dart';
|
import 'package:integration_test/integration_test.dart';
|
||||||
import 'package:webview_flutter_web_example/legacy/web_view.dart';
|
import 'package:webview_flutter_web_example/legacy/web_view.dart';
|
||||||
|
|
||||||
void main() {
|
void main() async {
|
||||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
// URLs to navigate to in tests. These need to be URLs that we are confident will
|
const String primaryPage = 'first.txt';
|
||||||
// always be accessible, and won't do redirection. (E.g., just
|
const String secondaryPage = 'second.txt';
|
||||||
// 'https://www.google.com/' will sometimes redirect traffic that looks
|
final HttpServer server =
|
||||||
// like it's coming from a bot, which is true of these tests).
|
await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
|
||||||
const String primaryUrl = 'https://flutter.dev/';
|
unawaited(server.forEach((HttpRequest request) {
|
||||||
const String secondaryUrl = 'https://www.google.com/robots.txt';
|
if (request.uri.path == '/$primaryPage') {
|
||||||
|
request.response.writeln('Hello, world.');
|
||||||
|
}
|
||||||
|
if (request.uri.path == '/$secondaryPage') {
|
||||||
|
request.response.writeln('Another page.');
|
||||||
|
} else {
|
||||||
|
fail('unexpected request: ${request.method} ${request.uri}');
|
||||||
|
}
|
||||||
|
request.response.close();
|
||||||
|
}));
|
||||||
|
final String prefixUrl = 'http://localhost:${server.port}';
|
||||||
|
final String primaryUrl = '$prefixUrl/$primaryPage';
|
||||||
|
final String secondaryUrl = '$prefixUrl/$secondaryPage';
|
||||||
|
|
||||||
testWidgets('initialUrl', (WidgetTester tester) async {
|
testWidgets('initialUrl', (WidgetTester tester) async {
|
||||||
final Completer<WebViewController> controllerCompleter =
|
final Completer<WebViewController> controllerCompleter =
|
||||||
|
@ -317,7 +317,8 @@ class DriveExamplesCommand extends PackageLoopingCommand {
|
|||||||
example.directory.childDirectory('integration_test');
|
example.directory.childDirectory('integration_test');
|
||||||
|
|
||||||
if (integrationTestDir.existsSync()) {
|
if (integrationTestDir.existsSync()) {
|
||||||
await for (final FileSystemEntity file in integrationTestDir.list()) {
|
await for (final FileSystemEntity file
|
||||||
|
in integrationTestDir.list(recursive: true)) {
|
||||||
if (file is File && file.basename.endsWith('_test.dart')) {
|
if (file is File && file.basename.endsWith('_test.dart')) {
|
||||||
tests.add(file);
|
tests.add(file);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user