| 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 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 _logEvent("Starting ie browser on: $url"); | 464 _logEvent("Starting ie browser on: $url"); |
| 465 return getVersion().then((version) { | 465 return getVersion().then((version) { |
| 466 _logEvent("Got version: $version"); | 466 _logEvent("Got version: $version"); |
| 467 return startBrowser(binary, [url]); | 467 return startBrowser(binary, [url]); |
| 468 }); | 468 }); |
| 469 } | 469 } |
| 470 String toString() => "IE"; | 470 String toString() => "IE"; |
| 471 } | 471 } |
| 472 | 472 |
| 473 | 473 |
| 474 class AndroidBrowserConfig { |
| 475 final String name; |
| 476 final String package; |
| 477 final String activity; |
| 478 final String action; |
| 479 AndroidBrowserConfig(this.name, this.package, this.activity, this.action); |
| 480 } |
| 481 |
| 482 |
| 483 final contentShellOnAndroidConfig = new AndroidBrowserConfig( |
| 484 'ContentShellOnAndroid', |
| 485 'org.chromium.content_shell_apk', |
| 486 '.ContentShellActivity', |
| 487 'android.intent.action.VIEW'); |
| 488 |
| 489 |
| 490 final dartiumOnAndroidConfig = new AndroidBrowserConfig( |
| 491 'DartiumOnAndroid', |
| 492 'com.google.android.apps.chrome', |
| 493 '.Main', |
| 494 'android.intent.action.VIEW'); |
| 495 |
| 496 |
| 497 class AndroidBrowser extends Browser { |
| 498 AdbDevice _adbDevice; |
| 499 AndroidBrowserConfig _config; |
| 500 |
| 501 AndroidBrowser(this._adbDevice, this._config); |
| 502 |
| 503 Future<bool> start(String url) { |
| 504 var intent = new Intent( |
| 505 _config.action, _config.package, _config.activity, url); |
| 506 return _adbDevice.waitForBootCompleted().then((_) { |
| 507 return _adbDevice.forceStop(_config.package); |
| 508 }).then((_) { |
| 509 return _adbDevice.killAll(); |
| 510 }).then((_) { |
| 511 return _adbDevice.adbRoot(); |
| 512 }).then((_) { |
| 513 return _adbDevice.setProp("DART_FORWARDING_PRINT", "1"); |
| 514 }).then((_) { |
| 515 return _adbDevice.startActivity(intent).then((_) => true); |
| 516 }); |
| 517 } |
| 518 |
| 519 Future<bool> close() { |
| 520 if (_adbDevice != null) { |
| 521 return _adbDevice.forceStop(_config.package).then((_) { |
| 522 return _adbDevice.killAll().then((_) => true); |
| 523 }); |
| 524 } |
| 525 return new Future.value(true); |
| 526 } |
| 527 |
| 528 String toString() => _config.name; |
| 529 } |
| 530 |
| 531 |
| 474 class AndroidChrome extends Browser { | 532 class AndroidChrome extends Browser { |
| 475 static const String viewAction = 'android.intent.action.VIEW'; | 533 static const String viewAction = 'android.intent.action.VIEW'; |
| 476 static const String mainAction = 'android.intent.action.MAIN'; | 534 static const String mainAction = 'android.intent.action.MAIN'; |
| 477 static const String chromePackage = 'com.android.chrome'; | 535 static const String chromePackage = 'com.android.chrome'; |
| 478 static const String browserPackage = 'com.android.browser'; | 536 static const String browserPackage = 'com.android.browser'; |
| 479 static const String firefoxPackage = 'org.mozilla.firefox'; | 537 static const String firefoxPackage = 'org.mozilla.firefox'; |
| 480 static const String turnScreenOnPackage = 'com.google.dart.turnscreenon'; | 538 static const String turnScreenOnPackage = 'com.google.dart.turnscreenon'; |
| 481 | 539 |
| 482 AndroidEmulator _emulator; | 540 AndroidEmulator _emulator; |
| 483 AdbDevice _adbDevice; | 541 AdbDevice _adbDevice; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 return _adbDevice.killAll().then((_) => true); | 589 return _adbDevice.killAll().then((_) => true); |
| 532 }); | 590 }); |
| 533 } | 591 } |
| 534 return new Future.value(true); | 592 return new Future.value(true); |
| 535 } | 593 } |
| 536 | 594 |
| 537 String toString() => "chromeOnAndroid"; | 595 String toString() => "chromeOnAndroid"; |
| 538 } | 596 } |
| 539 | 597 |
| 540 | 598 |
| 541 class ContentShellOnAndroid extends Browser { | |
| 542 static const String viewAction = 'android.intent.action.VIEW'; | |
| 543 static const String contentShellPackage = 'org.chromium.content_shell_apk'; | |
| 544 | |
| 545 AdbDevice _adbDevice; | |
| 546 | |
| 547 ContentShellOnAndroid(this._adbDevice); | |
| 548 | |
| 549 Future<bool> start(String url) { | |
| 550 var contentShellIntent = new Intent( | |
| 551 viewAction, contentShellPackage, '.ContentShellActivity', url); | |
| 552 | |
| 553 return _adbDevice.waitForBootCompleted().then((_) { | |
| 554 return _adbDevice.forceStop(contentShellIntent.package); | |
| 555 }).then((_) { | |
| 556 return _adbDevice.killAll(); | |
| 557 }).then((_) { | |
| 558 return _adbDevice.adbRoot(); | |
| 559 }).then((_) { | |
| 560 return _adbDevice.setProp("DART_FORWARDING_PRINT", "1"); | |
| 561 }).then((_) { | |
| 562 return _adbDevice.startActivity(contentShellIntent).then((_) => true); | |
| 563 }); | |
| 564 } | |
| 565 | |
| 566 Future<bool> close() { | |
| 567 if (_adbDevice != null) { | |
| 568 return _adbDevice.forceStop(contentShellPackage).then((_) { | |
| 569 return _adbDevice.killAll().then((_) => true); | |
| 570 }); | |
| 571 } | |
| 572 return new Future.value(true); | |
| 573 } | |
| 574 | |
| 575 String toString() => "ContentShellOnAndroid"; | |
| 576 } | |
| 577 | |
| 578 | |
| 579 class Firefox extends Browser { | 599 class Firefox extends Browser { |
| 580 static const String enablePopUp = | 600 static const String enablePopUp = |
| 581 'user_pref("dom.disable_open_during_load", false);'; | 601 'user_pref("dom.disable_open_during_load", false);'; |
| 582 static const String disableDefaultCheck = | 602 static const String disableDefaultCheck = |
| 583 'user_pref("browser.shell.checkDefaultBrowser", false);'; | 603 'user_pref("browser.shell.checkDefaultBrowser", false);'; |
| 584 static const String disableScriptTimeLimit = | 604 static const String disableScriptTimeLimit = |
| 585 'user_pref("dom.max_script_run_time", 0);'; | 605 'user_pref("dom.max_script_run_time", 0);'; |
| 586 | 606 |
| 587 static String _binary = _getBinary(); | 607 static String _binary = _getBinary(); |
| 588 | 608 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 }); | 782 }); |
| 763 } | 783 } |
| 764 | 784 |
| 765 Future<List<Browser>> getBrowsers() { | 785 Future<List<Browser>> getBrowsers() { |
| 766 // TODO(kustermann): This is a hackisch way to accomplish it and should | 786 // TODO(kustermann): This is a hackisch way to accomplish it and should |
| 767 // be encapsulated | 787 // be encapsulated |
| 768 var browsersCompleter = new Completer(); | 788 var browsersCompleter = new Completer(); |
| 769 var androidBrowserCreationMapping = { | 789 var androidBrowserCreationMapping = { |
| 770 'chromeOnAndroid' : (AdbDevice device) => new AndroidChrome(device), | 790 'chromeOnAndroid' : (AdbDevice device) => new AndroidChrome(device), |
| 771 'ContentShellOnAndroid' : (AdbDevice device) => | 791 'ContentShellOnAndroid' : (AdbDevice device) => |
| 772 new ContentShellOnAndroid(device), | 792 new AndroidBrowser(device, contentShellOnAndroidConfig), |
| 793 'DartiumOnAndroid' : (AdbDevice device) => |
| 794 new AndroidBrowser(device, dartiumOnAndroidConfig), |
| 773 }; | 795 }; |
| 774 if (androidBrowserCreationMapping.containsKey(browserName)) { | 796 if (androidBrowserCreationMapping.containsKey(browserName)) { |
| 775 AdbHelper.listDevices().then((deviceIds) { | 797 AdbHelper.listDevices().then((deviceIds) { |
| 776 if (deviceIds.length > 0) { | 798 if (deviceIds.length > 0) { |
| 777 var browsers = []; | 799 var browsers = []; |
| 778 for (int i = 0; i < deviceIds.length; i++) { | 800 for (int i = 0; i < deviceIds.length; i++) { |
| 779 var id = "BROWSER$i"; | 801 var id = "BROWSER$i"; |
| 780 var device = new AdbDevice(deviceIds[i]); | 802 var device = new AdbDevice(deviceIds[i]); |
| 781 adbDeviceMapping[id] = device; | 803 adbDeviceMapping[id] = device; |
| 782 var browser = androidBrowserCreationMapping[browserName](device); | 804 var browser = androidBrowserCreationMapping[browserName](device); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 status.currentTest.doneCallback(browserTestOutput); | 908 status.currentTest.doneCallback(browserTestOutput); |
| 887 status.currentTest = null; | 909 status.currentTest = null; |
| 888 | 910 |
| 889 // We don't want to start a new browser if we are terminating. | 911 // We don't want to start a new browser if we are terminating. |
| 890 if (underTermination) return; | 912 if (underTermination) return; |
| 891 var browser; | 913 var browser; |
| 892 var new_id = id; | 914 var new_id = id; |
| 893 if (browserName == 'chromeOnAndroid') { | 915 if (browserName == 'chromeOnAndroid') { |
| 894 browser = new AndroidChrome(adbDeviceMapping[id]); | 916 browser = new AndroidChrome(adbDeviceMapping[id]); |
| 895 } else if (browserName == 'ContentShellOnAndroid') { | 917 } else if (browserName == 'ContentShellOnAndroid') { |
| 896 browser = new ContentShellOnAndroid(adbDeviceMapping[id]); | 918 browser = new AndroidBrowser(adbDeviceMapping[id], |
| 919 contentShellOnAndroidConfig); |
| 920 } else if (browserName == 'DartiumOnAndroid') { |
| 921 browser = new AndroidBrowser(adbDeviceMapping[id], |
| 922 dartiumOnAndroidConfig); |
| 897 } else { | 923 } else { |
| 898 browserStatus.remove(id); | 924 browserStatus.remove(id); |
| 899 browser = getInstance(); | 925 browser = getInstance(); |
| 900 new_id = "BROWSER$browserIdCount"; | 926 new_id = "BROWSER$browserIdCount"; |
| 901 browserIdCount++; | 927 browserIdCount++; |
| 902 browserStatus[new_id] = new BrowserTestingStatus(browser); | 928 browserStatus[new_id] = new BrowserTestingStatus(browser); |
| 903 } | 929 } |
| 904 browser.id = new_id; | 930 browser.id = new_id; |
| 905 browser.start(testingServer.getDriverUrl(new_id)).then((success) { | 931 browser.start(testingServer.getDriverUrl(new_id)).then((success) { |
| 906 // We may have started terminating in the mean time. | 932 // We may have started terminating in the mean time. |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 Dart test driver, number of tests: <div id="number"></div><br> | 1351 Dart test driver, number of tests: <div id="number"></div><br> |
| 1326 Currently executing: <div id="currently_executing"></div><br> | 1352 Currently executing: <div id="currently_executing"></div><br> |
| 1327 Unhandled error: <div id="unhandled_error"></div> | 1353 Unhandled error: <div id="unhandled_error"></div> |
| 1328 <iframe id="embedded_iframe"></iframe> | 1354 <iframe id="embedded_iframe"></iframe> |
| 1329 </body> | 1355 </body> |
| 1330 </html> | 1356 </html> |
| 1331 """; | 1357 """; |
| 1332 return driverContent; | 1358 return driverContent; |
| 1333 } | 1359 } |
| 1334 } | 1360 } |
| OLD | NEW |