| 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:core"; | 7 import "dart:core"; |
| 8 import "dart:io"; | 8 import "dart:io"; |
| 9 | 9 |
| 10 import 'android.dart'; | 10 import 'android.dart'; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 _logEvent("Close called on browser"); | 91 _logEvent("Close called on browser"); |
| 92 if (process != null) { | 92 if (process != null) { |
| 93 if (process.kill(ProcessSignal.SIGKILL)) { | 93 if (process.kill(ProcessSignal.SIGKILL)) { |
| 94 _logEvent("Successfully sent kill signal to process."); | 94 _logEvent("Successfully sent kill signal to process."); |
| 95 } else { | 95 } else { |
| 96 _logEvent("Sending kill signal failed."); | 96 _logEvent("Sending kill signal failed."); |
| 97 } | 97 } |
| 98 return done; | 98 return done; |
| 99 } else { | 99 } else { |
| 100 _logEvent("The process is already dead."); | 100 _logEvent("The process is already dead."); |
| 101 return new Future.immediate(true); | 101 return new Future.value(true); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 /** | 105 /** |
| 106 * Start the browser using the supplied argument. | 106 * Start the browser using the supplied argument. |
| 107 * This sets up the error handling and usage logging. | 107 * This sets up the error handling and usage logging. |
| 108 */ | 108 */ |
| 109 Future<bool> startBrowser(String command, List<String> arguments) { | 109 Future<bool> startBrowser(String command, List<String> arguments) { |
| 110 return Process.start(command, arguments).then((startedProcess) { | 110 return Process.start(command, arguments).then((startedProcess) { |
| 111 process = startedProcess; | 111 process = startedProcess; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 String toString(); | 164 String toString(); |
| 165 /** Starts the browser loading the given url */ | 165 /** Starts the browser loading the given url */ |
| 166 Future<bool> start(String url); | 166 Future<bool> start(String url); |
| 167 } | 167 } |
| 168 | 168 |
| 169 class Safari extends Browser { | 169 class Safari extends Browser { |
| 170 /** | 170 /** |
| 171 * The binary used to run safari - changing this can be nececcary for | 171 * The binary used to run safari - changing this can be nececcary for |
| 172 * testing or using non standard safari installation. | 172 * testing or using non standard safari installation. |
| 173 */ | 173 */ |
| 174 const String binary = "/Applications/Safari.app/Contents/MacOS/Safari"; | 174 static const String binary = "/Applications/Safari.app/Contents/MacOS/Safari"; |
| 175 | 175 |
| 176 /** | 176 /** |
| 177 * We get the safari version by parsing a version file | 177 * We get the safari version by parsing a version file |
| 178 */ | 178 */ |
| 179 const String versionFile = "/Applications/Safari.app/Contents/version.plist"; | 179 static const String versionFile = |
| 180 "/Applications/Safari.app/Contents/version.plist"; |
| 180 | 181 |
| 181 /** | 182 /** |
| 182 * Directories where safari stores state. We delete these if the deleteCache | 183 * Directories where safari stores state. We delete these if the deleteCache |
| 183 * is set | 184 * is set |
| 184 */ | 185 */ |
| 185 static const List<String> CACHE_DIRECTORIES = | 186 static const List<String> CACHE_DIRECTORIES = |
| 186 const ["Library/Caches/com.apple.Safari", | 187 const ["Library/Caches/com.apple.Safari", |
| 187 "Library/Safari", | 188 "Library/Safari", |
| 188 "Library/Saved Application State/com.apple.Safari.savedState", | 189 "Library/Saved Application State/com.apple.Safari.savedState", |
| 189 "Library/Caches/Metadata/Safari"]; | 190 "Library/Caches/Metadata/Safari"]; |
| 190 | 191 |
| 191 | 192 |
| 192 Future<bool> allowPopUps() { | 193 Future<bool> allowPopUps() { |
| 193 var command = "defaults"; | 194 var command = "defaults"; |
| 194 var args = ["write", "com.apple.safari", | 195 var args = ["write", "com.apple.safari", |
| 195 "com.apple.Safari.ContentPageGroupIdentifier." | 196 "com.apple.Safari.ContentPageGroupIdentifier." |
| 196 "WebKit2JavaScriptCanOpenWindowsAutomatically", | 197 "WebKit2JavaScriptCanOpenWindowsAutomatically", |
| 197 "1"]; | 198 "1"]; |
| 198 return Process.run(command, args).then((result) { | 199 return Process.run(command, args).then((result) { |
| 199 if (result.exitCode != 0) { | 200 if (result.exitCode != 0) { |
| 200 _logEvent("Could not disable pop-up blocking for safari"); | 201 _logEvent("Could not disable pop-up blocking for safari"); |
| 201 return false; | 202 return false; |
| 202 } | 203 } |
| 203 return true; | 204 return true; |
| 204 }); | 205 }); |
| 205 } | 206 } |
| 206 | 207 |
| 207 Future<bool> deleteIfExists(Iterator<String> paths) { | 208 Future<bool> deleteIfExists(Iterator<String> paths) { |
| 208 if (!paths.moveNext()) return new Future.immediate(true); | 209 if (!paths.moveNext()) return new Future.value(true); |
| 209 Directory directory = new Directory(paths.current); | 210 Directory directory = new Directory(paths.current); |
| 210 return directory.exists().then((exists) { | 211 return directory.exists().then((exists) { |
| 211 if (exists) { | 212 if (exists) { |
| 212 _logEvent("Deleting ${paths.current}"); | 213 _logEvent("Deleting ${paths.current}"); |
| 213 return directory.delete(recursive: true) | 214 return directory.delete(recursive: true) |
| 214 .then((_) => deleteIfExists(paths)) | 215 .then((_) => deleteIfExists(paths)) |
| 215 .catchError((error) { | 216 .catchError((error) { |
| 216 _logEvent("Failure trying to delete ${paths.current}: $error"); | 217 _logEvent("Failure trying to delete ${paths.current}: $error"); |
| 217 return false; | 218 return false; |
| 218 }); | 219 }); |
| 219 } else { | 220 } else { |
| 220 _logEvent("${paths.current} is not present"); | 221 _logEvent("${paths.current} is not present"); |
| 221 return deleteIfExists(paths); | 222 return deleteIfExists(paths); |
| 222 } | 223 } |
| 223 }); | 224 }); |
| 224 } | 225 } |
| 225 | 226 |
| 226 // Clears the cache if the static deleteCache flag is set. | 227 // Clears the cache if the static deleteCache flag is set. |
| 227 // Returns false if the command to actually clear the cache did not complete. | 228 // Returns false if the command to actually clear the cache did not complete. |
| 228 Future<bool> clearCache() { | 229 Future<bool> clearCache() { |
| 229 if (!deleteCache) return new Future.immediate(true); | 230 if (!deleteCache) return new Future.value(true); |
| 230 var home = Platform.environment['HOME']; | 231 var home = Platform.environment['HOME']; |
| 231 Iterator iterator = CACHE_DIRECTORIES.map((s) => "$home/$s").iterator; | 232 Iterator iterator = CACHE_DIRECTORIES.map((s) => "$home/$s").iterator; |
| 232 return deleteIfExists(iterator); | 233 return deleteIfExists(iterator); |
| 233 } | 234 } |
| 234 | 235 |
| 235 Future<String> getVersion() { | 236 Future<String> getVersion() { |
| 236 /** | 237 /** |
| 237 * Example of the file: | 238 * Example of the file: |
| 238 * <?xml version="1.0" encoding="UTF-8"?> | 239 * <?xml version="1.0" encoding="UTF-8"?> |
| 239 * <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.co
m/DTDs/PropertyList-1.0.dtd"> | 240 * <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.co
m/DTDs/PropertyList-1.0.dtd"> |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 static bool deleteCache = false; | 309 static bool deleteCache = false; |
| 309 | 310 |
| 310 } | 311 } |
| 311 | 312 |
| 312 | 313 |
| 313 class Chrome extends Browser { | 314 class Chrome extends Browser { |
| 314 /** | 315 /** |
| 315 * The binary used to run chrome - changing this can be nececcary for | 316 * The binary used to run chrome - changing this can be nececcary for |
| 316 * testing or using non standard chrome installation. | 317 * testing or using non standard chrome installation. |
| 317 */ | 318 */ |
| 318 const String binary = "google-chrome"; | 319 static const String binary = "google-chrome"; |
| 319 | 320 |
| 320 Future<bool> start(String url) { | 321 Future<bool> start(String url) { |
| 321 _logEvent("Starting chrome browser on: $url"); | 322 _logEvent("Starting chrome browser on: $url"); |
| 322 // Get the version and log that. | 323 // Get the version and log that. |
| 323 return Process.run(binary, ["--version"]).then((var versionResult) { | 324 return Process.run(binary, ["--version"]).then((var versionResult) { |
| 324 if (versionResult.exitCode != 0) { | 325 if (versionResult.exitCode != 0) { |
| 325 _logEvent("Failed to chrome get version"); | 326 _logEvent("Failed to chrome get version"); |
| 326 _logEvent("Make sure $binary is a valid program for running chrome"); | 327 _logEvent("Make sure $binary is a valid program for running chrome"); |
| 327 return new Future.value(false); | 328 return new Future.value(false); |
| 328 } | 329 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 340 }).catchError((e) { | 341 }).catchError((e) { |
| 341 _logEvent("Running $binary --version failed with $e"); | 342 _logEvent("Running $binary --version failed with $e"); |
| 342 return false; | 343 return false; |
| 343 }); | 344 }); |
| 344 } | 345 } |
| 345 | 346 |
| 346 String toString() => "Chrome"; | 347 String toString() => "Chrome"; |
| 347 } | 348 } |
| 348 | 349 |
| 349 class AndroidChrome extends Browser { | 350 class AndroidChrome extends Browser { |
| 350 const String viewAction = 'android.intent.action.VIEW'; | 351 static const String viewAction = 'android.intent.action.VIEW'; |
| 351 const String mainAction = 'android.intent.action.MAIN'; | 352 static const String mainAction = 'android.intent.action.MAIN'; |
| 352 const String chromePackage = 'com.android.chrome'; | 353 static const String chromePackage = 'com.android.chrome'; |
| 353 const String browserPackage = 'com.android.browser'; | 354 static const String browserPackage = 'com.android.browser'; |
| 354 const String firefoxPackage = 'org.mozilla.firefox'; | 355 static const String firefoxPackage = 'org.mozilla.firefox'; |
| 355 const String turnScreenOnPackage = 'com.google.dart.turnscreenon'; | 356 static const String turnScreenOnPackage = 'com.google.dart.turnscreenon'; |
| 356 | 357 |
| 357 AndroidEmulator _emulator; | 358 AndroidEmulator _emulator; |
| 358 AdbDevice _adbDevice; | 359 AdbDevice _adbDevice; |
| 359 | 360 |
| 360 AndroidChrome(this._adbDevice); | 361 AndroidChrome(this._adbDevice); |
| 361 | 362 |
| 362 Future<bool> start(String url) { | 363 Future<bool> start(String url) { |
| 363 var browserIntent = new Intent( | 364 var browserIntent = new Intent( |
| 364 viewAction, browserPackage, '.BrowserActivity', url); | 365 viewAction, browserPackage, '.BrowserActivity', url); |
| 365 var chromeIntent = new Intent(viewAction, chromePackage, '.Main', url); | 366 var chromeIntent = new Intent(viewAction, chromePackage, '.Main', url); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 } | 411 } |
| 411 | 412 |
| 412 String toString() => "chromeOnAndroid"; | 413 String toString() => "chromeOnAndroid"; |
| 413 } | 414 } |
| 414 | 415 |
| 415 class Firefox extends Browser { | 416 class Firefox extends Browser { |
| 416 /** | 417 /** |
| 417 * The binary used to run firefox - changing this can be nececcary for | 418 * The binary used to run firefox - changing this can be nececcary for |
| 418 * testing or using non standard firefox installation. | 419 * testing or using non standard firefox installation. |
| 419 */ | 420 */ |
| 420 const String binary = "firefox"; | 421 static const String binary = "firefox"; |
| 421 | 422 |
| 422 const String enablePopUp = | 423 static const String enablePopUp = |
| 423 'user_pref("dom.disable_open_during_load", false);'; | 424 'user_pref("dom.disable_open_during_load", false);'; |
| 424 const String disableDefaultCheck = | 425 static const String disableDefaultCheck = |
| 425 'user_pref("browser.shell.checkDefaultBrowser", false);'; | 426 'user_pref("browser.shell.checkDefaultBrowser", false);'; |
| 426 | 427 |
| 427 Future _createPreferenceFile(var path) { | 428 Future _createPreferenceFile(var path) { |
| 428 var file = new File("${path.toString()}/user.js"); | 429 var file = new File("${path.toString()}/user.js"); |
| 429 var randomFile = file.openSync(mode: FileMode.WRITE); | 430 var randomFile = file.openSync(mode: FileMode.WRITE); |
| 430 randomFile.writeStringSync(enablePopUp); | 431 randomFile.writeStringSync(enablePopUp); |
| 431 randomFile.writeStringSync(disableDefaultCheck); | 432 randomFile.writeStringSync(disableDefaultCheck); |
| 432 randomFile.close(); | 433 randomFile.close(); |
| 433 } | 434 } |
| 434 | 435 |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 /// GET /next_test/BROWSER_ID -- returns "WAIT" "TERMINATE" or "url#id" | 770 /// GET /next_test/BROWSER_ID -- returns "WAIT" "TERMINATE" or "url#id" |
| 770 /// where url is the test to run, and id is the id of the test. | 771 /// where url is the test to run, and id is the id of the test. |
| 771 /// If there are currently no available tests the waitSignal is send | 772 /// If there are currently no available tests the waitSignal is send |
| 772 /// back. If we are in the process of terminating the terminateSignal | 773 /// back. If we are in the process of terminating the terminateSignal |
| 773 /// is send back and the browser will stop requesting new tasks. | 774 /// is send back and the browser will stop requesting new tasks. |
| 774 /// POST /report/BROWSER_ID?id=NUM -- sends back the dom of the executed | 775 /// POST /report/BROWSER_ID?id=NUM -- sends back the dom of the executed |
| 775 /// test | 776 /// test |
| 776 | 777 |
| 777 final String local_ip; | 778 final String local_ip; |
| 778 | 779 |
| 779 const String driverPath = "/driver"; | 780 static const String driverPath = "/driver"; |
| 780 const String nextTestPath = "/next_test"; | 781 static const String nextTestPath = "/next_test"; |
| 781 const String reportPath = "/report"; | 782 static const String reportPath = "/report"; |
| 782 const String waitSignal = "WAIT"; | 783 static const String waitSignal = "WAIT"; |
| 783 const String terminateSignal = "TERMINATE"; | 784 static const String terminateSignal = "TERMINATE"; |
| 784 | 785 |
| 785 var testCount = 0; | 786 var testCount = 0; |
| 786 var httpServer; | 787 var httpServer; |
| 787 var errorReportingServer; | 788 var errorReportingServer; |
| 788 bool underTermination = false; | 789 bool underTermination = false; |
| 789 bool useIframe = false; | 790 bool useIframe = false; |
| 790 | 791 |
| 791 Function testDoneCallBack; | 792 Function testDoneCallBack; |
| 792 Function nextTestCallBack; | 793 Function nextTestCallBack; |
| 793 | 794 |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 </head> | 1046 </head> |
| 1046 <body onload="startTesting()"> | 1047 <body onload="startTesting()"> |
| 1047 Dart test driver, number of tests: <div id="number"></div> | 1048 Dart test driver, number of tests: <div id="number"></div> |
| 1048 <iframe id="embedded_iframe"></iframe> | 1049 <iframe id="embedded_iframe"></iframe> |
| 1049 </body> | 1050 </body> |
| 1050 </html> | 1051 </html> |
| 1051 """; | 1052 """; |
| 1052 return driverContent; | 1053 return driverContent; |
| 1053 } | 1054 } |
| 1054 } | 1055 } |
| OLD | NEW |