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

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

Issue 29773006: Changes to run tests on Dartium content shell on Android. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 1 month 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
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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 return _adbDevice.forceStop(chromePackage).then((_) { 524 return _adbDevice.forceStop(chromePackage).then((_) {
525 return _adbDevice.killAll().then((_) => true); 525 return _adbDevice.killAll().then((_) => true);
526 }); 526 });
527 } 527 }
528 return new Future.value(true); 528 return new Future.value(true);
529 } 529 }
530 530
531 String toString() => "chromeOnAndroid"; 531 String toString() => "chromeOnAndroid";
532 } 532 }
533 533
534
535 class drtOnAndroid extends Browser {
kustermann 2013/10/24 09:36:00 drtOnAndroid => DrtOnAndroid Since drt has been r
zra 2013/10/24 15:34:50 Renamed ContentShellOnAndroid
536 static const String viewAction = 'android.intent.action.VIEW';
537 static const String contentShellPackage = 'org.chromium.content_shell_apk';
538
539 AndroidEmulator _emulator;
kustermann 2013/10/24 09:36:00 Where is this _emulator set / used ? Did you try
zra 2013/10/24 15:34:50 Removed
540 AdbDevice _adbDevice;
541
542 drtOnAndroid(this._adbDevice);
543
544 Future<bool> start(String url) {
545 var contentShellIntent = new Intent(
546 viewAction, contentShellPackage, '.ContentShellActivity', url);
547
548 return _adbDevice.waitForBootCompleted().then((_) {
549 return _adbDevice.forceStop(contentShellIntent.package);
550 }).then((_) {
551 return _adbDevice.killAll();
552 }).then((_) {
553 return _adbDevice.setProp("DART_FORWARDING_PRINT", "1");
kustermann 2013/10/24 09:36:00 Are you sure that a 'adb shell setprop' is setting
zra 2013/10/24 15:34:50 In a separate CL (https://codereview.chromium.org/
554 }).then((_) {
555 return _adbDevice.startActivity(contentShellIntent).then((_) => true);
556 });
557 }
558
559 Future<bool> close() {
560 if (_adbDevice != null) {
561 return _adbDevice.forceStop(contentShellPackage).then((_) {
562 return _adbDevice.killAll().then((_) => true);
563 });
564 }
565 return new Future.value(true);
566 }
567
568 String toString() => "drtOnAndroid";
569 }
570
571
534 class Firefox extends Browser { 572 class Firefox extends Browser {
535 static const String enablePopUp = 573 static const String enablePopUp =
536 'user_pref("dom.disable_open_during_load", false);'; 574 'user_pref("dom.disable_open_during_load", false);';
537 static const String disableDefaultCheck = 575 static const String disableDefaultCheck =
538 'user_pref("browser.shell.checkDefaultBrowser", false);'; 576 'user_pref("browser.shell.checkDefaultBrowser", false);';
539 static const String disableScriptTimeLimit = 577 static const String disableScriptTimeLimit =
540 'user_pref("dom.max_script_run_time", 0);'; 578 'user_pref("dom.max_script_run_time", 0);';
541 579
542 static String _binary = _getBinary(); 580 static String _binary = _getBinary();
543 581
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 BrowserTestRunner(this.globalConfiguration, 721 BrowserTestRunner(this.globalConfiguration,
684 this.localIp, 722 this.localIp,
685 this.browserName, 723 this.browserName,
686 this.maxNumBrowsers); 724 this.maxNumBrowsers);
687 725
688 Future<bool> start() { 726 Future<bool> start() {
689 // 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
690 // instead. 728 // instead.
691 bool useIframe = 729 bool useIframe =
692 !Browser.BROWSERS_WITH_WINDOW_SUPPORT.contains(browserName); 730 !Browser.BROWSERS_WITH_WINDOW_SUPPORT.contains(browserName);
693 testingServer = new BrowserTestingServer(localIp, useIframe); 731 testingServer = new BrowserTestingServer(
732 globalConfiguration, localIp, useIframe);
694 return testingServer.start().then((_) { 733 return testingServer.start().then((_) {
695 testingServer.testDoneCallBack = handleResults; 734 testingServer.testDoneCallBack = handleResults;
696 testingServer.testStartedCallBack = handleStarted; 735 testingServer.testStartedCallBack = handleStarted;
697 testingServer.nextTestCallBack = getNextTest; 736 testingServer.nextTestCallBack = getNextTest;
698 return getBrowsers().then((browsers) { 737 return getBrowsers().then((browsers) {
699 var futures = []; 738 var futures = [];
700 for (var browser in browsers) { 739 for (var browser in browsers) {
701 var url = testingServer.getDriverUrl(browser.id); 740 var url = testingServer.getDriverUrl(browser.id);
702 var future = browser.start(url).then((success) { 741 var future = browser.start(url).then((success) {
703 if (success) { 742 if (success) {
(...skipping 25 matching lines...) Expand all
729 var browser = new AndroidChrome(device); 768 var browser = new AndroidChrome(device);
730 browsers.add(browser); 769 browsers.add(browser);
731 // We store this in case we need to kill the browser. 770 // We store this in case we need to kill the browser.
732 browser.id = id; 771 browser.id = id;
733 } 772 }
734 browsersCompleter.complete(browsers); 773 browsersCompleter.complete(browsers);
735 } else { 774 } else {
736 throw new StateError("No android devices found."); 775 throw new StateError("No android devices found.");
737 } 776 }
738 }); 777 });
778 } else if (browserName == 'drtOnAndroid') {
kustermann 2013/10/24 09:36:00 There is no reason to duplicate this code. You cou
zra 2013/10/24 15:34:50 Done.
779 AdbHelper.listDevices().then((deviceIds) {
780 if (deviceIds.length > 0) {
781 var browsers = [];
782 for (int i = 0; i < deviceIds.length; i++) {
783 var id = "BROWSER$i";
784 var device = new AdbDevice(deviceIds[i]);
785 adbDeviceMapping[id] = device;
786 var browser = new drtOnAndroid(device);
787 browsers.add(browser);
788 // We store this in case we need to kill the browser.
789 browser.id = id;
790 }
791 browsersCompleter.complete(browsers);
792 } else {
793 throw new StateError("No android devices found.");
794 }
795 });
739 } else { 796 } else {
740 var browsers = []; 797 var browsers = [];
741 for (int i = 0; i < maxNumBrowsers; i++) { 798 for (int i = 0; i < maxNumBrowsers; i++) {
742 var id = "BROWSER$browserIdCount"; 799 var id = "BROWSER$browserIdCount";
743 browserIdCount++; 800 browserIdCount++;
744 var browser = getInstance(); 801 var browser = getInstance();
745 browsers.add(browser); 802 browsers.add(browser);
746 // We store this in case we need to kill the browser. 803 // We store this in case we need to kill the browser.
747 browser.id = id; 804 browser.id = id;
748 } 805 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 didTimeout: true); 889 didTimeout: true);
833 status.currentTest.doneCallback(browserTestOutput); 890 status.currentTest.doneCallback(browserTestOutput);
834 status.currentTest = null; 891 status.currentTest = null;
835 892
836 // We don't want to start a new browser if we are terminating. 893 // We don't want to start a new browser if we are terminating.
837 if (underTermination) return; 894 if (underTermination) return;
838 var browser; 895 var browser;
839 var new_id = id; 896 var new_id = id;
840 if (browserName == 'chromeOnAndroid') { 897 if (browserName == 'chromeOnAndroid') {
841 browser = new AndroidChrome(adbDeviceMapping[id]); 898 browser = new AndroidChrome(adbDeviceMapping[id]);
899 } else if (browserName == 'drtOnAndroid') {
900 browser = new drtOnAndroid(adbDeviceMapping[id]);
842 } else { 901 } else {
843 browserStatus.remove(id); 902 browserStatus.remove(id);
844 browser = getInstance(); 903 browser = getInstance();
845 new_id = "BROWSER$browserIdCount"; 904 new_id = "BROWSER$browserIdCount";
846 browserIdCount++; 905 browserIdCount++;
847 browserStatus[new_id] = new BrowserTestingStatus(browser); 906 browserStatus[new_id] = new BrowserTestingStatus(browser);
848 } 907 }
849 browser.id = new_id; 908 browser.id = new_id;
850 browser.start(testingServer.getDriverUrl(new_id)).then((success) { 909 browser.start(testingServer.getDriverUrl(new_id)).then((success) {
851 // We may have started terminating in the mean time. 910 // We may have started terminating in the mean time.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 } 1006 }
948 1007
949 Browser getInstance() { 1008 Browser getInstance() {
950 var browser = new Browser.byName(browserName, globalConfiguration); 1009 var browser = new Browser.byName(browserName, globalConfiguration);
951 browser.logger = logger; 1010 browser.logger = logger;
952 return browser; 1011 return browser;
953 } 1012 }
954 } 1013 }
955 1014
956 class BrowserTestingServer { 1015 class BrowserTestingServer {
1016 final Map globalConfiguration;
957 /// Interface of the testing server: 1017 /// Interface of the testing server:
958 /// 1018 ///
959 /// GET /driver/BROWSER_ID -- This will get the driver page to fetch 1019 /// GET /driver/BROWSER_ID -- This will get the driver page to fetch
960 /// and run tests ... 1020 /// and run tests ...
961 /// GET /next_test/BROWSER_ID -- returns "WAIT" "TERMINATE" or "url#id" 1021 /// GET /next_test/BROWSER_ID -- returns "WAIT" "TERMINATE" or "url#id"
962 /// where url is the test to run, and id is the id of the test. 1022 /// where url is the test to run, and id is the id of the test.
963 /// If there are currently no available tests the waitSignal is send 1023 /// If there are currently no available tests the waitSignal is send
964 /// back. If we are in the process of terminating the terminateSignal 1024 /// back. If we are in the process of terminating the terminateSignal
965 /// is send back and the browser will stop requesting new tasks. 1025 /// is send back and the browser will stop requesting new tasks.
966 /// POST /report/BROWSER_ID?id=NUM -- sends back the dom of the executed 1026 /// POST /report/BROWSER_ID?id=NUM -- sends back the dom of the executed
(...skipping 11 matching lines...) Expand all
978 var testCount = 0; 1038 var testCount = 0;
979 var httpServer; 1039 var httpServer;
980 var errorReportingServer; 1040 var errorReportingServer;
981 bool underTermination = false; 1041 bool underTermination = false;
982 bool useIframe = false; 1042 bool useIframe = false;
983 1043
984 Function testDoneCallBack; 1044 Function testDoneCallBack;
985 Function testStartedCallBack; 1045 Function testStartedCallBack;
986 Function nextTestCallBack; 1046 Function nextTestCallBack;
987 1047
988 BrowserTestingServer(this.localIp, this.useIframe); 1048 BrowserTestingServer(this.globalConfiguration, this.localIp, this.useIframe);
989 1049
990 Future start() { 1050 Future start() {
991 return HttpServer.bind(localIp, 0).then((createdServer) { 1051 int port = int.parse(globalConfiguration['test_driver_port']);
1052 return HttpServer.bind(localIp, port).then((createdServer) {
992 httpServer = createdServer; 1053 httpServer = createdServer;
993 void handler(HttpRequest request) { 1054 void handler(HttpRequest request) {
994 // Don't allow caching of resources from the browser controller, i.e., 1055 // Don't allow caching of resources from the browser controller, i.e.,
995 // we don't want the browser to cache the result of getNextTest. 1056 // we don't want the browser to cache the result of getNextTest.
996 request.response.headers.set("Cache-Control", 1057 request.response.headers.set("Cache-Control",
997 "no-cache, no-store, must-revalidate"); 1058 "no-cache, no-store, must-revalidate");
998 if (request.uri.path.startsWith(reportPath)) { 1059 if (request.uri.path.startsWith(reportPath)) {
999 var browserId = request.uri.path.substring(reportPath.length + 1); 1060 var browserId = request.uri.path.substring(reportPath.length + 1);
1000 var testId = 1061 var testId =
1001 int.parse(request.uri.queryParameters["id"].split("=")[1]); 1062 int.parse(request.uri.queryParameters["id"].split("=")[1]);
(...skipping 30 matching lines...) Expand all
1032 }); 1093 });
1033 } 1094 }
1034 void errorHandler(e) { 1095 void errorHandler(e) {
1035 if (!underTermination) print("Error occured in httpserver: $e"); 1096 if (!underTermination) print("Error occured in httpserver: $e");
1036 }; 1097 };
1037 1098
1038 httpServer.listen(handler, onError: errorHandler); 1099 httpServer.listen(handler, onError: errorHandler);
1039 1100
1040 // Set up the error reporting server that enables us to send back 1101 // Set up the error reporting server that enables us to send back
1041 // errors from the browser. 1102 // errors from the browser.
1042 return HttpServer.bind(localIp, 0).then((createdReportServer) { 1103 port = int.parse(globalConfiguration['test_driver_error_port']);
1104 return HttpServer.bind(localIp, port).then((createdReportServer) {
1043 errorReportingServer = createdReportServer; 1105 errorReportingServer = createdReportServer;
1044 void errorReportingHandler(HttpRequest request) { 1106 void errorReportingHandler(HttpRequest request) {
1045 StringBuffer buffer = new StringBuffer(); 1107 StringBuffer buffer = new StringBuffer();
1046 request.transform(UTF8.decoder).listen((data) { 1108 request.transform(UTF8.decoder).listen((data) {
1047 buffer.write(data); 1109 buffer.write(data);
1048 }, onDone: () { 1110 }, onDone: () {
1049 String back = buffer.toString(); 1111 String back = buffer.toString();
1050 request.response.headers.set("Access-Control-Allow-Origin", "*"); 1112 request.response.headers.set("Access-Control-Allow-Origin", "*");
1051 request.response.done.catchError((error) { 1113 request.response.done.catchError((error) {
1052 DebugLogger.error("Error getting error from browser" 1114 DebugLogger.error("Error getting error from browser"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 Dart test driver, number of tests: <div id="number"></div><br> 1328 Dart test driver, number of tests: <div id="number"></div><br>
1267 Currently executing: <div id="currently_executing"></div><br> 1329 Currently executing: <div id="currently_executing"></div><br>
1268 Unhandled error: <div id="unhandled_error"></div> 1330 Unhandled error: <div id="unhandled_error"></div>
1269 <iframe id="embedded_iframe"></iframe> 1331 <iframe id="embedded_iframe"></iframe>
1270 </body> 1332 </body>
1271 </html> 1333 </html>
1272 """; 1334 """;
1273 return driverContent; 1335 return driverContent;
1274 } 1336 }
1275 } 1337 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698