| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.runner.browser.content_shell; | 5 library test.runner.browser.content_shell; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import '../../utils.dart'; | 10 import '../../utils.dart'; |
| 11 import '../application_exception.dart'; | 11 import '../application_exception.dart'; |
| 12 import 'browser.dart'; | 12 import 'browser.dart'; |
| 13 | 13 |
| 14 final _observatoryRegExp = new RegExp(r"^Observatory listening on ([^ ]+)"); |
| 15 |
| 14 /// A class for running an instance of the Dartium content shell. | 16 /// A class for running an instance of the Dartium content shell. |
| 15 /// | 17 /// |
| 16 /// Most of the communication with the browser is expected to happen via HTTP, | 18 /// Most of the communication with the browser is expected to happen via HTTP, |
| 17 /// so this exposes a bare-bones API. The browser starts as soon as the class is | 19 /// so this exposes a bare-bones API. The browser starts as soon as the class is |
| 18 /// constructed, and is killed when [close] is called. | 20 /// constructed, and is killed when [close] is called. |
| 19 /// | 21 /// |
| 20 /// Any errors starting or running the process are reported through [onExit]. | 22 /// Any errors starting or running the process are reported through [onExit]. |
| 21 class ContentShell extends Browser { | 23 class ContentShell extends Browser { |
| 22 final name = "Content Shell"; | 24 final name = "Content Shell"; |
| 23 | 25 |
| 24 ContentShell(url, {String executable}) | 26 final Future<Uri> observatoryUrl; |
| 25 : super(() => _startBrowser(url, executable)); | |
| 26 | 27 |
| 27 /// Starts a new instance of content shell open to the given [url], which may | 28 factory ContentShell(url, {String executable}) { |
| 28 /// be a [Uri] or a [String]. | 29 var completer = new Completer.sync(); |
| 29 /// | 30 return new ContentShell._(() async { |
| 30 /// If [executable] is passed, it's used as the content shell executable. | 31 if (executable == null) executable = _defaultExecutable(); |
| 31 /// Otherwise the default executable name for the current OS will be used. | |
| 32 static Future<Process> _startBrowser(url, [String executable]) async { | |
| 33 if (executable == null) executable = _defaultExecutable(); | |
| 34 | 32 |
| 35 var process = await Process.start( | 33 var process = await Process.start( |
| 36 executable, ["--dump-render-tree", url.toString()], | 34 executable, ["--dump-render-tree", url.toString()], |
| 37 environment: {"DART_FLAGS": "--checked"}); | 35 environment: {"DART_FLAGS": "--checked"}); |
| 38 | 36 |
| 39 lineSplitter.bind(process.stderr).listen((line) { | 37 // The first observatory URL emitted is for the empty start page; the |
| 40 if (line != "[dartToStderr]: Dartium build has expired") return; | 38 // second is actually for the host page. |
| 39 completer.complete(lineSplitter.bind(process.stdout).map((line) { |
| 40 var match = _observatoryRegExp.firstMatch(line); |
| 41 if (match == null) return null; |
| 42 return Uri.parse(match[1]); |
| 43 }).where((uri) => uri != null).first); |
| 41 | 44 |
| 42 // TODO(nweiz): link to dartlang.org once it has download links for | 45 lineSplitter.bind(process.stderr).listen((line) { |
| 43 // content shell | 46 if (line != "[dartToStderr]: Dartium build has expired") return; |
| 44 // (https://github.com/dart-lang/www.dartlang.org/issues/1164). | |
| 45 throw new ApplicationException( | |
| 46 "You're using an expired content_shell. Upgrade to the latest " | |
| 47 "version:\n" | |
| 48 "http://gsdview.appspot.com/dart-archive/channels/stable/release/" | |
| 49 "latest/dartium/"); | |
| 50 }); | |
| 51 | 47 |
| 52 return process; | 48 // TODO(nweiz): link to dartlang.org once it has download links for |
| 49 // content shell |
| 50 // (https://github.com/dart-lang/www.dartlang.org/issues/1164). |
| 51 throw new ApplicationException( |
| 52 "You're using an expired content_shell. Upgrade to the latest " |
| 53 "version:\n" |
| 54 "http://gsdview.appspot.com/dart-archive/channels/stable/release/" |
| 55 "latest/dartium/"); |
| 56 }); |
| 57 |
| 58 return process; |
| 59 }, completer.future); |
| 53 } | 60 } |
| 54 | 61 |
| 62 ContentShell._(Future<Process> startBrowser(), this.observatoryUrl) |
| 63 : super(startBrowser); |
| 64 |
| 55 /// Return the default executable for the current operating system. | 65 /// Return the default executable for the current operating system. |
| 56 static String _defaultExecutable() => | 66 static String _defaultExecutable() => |
| 57 Platform.isWindows ? "content_shell.exe" : "content_shell"; | 67 Platform.isWindows ? "content_shell.exe" : "content_shell"; |
| 58 } | 68 } |
| OLD | NEW |