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

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

Issue 467643002: Browser testing: Run android content shell tests on hosts with multiple devices connected. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 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/bots/run_android_tests.sh ('k') | no next file » | 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: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 20 matching lines...) Expand all
31 31
32 /** The version of the browser - normally set when starting a browser */ 32 /** The version of the browser - normally set when starting a browser */
33 String version = ""; 33 String version = "";
34 34
35 // The path to the browser executable. 35 // The path to the browser executable.
36 String _binary; 36 String _binary;
37 37
38 /** 38 /**
39 * The underlying process - don't mess directly with this if you don't 39 * The underlying process - don't mess directly with this if you don't
40 * know what you are doing (this is an interactive process that needs 40 * know what you are doing (this is an interactive process that needs
41 * special threatment to not leak). 41 * special treatment to not leak).
42 */ 42 */
43 Process process; 43 Process process;
44 44
45 Function logger; 45 Function logger;
46 46
47 /** 47 /**
48 * Id of the browser 48 * Id of the browser
49 */ 49 */
50 String id; 50 String id;
51 51
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 'com.google.android.apps.chrome', 574 'com.google.android.apps.chrome',
575 '.Main', 575 '.Main',
576 'android.intent.action.VIEW'); 576 'android.intent.action.VIEW');
577 577
578 578
579 class AndroidBrowser extends Browser { 579 class AndroidBrowser extends Browser {
580 final bool checkedMode; 580 final bool checkedMode;
581 AdbDevice _adbDevice; 581 AdbDevice _adbDevice;
582 AndroidBrowserConfig _config; 582 AndroidBrowserConfig _config;
583 583
584 AndroidBrowser(this._adbDevice, this._config, this.checkedMode); 584 AndroidBrowser(this._adbDevice, this._config, this.checkedMode, apkPath) {
585 _binary = apkPath;
586 }
585 587
586 Future<bool> start(String url) { 588 Future<bool> start(String url) {
587 var intent = new Intent( 589 var intent = new Intent(
588 _config.action, _config.package, _config.activity, url); 590 _config.action, _config.package, _config.activity, url);
589 return _adbDevice.waitForBootCompleted().then((_) { 591 return _adbDevice.waitForBootCompleted().then((_) {
590 return _adbDevice.forceStop(_config.package); 592 return _adbDevice.forceStop(_config.package);
591 }).then((_) { 593 }).then((_) {
592 return _adbDevice.killAll(); 594 return _adbDevice.killAll();
593 }).then((_) { 595 }).then((_) {
594 return _adbDevice.adbRoot(); 596 return _adbDevice.adbRoot();
595 }).then((_) { 597 }).then((_) {
596 return _adbDevice.setProp("DART_FORWARDING_PRINT", "1"); 598 return _adbDevice.setProp("DART_FORWARDING_PRINT", "1");
597 }).then((_) { 599 }).then((_) {
598 if (checkedMode) { 600 if (checkedMode) {
599 return _adbDevice.setProp("DART_FLAGS", "--checked"); 601 return _adbDevice.setProp("DART_FLAGS", "--checked");
600 } else { 602 } else {
601 return _adbDevice.setProp("DART_FLAGS", ""); 603 return _adbDevice.setProp("DART_FLAGS", "");
602 } 604 }
603 }).then((_) { 605 }).then((_) {
606 return _adbDevice.installApk(new Path(_binary));
607 }).then((_) {
604 return _adbDevice.startActivity(intent).then((_) => true); 608 return _adbDevice.startActivity(intent).then((_) => true);
605 }); 609 });
606 } 610 }
607 611
608 Future<bool> close() { 612 Future<bool> close() {
609 if (_adbDevice != null) { 613 if (_adbDevice != null) {
610 return _adbDevice.forceStop(_config.package).then((_) { 614 return _adbDevice.forceStop(_config.package).then((_) {
611 return _adbDevice.killAll().then((_) => true); 615 return _adbDevice.killAll().then((_) => true);
612 }); 616 });
613 } 617 }
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 }); 882 });
879 }); 883 });
880 } 884 }
881 885
882 Future<List<Browser>> getBrowsers() { 886 Future<List<Browser>> getBrowsers() {
883 // TODO(kustermann): This is a hackisch way to accomplish it and should 887 // TODO(kustermann): This is a hackisch way to accomplish it and should
884 // be encapsulated 888 // be encapsulated
885 var browsersCompleter = new Completer(); 889 var browsersCompleter = new Completer();
886 var androidBrowserCreationMapping = { 890 var androidBrowserCreationMapping = {
887 'chromeOnAndroid' : (AdbDevice device) => new AndroidChrome(device), 891 'chromeOnAndroid' : (AdbDevice device) => new AndroidChrome(device),
888 'ContentShellOnAndroid' : (AdbDevice device) => 892 'ContentShellOnAndroid' : (AdbDevice device) => new AndroidBrowser(
889 new AndroidBrowser(device, contentShellOnAndroidConfig, checkedMode), 893 device,
890 'DartiumOnAndroid' : (AdbDevice device) => 894 contentShellOnAndroidConfig,
891 new AndroidBrowser(device, dartiumOnAndroidConfig, checkedMode), 895 checkedMode,
896 globalConfiguration['drt']),
897 'DartiumOnAndroid' : (AdbDevice device) => new AndroidBrowser(
898 device,
899 dartiumOnAndroidConfig,
900 checkedMode,
901 globalConfiguration['dartium']),
892 }; 902 };
893 if (androidBrowserCreationMapping.containsKey(browserName)) { 903 if (androidBrowserCreationMapping.containsKey(browserName)) {
894 AdbHelper.listDevices().then((deviceIds) { 904 AdbHelper.listDevices().then((deviceIds) {
895 if (deviceIds.length > 0) { 905 if (deviceIds.length > 0) {
896 var browsers = []; 906 var browsers = [];
897 for (int i = 0; i < deviceIds.length; i++) { 907 for (int i = 0; i < deviceIds.length; i++) {
898 var id = "BROWSER$i"; 908 var id = "BROWSER$i";
899 var device = new AdbDevice(deviceIds[i]); 909 var device = new AdbDevice(deviceIds[i]);
900 adbDeviceMapping[id] = device; 910 adbDeviceMapping[id] = device;
901 var browser = androidBrowserCreationMapping[browserName](device); 911 var browser = androidBrowserCreationMapping[browserName](device);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 } 1044 }
1035 1045
1036 void restartBrowser(String id) { 1046 void restartBrowser(String id) {
1037 var browser; 1047 var browser;
1038 var new_id = id; 1048 var new_id = id;
1039 if (browserName == 'chromeOnAndroid') { 1049 if (browserName == 'chromeOnAndroid') {
1040 browser = new AndroidChrome(adbDeviceMapping[id]); 1050 browser = new AndroidChrome(adbDeviceMapping[id]);
1041 } else if (browserName == 'ContentShellOnAndroid') { 1051 } else if (browserName == 'ContentShellOnAndroid') {
1042 browser = new AndroidBrowser(adbDeviceMapping[id], 1052 browser = new AndroidBrowser(adbDeviceMapping[id],
1043 contentShellOnAndroidConfig, 1053 contentShellOnAndroidConfig,
1044 checkedMode); 1054 checkedMode,
1055 globalConfiguration['drt']);
1045 } else if (browserName == 'DartiumOnAndroid') { 1056 } else if (browserName == 'DartiumOnAndroid') {
1046 browser = new AndroidBrowser(adbDeviceMapping[id], 1057 browser = new AndroidBrowser(adbDeviceMapping[id],
1047 dartiumOnAndroidConfig, 1058 dartiumOnAndroidConfig,
1048 checkedMode); 1059 checkedMode,
1060 globalConfiguration['dartium']);
1049 } else { 1061 } else {
1050 browserStatus.remove(id); 1062 browserStatus.remove(id);
1051 browser = getInstance(); 1063 browser = getInstance();
1052 new_id = "BROWSER$browserIdCount"; 1064 new_id = "BROWSER$browserIdCount";
1053 browserIdCount++; 1065 browserIdCount++;
1054 } 1066 }
1055 browser.id = new_id; 1067 browser.id = new_id;
1056 var status = new BrowserTestingStatus(browser); 1068 var status = new BrowserTestingStatus(browser);
1057 browserStatus[new_id] = status; 1069 browserStatus[new_id] = status;
1058 status.nextTestTimeout = createNextTestTimer(status); 1070 status.nextTestTimeout = createNextTestTimer(status);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 bool useIframe = false; 1257 bool useIframe = false;
1246 1258
1247 Function testDoneCallBack; 1259 Function testDoneCallBack;
1248 Function testStatusUpdateCallBack; 1260 Function testStatusUpdateCallBack;
1249 Function testStartedCallBack; 1261 Function testStartedCallBack;
1250 Function nextTestCallBack; 1262 Function nextTestCallBack;
1251 1263
1252 BrowserTestingServer(this.globalConfiguration, this.localIp, this.useIframe); 1264 BrowserTestingServer(this.globalConfiguration, this.localIp, this.useIframe);
1253 1265
1254 Future start() { 1266 Future start() {
1255 int port = globalConfiguration['test_driver_port']; 1267 var test_driver_port = globalConfiguration['test_driver_port'];
ricow1 2014/08/12 13:29:23 I think it sucks that we are sending in our global
1256 return HttpServer.bind(localIp, port).then((createdServer) { 1268 var test_driver_error_port = globalConfiguration['test_driver_error_port'];
1257 httpServer = createdServer; 1269 return HttpServer.bind(localIp, test_driver_port)
1258 void handler(HttpRequest request) { 1270 .then(setupDriverServer)
1259 // Don't allow caching of resources from the browser controller, i.e., 1271 .then((_) => HttpServer.bind(localIp, test_driver_error_port))
1260 // we don't want the browser to cache the result of getNextTest. 1272 .then(setupErrorServer);
1261 request.response.headers.set("Cache-Control", 1273 }
1262 "no-cache, no-store, must-revalidate"); 1274
1263 bool isReport = request.uri.path.startsWith(reportPath); 1275 void setupDriverServer(HttpServer server) {
1264 bool isStatusUpdate = request.uri.path.startsWith(statusUpdatePath); 1276 httpServer = server;
1265 if (isReport || isStatusUpdate) { 1277 void handler(HttpRequest request) {
1266 var browserId; 1278 print('Driver server received request ${request.uri}');
ricow1 2014/08/12 13:29:23 leftover print?
1267 if (isStatusUpdate) { 1279 // Don't allow caching of resources from the browser controller, i.e.,
1268 browserId = request.uri.path.substring(statusUpdatePath.length + 1); 1280 // we don't want the browser to cache the result of getNextTest.
1269 } else { 1281 request.response.headers.set("Cache-Control",
1270 browserId = request.uri.path.substring(reportPath.length + 1); 1282 "no-cache, no-store, must-revalidate");
1271 } 1283 bool isReport = request.uri.path.startsWith(reportPath);
1272 var testId = 1284 bool isStatusUpdate = request.uri.path.startsWith(statusUpdatePath);
1273 int.parse(request.uri.queryParameters["id"].split("=")[1]); 1285 if (isReport || isStatusUpdate) {
1274 handleReport( 1286 var browserId;
1275 request, browserId, testId, isStatusUpdate: isStatusUpdate); 1287 if (isStatusUpdate) {
1276 // handleReport will asynchroniously fetch the data and will handle 1288 browserId = request.uri.path.substring(statusUpdatePath.length + 1);
1277 // the closing of the streams. 1289 } else {
1278 return; 1290 browserId = request.uri.path.substring(reportPath.length + 1);
1279 } 1291 }
1280 if (request.uri.path.startsWith(startedPath)) { 1292 var testId =
1281 var browserId = request.uri.path.substring(startedPath.length + 1); 1293 int.parse(request.uri.queryParameters["id"].split("=")[1]);
1282 var testId = 1294 handleReport(
1283 int.parse(request.uri.queryParameters["id"].split("=")[1]); 1295 request, browserId, testId, isStatusUpdate: isStatusUpdate);
1284 handleStarted(request, browserId, testId); 1296 // handleReport will asynchroniously fetch the data and will handle
1285 return; 1297 // the closing of the streams.
1286 } 1298 return;
1287 var textResponse = ""; 1299 }
1288 if (request.uri.path.startsWith(driverPath)) { 1300 if (request.uri.path.startsWith(startedPath)) {
1289 var browserId = request.uri.path.substring(driverPath.length + 1); 1301 var browserId = request.uri.path.substring(startedPath.length + 1);
1290 textResponse = getDriverPage(browserId); 1302 var testId =
1291 } else if (request.uri.path.startsWith(nextTestPath)) { 1303 int.parse(request.uri.queryParameters["id"].split("=")[1]);
1292 var browserId = request.uri.path.substring(nextTestPath.length + 1); 1304 handleStarted(request, browserId, testId);
1293 textResponse = getNextTest(browserId); 1305 return;
1294 } else { 1306 }
1295 // /favicon.ico requests 1307 var textResponse = "";
1296 } 1308 if (request.uri.path.startsWith(driverPath)) {
1297 request.response.write(textResponse); 1309 var browserId = request.uri.path.substring(driverPath.length + 1);
1298 request.listen((_) {}, onDone: request.response.close); 1310 textResponse = getDriverPage(browserId);
1299 request.response.done.catchError((error) { 1311 } else if (request.uri.path.startsWith(nextTestPath)) {
1312 var browserId = request.uri.path.substring(nextTestPath.length + 1);
1313 textResponse = getNextTest(browserId);
1314 } else {
1315 // /favicon.ico requests
1316 }
1317 request.response.write(textResponse);
1318 request.listen((_) {}, onDone: request.response.close);
1319 request.response.done.catchError((error) {
1300 if (!underTermination) { 1320 if (!underTermination) {
1301 print("URI ${request.uri}"); 1321 print("URI ${request.uri}");
1302 print("Textresponse $textResponse"); 1322 print("Textresponse $textResponse");
1303 throw "Error returning content to browser: $error"; 1323 throw "Error returning content to browser: $error";
1304 } 1324 }
1305 }); 1325 });
1306 } 1326 }
1307 void errorHandler(e) { 1327 void errorHandler(e) {
1308 if (!underTermination) print("Error occured in httpserver: $e"); 1328 if (!underTermination) print("Error occured in httpserver: $e");
1309 }; 1329 }
1330 httpServer.listen(handler, onError: errorHandler);
1331 }
1310 1332
1311 httpServer.listen(handler, onError: errorHandler); 1333 void setupErrorServer(HttpServer server) {
1312 1334 errorReportingServer = server;
1313 // Set up the error reporting server that enables us to send back 1335 void errorReportingHandler(HttpRequest request) {
1314 // errors from the browser. 1336 StringBuffer buffer = new StringBuffer();
1315 port = globalConfiguration['test_driver_error_port']; 1337 request.transform(UTF8.decoder).listen((data) {
1316 return HttpServer.bind(localIp, port).then((createdReportServer) { 1338 buffer.write(data);
1317 errorReportingServer = createdReportServer; 1339 }, onDone: () {
1318 void errorReportingHandler(HttpRequest request) { 1340 String back = buffer.toString();
1319 StringBuffer buffer = new StringBuffer(); 1341 request.response.headers.set("Access-Control-Allow-Origin", "*");
1320 request.transform(UTF8.decoder).listen((data) { 1342 request.response.done.catchError((error) {
1321 buffer.write(data); 1343 DebugLogger.error("Error getting error from browser"
1322 }, onDone: () { 1344 "on uri ${request.uri.path}: $error");
1323 String back = buffer.toString(); 1345 });
1324 request.response.headers.set("Access-Control-Allow-Origin", "*"); 1346 request.response.close();
1325 request.response.done.catchError((error) { 1347 DebugLogger.error("Error from browser on : "
1326 DebugLogger.error("Error getting error from browser" 1348 "${request.uri.path}, data: $back");
1327 "on uri ${request.uri.path}: $error"); 1349 }, onError: (error) { print(error); });
1328 }); 1350 }
1329 request.response.close(); 1351 void errorHandler(e) {
1330 DebugLogger.error("Error from browser on : " 1352 if (!underTermination) print("Error occured in httpserver: $e");
1331 "${request.uri.path}, data: $back"); 1353 }
1332 }, onError: (error) { print(error); }); 1354 errorReportingServer.listen(errorReportingHandler, onError: errorHandler);
1333 }
1334 errorReportingServer.listen(errorReportingHandler,
1335 onError: errorHandler);
1336 return true;
1337 });
1338 });
1339 } 1355 }
1340 1356
1341 void handleReport(HttpRequest request, String browserId, var testId, 1357 void handleReport(HttpRequest request, String browserId, var testId,
1342 {bool isStatusUpdate}) { 1358 {bool isStatusUpdate}) {
1343 StringBuffer buffer = new StringBuffer(); 1359 StringBuffer buffer = new StringBuffer();
1344 request.transform(UTF8.decoder).listen((data) { 1360 request.transform(UTF8.decoder).listen((data) {
1345 buffer.write(data); 1361 buffer.write(data);
1346 }, onDone: () { 1362 }, onDone: () {
1347 String back = buffer.toString(); 1363 String back = buffer.toString();
1348 request.response.close(); 1364 request.response.close();
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 Dart test driver, number of tests: <div id="number"></div><br> 1602 Dart test driver, number of tests: <div id="number"></div><br>
1587 Currently executing: <div id="currently_executing"></div><br> 1603 Currently executing: <div id="currently_executing"></div><br>
1588 Unhandled error: <div id="unhandled_error"></div> 1604 Unhandled error: <div id="unhandled_error"></div>
1589 <iframe id="embedded_iframe"></iframe> 1605 <iframe id="embedded_iframe"></iframe>
1590 </body> 1606 </body>
1591 </html> 1607 </html>
1592 """; 1608 """;
1593 return driverContent; 1609 return driverContent;
1594 } 1610 }
1595 } 1611 }
OLDNEW
« no previous file with comments | « tools/bots/run_android_tests.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698