diff --git a/engine/src/flutter/lib/web_ui/dev/chrome.lock b/engine/src/flutter/lib/web_ui/dev/chrome.lock deleted file mode 100644 index 709de25af8..0000000000 --- a/engine/src/flutter/lib/web_ui/dev/chrome.lock +++ /dev/null @@ -1 +0,0 @@ -695653 \ No newline at end of file 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 39abff2e3e..8b54e86b1f 100644 --- a/engine/src/flutter/lib/web_ui/dev/chrome_installer.dart +++ b/engine/src/flutter/lib/web_ui/dev/chrome_installer.dart @@ -8,19 +8,19 @@ 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'; import 'environment.dart'; void addChromeVersionOption(ArgParser argParser) { - final String pinnedChromeVersion = - io.File(path.join(environment.webUiRootDir.path, 'dev', 'chrome.lock')) - .readAsStringSync() - .trim(); + final io.File lockFile = io.File(path.join(environment.webUiRootDir.path, 'dev', 'chrome_lock.yaml')); + final YamlMap lock = loadYaml(lockFile.readAsStringSync()); + final int pinnedChromeVersion = _PlatformBinding.instance.getChromeBuild(lock); argParser ..addOption( 'chrome-version', - defaultsTo: pinnedChromeVersion, + defaultsTo: '$pinnedChromeVersion', help: 'The Chrome version to use while running tests. If the requested ' 'version has not been installed, it will be downloaded and installed ' 'automatically. A specific Chrome build version number, such as 695653 ' @@ -34,7 +34,7 @@ void addChromeVersionOption(ArgParser argParser) { /// /// If [requestedVersion] is null, uses the version specified on the /// command-line. If not specified on the command-line, uses the version -/// specified in the "chrome.lock" file. +/// specified in the "chrome_lock.yaml" file. /// /// If [requestedVersion] is not null, installs that version. The value /// may be "latest" (the latest available build of Chrome), "system" @@ -162,7 +162,7 @@ class ChromeInstaller { return ChromeInstallation( version: version, - executable: path.join(versionDir.path, 'chrome-linux', 'chrome'), + executable: _PlatformBinding.instance.getExecutablePath(versionDir), ); } @@ -172,7 +172,7 @@ class ChromeInstaller { } versionDir.createSync(recursive: true); - final String url = 'https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F$version%2Fchrome-linux.zip?alt=media'; + final String url = _PlatformBinding.instance.getDownloadUrl(version); final StreamedResponse download = await client.send(Request( 'GET', Uri.parse(url), @@ -226,3 +226,47 @@ Future fetchLatestChromeVersion() async { client.close(); } } + +abstract class _PlatformBinding { + static _PlatformBinding get instance { + if (_instance == null) { + if (io.Platform.isLinux) { + _instance = _LinuxBinding(); + } else if (io.Platform.isMacOS) { + _instance = _MacBinding(); + } else { + throw '${io.Platform.operatingSystem} is not supported'; + } + } + return _instance; + } + static _PlatformBinding _instance; + + int getChromeBuild(YamlMap chromeLock); + String getDownloadUrl(String version); + String getExecutablePath(io.Directory versionDir); +} + +const String _kBaseDownloadUrl = 'https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o'; + +class _LinuxBinding implements _PlatformBinding { + @override + int getChromeBuild(YamlMap chromeLock) => chromeLock['Linux']; + + @override + String getDownloadUrl(String version) => '$_kBaseDownloadUrl/Linux_x64%2F$version%2Fchrome-linux.zip?alt=media'; + + @override + String getExecutablePath(io.Directory versionDir) => path.join(versionDir.path, 'chrome-linux', 'chrome'); +} + +class _MacBinding implements _PlatformBinding { + @override + int getChromeBuild(YamlMap chromeLock) => chromeLock['Mac']; + + @override + String getDownloadUrl(String version) => '$_kBaseDownloadUrl/Mac%2F$version%2Fchrome-mac.zip?alt=media'; + + @override + String getExecutablePath(io.Directory versionDir) => path.join(versionDir.path, 'chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium'); +} diff --git a/engine/src/flutter/lib/web_ui/dev/chrome_lock.yaml b/engine/src/flutter/lib/web_ui/dev/chrome_lock.yaml new file mode 100644 index 0000000000..3023a96d14 --- /dev/null +++ b/engine/src/flutter/lib/web_ui/dev/chrome_lock.yaml @@ -0,0 +1,4 @@ +# It seems Chrome can't always release from the same build for all operating +# systems, so we specify per-OS build number. +Linux: 695653 +Mac: 695656 diff --git a/engine/src/flutter/lib/web_ui/dev/test_platform.dart b/engine/src/flutter/lib/web_ui/dev/test_platform.dart index 79be1fd2de..339e4fa0bc 100644 --- a/engine/src/flutter/lib/web_ui/dev/test_platform.dart +++ b/engine/src/flutter/lib/web_ui/dev/test_platform.dart @@ -178,8 +178,15 @@ To automatically create this file call matchGoldenFile('$filename', write: true) }, }; } - // To tweak DPI we need to send an additional Emulation.setDeviceMetricsOverride. See: + + // Setting hardware-independent screen parameters: // https://chromedevtools.github.io/devtools-protocol/tot/Emulation + await wipConnection.sendCommand('Emulation.setDeviceMetricsOverride', { + 'width': _kMaxScreenshotWidth, + 'height': _kMaxScreenshotHeight, + 'deviceScaleFactor': 1, + 'mobile': false, + }); final wip.WipResponse response = await wipConnection.sendCommand('Page.captureScreenshot', captureScreenshotParameters); diff --git a/engine/src/flutter/lib/web_ui/pubspec.yaml b/engine/src/flutter/lib/web_ui/pubspec.yaml index f64508a0ed..60deee67e8 100644 --- a/engine/src/flutter/lib/web_ui/pubspec.yaml +++ b/engine/src/flutter/lib/web_ui/pubspec.yaml @@ -6,16 +6,17 @@ environment: dependencies: meta: 1.1.7 - image: 2.1.4 dev_dependencies: http: 0.12.0+2 + image: 2.1.4 path: 1.6.4 test: 1.6.5 quiver: 2.0.5 build_runner: 1.6.5 build_test: 0.10.8 build_web_compilers: 2.1.5 + yaml: 2.2.0 watcher: 0.9.7+12 web_engine_tester: path: ../../web_sdk/web_engine_tester