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

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

Issue 1228943005: Avoid an uncaught error. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 5 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 | « CHANGELOG.md ('k') | pubspec.yaml » ('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';
(...skipping 30 matching lines...) Expand all
41 /// once, and we want a timeout in case they fail so we only wait for so many 41 /// once, and we want a timeout in case they fail so we only wait for so many
42 /// at once. 42 /// at once.
43 final _pool = new Pool(8); 43 final _pool = new Pool(8);
44 44
45 /// The ID of the next suite to be loaded. 45 /// The ID of the next suite to be loaded.
46 /// 46 ///
47 /// This is used to ensure that the suites can be referred to consistently 47 /// This is used to ensure that the suites can be referred to consistently
48 /// across the client and server. 48 /// across the client and server.
49 int _suiteId = 0; 49 int _suiteId = 0;
50 50
51 /// Whether the channel to the browser has closed.
52 bool _closed;
53
51 /// Creates a new BrowserManager that communicates with [browser] over 54 /// Creates a new BrowserManager that communicates with [browser] over
52 /// [webSocket]. 55 /// [webSocket].
53 BrowserManager(this.browser, CompatibleWebSocket webSocket) 56 BrowserManager(this.browser, CompatibleWebSocket webSocket)
54 : _channel = new MultiChannel( 57 : _channel = new MultiChannel(
55 webSocket.map(JSON.decode), 58 webSocket.map(JSON.decode),
56 mapSink(webSocket, JSON.encode)); 59 mapSink(webSocket, JSON.encode)) {
60 _channel.stream.listen(null, onDone: () => _closed = true);
kevmoo 2015/07/14 23:33:38 feels weird, but I guess Stream doesn't have a don
61 }
57 62
58 /// Tells the browser the load a test suite from the URL [url]. 63 /// Tells the browser the load a test suite from the URL [url].
59 /// 64 ///
60 /// [url] should be an HTML page with a reference to the JS-compiled test 65 /// [url] should be an HTML page with a reference to the JS-compiled test
61 /// suite. [path] is the path of the original test suite file, which is used 66 /// suite. [path] is the path of the original test suite file, which is used
62 /// for reporting. [metadata] is the parsed metadata for the test suite. 67 /// for reporting. [metadata] is the parsed metadata for the test suite.
63 /// 68 ///
64 /// If [mapper] is passed, it's used to map stack traces for errors coming 69 /// If [mapper] is passed, it's used to map stack traces for errors coming
65 /// from this test suite. 70 /// from this test suite.
66 Future<Suite> loadSuite(String path, Uri url, Metadata metadata, 71 Future<Suite> loadSuite(String path, Uri url, Metadata metadata,
67 {StackTraceMapper mapper}) async { 72 {StackTraceMapper mapper}) async {
68 url = url.replace(fragment: Uri.encodeFull(JSON.encode({ 73 url = url.replace(fragment: Uri.encodeFull(JSON.encode({
69 "metadata": metadata.serialize(), 74 "metadata": metadata.serialize(),
70 "browser": browser.identifier 75 "browser": browser.identifier
71 }))); 76 })));
72 77
73 // The stream may close before emitting a value if the browser is killed 78 // The stream may close before emitting a value if the browser is killed
74 // prematurely (e.g. via Control-C). 79 // prematurely (e.g. via Control-C).
75 var suiteVirtualChannel = _channel.virtualChannel(); 80 var suiteVirtualChannel = _channel.virtualChannel();
76 var suiteId = _suiteId++; 81 var suiteId = _suiteId++;
77 var suiteChannel; 82 var suiteChannel;
78 83
79 closeIframe() { 84 closeIframe() {
85 if (_closed) return;
80 suiteChannel.sink.close(); 86 suiteChannel.sink.close();
81 _channel.sink.add({ 87 _channel.sink.add({
82 "command": "closeSuite", 88 "command": "closeSuite",
83 "id": suiteId 89 "id": suiteId
84 }); 90 });
85 } 91 }
86 92
87 var response = await _pool.withResource(() { 93 var response = await _pool.withResource(() {
88 _channel.sink.add({ 94 _channel.sink.add({
89 "command": "loadSuite", 95 "command": "loadSuite",
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 141 }
136 142
137 return new Suite(response["tests"].map((test) { 143 return new Suite(response["tests"].map((test) {
138 var testMetadata = new Metadata.deserialize(test['metadata']); 144 var testMetadata = new Metadata.deserialize(test['metadata']);
139 var testChannel = suiteChannel.virtualChannel(test['channel']); 145 var testChannel = suiteChannel.virtualChannel(test['channel']);
140 return new IframeTest(test['name'], testMetadata, testChannel, 146 return new IframeTest(test['name'], testMetadata, testChannel,
141 mapper: mapper); 147 mapper: mapper);
142 }), metadata: metadata, path: path, onClose: () => closeIframe()); 148 }), metadata: metadata, path: path, onClose: () => closeIframe());
143 } 149 }
144 } 150 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698