| 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; |
| 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() { |
| 330 if (Platform.isWindows) return _getWindowsBinary(); | 332 if (Platform.isWindows) { |
| 331 if (Platform.isMacOS) { | 333 return "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"; |
| 334 } else if (Platform.isMacOS) { |
| 332 return "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; | 335 return "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; |
| 333 } | 336 } |
| 334 if (Platform.isLinux) return 'google-chrome'; | 337 assert(Platform.isLinux); |
| 338 return 'google-chrome'; |
| 335 } | 339 } |
| 336 | 340 |
| 341 Map<String, String> _getEnvironment() => null; |
| 342 |
| 337 Future<bool> _getVersion() { | 343 Future<bool> _getVersion() { |
| 338 if (Platform.isWindows) { | 344 if (Platform.isWindows) { |
| 339 // The version flag does not work on windows. | 345 // The version flag does not work on windows. |
| 340 // See issue: | 346 // See issue: |
| 341 // https://code.google.com/p/chromium/issues/detail?id=158372 | 347 // https://code.google.com/p/chromium/issues/detail?id=158372 |
| 342 // The registry hack does not seem to work. | 348 // The registry hack does not seem to work. |
| 343 _version = "Can't get version on windows"; | 349 _version = "Can't get version on windows"; |
| 344 // We still validate that the binary exists so that we can give good | 350 // We still validate that the binary exists so that we can give good |
| 345 // feedback. | 351 // feedback. |
| 346 return new File(_binary).exists().then((exists) { | 352 return new File(_binary).exists().then((exists) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 368 // Get the version and log that. | 374 // Get the version and log that. |
| 369 return _getVersion().then((success) { | 375 return _getVersion().then((success) { |
| 370 if (!success) return false; | 376 if (!success) return false; |
| 371 _logEvent("Got version: $_version"); | 377 _logEvent("Got version: $_version"); |
| 372 | 378 |
| 373 return new Directory('').createTemp().then((userDir) { | 379 return new Directory('').createTemp().then((userDir) { |
| 374 _cleanup = () { userDir.deleteSync(recursive: true); }; | 380 _cleanup = () { userDir.deleteSync(recursive: true); }; |
| 375 var args = ["--user-data-dir=${userDir.path}", url, | 381 var args = ["--user-data-dir=${userDir.path}", url, |
| 376 "--disable-extensions", "--disable-popup-blocking", | 382 "--disable-extensions", "--disable-popup-blocking", |
| 377 "--bwsi", "--no-first-run"]; | 383 "--bwsi", "--no-first-run"]; |
| 378 return startBrowser(_binary, args); | 384 return startBrowser(_binary, args, environment: _getEnvironment()); |
| 379 }); | 385 }); |
| 380 }).catchError((e) { | 386 }).catchError((e) { |
| 381 _logEvent("Running $_binary --version failed with $e"); | 387 _logEvent("Running $_binary --version failed with $e"); |
| 382 return false; | 388 return false; |
| 383 }); | 389 }); |
| 384 } | 390 } |
| 385 | 391 |
| 386 String toString() => "Chrome"; | 392 String toString() => "Chrome"; |
| 387 } | 393 } |
| 388 | 394 |
| 395 class Dartium extends Chrome { |
| 396 String _getBinary() { |
| 397 if (Platform.operatingSystem == 'macos') { |
| 398 return new Path('client/tests/dartium/Chromium.app/Contents/' |
| 399 'MacOS/Chromium').toNativePath(); |
| 400 } |
| 401 return new Path('client/tests/dartium/chrome').toNativePath(); |
| 402 } |
| 403 |
| 404 Map<String, String> _getEnvironment() { |
| 405 var environment = new Map<String,String>.from(Platform.environment); |
| 406 // By setting this environment variable, dartium will forward "print()" |
| 407 // calls in dart to the top-level javascript function "dartPrint()" if |
| 408 // available. |
| 409 environment['DART_FORWARDING_PRINT'] = '1'; |
| 410 return environment; |
| 411 } |
| 412 |
| 413 String toString() => "Dartium"; |
| 414 } |
| 415 |
| 389 class IE extends Browser { | 416 class IE extends Browser { |
| 390 | 417 |
| 391 static const String binary = | 418 static const String binary = |
| 392 "c:\\Program Files\\Internet Explorer\\iexplore.exe"; | 419 "c:\\Program Files\\Internet Explorer\\iexplore.exe"; |
| 393 | 420 |
| 394 Future<String> getVersion() { | 421 Future<String> getVersion() { |
| 395 var args = ["query", | 422 var args = ["query", |
| 396 "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Internet Explorer", | 423 "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Internet Explorer", |
| 397 "/v", | 424 "/v", |
| 398 "version"]; | 425 "version"]; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 | 639 |
| 613 List<BrowserTest> testQueue = new List<BrowserTest>(); | 640 List<BrowserTest> testQueue = new List<BrowserTest>(); |
| 614 Map<String, BrowserTestingStatus> browserStatus = | 641 Map<String, BrowserTestingStatus> browserStatus = |
| 615 new Map<String, BrowserTestingStatus>(); | 642 new Map<String, BrowserTestingStatus>(); |
| 616 | 643 |
| 617 var adbDeviceMapping = new Map<String, AdbDevice>(); | 644 var adbDeviceMapping = new Map<String, AdbDevice>(); |
| 618 // This cache is used to guarantee that we never see double reporting. | 645 // This cache is used to guarantee that we never see double reporting. |
| 619 // If we do we need to provide developers with this information. | 646 // 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. | 647 // We don't add urls to the cache until we have run it. |
| 621 Map<int, String> testCache = new Map<int, String>(); | 648 Map<int, String> testCache = new Map<int, String>(); |
| 622 List<int> doubleReportingTests = new List<int>(); | 649 Map<int, String> doubleReportingOutputs = new Map<int, String>(); |
| 623 | 650 |
| 624 BrowserTestingServer testingServer; | 651 BrowserTestingServer testingServer; |
| 625 | 652 |
| 626 BrowserTestRunner(this.local_ip, this.browserName, this.maxNumBrowsers); | 653 BrowserTestRunner(this.local_ip, this.browserName, this.maxNumBrowsers); |
| 627 | 654 |
| 628 Future<bool> start() { | 655 Future<bool> start() { |
| 629 // If [browserName] doesn't support opening new windows, we use new iframes | 656 // If [browserName] doesn't support opening new windows, we use new iframes |
| 630 // instead. | 657 // instead. |
| 631 bool useIframe = | 658 bool useIframe = |
| 632 !Browser.BROWSERS_WITH_WINDOW_SUPPORT.contains(browserName); | 659 !Browser.BROWSERS_WITH_WINDOW_SUPPORT.contains(browserName); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 browsersCompleter.complete(browsers); | 716 browsersCompleter.complete(browsers); |
| 690 } | 717 } |
| 691 return browsersCompleter.future; | 718 return browsersCompleter.future; |
| 692 } | 719 } |
| 693 | 720 |
| 694 var timedOut = []; | 721 var timedOut = []; |
| 695 | 722 |
| 696 void handleResults(String browserId, String output, int testId) { | 723 void handleResults(String browserId, String output, int testId) { |
| 697 var status = browserStatus[browserId]; | 724 var status = browserStatus[browserId]; |
| 698 if (testCache.containsKey(testId)) { | 725 if (testCache.containsKey(testId)) { |
| 699 doubleReportingTests.add(testId); | 726 doubleReportingOutputs[testId] = output; |
| 700 return; | 727 return; |
| 701 } | 728 } |
| 702 | 729 |
| 703 if (status == null || status.timeout) { | 730 if (status == null || status.timeout) { |
| 704 // We don't do anything, this browser is currently being killed and | 731 // 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 | 732 // replaced. The browser here can be null if we decided to kill the |
| 706 // browser. | 733 // browser. |
| 707 } else if (status.currentTest != null) { | 734 } else if (status.currentTest != null) { |
| 708 status.currentTest.timeoutTimer.cancel(); | 735 status.currentTest.timeoutTimer.cancel(); |
| 709 status.currentTest.stopwatch.stop(); | 736 status.currentTest.stopwatch.stop(); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 Timer createTimeoutTimer(BrowserTest test, BrowserTestingStatus status) { | 851 Timer createTimeoutTimer(BrowserTest test, BrowserTestingStatus status) { |
| 825 return new Timer( | 852 return new Timer( |
| 826 new Duration(seconds: test.timeout), () { handleTimeout(status); }); | 853 new Duration(seconds: test.timeout), () { handleTimeout(status); }); |
| 827 } | 854 } |
| 828 | 855 |
| 829 void queueTest(BrowserTest test) { | 856 void queueTest(BrowserTest test) { |
| 830 testQueue.add(test); | 857 testQueue.add(test); |
| 831 } | 858 } |
| 832 | 859 |
| 833 void printDoubleReportingTests() { | 860 void printDoubleReportingTests() { |
| 834 if (doubleReportingTests.length == 0) return; | 861 if (doubleReportingOutputs.length == 0) return; |
| 835 // TODO(ricow): die on double reporting. | 862 // TODO(ricow): die on double reporting. |
| 836 // Currently we just report this here, we could have a callback to the | 863 // Currently we just report this here, we could have a callback to the |
| 837 // encapsulating environment. | 864 // encapsulating environment. |
| 838 print(""); | 865 print(""); |
| 839 print("Double reporting tests"); | 866 print("Double reporting tests"); |
| 840 for (var id in doubleReportingTests) { | 867 for (var id in doubleReportingOutputs.keys) { |
| 841 print(" ${testCache[id]}"); | 868 print(" ${testCache[id]}"); |
| 842 } | 869 } |
| 870 |
| 871 DebugLogger.warning("Double reporting tests:"); |
| 872 for (var id in doubleReportingOutputs.keys) { |
| 873 DebugLogger.warning("${testCache[id]}, output: "); |
| 874 DebugLogger.warning("${doubleReportingOutputs[id]}"); |
| 875 DebugLogger.warning(""); |
| 876 DebugLogger.warning(""); |
| 877 } |
| 843 } | 878 } |
| 844 | 879 |
| 845 Future<bool> terminate() { | 880 Future<bool> terminate() { |
| 846 var futures = []; | 881 var futures = []; |
| 847 underTermination = true; | 882 underTermination = true; |
| 848 testingServer.underTermination = true; | 883 testingServer.underTermination = true; |
| 849 for (BrowserTestingStatus status in browserStatus.values) { | 884 for (BrowserTestingStatus status in browserStatus.values) { |
| 850 futures.add(status.browser.close()); | 885 futures.add(status.browser.close()); |
| 851 } | 886 } |
| 852 return Future.wait(futures).then((values) { | 887 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> | 1212 Dart test driver, number of tests: <div id="number"></div><br> |
| 1178 Currently executing: <div id="currently_executing"></div><br> | 1213 Currently executing: <div id="currently_executing"></div><br> |
| 1179 Unhandled error: <div id="unhandled_error"></div> | 1214 Unhandled error: <div id="unhandled_error"></div> |
| 1180 <iframe id="embedded_iframe"></iframe> | 1215 <iframe id="embedded_iframe"></iframe> |
| 1181 </body> | 1216 </body> |
| 1182 </html> | 1217 </html> |
| 1183 """; | 1218 """; |
| 1184 return driverContent; | 1219 return driverContent; |
| 1185 } | 1220 } |
| 1186 } | 1221 } |
| OLD | NEW |