Index: lib/src/runner/browser/dartium.dart |
diff --git a/lib/src/runner/browser/chrome.dart b/lib/src/runner/browser/dartium.dart |
similarity index 65% |
copy from lib/src/runner/browser/chrome.dart |
copy to lib/src/runner/browser/dartium.dart |
index fc4e232920e60dbc875b5f29550c94aab2d4f0c5..ecb3289c9ae62ac4abd251d8fda367ab654b3381 100644 |
--- a/lib/src/runner/browser/chrome.dart |
+++ b/lib/src/runner/browser/dartium.dart |
@@ -2,7 +2,7 @@ |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
-library test.runner.browser.chrome; |
+library test.runner.browser.dartium; |
import 'dart:async'; |
import 'dart:io'; |
@@ -12,16 +12,14 @@ import 'package:path/path.dart' as p; |
import '../../util/io.dart'; |
import 'browser.dart'; |
-// TODO(nweiz): move this into its own package? |
-// TODO(nweiz): support other browsers. |
-/// A class for running an instance of Chrome. |
+/// A class for running an instance of Dartium. |
/// |
/// 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 Chrome implements Browser { |
+class Dartium implements Browser { |
/// The underlying process. |
Process _process; |
@@ -40,12 +38,12 @@ class Chrome implements Browser { |
Future get _onProcessStarted => _onProcessStartedCompleter.future; |
final _onProcessStartedCompleter = new Completer(); |
- /// Starts a new instance of Chrome open to the given [url], which may be a |
+ /// Starts a new instance of Dartium open to the given [url], which may be a |
/// [Uri] or a [String]. |
/// |
- /// If [executable] is passed, it's used as the Chrome executable. Otherwise |
+ /// If [executable] is passed, it's used as the Dartium executable. Otherwise |
/// the default executable name for the current OS will be used. |
- Chrome(url, {String executable}) { |
+ Dartium(url, {String executable}) { |
if (executable == null) executable = _defaultExecutable(); |
// Don't return a Future here because there's no need for the caller to wait |
@@ -63,7 +61,7 @@ class Chrome implements Browser { |
"--no-default-browser-check", |
"--disable-default-apps", |
"--disable-translate" |
- ]).then((process) { |
+ ], environment: {"DART_FLAGS": "--checked"}).then((process) { |
_process = process; |
_onProcessStartedCompleter.complete(); |
@@ -72,7 +70,7 @@ class Chrome implements Browser { |
return _process.exitCode; |
}); |
}).then((exitCode) { |
- if (exitCode != 0) throw "Chrome failed with exit code $exitCode."; |
+ if (exitCode != 0) throw "Dartium failed with exit code $exitCode."; |
}).then(_onExitCompleter.complete) |
.catchError(_onExitCompleter.completeError); |
} |
@@ -86,29 +84,36 @@ class Chrome implements Browser { |
/// Return the default executable for the current operating system. |
String _defaultExecutable() { |
- if (Platform.isMacOS) { |
- return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'; |
+ var dartium = _executableInEditor(); |
+ if (dartium != null) return dartium; |
+ return Platform.isWindows ? "dartium.exe" : "dartium"; |
+ } |
+ |
+ String _executableInEditor() { |
+ var dir = p.dirname(sdkDir); |
+ |
+ if (Platform.isWindows) { |
+ if (!new File(p.join(dir, "DartEditor.exe")).existsSync()) return null; |
+ |
+ var dartium = p.join(dir, "chromium\\chrome.exe"); |
+ return new File(dartium).existsSync() ? null : dartium; |
} |
- 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; |
+ |
+ if (Platform.isMacOS) { |
+ if (!new File(p.join(dir, "DartEditor.app/Contents/MacOS/DartEditor")) |
+ .existsSync()) { |
+ return null; |
+ } |
+ |
+ var dartium = p.join( |
+ dir, "chromium/Chromium.app/Contents/MacOs/Chromium"); |
+ return new File(dartium).existsSync() ? null : dartium; |
} |
- // 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"; |
+ assert(Platform.isLinux); |
+ if (!new File(p.join(dir, "DartEditor")).existsSync()) return null; |
+ |
+ var dartium = p.join(dir, "chromium", "chrome"); |
+ return new File(dartium).existsSync() ? null : dartium; |
} |
} |