Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library browser; | 4 library browser; |
| 5 | 5 |
| 6 import "dart:async"; | 6 import "dart:async"; |
| 7 import "dart:convert" show LineSplitter, UTF8; | 7 import "dart:convert" show LineSplitter, UTF8; |
| 8 import "dart:core"; | 8 import "dart:core"; |
| 9 import "dart:io"; | 9 import "dart:io"; |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 // of close() | 46 // of close() |
| 47 Future done; | 47 Future done; |
| 48 | 48 |
| 49 Browser(); | 49 Browser(); |
| 50 | 50 |
| 51 factory Browser.byName(String name) { | 51 factory Browser.byName(String name) { |
| 52 if (name == 'ff' || name == 'firefox') { | 52 if (name == 'ff' || name == 'firefox') { |
| 53 return new Firefox(); | 53 return new Firefox(); |
| 54 } else if (name == 'chrome') { | 54 } else if (name == 'chrome') { |
| 55 return new Chrome(); | 55 return new Chrome(); |
| 56 } else if (name == 'dartium') { | |
| 57 return new Dartium(); | |
| 56 } else if (name == 'safari') { | 58 } else if (name == 'safari') { |
| 57 return new Safari(); | 59 return new Safari(); |
| 58 } else if (name.startsWith('ie')) { | 60 } else if (name.startsWith('ie')) { |
| 59 return new IE(); | 61 return new IE(); |
| 60 } else { | 62 } else { |
| 61 throw "Non supported browser"; | 63 throw "Non supported browser"; |
| 62 } | 64 } |
| 63 } | 65 } |
| 64 | 66 |
| 65 static const List<String> SUPPORTED_BROWSERS = | 67 static const List<String> SUPPORTED_BROWSERS = |
| 66 const ['safari', 'ff', 'firefox', 'chrome', 'ie9', 'ie10']; | 68 const ['safari', 'ff', 'firefox', 'chrome', 'ie9', 'ie10', 'dartium']; |
| 67 | 69 |
| 68 static const List<String> BROWSERS_WITH_WINDOW_SUPPORT = | 70 static const List<String> BROWSERS_WITH_WINDOW_SUPPORT = |
| 69 const ['safari', 'ff', 'firefox', 'chrome']; | 71 const ['safari', 'ff', 'firefox', 'chrome']; |
| 70 | 72 |
| 71 // TODO(kustermann): add standard support for chrome on android | 73 // TODO(kustermann): add standard support for chrome on android |
| 72 static bool supportedBrowser(String name) { | 74 static bool supportedBrowser(String name) { |
| 73 return SUPPORTED_BROWSERS.contains(name); | 75 return SUPPORTED_BROWSERS.contains(name); |
| 74 } | 76 } |
| 75 | 77 |
| 76 void _logEvent(String event) { | 78 void _logEvent(String event) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 102 } else { | 104 } else { |
| 103 _logEvent("The process is already dead."); | 105 _logEvent("The process is already dead."); |
| 104 return new Future.value(true); | 106 return new Future.value(true); |
| 105 } | 107 } |
| 106 } | 108 } |
| 107 | 109 |
| 108 /** | 110 /** |
| 109 * Start the browser using the supplied argument. | 111 * Start the browser using the supplied argument. |
| 110 * This sets up the error handling and usage logging. | 112 * This sets up the error handling and usage logging. |
| 111 */ | 113 */ |
| 112 Future<bool> startBrowser(String command, List<String> arguments) { | 114 Future<bool> startBrowser(String command, |
| 113 return Process.start(command, arguments).then((startedProcess) { | 115 List<String> arguments, |
| 116 {Map<String,String> environment}) { | |
| 117 return Process.start(command, arguments, environment: environment) | |
| 118 .then((startedProcess) { | |
| 114 process = startedProcess; | 119 process = startedProcess; |
| 115 // Used to notify when exiting, and as a return value on calls to | 120 // Used to notify when exiting, and as a return value on calls to |
| 116 // close(). | 121 // close(). |
| 117 var doneCompleter = new Completer(); | 122 var doneCompleter = new Completer(); |
| 118 done = doneCompleter.future; | 123 done = doneCompleter.future; |
| 119 | 124 |
| 120 Completer stdoutDone = new Completer(); | 125 Completer stdoutDone = new Completer(); |
| 121 Completer stderrDone = new Completer(); | 126 Completer stderrDone = new Completer(); |
| 122 | 127 |
| 123 process.stdout.transform(UTF8.decoder).listen((data) { | 128 process.stdout.transform(UTF8.decoder).listen((data) { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 String toString() => "Safari"; | 314 String toString() => "Safari"; |
| 310 | 315 |
| 311 // Delete the user specific browser cache and profile data. | 316 // Delete the user specific browser cache and profile data. |
| 312 // Safari only have one per user, and you can't specify one by command line. | 317 // Safari only have one per user, and you can't specify one by command line. |
| 313 static bool deleteCache = false; | 318 static bool deleteCache = false; |
| 314 | 319 |
| 315 } | 320 } |
| 316 | 321 |
| 317 | 322 |
| 318 class Chrome extends Browser { | 323 class Chrome extends Browser { |
| 319 static String _binary = _getBinary(); | 324 String _binary; |
|
kasperl
2013/10/01 13:15:55
final? You'll need to initialize it in the initial
kustermann
2013/10/01 15:41:59
I've tried:
final String _binary;
...
Chrom
| |
| 320 | |
| 321 String _version = "Version not found yet"; | 325 String _version = "Version not found yet"; |
| 322 | 326 |
| 323 // This is extracted to a function since we may need to support several | 327 Chrome() { |
| 324 // locations. | 328 _binary = _getBinary(); |
| 325 static String _getWindowsBinary() { | |
| 326 return "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"; | |
| 327 } | 329 } |
| 328 | 330 |
| 329 static String _getBinary() { | 331 String _getBinary() { |
| 332 // This is extracted to a function since we may need to support several | |
|
kasperl
2013/10/01 13:15:55
So this is just planning for future changes?
kustermann
2013/10/01 15:41:59
Yeah, rico put this in.
It's not really necessary
| |
| 333 // locations. | |
| 334 String _getWindowsBinary() { | |
| 335 return "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"; | |
| 336 } | |
| 337 | |
| 330 if (Platform.isWindows) return _getWindowsBinary(); | 338 if (Platform.isWindows) return _getWindowsBinary(); |
| 331 if (Platform.isMacOS) { | 339 if (Platform.isMacOS) { |
| 332 return "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; | 340 return "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; |
| 333 } | 341 } |
| 334 if (Platform.isLinux) return 'google-chrome'; | 342 if (Platform.isLinux) return 'google-chrome'; |
| 335 } | 343 } |
| 336 | 344 |
| 345 Map<String, String> _getEnvironment() => null; | |
| 346 | |
| 337 Future<bool> _getVersion() { | 347 Future<bool> _getVersion() { |
| 338 if (Platform.isWindows) { | 348 if (Platform.isWindows) { |
| 339 // The version flag does not work on windows. | 349 // The version flag does not work on windows. |
| 340 // See issue: | 350 // See issue: |
| 341 // https://code.google.com/p/chromium/issues/detail?id=158372 | 351 // https://code.google.com/p/chromium/issues/detail?id=158372 |
| 342 // The registry hack does not seem to work. | 352 // The registry hack does not seem to work. |
| 343 _version = "Can't get version on windows"; | 353 _version = "Can't get version on windows"; |
| 344 // We still validate that the binary exists so that we can give good | 354 // We still validate that the binary exists so that we can give good |
| 345 // feedback. | 355 // feedback. |
| 346 return new File(_binary).exists().then((exists) { | 356 return new File(_binary).exists().then((exists) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 368 // Get the version and log that. | 378 // Get the version and log that. |
| 369 return _getVersion().then((success) { | 379 return _getVersion().then((success) { |
| 370 if (!success) return false; | 380 if (!success) return false; |
| 371 _logEvent("Got version: $_version"); | 381 _logEvent("Got version: $_version"); |
| 372 | 382 |
| 373 return new Directory('').createTemp().then((userDir) { | 383 return new Directory('').createTemp().then((userDir) { |
| 374 _cleanup = () { userDir.deleteSync(recursive: true); }; | 384 _cleanup = () { userDir.deleteSync(recursive: true); }; |
| 375 var args = ["--user-data-dir=${userDir.path}", url, | 385 var args = ["--user-data-dir=${userDir.path}", url, |
| 376 "--disable-extensions", "--disable-popup-blocking", | 386 "--disable-extensions", "--disable-popup-blocking", |
| 377 "--bwsi", "--no-first-run"]; | 387 "--bwsi", "--no-first-run"]; |
| 378 return startBrowser(_binary, args); | 388 return startBrowser(_binary, args, environment: _getEnvironment()); |
| 379 }); | 389 }); |
| 380 }).catchError((e) { | 390 }).catchError((e) { |
| 381 _logEvent("Running $_binary --version failed with $e"); | 391 _logEvent("Running $_binary --version failed with $e"); |
| 382 return false; | 392 return false; |
| 383 }); | 393 }); |
| 384 } | 394 } |
| 385 | 395 |
| 386 String toString() => "Chrome"; | 396 String toString() => "Chrome"; |
| 387 } | 397 } |
| 388 | 398 |
| 399 class Dartium extends Chrome { | |
| 400 String _getBinary() { | |
| 401 if (Platform.operatingSystem == 'macos') { | |
| 402 return new Path('client/tests/dartium/Chromium.app/Contents/' | |
| 403 'MacOS/Chromium').toNativePath(); | |
| 404 } | |
| 405 return new Path('client/tests/dartium/chrome').toNativePath(); | |
| 406 } | |
| 407 | |
| 408 Map<String, String> _getEnvironment() { | |
| 409 var environment = new Map<String,String>.from(Platform.environment); | |
| 410 // By setting this environment variable, dartium will forward "print()" | |
| 411 // calls in dart to the top-level javascript function "dartPrint()" if | |
| 412 // available. | |
| 413 environment['DART_FORWARDING_PRINT'] = '1'; | |
| 414 return environment; | |
| 415 } | |
| 416 | |
| 417 String toString() => "Dartium"; | |
| 418 } | |
| 419 | |
| 389 class IE extends Browser { | 420 class IE extends Browser { |
| 390 | 421 |
| 391 static const String binary = | 422 static const String binary = |
| 392 "c:\\Program Files\\Internet Explorer\\iexplore.exe"; | 423 "c:\\Program Files\\Internet Explorer\\iexplore.exe"; |
| 393 | 424 |
| 394 Future<String> getVersion() { | 425 Future<String> getVersion() { |
| 395 var args = ["query", | 426 var args = ["query", |
| 396 "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Internet Explorer", | 427 "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Internet Explorer", |
| 397 "/v", | 428 "/v", |
| 398 "version"]; | 429 "version"]; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 List<BrowserTest> testQueue = new List<BrowserTest>(); | 644 List<BrowserTest> testQueue = new List<BrowserTest>(); |
| 614 Map<String, BrowserTestingStatus> browserStatus = | 645 Map<String, BrowserTestingStatus> browserStatus = |
| 615 new Map<String, BrowserTestingStatus>(); | 646 new Map<String, BrowserTestingStatus>(); |
| 616 | 647 |
| 617 var adbDeviceMapping = new Map<String, AdbDevice>(); | 648 var adbDeviceMapping = new Map<String, AdbDevice>(); |
| 618 // This cache is used to guarantee that we never see double reporting. | 649 // This cache is used to guarantee that we never see double reporting. |
| 619 // If we do we need to provide developers with this information. | 650 // If we do we need to provide developers with this information. |
| 620 // We don't add urls to the cache until we have run it. | 651 // We don't add urls to the cache until we have run it. |
| 621 Map<int, String> testCache = new Map<int, String>(); | 652 Map<int, String> testCache = new Map<int, String>(); |
| 622 List<int> doubleReportingTests = new List<int>(); | 653 List<int> doubleReportingTests = new List<int>(); |
| 654 Map<int, String> doubleReportingOutputs = new Map<int, String>(); | |
| 623 | 655 |
| 624 BrowserTestingServer testingServer; | 656 BrowserTestingServer testingServer; |
| 625 | 657 |
| 626 BrowserTestRunner(this.local_ip, this.browserName, this.maxNumBrowsers); | 658 BrowserTestRunner(this.local_ip, this.browserName, this.maxNumBrowsers); |
| 627 | 659 |
| 628 Future<bool> start() { | 660 Future<bool> start() { |
| 629 // If [browserName] doesn't support opening new windows, we use new iframes | 661 // If [browserName] doesn't support opening new windows, we use new iframes |
| 630 // instead. | 662 // instead. |
| 631 bool useIframe = | 663 bool useIframe = |
| 632 !Browser.BROWSERS_WITH_WINDOW_SUPPORT.contains(browserName); | 664 !Browser.BROWSERS_WITH_WINDOW_SUPPORT.contains(browserName); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 689 browsersCompleter.complete(browsers); | 721 browsersCompleter.complete(browsers); |
| 690 } | 722 } |
| 691 return browsersCompleter.future; | 723 return browsersCompleter.future; |
| 692 } | 724 } |
| 693 | 725 |
| 694 var timedOut = []; | 726 var timedOut = []; |
| 695 | 727 |
| 696 void handleResults(String browserId, String output, int testId) { | 728 void handleResults(String browserId, String output, int testId) { |
| 697 var status = browserStatus[browserId]; | 729 var status = browserStatus[browserId]; |
| 698 if (testCache.containsKey(testId)) { | 730 if (testCache.containsKey(testId)) { |
| 699 doubleReportingTests.add(testId); | 731 doubleReportingTests.add(testId); |
|
kasperl
2013/10/01 13:15:55
Isn't the (linked) key set of the doubleReportingO
kustermann
2013/10/01 15:41:59
The keys in doubleReportingOutputs are enough, tha
| |
| 732 doubleReportingOutputs[testId] = output; | |
| 700 return; | 733 return; |
| 701 } | 734 } |
| 702 | 735 |
| 703 if (status == null || status.timeout) { | 736 if (status == null || status.timeout) { |
| 704 // We don't do anything, this browser is currently being killed and | 737 // We don't do anything, this browser is currently being killed and |
| 705 // replaced. The browser here can be null if we decided to kill the | 738 // replaced. The browser here can be null if we decided to kill the |
| 706 // browser. | 739 // browser. |
| 707 } else if (status.currentTest != null) { | 740 } else if (status.currentTest != null) { |
| 708 status.currentTest.timeoutTimer.cancel(); | 741 status.currentTest.timeoutTimer.cancel(); |
| 709 status.currentTest.stopwatch.stop(); | 742 status.currentTest.stopwatch.stop(); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 829 void queueTest(BrowserTest test) { | 862 void queueTest(BrowserTest test) { |
| 830 testQueue.add(test); | 863 testQueue.add(test); |
| 831 } | 864 } |
| 832 | 865 |
| 833 void printDoubleReportingTests() { | 866 void printDoubleReportingTests() { |
| 834 if (doubleReportingTests.length == 0) return; | 867 if (doubleReportingTests.length == 0) return; |
| 835 // TODO(ricow): die on double reporting. | 868 // TODO(ricow): die on double reporting. |
| 836 // Currently we just report this here, we could have a callback to the | 869 // Currently we just report this here, we could have a callback to the |
| 837 // encapsulating environment. | 870 // encapsulating environment. |
| 838 print(""); | 871 print(""); |
| 839 print("Double reporting tests"); | 872 print("Double reporting tests"); |
|
ricow1
2013/10/02 18:17:47
Do we want to remove the double reporting here whe
kustermann
2013/10/03 11:06:01
For now I'd leave it, if you pass '--write-debug-l
| |
| 840 for (var id in doubleReportingTests) { | 873 for (var id in doubleReportingTests) { |
| 841 print(" ${testCache[id]}"); | 874 print(" ${testCache[id]}"); |
| 842 } | 875 } |
| 876 | |
| 877 DebugLogger.warning("Double reporting tests:"); | |
| 878 for (var id in doubleReportingTests) { | |
| 879 DebugLogger.warning(" ${testCache[id]}, output: "); | |
| 880 DebugLogger.warning("${doubleReportingOutputs[id]}"); | |
| 881 DebugLogger.warning(""); | |
| 882 DebugLogger.warning(""); | |
| 883 } | |
|
kustermann
2013/10/01 12:55:06
I don't know if I should submit this, but we'd get
kasperl
2013/10/01 13:15:55
I'd submit it.
| |
| 843 } | 884 } |
| 844 | 885 |
| 845 Future<bool> terminate() { | 886 Future<bool> terminate() { |
| 846 var futures = []; | 887 var futures = []; |
| 847 underTermination = true; | 888 underTermination = true; |
| 848 testingServer.underTermination = true; | 889 testingServer.underTermination = true; |
| 849 for (BrowserTestingStatus status in browserStatus.values) { | 890 for (BrowserTestingStatus status in browserStatus.values) { |
| 850 futures.add(status.browser.close()); | 891 futures.add(status.browser.close()); |
| 851 } | 892 } |
| 852 return Future.wait(futures).then((values) { | 893 return Future.wait(futures).then((values) { |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1177 Dart test driver, number of tests: <div id="number"></div><br> | 1218 Dart test driver, number of tests: <div id="number"></div><br> |
| 1178 Currently executing: <div id="currently_executing"></div><br> | 1219 Currently executing: <div id="currently_executing"></div><br> |
| 1179 Unhandled error: <div id="unhandled_error"></div> | 1220 Unhandled error: <div id="unhandled_error"></div> |
| 1180 <iframe id="embedded_iframe"></iframe> | 1221 <iframe id="embedded_iframe"></iframe> |
| 1181 </body> | 1222 </body> |
| 1182 </html> | 1223 </html> |
| 1183 """; | 1224 """; |
| 1184 return driverContent; | 1225 return driverContent; |
| 1185 } | 1226 } |
| 1186 } | 1227 } |
| OLD | NEW |