Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(651)

Side by Side Diff: lib/src/runner/browser/iframe_test.dart

Issue 1704773002: Load web tests using the plugin infrastructure. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'package:stream_channel/stream_channel.dart';
6
7 import '../../backend/group.dart';
8 import '../../backend/live_test.dart';
9 import '../../backend/live_test_controller.dart';
10 import '../../backend/metadata.dart';
11 import '../../backend/operating_system.dart';
12 import '../../backend/state.dart';
13 import '../../backend/suite.dart';
14 import '../../backend/test.dart';
15 import '../../backend/test_platform.dart';
16 import '../../utils.dart';
17 import '../../util/remote_exception.dart';
18 import '../../util/stack_trace_mapper.dart';
19
20 /// A test in a running iframe.
21 class IframeTest extends Test {
22 final String name;
23 final Metadata metadata;
24
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].
30 final MultiChannel _channel;
31
32 IframeTest(this.name, this.metadata, this._channel, {StackTraceMapper mapper})
33 : _mapper = mapper;
34
35 LiveTest load(Suite suite, {Iterable<Group> groups}) {
36 var controller;
37 var testChannel;
38 controller = new LiveTestController(suite, this, () {
39 controller.setState(const State(Status.running, Result.success));
40
41 testChannel = _channel.virtualChannel();
42 _channel.sink.add({
43 'command': 'run',
44 'channel': testChannel.id
45 });
46
47 testChannel.stream.listen((message) {
48 if (message['type'] == 'error') {
49 var asyncError = RemoteException.deserialize(message['error']);
50
51 var stackTrace = asyncError.stackTrace;
52 if (_mapper != null) stackTrace = _mapper.mapStackTrace(stackTrace);
53
54 controller.addError(asyncError.error, stackTrace);
55 } else if (message['type'] == 'state-change') {
56 controller.setState(
57 new State(
58 new Status.parse(message['status']),
59 new Result.parse(message['result'])));
60 } else if (message['type'] == 'print') {
61 controller.print(message['line']);
62 } else {
63 assert(message['type'] == 'complete');
64 controller.completer.complete();
65 }
66 }, onDone: () {
67 // When the test channel closes—presumably becuase the browser
68 // closed—mark the test as complete no matter what.
69 if (controller.completer.isCompleted) return;
70 controller.completer.complete();
71 });
72 }, () {
73 // If the test has finished running, just disconnect the channel.
74 if (controller.completer.isCompleted) {
75 testChannel.sink.close();
76 return;
77 }
78
79 invoke(() async {
80 // If the test is still running, send it a message telling it to shut
81 // down ASAP. This causes the [Invoker] to eagerly throw exceptions
82 // whenever the test touches it.
83 testChannel.sink.add({'command': 'close'});
84 await controller.completer.future;
85 testChannel.sink.close();
86 });
87 }, groups: groups);
88 return controller.liveTest;
89 }
90
91 Test forPlatform(TestPlatform platform, {OperatingSystem os}) {
92 if (!metadata.testOn.evaluate(platform, os: os)) return null;
93 return new IframeTest(
94 name, metadata.forPlatform(platform, os: os), _channel,
95 mapper: _mapper);
96 }
97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698