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.browser_manager; | 5 library test.runner.browser.browser_manager; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 | 9 |
10 import 'package:http_parser/http_parser.dart'; | 10 import 'package:http_parser/http_parser.dart'; |
11 import 'package:pool/pool.dart'; | 11 import 'package:pool/pool.dart'; |
12 | 12 |
13 import '../../backend/metadata.dart'; | 13 import '../../backend/metadata.dart'; |
14 import '../../backend/test_platform.dart'; | 14 import '../../backend/test_platform.dart'; |
15 import '../../util/multi_channel.dart'; | 15 import '../../util/multi_channel.dart'; |
16 import '../../util/remote_exception.dart'; | 16 import '../../util/remote_exception.dart'; |
17 import '../../util/stack_trace_mapper.dart'; | 17 import '../../util/stack_trace_mapper.dart'; |
18 import '../../utils.dart'; | 18 import '../../utils.dart'; |
19 import '../environment.dart'; | |
19 import '../load_exception.dart'; | 20 import '../load_exception.dart'; |
20 import '../runner_suite.dart'; | 21 import '../runner_suite.dart'; |
21 import 'iframe_test.dart'; | 22 import 'iframe_test.dart'; |
22 | 23 |
23 /// A class that manages the connection to a single running browser. | 24 /// A class that manages the connection to a single running browser. |
24 /// | 25 /// |
25 /// This is in charge of telling the browser which test suites to load and | 26 /// This is in charge of telling the browser which test suites to load and |
26 /// converting its responses into [Suite] objects. | 27 /// converting its responses into [Suite] objects. |
27 class BrowserManager { | 28 class BrowserManager { |
28 /// The browser that this is managing. | 29 /// The browser that this is managing. |
(...skipping 15 matching lines...) Expand all Loading... | |
44 | 45 |
45 /// The ID of the next suite to be loaded. | 46 /// The ID of the next suite to be loaded. |
46 /// | 47 /// |
47 /// This is used to ensure that the suites can be referred to consistently | 48 /// This is used to ensure that the suites can be referred to consistently |
48 /// across the client and server. | 49 /// across the client and server. |
49 int _suiteId = 0; | 50 int _suiteId = 0; |
50 | 51 |
51 /// Whether the channel to the browser has closed. | 52 /// Whether the channel to the browser has closed. |
52 bool _closed = false; | 53 bool _closed = false; |
53 | 54 |
55 /// The environment to attach to each suite. | |
56 _BrowserEnvironment _environment; | |
57 | |
54 /// Creates a new BrowserManager that communicates with [browser] over | 58 /// Creates a new BrowserManager that communicates with [browser] over |
55 /// [webSocket]. | 59 /// [webSocket]. |
56 BrowserManager(this.browser, CompatibleWebSocket webSocket) | 60 BrowserManager(this.browser, CompatibleWebSocket webSocket) |
57 : _channel = new MultiChannel( | 61 : _channel = new MultiChannel( |
58 webSocket.map(JSON.decode), | 62 webSocket.map(JSON.decode), |
59 mapSink(webSocket, JSON.encode)) { | 63 mapSink(webSocket, JSON.encode)) { |
64 _environment = new _BrowserEnvironment(this); | |
60 _channel.stream.listen(null, onDone: () => _closed = true); | 65 _channel.stream.listen(null, onDone: () => _closed = true); |
61 } | 66 } |
62 | 67 |
63 /// Tells the browser the load a test suite from the URL [url]. | 68 /// Tells the browser the load a test suite from the URL [url]. |
64 /// | 69 /// |
65 /// [url] should be an HTML page with a reference to the JS-compiled test | 70 /// [url] should be an HTML page with a reference to the JS-compiled test |
66 /// suite. [path] is the path of the original test suite file, which is used | 71 /// suite. [path] is the path of the original test suite file, which is used |
67 /// for reporting. [metadata] is the parsed metadata for the test suite. | 72 /// for reporting. [metadata] is the parsed metadata for the test suite. |
68 /// | 73 /// |
69 /// If [mapper] is passed, it's used to map stack traces for errors coming | 74 /// If [mapper] is passed, it's used to map stack traces for errors coming |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 } | 138 } |
134 | 139 |
135 if (response["type"] == "error") { | 140 if (response["type"] == "error") { |
136 closeIframe(); | 141 closeIframe(); |
137 var asyncError = RemoteException.deserialize(response["error"]); | 142 var asyncError = RemoteException.deserialize(response["error"]); |
138 await new Future.error( | 143 await new Future.error( |
139 new LoadException(path, asyncError.error), | 144 new LoadException(path, asyncError.error), |
140 asyncError.stackTrace); | 145 asyncError.stackTrace); |
141 } | 146 } |
142 | 147 |
143 return new RunnerSuite(response["tests"].map((test) { | 148 return new RunnerSuite(_environment, response["tests"].map((test) { |
144 var testMetadata = new Metadata.deserialize(test['metadata']); | 149 var testMetadata = new Metadata.deserialize(test['metadata']); |
145 var testChannel = suiteChannel.virtualChannel(test['channel']); | 150 var testChannel = suiteChannel.virtualChannel(test['channel']); |
146 return new IframeTest(test['name'], testMetadata, testChannel, | 151 return new IframeTest(test['name'], testMetadata, testChannel, |
147 mapper: mapper); | 152 mapper: mapper); |
148 }), platform: browser, metadata: metadata, path: path, | 153 }), platform: browser, metadata: metadata, path: path, |
149 onClose: () => closeIframe()); | 154 onClose: () => closeIframe()); |
150 } | 155 } |
151 } | 156 } |
157 | |
158 /// An implementation of [Environment] for the browser. | |
159 /// | |
160 /// All methods forward directly to [BrowserManager]. | |
161 class _BrowserEnvironment implements Environment { | |
162 final BrowserManager _manager; | |
kevmoo
2015/07/30 01:37:24
This field ends up being unused.
Uh...
nweiz
2015/07/30 19:41:50
Right, the whole point of this CL is to set the st
| |
163 | |
164 _BrowserEnvironment(this._manager); | |
165 } | |
OLD | NEW |