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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:convert'; | 6 import 'dart:convert'; |
7 | 7 |
8 import 'package:async/async.dart'; | 8 import 'package:async/async.dart'; |
9 import 'package:http_parser/http_parser.dart'; | 9 import 'package:http_parser/http_parser.dart'; |
10 import 'package:pool/pool.dart'; | 10 import 'package:pool/pool.dart'; |
| 11 import 'package:stream_channel/stream_channel.dart'; |
11 | 12 |
12 import '../../backend/metadata.dart'; | 13 import '../../backend/metadata.dart'; |
13 import '../../backend/test_platform.dart'; | 14 import '../../backend/test_platform.dart'; |
14 import '../../util/multi_channel.dart'; | |
15 import '../../util/stack_trace_mapper.dart'; | 15 import '../../util/stack_trace_mapper.dart'; |
16 import '../../utils.dart'; | |
17 import '../application_exception.dart'; | 16 import '../application_exception.dart'; |
18 import '../environment.dart'; | 17 import '../environment.dart'; |
19 import '../runner_suite.dart'; | 18 import '../runner_suite.dart'; |
20 import 'browser.dart'; | 19 import 'browser.dart'; |
21 import 'chrome.dart'; | 20 import 'chrome.dart'; |
22 import 'content_shell.dart'; | 21 import 'content_shell.dart'; |
23 import 'dartium.dart'; | 22 import 'dartium.dart'; |
24 import 'firefox.dart'; | 23 import 'firefox.dart'; |
25 import 'internet_explorer.dart'; | 24 import 'internet_explorer.dart'; |
26 import 'phantom_js.dart'; | 25 import 'phantom_js.dart'; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 /// Starts the browser identified by [platform] and has it connect to [url]. | 74 /// Starts the browser identified by [platform] and has it connect to [url]. |
76 /// | 75 /// |
77 /// [url] should serve a page that establishes a WebSocket connection with | 76 /// [url] should serve a page that establishes a WebSocket connection with |
78 /// this process. That connection, once established, should be emitted via | 77 /// this process. That connection, once established, should be emitted via |
79 /// [future]. If [debug] is true, starts the browser in debug mode, with its | 78 /// [future]. If [debug] is true, starts the browser in debug mode, with its |
80 /// debugger interfaces on and detected. | 79 /// debugger interfaces on and detected. |
81 /// | 80 /// |
82 /// Returns the browser manager, or throws an [ApplicationException] if a | 81 /// Returns the browser manager, or throws an [ApplicationException] if a |
83 /// connection fails to be established. | 82 /// connection fails to be established. |
84 static Future<BrowserManager> start(TestPlatform platform, Uri url, | 83 static Future<BrowserManager> start(TestPlatform platform, Uri url, |
85 Future<CompatibleWebSocket> future, {bool debug: false}) { | 84 Future<WebSocketChannel> future, {bool debug: false}) { |
86 var browser = _newBrowser(url, platform, debug: debug); | 85 var browser = _newBrowser(url, platform, debug: debug); |
87 | 86 |
88 var completer = new Completer(); | 87 var completer = new Completer(); |
89 | 88 |
90 // TODO(nweiz): Gracefully handle the browser being killed before the | 89 // TODO(nweiz): Gracefully handle the browser being killed before the |
91 // tests complete. | 90 // tests complete. |
92 browser.onExit.then((_) { | 91 browser.onExit.then((_) { |
93 throw new ApplicationException( | 92 throw new ApplicationException( |
94 "${platform.name} exited before connecting."); | 93 "${platform.name} exited before connecting."); |
95 }).catchError((error, stackTrace) { | 94 }).catchError((error, stackTrace) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 case TestPlatform.firefox: return new Firefox(url); | 126 case TestPlatform.firefox: return new Firefox(url); |
128 case TestPlatform.safari: return new Safari(url); | 127 case TestPlatform.safari: return new Safari(url); |
129 case TestPlatform.internetExplorer: return new InternetExplorer(url); | 128 case TestPlatform.internetExplorer: return new InternetExplorer(url); |
130 default: | 129 default: |
131 throw new ArgumentError("$browser is not a browser."); | 130 throw new ArgumentError("$browser is not a browser."); |
132 } | 131 } |
133 } | 132 } |
134 | 133 |
135 /// Creates a new BrowserManager that communicates with [browser] over | 134 /// Creates a new BrowserManager that communicates with [browser] over |
136 /// [webSocket]. | 135 /// [webSocket]. |
137 BrowserManager._(this._browser, this._platform, CompatibleWebSocket webSocket) | 136 BrowserManager._(this._browser, this._platform, WebSocketChannel webSocket) |
138 : _channel = new MultiChannel( | 137 : _channel = new MultiChannel(webSocket.transform(jsonDocument)) { |
139 webSocket.map(JSON.decode), | |
140 mapSink(webSocket, JSON.encode)) { | |
141 _environment = _loadBrowserEnvironment(); | 138 _environment = _loadBrowserEnvironment(); |
142 _channel.stream.listen(_onMessage, onDone: close); | 139 _channel.stream.listen(_onMessage, onDone: close); |
143 } | 140 } |
144 | 141 |
145 /// Loads [_BrowserEnvironment]. | 142 /// Loads [_BrowserEnvironment]. |
146 Future<_BrowserEnvironment> _loadBrowserEnvironment() async { | 143 Future<_BrowserEnvironment> _loadBrowserEnvironment() async { |
147 var observatoryUrl; | 144 var observatoryUrl; |
148 if (_platform.isDartVM) observatoryUrl = await _browser.observatoryUrl; | 145 if (_platform.isDartVM) observatoryUrl = await _browser.observatoryUrl; |
149 | 146 |
150 var remoteDebuggerUrl; | 147 var remoteDebuggerUrl; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 243 |
247 final Uri observatoryUrl; | 244 final Uri observatoryUrl; |
248 | 245 |
249 final Uri remoteDebuggerUrl; | 246 final Uri remoteDebuggerUrl; |
250 | 247 |
251 _BrowserEnvironment(this._manager, this.observatoryUrl, | 248 _BrowserEnvironment(this._manager, this.observatoryUrl, |
252 this.remoteDebuggerUrl); | 249 this.remoteDebuggerUrl); |
253 | 250 |
254 CancelableOperation displayPause() => _manager._displayPause(); | 251 CancelableOperation displayPause() => _manager._displayPause(); |
255 } | 252 } |
OLD | NEW |