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 unittest.runner.isolate_test; | 5 library unittest.runner.browser.iframe_test; |
6 | 6 |
7 import 'dart:isolate'; | 7 import '../../backend/live_test.dart'; |
| 8 import '../../backend/live_test_controller.dart'; |
| 9 import '../../backend/state.dart'; |
| 10 import '../../backend/suite.dart'; |
| 11 import '../../backend/test.dart'; |
| 12 import '../../util/multi_channel.dart'; |
| 13 import '../../util/remote_exception.dart'; |
8 | 14 |
9 import '../backend/live_test.dart'; | 15 /// A test in a running iframe. |
10 import '../backend/live_test_controller.dart'; | 16 class IframeTest implements Test { |
11 import '../backend/state.dart'; | |
12 import '../backend/suite.dart'; | |
13 import '../backend/test.dart'; | |
14 import '../util/remote_exception.dart'; | |
15 | |
16 /// A test in another isolate. | |
17 class IsolateTest implements Test { | |
18 final String name; | 17 final String name; |
19 | 18 |
20 /// The port on which to communicate with the remote test. | 19 /// The channel used to communicate with the test's [IframeListener]. |
21 final SendPort _sendPort; | 20 final MultiChannel _channel; |
22 | 21 |
23 IsolateTest(this.name, this._sendPort); | 22 IframeTest(this.name, this._channel); |
24 | 23 |
25 /// Loads a single runnable instance of this test. | |
26 LiveTest load(Suite suite) { | 24 LiveTest load(Suite suite) { |
27 var receivePort; | |
28 var controller; | 25 var controller; |
29 controller = new LiveTestController(suite, this, () { | 26 controller = new LiveTestController(suite, this, () { |
30 controller.setState(const State(Status.running, Result.success)); | 27 controller.setState(const State(Status.running, Result.success)); |
31 | 28 |
32 receivePort = new ReceivePort(); | 29 var testChannel = _channel.virtualChannel(); |
33 _sendPort.send({ | 30 _channel.sink.add({ |
34 'command': 'run', | 31 'command': 'run', |
35 'reply': receivePort.sendPort | 32 'channel': testChannel.id |
36 }); | 33 }); |
37 | 34 |
38 receivePort.listen((message) { | 35 testChannel.stream.listen((message) { |
39 if (message['type'] == 'error') { | 36 if (message['type'] == 'error') { |
40 var asyncError = RemoteException.deserialize(message['error']); | 37 var asyncError = RemoteException.deserialize(message['error']); |
41 controller.addError(asyncError.error, asyncError.stackTrace); | 38 controller.addError(asyncError.error, asyncError.stackTrace); |
42 } else if (message['type'] == 'state-change') { | 39 } else if (message['type'] == 'state-change') { |
43 controller.setState( | 40 controller.setState( |
44 new State( | 41 new State( |
45 new Status.parse(message['status']), | 42 new Status.parse(message['status']), |
46 new Result.parse(message['result']))); | 43 new Result.parse(message['result']))); |
47 } else { | 44 } else { |
48 assert(message['type'] == 'complete'); | 45 assert(message['type'] == 'complete'); |
49 controller.completer.complete(); | 46 controller.completer.complete(); |
50 } | 47 } |
51 }); | 48 }); |
52 }, onClose: () { | |
53 if (receivePort != null) receivePort.close(); | |
54 }); | 49 }); |
55 return controller.liveTest; | 50 return controller.liveTest; |
56 } | 51 } |
57 } | 52 } |
OLD | NEW |