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:core"; | 7 import "dart:core"; |
| 8 import "dart:io"; | 8 import "dart:io"; |
| 9 | 9 |
| 10 import 'android.dart'; | 10 import 'android.dart'; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 | 47 |
| 48 Browser(); | 48 Browser(); |
| 49 | 49 |
| 50 factory Browser.byName(String name) { | 50 factory Browser.byName(String name) { |
| 51 if (name == 'ff' || name == 'firefox') { | 51 if (name == 'ff' || name == 'firefox') { |
| 52 return new Firefox(); | 52 return new Firefox(); |
| 53 } else if (name == 'chrome') { | 53 } else if (name == 'chrome') { |
| 54 return new Chrome(); | 54 return new Chrome(); |
| 55 } else if (name == 'safari') { | 55 } else if (name == 'safari') { |
| 56 return new Safari(); | 56 return new Safari(); |
| 57 } else if (name.startsWith('ie')) { | |
| 58 return new IE(); | |
| 57 } else { | 59 } else { |
| 58 throw "Non supported browser"; | 60 throw "Non supported browser"; |
| 59 } | 61 } |
| 60 } | 62 } |
| 61 | 63 |
| 62 static const List<String> SUPPORTED_BROWSERS = | 64 static const List<String> SUPPORTED_BROWSERS = |
| 63 const ['safari', 'ff', 'firefox', 'chrome']; | 65 const ['safari', 'ff', 'firefox', 'chrome', 'ie9', 'ie10']; |
| 64 | 66 |
| 65 static const List<String> BROWSERS_WITH_WINDOW_SUPPORT = | 67 static const List<String> BROWSERS_WITH_WINDOW_SUPPORT = |
| 66 const ['safari', 'ff', 'firefox', 'chrome']; | 68 const ['safari', 'ff', 'firefox', 'chrome']; |
| 67 | 69 |
| 68 // TODO(kustermann): add standard support for chrome on android | 70 // TODO(kustermann): add standard support for chrome on android |
| 69 static bool supportedBrowser(String name) { | 71 static bool supportedBrowser(String name) { |
| 70 return SUPPORTED_BROWSERS.contains(name); | 72 return SUPPORTED_BROWSERS.contains(name); |
| 71 } | 73 } |
| 72 | 74 |
| 73 void _logEvent(String event) { | 75 void _logEvent(String event) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 stderrDone.complete(true); | 139 stderrDone.complete(true); |
| 138 }); | 140 }); |
| 139 | 141 |
| 140 process.exitCode.then((exitCode) { | 142 process.exitCode.then((exitCode) { |
| 141 _logEvent("Browser closed with exitcode $exitCode"); | 143 _logEvent("Browser closed with exitcode $exitCode"); |
| 142 Future.wait([stdoutDone.future, stderrDone.future]).then((_) { | 144 Future.wait([stdoutDone.future, stderrDone.future]).then((_) { |
| 143 process = null; | 145 process = null; |
| 144 if (_cleanup != null) { | 146 if (_cleanup != null) { |
| 145 _cleanup(); | 147 _cleanup(); |
| 146 } | 148 } |
| 147 doneCompleter.complete(exitCode); | 149 doneCompleter.complete(true); |
| 150 }).catchError((error) { | |
| 151 _logEvent("Error closing browsers: $error"); | |
| 148 }); | 152 }); |
| 149 }); | 153 }); |
| 150 return true; | 154 return true; |
| 151 }).catchError((error) { | 155 }).catchError((error) { |
| 152 _logEvent("Running $command $arguments failed with $error"); | 156 _logEvent("Running $command $arguments failed with $error"); |
| 153 return false; | 157 return false; |
| 154 }); | 158 }); |
| 155 } | 159 } |
| 156 | 160 |
| 157 /** | 161 /** |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 }); | 344 }); |
| 341 }).catchError((e) { | 345 }).catchError((e) { |
| 342 _logEvent("Running $binary --version failed with $e"); | 346 _logEvent("Running $binary --version failed with $e"); |
| 343 return false; | 347 return false; |
| 344 }); | 348 }); |
| 345 } | 349 } |
| 346 | 350 |
| 347 String toString() => "Chrome"; | 351 String toString() => "Chrome"; |
| 348 } | 352 } |
| 349 | 353 |
| 354 class IE extends Browser { | |
| 355 | |
| 356 static const String binary = | |
| 357 "c:\\Program Files\\Internet Explorer\\iexplore.exe"; | |
|
kustermann
2013/08/14 11:06:16
Check if the path is the same for ie9/ie10.
ricow1
2013/08/14 11:29:48
It is
| |
| 358 | |
| 359 Future<String> getVersion() { | |
| 360 var args = ["query", | |
| 361 "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Internet Explorer", | |
| 362 "/v", | |
| 363 "version"]; | |
| 364 return Process.run("reg", args).then((result) { | |
| 365 if (result.exitCode == 0) { | |
| 366 // The string we get back looks like this: | |
| 367 // HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer | |
| 368 // version REG_SZ 9.0.8112.16421 | |
| 369 var findString = "REG_SZ"; | |
| 370 var index = result.stdout.indexOf(findString); | |
| 371 if (index > 0) { | |
| 372 return result.stdout.substring(index + findString.length).trim(); | |
| 373 } | |
| 374 } | |
| 375 return "Could not get the version of internet explorer"; | |
| 376 }); | |
| 377 } | |
| 378 | |
|
kustermann
2013/08/14 11:06:16
extra line
ricow1
2013/08/14 11:29:48
done
| |
| 379 | |
| 380 Future<bool> start(String url) { | |
| 381 _logEvent("Starting ie browser on: $url"); | |
| 382 return getVersion().then((version) { | |
| 383 _logEvent("Got version: $version"); | |
| 384 return startBrowser(binary, [url]); | |
| 385 }); | |
| 386 } | |
| 387 String toString() => "IE"; | |
| 388 } | |
| 389 | |
| 390 | |
| 350 class AndroidChrome extends Browser { | 391 class AndroidChrome extends Browser { |
| 351 static const String viewAction = 'android.intent.action.VIEW'; | 392 static const String viewAction = 'android.intent.action.VIEW'; |
| 352 static const String mainAction = 'android.intent.action.MAIN'; | 393 static const String mainAction = 'android.intent.action.MAIN'; |
| 353 static const String chromePackage = 'com.android.chrome'; | 394 static const String chromePackage = 'com.android.chrome'; |
| 354 static const String browserPackage = 'com.android.browser'; | 395 static const String browserPackage = 'com.android.browser'; |
| 355 static const String firefoxPackage = 'org.mozilla.firefox'; | 396 static const String firefoxPackage = 'org.mozilla.firefox'; |
| 356 static const String turnScreenOnPackage = 'com.google.dart.turnscreenon'; | 397 static const String turnScreenOnPackage = 'com.google.dart.turnscreenon'; |
| 357 | 398 |
| 358 AndroidEmulator _emulator; | 399 AndroidEmulator _emulator; |
| 359 AdbDevice _adbDevice; | 400 AdbDevice _adbDevice; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 } | 643 } |
| 603 browsersCompleter.complete(browsers); | 644 browsersCompleter.complete(browsers); |
| 604 } | 645 } |
| 605 return browsersCompleter.future; | 646 return browsersCompleter.future; |
| 606 } | 647 } |
| 607 | 648 |
| 608 var timedOut = []; | 649 var timedOut = []; |
| 609 | 650 |
| 610 void handleResults(String browserId, String output, int testId) { | 651 void handleResults(String browserId, String output, int testId) { |
| 611 var status = browserStatus[browserId]; | 652 var status = browserStatus[browserId]; |
| 612 DebugLogger.info("Handling result for browser ${browserId}"); | |
| 613 if (testCache.containsKey(testId)) { | 653 if (testCache.containsKey(testId)) { |
| 614 doubleReportingTests.add(testId); | 654 doubleReportingTests.add(testId); |
| 615 return; | 655 return; |
| 616 } | 656 } |
| 617 | 657 |
| 618 if (status.timeout) { | 658 if (status.timeout) { |
| 619 // We don't do anything, this browser is currently being killed and | 659 // We don't do anything, this browser is currently being killed and |
| 620 // replaced. | 660 // replaced. |
| 621 } else if (status.currentTest != null) { | 661 } else if (status.currentTest != null) { |
| 622 status.currentTest.timeoutTimer.cancel(); | 662 status.currentTest.timeoutTimer.cancel(); |
| 623 status.currentTest.stopwatch.stop(); | 663 status.currentTest.stopwatch.stop(); |
| 624 | 664 |
| 625 if (status.currentTest.id != testId) { | 665 if (status.currentTest.id != testId) { |
| 626 print("Expected test id ${status.currentTest.id} for" | 666 print("Expected test id ${status.currentTest.id} for" |
| 627 "${status.currentTest.url}"); | 667 "${status.currentTest.url}"); |
| 628 print("Got test id ${testId}"); | 668 print("Got test id ${testId}"); |
| 629 print("Last test id was ${status.lastTest.id} for " | 669 print("Last test id was ${status.lastTest.id} for " |
| 630 "${status.currentTest.url}"); | 670 "${status.currentTest.url}"); |
| 631 throw("This should never happen, wrong test id"); | 671 throw("This should never happen, wrong test id"); |
| 632 } | 672 } |
| 633 testCache[testId] = status.currentTest.url; | 673 testCache[testId] = status.currentTest.url; |
| 634 DebugLogger.info("Size of output for test $testId : ${output.length}"); | |
| 635 Stopwatch watch = new Stopwatch()..start(); | 674 Stopwatch watch = new Stopwatch()..start(); |
| 636 status.currentTest.doneCallback(output, | 675 status.currentTest.doneCallback(output, |
| 637 status.currentTest.stopwatch.elapsed); | 676 status.currentTest.stopwatch.elapsed); |
| 638 watch.stop(); | 677 watch.stop(); |
| 639 DebugLogger.info("Handling of test $testId took : ${watch.elapsed}"); | |
| 640 status.lastTest = status.currentTest; | 678 status.lastTest = status.currentTest; |
| 641 status.currentTest = null; | 679 status.currentTest = null; |
| 642 } else { | 680 } else { |
| 643 print("\nThis is bad, should never happen, handleResult no test"); | 681 print("\nThis is bad, should never happen, handleResult no test"); |
| 644 print("URL: ${status.lastTest.url}"); | 682 print("URL: ${status.lastTest.url}"); |
| 645 print(output); | 683 print(output); |
| 646 terminate().then((_) { | 684 terminate().then((_) { |
| 647 exit(1); | 685 exit(1); |
| 648 }); | 686 }); |
| 649 } | 687 } |
| 650 } | 688 } |
| 651 | 689 |
| 652 void handleTimeout(BrowserTestingStatus status) { | 690 void handleTimeout(BrowserTestingStatus status) { |
| 653 // We simply kill the browser and starts up a new one! | 691 // We simply kill the browser and starts up a new one! |
| 654 // We could be smarter here, but it does not seems like it is worth it. | 692 // We could be smarter here, but it does not seems like it is worth it. |
| 655 DebugLogger.info("Handling timeout for browser ${status.browser.id}"); | |
| 656 status.timeout = true; | 693 status.timeout = true; |
| 657 timedOut.add(status.currentTest.url); | 694 timedOut.add(status.currentTest.url); |
| 658 var id = status.browser.id; | 695 var id = status.browser.id; |
| 659 status.browser.close().then((_) { | 696 status.browser.close().then((_) { |
| 660 // We don't want to start a new browser if we are terminating. | 697 // We don't want to start a new browser if we are terminating. |
| 661 if (underTermination) return; | 698 if (underTermination) return; |
| 662 var browser; | 699 var browser; |
| 663 var new_id = id; | 700 var new_id = id; |
| 664 if (browserName == 'chromeOnAndroid') { | 701 if (browserName == 'chromeOnAndroid') { |
| 665 browser = new AndroidChrome(adbDeviceMapping[id]); | 702 browser = new AndroidChrome(adbDeviceMapping[id]); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 694 status.currentTest.stopwatch.stop(); | 731 status.currentTest.stopwatch.stop(); |
| 695 status.currentTest.doneCallback("TIMEOUT", | 732 status.currentTest.doneCallback("TIMEOUT", |
| 696 status.currentTest.stopwatch.elapsed); | 733 status.currentTest.stopwatch.elapsed); |
| 697 status.currentTest = null; | 734 status.currentTest = null; |
| 698 } | 735 } |
| 699 | 736 |
| 700 BrowserTest getNextTest(String browserId) { | 737 BrowserTest getNextTest(String browserId) { |
| 701 if (testQueue.isEmpty) return null; | 738 if (testQueue.isEmpty) return null; |
| 702 var status = browserStatus[browserId]; | 739 var status = browserStatus[browserId]; |
| 703 if (status == null) return null; | 740 if (status == null) return null; |
| 704 DebugLogger.info("Handling getNext for browser " | |
| 705 "${browserId} timeout status: ${status.timeout}"); | |
| 706 | 741 |
| 707 // We are currently terminating this browser, don't start a new test. | 742 // We are currently terminating this browser, don't start a new test. |
| 708 if (status.timeout) return null; | 743 if (status.timeout) return null; |
| 709 BrowserTest test = testQueue.removeLast(); | 744 BrowserTest test = testQueue.removeLast(); |
| 710 if (status.currentTest == null) { | 745 if (status.currentTest == null) { |
| 711 status.currentTest = test; | 746 status.currentTest = test; |
| 712 } else { | 747 } else { |
| 713 // TODO(ricow): Handle this better. | 748 // TODO(ricow): Handle this better. |
| 714 print("This is bad, should never happen, getNextTest all full"); | 749 print("This is bad, should never happen, getNextTest all full"); |
| 715 print("This happened for browser $browserId"); | 750 print("This happened for browser $browserId"); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 | 829 |
| 795 Function testDoneCallBack; | 830 Function testDoneCallBack; |
| 796 Function nextTestCallBack; | 831 Function nextTestCallBack; |
| 797 | 832 |
| 798 BrowserTestingServer(this.local_ip, this.useIframe); | 833 BrowserTestingServer(this.local_ip, this.useIframe); |
| 799 | 834 |
| 800 Future start() { | 835 Future start() { |
| 801 return HttpServer.bind(local_ip, 0).then((createdServer) { | 836 return HttpServer.bind(local_ip, 0).then((createdServer) { |
| 802 httpServer = createdServer; | 837 httpServer = createdServer; |
| 803 void handler(HttpRequest request) { | 838 void handler(HttpRequest request) { |
| 804 DebugLogger.info("Handling request to: ${request.uri.path}"); | 839 // Don't allow caching of resources from the browser controller, i.e., |
| 840 // we don't want the browser to cache the result of getNextTest. | |
| 841 request.response.headers.set("Cache-Control", | |
| 842 "no-cache, no-store, must-revalidate"); | |
| 805 if (request.uri.path.startsWith(reportPath)) { | 843 if (request.uri.path.startsWith(reportPath)) { |
| 806 var browserId = request.uri.path.substring(reportPath.length + 1); | 844 var browserId = request.uri.path.substring(reportPath.length + 1); |
| 807 var testId = | 845 var testId = |
| 808 int.parse(request.uri.queryParameters["id"].split("=")[1]); | 846 int.parse(request.uri.queryParameters["id"].split("=")[1]); |
| 809 handleReport(request, browserId, testId); | 847 handleReport(request, browserId, testId); |
| 810 // handleReport will asynchroniously fetch the data and will handle | 848 // handleReport will asynchroniously fetch the data and will handle |
| 811 // the closing of the streams. | 849 // the closing of the streams. |
| 812 return; | 850 return; |
| 813 } | 851 } |
| 814 var textResponse = ""; | 852 var textResponse = ""; |
| 815 if (request.uri.path.startsWith(driverPath)) { | 853 if (request.uri.path.startsWith(driverPath)) { |
| 816 var browserId = request.uri.path.substring(driverPath.length + 1); | 854 var browserId = request.uri.path.substring(driverPath.length + 1); |
| 817 textResponse = getDriverPage(browserId); | 855 textResponse = getDriverPage(browserId); |
| 818 } else if (request.uri.path.startsWith(nextTestPath)) { | 856 } else if (request.uri.path.startsWith(nextTestPath)) { |
| 819 var browserId = request.uri.path.substring(nextTestPath.length + 1); | 857 var browserId = request.uri.path.substring(nextTestPath.length + 1); |
| 820 textResponse = getNextTest(browserId); | 858 textResponse = getNextTest(browserId); |
| 821 } else { | 859 } else { |
| 822 DebugLogger.info("Handling non standard request to: " | 860 // /favicon.ico requests |
| 823 "${request.uri.path}"); | |
| 824 } | 861 } |
| 825 request.response.write(textResponse); | 862 request.response.write(textResponse); |
| 826 request.listen((_) {}, onDone: request.response.close); | 863 request.listen((_) {}, onDone: request.response.close); |
| 827 request.response.done.then((_) { | 864 request.response.done.catchError((error) { |
| 828 DebugLogger.info("Done handling request to: ${request.uri.path}"); | |
| 829 }).catchError((error) { | |
| 830 if (!underTermination) { | 865 if (!underTermination) { |
| 831 print("URI ${request.uri}"); | 866 print("URI ${request.uri}"); |
| 832 print("Textresponse $textResponse"); | 867 print("Textresponse $textResponse"); |
| 833 throw "Error returning content to browser: $error"; | 868 throw "Error returning content to browser: $error"; |
| 834 } | 869 } |
| 835 }); | 870 }); |
| 836 } | 871 } |
| 837 void errorHandler(e) { | 872 void errorHandler(e) { |
| 838 if (!underTermination) print("Error occured in httpserver: $e"); | 873 if (!underTermination) print("Error occured in httpserver: $e"); |
| 839 }; | 874 }; |
| 840 | 875 |
| 841 httpServer.listen(handler, onError: errorHandler); | 876 httpServer.listen(handler, onError: errorHandler); |
| 842 | 877 |
| 843 // Set up the error reporting server that enables us to send back | 878 // Set up the error reporting server that enables us to send back |
| 844 // errors from the browser. | 879 // errors from the browser. |
| 845 return HttpServer.bind(local_ip, 0).then((createdReportServer) { | 880 return HttpServer.bind(local_ip, 0).then((createdReportServer) { |
| 846 errorReportingServer = createdReportServer; | 881 errorReportingServer = createdReportServer; |
| 847 void errorReportingHandler(HttpRequest request) { | 882 void errorReportingHandler(HttpRequest request) { |
| 848 StringBuffer buffer = new StringBuffer(); | 883 StringBuffer buffer = new StringBuffer(); |
| 849 request.transform(new StringDecoder()).listen((data) { | 884 request.transform(new StringDecoder()).listen((data) { |
| 850 buffer.write(data); | 885 buffer.write(data); |
| 851 }, onDone: () { | 886 }, onDone: () { |
| 852 String back = buffer.toString(); | 887 String back = buffer.toString(); |
| 853 request.response.headers.set("Access-Control-Allow-Origin", "*"); | 888 request.response.headers.set("Access-Control-Allow-Origin", "*"); |
| 854 | |
| 855 request.response.done.catchError((error) { | 889 request.response.done.catchError((error) { |
| 856 DebugLogger.error("Error getting error from browser" | 890 DebugLogger.error("Error getting error from browser" |
| 857 "on uri ${request.uri.path}: $error"); | 891 "on uri ${request.uri.path}: $error"); |
| 858 }); | 892 }); |
| 859 request.response.close(); | 893 request.response.close(); |
| 860 DebugLogger.error("Error from browser on : " | 894 DebugLogger.error("Error from browser on : " |
| 861 "${request.uri.path}, data: $back"); | 895 "${request.uri.path}, data: $back"); |
| 862 }, onError: (error) { print(error); }); | 896 }, onError: (error) { print(error); }); |
| 863 } | 897 } |
| 864 errorReportingServer.listen(errorReportingHandler, | 898 errorReportingServer.listen(errorReportingHandler, |
| 865 onError: errorHandler); | 899 onError: errorHandler); |
| 866 return true; | 900 return true; |
| 867 }); | 901 }); |
| 868 }); | 902 }); |
| 869 } | 903 } |
| 870 | 904 |
| 871 void handleReport(HttpRequest request, String browserId, var testId) { | 905 void handleReport(HttpRequest request, String browserId, var testId) { |
| 872 StringBuffer buffer = new StringBuffer(); | 906 StringBuffer buffer = new StringBuffer(); |
| 873 request.transform(new StringDecoder()).listen((data) { | 907 request.transform(new StringDecoder()).listen((data) { |
| 874 buffer.write(data); | 908 buffer.write(data); |
| 875 }, onDone: () { | 909 }, onDone: () { |
| 876 String back = buffer.toString(); | 910 String back = buffer.toString(); |
| 877 request.response.close(); | 911 request.response.close(); |
| 878 testDoneCallBack(browserId, back, testId); | 912 testDoneCallBack(browserId, back, testId); |
| 879 DebugLogger.info("Done handling request to: ${request.uri.path}"); | |
| 880 }, onError: (error) { print(error); }); | 913 }, onError: (error) { print(error); }); |
| 881 } | 914 } |
| 882 | 915 |
| 883 String getNextTest(String browserId) { | 916 String getNextTest(String browserId) { |
| 884 var nextTest = nextTestCallBack(browserId); | 917 var nextTest = nextTestCallBack(browserId); |
| 885 if (underTermination) { | 918 if (underTermination) { |
| 886 // Browsers will be killed shortly, send them a terminate signal so | 919 // Browsers will be killed shortly, send them a terminate signal so |
| 887 // that they stop pulling. | 920 // that they stop pulling. |
| 888 return terminateSignal; | 921 return terminateSignal; |
| 889 } else if (nextTest == null) { | 922 } else if (nextTest == null) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 911 String driverContent = """ | 944 String driverContent = """ |
| 912 <!DOCTYPE html><html> | 945 <!DOCTYPE html><html> |
| 913 <head> | 946 <head> |
| 914 <title>Driving page</title> | 947 <title>Driving page</title> |
| 915 <script type='text/javascript'> | 948 <script type='text/javascript'> |
| 916 | 949 |
| 917 function startTesting() { | 950 function startTesting() { |
| 918 var number_of_tests = 0; | 951 var number_of_tests = 0; |
| 919 var current_id; | 952 var current_id; |
| 920 var last_reported_id; | 953 var last_reported_id; |
| 954 // Describes a state where we are currently fetching the next test | |
| 955 // from the server. We use this to never double request tasks. | |
| 956 var instantiating_next_test = false; | |
|
kustermann
2013/08/14 11:06:16
I'd rename this to 'var old_test_finished', set it
| |
| 921 var testing_window; | 957 var testing_window; |
| 922 // We use this to determine if we did actually get back a start event | |
| 923 // from the test we just loaded. | |
| 924 var did_start = false; | |
| 925 | 958 |
| 926 var embedded_iframe = document.getElementById('embedded_iframe'); | 959 var embedded_iframe = document.getElementById('embedded_iframe'); |
| 927 var use_iframe = ${useIframe}; | 960 var use_iframe = ${useIframe}; |
| 928 var start = new Date(); | 961 var start = new Date(); |
| 929 | 962 |
| 930 function newTaskHandler() { | 963 function newTaskHandler() { |
| 931 if (this.readyState == this.DONE) { | 964 if (this.readyState == this.DONE) { |
| 932 if (this.status == 200) { | 965 if (this.status == 200) { |
| 933 if (this.responseText == '$waitSignal') { | 966 if (this.responseText == '$waitSignal') { |
| 934 setTimeout(getNextTask, 500); | 967 setTimeout(getNextTask, 500); |
| 935 } else if (this.responseText == '$terminateSignal') { | 968 } else if (this.responseText == '$terminateSignal') { |
| 936 // Don't do anything, we will be killed shortly. | 969 // Don't do anything, we will be killed shortly. |
| 937 } else { | 970 } else { |
| 938 var elapsed = new Date() - start; | 971 var elapsed = new Date() - start; |
| 939 // TODO(ricow): Do something more clever here. | |
| 940 if (nextTask != undefined) alert('This is really bad'); | |
| 941 // The task is send to us as: | 972 // The task is send to us as: |
| 942 // URL#ID | 973 // URL#ID |
| 943 var split = this.responseText.split('#'); | 974 var split = this.responseText.split('#'); |
| 944 var nextTask = split[0]; | 975 var nextTask = split[0]; |
| 945 current_id = split[1]; | 976 current_id = split[1]; |
| 946 reportError('Done getting task : ' + elapsed); | |
| 947 did_start = false; | |
| 948 run(nextTask); | 977 run(nextTask); |
| 949 } | 978 } |
| 950 } else { | 979 } else { |
| 951 reportError('Could not contact the server and get a new task'); | 980 reportError('Could not contact the server and get a new task'); |
| 952 } | 981 } |
| 953 } | 982 } |
| 954 } | 983 } |
| 955 | 984 |
| 956 function getNextTask() { | 985 function getNextTask() { |
| 957 var elapsed = new Date() - start; | 986 // Until we have the next task we set the current_id to a specific |
| 958 reportError('Getting task at: ' + elapsed); | 987 // negative value. |
| 988 instantiating_next_test = true; | |
| 959 var client = new XMLHttpRequest(); | 989 var client = new XMLHttpRequest(); |
| 960 client.onreadystatechange = newTaskHandler; | 990 client.onreadystatechange = newTaskHandler; |
| 961 client.open('GET', '$nextTestPath/$browserId'); | 991 client.open('GET', '$nextTestPath/$browserId'); |
| 962 client.send(); | 992 client.send(); |
| 963 } | 993 } |
| 964 | 994 |
| 965 function run(url) { | 995 function run(url) { |
| 966 number_of_tests++; | 996 number_of_tests++; |
| 967 document.getElementById('number').innerHTML = number_of_tests; | 997 document.getElementById('number').innerHTML = number_of_tests; |
| 968 if (use_iframe) { | 998 if (use_iframe) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 994 } | 1024 } |
| 995 client.onreadystatechange = handleReady; | 1025 client.onreadystatechange = handleReady; |
| 996 client.open('POST', '$errorReportingUrl?test=1'); | 1026 client.open('POST', '$errorReportingUrl?test=1'); |
| 997 client.setRequestHeader('Content-type', | 1027 client.setRequestHeader('Content-type', |
| 998 'application/x-www-form-urlencoded'); | 1028 'application/x-www-form-urlencoded'); |
| 999 client.send(msg); | 1029 client.send(msg); |
| 1000 } | 1030 } |
| 1001 | 1031 |
| 1002 function reportMessage(msg) { | 1032 function reportMessage(msg) { |
| 1003 if (msg == 'STARTING') { | 1033 if (msg == 'STARTING') { |
| 1004 did_start = true; | 1034 instantiating_next_test = false; |
| 1005 return; | 1035 return; |
| 1006 } | 1036 } |
| 1007 var client = new XMLHttpRequest(); | 1037 |
| 1038 // We define this here to capture the value of the posting id. | |
| 1039 // That way we can make sure to never ask for a new task if the | |
| 1040 // reported id is not the currently running id. If we just use | |
| 1041 // current_id and last_reported_id, current_id may have been changed | |
| 1042 // by the next test. | |
| 1043 var posting_id = | |
| 1044 instantiating_next_test ? last_reported_id : current_id; | |
|
kustermann
2013/08/14 11:06:16
I'd add a variable here (so it's captured by the c
ricow1
2013/08/14 11:29:48
Changed it _again_ :-)
| |
| 1008 function handleReady() { | 1045 function handleReady() { |
| 1009 if (this.readyState == this.DONE) { | 1046 if (this.readyState == this.DONE) { |
| 1010 if (this.status == 200) { | 1047 if (this.status == 200) { |
| 1011 if (last_reported_id != current_id && did_start) { | 1048 if (posting_id == current_id && !instantiating_next_test) { |
| 1012 var elapsed = new Date() - start; | 1049 last_reported_id = current_id; |
| 1013 reportError('Done sending results at: ' + elapsed); | |
| 1014 getNextTask(); | 1050 getNextTask(); |
| 1015 last_reported_id = current_id; | |
| 1016 } | 1051 } |
| 1017 } else { | 1052 } else { |
| 1018 reportError('Error sending result to server'); | 1053 reportError('Error sending result to server'); |
| 1019 } | 1054 } |
| 1020 } | 1055 } |
| 1021 } | 1056 } |
| 1057 var client = new XMLHttpRequest(); | |
| 1022 client.onreadystatechange = handleReady; | 1058 client.onreadystatechange = handleReady; |
| 1023 // If did_start is false it means that we did actually set the url on | |
| 1024 // the testing_window, but this is a report left in the event loop or | |
| 1025 // a callback because the page did not load yet. | |
| 1026 // In both cases this is a double report from the last test. | |
| 1027 var posting_id = did_start ? current_id : last_reported_id; | |
| 1028 client.open('POST', '$reportPath/${browserId}?id=' + posting_id); | 1059 client.open('POST', '$reportPath/${browserId}?id=' + posting_id); |
| 1029 client.setRequestHeader('Content-type', | 1060 client.setRequestHeader('Content-type', |
| 1030 'application/x-www-form-urlencoded'); | 1061 'application/x-www-form-urlencoded'); |
| 1031 client.send(msg); | 1062 client.send(msg); |
| 1032 var elapsed = new Date() - start; | |
| 1033 reportError('Sending results at: ' + elapsed); | |
| 1034 } | 1063 } |
| 1035 | 1064 |
| 1036 function messageHandler(e) { | 1065 function messageHandler(e) { |
| 1037 var msg = e.data; | 1066 var msg = e.data; |
| 1038 if (typeof msg != 'string') return; | 1067 if (typeof msg != 'string') return; |
| 1039 reportMessage(msg); | 1068 reportMessage(msg); |
| 1040 } | 1069 } |
| 1041 | 1070 |
| 1042 window.addEventListener('message', messageHandler, false); | 1071 window.addEventListener('message', messageHandler, false); |
| 1043 waitForDone = false; | 1072 waitForDone = false; |
| 1044 | 1073 |
| 1045 getNextTask(); | 1074 getNextTask(); |
| 1046 } | 1075 } |
| 1047 | 1076 |
| 1048 </script> | 1077 </script> |
| 1049 </head> | 1078 </head> |
| 1050 <body onload="startTesting()"> | 1079 <body onload="startTesting()"> |
| 1051 Dart test driver, number of tests: <div id="number"></div> | 1080 Dart test driver, number of tests: <div id="number"></div> |
| 1052 <iframe id="embedded_iframe"></iframe> | 1081 <iframe id="embedded_iframe"></iframe> |
| 1053 </body> | 1082 </body> |
| 1054 </html> | 1083 </html> |
| 1055 """; | 1084 """; |
| 1056 return driverContent; | 1085 return driverContent; |
| 1057 } | 1086 } |
| 1058 } | 1087 } |
| OLD | NEW |