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 | 5 |
5 import 'dart:async'; | 6 import "dart:async"; |
6 import 'dart:convert'; | 7 import "dart:convert" show UTF8, JSON; |
7 import 'dart:core'; | 8 import "dart:core"; |
8 import 'dart:io'; | 9 import "dart:io"; |
9 import 'dart:math'; | 10 import "dart:math" show min; |
10 | 11 |
11 import 'android.dart'; | 12 import 'android.dart'; |
12 import 'configuration.dart'; | 13 import 'http_server.dart'; |
13 import 'path.dart'; | 14 import 'path.dart'; |
14 import 'reset_safari.dart'; | |
15 import 'utils.dart'; | 15 import 'utils.dart'; |
16 | 16 |
| 17 import 'reset_safari.dart' show killAndResetSafari; |
| 18 |
17 typedef void BrowserDoneCallback(BrowserTestOutput output); | 19 typedef void BrowserDoneCallback(BrowserTestOutput output); |
18 typedef void TestChangedCallback(String browserId, String output, int testId); | 20 typedef void TestChangedCallback(String browserId, String output, int testId); |
19 typedef BrowserTest NextTestCallback(String browserId); | 21 typedef BrowserTest NextTestCallback(String browserId); |
20 | 22 |
21 class BrowserOutput { | 23 class BrowserOutput { |
22 final StringBuffer stdout = new StringBuffer(); | 24 final StringBuffer stdout = new StringBuffer(); |
23 final StringBuffer stderr = new StringBuffer(); | 25 final StringBuffer stderr = new StringBuffer(); |
24 final StringBuffer eventLog = new StringBuffer(); | 26 final StringBuffer eventLog = new StringBuffer(); |
25 } | 27 } |
26 | 28 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 66 |
65 /** Print everything (stdout, stderr, usageLog) whenever we add to it */ | 67 /** Print everything (stdout, stderr, usageLog) whenever we add to it */ |
66 bool debugPrint = false; | 68 bool debugPrint = false; |
67 | 69 |
68 // This future returns when the process exits. It is also the return value | 70 // This future returns when the process exits. It is also the return value |
69 // of close() | 71 // of close() |
70 Future done; | 72 Future done; |
71 | 73 |
72 Browser(); | 74 Browser(); |
73 | 75 |
74 factory Browser.byRuntime(Runtime runtime, String executablePath, | 76 factory Browser.byName(String name, String executablePath, |
75 [bool checkedMode = false]) { | 77 [bool checkedMode = false]) { |
76 Browser browser; | 78 Browser browser; |
77 switch (runtime) { | 79 if (name == 'firefox') { |
78 case Runtime.firefox: | 80 browser = new Firefox(); |
79 browser = new Firefox(); | 81 } else if (name == 'chrome') { |
80 break; | 82 browser = new Chrome(); |
81 case Runtime.chrome: | 83 } else if (name == 'dartium') { |
82 browser = new Chrome(); | 84 browser = new Dartium(checkedMode); |
83 break; | 85 } else if (name == 'safari') { |
84 case Runtime.dartium: | 86 browser = new Safari(); |
85 browser = new Dartium(checkedMode); | 87 } else if (name == 'safarimobilesim') { |
86 break; | 88 browser = new SafariMobileSimulator(); |
87 case Runtime.safari: | 89 } else if (name.startsWith('ie')) { |
88 browser = new Safari(); | 90 browser = new IE(); |
89 break; | 91 } else { |
90 case Runtime.safariMobileSim: | 92 throw "Non supported browser"; |
91 browser = new SafariMobileSimulator(); | |
92 break; | |
93 case Runtime.ie9: | |
94 case Runtime.ie10: | |
95 case Runtime.ie11: | |
96 browser = new IE(); | |
97 break; | |
98 default: | |
99 throw "unreachable"; | |
100 } | 93 } |
101 | |
102 browser._binary = executablePath; | 94 browser._binary = executablePath; |
103 return browser; | 95 return browser; |
104 } | 96 } |
105 | 97 |
106 static const List<String> SUPPORTED_BROWSERS = const [ | 98 static const List<String> SUPPORTED_BROWSERS = const [ |
107 'safari', | 99 'safari', |
108 'ff', | 100 'ff', |
109 'firefox', | 101 'firefox', |
110 'chrome', | 102 'chrome', |
111 'ie9', | 103 'ie9', |
112 'ie10', | 104 'ie10', |
113 'ie11', | 105 'ie11', |
114 'dartium' | 106 'dartium' |
115 ]; | 107 ]; |
116 | 108 |
| 109 static const List<String> BROWSERS_WITH_WINDOW_SUPPORT = const [ |
| 110 'ie11', |
| 111 'ie10' |
| 112 ]; |
| 113 |
| 114 /// If [browserName] doesn't support Window.open, we use iframes instead. |
| 115 static bool requiresIframe(String browserName) { |
| 116 return !BROWSERS_WITH_WINDOW_SUPPORT.contains(browserName); |
| 117 } |
| 118 |
117 static bool requiresFocus(String browserName) { | 119 static bool requiresFocus(String browserName) { |
118 return browserName == "safari"; | 120 return browserName == "safari"; |
119 } | 121 } |
120 | 122 |
121 // TODO(kustermann): add standard support for chrome on android | 123 // TODO(kustermann): add standard support for chrome on android |
122 static bool supportedBrowser(String name) { | 124 static bool supportedBrowser(String name) { |
123 return SUPPORTED_BROWSERS.contains(name); | 125 return SUPPORTED_BROWSERS.contains(name); |
124 } | 126 } |
125 | 127 |
126 void _logEvent(String event) { | 128 void _logEvent(String event) { |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 /// driver page to the browsers, serves tests, and receives results and | 938 /// driver page to the browsers, serves tests, and receives results and |
937 /// requests back from the browsers. | 939 /// requests back from the browsers. |
938 class BrowserTestRunner { | 940 class BrowserTestRunner { |
939 static const int MAX_NEXT_TEST_TIMEOUTS = 10; | 941 static const int MAX_NEXT_TEST_TIMEOUTS = 10; |
940 static const Duration NEXT_TEST_TIMEOUT = const Duration(seconds: 120); | 942 static const Duration NEXT_TEST_TIMEOUT = const Duration(seconds: 120); |
941 static const Duration RESTART_BROWSER_INTERVAL = const Duration(seconds: 60); | 943 static const Duration RESTART_BROWSER_INTERVAL = const Duration(seconds: 60); |
942 | 944 |
943 /// If the queue was recently empty, don't start another browser. | 945 /// If the queue was recently empty, don't start another browser. |
944 static const Duration MIN_NONEMPTY_QUEUE_TIME = const Duration(seconds: 1); | 946 static const Duration MIN_NONEMPTY_QUEUE_TIME = const Duration(seconds: 1); |
945 | 947 |
946 final Configuration configuration; | 948 final Map<String, dynamic> configuration; |
947 final BrowserTestingServer testingServer; | 949 final BrowserTestingServer testingServer; |
948 | 950 |
949 final String localIp; | 951 final String localIp; |
| 952 final String browserName; |
950 int maxNumBrowsers; | 953 int maxNumBrowsers; |
| 954 final bool checkedMode; |
951 int numBrowsers = 0; | 955 int numBrowsers = 0; |
952 // Used to send back logs from the browser (start, stop etc) | 956 // Used to send back logs from the browser (start, stop etc) |
953 Function logger; | 957 Function logger; |
954 | 958 |
955 int browserIdCounter = 1; | 959 int browserIdCounter = 1; |
956 | 960 |
957 bool testingServerStarted = false; | 961 bool testingServerStarted = false; |
958 bool underTermination = false; | 962 bool underTermination = false; |
959 int numBrowserGetTestTimeouts = 0; | 963 int numBrowserGetTestTimeouts = 0; |
960 DateTime lastEmptyTestQueueTime = new DateTime.now(); | 964 DateTime lastEmptyTestQueueTime = new DateTime.now(); |
961 String _currentStartingBrowserId; | 965 String _currentStartingBrowserId; |
962 List<BrowserTest> testQueue = []; | 966 List<BrowserTest> testQueue = new List<BrowserTest>(); |
963 Map<String, BrowserStatus> browserStatus = {}; | 967 Map<String, BrowserStatus> browserStatus = new Map<String, BrowserStatus>(); |
964 | 968 |
965 Map<String, AdbDevice> adbDeviceMapping = {}; | 969 var adbDeviceMapping = new Map<String, AdbDevice>(); |
966 List<AdbDevice> idleAdbDevices; | 970 List<AdbDevice> idleAdbDevices; |
967 | 971 |
968 // This cache is used to guarantee that we never see double reporting. | 972 // This cache is used to guarantee that we never see double reporting. |
969 // If we do we need to provide developers with this information. | 973 // If we do we need to provide developers with this information. |
970 // We don't add urls to the cache until we have run it. | 974 // We don't add urls to the cache until we have run it. |
971 Map<int, String> testCache = {}; | 975 Map<int, String> testCache = new Map<int, String>(); |
972 | 976 |
973 Map<int, String> doubleReportingOutputs = {}; | 977 Map<int, String> doubleReportingOutputs = new Map<int, String>(); |
974 List<String> timedOut = []; | 978 List<String> timedOut = []; |
975 | 979 |
976 // We will start a new browser when the test queue hasn't been empty | 980 // We will start a new browser when the test queue hasn't been empty |
977 // recently, we have fewer than maxNumBrowsers browsers, and there is | 981 // recently, we have fewer than maxNumBrowsers browsers, and there is |
978 // no other browser instance currently starting up. | 982 // no other browser instance currently starting up. |
979 bool get queueWasEmptyRecently { | 983 bool get queueWasEmptyRecently { |
980 return testQueue.isEmpty || | 984 return testQueue.isEmpty || |
981 new DateTime.now().difference(lastEmptyTestQueueTime) < | 985 new DateTime.now().difference(lastEmptyTestQueueTime) < |
982 MIN_NONEMPTY_QUEUE_TIME; | 986 MIN_NONEMPTY_QUEUE_TIME; |
983 } | 987 } |
984 | 988 |
985 // While a browser is starting, but has not requested its first test, its | 989 // While a browser is starting, but has not requested its first test, its |
986 // browserId is stored in _currentStartingBrowserId. | 990 // browserId is stored in _currentStartingBrowserId. |
987 // When no browser is currently starting, _currentStartingBrowserId is null. | 991 // When no browser is currently starting, _currentStartingBrowserId is null. |
988 bool get aBrowserIsCurrentlyStarting => _currentStartingBrowserId != null; | 992 bool get aBrowserIsCurrentlyStarting => _currentStartingBrowserId != null; |
989 void markCurrentlyStarting(String id) { | 993 void markCurrentlyStarting(String id) { |
990 _currentStartingBrowserId = id; | 994 _currentStartingBrowserId = id; |
991 } | 995 } |
992 | 996 |
993 void markNotCurrentlyStarting(String id) { | 997 void markNotCurrentlyStarting(String id) { |
994 if (_currentStartingBrowserId == id) _currentStartingBrowserId = null; | 998 if (_currentStartingBrowserId == id) _currentStartingBrowserId = null; |
995 } | 999 } |
996 | 1000 |
997 BrowserTestRunner( | 1001 BrowserTestRunner(Map<String, dynamic> configuration, String localIp, |
998 Configuration configuration, String localIp, this.maxNumBrowsers) | 1002 String browserName, this.maxNumBrowsers) |
999 : configuration = configuration, | 1003 : configuration = configuration, |
1000 localIp = localIp, | 1004 localIp = localIp, |
1001 testingServer = new BrowserTestingServer(configuration, localIp, | 1005 browserName = (browserName == 'ff') ? 'firefox' : browserName, |
1002 Browser.requiresFocus(configuration.runtime.name)) { | 1006 checkedMode = configuration['checked'] as bool, |
| 1007 testingServer = new BrowserTestingServer( |
| 1008 configuration, |
| 1009 localIp, |
| 1010 Browser.requiresIframe(browserName), |
| 1011 Browser.requiresFocus(browserName)) { |
1003 testingServer.testRunner = this; | 1012 testingServer.testRunner = this; |
1004 } | 1013 } |
1005 | 1014 |
1006 Future start() async { | 1015 Future start() async { |
1007 await testingServer.start(); | 1016 await testingServer.start(); |
1008 testingServer | 1017 testingServer |
1009 ..testDoneCallBack = handleResults | 1018 ..testDoneCallBack = handleResults |
1010 ..testStatusUpdateCallBack = handleStatusUpdate | 1019 ..testStatusUpdateCallBack = handleStatusUpdate |
1011 ..testStartedCallBack = handleStarted | 1020 ..testStartedCallBack = handleStarted |
1012 ..nextTestCallBack = getNextTest; | 1021 ..nextTestCallBack = getNextTest; |
1013 if (configuration.runtime == Runtime.chromeOnAndroid) { | 1022 if (browserName == 'chromeOnAndroid') { |
1014 var idbNames = await AdbHelper.listDevices(); | 1023 var idbNames = await AdbHelper.listDevices(); |
1015 idleAdbDevices = new List.from(idbNames.map((id) => new AdbDevice(id))); | 1024 idleAdbDevices = new List.from(idbNames.map((id) => new AdbDevice(id))); |
1016 maxNumBrowsers = min(maxNumBrowsers, idleAdbDevices.length); | 1025 maxNumBrowsers = min(maxNumBrowsers, idleAdbDevices.length); |
1017 } | 1026 } |
1018 testingServerStarted = true; | 1027 testingServerStarted = true; |
1019 requestBrowser(); | 1028 requestBrowser(); |
1020 } | 1029 } |
1021 | 1030 |
1022 /// requestBrowser() is called whenever we might want to start an additional | 1031 /// requestBrowser() is called whenever we might want to start an additional |
1023 /// browser instance. | 1032 /// browser instance. |
1024 /// It is called when starting the BrowserTestRunner, and whenever a browser | 1033 /// It is called when starting the BrowserTestRunner, and whenever a browser |
1025 /// is killed, whenever a new test is enqueued, or whenever a browser | 1034 /// is killed, whenever a new test is enqueued, or whenever a browser |
1026 /// finishes a test. | 1035 /// finishes a test. |
1027 /// So we are guaranteed that this will always eventually be called, as long | 1036 /// So we are guaranteed that this will always eventually be called, as long |
1028 /// as the test queue isn't empty. | 1037 /// as the test queue isn't empty. |
1029 void requestBrowser() { | 1038 void requestBrowser() { |
1030 if (!testingServerStarted) return; | 1039 if (!testingServerStarted) return; |
1031 if (underTermination) return; | 1040 if (underTermination) return; |
1032 if (numBrowsers == maxNumBrowsers) return; | 1041 if (numBrowsers == maxNumBrowsers) return; |
1033 if (aBrowserIsCurrentlyStarting) return; | 1042 if (aBrowserIsCurrentlyStarting) return; |
1034 if (numBrowsers > 0 && queueWasEmptyRecently) return; | 1043 if (numBrowsers > 0 && queueWasEmptyRecently) return; |
1035 createBrowser(); | 1044 createBrowser(); |
1036 } | 1045 } |
1037 | 1046 |
1038 String getNextBrowserId() => "BROWSER${browserIdCounter++}"; | 1047 String getNextBrowserId() => "BROWSER${browserIdCounter++}"; |
1039 | 1048 |
1040 void createBrowser() { | 1049 void createBrowser() { |
1041 var id = getNextBrowserId(); | 1050 final String id = getNextBrowserId(); |
1042 var url = testingServer.getDriverUrl(id); | 1051 final String url = testingServer.getDriverUrl(id); |
1043 | |
1044 Browser browser; | 1052 Browser browser; |
1045 if (configuration.runtime == Runtime.chromeOnAndroid) { | 1053 if (browserName == 'chromeOnAndroid') { |
1046 AdbDevice device = idleAdbDevices.removeLast(); | 1054 AdbDevice device = idleAdbDevices.removeLast(); |
1047 adbDeviceMapping[id] = device; | 1055 adbDeviceMapping[id] = device; |
1048 browser = new AndroidChrome(device); | 1056 browser = new AndroidChrome(device); |
1049 } else { | 1057 } else { |
1050 var path = configuration.browserLocation; | 1058 String path = Locations.getBrowserLocation(browserName, configuration); |
1051 browser = new Browser.byRuntime( | 1059 browser = new Browser.byName(browserName, path, checkedMode); |
1052 configuration.runtime, path, configuration.isChecked); | |
1053 browser.logger = logger; | 1060 browser.logger = logger; |
1054 } | 1061 } |
1055 | |
1056 browser.id = id; | 1062 browser.id = id; |
1057 markCurrentlyStarting(id); | 1063 markCurrentlyStarting(id); |
1058 var status = new BrowserStatus(browser); | 1064 final status = new BrowserStatus(browser); |
1059 browserStatus[id] = status; | 1065 browserStatus[id] = status; |
1060 numBrowsers++; | 1066 numBrowsers++; |
1061 status.nextTestTimeout = createNextTestTimer(status); | 1067 status.nextTestTimeout = createNextTestTimer(status); |
1062 browser.start(url); | 1068 browser.start(url); |
1063 } | 1069 } |
1064 | 1070 |
1065 void handleResults(String browserId, String output, int testId) { | 1071 void handleResults(String browserId, String output, int testId) { |
1066 var status = browserStatus[browserId]; | 1072 var status = browserStatus[browserId]; |
1067 if (testCache.containsKey(testId)) { | 1073 if (testCache.containsKey(testId)) { |
1068 doubleReportingOutputs[testId] = output; | 1074 doubleReportingOutputs[testId] = output; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 | 1181 |
1176 // We don't want to start a new browser if we are terminating. | 1182 // We don't want to start a new browser if we are terminating. |
1177 if (underTermination) return; | 1183 if (underTermination) return; |
1178 removeBrowser(id); | 1184 removeBrowser(id); |
1179 requestBrowser(); | 1185 requestBrowser(); |
1180 } | 1186 } |
1181 | 1187 |
1182 /// Remove a browser that has closed from our data structures that track | 1188 /// Remove a browser that has closed from our data structures that track |
1183 /// open browsers. Check if we want to replace it with a new browser. | 1189 /// open browsers. Check if we want to replace it with a new browser. |
1184 void removeBrowser(String id) { | 1190 void removeBrowser(String id) { |
1185 if (configuration.runtime == Runtime.chromeOnAndroid) { | 1191 if (browserName == 'chromeOnAndroid') { |
1186 idleAdbDevices.add(adbDeviceMapping.remove(id)); | 1192 idleAdbDevices.add(adbDeviceMapping.remove(id)); |
1187 } | 1193 } |
1188 markNotCurrentlyStarting(id); | 1194 markNotCurrentlyStarting(id); |
1189 browserStatus.remove(id); | 1195 browserStatus.remove(id); |
1190 --numBrowsers; | 1196 --numBrowsers; |
1191 } | 1197 } |
1192 | 1198 |
1193 BrowserTest getNextTest(String browserId) { | 1199 BrowserTest getNextTest(String browserId) { |
1194 markNotCurrentlyStarting(browserId); | 1200 markNotCurrentlyStarting(browserId); |
1195 var status = browserStatus[browserId]; | 1201 var status = browserStatus[browserId]; |
1196 if (status == null) return null; | 1202 if (status == null) return null; |
1197 if (status.nextTestTimeout != null) { | 1203 if (status.nextTestTimeout != null) { |
1198 status.nextTestTimeout.cancel(); | 1204 status.nextTestTimeout.cancel(); |
1199 status.nextTestTimeout = null; | 1205 status.nextTestTimeout = null; |
1200 } | 1206 } |
1201 if (testQueue.isEmpty) return null; | 1207 if (testQueue.isEmpty) return null; |
1202 | 1208 |
1203 // We are currently terminating this browser, don't start a new test. | 1209 // We are currently terminating this browser, don't start a new test. |
1204 if (status.timeout) return null; | 1210 if (status.timeout) return null; |
1205 | 1211 |
1206 // Restart Internet Explorer if it has been | 1212 // Restart Internet Explorer if it has been |
1207 // running for longer than RESTART_BROWSER_INTERVAL. The tests have | 1213 // running for longer than RESTART_BROWSER_INTERVAL. The tests have |
1208 // had flaky timeouts, and this may help. | 1214 // had flaky timeouts, and this may help. |
1209 if ((configuration.runtime == Runtime.ie10 || | 1215 if ((browserName == 'ie10' || browserName == 'ie11') && |
1210 configuration.runtime == Runtime.ie11) && | |
1211 status.timeSinceRestart.elapsed > RESTART_BROWSER_INTERVAL) { | 1216 status.timeSinceRestart.elapsed > RESTART_BROWSER_INTERVAL) { |
1212 var id = status.browser.id; | 1217 var id = status.browser.id; |
1213 // Reset stopwatch so we don't trigger again before restarting. | 1218 // Reset stopwatch so we don't trigger again before restarting. |
1214 status.timeout = true; | 1219 status.timeout = true; |
1215 status.browser.close().then((_) { | 1220 status.browser.close().then((_) { |
1216 // We don't want to start a new browser if we are terminating. | 1221 // We don't want to start a new browser if we are terminating. |
1217 if (underTermination) return; | 1222 if (underTermination) return; |
1218 removeBrowser(id); | 1223 removeBrowser(id); |
1219 requestBrowser(); | 1224 requestBrowser(); |
1220 }); | 1225 }); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 for (var browser in browsers) { | 1335 for (var browser in browsers) { |
1331 await browser.close(); | 1336 await browser.close(); |
1332 } | 1337 } |
1333 | 1338 |
1334 testingServer.errorReportingServer.close(); | 1339 testingServer.errorReportingServer.close(); |
1335 printDoubleReportingTests(); | 1340 printDoubleReportingTests(); |
1336 } | 1341 } |
1337 } | 1342 } |
1338 | 1343 |
1339 class BrowserTestingServer { | 1344 class BrowserTestingServer { |
1340 final Configuration configuration; | 1345 final Map configuration; |
1341 | 1346 |
1342 /// Interface of the testing server: | 1347 /// Interface of the testing server: |
1343 /// | 1348 /// |
1344 /// GET /driver/BROWSER_ID -- This will get the driver page to fetch | 1349 /// GET /driver/BROWSER_ID -- This will get the driver page to fetch |
1345 /// and run tests ... | 1350 /// and run tests ... |
1346 /// GET /next_test/BROWSER_ID -- returns "WAIT" "TERMINATE" or "url#id" | 1351 /// GET /next_test/BROWSER_ID -- returns "WAIT" "TERMINATE" or "url#id" |
1347 /// where url is the test to run, and id is the id of the test. | 1352 /// where url is the test to run, and id is the id of the test. |
1348 /// If there are currently no available tests the waitSignal is send | 1353 /// If there are currently no available tests the waitSignal is send |
1349 /// back. If we are in the process of terminating the terminateSignal | 1354 /// back. If we are in the process of terminating the terminateSignal |
1350 /// is send back and the browser will stop requesting new tasks. | 1355 /// is send back and the browser will stop requesting new tasks. |
1351 /// POST /report/BROWSER_ID?id=NUM -- sends back the dom of the executed | 1356 /// POST /report/BROWSER_ID?id=NUM -- sends back the dom of the executed |
1352 /// test | 1357 /// test |
1353 | 1358 |
1354 final String localIp; | 1359 final String localIp; |
| 1360 final bool useIframe; |
1355 final bool requiresFocus; | 1361 final bool requiresFocus; |
1356 BrowserTestRunner testRunner; | 1362 BrowserTestRunner testRunner; |
1357 | 1363 |
1358 static const String driverPath = "/driver"; | 1364 static const String driverPath = "/driver"; |
1359 static const String nextTestPath = "/next_test"; | 1365 static const String nextTestPath = "/next_test"; |
1360 static const String reportPath = "/report"; | 1366 static const String reportPath = "/report"; |
1361 static const String statusUpdatePath = "/status_update"; | 1367 static const String statusUpdatePath = "/status_update"; |
1362 static const String startedPath = "/started"; | 1368 static const String startedPath = "/started"; |
1363 static const String waitSignal = "WAIT"; | 1369 static const String waitSignal = "WAIT"; |
1364 static const String terminateSignal = "TERMINATE"; | 1370 static const String terminateSignal = "TERMINATE"; |
1365 | 1371 |
1366 var testCount = 0; | 1372 var testCount = 0; |
1367 HttpServer errorReportingServer; | 1373 HttpServer errorReportingServer; |
1368 bool underTermination = false; | 1374 bool underTermination = false; |
1369 | 1375 |
1370 TestChangedCallback testDoneCallBack; | 1376 TestChangedCallback testDoneCallBack; |
1371 TestChangedCallback testStatusUpdateCallBack; | 1377 TestChangedCallback testStatusUpdateCallBack; |
1372 TestChangedCallback testStartedCallBack; | 1378 TestChangedCallback testStartedCallBack; |
1373 NextTestCallback nextTestCallBack; | 1379 NextTestCallback nextTestCallBack; |
1374 | 1380 |
1375 BrowserTestingServer(this.configuration, this.localIp, this.requiresFocus); | 1381 BrowserTestingServer( |
| 1382 this.configuration, this.localIp, this.useIframe, this.requiresFocus); |
1376 | 1383 |
1377 Future start() { | 1384 Future start() { |
| 1385 var testDriverErrorPort = configuration['test_driver_error_port'] as int; |
1378 return HttpServer | 1386 return HttpServer |
1379 .bind(localIp, configuration.testDriverErrorPort) | 1387 .bind(localIp, testDriverErrorPort) |
1380 .then(setupErrorServer) | 1388 .then(setupErrorServer) |
1381 .then(setupDispatchingServer); | 1389 .then(setupDispatchingServer); |
1382 } | 1390 } |
1383 | 1391 |
1384 void setupErrorServer(HttpServer server) { | 1392 void setupErrorServer(HttpServer server) { |
1385 errorReportingServer = server; | 1393 errorReportingServer = server; |
1386 void errorReportingHandler(HttpRequest request) { | 1394 void errorReportingHandler(HttpRequest request) { |
1387 StringBuffer buffer = new StringBuffer(); | 1395 StringBuffer buffer = new StringBuffer(); |
1388 request.transform(UTF8.decoder).listen((data) { | 1396 request.transform(UTF8.decoder).listen((data) { |
1389 buffer.write(data); | 1397 buffer.write(data); |
(...skipping 13 matching lines...) Expand all Loading... |
1403 } | 1411 } |
1404 | 1412 |
1405 void errorHandler(e) { | 1413 void errorHandler(e) { |
1406 if (!underTermination) print("Error occured in httpserver: $e"); | 1414 if (!underTermination) print("Error occured in httpserver: $e"); |
1407 } | 1415 } |
1408 | 1416 |
1409 errorReportingServer.listen(errorReportingHandler, onError: errorHandler); | 1417 errorReportingServer.listen(errorReportingHandler, onError: errorHandler); |
1410 } | 1418 } |
1411 | 1419 |
1412 void setupDispatchingServer(_) { | 1420 void setupDispatchingServer(_) { |
1413 var server = configuration.servers.server; | 1421 var server = (configuration['_servers_'] as TestingServers).server; |
1414 void noCache(HttpRequest request) { | 1422 void noCache(HttpRequest request) { |
1415 request.response.headers | 1423 request.response.headers |
1416 .set("Cache-Control", "no-cache, no-store, must-revalidate"); | 1424 .set("Cache-Control", "no-cache, no-store, must-revalidate"); |
1417 } | 1425 } |
1418 | 1426 |
1419 int testId(HttpRequest request) => | 1427 int testId(HttpRequest request) => |
1420 int.parse(request.uri.queryParameters["id"]); | 1428 int.parse(request.uri.queryParameters["id"]); |
1421 String browserId(HttpRequest request, String prefix) => | 1429 String browserId(HttpRequest request, String prefix) => |
1422 request.uri.path.substring(prefix.length + 1); | 1430 request.uri.path.substring(prefix.length + 1); |
1423 | 1431 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1519 return nextTest == null ? waitSignal : nextTest.toJSON(); | 1527 return nextTest == null ? waitSignal : nextTest.toJSON(); |
1520 } | 1528 } |
1521 | 1529 |
1522 String getDriverUrl(String browserId) { | 1530 String getDriverUrl(String browserId) { |
1523 if (errorReportingServer == null) { | 1531 if (errorReportingServer == null) { |
1524 print("Bad browser testing server, you are not started yet. Can't " | 1532 print("Bad browser testing server, you are not started yet. Can't " |
1525 "produce driver url"); | 1533 "produce driver url"); |
1526 exit(1); | 1534 exit(1); |
1527 // This should never happen - exit immediately; | 1535 // This should never happen - exit immediately; |
1528 } | 1536 } |
1529 | 1537 var port = (configuration['_servers_'] as TestingServers).port; |
1530 return "http://$localIp:${configuration.servers.port}/driver/$browserId"; | 1538 return "http://$localIp:$port/driver/$browserId"; |
1531 } | 1539 } |
1532 | 1540 |
1533 Future<String> getDriverPage(String browserId) async { | 1541 Future<String> getDriverPage(String browserId) async { |
1534 await testRunner.browserStatus[browserId].browser.onDriverPageRequested(); | 1542 await testRunner.browserStatus[browserId].browser.onDriverPageRequested(); |
1535 var errorReportingUrl = | 1543 var errorReportingUrl = |
1536 "http://$localIp:${errorReportingServer.port}/$browserId"; | 1544 "http://$localIp:${errorReportingServer.port}/$browserId"; |
1537 String driverContent = """ | 1545 String driverContent = """ |
1538 <!DOCTYPE html><html> | 1546 <!DOCTYPE html><html> |
1539 <head> | 1547 <head> |
1540 <title>Driving page</title> | 1548 <title>Driving page</title> |
(...skipping 29 matching lines...) Expand all Loading... |
1570 var test_completed = true; | 1578 var test_completed = true; |
1571 // Has the test in the current iframe reported that it is started? | 1579 // Has the test in the current iframe reported that it is started? |
1572 var test_started = false; | 1580 var test_started = false; |
1573 var testing_window; | 1581 var testing_window; |
1574 | 1582 |
1575 var embedded_iframe_div = document.getElementById('embedded_iframe_div'); | 1583 var embedded_iframe_div = document.getElementById('embedded_iframe_div'); |
1576 var embedded_iframe = document.getElementById('embedded_iframe'); | 1584 var embedded_iframe = document.getElementById('embedded_iframe'); |
1577 var number_div = document.getElementById('number'); | 1585 var number_div = document.getElementById('number'); |
1578 var executing_div = document.getElementById('currently_executing'); | 1586 var executing_div = document.getElementById('currently_executing'); |
1579 var error_div = document.getElementById('unhandled_error'); | 1587 var error_div = document.getElementById('unhandled_error'); |
1580 var use_iframe = ${configuration.runtime.requiresIFrame}; | 1588 var use_iframe = ${useIframe}; |
1581 var start = new Date(); | 1589 var start = new Date(); |
1582 | 1590 |
1583 // Object that holds the state of an HTML test | 1591 // Object that holds the state of an HTML test |
1584 var html_test; | 1592 var html_test; |
1585 | 1593 |
1586 function newTaskHandler() { | 1594 function newTaskHandler() { |
1587 if (this.readyState == this.DONE) { | 1595 if (this.readyState == this.DONE) { |
1588 if (this.status == 200) { | 1596 if (this.status == 200) { |
1589 if (this.responseText == '$waitSignal') { | 1597 if (this.responseText == '$waitSignal') { |
1590 setTimeout(getNextTask, 500); | 1598 setTimeout(getNextTask, 500); |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1940 'exit code: ${result.exitCode}\n' | 1948 'exit code: ${result.exitCode}\n' |
1941 'stdout: ${result.stdout}\n' | 1949 'stdout: ${result.stdout}\n' |
1942 'stderr: ${result.stderr}'); | 1950 'stderr: ${result.stderr}'); |
1943 } else { | 1951 } else { |
1944 print('[$message] Successfully uploaded screenshot to $storageUrl'); | 1952 print('[$message] Successfully uploaded screenshot to $storageUrl'); |
1945 } | 1953 } |
1946 new File(screenshotFile).deleteSync(); | 1954 new File(screenshotFile).deleteSync(); |
1947 } | 1955 } |
1948 print('--------------------------------------------------------------------'); | 1956 print('--------------------------------------------------------------------'); |
1949 } | 1957 } |
OLD | NEW |