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

Unified Diff: lib/src/runner/browser/safari.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/phantom_js.dart ('k') | lib/src/util/dart.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/runner/browser/safari.dart
diff --git a/lib/src/runner/browser/safari.dart b/lib/src/runner/browser/safari.dart
index 20f4e39ecd6f880f214d7d17c960191c4297ec92..e600e00e6ea77a3bfcafc3af05e5f4806931d1db 100644
--- a/lib/src/runner/browser/safari.dart
+++ b/lib/src/runner/browser/safari.dart
@@ -9,82 +9,43 @@ 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 Safari.
///
/// Any errors starting or running the process are reported through [onExit].
-class Safari implements Browser {
- /// The underlying process.
- Process _process;
+class Safari extends Browser {
+ final name = "Safari";
- 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();
+ Safari(url, {String executable})
+ : super(() => _startBrowser(url, executable));
/// Starts a new instance of Safari open to the given [url], which may be a
/// [Uri] or a [String].
///
- /// If [executable] is passed, it's used as the Safari executable. Otherwise
- /// the default executable name for the current OS will be used.
- Safari(url, {String executable}) {
+ /// If [executable] is passed, it's used as the content shell executable.
+ /// Otherwise the default executable name for the current OS will be used.
+ static Future<Process> _startBrowser(url, [String executable]) async {
if (executable == null) {
executable = '/Applications/Safari.app/Contents/MacOS/Safari';
}
- // 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 {
- // 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.
- var redirect = p.join(dir, 'redirect.html');
- new File(redirect).writeAsStringSync(
- "<script>location = " + JSON.encode(url.toString()) + "</script>");
-
- var process = await Process.start(executable, [redirect]);
- _process = process;
- _onProcessStartedCompleter.complete();
+ var dir = createTempDir();
- // 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;
- });
+ // 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.
+ var redirect = p.join(dir, 'redirect.html');
+ new File(redirect).writeAsStringSync(
+ "<script>location = " + JSON.encode(url.toString()) + "</script>");
- if (exitCode != 0) {
- var error = await UTF8.decodeStream(_process.stderr);
- throw new ApplicationException(
- "Safari 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 Safari: ${getErrorMessage(error)}."),
- stackTrace);
- }
- });
- }
+ var process = await Process.start(executable, [redirect]);
- Future close() {
- _onProcessStarted.then((_) => _process.kill());
+ process.exitCode
+ .then((_) => new Directory(dir).deleteSync(recursive: true));
- // Swallow exceptions. The user should explicitly use [onExit] for these.
- return onExit.catchError((_) {});
+ return process;
}
}
« no previous file with comments | « lib/src/runner/browser/phantom_js.dart ('k') | lib/src/util/dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698