From ce8fe9903d1e8b0e9bef9862fb5e126d6d567088 Mon Sep 17 00:00:00 2001 From: nturgut Date: Mon, 1 Jun 2020 16:52:27 -0700 Subject: [PATCH] [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 --- engine/src/flutter/lib/web_ui/dev/safari.dart | 65 ++++++++++++------- .../lib/web_ui/dev/safari_installation.dart | 12 +++- .../lib/web_ui/dev/supported_browsers.dart | 4 ++ .../flutter/lib/web_ui/dev/test_platform.dart | 14 ++-- 4 files changed, 62 insertions(+), 33 deletions(-) diff --git a/engine/src/flutter/lib/web_ui/dev/safari.dart b/engine/src/flutter/lib/web_ui/dev/safari.dart index 0582e157c5..3de4116a38 100644 --- a/engine/src/flutter/lib/web_ui/dev/safari.dart +++ b/engine/src/flutter/lib/web_ui/dev/safari.dart @@ -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; + } }); } diff --git a/engine/src/flutter/lib/web_ui/dev/safari_installation.dart b/engine/src/flutter/lib/web_ui/dev/safari_installation.dart index 95c7dc2332..896535bc42 100644 --- a/engine/src/flutter/lib/web_ui/dev/safari_installation.dart +++ b/engine/src/flutter/lib/web_ui/dev/safari_installation.dart @@ -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 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( diff --git a/engine/src/flutter/lib/web_ui/dev/supported_browsers.dart b/engine/src/flutter/lib/web_ui/dev/supported_browsers.dart index c491baf4d8..5c475d5c5c 100644 --- a/engine/src/flutter/lib/web_ui/dev/supported_browsers.dart +++ b/engine/src/flutter/lib/web_ui/dev/supported_browsers.dart @@ -45,6 +45,7 @@ class SupportedBrowsers { 'edge': Runtime.internetExplorer, 'firefox': Runtime.firefox, 'safari': Runtime.safari, + 'ios-safari': Runtime.safari, }; final Map supportedBrowserToPlatform = { @@ -52,6 +53,7 @@ class SupportedBrowsers { 'edge': 'ie', 'firefox': 'firefox', 'safari': 'safari', + 'ios-safari': 'safari', }; final Map 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._(); 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 0d76ed97de..20e16be900 100644 --- a/engine/src/flutter/lib/web_ui/dev/test_platform.dart +++ b/engine/src/flutter/lib/web_ui/dev/test_platform.dart @@ -688,9 +688,12 @@ class BrowserManager { var completer = Completer(); - 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].