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