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/group.dart'; | 7 import '../../backend/group.dart'; |
8 import '../../backend/live_test.dart'; | 8 import '../../backend/live_test.dart'; |
9 import '../../backend/live_test_controller.dart'; | 9 import '../../backend/live_test_controller.dart'; |
10 import '../../backend/metadata.dart'; | 10 import '../../backend/metadata.dart'; |
11 import '../../backend/operating_system.dart'; | 11 import '../../backend/operating_system.dart'; |
12 import '../../backend/state.dart'; | 12 import '../../backend/state.dart'; |
13 import '../../backend/suite.dart'; | 13 import '../../backend/suite.dart'; |
14 import '../../backend/test.dart'; | 14 import '../../backend/test.dart'; |
15 import '../../backend/test_platform.dart'; | 15 import '../../backend/test_platform.dart'; |
| 16 import '../../utils.dart'; |
16 import '../../util/multi_channel.dart'; | 17 import '../../util/multi_channel.dart'; |
17 import '../../util/remote_exception.dart'; | 18 import '../../util/remote_exception.dart'; |
18 import '../../util/stack_trace_mapper.dart'; | 19 import '../../util/stack_trace_mapper.dart'; |
19 | 20 |
20 /// A test in a running iframe. | 21 /// A test in a running iframe. |
21 class IframeTest extends Test { | 22 class IframeTest extends Test { |
22 final String name; | 23 final String name; |
23 final Metadata metadata; | 24 final Metadata metadata; |
24 | 25 |
25 /// The mapper used to map stack traces for errors coming from this test, or | 26 /// The mapper used to map stack traces for errors coming from this test, or |
(...skipping 30 matching lines...) Expand all Loading... |
56 controller.setState( | 57 controller.setState( |
57 new State( | 58 new State( |
58 new Status.parse(message['status']), | 59 new Status.parse(message['status']), |
59 new Result.parse(message['result']))); | 60 new Result.parse(message['result']))); |
60 } else if (message['type'] == 'print') { | 61 } else if (message['type'] == 'print') { |
61 controller.print(message['line']); | 62 controller.print(message['line']); |
62 } else { | 63 } else { |
63 assert(message['type'] == 'complete'); | 64 assert(message['type'] == 'complete'); |
64 controller.completer.complete(); | 65 controller.completer.complete(); |
65 } | 66 } |
| 67 }, onDone: () { |
| 68 // When the test channel closes—presumably becuase the browser |
| 69 // closed—mark the test as complete no matter what. |
| 70 if (controller.completer.isCompleted) return; |
| 71 controller.completer.complete(); |
66 }); | 72 }); |
67 }, () { | 73 }, () { |
68 // Ignore all future messages from the test and complete it immediately. | 74 // If the test has finished running, just disconnect the channel. |
69 // We don't need to tell it to run its tear-down because there's nothing a | 75 if (controller.completer.isCompleted) { |
70 // browser test needs to clean up on the file system anyway. | 76 testChannel.sink.close(); |
71 testChannel.sink.close(); | 77 return; |
72 if (!controller.completer.isCompleted) controller.completer.complete(); | 78 } |
| 79 |
| 80 invoke(() async { |
| 81 // If the test is still running, send it a message telling it to shut |
| 82 // down ASAP. This causes the [Invoker] to eagerly throw exceptions |
| 83 // whenever the test touches it. |
| 84 testChannel.sink.add({'command': 'close'}); |
| 85 await controller.completer.future; |
| 86 testChannel.sink.close(); |
| 87 }); |
73 }, groups: groups); | 88 }, groups: groups); |
74 return controller.liveTest; | 89 return controller.liveTest; |
75 } | 90 } |
76 | 91 |
77 Test forPlatform(TestPlatform platform, {OperatingSystem os}) { | 92 Test forPlatform(TestPlatform platform, {OperatingSystem os}) { |
78 if (!metadata.testOn.evaluate(platform, os: os)) return null; | 93 if (!metadata.testOn.evaluate(platform, os: os)) return null; |
79 return new IframeTest( | 94 return new IframeTest( |
80 name, metadata.forPlatform(platform, os: os), _channel, | 95 name, metadata.forPlatform(platform, os: os), _channel, |
81 mapper: _mapper); | 96 mapper: _mapper); |
82 } | 97 } |
83 } | 98 } |
OLD | NEW |