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

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

Issue 1175163003: Factor out some common logic from the launchers. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: fix test Created 5 years, 6 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 | « lib/src/runner/browser/content_shell.dart ('k') | lib/src/runner/browser/firefox.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/runner/browser/dartium.dart
diff --git a/lib/src/runner/browser/dartium.dart b/lib/src/runner/browser/dartium.dart
index 3e608a5eb7fc9df8437fef8285d2996202cbfb62..0783f1005e43bebcff04656b0eb3a03752959e6f 100644
--- a/lib/src/runner/browser/dartium.dart
+++ b/lib/src/runner/browser/dartium.dart
@@ -5,15 +5,11 @@
library test.runner.browser.dartium;
import 'dart:async';
-import 'dart:convert';
import 'dart:io';
import 'package:path/path.dart' as p;
-import 'package:stack_trace/stack_trace.dart';
import '../../util/io.dart';
-import '../../utils.dart';
-import '../application_exception.dart';
import 'browser.dart';
/// A class for running an instance of Dartium.
@@ -23,85 +19,47 @@ import 'browser.dart';
/// constructed, and is killed when [close] is called.
///
/// Any errors starting or running the process are reported through [onExit].
-class Dartium implements Browser {
- /// The underlying process.
- Process _process;
+class Dartium extends Browser {
+ final name = "Dartium";
- Future get onExit => _onExitCompleter.future;
- final _onExitCompleter = new Completer();
-
- /// A future that completes when the browser process has started.
- ///
- /// This is used to ensure that [close] works regardless of when it's called.
- Future get _onProcessStarted => _onProcessStartedCompleter.future;
- final _onProcessStartedCompleter = new Completer();
+ Dartium(url, {String executable})
+ : super(() => _startBrowser(url, executable));
/// 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 Dartium executable. Otherwise
/// the default executable name for the current OS will be used.
- Dartium(url, {String executable}) {
+ static Future<Process> _startBrowser(url, [String executable]) async {
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
- // request instead.
- invoke(() async {
- try {
- var exitCode = await withTempDir((dir) async {
- var process = await Process.start(executable, [
- "--user-data-dir=$dir",
- url.toString(),
- "--disable-extensions",
- "--disable-popup-blocking",
- "--bwsi",
- "--no-first-run",
- "--no-default-browser-check",
- "--disable-default-apps",
- "--disable-translate"
- ], environment: {"DART_FLAGS": "--checked"});
-
- _process = process;
- _onProcessStartedCompleter.complete();
-
- // TODO(nweiz): the browser's standard output is almost always useless
- // noise, but we should allow the user to opt in to seeing it.
- return await _process.exitCode;
- });
-
- if (exitCode != 0) {
- var error = await UTF8.decodeStream(_process.stderr);
- throw new ApplicationException(
- "Dartium failed with exit code $exitCode:\n$error");
- }
-
- _onExitCompleter.complete();
- } catch (error, stackTrace) {
- if (stackTrace == null) stackTrace = new Trace.current();
- _onExitCompleter.completeError(
- new ApplicationException(
- "Failed to start Dartium: ${getErrorMessage(error)}."),
- stackTrace);
- }
- });
- }
-
- Future close() {
- _onProcessStarted.then((_) => _process.kill());
-
- // Swallow exceptions. The user should explicitly use [onExit] for these.
- return onExit.catchError((_) {});
+ var dir = createTempDir();
+ var process = await Process.start(executable, [
+ "--user-data-dir=$dir",
+ url.toString(),
+ "--disable-extensions",
+ "--disable-popup-blocking",
+ "--bwsi",
+ "--no-first-run",
+ "--no-default-browser-check",
+ "--disable-default-apps",
+ "--disable-translate"
+ ], environment: {"DART_FLAGS": "--checked"});
+
+ process.exitCode
+ .then((_) => new Directory(dir).deleteSync(recursive: true));
+
+ return process;
}
/// Return the default executable for the current operating system.
- String _defaultExecutable() {
+ static String _defaultExecutable() {
var dartium = _executableInEditor();
if (dartium != null) return dartium;
return Platform.isWindows ? "dartium.exe" : "dartium";
}
- String _executableInEditor() {
+ static String _executableInEditor() {
var dir = p.dirname(sdkDir);
if (Platform.isWindows) {
« no previous file with comments | « lib/src/runner/browser/content_shell.dart ('k') | lib/src/runner/browser/firefox.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698