forked from firka/flutter
[web] migrate some felt code to null safety (flutter/engine#26644)
* [web] migrate some felt code to null safety
This commit is contained in:
@@ -1779,7 +1779,6 @@ FILE: ../../../flutter/vulkan/vulkan_window.h
|
||||
FILE: ../../../flutter/web_sdk/libraries.json
|
||||
FILE: ../../../flutter/web_sdk/sdk_rewriter.dart
|
||||
FILE: ../../../flutter/web_sdk/web_test_utils/lib/environment.dart
|
||||
FILE: ../../../flutter/web_sdk/web_test_utils/lib/exceptions.dart
|
||||
FILE: ../../../flutter/web_sdk/web_test_utils/lib/goldens.dart
|
||||
FILE: ../../../flutter/web_sdk/web_test_utils/lib/image_compare.dart
|
||||
----------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.6
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
@@ -13,8 +12,6 @@ import 'package:typed_data/typed_buffers.dart';
|
||||
|
||||
import 'package:test_api/src/utils.dart' show getErrorMessage;
|
||||
|
||||
import 'common.dart'; // ignore: unused_import
|
||||
|
||||
/// An interface for running browser instances.
|
||||
///
|
||||
/// This is intentionally coarse-grained: browsers are controlled primary from
|
||||
@@ -28,15 +25,15 @@ abstract class Browser {
|
||||
|
||||
/// The Observatory URL for this browser.
|
||||
///
|
||||
/// This will return `null` for browsers that aren't running the Dart VM, or
|
||||
/// Returns `null` for browsers that aren't running the Dart VM, or
|
||||
/// if the Observatory URL can't be found.
|
||||
Future<Uri> get observatoryUrl => null;
|
||||
Future<Uri>? get observatoryUrl => null;
|
||||
|
||||
/// The remote debugger URL for this browser.
|
||||
///
|
||||
/// This will return `null` for browsers that don't support remote debugging,
|
||||
/// Returns `null` for browsers that don't support remote debugging,
|
||||
/// or if the remote debugging URL can't be found.
|
||||
Future<Uri> get remoteDebuggerUrl => null;
|
||||
Future<Uri>? get remoteDebuggerUrl => null;
|
||||
|
||||
/// The underlying process.
|
||||
///
|
||||
@@ -110,7 +107,7 @@ abstract class Browser {
|
||||
}
|
||||
|
||||
_onExitCompleter.complete();
|
||||
}, (dynamic error, StackTrace stackTrace) {
|
||||
}, (dynamic error, StackTrace? stackTrace) {
|
||||
// Ignore any errors after the browser has been closed.
|
||||
if (_closed) {
|
||||
return;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.6
|
||||
import 'dart:io' show Platform;
|
||||
import 'dart:async';
|
||||
|
||||
@@ -30,7 +29,7 @@ class BuildCommand extends Command<bool> with ArgUtils {
|
||||
@override
|
||||
String get description => 'Build the Flutter web engine.';
|
||||
|
||||
bool get isWatchMode => boolArg('watch');
|
||||
bool get isWatchMode => boolArg('watch') ?? false;
|
||||
|
||||
@override
|
||||
FutureOr<bool> run() async {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.6
|
||||
import 'dart:async';
|
||||
import 'dart:io' as io;
|
||||
|
||||
@@ -30,9 +29,9 @@ class CleanCommand extends Command<bool> with ArgUtils {
|
||||
@override
|
||||
String get name => 'clean';
|
||||
|
||||
bool get _alsoCleanNinja => boolArg('ninja');
|
||||
bool get _alsoCleanNinja => boolArg('ninja') ?? false;
|
||||
|
||||
bool get _alsoCleanFlutterRepo => boolArg('flutter');
|
||||
bool get _alsoCleanFlutterRepo => boolArg('flutter') ?? true;
|
||||
|
||||
@override
|
||||
String get description => 'Deletes build caches and artifacts.';
|
||||
|
||||
@@ -2,11 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.6
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
@@ -20,21 +18,23 @@ const double kMaxDiffRateFailure = 0.28 / 100; // 0.28%
|
||||
|
||||
abstract class PlatformBinding {
|
||||
static PlatformBinding get instance {
|
||||
if (_instance == null) {
|
||||
PlatformBinding? binding = _instance;
|
||||
if (binding == null) {
|
||||
if (io.Platform.isLinux) {
|
||||
_instance = _LinuxBinding();
|
||||
binding = _LinuxBinding();
|
||||
} else if (io.Platform.isMacOS) {
|
||||
_instance = _MacBinding();
|
||||
binding = _MacBinding();
|
||||
} else if (io.Platform.isWindows) {
|
||||
_instance = _WindowsBinding();
|
||||
binding = _WindowsBinding();
|
||||
} else {
|
||||
throw '${io.Platform.operatingSystem} is not supported';
|
||||
}
|
||||
_instance = binding;
|
||||
}
|
||||
return _instance;
|
||||
return binding;
|
||||
}
|
||||
|
||||
static PlatformBinding _instance;
|
||||
static PlatformBinding? _instance;
|
||||
|
||||
int getChromeBuild(YamlMap chromeLock);
|
||||
String getChromeDownloadUrl(String version);
|
||||
@@ -175,8 +175,8 @@ class _MacBinding implements PlatformBinding {
|
||||
|
||||
class BrowserInstallation {
|
||||
const BrowserInstallation({
|
||||
@required this.version,
|
||||
@required this.executable,
|
||||
required this.version,
|
||||
required this.executable,
|
||||
});
|
||||
|
||||
/// Browser version.
|
||||
@@ -219,7 +219,7 @@ class BrowserLock {
|
||||
/// A string sink that swallows all input.
|
||||
class DevNull implements StringSink {
|
||||
@override
|
||||
void write(Object obj) {}
|
||||
void write(Object? obj) {}
|
||||
|
||||
@override
|
||||
void writeAll(Iterable objects, [String separator = ""]) {}
|
||||
@@ -228,7 +228,7 @@ class DevNull implements StringSink {
|
||||
void writeCharCode(int charCode) {}
|
||||
|
||||
@override
|
||||
void writeln([Object obj = ""]) {}
|
||||
void writeln([Object? obj = ""]) {}
|
||||
}
|
||||
|
||||
/// Whether the felt command is running on Cirrus CI.
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.6
|
||||
import 'dart:io' as io;
|
||||
import 'package:path/path.dart' as pathlib;
|
||||
|
||||
@@ -10,11 +9,10 @@ import 'exceptions.dart';
|
||||
|
||||
/// Contains various environment variables, such as common file paths and command-line options.
|
||||
Environment get environment {
|
||||
_environment ??= Environment();
|
||||
return _environment;
|
||||
return _environment ??= Environment();
|
||||
}
|
||||
|
||||
Environment _environment;
|
||||
Environment? _environment;
|
||||
|
||||
/// Contains various environment variables, such as common file paths and command-line options.
|
||||
class Environment {
|
||||
@@ -59,14 +57,14 @@ class Environment {
|
||||
}
|
||||
|
||||
Environment._({
|
||||
this.self,
|
||||
this.webUiRootDir,
|
||||
this.engineSrcDir,
|
||||
this.engineToolsDir,
|
||||
this.integrationTestsDir,
|
||||
this.outDir,
|
||||
this.hostDebugUnoptDir,
|
||||
this.dartSdkDir,
|
||||
required this.self,
|
||||
required this.webUiRootDir,
|
||||
required this.engineSrcDir,
|
||||
required this.engineToolsDir,
|
||||
required this.integrationTestsDir,
|
||||
required this.outDir,
|
||||
required this.hostDebugUnoptDir,
|
||||
required this.dartSdkDir,
|
||||
});
|
||||
|
||||
/// The Dart script that's currently running.
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.6
|
||||
@TestOn('vm && linux')
|
||||
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'common.dart';
|
||||
import 'environment.dart';
|
||||
import 'firefox_installer.dart';
|
||||
|
||||
void main() async {
|
||||
void deleteFirefoxInstallIfExists() {
|
||||
final io.Directory firefoxInstallationDir = io.Directory(
|
||||
path.join(environment.webUiDartToolDir.path, 'firefox'),
|
||||
);
|
||||
|
||||
if (firefoxInstallationDir.existsSync()) {
|
||||
firefoxInstallationDir.deleteSync(recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
setUpAll(() {
|
||||
deleteFirefoxInstallIfExists();
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
deleteFirefoxInstallIfExists();
|
||||
});
|
||||
|
||||
test('installs a given version of Firefox', () async {
|
||||
FirefoxInstaller installer = FirefoxInstaller(version: '69.0.2');
|
||||
expect(installer.isInstalled, isFalse);
|
||||
|
||||
BrowserInstallation installation = await getOrInstallFirefox('69.0.2');
|
||||
|
||||
expect(installation.version, '69.0.2');
|
||||
expect(installer.isInstalled, isTrue);
|
||||
expect(io.File(installation.executable).existsSync(), isTrue);
|
||||
});
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.6
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.6
|
||||
import 'dart:convert';
|
||||
|
||||
import 'utils.dart';
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.6
|
||||
import 'dart:async';
|
||||
import 'dart:io' as io;
|
||||
|
||||
@@ -50,7 +49,7 @@ class FilePath {
|
||||
Future<int> runProcess(
|
||||
String executable,
|
||||
List<String> arguments, {
|
||||
String workingDirectory,
|
||||
String? workingDirectory,
|
||||
bool mustSucceed: false,
|
||||
Map<String, String> environment = const <String, String>{},
|
||||
}) async {
|
||||
@@ -81,7 +80,7 @@ Future<int> runProcess(
|
||||
Future<void> startProcess(
|
||||
String executable,
|
||||
List<String> arguments, {
|
||||
String workingDirectory,
|
||||
String? workingDirectory,
|
||||
bool mustSucceed: false,
|
||||
}) async {
|
||||
final io.Process process = await io.Process.start(
|
||||
@@ -102,7 +101,7 @@ Future<void> startProcess(
|
||||
Future<String> evalProcess(
|
||||
String executable,
|
||||
List<String> arguments, {
|
||||
String workingDirectory,
|
||||
String? workingDirectory,
|
||||
}) async {
|
||||
final io.ProcessResult result = await io.Process.run(
|
||||
executable,
|
||||
@@ -144,17 +143,17 @@ Future<void> runFlutter(
|
||||
@immutable
|
||||
class ProcessException implements Exception {
|
||||
ProcessException({
|
||||
@required this.description,
|
||||
@required this.executable,
|
||||
@required this.arguments,
|
||||
@required this.workingDirectory,
|
||||
@required this.exitCode,
|
||||
required this.description,
|
||||
required this.executable,
|
||||
required this.arguments,
|
||||
required this.workingDirectory,
|
||||
required this.exitCode,
|
||||
});
|
||||
|
||||
final String description;
|
||||
final String executable;
|
||||
final List<String> arguments;
|
||||
final String workingDirectory;
|
||||
final String? workingDirectory;
|
||||
final int exitCode;
|
||||
|
||||
@override
|
||||
@@ -173,20 +172,20 @@ class ProcessException implements Exception {
|
||||
/// Adds utility methods
|
||||
mixin ArgUtils<T> on Command<T> {
|
||||
/// Extracts a boolean argument from [argResults].
|
||||
bool boolArg(String name) => argResults[name] as bool;
|
||||
bool? boolArg(String name) => argResults?[name] as bool?;
|
||||
|
||||
/// Extracts a string argument from [argResults].
|
||||
String stringArg(String name) => argResults[name] as String;
|
||||
String? stringArg(String name) => argResults?[name] as String?;
|
||||
|
||||
/// Extracts a integer argument from [argResults].
|
||||
///
|
||||
/// If the argument value cannot be parsed as [int] throws an [ArgumentError].
|
||||
int intArg(String name) {
|
||||
final String rawValue = stringArg(name);
|
||||
int? intArg(String name) {
|
||||
final String? rawValue = stringArg(name);
|
||||
if (rawValue == null) {
|
||||
return null;
|
||||
}
|
||||
final int value = int.tryParse(rawValue);
|
||||
final int? value = int.tryParse(rawValue);
|
||||
if (value == null) {
|
||||
throw ArgumentError(
|
||||
'Argument $name should be an integer value but was "$rawValue"',
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.6
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:watcher/watcher.dart';
|
||||
|
||||
@@ -28,11 +26,11 @@ typedef PipelineStep = Future<void> Function();
|
||||
/// When a pipeline is stopped, it switches to the [PipelineStatus.stopping]
|
||||
/// state and waits until the current task finishes.
|
||||
class Pipeline {
|
||||
Pipeline({@required this.steps});
|
||||
Pipeline({required this.steps});
|
||||
|
||||
final Iterable<PipelineStep> steps;
|
||||
|
||||
Future<dynamic> _currentStepFuture;
|
||||
Future<dynamic>? _currentStepFuture;
|
||||
|
||||
PipelineStatus get status => _status;
|
||||
PipelineStatus _status = PipelineStatus.idle;
|
||||
@@ -81,8 +79,8 @@ typedef WatchEventPredicate = bool Function(WatchEvent event);
|
||||
/// ignore certain files.
|
||||
class PipelineWatcher {
|
||||
PipelineWatcher({
|
||||
@required this.dir,
|
||||
@required this.pipeline,
|
||||
required this.dir,
|
||||
required this.pipeline,
|
||||
this.ignore,
|
||||
}) : watcher = DirectoryWatcher(dir);
|
||||
|
||||
@@ -97,7 +95,7 @@ class PipelineWatcher {
|
||||
|
||||
/// A callback that determines whether to rerun the pipeline or not for a
|
||||
/// given [WatchEvent] instance.
|
||||
final WatchEventPredicate ignore;
|
||||
final WatchEventPredicate? ignore;
|
||||
|
||||
/// Activates the watcher.
|
||||
void start() {
|
||||
@@ -105,10 +103,10 @@ class PipelineWatcher {
|
||||
}
|
||||
|
||||
int _pipelineRunCount = 0;
|
||||
Timer _scheduledPipeline;
|
||||
Timer? _scheduledPipeline;
|
||||
|
||||
void _onEvent(WatchEvent event) {
|
||||
if (ignore != null && ignore(event)) {
|
||||
if (ignore?.call(event) == true) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:html';
|
||||
|
||||
import 'package:js/js.dart';
|
||||
import 'package:stack_trace/stack_trace.dart';
|
||||
import 'package:stream_channel/stream_channel.dart';
|
||||
import 'package:js/js.dart';
|
||||
|
||||
/// A class defined in content shell, used to control its behavior.
|
||||
@JS()
|
||||
@@ -21,7 +21,7 @@ class _TestRunner {
|
||||
|
||||
/// Returns the current content shell runner, or `null` if none exists.
|
||||
@JS()
|
||||
external _TestRunner get testRunner;
|
||||
external _TestRunner? get testRunner;
|
||||
|
||||
/// A class that exposes the test API to JS.
|
||||
///
|
||||
@@ -38,7 +38,7 @@ class _JSApi {
|
||||
/// running.
|
||||
external Function get restartCurrent;
|
||||
|
||||
external factory _JSApi({void resume(), void restartCurrent()});
|
||||
external factory _JSApi({void Function() resume, void Function() restartCurrent});
|
||||
}
|
||||
|
||||
/// Sets the top-level `dartTest` object so that it's visible to JS.
|
||||
@@ -111,49 +111,52 @@ void main() {
|
||||
testRunner?.waitUntilDone();
|
||||
|
||||
if (_currentUrl.queryParameters['debug'] == 'true') {
|
||||
document.body.classes.add('debug');
|
||||
document.body!.classes.add('debug');
|
||||
}
|
||||
|
||||
runZoned(() {
|
||||
final MultiChannel<dynamic> serverChannel = _connectToServer();
|
||||
serverChannel.stream.listen((dynamic message) {
|
||||
if (message['command'] == 'loadSuite') {
|
||||
final int channelId = message['channel'];
|
||||
final String url = message['url'];
|
||||
final int messageId = message['id'];
|
||||
final VirtualChannel<dynamic> suiteChannel = serverChannel.virtualChannel(channelId);
|
||||
final StreamChannel<dynamic> iframeChannel = _connectToIframe(url, messageId);
|
||||
suiteChannel.pipe(iframeChannel);
|
||||
} else if (message['command'] == 'displayPause') {
|
||||
document.body.classes.add('paused');
|
||||
} else if (message['command'] == 'resume') {
|
||||
document.body.classes.remove('paused');
|
||||
} else {
|
||||
assert(message['command'] == 'closeSuite');
|
||||
_iframes.remove(message['id']).remove();
|
||||
runZonedGuarded(
|
||||
() {
|
||||
final MultiChannel<dynamic> serverChannel = _connectToServer();
|
||||
serverChannel.stream.listen((dynamic message) {
|
||||
if (message['command'] == 'loadSuite') {
|
||||
final int channelId = message['channel'] as int;
|
||||
final String url = message['url'] as String;
|
||||
final int messageId = message['id'] as int;
|
||||
final VirtualChannel<dynamic> suiteChannel = serverChannel.virtualChannel(channelId);
|
||||
final StreamChannel<dynamic> iframeChannel = _connectToIframe(url, messageId);
|
||||
suiteChannel.pipe(iframeChannel);
|
||||
} else if (message['command'] == 'displayPause') {
|
||||
document.body!.classes.add('paused');
|
||||
} else if (message['command'] == 'resume') {
|
||||
document.body!.classes.remove('paused');
|
||||
} else {
|
||||
assert(message['command'] == 'closeSuite');
|
||||
_iframes.remove(message['id'])!.remove();
|
||||
|
||||
for (StreamSubscription<dynamic> subscription in _subscriptions.remove(message['id'])) {
|
||||
subscription.cancel();
|
||||
for (final StreamSubscription<dynamic> subscription in _subscriptions.remove(message['id'])!) {
|
||||
subscription.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Send periodic pings to the test runner so it can know when the browser is
|
||||
// paused for debugging.
|
||||
Timer.periodic(Duration(seconds: 1),
|
||||
(_) => serverChannel.sink.add(<String, String>{'command': 'ping'}));
|
||||
// Send periodic pings to the test runner so it can know when the browser is
|
||||
// paused for debugging.
|
||||
Timer.periodic(const Duration(seconds: 1),
|
||||
(_) => serverChannel.sink.add(<String, String>{'command': 'ping'}));
|
||||
|
||||
_jsApi = _JSApi(resume: allowInterop(() {
|
||||
if (!document.body.classes.remove('paused')) {
|
||||
return;
|
||||
}
|
||||
serverChannel.sink.add(<String, String>{'command': 'resume'});
|
||||
}), restartCurrent: allowInterop(() {
|
||||
serverChannel.sink.add(<String, String>{'command': 'restart'});
|
||||
}));
|
||||
}, onError: (dynamic error, StackTrace stackTrace) {
|
||||
print('$error\n${Trace.from(stackTrace).terse}');
|
||||
});
|
||||
_jsApi = _JSApi(resume: allowInterop(() {
|
||||
if (!document.body!.classes.remove('paused')) {
|
||||
return;
|
||||
}
|
||||
serverChannel.sink.add(<String, String>{'command': 'resume'});
|
||||
}), restartCurrent: allowInterop(() {
|
||||
serverChannel.sink.add(<String, String>{'command': 'restart'});
|
||||
}));
|
||||
},
|
||||
(dynamic error, StackTrace stackTrace) {
|
||||
print('$error\n${Trace.from(stackTrace).terse}');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Creates a [MultiChannel] connection to the server, using a [WebSocket] as
|
||||
@@ -161,11 +164,11 @@ void main() {
|
||||
MultiChannel<dynamic> _connectToServer() {
|
||||
// The `managerUrl` query parameter contains the WebSocket URL of the remote
|
||||
// [BrowserManager] with which this communicates.
|
||||
final WebSocket webSocket = WebSocket(_currentUrl.queryParameters['managerUrl']);
|
||||
final WebSocket webSocket = WebSocket(_currentUrl.queryParameters['managerUrl']!);
|
||||
|
||||
final StreamChannelController<dynamic> controller = StreamChannelController<dynamic>(sync: true);
|
||||
webSocket.onMessage.listen((MessageEvent message) {
|
||||
final String data = message.data;
|
||||
final String data = message.data as String;
|
||||
controller.local.sink.add(jsonDecode(data));
|
||||
});
|
||||
|
||||
@@ -186,7 +189,7 @@ StreamChannel<dynamic> _connectToIframe(String url, int id) {
|
||||
..src = url
|
||||
..width = '1000'
|
||||
..height = '1000';
|
||||
document.body.children.add(iframe);
|
||||
document.body!.children.add(iframe);
|
||||
|
||||
// Use this to communicate securely with the iframe.
|
||||
final MessageChannel channel = MessageChannel();
|
||||
@@ -217,7 +220,7 @@ StreamChannel<dynamic> _connectToIframe(String url, int id) {
|
||||
if (message.data['ready'] == true) {
|
||||
// This message indicates that the iframe is actively listening for
|
||||
// events, so the message channel's second port can now be transferred.
|
||||
iframe.contentWindow.postMessage('port', window.location.origin, <MessagePort>[channel.port2]);
|
||||
iframe.contentWindow!.postMessage('port', window.location.origin, <MessagePort>[channel.port2]);
|
||||
readyCompleter.complete();
|
||||
} else if (message.data['exception'] == true) {
|
||||
// This message from `dart.js` indicates that an exception occurred
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: web_engine_tester
|
||||
|
||||
environment:
|
||||
sdk: ">=2.2.0 <3.0.0"
|
||||
sdk: ">=2.12.0-0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
js: 0.6.3
|
||||
|
||||
@@ -2,33 +2,38 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.6
|
||||
import 'dart:io' as io;
|
||||
import 'package:path/path.dart' as pathlib;
|
||||
|
||||
import 'exceptions.dart';
|
||||
|
||||
/// Contains various environment variables, such as common file paths and command-line options.
|
||||
Environment get environment {
|
||||
_environment ??= Environment();
|
||||
return _environment;
|
||||
return _environment ??= Environment();
|
||||
}
|
||||
|
||||
Environment _environment;
|
||||
Environment? _environment;
|
||||
|
||||
/// Contains various environment variables, such as common file paths and command-line options.
|
||||
class Environment {
|
||||
/// Creates an environment deduced from the path of the main Dart script.
|
||||
factory Environment() {
|
||||
final io.File self = io.File.fromUri(io.Platform.script);
|
||||
final io.Directory engineSrcDir = self.parent.parent.parent.parent.parent;
|
||||
return _prepareEnvironmentFromEngineDir(self, engineSrcDir);
|
||||
}
|
||||
|
||||
factory Environment.forIntegrationTests() {
|
||||
final io.File self = io.File.fromUri(io.Platform.script);
|
||||
final io.Directory engineSrcDir =
|
||||
self.parent.parent.parent.parent.parent.parent;
|
||||
return _prepareEnvironmentFromEngineDir(self, engineSrcDir);
|
||||
final io.File script = io.File.fromUri(io.Platform.script);
|
||||
io.Directory directory = script.parent;
|
||||
bool foundEngineRepoRoot = false;
|
||||
while (!foundEngineRepoRoot) {
|
||||
foundEngineRepoRoot = directory
|
||||
.listSync()
|
||||
.whereType<io.File>()
|
||||
.map((io.File file) => pathlib.basename(file.path))
|
||||
.contains('DEPS');
|
||||
final io.Directory parent = directory.parent;
|
||||
if (parent.path == directory.path) {
|
||||
throw Exception(
|
||||
'Failed to locate the root of the engine repository starting from ${script.path}',
|
||||
);
|
||||
}
|
||||
directory = parent;
|
||||
}
|
||||
return _prepareEnvironmentFromEngineDir(script, directory);
|
||||
}
|
||||
|
||||
static Environment _prepareEnvironmentFromEngineDir(
|
||||
@@ -46,7 +51,7 @@ class Environment {
|
||||
final io.Directory integrationTestsDir = io.Directory(
|
||||
pathlib.join(engineSrcDir.path, 'flutter', 'e2etests', 'web'));
|
||||
|
||||
for (io.Directory expectedDirectory in <io.Directory>[
|
||||
for (final io.Directory expectedDirectory in <io.Directory>[
|
||||
engineSrcDir,
|
||||
outDir,
|
||||
hostDebugUnoptDir,
|
||||
@@ -54,7 +59,7 @@ class Environment {
|
||||
webUiRootDir
|
||||
]) {
|
||||
if (!expectedDirectory.existsSync()) {
|
||||
throw ToolException('$expectedDirectory does not exist.');
|
||||
throw Exception('$expectedDirectory does not exist.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,14 +76,14 @@ class Environment {
|
||||
}
|
||||
|
||||
Environment._({
|
||||
this.self,
|
||||
this.webUiRootDir,
|
||||
this.engineSrcDir,
|
||||
this.engineToolsDir,
|
||||
this.integrationTestsDir,
|
||||
this.outDir,
|
||||
this.hostDebugUnoptDir,
|
||||
this.dartSdkDir,
|
||||
required this.self,
|
||||
required this.webUiRootDir,
|
||||
required this.engineSrcDir,
|
||||
required this.engineToolsDir,
|
||||
required this.integrationTestsDir,
|
||||
required this.outDir,
|
||||
required this.hostDebugUnoptDir,
|
||||
required this.dartSdkDir,
|
||||
});
|
||||
|
||||
/// The Dart script that's currently running.
|
||||
@@ -120,6 +125,8 @@ class Environment {
|
||||
/// Path to where github.com/flutter/engine is checked out inside the engine workspace.
|
||||
io.Directory get flutterDirectory =>
|
||||
io.Directory(pathlib.join(engineSrcDir.path, 'flutter'));
|
||||
|
||||
/// Path to the "web_sdk" directory in the engine source tree.
|
||||
io.Directory get webSdkRootDir => io.Directory(pathlib.join(
|
||||
flutterDirectory.path,
|
||||
'web_sdk',
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
class BrowserInstallerException implements Exception {
|
||||
BrowserInstallerException(this.message);
|
||||
|
||||
final String message;
|
||||
|
||||
@override
|
||||
String toString() => message;
|
||||
}
|
||||
|
||||
class DriverException implements Exception {
|
||||
DriverException(this.message);
|
||||
|
||||
final String message;
|
||||
|
||||
@override
|
||||
String toString() => message;
|
||||
}
|
||||
|
||||
class ToolException implements Exception {
|
||||
ToolException(this.message);
|
||||
|
||||
final String message;
|
||||
|
||||
@override
|
||||
String toString() => message;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
// @dart = 2.6
|
||||
|
||||
import 'dart:io' as io;
|
||||
import 'package:image/image.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
@@ -26,8 +26,8 @@ enum PixelComparison {
|
||||
void main(List<String> args) {
|
||||
final io.File fileA = io.File(args[0]);
|
||||
final io.File fileB = io.File(args[1]);
|
||||
final Image imageA = decodeNamedImage(fileA.readAsBytesSync(), 'a.png');
|
||||
final Image imageB = decodeNamedImage(fileB.readAsBytesSync(), 'b.png');
|
||||
final Image imageA = decodeNamedImage(fileA.readAsBytesSync(), 'a.png')!;
|
||||
final Image imageB = decodeNamedImage(fileB.readAsBytesSync(), 'b.png')!;
|
||||
final ImageDiff diff = ImageDiff(
|
||||
golden: imageA, other: imageB, pixelComparison: PixelComparison.fuzzy);
|
||||
print('Diff: ${(diff.rate * 100).toStringAsFixed(4)}%');
|
||||
@@ -51,7 +51,7 @@ class ImageDiff {
|
||||
/// * white: when both pixels are the same
|
||||
/// * red: when a pixel is found in other, but not in golden
|
||||
/// * green: when a pixel is found in golden, but not in other
|
||||
Image diff;
|
||||
late Image diff;
|
||||
|
||||
/// The ratio of wrong pixels to all pixels in golden (between 0 and 1)
|
||||
/// This gets set to 1 (100% difference) when golden and other aren't the same size.
|
||||
@@ -60,9 +60,9 @@ class ImageDiff {
|
||||
/// Image diff constructor which requires two [Image]s to compare and
|
||||
/// [PixelComparison] algorithm.
|
||||
ImageDiff({
|
||||
@required this.golden,
|
||||
@required this.other,
|
||||
@required this.pixelComparison,
|
||||
required this.golden,
|
||||
required this.other,
|
||||
required this.pixelComparison,
|
||||
}) {
|
||||
_computeDiff();
|
||||
}
|
||||
@@ -196,8 +196,6 @@ String getPrintableDiffFilesInfo(double diffRate, double maxRate) =>
|
||||
/// Reads the url of the repo and `commit no` to sync to, from
|
||||
/// `goldens_lock.yaml`.
|
||||
class GoldensRepoFetcher {
|
||||
String _repository;
|
||||
String _revision;
|
||||
final io.Directory _webUiGoldensRepositoryDirectory;
|
||||
final String _lockFilePath;
|
||||
|
||||
@@ -212,15 +210,15 @@ class GoldensRepoFetcher {
|
||||
Future<void> fetch() async {
|
||||
final io.File lockFile = io.File(path.join(_lockFilePath));
|
||||
final YamlMap lock = loadYaml(lockFile.readAsStringSync()) as YamlMap;
|
||||
_repository = lock['repository'] as String;
|
||||
_revision = lock['revision'] as String;
|
||||
final String repository = lock['repository'] as String;
|
||||
final String revision = lock['revision'] as String;
|
||||
|
||||
final String localRevision = await _getLocalRevision();
|
||||
if (localRevision == _revision) {
|
||||
final String? localRevision = await _getLocalRevision();
|
||||
if (localRevision == revision) {
|
||||
return;
|
||||
}
|
||||
|
||||
print('Fetching $_repository@$_revision');
|
||||
print('Fetching $repository@$revision');
|
||||
|
||||
if (!_webUiGoldensRepositoryDirectory.existsSync()) {
|
||||
_webUiGoldensRepositoryDirectory.createSync(recursive: true);
|
||||
@@ -230,7 +228,7 @@ class GoldensRepoFetcher {
|
||||
);
|
||||
|
||||
await _runGit(
|
||||
<String>['remote', 'add', 'origin', _repository],
|
||||
<String>['remote', 'add', 'origin', repository],
|
||||
_webUiGoldensRepositoryDirectory.path,
|
||||
);
|
||||
}
|
||||
@@ -240,12 +238,12 @@ class GoldensRepoFetcher {
|
||||
_webUiGoldensRepositoryDirectory.path,
|
||||
);
|
||||
await _runGit(
|
||||
<String>['checkout', _revision],
|
||||
<String>['checkout', revision],
|
||||
_webUiGoldensRepositoryDirectory.path,
|
||||
);
|
||||
}
|
||||
|
||||
Future<String> _getLocalRevision() async {
|
||||
Future<String?> _getLocalRevision() async {
|
||||
final io.File head = io.File(
|
||||
path.join(_webUiGoldensRepositoryDirectory.path, '.git', 'HEAD'));
|
||||
|
||||
|
||||
@@ -25,11 +25,9 @@ String compareImage(
|
||||
PixelComparison pixelComparison,
|
||||
double maxDiffRateFailure, {
|
||||
String goldensDirectory = '',
|
||||
bool forIntegrationTests = false,
|
||||
bool write = false,
|
||||
}) {
|
||||
final Environment environment =
|
||||
forIntegrationTests ? Environment.forIntegrationTests() : Environment();
|
||||
final Environment environment = Environment();
|
||||
if (goldensDirectory.isEmpty) {
|
||||
goldensDirectory = p.join(
|
||||
environment.webUiGoldensRepositoryDirectory.path,
|
||||
@@ -62,7 +60,7 @@ To automatically create this file call matchGoldenFile('$filename', write: true)
|
||||
}
|
||||
}
|
||||
|
||||
final Image golden = decodeNamedImage(file.readAsBytesSync(), filename);
|
||||
final Image golden = decodeNamedImage(file.readAsBytesSync(), filename)!;
|
||||
|
||||
// Compare screenshots.
|
||||
final ImageDiff diff = ImageDiff(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: web_test_utils
|
||||
|
||||
environment:
|
||||
sdk: ">=2.11.0-0 <3.0.0"
|
||||
sdk: ">=2.12.0-0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
path: 1.8.0
|
||||
|
||||
Reference in New Issue
Block a user