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

Side by Side Diff: tools/testing/dart/browser_controller.dart

Issue 22420002: Add support for ie in the browser controller (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 months 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 | Annotate | Revision Log
« no previous file with comments | « tools/test.dart ('k') | tools/testing/dart/test_runner.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) 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
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
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(exitCode == 0);
kustermann 2013/08/13 07:44:03 Since we always kill the browser (sooner or later)
ricow1 2013/08/14 08:13:51 That is true, change and added error handling
148 }); 150 });
149 }); 151 });
150 return true; 152 return true;
151 }).catchError((error) { 153 }).catchError((error) {
152 _logEvent("Running $command $arguments failed with $error"); 154 _logEvent("Running $command $arguments failed with $error");
153 return false; 155 return false;
154 }); 156 });
155 } 157 }
156 158
157 /** 159 /**
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 }); 342 });
341 }).catchError((e) { 343 }).catchError((e) {
342 _logEvent("Running $binary --version failed with $e"); 344 _logEvent("Running $binary --version failed with $e");
343 return false; 345 return false;
344 }); 346 });
345 } 347 }
346 348
347 String toString() => "Chrome"; 349 String toString() => "Chrome";
348 } 350 }
349 351
352 class IE extends Browser {
353
354 static const String binary =
355 "c:\\Program Files\\Internet Explorer\\iexplore.exe";
kustermann 2013/08/13 07:44:03 Is this the same path for IE9 and IE10?
ricow1 2013/08/14 08:13:51 Yes this is the standard location, but as I said p
356
357 Future<String> getVersion() {
358 var args = ["query",
359 "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Internet Explorer",
360 "/v",
361 "version"];
362 return Process.run("reg", args).then((result) {
363 if (result.exitCode == 0) {
364 // The string we get back looks like this:
365 // HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer
366 // version REG_SZ 9.0.8112.16421
367 var findString = "REG_SZ";
368 var index = result.stdout.indexOf(findString) + findString.length;
369 if (index > 0) {
370 return result.stdout.substring(index).trim();
kustermann 2013/08/13 07:44:03 I indexOf(findString) is -1 and you add 6 it will
ricow1 2013/08/14 08:13:51 Changed to not add the length until inside the if
371 }
372 }
373 return "Could not get the version of internet explorer";
374 });
375 }
376
377
378 Future<bool> start(String url) {
379 _logEvent("Starting ie browser on: $url");
380 // Get the version and log that.
kustermann 2013/08/13 07:44:03 That comment is not really necessary, the code is
ricow1 2013/08/14 08:13:51 Done.
381 return getVersion().then((version) {
382 _logEvent("Got version: $version");
383 return startBrowser(binary, [url]);
384 });
385 }
386 String toString() => "IE";
387 }
388
389
350 class AndroidChrome extends Browser { 390 class AndroidChrome extends Browser {
351 static const String viewAction = 'android.intent.action.VIEW'; 391 static const String viewAction = 'android.intent.action.VIEW';
352 static const String mainAction = 'android.intent.action.MAIN'; 392 static const String mainAction = 'android.intent.action.MAIN';
353 static const String chromePackage = 'com.android.chrome'; 393 static const String chromePackage = 'com.android.chrome';
354 static const String browserPackage = 'com.android.browser'; 394 static const String browserPackage = 'com.android.browser';
355 static const String firefoxPackage = 'org.mozilla.firefox'; 395 static const String firefoxPackage = 'org.mozilla.firefox';
356 static const String turnScreenOnPackage = 'com.google.dart.turnscreenon'; 396 static const String turnScreenOnPackage = 'com.google.dart.turnscreenon';
357 397
358 AndroidEmulator _emulator; 398 AndroidEmulator _emulator;
359 AdbDevice _adbDevice; 399 AdbDevice _adbDevice;
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 } 642 }
603 browsersCompleter.complete(browsers); 643 browsersCompleter.complete(browsers);
604 } 644 }
605 return browsersCompleter.future; 645 return browsersCompleter.future;
606 } 646 }
607 647
608 var timedOut = []; 648 var timedOut = [];
609 649
610 void handleResults(String browserId, String output, int testId) { 650 void handleResults(String browserId, String output, int testId) {
611 var status = browserStatus[browserId]; 651 var status = browserStatus[browserId];
612 DebugLogger.info("Handling result for browser ${browserId}");
613 if (testCache.containsKey(testId)) { 652 if (testCache.containsKey(testId)) {
614 doubleReportingTests.add(testId); 653 doubleReportingTests.add(testId);
615 return; 654 return;
616 } 655 }
617 656
618 if (status.timeout) { 657 if (status.timeout) {
619 // We don't do anything, this browser is currently being killed and 658 // We don't do anything, this browser is currently being killed and
620 // replaced. 659 // replaced.
621 } else if (status.currentTest != null) { 660 } else if (status.currentTest != null) {
622 status.currentTest.timeoutTimer.cancel(); 661 status.currentTest.timeoutTimer.cancel();
623 status.currentTest.stopwatch.stop(); 662 status.currentTest.stopwatch.stop();
624 663
625 if (status.currentTest.id != testId) { 664 if (status.currentTest.id != testId) {
626 print("Expected test id ${status.currentTest.id} for" 665 print("Expected test id ${status.currentTest.id} for"
627 "${status.currentTest.url}"); 666 "${status.currentTest.url}");
628 print("Got test id ${testId}"); 667 print("Got test id ${testId}");
629 print("Last test id was ${status.lastTest.id} for " 668 print("Last test id was ${status.lastTest.id} for "
630 "${status.currentTest.url}"); 669 "${status.currentTest.url}");
631 throw("This should never happen, wrong test id"); 670 throw("This should never happen, wrong test id");
632 } 671 }
633 testCache[testId] = status.currentTest.url; 672 testCache[testId] = status.currentTest.url;
634 DebugLogger.info("Size of output for test $testId : ${output.length}");
635 Stopwatch watch = new Stopwatch()..start(); 673 Stopwatch watch = new Stopwatch()..start();
636 status.currentTest.doneCallback(output, 674 status.currentTest.doneCallback(output,
637 status.currentTest.stopwatch.elapsed); 675 status.currentTest.stopwatch.elapsed);
638 watch.stop(); 676 watch.stop();
639 DebugLogger.info("Handling of test $testId took : ${watch.elapsed}");
640 status.lastTest = status.currentTest; 677 status.lastTest = status.currentTest;
641 status.currentTest = null; 678 status.currentTest = null;
642 } else { 679 } else {
643 print("\nThis is bad, should never happen, handleResult no test"); 680 print("\nThis is bad, should never happen, handleResult no test");
644 print("URL: ${status.lastTest.url}"); 681 print("URL: ${status.lastTest.url}");
645 print(output); 682 print(output);
646 terminate().then((_) { 683 terminate().then((_) {
647 exit(1); 684 exit(1);
648 }); 685 });
649 } 686 }
650 } 687 }
651 688
652 void handleTimeout(BrowserTestingStatus status) { 689 void handleTimeout(BrowserTestingStatus status) {
653 // We simply kill the browser and starts up a new one! 690 // 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. 691 // 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; 692 status.timeout = true;
657 timedOut.add(status.currentTest.url); 693 timedOut.add(status.currentTest.url);
658 var id = status.browser.id; 694 var id = status.browser.id;
659 status.browser.close().then((_) { 695 status.browser.close().then((_) {
660 // We don't want to start a new browser if we are terminating. 696 // We don't want to start a new browser if we are terminating.
661 if (underTermination) return; 697 if (underTermination) return;
662 var browser; 698 var browser;
663 var new_id = id; 699 var new_id = id;
664 if (browserName == 'chromeOnAndroid') { 700 if (browserName == 'chromeOnAndroid') {
665 browser = new AndroidChrome(adbDeviceMapping[id]); 701 browser = new AndroidChrome(adbDeviceMapping[id]);
(...skipping 28 matching lines...) Expand all
694 status.currentTest.stopwatch.stop(); 730 status.currentTest.stopwatch.stop();
695 status.currentTest.doneCallback("TIMEOUT", 731 status.currentTest.doneCallback("TIMEOUT",
696 status.currentTest.stopwatch.elapsed); 732 status.currentTest.stopwatch.elapsed);
697 status.currentTest = null; 733 status.currentTest = null;
698 } 734 }
699 735
700 BrowserTest getNextTest(String browserId) { 736 BrowserTest getNextTest(String browserId) {
701 if (testQueue.isEmpty) return null; 737 if (testQueue.isEmpty) return null;
702 var status = browserStatus[browserId]; 738 var status = browserStatus[browserId];
703 if (status == null) return null; 739 if (status == null) return null;
704 DebugLogger.info("Handling getNext for browser "
705 "${browserId} timeout status: ${status.timeout}");
706 740
707 // We are currently terminating this browser, don't start a new test. 741 // We are currently terminating this browser, don't start a new test.
708 if (status.timeout) return null; 742 if (status.timeout) return null;
709 BrowserTest test = testQueue.removeLast(); 743 BrowserTest test = testQueue.removeLast();
710 if (status.currentTest == null) { 744 if (status.currentTest == null) {
711 status.currentTest = test; 745 status.currentTest = test;
712 } else { 746 } else {
713 // TODO(ricow): Handle this better. 747 // TODO(ricow): Handle this better.
714 print("This is bad, should never happen, getNextTest all full"); 748 print("This is bad, should never happen, getNextTest all full");
715 print("This happened for browser $browserId"); 749 print("This happened for browser $browserId");
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 828
795 Function testDoneCallBack; 829 Function testDoneCallBack;
796 Function nextTestCallBack; 830 Function nextTestCallBack;
797 831
798 BrowserTestingServer(this.local_ip, this.useIframe); 832 BrowserTestingServer(this.local_ip, this.useIframe);
799 833
800 Future start() { 834 Future start() {
801 return HttpServer.bind(local_ip, 0).then((createdServer) { 835 return HttpServer.bind(local_ip, 0).then((createdServer) {
802 httpServer = createdServer; 836 httpServer = createdServer;
803 void handler(HttpRequest request) { 837 void handler(HttpRequest request) {
804 DebugLogger.info("Handling request to: ${request.uri.path}"); 838 // Don't allow caching of resources from the browser controller, i.e.,
839 // we don't want the browser to cache the result of getNextTest.
840 request.response.headers.set("Cache-Control",
841 "no-cache, no-store, must-revalidate");
805 if (request.uri.path.startsWith(reportPath)) { 842 if (request.uri.path.startsWith(reportPath)) {
806 var browserId = request.uri.path.substring(reportPath.length + 1); 843 var browserId = request.uri.path.substring(reportPath.length + 1);
807 var testId = 844 var testId =
808 int.parse(request.uri.queryParameters["id"].split("=")[1]); 845 int.parse(request.uri.queryParameters["id"].split("=")[1]);
809 handleReport(request, browserId, testId); 846 handleReport(request, browserId, testId);
810 // handleReport will asynchroniously fetch the data and will handle 847 // handleReport will asynchroniously fetch the data and will handle
811 // the closing of the streams. 848 // the closing of the streams.
812 return; 849 return;
813 } 850 }
814 var textResponse = ""; 851 var textResponse = "";
815 if (request.uri.path.startsWith(driverPath)) { 852 if (request.uri.path.startsWith(driverPath)) {
816 var browserId = request.uri.path.substring(driverPath.length + 1); 853 var browserId = request.uri.path.substring(driverPath.length + 1);
817 textResponse = getDriverPage(browserId); 854 textResponse = getDriverPage(browserId);
818 } else if (request.uri.path.startsWith(nextTestPath)) { 855 } else if (request.uri.path.startsWith(nextTestPath)) {
819 var browserId = request.uri.path.substring(nextTestPath.length + 1); 856 var browserId = request.uri.path.substring(nextTestPath.length + 1);
820 textResponse = getNextTest(browserId); 857 textResponse = getNextTest(browserId);
821 } else { 858 } else {
822 DebugLogger.info("Handling non standard request to: " 859 // /favicon.ico requests
823 "${request.uri.path}");
824 } 860 }
825 request.response.write(textResponse); 861 request.response.write(textResponse);
826 request.listen((_) {}, onDone: request.response.close); 862 request.listen((_) {}, onDone: request.response.close);
827 request.response.done.then((_) { 863 request.response.done.catchError((error) {
828 DebugLogger.info("Done handling request to: ${request.uri.path}");
829 }).catchError((error) {
830 if (!underTermination) { 864 if (!underTermination) {
831 print("URI ${request.uri}"); 865 print("URI ${request.uri}");
832 print("Textresponse $textResponse"); 866 print("Textresponse $textResponse");
833 throw "Error returning content to browser: $error"; 867 throw "Error returning content to browser: $error";
834 } 868 }
835 }); 869 });
836 } 870 }
837 void errorHandler(e) { 871 void errorHandler(e) {
838 if (!underTermination) print("Error occured in httpserver: $e"); 872 if (!underTermination) print("Error occured in httpserver: $e");
839 }; 873 };
840 874
841 httpServer.listen(handler, onError: errorHandler); 875 httpServer.listen(handler, onError: errorHandler);
842 876
843 // Set up the error reporting server that enables us to send back 877 // Set up the error reporting server that enables us to send back
844 // errors from the browser. 878 // errors from the browser.
845 return HttpServer.bind(local_ip, 0).then((createdReportServer) { 879 return HttpServer.bind(local_ip, 0).then((createdReportServer) {
846 errorReportingServer = createdReportServer; 880 errorReportingServer = createdReportServer;
847 void errorReportingHandler(HttpRequest request) { 881 void errorReportingHandler(HttpRequest request) {
848 StringBuffer buffer = new StringBuffer(); 882 StringBuffer buffer = new StringBuffer();
849 request.transform(new StringDecoder()).listen((data) { 883 request.transform(new StringDecoder()).listen((data) {
850 buffer.write(data); 884 buffer.write(data);
851 }, onDone: () { 885 }, onDone: () {
852 String back = buffer.toString(); 886 String back = buffer.toString();
853 request.response.headers.set("Access-Control-Allow-Origin", "*"); 887 request.response.headers.set("Access-Control-Allow-Origin", "*");
888 request.response.headers.set(
889 "Cache-Control",
890 "no-cache, no-store, must-revalidate");
kustermann 2013/08/13 07:44:03 Why do you have this. We never GET anything from t
ricow1 2013/08/14 08:13:51 Removed here
854 891
855 request.response.done.catchError((error) { 892 request.response.done.catchError((error) {
856 DebugLogger.error("Error getting error from browser" 893 DebugLogger.error("Error getting error from browser"
857 "on uri ${request.uri.path}: $error"); 894 "on uri ${request.uri.path}: $error");
858 }); 895 });
859 request.response.close(); 896 request.response.close();
860 DebugLogger.error("Error from browser on : " 897 DebugLogger.error("Error from browser on : "
861 "${request.uri.path}, data: $back"); 898 "${request.uri.path}, data: $back");
862 }, onError: (error) { print(error); }); 899 }, onError: (error) { print(error); });
863 } 900 }
864 errorReportingServer.listen(errorReportingHandler, 901 errorReportingServer.listen(errorReportingHandler,
865 onError: errorHandler); 902 onError: errorHandler);
866 return true; 903 return true;
867 }); 904 });
868 }); 905 });
869 } 906 }
870 907
871 void handleReport(HttpRequest request, String browserId, var testId) { 908 void handleReport(HttpRequest request, String browserId, var testId) {
872 StringBuffer buffer = new StringBuffer(); 909 StringBuffer buffer = new StringBuffer();
873 request.transform(new StringDecoder()).listen((data) { 910 request.transform(new StringDecoder()).listen((data) {
874 buffer.write(data); 911 buffer.write(data);
875 }, onDone: () { 912 }, onDone: () {
876 String back = buffer.toString(); 913 String back = buffer.toString();
877 request.response.close(); 914 request.response.close();
878 testDoneCallBack(browserId, back, testId); 915 testDoneCallBack(browserId, back, testId);
879 DebugLogger.info("Done handling request to: ${request.uri.path}");
880 }, onError: (error) { print(error); }); 916 }, onError: (error) { print(error); });
881 } 917 }
882 918
883 String getNextTest(String browserId) { 919 String getNextTest(String browserId) {
884 var nextTest = nextTestCallBack(browserId); 920 var nextTest = nextTestCallBack(browserId);
885 if (underTermination) { 921 if (underTermination) {
886 // Browsers will be killed shortly, send them a terminate signal so 922 // Browsers will be killed shortly, send them a terminate signal so
887 // that they stop pulling. 923 // that they stop pulling.
888 return terminateSignal; 924 return terminateSignal;
889 } else if (nextTest == null) { 925 } else if (nextTest == null) {
(...skipping 20 matching lines...) Expand all
910 "http://$local_ip:${errorReportingServer.port}/$browserId"; 946 "http://$local_ip:${errorReportingServer.port}/$browserId";
911 String driverContent = """ 947 String driverContent = """
912 <!DOCTYPE html><html> 948 <!DOCTYPE html><html>
913 <head> 949 <head>
914 <title>Driving page</title> 950 <title>Driving page</title>
915 <script type='text/javascript'> 951 <script type='text/javascript'>
916 952
917 function startTesting() { 953 function startTesting() {
918 var number_of_tests = 0; 954 var number_of_tests = 0;
919 var current_id; 955 var current_id;
956 // Describes a state where we are currently fetching the next test
957 // from the server. We use this to never double request tasks.
958 var FETCHING_NEXT_TEST = -1;
920 var last_reported_id; 959 var last_reported_id;
921 var testing_window; 960 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 961
926 var embedded_iframe = document.getElementById('embedded_iframe'); 962 var embedded_iframe = document.getElementById('embedded_iframe');
927 var use_iframe = ${useIframe}; 963 var use_iframe = ${useIframe};
928 var start = new Date(); 964 var start = new Date();
929 965
930 function newTaskHandler() { 966 function newTaskHandler() {
931 if (this.readyState == this.DONE) { 967 if (this.readyState == this.DONE) {
932 if (this.status == 200) { 968 if (this.status == 200) {
933 if (this.responseText == '$waitSignal') { 969 if (this.responseText == '$waitSignal') {
934 setTimeout(getNextTask, 500); 970 setTimeout(getNextTask, 500);
935 } else if (this.responseText == '$terminateSignal') { 971 } else if (this.responseText == '$terminateSignal') {
936 // Don't do anything, we will be killed shortly. 972 // Don't do anything, we will be killed shortly.
937 } else { 973 } else {
938 var elapsed = new Date() - start; 974 var elapsed = new Date() - start;
939 // TODO(ricow): Do something more clever here. 975 // TODO(ricow): Do something more clever here.
940 if (nextTask != undefined) alert('This is really bad'); 976 if (nextTask != undefined) alert('This is really bad');
kustermann 2013/08/13 07:44:03 This can be removed, right? The 'nextTask' variabl
ricow1 2013/08/14 08:13:51 Yes that is a left over artifact, removed
941 // The task is send to us as: 977 // The task is send to us as:
942 // URL#ID 978 // URL#ID
943 var split = this.responseText.split('#'); 979 var split = this.responseText.split('#');
kustermann 2013/08/13 07:44:03 We should probably reverse the entries. The URL co
ricow1 2013/08/14 08:13:51 I will not do that in this cl
944 var nextTask = split[0]; 980 var nextTask = split[0];
945 current_id = split[1]; 981 current_id = split[1];
kustermann 2013/08/13 07:44:03 I think this is not right. After setting "current_
ricow1 2013/08/14 08:13:51 Changed
ricow1 2013/08/14 08:13:51 Changed
946 reportError('Done getting task : ' + elapsed);
947 did_start = false;
948 run(nextTask); 982 run(nextTask);
949 } 983 }
950 } else { 984 } else {
951 reportError('Could not contact the server and get a new task'); 985 reportError('Could not contact the server and get a new task');
952 } 986 }
953 } 987 }
954 } 988 }
955 989
956 function getNextTask() { 990 function getNextTask() {
957 var elapsed = new Date() - start; 991 // Until we have the next task we set the current_id to a specific
958 reportError('Getting task at: ' + elapsed); 992 // negative value.
993 current_id = FETCHING_NEXT_TEST;
959 var client = new XMLHttpRequest(); 994 var client = new XMLHttpRequest();
960 client.onreadystatechange = newTaskHandler; 995 client.onreadystatechange = newTaskHandler;
961 client.open('GET', '$nextTestPath/$browserId'); 996 client.open('GET', '$nextTestPath/$browserId');
962 client.send(); 997 client.send();
963 } 998 }
964 999
965 function run(url) { 1000 function run(url) {
966 number_of_tests++; 1001 number_of_tests++;
967 document.getElementById('number').innerHTML = number_of_tests; 1002 document.getElementById('number').innerHTML = number_of_tests;
968 if (use_iframe) { 1003 if (use_iframe) {
(...skipping 24 matching lines...) Expand all
993 } 1028 }
994 } 1029 }
995 client.onreadystatechange = handleReady; 1030 client.onreadystatechange = handleReady;
996 client.open('POST', '$errorReportingUrl?test=1'); 1031 client.open('POST', '$errorReportingUrl?test=1');
997 client.setRequestHeader('Content-type', 1032 client.setRequestHeader('Content-type',
998 'application/x-www-form-urlencoded'); 1033 'application/x-www-form-urlencoded');
999 client.send(msg); 1034 client.send(msg);
1000 } 1035 }
1001 1036
1002 function reportMessage(msg) { 1037 function reportMessage(msg) {
1003 if (msg == 'STARTING') { 1038 // We define this here to capture the value of the posting id.
1004 did_start = true; 1039 // That way we can make sure to never ask for a new task if the
1005 return; 1040 // reported id is not the currently running id. If we just use
1006 } 1041 // current_id and last_reported_id, current_id may have been changed
1007 var client = new XMLHttpRequest(); 1042 // by the next test.
1043 var posting_id =
1044 current_id == FETCHING_NEXT_TEST ? last_reported_id : current_id;
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) {
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 }
OLDNEW
« no previous file with comments | « tools/test.dart ('k') | tools/testing/dart/test_runner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698