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'; | |
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; | |
31 var closeCompleter = new Completer(); | |
kevmoo
2015/04/03 00:49:45
This seems to not be used?
nweiz
2015/04/03 20:56:21
Done.
| |
28 controller = new LiveTestController(suite, this, () { | 32 controller = new LiveTestController(suite, this, () { |
29 controller.setState(const State(Status.running, Result.success)); | 33 controller.setState(const State(Status.running, Result.success)); |
30 | 34 |
31 var testChannel = _channel.virtualChannel(); | 35 testChannel = _channel.virtualChannel(); |
32 _channel.sink.add({ | 36 _channel.sink.add({ |
33 'command': 'run', | 37 'command': 'run', |
34 'channel': testChannel.id | 38 'channel': testChannel.id |
35 }); | 39 }); |
36 | 40 |
37 testChannel.stream.listen((message) { | 41 testChannel.stream.listen((message) { |
38 if (message['type'] == 'error') { | 42 if (message['type'] == 'error') { |
39 var asyncError = RemoteException.deserialize(message['error']); | 43 var asyncError = RemoteException.deserialize(message['error']); |
40 controller.addError(asyncError.error, asyncError.stackTrace); | 44 controller.addError(asyncError.error, asyncError.stackTrace); |
41 } else if (message['type'] == 'state-change') { | 45 } else if (message['type'] == 'state-change') { |
42 controller.setState( | 46 controller.setState( |
43 new State( | 47 new State( |
44 new Status.parse(message['status']), | 48 new Status.parse(message['status']), |
45 new Result.parse(message['result']))); | 49 new Result.parse(message['result']))); |
46 } else if (message['type'] == 'print') { | 50 } else if (message['type'] == 'print') { |
47 controller.print(message['line']); | 51 controller.print(message['line']); |
48 } else { | 52 } else { |
49 assert(message['type'] == 'complete'); | 53 assert(message['type'] == 'complete'); |
50 controller.completer.complete(); | 54 controller.completer.complete(); |
51 } | 55 } |
52 }); | 56 }); |
57 }, () { | |
58 // Ignore all future messages from the test and complete it immediately. | |
59 // We don't need to tell it to run its tear-down because there's nothing a | |
60 // browser test needs to clean up on the file system anyway. | |
61 testChannel.sink.close(); | |
62 if (!controller.completer.isCompleted) controller.completer.complete(); | |
53 }); | 63 }); |
54 return controller.liveTest; | 64 return controller.liveTest; |
55 } | 65 } |
56 } | 66 } |
OLD | NEW |