Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webview_flutter] Use a local web server for legacy web integration tests #5956

Merged
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 @@ -4,22 +4,35 @@

import 'dart:async';
import 'dart:html' as html;
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:webview_flutter_web_example/legacy/web_view.dart';

void main() {
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 String primaryPage = 'first.txt';
const String secondaryPage = 'second.txt';
final HttpServer server =
await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
unawaited(server.forEach((HttpRequest request) {
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 {
final Completer<WebViewController> controllerCompleter =
Expand Down
3 changes: 2 additions & 1 deletion script/tool/lib/src/drive_examples_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ class DriveExamplesCommand extends PackageLoopingCommand {
example.directory.childDirectory('integration_test');

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')) {
tests.add(file);
}
Expand Down