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

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

Issue 1097183003: Add an "onPlatform" parameter to test() and group(). (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 8 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 | « lib/src/backend/test.dart ('k') | lib/src/runner/browser/iframe_listener.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.browser_manager; 5 library test.runner.browser.browser_manager;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:http_parser/http_parser.dart'; 10 import 'package:http_parser/http_parser.dart';
11 11
12 import '../../backend/metadata.dart'; 12 import '../../backend/metadata.dart';
13 import '../../backend/suite.dart'; 13 import '../../backend/suite.dart';
14 import '../../backend/test_platform.dart';
14 import '../../util/multi_channel.dart'; 15 import '../../util/multi_channel.dart';
15 import '../../util/remote_exception.dart'; 16 import '../../util/remote_exception.dart';
16 import '../../utils.dart'; 17 import '../../utils.dart';
17 import '../load_exception.dart'; 18 import '../load_exception.dart';
18 import 'iframe_test.dart'; 19 import 'iframe_test.dart';
19 20
20 /// A class that manages the connection to a single running browser. 21 /// A class that manages the connection to a single running browser.
21 /// 22 ///
22 /// This is in charge of telling the browser which test suites to load and 23 /// This is in charge of telling the browser which test suites to load and
23 /// converting its responses into [Suite] objects. 24 /// converting its responses into [Suite] objects.
24 class BrowserManager { 25 class BrowserManager {
26 /// The browser that this is managing.
27 final TestPlatform browser;
28
25 /// The channel used to communicate with the browser. 29 /// The channel used to communicate with the browser.
26 /// 30 ///
27 /// This is connected to a page running `static/host.dart`. 31 /// This is connected to a page running `static/host.dart`.
28 final MultiChannel _channel; 32 final MultiChannel _channel;
29 33
30 /// Creates a new BrowserManager that communicates with a browser over 34 /// Creates a new BrowserManager that communicates with [browser] over
31 /// [webSocket]. 35 /// [webSocket].
32 BrowserManager(CompatibleWebSocket webSocket) 36 BrowserManager(this.browser, CompatibleWebSocket webSocket)
33 : _channel = new MultiChannel( 37 : _channel = new MultiChannel(
34 webSocket.map(JSON.decode), 38 webSocket.map(JSON.decode),
35 mapSink(webSocket, JSON.encode)); 39 mapSink(webSocket, JSON.encode));
36 40
37 /// Tells the browser the load a test suite from the URL [url]. 41 /// Tells the browser the load a test suite from the URL [url].
38 /// 42 ///
39 /// [url] should be an HTML page with a reference to the JS-compiled test 43 /// [url] should be an HTML page with a reference to the JS-compiled test
40 /// suite. [path] is the path of the original test suite file, which is used 44 /// suite. [path] is the path of the original test suite file, which is used
41 /// for reporting. [metadata] is the parsed metadata for the test suite. 45 /// for reporting. [metadata] is the parsed metadata for the test suite.
42 Future<Suite> loadSuite(String path, Uri url, Metadata metadata) { 46 Future<Suite> loadSuite(String path, Uri url, Metadata metadata) {
43 url = url.replace( 47 url = url.replace(fragment: Uri.encodeFull(JSON.encode({
44 fragment: Uri.encodeFull(JSON.encode(metadata.serialize()))); 48 "metadata": metadata.serialize(),
49 "browser": browser.identifier
50 })));
45 51
46 var suiteChannel = _channel.virtualChannel(); 52 var suiteChannel = _channel.virtualChannel();
47 _channel.sink.add({ 53 _channel.sink.add({
48 "command": "loadSuite", 54 "command": "loadSuite",
49 "url": url.toString(), 55 "url": url.toString(),
50 "channel": suiteChannel.id 56 "channel": suiteChannel.id
51 }); 57 });
52 58
53 // Create a nested MultiChannel because the iframe will be using a channel 59 // Create a nested MultiChannel because the iframe will be using a channel
54 // wrapped within the host's channel. 60 // wrapped within the host's channel.
55 suiteChannel = new MultiChannel(suiteChannel.stream, suiteChannel.sink); 61 suiteChannel = new MultiChannel(suiteChannel.stream, suiteChannel.sink);
56 62
57 // The stream may close before emitting a value if the browser is killed 63 // The stream may close before emitting a value if the browser is killed
58 // prematurely (e.g. via Control-C). 64 // prematurely (e.g. via Control-C).
59 return maybeFirst(suiteChannel.stream) 65 return maybeFirst(suiteChannel.stream)
60 .timeout(new Duration(seconds: 7), onTimeout: () { 66 .timeout(new Duration(seconds: 7), onTimeout: () {
61 throw new LoadException( 67 throw new LoadException(
62 path, "Timed out waiting for the test suite to connect."); 68 path,
69 "Timed out waiting for the test suite to connect on "
70 "${browser.name}.");
63 }).then((response) { 71 }).then((response) {
64 if (response == null) return null; 72 if (response == null) return null;
65 73
66 if (response["type"] == "loadException") { 74 if (response["type"] == "loadException") {
67 return new Future.error(new LoadException(path, response["message"])); 75 return new Future.error(new LoadException(path, response["message"]));
68 } else if (response["type"] == "error") { 76 } else if (response["type"] == "error") {
69 var asyncError = RemoteException.deserialize(response["error"]); 77 var asyncError = RemoteException.deserialize(response["error"]);
70 return new Future.error( 78 return new Future.error(
71 new LoadException(path, asyncError.error), 79 new LoadException(path, asyncError.error),
72 asyncError.stackTrace); 80 asyncError.stackTrace);
73 } 81 }
74 82
75 return new Suite(response["tests"].map((test) { 83 return new Suite(response["tests"].map((test) {
76 var testMetadata = new Metadata.deserialize(test['metadata']); 84 var testMetadata = new Metadata.deserialize(test['metadata']);
77 var testChannel = suiteChannel.virtualChannel(test['channel']); 85 var testChannel = suiteChannel.virtualChannel(test['channel']);
78 return new IframeTest(test['name'], testMetadata, testChannel); 86 return new IframeTest(test['name'], testMetadata, testChannel);
79 }), metadata: metadata, path: path); 87 }), metadata: metadata, path: path);
80 }); 88 });
81 } 89 }
82 } 90 }
OLDNEW
« no previous file with comments | « lib/src/backend/test.dart ('k') | lib/src/runner/browser/iframe_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698