Skip to content

Commit 8fbdf65

Browse files
[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 #95420
1 parent f858453 commit 8fbdf65

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

packages/webview_flutter/webview_flutter_web/example/integration_test/legacy/webview_flutter_test.dart

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,35 @@
44

55
import 'dart:async';
66
import 'dart:html' as html;
7+
import 'dart:io';
78

89
import 'package:flutter/material.dart';
910
import 'package:flutter/widgets.dart';
1011
import 'package:flutter_test/flutter_test.dart';
1112
import 'package:integration_test/integration_test.dart';
1213
import 'package:webview_flutter_web_example/legacy/web_view.dart';
1314

14-
void main() {
15+
void main() async {
1516
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
1617

17-
// URLs to navigate to in tests. These need to be URLs that we are confident will
18-
// always be accessible, and won't do redirection. (E.g., just
19-
// 'https://www.google.com/' will sometimes redirect traffic that looks
20-
// like it's coming from a bot, which is true of these tests).
21-
const String primaryUrl = 'https://flutter.dev/';
22-
const String secondaryUrl = 'https://www.google.com/robots.txt';
18+
const String primaryPage = 'first.txt';
19+
const String secondaryPage = 'second.txt';
20+
final HttpServer server =
21+
await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
22+
unawaited(server.forEach((HttpRequest request) {
23+
if (request.uri.path == '/$primaryPage') {
24+
request.response.writeln('Hello, world.');
25+
}
26+
if (request.uri.path == '/$secondaryPage') {
27+
request.response.writeln('Another page.');
28+
} else {
29+
fail('unexpected request: ${request.method} ${request.uri}');
30+
}
31+
request.response.close();
32+
}));
33+
final String prefixUrl = 'http://localhost:${server.port}';
34+
final String primaryUrl = '$prefixUrl/$primaryPage';
35+
final String secondaryUrl = '$prefixUrl/$secondaryPage';
2336

2437
testWidgets('initialUrl', (WidgetTester tester) async {
2538
final Completer<WebViewController> controllerCompleter =

script/tool/lib/src/drive_examples_command.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ class DriveExamplesCommand extends PackageLoopingCommand {
317317
example.directory.childDirectory('integration_test');
318318

319319
if (integrationTestDir.existsSync()) {
320-
await for (final FileSystemEntity file in integrationTestDir.list()) {
320+
await for (final FileSystemEntity file
321+
in integrationTestDir.list(recursive: true)) {
321322
if (file is File && file.basename.endsWith('_test.dart')) {
322323
tests.add(file);
323324
}

0 commit comments

Comments
 (0)