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.iframe_test; | 5 library test.runner.browser.iframe_test; |
6 | 6 |
7 import '../../backend/live_test.dart'; | 7 import '../../backend/live_test.dart'; |
8 import '../../backend/live_test_controller.dart'; | 8 import '../../backend/live_test_controller.dart'; |
9 import '../../backend/metadata.dart'; | 9 import '../../backend/metadata.dart'; |
10 import '../../backend/state.dart'; | 10 import '../../backend/state.dart'; |
11 import '../../backend/suite.dart'; | 11 import '../../backend/suite.dart'; |
12 import '../../backend/test.dart'; | 12 import '../../backend/test.dart'; |
13 import '../../util/multi_channel.dart'; | 13 import '../../util/multi_channel.dart'; |
14 import '../../util/remote_exception.dart'; | 14 import '../../util/remote_exception.dart'; |
15 | 15 |
16 /// A test in a running iframe. | 16 /// A test in a running iframe. |
17 class IframeTest implements Test { | 17 class IframeTest implements Test { |
18 final String name; | 18 final String name; |
19 final Metadata metadata; | 19 final Metadata metadata; |
20 | 20 |
21 /// The channel used to communicate with the test's [IframeListener]. | 21 /// The channel used to communicate with the test's [IframeListener]. |
22 final MultiChannel _channel; | 22 final MultiChannel _channel; |
23 | 23 |
24 IframeTest(this.name, this.metadata, this._channel); | 24 IframeTest(this.name, this.metadata, this._channel); |
25 | 25 |
26 LiveTest load(Suite suite) { | 26 LiveTest load(Suite suite) { |
27 var controller; | 27 var controller; |
| 28 var testChannel; |
28 controller = new LiveTestController(suite, this, () { | 29 controller = new LiveTestController(suite, this, () { |
29 controller.setState(const State(Status.running, Result.success)); | 30 controller.setState(const State(Status.running, Result.success)); |
30 | 31 |
31 var testChannel = _channel.virtualChannel(); | 32 testChannel = _channel.virtualChannel(); |
32 _channel.sink.add({ | 33 _channel.sink.add({ |
33 'command': 'run', | 34 'command': 'run', |
34 'channel': testChannel.id | 35 'channel': testChannel.id |
35 }); | 36 }); |
36 | 37 |
37 testChannel.stream.listen((message) { | 38 testChannel.stream.listen((message) { |
38 if (message['type'] == 'error') { | 39 if (message['type'] == 'error') { |
39 var asyncError = RemoteException.deserialize(message['error']); | 40 var asyncError = RemoteException.deserialize(message['error']); |
40 controller.addError(asyncError.error, asyncError.stackTrace); | 41 controller.addError(asyncError.error, asyncError.stackTrace); |
41 } else if (message['type'] == 'state-change') { | 42 } else if (message['type'] == 'state-change') { |
42 controller.setState( | 43 controller.setState( |
43 new State( | 44 new State( |
44 new Status.parse(message['status']), | 45 new Status.parse(message['status']), |
45 new Result.parse(message['result']))); | 46 new Result.parse(message['result']))); |
46 } else if (message['type'] == 'print') { | 47 } else if (message['type'] == 'print') { |
47 controller.print(message['line']); | 48 controller.print(message['line']); |
48 } else { | 49 } else { |
49 assert(message['type'] == 'complete'); | 50 assert(message['type'] == 'complete'); |
50 controller.completer.complete(); | 51 controller.completer.complete(); |
51 } | 52 } |
52 }); | 53 }); |
| 54 }, () { |
| 55 // Ignore all future messages from the test and complete it immediately. |
| 56 // We don't need to tell it to run its tear-down because there's nothing a |
| 57 // browser test needs to clean up on the file system anyway. |
| 58 testChannel.sink.close(); |
| 59 if (!controller.completer.isCompleted) controller.completer.complete(); |
53 }); | 60 }); |
54 return controller.liveTest; | 61 return controller.liveTest; |
55 } | 62 } |
56 } | 63 } |
OLD | NEW |