| OLD | NEW |
| 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'; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 /// screen. | 74 /// screen. |
| 75 CancelableCompleter _pauseCompleter; | 75 CancelableCompleter _pauseCompleter; |
| 76 | 76 |
| 77 /// The environment to attach to each suite. | 77 /// The environment to attach to each suite. |
| 78 Future<_BrowserEnvironment> _environment; | 78 Future<_BrowserEnvironment> _environment; |
| 79 | 79 |
| 80 /// Starts the browser identified by [platform] and has it connect to [url]. | 80 /// Starts the browser identified by [platform] and has it connect to [url]. |
| 81 /// | 81 /// |
| 82 /// [url] should serve a page that establishes a WebSocket connection with | 82 /// [url] should serve a page that establishes a WebSocket connection with |
| 83 /// this process. That connection, once established, should be emitted via | 83 /// this process. That connection, once established, should be emitted via |
| 84 /// [future]. | 84 /// [future]. If [debug] is true, starts the browser in debug mode, with its |
| 85 /// debugger interfaces on and detected. |
| 85 /// | 86 /// |
| 86 /// Returns the browser manager, or throws an [ApplicationException] if a | 87 /// Returns the browser manager, or throws an [ApplicationException] if a |
| 87 /// connection fails to be established. | 88 /// connection fails to be established. |
| 88 static Future<BrowserManager> start(TestPlatform platform, Uri url, | 89 static Future<BrowserManager> start(TestPlatform platform, Uri url, |
| 89 Future<CompatibleWebSocket> future) { | 90 Future<CompatibleWebSocket> future, {bool debug: false}) { |
| 90 var browser = _newBrowser(url, platform); | 91 var browser = _newBrowser(url, platform, debug: debug); |
| 91 | 92 |
| 92 var completer = new Completer(); | 93 var completer = new Completer(); |
| 93 | 94 |
| 94 // TODO(nweiz): Gracefully handle the browser being killed before the | 95 // TODO(nweiz): Gracefully handle the browser being killed before the |
| 95 // tests complete. | 96 // tests complete. |
| 96 browser.onExit.then((_) { | 97 browser.onExit.then((_) { |
| 97 throw new ApplicationException( | 98 throw new ApplicationException( |
| 98 "${platform.name} exited before connecting."); | 99 "${platform.name} exited before connecting."); |
| 99 }).catchError((error, stackTrace) { | 100 }).catchError((error, stackTrace) { |
| 100 if (completer.isCompleted) return; | 101 if (completer.isCompleted) return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 111 }); | 112 }); |
| 112 | 113 |
| 113 return completer.future.timeout(new Duration(seconds: 30), onTimeout: () { | 114 return completer.future.timeout(new Duration(seconds: 30), onTimeout: () { |
| 114 browser.close(); | 115 browser.close(); |
| 115 throw new ApplicationException( | 116 throw new ApplicationException( |
| 116 "Timed out waiting for ${platform.name} to connect."); | 117 "Timed out waiting for ${platform.name} to connect."); |
| 117 }); | 118 }); |
| 118 } | 119 } |
| 119 | 120 |
| 120 /// Starts the browser identified by [browser] and has it load [url]. | 121 /// Starts the browser identified by [browser] and has it load [url]. |
| 121 static Browser _newBrowser(Uri url, TestPlatform browser) { | 122 /// |
| 123 /// If [debug] is true, starts the browser in debug mode. |
| 124 static Browser _newBrowser(Uri url, TestPlatform browser, |
| 125 {bool debug: false}) { |
| 122 switch (browser) { | 126 switch (browser) { |
| 123 case TestPlatform.dartium: return new Dartium(url); | 127 case TestPlatform.dartium: return new Dartium(url, debug: debug); |
| 124 case TestPlatform.contentShell: return new ContentShell(url); | 128 case TestPlatform.contentShell: |
| 129 return new ContentShell(url, debug: debug); |
| 125 case TestPlatform.chrome: return new Chrome(url); | 130 case TestPlatform.chrome: return new Chrome(url); |
| 126 case TestPlatform.phantomJS: return new PhantomJS(url); | 131 case TestPlatform.phantomJS: return new PhantomJS(url); |
| 127 case TestPlatform.firefox: return new Firefox(url); | 132 case TestPlatform.firefox: return new Firefox(url); |
| 128 case TestPlatform.safari: return new Safari(url); | 133 case TestPlatform.safari: return new Safari(url); |
| 129 case TestPlatform.internetExplorer: return new InternetExplorer(url); | 134 case TestPlatform.internetExplorer: return new InternetExplorer(url); |
| 130 default: | 135 default: |
| 131 throw new ArgumentError("$browser is not a browser."); | 136 throw new ArgumentError("$browser is not a browser."); |
| 132 } | 137 } |
| 133 } | 138 } |
| 134 | 139 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 /// All methods forward directly to [BrowserManager]. | 282 /// All methods forward directly to [BrowserManager]. |
| 278 class _BrowserEnvironment implements Environment { | 283 class _BrowserEnvironment implements Environment { |
| 279 final BrowserManager _manager; | 284 final BrowserManager _manager; |
| 280 | 285 |
| 281 final Uri observatoryUrl; | 286 final Uri observatoryUrl; |
| 282 | 287 |
| 283 _BrowserEnvironment(this._manager, this.observatoryUrl); | 288 _BrowserEnvironment(this._manager, this.observatoryUrl); |
| 284 | 289 |
| 285 CancelableFuture displayPause() => _manager._displayPause(); | 290 CancelableFuture displayPause() => _manager._displayPause(); |
| 286 } | 291 } |
| OLD | NEW |