[web] runs ios unit tests (flutter/engine#18650)
* runs ios unit tests, if the simulator is already booted. * address reviewer comments * changing comments for the Safari desktop tests * addressing reviewer comments. removing the timeout. * change mobile browsers ver name for safari.dart * removing then calback on browser exit, only leaving the exception callback
This commit is contained in:
@@ -23,37 +23,56 @@ class Safari extends Browser {
|
||||
|
||||
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);
|
||||
return Safari._(() async {
|
||||
// TODO(nurhan): Configure info log for LUCI.
|
||||
final BrowserInstallation installation = await getOrInstallSafari(
|
||||
version,
|
||||
infoLog: DevNull(),
|
||||
);
|
||||
if (isMobileBrowser) {
|
||||
// iOS-Safari
|
||||
// Uses `xcrun simctl`. It is a command line utility to control the
|
||||
// Simulator. For more details on interacting with the simulator:
|
||||
// https://developer.apple.com/library/archive/documentation/IDEs/Conceptual/iOS_Simulator_Guide/InteractingwiththeiOSSimulator/InteractingwiththeiOSSimulator.html
|
||||
var process = await Process.start('xcrun', [
|
||||
'simctl',
|
||||
'openurl', // Opens the url on Safari installed on the simulator.
|
||||
'booted', // The simulator is already booted.
|
||||
'${url.toString()}'
|
||||
]);
|
||||
|
||||
// In the latest versions of MacOs opening Safari browser with a file brings
|
||||
// a popup which halts the test.
|
||||
// The following list of arguments needs to be provided to the `open` command
|
||||
// to open Safari for a given URL. In summary they provide a new instance
|
||||
// to open, that instance to wait for opening the url until Safari launches,
|
||||
// provide Safari bundles identifier.
|
||||
// The details copied from `man open` on MacOS.
|
||||
// TODO(nurhan): https://github.com/flutter/flutter/issues/50809
|
||||
var process = await Process.start(installation.executable, [
|
||||
'-F', // Open a fresh application with no persistant state.
|
||||
'-W', // Open to wait until the applications it opens.
|
||||
'-n', // Open a new instance of the application.
|
||||
'-b', // Specifies the bundle identifier for the application to use.
|
||||
'com.apple.Safari', // Bundle identifier for Safari.
|
||||
'${url.toString()}'
|
||||
]);
|
||||
return process;
|
||||
} else {
|
||||
// Desktop-Safari
|
||||
// TODO(nurhan): Configure info log for LUCI.
|
||||
final BrowserInstallation installation = await getOrInstallSafari(
|
||||
version,
|
||||
infoLog: DevNull(),
|
||||
);
|
||||
|
||||
return process;
|
||||
// In the macOS Catalina opening Safari browser with a file brings
|
||||
// a popup which halts the test.
|
||||
// The following list of arguments needs to be provided to the `open`
|
||||
// command to open Safari for a given URL. In summary, `open` tool opens
|
||||
// a new Safari browser (even if one is already open), opens it with no
|
||||
// persistent state and wait until it opens.
|
||||
// The details copied from `man open` on macOS.
|
||||
// TODO(nurhan): https://github.com/flutter/flutter/issues/50809
|
||||
var process = await Process.start(installation.executable, [
|
||||
// These are flags for `open` command line tool.
|
||||
'-F', // Open a fresh Safari with no persistant state.
|
||||
'-W', // Wait until the Safari opens.
|
||||
'-n', // Open a new instance of the Safari even another one is open.
|
||||
'-b', // Specifies the bundle identifier for the application to use.
|
||||
'com.apple.Safari', // Bundle identifier for Safari.
|
||||
'${url.toString()}'
|
||||
]);
|
||||
|
||||
return process;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -37,10 +37,16 @@ class SafariArgParser extends BrowserArgParser {
|
||||
void parseOptions(ArgResults argResults) {
|
||||
_version = argResults['safari-version'] as String;
|
||||
assert(_version == 'system');
|
||||
final String browser = argResults['browser'] as String;
|
||||
_isMobileBrowser = browser == 'ios-safari' ? true : false;
|
||||
}
|
||||
|
||||
@override
|
||||
String get version => _version;
|
||||
|
||||
bool _isMobileBrowser;
|
||||
|
||||
bool get isMobileBrowser => _isMobileBrowser;
|
||||
}
|
||||
|
||||
/// Returns the installation of Safari.
|
||||
@@ -57,16 +63,16 @@ Future<BrowserInstallation> getOrInstallSafari(
|
||||
StringSink infoLog,
|
||||
}) async {
|
||||
|
||||
// These tests are aimed to run only on MacOs machines local or on LUCI.
|
||||
// These tests are aimed to run only on macOS machines local or on LUCI.
|
||||
if (!io.Platform.isMacOS) {
|
||||
throw UnimplementedError('Safari on ${io.Platform.operatingSystem} is'
|
||||
' not supported. Safari is only supported on MacOS.');
|
||||
' not supported. Safari is only supported on macOS.');
|
||||
}
|
||||
|
||||
infoLog ??= io.stdout;
|
||||
|
||||
if (requestedVersion == 'system') {
|
||||
// Since Safari is included in MacOS, always assume there will be one on the
|
||||
// Since Safari is included in macOS, always assume there will be one on the
|
||||
// system.
|
||||
infoLog.writeln('Using the system version that is already installed.');
|
||||
return BrowserInstallation(
|
||||
|
||||
@@ -45,6 +45,7 @@ class SupportedBrowsers {
|
||||
'edge': Runtime.internetExplorer,
|
||||
'firefox': Runtime.firefox,
|
||||
'safari': Runtime.safari,
|
||||
'ios-safari': Runtime.safari,
|
||||
};
|
||||
|
||||
final Map<String, String> supportedBrowserToPlatform = {
|
||||
@@ -52,6 +53,7 @@ class SupportedBrowsers {
|
||||
'edge': 'ie',
|
||||
'firefox': 'firefox',
|
||||
'safari': 'safari',
|
||||
'ios-safari': 'safari',
|
||||
};
|
||||
|
||||
final Map<String, String> browserToConfiguration = {
|
||||
@@ -63,6 +65,8 @@ class SupportedBrowsers {
|
||||
'--configuration=${environment.webUiRootDir.path}/dart_test_firefox.yaml',
|
||||
'safari':
|
||||
'--configuration=${environment.webUiRootDir.path}/dart_test_safari.yaml',
|
||||
'ios-safari':
|
||||
'--configuration=${environment.webUiRootDir.path}/dart_test_safari.yaml',
|
||||
};
|
||||
|
||||
static final SupportedBrowsers _singletonInstance = SupportedBrowsers._();
|
||||
|
||||
@@ -688,9 +688,12 @@ class BrowserManager {
|
||||
|
||||
var completer = Completer<BrowserManager>();
|
||||
|
||||
browser.onExit.then((_) {
|
||||
throw Exception('${runtime.name} exited before connecting.');
|
||||
}).catchError((dynamic error, StackTrace stackTrace) {
|
||||
// For the cases where we use a delegator such as `adb` (for Android) or
|
||||
// `xcrun` (for IOS), these delegator processes can shut down before the
|
||||
// websocket is available. Therefore do not throw an error if proccess
|
||||
// exits with exitCode 0. Note that `browser` will throw and error if the
|
||||
// exit code was not 0, which will be processed by the next callback.
|
||||
browser.onExit.catchError((dynamic error, StackTrace stackTrace) {
|
||||
if (completer.isCompleted) {
|
||||
return;
|
||||
}
|
||||
@@ -710,10 +713,7 @@ class BrowserManager {
|
||||
completer.completeError(error, stackTrace);
|
||||
});
|
||||
|
||||
return completer.future.timeout(Duration(seconds: 30), onTimeout: () {
|
||||
browser.close();
|
||||
throw Exception('Timed out waiting for ${runtime.name} to connect.');
|
||||
});
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
/// Starts the browser identified by [browser] using [settings] and has it load [url].
|
||||
|
||||
Reference in New Issue
Block a user