Chromium Code Reviews| 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; |
| 198 }); | |
| 199 } | |
| 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 command = "rm"; | |
| 206 var args = ["-rf", "\$HOME/Library/Caches/com.apple.Safari"]; | |
|
kustermann
2013/06/20 09:21:04
As discussed offline, this doesn't work.
Please re
ricow1
2013/06/20 10:24:05
Done.
| |
| 207 _logEvent("Clearing safari cache: $command ${args.join(' ')}"); | |
| 208 return Process.run(command, args).then((result) { | |
| 209 if (result.exitCode != 0) { | |
| 210 _logEvent("Could not clear safari cache"); | |
| 211 return false; | |
| 212 } | |
| 213 return true; | |
| 199 }); | 214 }); |
| 200 } | 215 } |
| 201 | 216 |
| 202 Future<String> getVersion() { | 217 Future<String> getVersion() { |
| 203 /** | 218 /** |
| 204 * Example of the file: | 219 * Example of the file: |
| 205 * <?xml version="1.0" encoding="UTF-8"?> | 220 * <?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"> | 221 * <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.co m/DTDs/PropertyList-1.0.dtd"> |
| 207 * <plist version="1.0"> | 222 * <plist version="1.0"> |
| 208 * <dict> | 223 * <dict> |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 235 void _createLaunchHTML(var path, var url) { | 250 void _createLaunchHTML(var path, var url) { |
| 236 var file = new File("${path}/launch.html"); | 251 var file = new File("${path}/launch.html"); |
| 237 var randomFile = file.openSync(FileMode.WRITE); | 252 var randomFile = file.openSync(FileMode.WRITE); |
| 238 var content = '<script language="JavaScript">location = "$url"</script>'; | 253 var content = '<script language="JavaScript">location = "$url"</script>'; |
| 239 randomFile.writeStringSync(content); | 254 randomFile.writeStringSync(content); |
| 240 randomFile.close(); | 255 randomFile.close(); |
| 241 } | 256 } |
| 242 | 257 |
| 243 Future<bool> start(String url) { | 258 Future<bool> start(String url) { |
| 244 _logEvent("Starting Safari browser on: $url"); | 259 _logEvent("Starting Safari browser on: $url"); |
| 245 // Get the version and log that. | |
| 246 return allowPopUps().then((success) { | 260 return allowPopUps().then((success) { |
| 247 if (!success) { | 261 if (!success) { |
| 248 return new Future.immediate(false); | 262 return new Future.immediate(false); |
| 249 } | 263 } |
| 250 return getVersion().then((version) { | 264 return clearCache().then((cleared) { |
| 251 _logEvent("Got version: $version"); | 265 if (!cleared) { |
| 252 var args = ["'$url'"]; | 266 return new Future.immediate(false); |
| 253 return new Directory('').createTemp().then((userDir) { | 267 } |
| 254 _cleanup = () { userDir.deleteSync(recursive: true); }; | 268 // Get the version and log that. |
| 255 _createLaunchHTML(userDir.path, url); | 269 return getVersion().then((version) { |
| 256 var args = ["${userDir.path}/launch.html"]; | 270 _logEvent("Got version: $version"); |
| 257 return startBrowser(binary, args); | 271 return new Directory('').createTemp().then((userDir) { |
| 272 _cleanup = () { userDir.deleteSync(recursive: true); }; | |
| 273 _createLaunchHTML(userDir.path, url); | |
| 274 var args = ["${userDir.path}/launch.html"]; | |
| 275 return startBrowser(binary, args); | |
| 276 }); | |
| 277 }).catchError((e) { | |
|
kustermann
2013/06/20 09:21:04
e -> error.
ricow1
2013/06/20 10:24:05
Done.
| |
| 278 _logEvent("Running $binary --version failed with $e"); | |
| 279 return false; | |
| 258 }); | 280 }); |
| 259 }).catchError((e) { | |
| 260 _logEvent("Running $binary --version failed with $e"); | |
| 261 return false; | |
| 262 }); | 281 }); |
| 263 }); | 282 }); |
| 264 } | 283 } |
| 265 | 284 |
| 266 String toString() => "Safari"; | 285 String toString() => "Safari"; |
| 286 | |
| 287 static bool deleteCache = false; | |
|
kustermann
2013/06/20 09:21:04
Add a comment here.
ricow1
2013/06/20 10:24:05
Done.
| |
| 288 | |
| 267 } | 289 } |
| 268 | 290 |
| 269 | 291 |
| 270 class Chrome extends Browser { | 292 class Chrome extends Browser { |
| 271 /** | 293 /** |
| 272 * The binary used to run chrome - changing this can be nececcary for | 294 * The binary used to run chrome - changing this can be nececcary for |
| 273 * testing or using non standard chrome installation. | 295 * testing or using non standard chrome installation. |
| 274 */ | 296 */ |
| 275 const String binary = "google-chrome"; | 297 const String binary = "google-chrome"; |
| 276 | 298 |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1007 </head> | 1029 </head> |
| 1008 <body onload="startTesting()"> | 1030 <body onload="startTesting()"> |
| 1009 Dart test driver, number of tests: <div id="number"></div> | 1031 Dart test driver, number of tests: <div id="number"></div> |
| 1010 <iframe id="embedded_iframe"></iframe> | 1032 <iframe id="embedded_iframe"></iframe> |
| 1011 </body> | 1033 </body> |
| 1012 </html> | 1034 </html> |
| 1013 """; | 1035 """; |
| 1014 return driverContent; | 1036 return driverContent; |
| 1015 } | 1037 } |
| 1016 } | 1038 } |
| OLD | NEW |