| 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 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 } | 623 } |
| 624 | 624 |
| 625 String toString() => "Firefox"; | 625 String toString() => "Firefox"; |
| 626 } | 626 } |
| 627 | 627 |
| 628 | 628 |
| 629 /** | 629 /** |
| 630 * Describes the current state of a browser used for testing. | 630 * Describes the current state of a browser used for testing. |
| 631 */ | 631 */ |
| 632 class BrowserTestingStatus { | 632 class BrowserTestingStatus { |
| 633 // TODO(ricow): Add prefetching to the browsers. We spend a lot of time waiting | |
| 634 // for the next test. Handling timeouts is the hard part of this! | |
| 635 | |
| 636 Browser browser; | 633 Browser browser; |
| 637 BrowserTest currentTest; | 634 BrowserTest currentTest; |
| 635 |
| 638 // This is currently not used for anything except for error reporting. | 636 // This is currently not used for anything except for error reporting. |
| 639 // Given the usefulness of this in debugging issues this should not be | 637 // Given the usefulness of this in debugging issues this should not be |
| 640 // removed even when we have really stable system. | 638 // removed even when we have really stable system. |
| 641 BrowserTest lastTest; | 639 BrowserTest lastTest; |
| 642 bool timeout = false; | 640 bool timeout = false; |
| 643 BrowserTestingStatus(Browser this.browser); | 641 BrowserTestingStatus(Browser this.browser); |
| 644 } | 642 } |
| 645 | 643 |
| 646 | 644 |
| 647 /** | 645 /** |
| 648 * Describes a single test to be run int the browser. | 646 * Describes a single test to be run int the browser. |
| 649 */ | 647 */ |
| 650 class BrowserTest { | 648 class BrowserTest { |
| 651 // TODO(ricow): Add timeout callback instead of the string passing hack. | 649 // TODO(ricow): Add timeout callback instead of the string passing hack. |
| 652 Function doneCallback; | 650 Function doneCallback; |
| 653 String url; | 651 String url; |
| 654 int timeout; | 652 int timeout; |
| 653 String lastKnownMessage = ''; |
| 655 Stopwatch stopwatch; | 654 Stopwatch stopwatch; |
| 656 | 655 |
| 657 // This might be null | 656 // This might be null |
| 658 Duration delayUntilTestStarted; | 657 Duration delayUntilTestStarted; |
| 659 | 658 |
| 660 // We store this here for easy access when tests time out (instead of | 659 // We store this here for easy access when tests time out (instead of |
| 661 // capturing this in a closure) | 660 // capturing this in a closure) |
| 662 Timer timeoutTimer; | 661 Timer timeoutTimer; |
| 663 | 662 |
| 664 // Used for debugging, this is simply a unique identifier assigned to each | 663 // Used for debugging, this is simply a unique identifier assigned to each |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 | 725 |
| 727 Future<bool> start() { | 726 Future<bool> start() { |
| 728 // If [browserName] doesn't support opening new windows, we use new iframes | 727 // If [browserName] doesn't support opening new windows, we use new iframes |
| 729 // instead. | 728 // instead. |
| 730 bool useIframe = | 729 bool useIframe = |
| 731 !Browser.BROWSERS_WITH_WINDOW_SUPPORT.contains(browserName); | 730 !Browser.BROWSERS_WITH_WINDOW_SUPPORT.contains(browserName); |
| 732 testingServer = new BrowserTestingServer( | 731 testingServer = new BrowserTestingServer( |
| 733 globalConfiguration, localIp, useIframe); | 732 globalConfiguration, localIp, useIframe); |
| 734 return testingServer.start().then((_) { | 733 return testingServer.start().then((_) { |
| 735 testingServer.testDoneCallBack = handleResults; | 734 testingServer.testDoneCallBack = handleResults; |
| 735 testingServer.testStatusUpdateCallBack = handleStatusUpdate; |
| 736 testingServer.testStartedCallBack = handleStarted; | 736 testingServer.testStartedCallBack = handleStarted; |
| 737 testingServer.nextTestCallBack = getNextTest; | 737 testingServer.nextTestCallBack = getNextTest; |
| 738 return getBrowsers().then((browsers) { | 738 return getBrowsers().then((browsers) { |
| 739 var futures = []; | 739 var futures = []; |
| 740 for (var browser in browsers) { | 740 for (var browser in browsers) { |
| 741 var url = testingServer.getDriverUrl(browser.id); | 741 var url = testingServer.getDriverUrl(browser.id); |
| 742 var future = browser.start(url).then((success) { | 742 var future = browser.start(url).then((success) { |
| 743 if (success) { | 743 if (success) { |
| 744 browserStatus[browser.id] = new BrowserTestingStatus(browser); | 744 browserStatus[browser.id] = new BrowserTestingStatus(browser); |
| 745 } | 745 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 } else { | 840 } else { |
| 841 print("\nThis is bad, should never happen, handleResult no test"); | 841 print("\nThis is bad, should never happen, handleResult no test"); |
| 842 print("URL: ${status.lastTest.url}"); | 842 print("URL: ${status.lastTest.url}"); |
| 843 print(output); | 843 print(output); |
| 844 terminate().then((_) { | 844 terminate().then((_) { |
| 845 exit(1); | 845 exit(1); |
| 846 }); | 846 }); |
| 847 } | 847 } |
| 848 } | 848 } |
| 849 | 849 |
| 850 void handleStatusUpdate(String browserId, String output, int testId) { |
| 851 var status = browserStatus[browserId]; |
| 852 |
| 853 if (status == null || status.timeout) { |
| 854 // We don't do anything, this browser is currently being killed and |
| 855 // replaced. The browser here can be null if we decided to kill the |
| 856 // browser. |
| 857 } else if (status.currentTest != null && status.currentTest.id != testId) { |
| 858 status.currentTest.lastKnownMessage = output; |
| 859 } |
| 860 } |
| 861 |
| 850 void handleStarted(String browserId, String output, int testId) { | 862 void handleStarted(String browserId, String output, int testId) { |
| 851 var status = browserStatus[browserId]; | 863 var status = browserStatus[browserId]; |
| 852 | 864 |
| 853 if (status != null && !status.timeout && status.currentTest != null) { | 865 if (status != null && !status.timeout && status.currentTest != null) { |
| 854 status.currentTest.timeoutTimer.cancel(); | 866 status.currentTest.timeoutTimer.cancel(); |
| 855 status.currentTest.timeoutTimer = | 867 status.currentTest.timeoutTimer = |
| 856 createTimeoutTimer(status.currentTest, status); | 868 createTimeoutTimer(status.currentTest, status); |
| 857 status.currentTest.delayUntilTestStarted = | 869 status.currentTest.delayUntilTestStarted = |
| 858 status.currentTest.stopwatch.elapsed; | 870 status.currentTest.stopwatch.elapsed; |
| 859 } | 871 } |
| 860 } | 872 } |
| 861 | 873 |
| 862 void handleTimeout(BrowserTestingStatus status) { | 874 void handleTimeout(BrowserTestingStatus status) { |
| 863 // We simply kill the browser and starts up a new one! | 875 // We simply kill the browser and starts up a new one! |
| 864 // We could be smarter here, but it does not seems like it is worth it. | 876 // We could be smarter here, but it does not seems like it is worth it. |
| 865 status.timeout = true; | 877 status.timeout = true; |
| 866 timedOut.add(status.currentTest.url); | 878 timedOut.add(status.currentTest.url); |
| 867 var id = status.browser.id; | 879 var id = status.browser.id; |
| 868 | 880 |
| 869 status.currentTest.stopwatch.stop(); | 881 status.currentTest.stopwatch.stop(); |
| 870 status.browser.close().then((_) { | 882 status.browser.close().then((_) { |
| 883 var lastKnownMessage = |
| 884 'Dom could not be fetched, since the test timed out.'; |
| 885 if (status.currentTest.lastKnownMessage.length > 0) { |
| 886 lastKnownMessage = status.currentTest.lastKnownMessage; |
| 887 } |
| 871 // Wait until the browser is closed before reporting the test as timeout. | 888 // Wait until the browser is closed before reporting the test as timeout. |
| 872 // This will enable us to capture stdout/stderr from the browser | 889 // This will enable us to capture stdout/stderr from the browser |
| 873 // (which might provide us with information about what went wrong). | 890 // (which might provide us with information about what went wrong). |
| 874 var browserTestOutput = new BrowserTestOutput( | 891 var browserTestOutput = new BrowserTestOutput( |
| 875 status.currentTest.delayUntilTestStarted, | 892 status.currentTest.delayUntilTestStarted, |
| 876 status.currentTest.stopwatch.elapsed, | 893 status.currentTest.stopwatch.elapsed, |
| 877 'Dom could not be fetched, since the test timed out.', | 894 lastKnownMessage, |
| 878 status.browser.testBrowserOutput, | 895 status.browser.testBrowserOutput, |
| 879 didTimeout: true); | 896 didTimeout: true); |
| 880 status.currentTest.doneCallback(browserTestOutput); | 897 status.currentTest.doneCallback(browserTestOutput); |
| 881 status.currentTest = null; | 898 status.currentTest = null; |
| 882 | 899 |
| 883 // We don't want to start a new browser if we are terminating. | 900 // We don't want to start a new browser if we are terminating. |
| 884 if (underTermination) return; | 901 if (underTermination) return; |
| 885 var browser; | 902 var browser; |
| 886 var new_id = id; | 903 var new_id = id; |
| 887 if (browserName == 'chromeOnAndroid') { | 904 if (browserName == 'chromeOnAndroid') { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 if (testQueue.isEmpty) return null; | 945 if (testQueue.isEmpty) return null; |
| 929 var status = browserStatus[browserId]; | 946 var status = browserStatus[browserId]; |
| 930 if (status == null) return null; | 947 if (status == null) return null; |
| 931 | 948 |
| 932 // We are currently terminating this browser, don't start a new test. | 949 // We are currently terminating this browser, don't start a new test. |
| 933 if (status.timeout) return null; | 950 if (status.timeout) return null; |
| 934 | 951 |
| 935 BrowserTest test = testQueue.removeLast(); | 952 BrowserTest test = testQueue.removeLast(); |
| 936 if (status.currentTest == null) { | 953 if (status.currentTest == null) { |
| 937 status.currentTest = test; | 954 status.currentTest = test; |
| 955 status.currentTest.lastKnownMessage = ''; |
| 938 } else { | 956 } else { |
| 939 // TODO(ricow): Handle this better. | 957 // TODO(ricow): Handle this better. |
| 940 print("This is bad, should never happen, getNextTest all full"); | 958 print("This is bad, should never happen, getNextTest all full"); |
| 941 print("This happened for browser $browserId"); | 959 print("This happened for browser $browserId"); |
| 942 print("Old test was: ${status.currentTest.url}"); | 960 print("Old test was: ${status.currentTest.url}"); |
| 943 print("Timed out tests:"); | 961 print("Timed out tests:"); |
| 944 for (var v in timedOut) { | 962 for (var v in timedOut) { |
| 945 print(" $v"); | 963 print(" $v"); |
| 946 } | 964 } |
| 947 exit(1); | 965 exit(1); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 /// back. If we are in the process of terminating the terminateSignal | 1040 /// back. If we are in the process of terminating the terminateSignal |
| 1023 /// is send back and the browser will stop requesting new tasks. | 1041 /// is send back and the browser will stop requesting new tasks. |
| 1024 /// POST /report/BROWSER_ID?id=NUM -- sends back the dom of the executed | 1042 /// POST /report/BROWSER_ID?id=NUM -- sends back the dom of the executed |
| 1025 /// test | 1043 /// test |
| 1026 | 1044 |
| 1027 final String localIp; | 1045 final String localIp; |
| 1028 | 1046 |
| 1029 static const String driverPath = "/driver"; | 1047 static const String driverPath = "/driver"; |
| 1030 static const String nextTestPath = "/next_test"; | 1048 static const String nextTestPath = "/next_test"; |
| 1031 static const String reportPath = "/report"; | 1049 static const String reportPath = "/report"; |
| 1050 static const String statusUpdatePath = "/status_update"; |
| 1032 static const String startedPath = "/started"; | 1051 static const String startedPath = "/started"; |
| 1033 static const String waitSignal = "WAIT"; | 1052 static const String waitSignal = "WAIT"; |
| 1034 static const String terminateSignal = "TERMINATE"; | 1053 static const String terminateSignal = "TERMINATE"; |
| 1035 | 1054 |
| 1036 var testCount = 0; | 1055 var testCount = 0; |
| 1037 var httpServer; | 1056 var httpServer; |
| 1038 var errorReportingServer; | 1057 var errorReportingServer; |
| 1039 bool underTermination = false; | 1058 bool underTermination = false; |
| 1040 bool useIframe = false; | 1059 bool useIframe = false; |
| 1041 | 1060 |
| 1042 Function testDoneCallBack; | 1061 Function testDoneCallBack; |
| 1062 Function testStatusUpdateCallBack; |
| 1043 Function testStartedCallBack; | 1063 Function testStartedCallBack; |
| 1044 Function nextTestCallBack; | 1064 Function nextTestCallBack; |
| 1045 | 1065 |
| 1046 BrowserTestingServer(this.globalConfiguration, this.localIp, this.useIframe); | 1066 BrowserTestingServer(this.globalConfiguration, this.localIp, this.useIframe); |
| 1047 | 1067 |
| 1048 Future start() { | 1068 Future start() { |
| 1049 int port = globalConfiguration['test_driver_port']; | 1069 int port = globalConfiguration['test_driver_port']; |
| 1050 return HttpServer.bind(localIp, port).then((createdServer) { | 1070 return HttpServer.bind(localIp, port).then((createdServer) { |
| 1051 httpServer = createdServer; | 1071 httpServer = createdServer; |
| 1052 void handler(HttpRequest request) { | 1072 void handler(HttpRequest request) { |
| 1053 // Don't allow caching of resources from the browser controller, i.e., | 1073 // Don't allow caching of resources from the browser controller, i.e., |
| 1054 // we don't want the browser to cache the result of getNextTest. | 1074 // we don't want the browser to cache the result of getNextTest. |
| 1055 request.response.headers.set("Cache-Control", | 1075 request.response.headers.set("Cache-Control", |
| 1056 "no-cache, no-store, must-revalidate"); | 1076 "no-cache, no-store, must-revalidate"); |
| 1057 if (request.uri.path.startsWith(reportPath)) { | 1077 bool isReport = request.uri.path.startsWith(reportPath); |
| 1058 var browserId = request.uri.path.substring(reportPath.length + 1); | 1078 bool isStatusUpdate = request.uri.path.startsWith(statusUpdatePath); |
| 1079 if (isReport || isStatusUpdate) { |
| 1080 var browserId; |
| 1081 if (isStatusUpdate) { |
| 1082 browserId = request.uri.path.substring(statusUpdatePath.length + 1); |
| 1083 } else { |
| 1084 browserId = request.uri.path.substring(reportPath.length + 1); |
| 1085 } |
| 1059 var testId = | 1086 var testId = |
| 1060 int.parse(request.uri.queryParameters["id"].split("=")[1]); | 1087 int.parse(request.uri.queryParameters["id"].split("=")[1]); |
| 1061 handleReport(request, browserId, testId); | 1088 handleReport( |
| 1089 request, browserId, testId, isStatusUpdate: isStatusUpdate); |
| 1062 // handleReport will asynchroniously fetch the data and will handle | 1090 // handleReport will asynchroniously fetch the data and will handle |
| 1063 // the closing of the streams. | 1091 // the closing of the streams. |
| 1064 return; | 1092 return; |
| 1065 } | 1093 } |
| 1066 if (request.uri.path.startsWith(startedPath)) { | 1094 if (request.uri.path.startsWith(startedPath)) { |
| 1067 var browserId = request.uri.path.substring(startedPath.length + 1); | 1095 var browserId = request.uri.path.substring(startedPath.length + 1); |
| 1068 var testId = | 1096 var testId = |
| 1069 int.parse(request.uri.queryParameters["id"].split("=")[1]); | 1097 int.parse(request.uri.queryParameters["id"].split("=")[1]); |
| 1070 handleStarted(request, browserId, testId); | 1098 handleStarted(request, browserId, testId); |
| 1071 return; | 1099 return; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 "${request.uri.path}, data: $back"); | 1145 "${request.uri.path}, data: $back"); |
| 1118 }, onError: (error) { print(error); }); | 1146 }, onError: (error) { print(error); }); |
| 1119 } | 1147 } |
| 1120 errorReportingServer.listen(errorReportingHandler, | 1148 errorReportingServer.listen(errorReportingHandler, |
| 1121 onError: errorHandler); | 1149 onError: errorHandler); |
| 1122 return true; | 1150 return true; |
| 1123 }); | 1151 }); |
| 1124 }); | 1152 }); |
| 1125 } | 1153 } |
| 1126 | 1154 |
| 1127 void handleReport(HttpRequest request, String browserId, var testId) { | 1155 void handleReport(HttpRequest request, String browserId, var testId, |
| 1156 {bool isStatusUpdate}) { |
| 1128 StringBuffer buffer = new StringBuffer(); | 1157 StringBuffer buffer = new StringBuffer(); |
| 1129 request.transform(UTF8.decoder).listen((data) { | 1158 request.transform(UTF8.decoder).listen((data) { |
| 1130 buffer.write(data); | 1159 buffer.write(data); |
| 1131 }, onDone: () { | 1160 }, onDone: () { |
| 1132 String back = buffer.toString(); | 1161 String back = buffer.toString(); |
| 1133 request.response.close(); | 1162 request.response.close(); |
| 1134 testDoneCallBack(browserId, back, testId); | 1163 if (isStatusUpdate) { |
| 1164 testStatusUpdateCallBack(browserId, back, testId); |
| 1165 } else { |
| 1166 testDoneCallBack(browserId, back, testId); |
| 1167 } |
| 1135 // TODO(ricow): We should do something smart if we get an error here. | 1168 // TODO(ricow): We should do something smart if we get an error here. |
| 1136 }, onError: (error) { DebugLogger.error("$error"); }); | 1169 }, onError: (error) { DebugLogger.error("$error"); }); |
| 1137 } | 1170 } |
| 1138 | 1171 |
| 1139 void handleStarted(HttpRequest request, String browserId, var testId) { | 1172 void handleStarted(HttpRequest request, String browserId, var testId) { |
| 1140 StringBuffer buffer = new StringBuffer(); | 1173 StringBuffer buffer = new StringBuffer(); |
| 1141 // If an error occurs while receiving the data from the request stream, | 1174 // If an error occurs while receiving the data from the request stream, |
| 1142 // we don't handle it specially. We can safely ignore it, since the started | 1175 // we don't handle it specially. We can safely ignore it, since the started |
| 1143 // events are not crucial. | 1176 // events are not crucial. |
| 1144 request.transform(UTF8.decoder).listen((data) { | 1177 request.transform(UTF8.decoder).listen((data) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 | 1209 |
| 1177 | 1210 |
| 1178 String getDriverPage(String browserId) { | 1211 String getDriverPage(String browserId) { |
| 1179 var errorReportingUrl = | 1212 var errorReportingUrl = |
| 1180 "http://$localIp:${errorReportingServer.port}/$browserId"; | 1213 "http://$localIp:${errorReportingServer.port}/$browserId"; |
| 1181 String driverContent = """ | 1214 String driverContent = """ |
| 1182 <!DOCTYPE html><html> | 1215 <!DOCTYPE html><html> |
| 1183 <head> | 1216 <head> |
| 1184 <title>Driving page</title> | 1217 <title>Driving page</title> |
| 1185 <script type='text/javascript'> | 1218 <script type='text/javascript'> |
| 1186 | |
| 1187 function startTesting() { | 1219 function startTesting() { |
| 1188 var number_of_tests = 0; | 1220 var number_of_tests = 0; |
| 1189 var current_id; | 1221 var current_id; |
| 1190 var next_id; | 1222 var next_id; |
| 1191 // Describes a state where we are currently fetching the next test | 1223 // Describes a state where we are currently fetching the next test |
| 1192 // from the server. We use this to never double request tasks. | 1224 // from the server. We use this to never double request tasks. |
| 1193 var test_completed = true; | 1225 var test_completed = true; |
| 1194 var testing_window; | 1226 var testing_window; |
| 1195 | 1227 |
| 1196 var embedded_iframe = document.getElementById('embedded_iframe'); | 1228 var embedded_iframe = document.getElementById('embedded_iframe'); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 if (this.readyState == this.DONE && this.status != 200) { | 1304 if (this.readyState == this.DONE && this.status != 200) { |
| 1273 var error = 'Sending back error did not succeeed: ' + this.status; | 1305 var error = 'Sending back error did not succeeed: ' + this.status; |
| 1274 error = error + '. Failed to send msg: ' + msg; | 1306 error = error + '. Failed to send msg: ' + msg; |
| 1275 error_div.innerHTML = error; | 1307 error_div.innerHTML = error; |
| 1276 } | 1308 } |
| 1277 } | 1309 } |
| 1278 contactBrowserController( | 1310 contactBrowserController( |
| 1279 'POST', '$errorReportingUrl?test=1', handleReady, msg, true); | 1311 'POST', '$errorReportingUrl?test=1', handleReady, msg, true); |
| 1280 } | 1312 } |
| 1281 | 1313 |
| 1282 function reportMessage(msg) { | 1314 function reportMessage(msg, isFirstMessage, isStatusUpdate) { |
| 1283 if (msg == 'STARTING') { | 1315 if (isFirstMessage) { |
| 1284 test_completed = false; | 1316 test_completed = false; |
| 1285 current_id = next_id; | 1317 current_id = next_id; |
| 1286 contactBrowserController( | 1318 contactBrowserController( |
| 1287 'POST', '$startedPath/${browserId}?id=' + current_id, | 1319 'POST', '$startedPath/${browserId}?id=' + current_id, |
| 1288 function () {}, msg, true); | 1320 function () {}, msg, true); |
| 1289 return; | 1321 } else if (isStatusUpdate) { |
| 1290 } | 1322 contactBrowserController( |
| 1323 'POST', '$statusUpdatePath/${browserId}?id=' + current_id, |
| 1324 function() {}, msg, true); |
| 1325 } else { |
| 1326 var is_double_report = test_completed; |
| 1327 test_completed = true; |
| 1291 | 1328 |
| 1292 var is_double_report = test_completed; | 1329 function handleReady() { |
| 1293 test_completed = true; | 1330 if (this.readyState == this.DONE) { |
| 1294 | 1331 if (this.status == 200) { |
| 1295 function handleReady() { | 1332 if (!is_double_report) { |
| 1296 if (this.readyState == this.DONE) { | 1333 getNextTask(); |
| 1297 if (this.status == 200) { | 1334 } |
| 1298 if (!is_double_report) { | 1335 } else { |
| 1299 getNextTask(); | 1336 reportError('Error sending result to server'); |
| 1300 } | 1337 } |
| 1301 } else { | |
| 1302 reportError('Error sending result to server'); | |
| 1303 } | 1338 } |
| 1304 } | 1339 } |
| 1305 } | 1340 contactBrowserController( |
| 1306 contactBrowserController( | |
| 1307 'POST', '$reportPath/${browserId}?id=' + current_id, handleReady, | 1341 'POST', '$reportPath/${browserId}?id=' + current_id, handleReady, |
| 1308 msg, true); | 1342 msg, true); |
| 1343 } |
| 1344 } |
| 1345 |
| 1346 function parseResult(result) { |
| 1347 var parsedData = null; |
| 1348 try { |
| 1349 parsedData = JSON.parse(result); |
| 1350 } catch(error) { } |
| 1351 return parsedData; |
| 1309 } | 1352 } |
| 1310 | 1353 |
| 1311 function messageHandler(e) { | 1354 function messageHandler(e) { |
| 1312 var msg = e.data; | 1355 var msg = e.data; |
| 1313 if (typeof msg != 'string') return; | 1356 if (typeof msg != 'string') return; |
| 1314 reportMessage(msg); | 1357 |
| 1358 var parsedData = parseResult(msg); |
| 1359 if (parsedData) { |
| 1360 // Only if the JSON was valid, we'll post it back. |
| 1361 var message = parsedData['message']; |
| 1362 var isFirstMessage = parsedData['is_first_message']; |
| 1363 var isStatusUpdate = parsedData['is_status_update']; |
| 1364 var isDone = parsedData['is_done']; |
| 1365 if (!isFirstMessage && !isStatusUpdate) { |
| 1366 if (!isDone) { |
| 1367 alert("Bug in test_controller.js: " + |
| 1368 "isFirstMessage/isStatusUpdate/isDone were all false"); |
| 1369 } |
| 1370 } |
| 1371 if (message) { |
| 1372 reportMessage(message, isFirstMessage, isStatusUpdate); |
| 1373 } |
| 1374 } else { |
| 1375 reportMessage(msg, msg == 'STARTING', false); |
| 1376 } |
| 1315 } | 1377 } |
| 1316 | 1378 |
| 1317 window.addEventListener('message', messageHandler, false); | 1379 window.addEventListener('message', messageHandler, false); |
| 1318 waitForDone = false; | 1380 waitForDone = false; |
| 1319 | 1381 |
| 1320 getNextTask(); | 1382 getNextTask(); |
| 1321 } | 1383 } |
| 1322 | 1384 |
| 1323 </script> | 1385 </script> |
| 1324 </head> | 1386 </head> |
| 1325 <body onload="startTesting()"> | 1387 <body onload="startTesting()"> |
| 1326 Dart test driver, number of tests: <div id="number"></div><br> | 1388 Dart test driver, number of tests: <div id="number"></div><br> |
| 1327 Currently executing: <div id="currently_executing"></div><br> | 1389 Currently executing: <div id="currently_executing"></div><br> |
| 1328 Unhandled error: <div id="unhandled_error"></div> | 1390 Unhandled error: <div id="unhandled_error"></div> |
| 1329 <iframe id="embedded_iframe"></iframe> | 1391 <iframe id="embedded_iframe"></iframe> |
| 1330 </body> | 1392 </body> |
| 1331 </html> | 1393 </html> |
| 1332 """; | 1394 """; |
| 1333 return driverContent; | 1395 return driverContent; |
| 1334 } | 1396 } |
| 1335 } | 1397 } |
| OLD | NEW |