| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 * The binary used to run safari - changing this can be nececcary for | 176 * The binary used to run safari - changing this can be nececcary for |
| 177 * testing or using non standard safari installation. | 177 * testing or using non standard safari installation. |
| 178 */ | 178 */ |
| 179 const String binary = "/Applications/Safari.app/Contents/MacOS/Safari"; | 179 const String binary = "/Applications/Safari.app/Contents/MacOS/Safari"; |
| 180 | 180 |
| 181 /** | 181 /** |
| 182 * We get the safari version by parsing a version file | 182 * We get the safari version by parsing a version file |
| 183 */ | 183 */ |
| 184 const String versionFile = "/Applications/Safari.app/Contents/version.plist"; | 184 const String versionFile = "/Applications/Safari.app/Contents/version.plist"; |
| 185 | 185 |
| 186 | |
| 187 Future<bool> allowPopUps() { | 186 Future<bool> allowPopUps() { |
| 188 var command = "defaults"; | 187 var command = "defaults"; |
| 189 var args = ["write", "com.apple.safari", | 188 var args = ["write", "com.apple.safari", |
| 190 "com.apple.Safari.ContentPageGroupIdentifier." | 189 "com.apple.Safari.ContentPageGroupIdentifier." |
| 191 "WebKit2JavaScriptCanOpenWindowsAutomatically", | 190 "WebKit2JavaScriptCanOpenWindowsAutomatically", |
| 192 "1"]; | 191 "1"]; |
| 193 return Process.run(command, args).then((result) { | 192 return Process.run(command, args).then((result) { |
| 194 if (result.exitCode != 0) { | 193 if (result.exitCode != 0) { |
| 195 _logEvent("Could not disable pop-up blocking for safari"); | 194 _logEvent("Could not disable pop-up blocking for safari"); |
| 196 return false; | 195 return false; |
| 197 } | 196 } |
| 198 return true; | 197 return true; |
| 199 }); | 198 }); |
| 200 } | 199 } |
| 201 | 200 |
| 201 // Clears the cache if the static deleteCache flag is set. |
| 202 // Returns false if the command to actually clear the cache did not complete. |
| 203 Future<bool> clearCache() { |
| 204 if (!deleteCache) return new Future.immediate(true); |
| 205 var home = Platform.environment['HOME']; |
| 206 var cache = "$home/Library/Caches/com.apple.Safari"; |
| 207 _logEvent("Clearing safari cache: $cache}"); |
| 208 return new Directory(cache).delete(recursive: true) |
| 209 .then((_) => true) |
| 210 // This normally means that the directory was not there. |
| 211 .catchError((error) => true); |
| 212 } |
| 213 |
| 202 Future<String> getVersion() { | 214 Future<String> getVersion() { |
| 203 /** | 215 /** |
| 204 * Example of the file: | 216 * Example of the file: |
| 205 * <?xml version="1.0" encoding="UTF-8"?> | 217 * <?xml version="1.0" encoding="UTF-8"?> |
| 206 * <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.co
m/DTDs/PropertyList-1.0.dtd"> | 218 * <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.co
m/DTDs/PropertyList-1.0.dtd"> |
| 207 * <plist version="1.0"> | 219 * <plist version="1.0"> |
| 208 * <dict> | 220 * <dict> |
| 209 * <key>BuildVersion</key> | 221 * <key>BuildVersion</key> |
| 210 * <string>2</string> | 222 * <string>2</string> |
| 211 * <key>CFBundleShortVersionString</key> | 223 * <key>CFBundleShortVersionString</key> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 235 void _createLaunchHTML(var path, var url) { | 247 void _createLaunchHTML(var path, var url) { |
| 236 var file = new File("${path}/launch.html"); | 248 var file = new File("${path}/launch.html"); |
| 237 var randomFile = file.openSync(FileMode.WRITE); | 249 var randomFile = file.openSync(FileMode.WRITE); |
| 238 var content = '<script language="JavaScript">location = "$url"</script>'; | 250 var content = '<script language="JavaScript">location = "$url"</script>'; |
| 239 randomFile.writeStringSync(content); | 251 randomFile.writeStringSync(content); |
| 240 randomFile.close(); | 252 randomFile.close(); |
| 241 } | 253 } |
| 242 | 254 |
| 243 Future<bool> start(String url) { | 255 Future<bool> start(String url) { |
| 244 _logEvent("Starting Safari browser on: $url"); | 256 _logEvent("Starting Safari browser on: $url"); |
| 245 // Get the version and log that. | |
| 246 return allowPopUps().then((success) { | 257 return allowPopUps().then((success) { |
| 247 if (!success) { | 258 if (!success) { |
| 248 return new Future.immediate(false); | 259 return new Future.immediate(false); |
| 249 } | 260 } |
| 250 return getVersion().then((version) { | 261 return clearCache().then((_) { |
| 251 _logEvent("Got version: $version"); | 262 // Get the version and log that. |
| 252 var args = ["'$url'"]; | 263 return getVersion().then((version) { |
| 253 return new Directory('').createTemp().then((userDir) { | 264 _logEvent("Got version: $version"); |
| 254 _cleanup = () { userDir.deleteSync(recursive: true); }; | 265 return new Directory('').createTemp().then((userDir) { |
| 255 _createLaunchHTML(userDir.path, url); | 266 _cleanup = () { userDir.deleteSync(recursive: true); }; |
| 256 var args = ["${userDir.path}/launch.html"]; | 267 _createLaunchHTML(userDir.path, url); |
| 257 return startBrowser(binary, args); | 268 var args = ["${userDir.path}/launch.html"]; |
| 269 return startBrowser(binary, args); |
| 270 }); |
| 271 }).catchError((error) { |
| 272 _logEvent("Running $binary --version failed with $error"); |
| 273 return false; |
| 258 }); | 274 }); |
| 259 }).catchError((e) { | |
| 260 _logEvent("Running $binary --version failed with $e"); | |
| 261 return false; | |
| 262 }); | 275 }); |
| 263 }); | 276 }); |
| 264 } | 277 } |
| 265 | 278 |
| 266 String toString() => "Safari"; | 279 String toString() => "Safari"; |
| 280 |
| 281 // Delete the user specific browser cache and profile data. |
| 282 // Safari only have one per user, and you can't specify one by command line. |
| 283 static bool deleteCache = false; |
| 284 |
| 267 } | 285 } |
| 268 | 286 |
| 269 | 287 |
| 270 class Chrome extends Browser { | 288 class Chrome extends Browser { |
| 271 /** | 289 /** |
| 272 * The binary used to run chrome - changing this can be nececcary for | 290 * The binary used to run chrome - changing this can be nececcary for |
| 273 * testing or using non standard chrome installation. | 291 * testing or using non standard chrome installation. |
| 274 */ | 292 */ |
| 275 const String binary = "google-chrome"; | 293 const String binary = "google-chrome"; |
| 276 | 294 |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 </head> | 1025 </head> |
| 1008 <body onload="startTesting()"> | 1026 <body onload="startTesting()"> |
| 1009 Dart test driver, number of tests: <div id="number"></div> | 1027 Dart test driver, number of tests: <div id="number"></div> |
| 1010 <iframe id="embedded_iframe"></iframe> | 1028 <iframe id="embedded_iframe"></iframe> |
| 1011 </body> | 1029 </body> |
| 1012 </html> | 1030 </html> |
| 1013 """; | 1031 """; |
| 1014 return driverContent; | 1032 return driverContent; |
| 1015 } | 1033 } |
| 1016 } | 1034 } |
| OLD | NEW |