[web] Fixing launching Safari. This should solve the LUCI issue (flutter/engine#16590)

* Fixing launching Safari. This should solve the LUCI issue

* more comments and linking the issue
This commit is contained in:
Nurhan Turgut
2020-02-14 10:27:20 -08:00
committed by GitHub
parent 72edf47d71
commit fb1b707879
3 changed files with 21 additions and 29 deletions

View File

@@ -50,7 +50,7 @@ abstract class PlatformBinding {
String getChromeExecutablePath(io.Directory versionDir);
String getFirefoxExecutablePath(io.Directory versionDir);
String getFirefoxLatestVersionUrl();
String getSafariSystemExecutablePath();
String getMacApplicationLauncher();
String getCommandToRunEdge();
}
@@ -85,7 +85,7 @@ class _WindowsBinding implements PlatformBinding {
'https://download.mozilla.org/?product=firefox-latest&os=win&lang=en-US';
@override
String getSafariSystemExecutablePath() =>
String getMacApplicationLauncher() =>
throw UnsupportedError('Safari is not supported on Windows');
@override
@@ -120,7 +120,7 @@ class _LinuxBinding implements PlatformBinding {
'https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US';
@override
String getSafariSystemExecutablePath() =>
String getMacApplicationLauncher() =>
throw UnsupportedError('Safari is not supported on Linux');
@override
@@ -161,8 +161,7 @@ class _MacBinding implements PlatformBinding {
'https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US';
@override
String getSafariSystemExecutablePath() =>
'/Applications/Safari.app/Contents/MacOS/Safari';
String getMacApplicationLauncher() => 'open';
@override
String getCommandToRunEdge() =>

View File

@@ -3,16 +3,8 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'environment.dart';
import 'package:path/path.dart' as path;
import 'package:pedantic/pedantic.dart';
import 'package:test_core/src/util/io.dart'; // ignore: implementation_imports
import 'browser.dart';
import 'safari_installation.dart';
import 'common.dart';
@@ -43,21 +35,22 @@ class Safari extends Browser {
infoLog: DevNull(),
);
// Safari will only open files (not general URLs) via the command-line
// API, so we create a dummy file to redirect it to the page we actually
// want it to load.
final Directory redirectDir = Directory(
path.join(environment.webUiDartToolDir.path),
);
final redirect = path.join(redirectDir.path, 'redirect.html');
File(redirect).writeAsStringSync(
'<script>location = ' + jsonEncode(url.toString()) + '</script>');
var process =
await Process.start(installation.executable, [redirect] /* args */);
unawaited(process.exitCode
.then((_) => File(redirect).deleteSync(recursive: true)));
// 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;
});

View File

@@ -70,7 +70,7 @@ Future<BrowserInstallation> getOrInstallSafari(
infoLog.writeln('Using the system version that is already installed.');
return BrowserInstallation(
version: 'system',
executable: PlatformBinding.instance.getSafariSystemExecutablePath(),
executable: PlatformBinding.instance.getMacApplicationLauncher(),
);
} else {
infoLog.writeln('Unsupported version $requestedVersion.');