Skip to content

Commit

Permalink
Add macOS testing support (flutter#12383)
Browse files Browse the repository at this point in the history
- Add support for macOS in `felt test`
- Set viewport so it does not depend on real device pixel density
  • Loading branch information
yjbanov authored Sep 22, 2019
1 parent e729144 commit 94368ac
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 11 deletions.
1 change: 0 additions & 1 deletion lib/web_ui/dev/chrome.lock

This file was deleted.

60 changes: 52 additions & 8 deletions lib/web_ui/dev/chrome_installer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand All @@ -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"
Expand Down Expand Up @@ -162,7 +162,7 @@ class ChromeInstaller {

return ChromeInstallation(
version: version,
executable: path.join(versionDir.path, 'chrome-linux', 'chrome'),
executable: _PlatformBinding.instance.getExecutablePath(versionDir),
);
}

Expand All @@ -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),
Expand Down Expand Up @@ -226,3 +226,47 @@ Future<String> 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');
}
4 changes: 4 additions & 0 deletions lib/web_ui/dev/chrome_lock.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion lib/web_ui/dev/test_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion lib/web_ui/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 94368ac

Please sign in to comment.