diff --git a/engine/src/flutter/lib/web_ui/dev/browser.dart b/engine/src/flutter/lib/web_ui/dev/browser.dart index 0b8c79255c..4c46d64bac 100644 --- a/engine/src/flutter/lib/web_ui/dev/browser.dart +++ b/engine/src/flutter/lib/web_ui/dev/browser.dart @@ -26,12 +26,12 @@ abstract class BrowserEnvironment { /// Prepares the OS environment to run tests for this browser. /// - /// This may include things like staring web drivers, iOS Simulators, and/or - /// Android emulators. + /// This may include things like installing browsers, and starting web drivers, + /// iOS Simulators, and/or Android emulators. /// /// Typically the browser environment is prepared once and supports multiple /// browser instances. - Future prepareEnvironment(); + Future prepare(); /// Launches a browser instance. /// diff --git a/engine/src/flutter/lib/web_ui/dev/chrome.dart b/engine/src/flutter/lib/web_ui/dev/chrome.dart index 5fbde02a8f..f793153cb8 100644 --- a/engine/src/flutter/lib/web_ui/dev/chrome.dart +++ b/engine/src/flutter/lib/web_ui/dev/chrome.dart @@ -21,17 +21,23 @@ import 'environment.dart'; /// Provides an environment for desktop Chrome. class ChromeEnvironment implements BrowserEnvironment { + late final BrowserInstallation _installation; + @override Browser launchBrowserInstance(Uri url, {bool debug = false}) { - return Chrome(url, debug: debug); + return Chrome(url, _installation, debug: debug); } @override Runtime get packageTestRuntime => Runtime.chrome; @override - Future prepareEnvironment() async { - // Chrome doesn't need any special prep. + Future prepare() async { + final String version = browserLock.chromeLock.versionForCurrentPlatform; + _installation = await getOrInstallChrome( + version, + infoLog: isCirrus ? stdout : DevNull(), + ); } @override @@ -64,15 +70,9 @@ class Chrome extends Browser { /// 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}) { - final String version = browserLock.chromeLock.versionForCurrentPlatform; + factory Chrome(Uri url, BrowserInstallation installation, {bool debug = false}) { final Completer remoteDebuggerCompleter = Completer.sync(); return Chrome._(() async { - final BrowserInstallation installation = await getOrInstallChrome( - version, - infoLog: isCirrus ? stdout : DevNull(), - ); - // A good source of various Chrome CLI options: // https://peter.sh/experiments/chromium-command-line-switches/ // 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 46fec58a99..72d432e206 100644 --- a/engine/src/flutter/lib/web_ui/dev/chrome_installer.dart +++ b/engine/src/flutter/lib/web_ui/dev/chrome_installer.dart @@ -11,7 +11,6 @@ import 'package:archive/archive_io.dart'; import 'package:http/http.dart'; import 'package:path/path.dart' as path; -import 'browser_lock.dart'; import 'common.dart'; import 'environment.dart'; import 'exceptions.dart'; @@ -140,25 +139,21 @@ class ChromeInstaller { } Future install() async { - if (versionDir.existsSync() && !isLuci) { - versionDir.deleteSync(recursive: true); - versionDir.createSync(recursive: true); - } else if (versionDir.existsSync() && isLuci) { - print('INFO: Chrome version directory in LUCI: ' - '${versionDir.path}'); - } else if (!versionDir.existsSync() && isLuci) { - // Chrome should have been deployed as a CIPD package on LUCI. - // Throw if it does not exists. - throw StateError('Failed to locate Chrome on LUCI on path:' - '${versionDir.path}'); - } else { - // If the directory does not exists and felt is not running on LUCI. - versionDir.createSync(recursive: true); + if (isLuci) { + throw StateError( + 'Rejecting attempt to install Chromium on LUCI. LUCI is expected to ' + 'provide Chromium as a CIPD dependency managed using .ci.yaml.', + ); } - print('INFO: Starting Chrome download.'); + if (versionDir.existsSync()) { + versionDir.deleteSync(recursive: true); + } + versionDir.createSync(recursive: true); final String url = PlatformBinding.instance.getChromeDownloadUrl(version); + print('Downloading Chrome from $url'); + final StreamedResponse download = await client.send(Request( 'GET', Uri.parse(url), @@ -256,24 +251,3 @@ Future fetchLatestChromeVersion() async { client.close(); } } - -/// Make sure LUCI bot has the pinned Chrome version and return the executable. -/// -/// We are using CIPD packages in LUCI. The pinned chrome version from the -/// `browser_lock.yaml` file will already be installed in the LUCI bot. -/// Verify if Chrome is installed and use it for the integration tests. -String preinstalledChromeExecutable() { - // Note that build number and major version is different for Chrome. - // For example for a build number `753189`, major version is 83. - final String buildNumber = browserLock.chromeLock.versionForCurrentPlatform; - final ChromeInstaller chromeInstaller = ChromeInstaller(version: buildNumber); - if (chromeInstaller.isInstalled) { - 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.', - ); - } -} diff --git a/engine/src/flutter/lib/web_ui/dev/edge.dart b/engine/src/flutter/lib/web_ui/dev/edge.dart index 0b810bccca..bf3acc7159 100644 --- a/engine/src/flutter/lib/web_ui/dev/edge.dart +++ b/engine/src/flutter/lib/web_ui/dev/edge.dart @@ -23,7 +23,7 @@ class EdgeEnvironment implements BrowserEnvironment { Runtime get packageTestRuntime => Runtime.internetExplorer; @override - Future prepareEnvironment() async { + Future prepare() async { // Edge doesn't need any special prep. } diff --git a/engine/src/flutter/lib/web_ui/dev/firefox.dart b/engine/src/flutter/lib/web_ui/dev/firefox.dart index 61c02da271..c661378600 100644 --- a/engine/src/flutter/lib/web_ui/dev/firefox.dart +++ b/engine/src/flutter/lib/web_ui/dev/firefox.dart @@ -18,17 +18,22 @@ import 'firefox_installer.dart'; /// Provides an environment for the desktop Firefox. class FirefoxEnvironment implements BrowserEnvironment { + late final BrowserInstallation _installation; + @override Browser launchBrowserInstance(Uri url, {bool debug = false}) { - return Firefox(url, debug: debug); + return Firefox(url, this, debug: debug); } @override Runtime get packageTestRuntime => Runtime.firefox; @override - Future prepareEnvironment() async { - // Firefox doesn't need any special prep. + Future prepare() async { + _installation = await getOrInstallFirefox( + browserLock.firefoxLock.version, + infoLog: isCirrus ? stdout : DevNull(), + ); } @override @@ -54,14 +59,10 @@ class Firefox extends Browser { /// 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}) { + factory Firefox(Uri url, FirefoxEnvironment firefoxEnvironment, {bool debug = false}) { + final BrowserInstallation installation = firefoxEnvironment._installation; final Completer remoteDebuggerCompleter = Completer.sync(); return Firefox._(() async { - final BrowserInstallation installation = await getOrInstallFirefox( - browserLock.firefoxLock.version, - infoLog: isCirrus ? stdout : DevNull(), - ); - // Using a profile on opening will prevent popups related to profiles. const String _profile = ''' user_pref("browser.shell.checkDefaultBrowser", false); @@ -79,9 +80,9 @@ user_pref("dom.max_script_run_time", 0); temporaryProfileDirectory.deleteSync(recursive: true); } temporaryProfileDirectory.createSync(recursive: true); - File(path.join(temporaryProfileDirectory.path, 'prefs.js')) .writeAsStringSync(_profile); + final bool isMac = Platform.isMacOS; final List args = [ url.toString(), diff --git a/engine/src/flutter/lib/web_ui/dev/safari_ios.dart b/engine/src/flutter/lib/web_ui/dev/safari_ios.dart index cd68ec0fc7..0dd41c08c8 100644 --- a/engine/src/flutter/lib/web_ui/dev/safari_ios.dart +++ b/engine/src/flutter/lib/web_ui/dev/safari_ios.dart @@ -28,7 +28,7 @@ class SafariIosEnvironment implements BrowserEnvironment { Runtime get packageTestRuntime => Runtime.safari; @override - Future prepareEnvironment() async { + Future prepare() async { await initIosSimulator(); } diff --git a/engine/src/flutter/lib/web_ui/dev/safari_macos.dart b/engine/src/flutter/lib/web_ui/dev/safari_macos.dart index 5bfc70ef8c..1cbbed65f2 100644 --- a/engine/src/flutter/lib/web_ui/dev/safari_macos.dart +++ b/engine/src/flutter/lib/web_ui/dev/safari_macos.dart @@ -23,7 +23,7 @@ class SafariMacOsEnvironment implements BrowserEnvironment { Runtime get packageTestRuntime => Runtime.safari; @override - Future prepareEnvironment() async { + Future prepare() async { // Nothing extra to prepare for desktop Safari. } diff --git a/engine/src/flutter/lib/web_ui/dev/steps/run_tests_step.dart b/engine/src/flutter/lib/web_ui/dev/steps/run_tests_step.dart index 6142cad120..185ae8e811 100644 --- a/engine/src/flutter/lib/web_ui/dev/steps/run_tests_step.dart +++ b/engine/src/flutter/lib/web_ui/dev/steps/run_tests_step.dart @@ -73,7 +73,7 @@ class RunTestsStep implements PipelineStep { @override Future run() async { await _prepareTestResultsDirectory(); - await _browserEnvironment.prepareEnvironment(); + await _browserEnvironment.prepare(); final SkiaGoldClient? skiaClient = await _createSkiaClient();