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

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

Issue 971103002: Add BrowserManager and IframeTest for communicating with browser tests. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Fix errors Created 5 years, 9 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
« no previous file with comments | « no previous file | lib/src/runner/browser/iframe_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 library unittest.runner.browser.browser_manager;
6
7 import 'dart:async';
8 import 'dart:convert';
9
10 import 'package:http_parser/http_parser.dart';
11
12 import '../../backend/suite.dart';
13 import '../../util/multi_channel.dart';
14 import '../../util/remote_exception.dart';
15 import '../../utils.dart';
16 import '../load_exception.dart';
17 import 'iframe_test.dart';
18
19 /// A class that manages the connection to a single running browser.
20 ///
21 /// This is in charge of telling the browser which test suites to load and
22 /// converting its responses into [Suite] objects.
23 class BrowserManager {
24 /// The channel used to communicate with the browser.
25 ///
26 /// This is connected to a page running `static/host.dart`.
27 final MultiChannel _channel;
28
29 /// Creates a new BrowserManager that communicates with a browser over
30 /// [webSocket].
31 BrowserManager(CompatibleWebSocket webSocket)
32 : _channel = new MultiChannel(
33 webSocket.map(JSON.decode),
34 mapSink(webSocket, JSON.encode));
35
36 /// Tells the browser the load a test suite from the URL [url].
37 ///
38 /// [url] should be an HTML page with a reference to the JS-compiled test
39 /// suite. [path] is the path of the original test suite file, which is used
40 /// for reporting.
41 Future<Suite> loadSuite(String path, Uri url) {
42 var suiteChannel = _channel.virtualChannel();
43 _channel.sink.add({
44 "command": "loadSuite",
45 "url": url.toString(),
46 "channel": suiteChannel.id
47 });
48
49 // Create a nested MultiChannel because the iframe will be using a channel
50 // wrapped within the host's channel.
51 suiteChannel = new MultiChannel(suiteChannel.stream, suiteChannel.sink);
52 return suiteChannel.stream.first.then((response) {
53 if (response["type"] == "loadException") {
54 return new Future.error(new LoadException(path, response["message"]));
55 } else if (response["type"] == "error") {
56 var asyncError = RemoteException.deserialize(response["error"]);
57 return new Future.error(
58 new LoadException(path, asyncError.error),
59 asyncError.stackTrace);
60 }
61
62 return new Suite(path, response["tests"].map((test) {
63 var testChannel = suiteChannel.virtualChannel(test['channel']);
64 return new IframeTest(test['name'], testChannel);
65 }));
66 });
67 }
68 }
OLDNEW
« no previous file with comments | « no previous file | lib/src/runner/browser/iframe_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698