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

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

Issue 1414793015: Use the async package's CancelableOperation. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 1 month 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/dartium.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:async/async.dart'; 10 import 'package:async/async.dart';
11 import 'package:http_parser/http_parser.dart'; 11 import 'package:http_parser/http_parser.dart';
12 import 'package:pool/pool.dart'; 12 import 'package:pool/pool.dart';
13 13
14 import '../../backend/group.dart'; 14 import '../../backend/group.dart';
15 import '../../backend/metadata.dart'; 15 import '../../backend/metadata.dart';
16 import '../../backend/test.dart'; 16 import '../../backend/test.dart';
17 import '../../backend/test_platform.dart'; 17 import '../../backend/test_platform.dart';
18 import '../../util/cancelable_future.dart';
19 import '../../util/multi_channel.dart'; 18 import '../../util/multi_channel.dart';
20 import '../../util/remote_exception.dart'; 19 import '../../util/remote_exception.dart';
21 import '../../util/stack_trace_mapper.dart'; 20 import '../../util/stack_trace_mapper.dart';
22 import '../../utils.dart'; 21 import '../../utils.dart';
23 import '../application_exception.dart'; 22 import '../application_exception.dart';
24 import '../environment.dart'; 23 import '../environment.dart';
25 import '../load_exception.dart'; 24 import '../load_exception.dart';
26 import '../runner_suite.dart'; 25 import '../runner_suite.dart';
27 import 'browser.dart'; 26 import 'browser.dart';
28 import 'chrome.dart'; 27 import 'chrome.dart';
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 Map test) { 274 Map test) {
276 if (test == null) return null; 275 if (test == null) return null;
277 276
278 var metadata = new Metadata.deserialize(test['metadata']); 277 var metadata = new Metadata.deserialize(test['metadata']);
279 var testChannel = suiteChannel.virtualChannel(test['channel']); 278 var testChannel = suiteChannel.virtualChannel(test['channel']);
280 return new IframeTest(test['name'], metadata, testChannel, 279 return new IframeTest(test['name'], metadata, testChannel,
281 mapper: mapper); 280 mapper: mapper);
282 } 281 }
283 282
284 /// An implementation of [Environment.displayPause]. 283 /// An implementation of [Environment.displayPause].
285 CancelableFuture _displayPause() { 284 CancelableOperation _displayPause() {
286 if (_pauseCompleter != null) return _pauseCompleter.future; 285 if (_pauseCompleter != null) return _pauseCompleter.operation;
287 286
288 _pauseCompleter = new CancelableCompleter(() { 287 _pauseCompleter = new CancelableCompleter(onCancel: () {
289 _channel.sink.add({"command": "resume"}); 288 _channel.sink.add({"command": "resume"});
290 _pauseCompleter = null; 289 _pauseCompleter = null;
291 }); 290 });
292 291
293 _channel.sink.add({"command": "displayPause"}); 292 _pauseCompleter.operation.value.whenComplete(() {
294 return _pauseCompleter.future.whenComplete(() {
295 _pauseCompleter = null; 293 _pauseCompleter = null;
296 }); 294 });
295
296 _channel.sink.add({"command": "displayPause"});
297
298 return _pauseCompleter.operation;
297 } 299 }
298 300
299 /// The callback for handling messages received from the host page. 301 /// The callback for handling messages received from the host page.
300 void _onMessage(Map message) { 302 void _onMessage(Map message) {
301 assert(message["command"] == "resume"); 303 assert(message["command"] == "resume");
302 if (_pauseCompleter == null) return; 304 if (_pauseCompleter == null) return;
303 _pauseCompleter.complete(); 305 _pauseCompleter.complete();
304 } 306 }
305 307
306 /// Closes the manager and releases any resources it owns, including closing 308 /// Closes the manager and releases any resources it owns, including closing
(...skipping 13 matching lines...) Expand all
320 class _BrowserEnvironment implements Environment { 322 class _BrowserEnvironment implements Environment {
321 final BrowserManager _manager; 323 final BrowserManager _manager;
322 324
323 final Uri observatoryUrl; 325 final Uri observatoryUrl;
324 326
325 final Uri remoteDebuggerUrl; 327 final Uri remoteDebuggerUrl;
326 328
327 _BrowserEnvironment(this._manager, this.observatoryUrl, 329 _BrowserEnvironment(this._manager, this.observatoryUrl,
328 this.remoteDebuggerUrl); 330 this.remoteDebuggerUrl);
329 331
330 CancelableFuture displayPause() => _manager._displayPause(); 332 CancelableOperation displayPause() => _manager._displayPause();
331 } 333 }
OLDNEW
« no previous file with comments | « no previous file | lib/src/runner/browser/dartium.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698