| 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, JSON; | 7 import "dart:convert" show LineSplitter, UTF8, JSON; |
| 8 import "dart:core"; | 8 import "dart:core"; |
| 9 import "dart:io"; | 9 import "dart:io"; |
| 10 | 10 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 */ | 242 */ |
| 243 BrowserOutput get allBrowserOutput => _allBrowserOutput; | 243 BrowserOutput get allBrowserOutput => _allBrowserOutput; |
| 244 BrowserOutput get testBrowserOutput => _testBrowserOutput; | 244 BrowserOutput get testBrowserOutput => _testBrowserOutput; |
| 245 | 245 |
| 246 void resetTestBrowserOutput() { | 246 void resetTestBrowserOutput() { |
| 247 _testBrowserOutput = new BrowserOutput(); | 247 _testBrowserOutput = new BrowserOutput(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 String toString(); | 250 String toString(); |
| 251 | 251 |
| 252 /** | |
| 253 * Identifies the device the browser is running on. | |
| 254 * Used for testing on android devices. | |
| 255 */ | |
| 256 String get deviceIdMessage => ""; | |
| 257 | |
| 258 /** Starts the browser loading the given url */ | 252 /** Starts the browser loading the given url */ |
| 259 Future<bool> start(String url); | 253 Future<bool> start(String url); |
| 260 } | 254 } |
| 261 | 255 |
| 262 class Safari extends Browser { | 256 class Safari extends Browser { |
| 263 /** | 257 /** |
| 264 * We get the safari version by parsing a version file | 258 * We get the safari version by parsing a version file |
| 265 */ | 259 */ |
| 266 static const String versionFile = | 260 static const String versionFile = |
| 267 "/Applications/Safari.app/Contents/version.plist"; | 261 "/Applications/Safari.app/Contents/version.plist"; |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 Future<bool> close() { | 614 Future<bool> close() { |
| 621 if (_adbDevice != null) { | 615 if (_adbDevice != null) { |
| 622 return _adbDevice.forceStop(_config.package).then((_) { | 616 return _adbDevice.forceStop(_config.package).then((_) { |
| 623 return _adbDevice.killAll().then((_) => true); | 617 return _adbDevice.killAll().then((_) => true); |
| 624 }); | 618 }); |
| 625 } | 619 } |
| 626 return new Future.value(true); | 620 return new Future.value(true); |
| 627 } | 621 } |
| 628 | 622 |
| 629 String toString() => _config.name; | 623 String toString() => _config.name; |
| 630 | |
| 631 String get deviceIdMessage => | |
| 632 'Android device id: ${_adbDevice.deviceId}\n'; | |
| 633 } | 624 } |
| 634 | 625 |
| 635 | 626 |
| 636 class AndroidChrome extends Browser { | 627 class AndroidChrome extends Browser { |
| 637 static const String viewAction = 'android.intent.action.VIEW'; | 628 static const String viewAction = 'android.intent.action.VIEW'; |
| 638 static const String mainAction = 'android.intent.action.MAIN'; | 629 static const String mainAction = 'android.intent.action.MAIN'; |
| 639 static const String chromePackage = 'com.android.chrome'; | 630 static const String chromePackage = 'com.android.chrome'; |
| 640 static const String browserPackage = 'com.android.browser'; | 631 static const String browserPackage = 'com.android.browser'; |
| 641 static const String firefoxPackage = 'org.mozilla.firefox'; | 632 static const String firefoxPackage = 'org.mozilla.firefox'; |
| 642 static const String turnScreenOnPackage = 'com.google.dart.turnscreenon'; | 633 static const String turnScreenOnPackage = 'com.google.dart.turnscreenon'; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 Future<bool> close() { | 681 Future<bool> close() { |
| 691 if (_adbDevice != null) { | 682 if (_adbDevice != null) { |
| 692 return _adbDevice.forceStop(chromePackage).then((_) { | 683 return _adbDevice.forceStop(chromePackage).then((_) { |
| 693 return _adbDevice.killAll().then((_) => true); | 684 return _adbDevice.killAll().then((_) => true); |
| 694 }); | 685 }); |
| 695 } | 686 } |
| 696 return new Future.value(true); | 687 return new Future.value(true); |
| 697 } | 688 } |
| 698 | 689 |
| 699 String toString() => "chromeOnAndroid"; | 690 String toString() => "chromeOnAndroid"; |
| 700 | |
| 701 String get deviceIdMessage => | |
| 702 'Android device id: ${_adbDevice.deviceId}\n'; | |
| 703 } | 691 } |
| 704 | 692 |
| 705 | 693 |
| 706 class Firefox extends Browser { | 694 class Firefox extends Browser { |
| 707 static const String enablePopUp = | 695 static const String enablePopUp = |
| 708 'user_pref("dom.disable_open_during_load", false);'; | 696 'user_pref("dom.disable_open_during_load", false);'; |
| 709 static const String disableDefaultCheck = | 697 static const String disableDefaultCheck = |
| 710 'user_pref("browser.shell.checkDefaultBrowser", false);'; | 698 'user_pref("browser.shell.checkDefaultBrowser", false);'; |
| 711 static const String disableScriptTimeLimit = | 699 static const String disableScriptTimeLimit = |
| 712 'user_pref("dom.max_script_run_time", 0);'; | 700 'user_pref("dom.max_script_run_time", 0);'; |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 print("Last test id was ${status.lastTest.id} for " | 981 print("Last test id was ${status.lastTest.id} for " |
| 994 "${status.currentTest.url}"); | 982 "${status.currentTest.url}"); |
| 995 throw("This should never happen, wrong test id"); | 983 throw("This should never happen, wrong test id"); |
| 996 } | 984 } |
| 997 testCache[testId] = status.currentTest.url; | 985 testCache[testId] = status.currentTest.url; |
| 998 | 986 |
| 999 // Report that the test is finished now | 987 // Report that the test is finished now |
| 1000 var browserTestOutput = new BrowserTestOutput( | 988 var browserTestOutput = new BrowserTestOutput( |
| 1001 status.currentTest.delayUntilTestStarted, | 989 status.currentTest.delayUntilTestStarted, |
| 1002 status.currentTest.stopwatch.elapsed, | 990 status.currentTest.stopwatch.elapsed, |
| 1003 status.browser.deviceIdMessage + output, | 991 output, |
| 1004 status.browser.testBrowserOutput); | 992 status.browser.testBrowserOutput); |
| 1005 status.currentTest.doneCallback(browserTestOutput); | 993 status.currentTest.doneCallback(browserTestOutput); |
| 1006 | 994 |
| 1007 status.lastTest = status.currentTest; | 995 status.lastTest = status.currentTest; |
| 1008 status.currentTest = null; | 996 status.currentTest = null; |
| 1009 status.nextTestTimeout = createNextTestTimer(status); | 997 status.nextTestTimeout = createNextTestTimer(status); |
| 1010 } else { | 998 } else { |
| 1011 print("\nThis is bad, should never happen, handleResult no test"); | 999 print("\nThis is bad, should never happen, handleResult no test"); |
| 1012 print("URL: ${status.lastTest.url}"); | 1000 print("URL: ${status.lastTest.url}"); |
| 1013 print(output); | 1001 print(output); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 // We simply kill the browser and starts up a new one! | 1033 // We simply kill the browser and starts up a new one! |
| 1046 // We could be smarter here, but it does not seems like it is worth it. | 1034 // We could be smarter here, but it does not seems like it is worth it. |
| 1047 if (status.timeout) { | 1035 if (status.timeout) { |
| 1048 DebugLogger.error( | 1036 DebugLogger.error( |
| 1049 "Got test timeout for an already restarting browser"); | 1037 "Got test timeout for an already restarting browser"); |
| 1050 return; | 1038 return; |
| 1051 } | 1039 } |
| 1052 status.timeout = true; | 1040 status.timeout = true; |
| 1053 timedOut.add(status.currentTest.url); | 1041 timedOut.add(status.currentTest.url); |
| 1054 var id = status.browser.id; | 1042 var id = status.browser.id; |
| 1055 String deviceMessage = status.browser.deviceIdMessage; | |
| 1056 | 1043 |
| 1057 status.currentTest.stopwatch.stop(); | 1044 status.currentTest.stopwatch.stop(); |
| 1058 status.browser.close().then((_) { | 1045 status.browser.close().then((_) { |
| 1059 var lastKnownMessage = | 1046 var lastKnownMessage = |
| 1060 'Dom could not be fetched, since the test timed out.'; | 1047 'Dom could not be fetched, since the test timed out.'; |
| 1061 if (status.currentTest.lastKnownMessage.length > 0) { | 1048 if (status.currentTest.lastKnownMessage.length > 0) { |
| 1062 lastKnownMessage = status.currentTest.lastKnownMessage; | 1049 lastKnownMessage = status.currentTest.lastKnownMessage; |
| 1063 } | 1050 } |
| 1064 // Wait until the browser is closed before reporting the test as timeout. | 1051 // Wait until the browser is closed before reporting the test as timeout. |
| 1065 // This will enable us to capture stdout/stderr from the browser | 1052 // This will enable us to capture stdout/stderr from the browser |
| 1066 // (which might provide us with information about what went wrong). | 1053 // (which might provide us with information about what went wrong). |
| 1067 var browserTestOutput = new BrowserTestOutput( | 1054 var browserTestOutput = new BrowserTestOutput( |
| 1068 status.currentTest.delayUntilTestStarted, | 1055 status.currentTest.delayUntilTestStarted, |
| 1069 status.currentTest.stopwatch.elapsed, | 1056 status.currentTest.stopwatch.elapsed, |
| 1070 deviceMessage + lastKnownMessage, | 1057 lastKnownMessage, |
| 1071 status.browser.testBrowserOutput, | 1058 status.browser.testBrowserOutput, |
| 1072 didTimeout: true); | 1059 didTimeout: true); |
| 1073 status.currentTest.doneCallback(browserTestOutput); | 1060 status.currentTest.doneCallback(browserTestOutput); |
| 1074 status.lastTest = status.currentTest; | 1061 status.lastTest = status.currentTest; |
| 1075 status.currentTest = null; | 1062 status.currentTest = null; |
| 1076 | 1063 |
| 1077 // We don't want to start a new browser if we are terminating. | 1064 // We don't want to start a new browser if we are terminating. |
| 1078 if (underTermination) return; | 1065 if (underTermination) return; |
| 1079 restartBrowser(id); | 1066 restartBrowser(id); |
| 1080 }); | 1067 }); |
| (...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1779 </div> | 1766 </div> |
| 1780 <div id="embedded_iframe_div" class="test box"> | 1767 <div id="embedded_iframe_div" class="test box"> |
| 1781 <iframe style="width:100%;height:100%;" id="embedded_iframe"></iframe> | 1768 <iframe style="width:100%;height:100%;" id="embedded_iframe"></iframe> |
| 1782 </div> | 1769 </div> |
| 1783 </body> | 1770 </body> |
| 1784 </html> | 1771 </html> |
| 1785 """; | 1772 """; |
| 1786 return driverContent; | 1773 return driverContent; |
| 1787 } | 1774 } |
| 1788 } | 1775 } |
| OLD | NEW |