未验证 提交 bc41ab51 编写于 作者: N Nurhan Turgut 提交者: GitHub

[web] Add Edge support for Flutter Engine unit-tests. (#15641)

* Add Edge support for Flutter Engine unit-tests. This does not include the launcher

* Add mapping from browser name to platform.

* remove ie from supported browser maps
上级 32915417
# For more information on test and runner configurations:
#
# * https://github.com/dart-lang/test/blob/master/pkgs/test/doc/configuration.md#platforms
platforms:
- ie
- vm
...@@ -51,6 +51,7 @@ abstract class PlatformBinding { ...@@ -51,6 +51,7 @@ abstract class PlatformBinding {
String getFirefoxExecutablePath(io.Directory versionDir); String getFirefoxExecutablePath(io.Directory versionDir);
String getFirefoxLatestVersionUrl(); String getFirefoxLatestVersionUrl();
String getSafariSystemExecutablePath(); String getSafariSystemExecutablePath();
String getCommandToRunEdge();
} }
const String _kBaseDownloadUrl = const String _kBaseDownloadUrl =
...@@ -86,6 +87,12 @@ class _WindowsBinding implements PlatformBinding { ...@@ -86,6 +87,12 @@ class _WindowsBinding implements PlatformBinding {
@override @override
String getSafariSystemExecutablePath() => String getSafariSystemExecutablePath() =>
throw UnsupportedError('Safari is not supported on Windows'); throw UnsupportedError('Safari is not supported on Windows');
// TODO(nurhan): Add code to check and install MicrosoftEdgeLauncher
// if missing.
// See: https://github.com/flutter/flutter/issues/48823
@override
String getCommandToRunEdge() => 'MicrosoftEdgeLauncher';
} }
class _LinuxBinding implements PlatformBinding { class _LinuxBinding implements PlatformBinding {
...@@ -118,6 +125,10 @@ class _LinuxBinding implements PlatformBinding { ...@@ -118,6 +125,10 @@ class _LinuxBinding implements PlatformBinding {
@override @override
String getSafariSystemExecutablePath() => String getSafariSystemExecutablePath() =>
throw UnsupportedError('Safari is not supported on Linux'); throw UnsupportedError('Safari is not supported on Linux');
@override
String getCommandToRunEdge() =>
throw UnsupportedError('Edge is not supported on Linux');
} }
class _MacBinding implements PlatformBinding { class _MacBinding implements PlatformBinding {
...@@ -155,6 +166,10 @@ class _MacBinding implements PlatformBinding { ...@@ -155,6 +166,10 @@ class _MacBinding implements PlatformBinding {
@override @override
String getSafariSystemExecutablePath() => String getSafariSystemExecutablePath() =>
'/Applications/Safari.app/Contents/MacOS/Safari'; '/Applications/Safari.app/Contents/MacOS/Safari';
@override
String getCommandToRunEdge() =>
throw UnimplementedError('Tests for Edge are not implemented for MacOS.');
} }
class BrowserInstallation { class BrowserInstallation {
......
// 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.
import 'dart:async';
import 'dart:io';
import 'browser.dart';
import 'common.dart';
import 'edge_installation.dart';
/// A class for running an instance of Edge.
///
/// Most of the communication with the browser is expected to happen via HTTP,
/// so this exposes a bare-bones API. The browser starts as soon as the class is
/// constructed, and is killed when [close] is called.
///
/// Any errors starting or running the process are reported through [onExit].
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;
assert(version != null);
return Edge._(() async {
// TODO(nurhan): Configure info log for LUCI.
final BrowserInstallation installation = await getEdgeInstallation(
version,
infoLog: DevNull(),
);
// Debug is not a valid option for Edge. Remove it.
String pathToOpen = url.toString();
if(pathToOpen.contains('debug')) {
int index = pathToOpen.indexOf('debug');
pathToOpen = pathToOpen.substring(0, index-1);
}
var process =
await Process.start(installation.executable, ['$pathToOpen','-k']);
return process;
});
}
Edge._(Future<Process> startBrowser()) : super(startBrowser);
}
// 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.
import 'dart:async';
import 'dart:io' as io;
import 'package:args/args.dart';
import 'common.dart';
class EdgeArgParser extends BrowserArgParser {
static final EdgeArgParser _singletonInstance = EdgeArgParser._();
/// The [EdgeArgParser] singleton.
static EdgeArgParser get instance => _singletonInstance;
String _version;
EdgeArgParser._();
@override
void populateOptions(ArgParser argParser) {
argParser
..addOption(
'edge-version',
defaultsTo: 'system',
help: 'The Edge version to use while running tests. The Edge '
'browser installed on the system is used as the only option now.',
);
}
@override
void parseOptions(ArgResults argResults) {
_version = argResults['edge-version'];
assert(_version == 'system');
}
@override
String get version => _version;
}
/// Returns the installation of Edge.
///
/// Currently uses the Edge version installed on the operating system.
///
/// As explained on the Microsoft help page: `Microsoft Edge comes
/// exclusively with Windows 10 and cannot be downloaded or installed separately.`
/// See: https://support.microsoft.com/en-us/help/17171/microsoft-edge-get-to-know
///
// TODO(nurhan): Investigate running tests for the tech preview downloads
// from the beta channel.
Future<BrowserInstallation> getEdgeInstallation(
String requestedVersion, {
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.
if (!io.Platform.isWindows) {
throw UnimplementedError(
'Tests for Edge on ${io.Platform.operatingSystem} is'
' not supported.');
}
infoLog ??= io.stdout;
if (requestedVersion == 'system') {
// Since Edge is included in Windows, always assume there will be one on the
// system.
infoLog.writeln('Using the system version that is already installed.');
return BrowserInstallation(
version: 'system',
executable: PlatformBinding.instance.getCommandToRunEdge(),
);
} else {
infoLog.writeln('Unsupported version $requestedVersion.');
throw UnimplementedError();
}
}
...@@ -8,7 +8,9 @@ import 'browser.dart'; ...@@ -8,7 +8,9 @@ import 'browser.dart';
import 'chrome.dart'; import 'chrome.dart';
import 'chrome_installer.dart'; import 'chrome_installer.dart';
import 'common.dart'; import 'common.dart';
import 'edge.dart';
import 'environment.dart'; import 'environment.dart';
import 'edge_installation.dart';
import 'firefox.dart'; import 'firefox.dart';
import 'firefox_installer.dart'; import 'firefox_installer.dart';
import 'safari.dart'; import 'safari.dart';
...@@ -23,21 +25,43 @@ import 'safari_installation.dart'; ...@@ -23,21 +25,43 @@ import 'safari_installation.dart';
/// ///
/// One should also implement [BrowserArgParser] and add it to the [argParsers]. /// One should also implement [BrowserArgParser] and add it to the [argParsers].
class SupportedBrowsers { class SupportedBrowsers {
final List<BrowserArgParser> argParsers = final List<BrowserArgParser> argParsers = List.of([
List.of([ChromeArgParser.instance, FirefoxArgParser.instance, SafariArgParser.instance]); ChromeArgParser.instance,
EdgeArgParser.instance,
FirefoxArgParser.instance,
SafariArgParser.instance
]);
final List<String> supportedBrowserNames = ['chrome', 'firefox', 'safari']; final List<String> supportedBrowserNames = [
'chrome',
'edge',
'firefox',
'safari'
];
final Map<String, Runtime> supportedBrowsersToRuntimes = { final Map<String, Runtime> supportedBrowsersToRuntimes = {
'chrome': Runtime.chrome, 'chrome': Runtime.chrome,
'edge': Runtime.internetExplorer,
'firefox': Runtime.firefox, 'firefox': Runtime.firefox,
'safari': Runtime.safari, 'safari': Runtime.safari,
}; };
final Map<String, String> supportedBrowserToPlatform = {
'chrome': 'chrome',
'edge': 'ie',
'firefox': 'firefox',
'safari': 'safari',
};
final Map<String, String> browserToConfiguration = { final Map<String, String> browserToConfiguration = {
'chrome': '--configuration=${environment.webUiRootDir.path}/dart_test_chrome.yaml', 'chrome':
'firefox': '--configuration=${environment.webUiRootDir.path}/dart_test_firefox.yaml', '--configuration=${environment.webUiRootDir.path}/dart_test_chrome.yaml',
'safari': '--configuration=${environment.webUiRootDir.path}/dart_test_safari.yaml', 'edge':
'--configuration=${environment.webUiRootDir.path}/dart_test_edge.yaml',
'firefox':
'--configuration=${environment.webUiRootDir.path}/dart_test_firefox.yaml',
'safari':
'--configuration=${environment.webUiRootDir.path}/dart_test_safari.yaml',
}; };
static final SupportedBrowsers _singletonInstance = SupportedBrowsers._(); static final SupportedBrowsers _singletonInstance = SupportedBrowsers._();
...@@ -48,8 +72,10 @@ class SupportedBrowsers { ...@@ -48,8 +72,10 @@ class SupportedBrowsers {
SupportedBrowsers._(); SupportedBrowsers._();
Browser getBrowser(Runtime runtime, Uri url, {bool debug = false}) { Browser getBrowser(Runtime runtime, Uri url, {bool debug = false}) {
if (runtime == Runtime.chrome) { if (runtime == Runtime.chrome) {
return Chrome(url, debug: debug); return Chrome(url, debug: debug);
} else if (runtime == Runtime.internetExplorer) {
return Edge(url, debug: debug);
} else if (runtime == Runtime.firefox) { } else if (runtime == Runtime.firefox) {
return Firefox(url, debug: debug); return Firefox(url, debug: debug);
} else if (runtime == Runtime.safari) { } else if (runtime == Runtime.safari) {
......
...@@ -250,9 +250,7 @@ class TestCommand extends Command<bool> { ...@@ -250,9 +250,7 @@ class TestCommand extends Command<bool> {
} }
Future<void> _buildTests({List<FilePath> targets}) async { Future<void> _buildTests({List<FilePath> targets}) async {
final int exitCode = await runProcess( List<String> arguments = <String>[
environment.pubExecutable,
<String>[
'run', 'run',
'build_runner', 'build_runner',
'build', 'build',
...@@ -264,7 +262,10 @@ class TestCommand extends Command<bool> { ...@@ -264,7 +262,10 @@ class TestCommand extends Command<bool> {
'--build-filter=${path.relativeToWebUi}.js', '--build-filter=${path.relativeToWebUi}.js',
'--build-filter=${path.relativeToWebUi}.browser_test.dart.js', '--build-filter=${path.relativeToWebUi}.browser_test.dart.js',
], ],
], ];
final int exitCode = await runProcess(
environment.pubExecutable,
arguments,
workingDirectory: environment.webUiRootDir.path, workingDirectory: environment.webUiRootDir.path,
); );
...@@ -287,7 +288,7 @@ class TestCommand extends Command<bool> { ...@@ -287,7 +288,7 @@ class TestCommand extends Command<bool> {
...<String>['-r', 'compact'], ...<String>['-r', 'compact'],
'--concurrency=$concurrency', '--concurrency=$concurrency',
if (isDebug) '--pause-after-load', if (isDebug) '--pause-after-load',
'--platform=$browser', '--platform=${SupportedBrowsers.instance.supportedBrowserToPlatform[browser]}',
'--precompiled=${environment.webUiRootDir.path}/build', '--precompiled=${environment.webUiRootDir.path}/build',
SupportedBrowsers.instance.browserToConfiguration[browser], SupportedBrowsers.instance.browserToConfiguration[browser],
'--', '--',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册