diff --git a/engine/src/flutter/lib/web_ui/dev/build.dart b/engine/src/flutter/lib/web_ui/dev/build.dart index 10f85c47b1..f246d0c270 100644 --- a/engine/src/flutter/lib/web_ui/dev/build.dart +++ b/engine/src/flutter/lib/web_ui/dev/build.dart @@ -17,9 +17,10 @@ class BuildCommand extends Command with ArgUtils { argParser ..addFlag( 'watch', + defaultsTo: false, abbr: 'w', help: 'Run the build in watch mode so it rebuilds whenever a change' - 'is made.', + 'is made. Disabled by default.', ); } @@ -29,7 +30,7 @@ class BuildCommand extends Command with ArgUtils { @override String get description => 'Build the Flutter web engine.'; - bool get isWatchMode => boolArg('watch') ?? false; + bool get isWatchMode => boolArg('watch')!; @override FutureOr run() async { diff --git a/engine/src/flutter/lib/web_ui/dev/chrome.dart b/engine/src/flutter/lib/web_ui/dev/chrome.dart index 728df7b134..cc8a8452bd 100644 --- a/engine/src/flutter/lib/web_ui/dev/chrome.dart +++ b/engine/src/flutter/lib/web_ui/dev/chrome.dart @@ -2,18 +2,16 @@ // 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'; import 'package:pedantic/pedantic.dart'; -import 'package:test_core/src/util/io.dart'; - import 'browser.dart'; import 'chrome_installer.dart'; import 'common.dart'; +import 'environment.dart'; /// A class for running an instance of Chrome. /// @@ -29,14 +27,10 @@ class Chrome extends Browser { @override final Future remoteDebuggerUrl; - static String version; - /// Starts a new instance of Chrome open to the given [url], which may be a /// [Uri] or a [String]. factory Chrome(Uri url, {bool debug = false}) { - version = ChromeArgParser.instance.version; - - assert(version != null); + String version = ChromeArgParser.instance.version; var remoteDebuggerCompleter = Completer.sync(); return Chrome._(() async { final BrowserInstallation installation = await getOrInstallChrome( @@ -56,7 +50,7 @@ class Chrome extends Browser { // --disable-font-subpixel-positioning final bool isChromeNoSandbox = Platform.environment['CHROME_NO_SANDBOX'] == 'true'; - var dir = createTempDir(); + final String dir = environment.webUiDartToolDir.createTempSync('test_chrome_user_data_').resolveSymbolicLinksSync(); var args = [ '--user-data-dir=$dir', url.toString(), @@ -105,7 +99,7 @@ class Chrome extends Browser { /// Inconsistency detected by ld.so: ../elf/dl-tls.c: 493: _dl_allocate_tls_init: Assertion `listp->slotinfo[cnt].gen <= GL(dl_tls_generation)' failed! const String _kGlibcError = 'Inconsistency detected by ld.so'; -Future _spawnChromiumProcess(String executable, List args, { String workingDirectory }) async { +Future _spawnChromiumProcess(String executable, List args, { String? workingDirectory }) async { // Keep attempting to launch the browser until one of: // - Chrome launched successfully, in which case we just return from the loop. // - The tool detected an unretriable Chrome error, in which case we throw ToolExit. @@ -134,11 +128,10 @@ Future _spawnChromiumProcess(String executable, List args, { St }) .firstWhere((String line) => line.startsWith('DevTools listening'), orElse: () { if (hitGlibcBug) { - print( - 'Encountered glibc bug https://sourceware.org/bugzilla/show_bug.cgi?id=19329. ' - 'Will try launching browser again.', - ); - return null; + final String message = 'Encountered glibc bug https://sourceware.org/bugzilla/show_bug.cgi?id=19329. ' + 'Will try launching browser again.'; + print(message); + return message; } print('Failed to launch browser. Command used to launch it: ${args.join(' ')}'); throw Exception( @@ -157,7 +150,27 @@ Future _spawnChromiumProcess(String executable, List args, { St // launching more processes. process.exitCode.timeout(const Duration(seconds: 1), onTimeout: () { process.kill(); - return null; + return -1; }); } } + +/// Returns the full URL of the Chrome remote debugger for the main page. +/// +/// This takes the [base] remote debugger URL (which points to a browser-wide +/// page) and uses its JSON API to find the resolved URL for debugging the host +/// page. +Future getRemoteDebuggerUrl(Uri base) async { + try { + final HttpClient client = HttpClient(); + final HttpClientRequest request = await client.getUrl(base.resolve('/json/list')); + final HttpClientResponse response = await request.close(); + final List jsonObject = + await json.fuse(utf8).decoder.bind(response).single as List; + return base.resolve(jsonObject.first['devtoolsFrontendUrl'] as String); + } catch (_) { + // If we fail to talk to the remote debugger protocol, give up and return + // the raw URL rather than crashing. + return base; + } +} diff --git a/engine/src/flutter/lib/web_ui/dev/chrome_installer.dart b/engine/src/flutter/lib/web_ui/dev/chrome_installer.dart index 36254e8f63..9a518d96ab 100644 --- a/engine/src/flutter/lib/web_ui/dev/chrome_installer.dart +++ b/engine/src/flutter/lib/web_ui/dev/chrome_installer.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; @@ -10,7 +9,6 @@ import 'package:archive/archive.dart'; import 'package:archive/archive_io.dart'; import 'package:args/args.dart'; import 'package:http/http.dart'; -import 'package:meta/meta.dart'; import 'package:path/path.dart' as path; import 'package:yaml/yaml.dart'; @@ -24,8 +22,8 @@ class ChromeArgParser extends BrowserArgParser { /// The [ChromeArgParser] singleton. static ChromeArgParser get instance => _singletonInstance; - String _version; - int _pinnedChromeBuildNumber; + late String _version; + late int _pinnedChromeBuildNumber; ChromeArgParser._(); @@ -73,7 +71,7 @@ class ChromeArgParser extends BrowserArgParser { /// https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Linux_x64/ Future getOrInstallChrome( String requestedVersion, { - StringSink infoLog, + StringSink? infoLog, }) async { infoLog ??= io.stdout; @@ -84,7 +82,7 @@ Future getOrInstallChrome( ); } - ChromeInstaller installer; + ChromeInstaller? installer; try { installer = requestedVersion == 'latest' ? await ChromeInstaller.latest() @@ -96,11 +94,11 @@ Future getOrInstallChrome( } else { infoLog.writeln('Installing Chrome version: ${installer.version}'); await installer.install(); - final BrowserInstallation installation = installer.getInstallation(); + final BrowserInstallation installation = installer.getInstallation()!; infoLog.writeln( 'Installations complete. To launch it run ${installation.executable}'); } - return installer.getInstallation(); + return installer.getInstallation()!; } finally { installer?.close(); } @@ -121,7 +119,7 @@ Future _findSystemChromeExecutable() async { /// Manages the installation of a particular [version] of Chrome. class ChromeInstaller { factory ChromeInstaller({ - @required String version, + required String version, }) { if (version == 'system') { throw BrowserInstallerException( @@ -150,9 +148,9 @@ class ChromeInstaller { } ChromeInstaller._({ - @required this.version, - @required this.chromeInstallationDir, - @required this.versionDir, + required this.version, + required this.chromeInstallationDir, + required this.versionDir, }); /// Chrome version managed by this installer. @@ -171,7 +169,7 @@ class ChromeInstaller { return versionDir.existsSync(); } - BrowserInstallation getInstallation() { + BrowserInstallation? getInstallation() { if (!isInstalled) { return null; } @@ -304,12 +302,13 @@ String preinstalledChromeExecutable() { final String buildNumber = ChromeArgParser.instance.pinnedChromeBuildNumber; final ChromeInstaller chromeInstaller = ChromeInstaller(version: buildNumber); if (chromeInstaller.isInstalled) { - print('INFO: Found chrome executable for LUCI: ' - '${chromeInstaller.getInstallation().executable}'); - return chromeInstaller.getInstallation().executable; + final String executable = chromeInstaller.getInstallation()!.executable; + print('INFO: Found chrome executable for LUCI: $executable'); + return executable; } else { throw StateError( - 'Failed to locate pinned Chrome build: $buildNumber on LUCI.'); + 'Failed to locate pinned Chrome build: $buildNumber on LUCI.', + ); } } diff --git a/engine/src/flutter/lib/web_ui/dev/clean.dart b/engine/src/flutter/lib/web_ui/dev/clean.dart index 6f34f44398..a7a00e911c 100644 --- a/engine/src/flutter/lib/web_ui/dev/clean.dart +++ b/engine/src/flutter/lib/web_ui/dev/clean.dart @@ -17,21 +17,21 @@ class CleanCommand extends Command with ArgUtils { ..addFlag( 'flutter', defaultsTo: true, - help: 'Cleans up the .dart_tool directory under engine/src/flutter.', + help: 'Cleans up the .dart_tool directory under engine/src/flutter. Enabled by default.', ) ..addFlag( 'ninja', defaultsTo: false, - help: 'Also clean up the engine out directory with ninja output.', + help: 'Also clean up the engine out directory with ninja output. Disabled by default.', ); } @override String get name => 'clean'; - bool get _alsoCleanNinja => boolArg('ninja') ?? false; + bool get _alsoCleanNinja => boolArg('ninja')!; - bool get _alsoCleanFlutterRepo => boolArg('flutter') ?? true; + bool get _alsoCleanFlutterRepo => boolArg('flutter')!; @override String get description => 'Deletes build caches and artifacts.'; diff --git a/engine/src/flutter/lib/web_ui/dev/common.dart b/engine/src/flutter/lib/web_ui/dev/common.dart index 04a1e8fef1..97a6e3a79f 100644 --- a/engine/src/flutter/lib/web_ui/dev/common.dart +++ b/engine/src/flutter/lib/web_ui/dev/common.dart @@ -18,24 +18,23 @@ const double kMaxDiffRateFailure = 0.28 / 100; // 0.28% abstract class PlatformBinding { static PlatformBinding get instance { - PlatformBinding? binding = _instance; - if (binding == null) { - if (io.Platform.isLinux) { - binding = _LinuxBinding(); - } else if (io.Platform.isMacOS) { - binding = _MacBinding(); - } else if (io.Platform.isWindows) { - binding = _WindowsBinding(); - } else { - throw '${io.Platform.operatingSystem} is not supported'; - } - _instance = binding; - } - return binding; + return _instance ??= _createInstance(); } - static PlatformBinding? _instance; + static PlatformBinding _createInstance() { + if (io.Platform.isLinux) { + return _LinuxBinding(); + } + if (io.Platform.isMacOS) { + return _MacBinding(); + } + if (io.Platform.isWindows) { + return _WindowsBinding(); + } + throw '${io.Platform.operatingSystem} is not supported'; + } + int getChromeBuild(YamlMap chromeLock); String getChromeDownloadUrl(String version); String getFirefoxDownloadUrl(String version); diff --git a/engine/src/flutter/lib/web_ui/dev/create_simulator.dart b/engine/src/flutter/lib/web_ui/dev/create_simulator.dart index f180c3beaa..c325aff7da 100644 --- a/engine/src/flutter/lib/web_ui/dev/create_simulator.dart +++ b/engine/src/flutter/lib/web_ui/dev/create_simulator.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 'package:args/command_runner.dart'; @@ -35,8 +34,8 @@ class CreateSimulatorCommand extends Command with ArgUtils { @override FutureOr run() async { - IosSafariArgParser.instance.parseOptions(argResults); - final String simulatorType = argResults['type'] as String; + IosSafariArgParser.instance.parseOptions(argResults!); + final String simulatorType = argResults!['type'] as String; if (simulatorType.toUpperCase() != 'IOS') { throw Exception('Currently the only iOS Simulators are supported'); } diff --git a/engine/src/flutter/lib/web_ui/dev/driver_manager.dart b/engine/src/flutter/lib/web_ui/dev/driver_manager.dart index 753eb70d1c..61550ff33b 100644 --- a/engine/src/flutter/lib/web_ui/dev/driver_manager.dart +++ b/engine/src/flutter/lib/web_ui/dev/driver_manager.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:io' as io; import 'package:path/path.dart' as pathlib; @@ -29,7 +28,7 @@ class ChromeDriverManager extends DriverManager { /// Initialized to the current first to avoid the `Non-nullable` error. // TODO: https://github.com/flutter/flutter/issues/53179. Local integration // tests are still using the system Chrome. - io.Directory _browserDriverDirWithVersion; + late final io.Directory _browserDriverDirWithVersion; ChromeDriverManager(String browser) : super(browser) { final io.File lockFile = io.File(pathlib.join( diff --git a/engine/src/flutter/lib/web_ui/dev/edge.dart b/engine/src/flutter/lib/web_ui/dev/edge.dart index e1f5cf497b..3059fd21f4 100644 --- a/engine/src/flutter/lib/web_ui/dev/edge.dart +++ b/engine/src/flutter/lib/web_ui/dev/edge.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'; @@ -21,14 +20,11 @@ class Edge extends Browser { @override final name = 'Edge'; - static String version; - /// Starts a new instance of Safari open to the given [url], which may be a /// [Uri] or a [String]. factory Edge(Uri url, {bool debug = false}) { - version = EdgeArgParser.instance.version; + final String version = EdgeArgParser.instance.version; - assert(version != null); return Edge._(() async { // TODO(nurhan): Configure info log for LUCI. final BrowserInstallation installation = await getEdgeInstallation( diff --git a/engine/src/flutter/lib/web_ui/dev/edge_installation.dart b/engine/src/flutter/lib/web_ui/dev/edge_installation.dart index efdf03f30b..2b6353ba38 100644 --- a/engine/src/flutter/lib/web_ui/dev/edge_installation.dart +++ b/engine/src/flutter/lib/web_ui/dev/edge_installation.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; @@ -19,7 +18,7 @@ class EdgeArgParser extends BrowserArgParser { /// The [EdgeArgParser] singleton. static EdgeArgParser get instance => _singletonInstance; - String _version; + late String _version; EdgeArgParser._(); @@ -56,7 +55,7 @@ class EdgeArgParser extends BrowserArgParser { // from the beta channel. Future getEdgeInstallation( String requestedVersion, { - StringSink infoLog, + StringSink? infoLog, }) async { // For now these tests are aimed to run only on Windows machines local or on LUCI/CI. // In the future we can investigate to run them on Android or on MacOS. @@ -127,7 +126,7 @@ class EdgeLauncher { BrowserLock.instance.configuration['edge']['launcher_version'] as String; /// Install the launcher if it does not exist in this system. - void install() async { + Future install() async { // Checks if the `MicrosoftEdgeLauncher` executable exists. if (isInstalled) { return; diff --git a/engine/src/flutter/lib/web_ui/dev/firefox.dart b/engine/src/flutter/lib/web_ui/dev/firefox.dart index ccff1789d5..c479133587 100644 --- a/engine/src/flutter/lib/web_ui/dev/firefox.dart +++ b/engine/src/flutter/lib/web_ui/dev/firefox.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'; @@ -30,14 +29,10 @@ class Firefox extends Browser { @override final Future remoteDebuggerUrl; - static String version; - /// Starts a new instance of Firefox open to the given [url], which may be a /// [Uri] or a [String]. factory Firefox(Uri url, {bool debug = false}) { - version = FirefoxArgParser.instance.version; - - assert(version != null); + final String version = FirefoxArgParser.instance.version; var remoteDebuggerCompleter = Completer.sync(); return Firefox._(() async { final BrowserInstallation installation = await getOrInstallFirefox( diff --git a/engine/src/flutter/lib/web_ui/dev/firefox_installer.dart b/engine/src/flutter/lib/web_ui/dev/firefox_installer.dart index e282d2a3df..0cd2c2b28b 100644 --- a/engine/src/flutter/lib/web_ui/dev/firefox_installer.dart +++ b/engine/src/flutter/lib/web_ui/dev/firefox_installer.dart @@ -1,12 +1,11 @@ // 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:args/args.dart'; import 'package:http/http.dart'; -import 'package:meta/meta.dart'; import 'package:path/path.dart' as path; import 'package:yaml/yaml.dart'; @@ -20,7 +19,7 @@ class FirefoxArgParser extends BrowserArgParser { /// The [FirefoxArgParser] singleton. static FirefoxArgParser get instance => _singletonInstance; - String _version; + late final String _version; FirefoxArgParser._(); @@ -64,7 +63,7 @@ class FirefoxArgParser extends BrowserArgParser { /// https://download-installer.cdn.mozilla.net/pub/firefox/releases/ Future getOrInstallFirefox( String requestedVersion, { - StringSink infoLog, + StringSink? infoLog, }) async { // These tests are aimed to run only on the Linux containers in Cirrus. // Therefore Firefox installation is implemented only for Linux now. @@ -82,7 +81,7 @@ Future getOrInstallFirefox( ); } - FirefoxInstaller installer; + FirefoxInstaller? installer; try { installer = requestedVersion == 'latest' ? await FirefoxInstaller.latest() @@ -94,11 +93,11 @@ Future getOrInstallFirefox( } else { infoLog.writeln('Installing Firefox version: ${installer.version}'); await installer.install(); - final BrowserInstallation installation = installer.getInstallation(); + final BrowserInstallation installation = installer.getInstallation()!; infoLog.writeln( 'Installations complete. To launch it run ${installation.executable}'); } - return installer.getInstallation(); + return installer.getInstallation()!; } finally { installer?.close(); } @@ -107,7 +106,7 @@ Future getOrInstallFirefox( /// Manages the installation of a particular [version] of Firefox. class FirefoxInstaller { factory FirefoxInstaller({ - @required String version, + required String version, }) { if (version == 'system') { throw BrowserInstallerException( @@ -138,9 +137,9 @@ class FirefoxInstaller { } FirefoxInstaller._({ - @required this.version, - @required this.firefoxInstallationDir, - @required this.versionDir, + required this.version, + required this.firefoxInstallationDir, + required this.versionDir, }); /// Firefox version managed by this installer. @@ -159,7 +158,7 @@ class FirefoxInstaller { return versionDir.existsSync(); } - BrowserInstallation getInstallation() { + BrowserInstallation? getInstallation() { if (!isInstalled) { return null; } @@ -262,7 +261,7 @@ class FirefoxInstaller { } List processOutput = (mountResult.stdout as String).split('\n'); - String volumePath = _volumeFromMountResult(processOutput); + final String? volumePath = _volumeFromMountResult(processOutput); if (volumePath == null) { throw BrowserInstallerException( 'Failed to parse mount dmg result ${processOutput.join('\n')}.\n' @@ -273,7 +272,7 @@ class FirefoxInstaller { // Parses volume from mount result. // Output is of form: {devicename} /Volumes/{name}. - String _volumeFromMountResult(List lines) { + String? _volumeFromMountResult(List lines) { for (String line in lines) { int pos = line.indexOf('/Volumes'); if (pos != -1) { @@ -326,8 +325,8 @@ Future fetchLatestFirefoxVersionLinux() async { // We will parse the HttpHeaders to find the redirect location. final io.HttpClientResponse response = await request.close(); - final String location = response.headers.value('location'); - final String version = forFirefoxVersion.stringMatch(location); + final String location = response.headers.value('location')!; + final String version = forFirefoxVersion.stringMatch(location)!; return version.substring(version.lastIndexOf('-') + 1); } @@ -341,13 +340,13 @@ Future fetchLatestFirefoxVersionMacOS() async { // We will parse the HttpHeaders to find the redirect location. final io.HttpClientResponse response = await request.close(); - final String location = response.headers.value('location'); - final String version = forFirefoxVersion.stringMatch(location); + final String location = response.headers.value('location')!; + final String version = forFirefoxVersion.stringMatch(location)!; return version.substring(version.lastIndexOf('/') + 1); } Future getInstaller({String requestedVersion = 'latest'}) async { - FirefoxInstaller installer; + FirefoxInstaller? installer; try { installer = requestedVersion == 'latest' ? await FirefoxInstaller.latest() @@ -359,11 +358,11 @@ Future getInstaller({String requestedVersion = 'latest'}) a } else { print('Installing Firefox version: ${installer.version}'); await installer.install(); - final BrowserInstallation installation = installer.getInstallation(); + final BrowserInstallation installation = installer.getInstallation()!; print( 'Installations complete. To launch it run ${installation.executable}'); } - return installer.getInstallation(); + return installer.getInstallation()!; } finally { installer?.close(); } diff --git a/engine/src/flutter/lib/web_ui/dev/integration_tests_manager.dart b/engine/src/flutter/lib/web_ui/dev/integration_tests_manager.dart index 5fe17d14f7..30794f9b9a 100644 --- a/engine/src/flutter/lib/web_ui/dev/integration_tests_manager.dart +++ b/engine/src/flutter/lib/web_ui/dev/integration_tests_manager.dart @@ -2,8 +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/args.dart'; import 'package:path/path.dart' as pathlib; @@ -182,8 +180,8 @@ class IntegrationTestsManager { final Set renderingBackends = _getRenderingBackends(); for (String renderingBackend in renderingBackends) { for (String mode in buildModes) { - if (!blockedTestsListsMapForModes[mode].contains(target) && - !blockedTestsListsMapForRenderBackends[renderingBackend] + if (!blockedTestsListsMapForModes[mode]!.contains(target) && + !blockedTestsListsMapForRenderBackends[renderingBackend]! .contains(target)) { final bool result = await _runTestsInMode(directory, target, mode: mode, webRenderer: renderingBackend); @@ -268,7 +266,7 @@ class IntegrationTestsManager { // Whether the project has the pubspec.yaml file. bool pubSpecFound = false; // The test directory 'test_driver'. - io.Directory testDirectory; + io.Directory? testDirectory; for (io.FileSystemEntity e in entities) { // The tests should be under this directories. @@ -508,7 +506,7 @@ class IntegrationTestsArgumentParser { /// If target name is provided integration tests can run that one test /// instead of running all the tests. - String testTarget; + late final String testTarget; /// The build mode to run the integration tests. /// @@ -517,13 +515,13 @@ class IntegrationTestsArgumentParser { /// /// In order to skip a test for one of the modes, add the test to the /// `blockedTestsListsMapForModes` list for the relevant compile mode. - String buildMode; + late final String buildMode; /// Whether to use html, canvaskit or auto for web renderer. /// /// If not set all backends will be used one after another for integration /// tests. If set only the provided option will be used. - String webRenderer; + late final String webRenderer; void populateOptions(ArgParser argParser) { argParser diff --git a/engine/src/flutter/lib/web_ui/dev/safari.dart b/engine/src/flutter/lib/web_ui/dev/safari.dart index 46231f783e..cbcd42ca2f 100644 --- a/engine/src/flutter/lib/web_ui/dev/safari.dart +++ b/engine/src/flutter/lib/web_ui/dev/safari.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'; @@ -21,16 +20,11 @@ class Safari extends Browser { @override final name = 'Safari'; - static String version; - - static bool isMobileBrowser; - /// Starts a new instance of Safari open to the given [url], which may be a /// [Uri] or a [String]. factory Safari(Uri url, {bool debug = false}) { - version = SafariArgParser.instance.version; - isMobileBrowser = SafariArgParser.instance.isMobileBrowser; - assert(version != null); + final String version = SafariArgParser.instance.version; + final bool isMobileBrowser = SafariArgParser.instance.isMobileBrowser; return Safari._(() async { if (isMobileBrowser) { // iOS-Safari diff --git a/engine/src/flutter/lib/web_ui/dev/safari_installation.dart b/engine/src/flutter/lib/web_ui/dev/safari_installation.dart index 773a5b7f58..db09e9484d 100644 --- a/engine/src/flutter/lib/web_ui/dev/safari_installation.dart +++ b/engine/src/flutter/lib/web_ui/dev/safari_installation.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; @@ -19,8 +18,6 @@ class SafariArgParser extends BrowserArgParser { /// The [SafariArgParser] singleton. static SafariArgParser get instance => _singletonInstance; - String _version; - SafariArgParser._(); @override @@ -49,45 +46,64 @@ class SafariArgParser extends BrowserArgParser { @override String get version => _version; + late String _version; - bool _isMobileBrowser; bool get isMobileBrowser => _isMobileBrowser; + late bool _isMobileBrowser; } class IosSafariArgParser extends BrowserArgParser { - static final IosSafariArgParser _singletonInstance = IosSafariArgParser._(); + static final IosSafariArgParser _singletonInstance = () { + final YamlMap browserLock = BrowserLock.instance.configuration; + return IosSafariArgParser._( + pinnedIosMajorVersion: browserLock['ios-safari']['majorVersion'] as int, + pinnedIosMinorVersion: browserLock['ios-safari']['minorVersion'] as int, + pinnedIosDevice: browserLock['ios-safari']['device'] as String, + ); + }(); /// The [IosSafariArgParser] singleton. static IosSafariArgParser get instance => _singletonInstance; String get version => 'iOS ${iosMajorVersion}.${iosMinorVersion}'; - int _pinnedIosMajorVersion; - int _iosMajorVersion; + final int _pinnedIosMajorVersion; + int? _iosMajorVersion; int get iosMajorVersion => _iosMajorVersion ?? _pinnedIosMajorVersion; - int _pinnedIosMinorVersion; - int _iosMinorVersion; + final int _pinnedIosMinorVersion; + int? _iosMinorVersion; int get iosMinorVersion => _iosMinorVersion ?? _pinnedIosMinorVersion; - String _pinnedIosDevice; - String _iosDevice; + final String _pinnedIosDevice; + String? _iosDevice; String get iosDevice => _iosDevice ?? _pinnedIosDevice; - IosSafariArgParser._(); + IosSafariArgParser._({ + required int pinnedIosMajorVersion, + required int pinnedIosMinorVersion, + required String pinnedIosDevice, + }) : + this._pinnedIosMajorVersion = pinnedIosMajorVersion, + this._pinnedIosMinorVersion = pinnedIosMinorVersion, + this._pinnedIosDevice = pinnedIosDevice; /// Returns [IosSimulator] if the [Platform] is `macOS` and simulator /// is started. /// /// Throws an [StateError] if these two conditions are not met. - IosSimulator get iosSimulator => io.Platform.isMacOS - ? (_iosSimulator != null - ? _iosSimulator - : throw StateError('iosSimulator not started. Please first call ' - 'initIOSSimulator method')) - : throw StateError('iOS Simulator is only available on macOS machines.'); - - IosSimulator _iosSimulator; + IosSimulator get iosSimulator { + if (!io.Platform.isMacOS) { + throw StateError('iOS Simulator is only available on macOS machines.'); + } + if (_iosSimulator == null) { + throw StateError( + 'iOS Simulator not started. Please first call initIOSSimulator method', + ); + } + return _iosSimulator!; + } + IosSimulator? _iosSimulator; /// Inializes and boots an [IosSimulator] using the [iosMajorVersion], /// [iosMinorVersion] and [iosDevice] arguments. @@ -96,36 +112,34 @@ class IosSafariArgParser extends BrowserArgParser { throw StateError('_iosSimulator can only be initialized once'); } final IosSimulatorManager iosSimulatorManager = IosSimulatorManager(); + final IosSimulator simulator; try { - _iosSimulator = await iosSimulatorManager.getSimulator( + simulator = await iosSimulatorManager.getSimulator( iosMajorVersion, iosMinorVersion, iosDevice, ); + _iosSimulator = simulator; } catch (e) { throw Exception('Error getting requested simulator. Try running ' '`felt create` command first before running the tests. Exception: ' '$e'); } - if (!_iosSimulator.booted) { - await _iosSimulator.boot(); - print('INFO: Simulator ${_iosSimulator.id} booted.'); + if (!simulator.booted) { + await simulator.boot(); + print('INFO: Simulator ${simulator.id} booted.'); cleanupCallbacks.add(() async { - await _iosSimulator.shutdown(); - print('INFO: Simulator ${_iosSimulator.id} shutdown.'); + await simulator.shutdown(); + print('INFO: Simulator ${simulator.id} shutdown.'); }); } } @override void populateOptions(ArgParser argParser) { - final YamlMap browserLock = BrowserLock.instance.configuration; - _pinnedIosMajorVersion = browserLock['ios-safari']['majorVersion'] as int; - _pinnedIosMinorVersion = browserLock['ios-safari']['minorVersion'] as int; final pinnedIosVersion = '${_pinnedIosMajorVersion}.${_pinnedIosMinorVersion}'; - _pinnedIosDevice = browserLock['ios-safari']['device'] as String; argParser ..addOption('version', defaultsTo: '$pinnedIosVersion', @@ -171,7 +185,7 @@ class IosSafariArgParser extends BrowserArgParser { // technology preview. Future getOrInstallSafari( String requestedVersion, { - StringSink infoLog, + StringSink? infoLog, }) async { // These tests are aimed to run only on macOS machines local or on LUCI. if (!io.Platform.isMacOS) { diff --git a/engine/src/flutter/lib/web_ui/dev/screenshot_manager.dart b/engine/src/flutter/lib/web_ui/dev/screenshot_manager.dart index 3cceaa267d..6a75ebc252 100644 --- a/engine/src/flutter/lib/web_ui/dev/screenshot_manager.dart +++ b/engine/src/flutter/lib/web_ui/dev/screenshot_manager.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:io' as io; import 'dart:convert'; import 'dart:math'; @@ -32,14 +31,19 @@ class ChromeScreenshotManager extends ScreenshotManager { /// [region] is used to decide which part of the web content will be used in /// test image. It includes starting coordinate x,y as well as height and /// width of the area to capture. - Future capture(Rectangle region) async { + Future capture(Rectangle? region) async { final wip.ChromeConnection chromeConnection = wip.ChromeConnection('localhost', kDevtoolsPort); - final wip.ChromeTab chromeTab = await chromeConnection.getTab( + final wip.ChromeTab? chromeTab = await chromeConnection.getTab( (wip.ChromeTab chromeTab) => chromeTab.url.contains('localhost')); + if (chromeTab == null) { + throw StateError( + 'Failed locate Chrome tab with the test page', + ); + } final wip.WipConnection wipConnection = await chromeTab.connect(); - Map captureScreenshotParameters = null; + Map? captureScreenshotParameters = null; if (region != null) { captureScreenshotParameters = { 'format': 'png', @@ -68,7 +72,7 @@ class ChromeScreenshotManager extends ScreenshotManager { 'Page.captureScreenshot', captureScreenshotParameters); final Image screenshot = - decodePng(base64.decode(response.result['data'] as String)); + decodePng(base64.decode(response.result!['data'] as String))!; return screenshot; } @@ -99,7 +103,7 @@ class IosSafariScreenshotManager extends ScreenshotManager { /// This scale factor is used to enlarge/shrink the screenshot region /// sent from the tests. /// For more details see [_scaleScreenshotRegion(region)]. - double _scaleFactor; + late final double _scaleFactor; /// Height of the part to crop from the top of the image. /// @@ -108,13 +112,13 @@ class IosSafariScreenshotManager extends ScreenshotManager { /// the screen, the screenshot will differ between each run. /// Note that this gap can change per phone and per iOS version. For more /// details refer to `browser_lock.yaml` file. - int _heightOfHeader; + late final int _heightOfHeader; /// Height of the part to crop from the bottom of the image. /// /// This area is the footer navigation bar of the phone, it is not the area /// used by tests (which is inside the browser). - int _heightOfFooter; + late final int _heightOfFooter; /// Used as a suffix for the temporary file names used for screenshots. int _fileNameCounter = 0; @@ -153,7 +157,7 @@ class IosSafariScreenshotManager extends ScreenshotManager { /// width of the area to capture. /// /// Uses simulator tool `xcrun simctl`'s 'screenshot' command. - Future capture(Rectangle region) async { + Future capture(Rectangle? region) async { final String filename = 'screenshot${_fileNameCounter}.png'; _fileNameCounter++; @@ -170,7 +174,7 @@ class IosSafariScreenshotManager extends ScreenshotManager { imageBytes = await file.readAsBytes(); file.deleteSync(); - final Image screenshot = decodePng(imageBytes); + final Image screenshot = decodePng(imageBytes)!; // Create an image with no footer and header. The _heightOfHeader, // _heightOfFooter values are already in real coordinates therefore // they don't need to be scaled. @@ -227,7 +231,7 @@ abstract class ScreenshotManager { static ScreenshotManager choose(String browser) { if (isBrowserSupported(browser)) { - return _browserFactories[browser](); + return _browserFactories[browser]!(); } throw StateError('Screenshot tests are only supported on Chrome and on ' 'iOS Safari'); diff --git a/engine/src/flutter/lib/web_ui/dev/supported_browsers.dart b/engine/src/flutter/lib/web_ui/dev/supported_browsers.dart index 5c475d5c5c..dff687a209 100644 --- a/engine/src/flutter/lib/web_ui/dev/supported_browsers.dart +++ b/engine/src/flutter/lib/web_ui/dev/supported_browsers.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 'package:test_api/src/backend/runtime.dart'; import 'browser.dart'; diff --git a/engine/src/flutter/lib/web_ui/pubspec.yaml b/engine/src/flutter/lib/web_ui/pubspec.yaml index 4b14073189..9e968f2e18 100644 --- a/engine/src/flutter/lib/web_ui/pubspec.yaml +++ b/engine/src/flutter/lib/web_ui/pubspec.yaml @@ -28,9 +28,9 @@ dev_dependencies: git: url: git://github.com/flutter/web_installers.git path: packages/simulators/ - ref: 4a9643e55e9bd127f4e4e3cb20e562ed5d5b9aa7 + ref: 4a7b0a2c84b8993bf4d19030218de38c18838c26 web_driver_installer: git: url: git://github.com/flutter/web_installers.git path: packages/web_drivers/ - ref: 946111ae3248132e3773bf5c5327bcbbefa0c5f2 + ref: 4a7b0a2c84b8993bf4d19030218de38c18838c26