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