| 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 import 'package:stream_channel/stream_channel.dart'; | 5 import 'package:stream_channel/stream_channel.dart'; |
| 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 '../utils.dart'; |
| 17 import '../../util/remote_exception.dart'; | 17 import '../util/remote_exception.dart'; |
| 18 import '../../util/stack_trace_mapper.dart'; | |
| 19 | 18 |
| 20 /// A test in a running iframe. | 19 /// A test running remotely, controlled by a stream channel. |
| 21 class IframeTest extends Test { | 20 class RunnerTest extends Test { |
| 22 final String name; | 21 final String name; |
| 23 final Metadata metadata; | 22 final Metadata metadata; |
| 24 | 23 |
| 25 /// The mapper used to map stack traces for errors coming from this test, or | |
| 26 /// `null`. | |
| 27 final StackTraceMapper _mapper; | |
| 28 | |
| 29 /// The channel used to communicate with the test's [IframeListener]. | 24 /// The channel used to communicate with the test's [IframeListener]. |
| 30 final MultiChannel _channel; | 25 final MultiChannel _channel; |
| 31 | 26 |
| 32 IframeTest(this.name, this.metadata, this._channel, {StackTraceMapper mapper}) | 27 RunnerTest(this.name, this.metadata, this._channel); |
| 33 : _mapper = mapper; | |
| 34 | 28 |
| 35 LiveTest load(Suite suite, {Iterable<Group> groups}) { | 29 LiveTest load(Suite suite, {Iterable<Group> groups}) { |
| 36 var controller; | 30 var controller; |
| 37 var testChannel; | 31 var testChannel; |
| 38 controller = new LiveTestController(suite, this, () { | 32 controller = new LiveTestController(suite, this, () { |
| 39 controller.setState(const State(Status.running, Result.success)); | 33 controller.setState(const State(Status.running, Result.success)); |
| 40 | 34 |
| 41 testChannel = _channel.virtualChannel(); | 35 testChannel = _channel.virtualChannel(); |
| 42 _channel.sink.add({ | 36 _channel.sink.add({ |
| 43 'command': 'run', | 37 'command': 'run', |
| 44 'channel': testChannel.id | 38 'channel': testChannel.id |
| 45 }); | 39 }); |
| 46 | 40 |
| 47 testChannel.stream.listen((message) { | 41 testChannel.stream.listen((message) { |
| 48 if (message['type'] == 'error') { | 42 if (message['type'] == 'error') { |
| 49 var asyncError = RemoteException.deserialize(message['error']); | 43 var asyncError = RemoteException.deserialize(message['error']); |
| 50 | 44 |
| 51 var stackTrace = asyncError.stackTrace; | 45 var stackTrace = asyncError.stackTrace; |
| 52 if (_mapper != null) stackTrace = _mapper.mapStackTrace(stackTrace); | |
| 53 | |
| 54 controller.addError(asyncError.error, stackTrace); | 46 controller.addError(asyncError.error, stackTrace); |
| 55 } else if (message['type'] == 'state-change') { | 47 } else if (message['type'] == 'state-change') { |
| 56 controller.setState( | 48 controller.setState( |
| 57 new State( | 49 new State( |
| 58 new Status.parse(message['status']), | 50 new Status.parse(message['status']), |
| 59 new Result.parse(message['result']))); | 51 new Result.parse(message['result']))); |
| 60 } else if (message['type'] == 'print') { | 52 } else if (message['type'] == 'print') { |
| 61 controller.print(message['line']); | 53 controller.print(message['line']); |
| 62 } else { | 54 } else { |
| 63 assert(message['type'] == 'complete'); | 55 assert(message['type'] == 'complete'); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 83 testChannel.sink.add({'command': 'close'}); | 75 testChannel.sink.add({'command': 'close'}); |
| 84 await controller.completer.future; | 76 await controller.completer.future; |
| 85 testChannel.sink.close(); | 77 testChannel.sink.close(); |
| 86 }); | 78 }); |
| 87 }, groups: groups); | 79 }, groups: groups); |
| 88 return controller.liveTest; | 80 return controller.liveTest; |
| 89 } | 81 } |
| 90 | 82 |
| 91 Test forPlatform(TestPlatform platform, {OperatingSystem os}) { | 83 Test forPlatform(TestPlatform platform, {OperatingSystem os}) { |
| 92 if (!metadata.testOn.evaluate(platform, os: os)) return null; | 84 if (!metadata.testOn.evaluate(platform, os: os)) return null; |
| 93 return new IframeTest( | 85 return new RunnerTest( |
| 94 name, metadata.forPlatform(platform, os: os), _channel, | 86 name, metadata.forPlatform(platform, os: os), _channel); |
| 95 mapper: _mapper); | |
| 96 } | 87 } |
| 97 } | 88 } |
| OLD | NEW |