Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: lib/src/runner/browser/chrome.dart

Issue 978093003: Better configure the Chrome launcher. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Code review changes Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/runner/browser/chrome.dart
diff --git a/lib/src/runner/browser/chrome.dart b/lib/src/runner/browser/chrome.dart
index 2a198a15fc669925a1603f4478b86ff1f4aa4c7c..8b155c11a24dd1f9f719126444f51ec25b7487b9 100644
--- a/lib/src/runner/browser/chrome.dart
+++ b/lib/src/runner/browser/chrome.dart
@@ -7,6 +7,8 @@ library unittest.runner.browser.chrome;
import 'dart:async';
import 'dart:io';
+import 'package:path/path.dart' as p;
+
import '../../util/io.dart';
// TODO(nweiz): move this into its own package?
@@ -45,9 +47,9 @@ class Chrome {
/// [Uri] or a [String].
///
/// If [executable] is passed, it's used as the Chrome executable. Otherwise
- /// `"google-chrome"` will be looked up on the system PATH.
+ /// the default executable name for the current OS will be used.
Chrome(url, {String executable}) {
- if (executable == null) executable = "google-chrome";
+ if (executable == null) executable = _defaultExecutable();
// Don't return a Future here because there's no need for the caller to wait
// for the process to actually start. They should just wait for the HTTP
@@ -60,7 +62,10 @@ class Chrome {
"--disable-extensions",
"--disable-popup-blocking",
"--bwsi",
- "--no-first-run"
+ "--no-first-run",
+ "--no-default-browser-check",
+ "--disable-default-apps",
+ "--disable-translate"
]).then((process) {
_process = process;
_onProcessStartedCompleter.complete();
@@ -85,4 +90,32 @@ class Chrome {
// Swallow exceptions. The user should explicitly use [onExit] for these.
return onExit.catchError((_) {});
}
+
+ /// Return the default executable for the current operating system.
+ String _defaultExecutable() {
+ if (Platform.isMacOS) {
+ return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
+ }
+ if (!Platform.isWindows) return 'google-chrome';
+
+ // Chrome could be installed in several places on Windows. The only way to
+ // find it is to check.
+ var prefixes = [
+ Platform.environment['LOCALAPPDATA'],
+ Platform.environment['PROGRAMFILES'],
+ Platform.environment['PROGRAMFILES(X86)']
+ ];
+ var suffix = r'Google\Chrome\Application\chrome.exe';
+
+ for (var prefix in prefixes) {
+ if (prefix == null) continue;
+
+ var path = p.join(prefix, suffix);
+ if (new File(p.join(prefix, suffix)).existsSync()) return path;
+ }
+
+ // Fall back on looking it up on the path. This probably won't work, but at
+ // least it will fail with a useful error message.
+ return "chrome.exe";
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698