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 ([^ ]+)"); | 14 final _observatoryRegExp = new RegExp(r"^Observatory listening on ([^ ]+)"); |
15 | 15 |
16 /// A class for running an instance of the Dartium content shell. | 16 /// A class for running an instance of the Dartium content shell. |
17 /// | 17 /// |
18 /// 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, |
19 /// 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 |
20 /// constructed, and is killed when [close] is called. | 20 /// constructed, and is killed when [close] is called. |
21 /// | 21 /// |
22 /// Any errors starting or running the process are reported through [onExit]. | 22 /// Any errors starting or running the process are reported through [onExit]. |
23 class ContentShell extends Browser { | 23 class ContentShell extends Browser { |
24 final name = "Content Shell"; | 24 final name = "Content Shell"; |
25 | 25 |
26 final Future<Uri> observatoryUrl; | 26 final Future<Uri> observatoryUrl; |
27 | 27 |
28 factory ContentShell(url, {String executable}) { | 28 factory ContentShell(url, {String executable, bool debug: false}) { |
29 var completer = new Completer.sync(); | 29 var completer = new Completer.sync(); |
30 return new ContentShell._(() async { | 30 return new ContentShell._(() async { |
31 if (executable == null) executable = _defaultExecutable(); | 31 if (executable == null) executable = _defaultExecutable(); |
32 | 32 |
33 var process = await Process.start( | 33 var process = await Process.start( |
34 executable, ["--dump-render-tree", url.toString()], | 34 executable, ["--dump-render-tree", url.toString()], |
35 environment: {"DART_FLAGS": "--checked"}); | 35 environment: {"DART_FLAGS": "--checked"}); |
36 | 36 |
37 // The first observatory URL emitted is for the empty start page; the | 37 if (debug) { |
38 // second is actually for the host page. | 38 completer.complete(lineSplitter.bind(process.stdout).map((line) { |
39 completer.complete(lineSplitter.bind(process.stdout).map((line) { | 39 var match = _observatoryRegExp.firstMatch(line); |
40 var match = _observatoryRegExp.firstMatch(line); | 40 if (match == null) return null; |
41 if (match == null) return null; | 41 return Uri.parse(match[1]); |
42 return Uri.parse(match[1]); | 42 }).where((uri) => uri != null).first); |
43 }).where((uri) => uri != null).first); | 43 } else { |
| 44 completer.complete(null); |
| 45 } |
44 | 46 |
45 lineSplitter.bind(process.stderr).listen((line) { | 47 lineSplitter.bind(process.stderr).listen((line) { |
46 if (line != "[dartToStderr]: Dartium build has expired") return; | 48 if (line != "[dartToStderr]: Dartium build has expired") return; |
47 | 49 |
48 // TODO(nweiz): link to dartlang.org once it has download links for | 50 // TODO(nweiz): link to dartlang.org once it has download links for |
49 // content shell | 51 // content shell |
50 // (https://github.com/dart-lang/www.dartlang.org/issues/1164). | 52 // (https://github.com/dart-lang/www.dartlang.org/issues/1164). |
51 throw new ApplicationException( | 53 throw new ApplicationException( |
52 "You're using an expired content_shell. Upgrade to the latest " | 54 "You're using an expired content_shell. Upgrade to the latest " |
53 "version:\n" | 55 "version:\n" |
54 "http://gsdview.appspot.com/dart-archive/channels/stable/release/" | 56 "http://gsdview.appspot.com/dart-archive/channels/stable/release/" |
55 "latest/dartium/"); | 57 "latest/dartium/"); |
56 }); | 58 }); |
57 | 59 |
58 return process; | 60 return process; |
59 }, completer.future); | 61 }, completer.future); |
60 } | 62 } |
61 | 63 |
62 ContentShell._(Future<Process> startBrowser(), this.observatoryUrl) | 64 ContentShell._(Future<Process> startBrowser(), this.observatoryUrl) |
63 : super(startBrowser); | 65 : super(startBrowser); |
64 | 66 |
65 /// Return the default executable for the current operating system. | 67 /// Return the default executable for the current operating system. |
66 static String _defaultExecutable() => | 68 static String _defaultExecutable() => |
67 Platform.isWindows ? "content_shell.exe" : "content_shell"; | 69 Platform.isWindows ? "content_shell.exe" : "content_shell"; |
68 } | 70 } |
OLD | NEW |