Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Unified Diff: tools/testing/dart/browser_controller.dart

Issue 16094004: Add safari browser controller. (Closed) Base URL: http://dart.googlecode.com/svn/trunk/dart/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/testing/dart/test_runner.dart » ('j') | tools/testing/dart/test_runner.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/testing/dart/browser_controller.dart
===================================================================
--- tools/testing/dart/browser_controller.dart (revision 23230)
+++ tools/testing/dart/browser_controller.dart (working copy)
@@ -48,6 +48,9 @@
/** Print everything (stdout, stderr, usageLog) whenever we add to it */
bool debugPrint = true;
+ // We use this to gracefully handle double calls to close.
+ bool underTermination = false;
+
void _logEvent(String event) {
String toLog = "$this ($id) - ${new DateTime.now()}: $event \n";
if (debugPrint) print("usageLog: $toLog");
@@ -119,6 +122,11 @@
/** Close the browser */
Future<bool> close() {
_logEvent("Close called on browser");
+ if (underTermination) {
+ _logEvent("Browser already under termination.");
+ return new Future.immediate(true);
+ }
+ underTermination = true;
if (process == null) {
_logEvent("No process open, nothing to kill.");
return new Future.immediate(true);
@@ -178,6 +186,62 @@
Future<bool> start(String url);
}
+class Safari extends Browser {
+ /**
+ * The binary used to run safari - changing this can be nececcary for
+ * testing or using non standard safari installation.
+ */
+ const String binary = "/Applications/Safari.app/Contents/MacOS/Safari";
+
+ /**
+ * We get the safari version by parsing a version file
+ */
+ const String versionFile = "/Applications/Safari.app/Contents/version.plist";
+
+ Future<String> getVersion() {
+ File f = new File(versionFile);
+ return f.readAsLines().then((content) {
+ bool versionOnNextLine = false;
kustermann 2013/05/28 07:42:39 Small comment about how the file looks like would
ricow1 2013/05/28 08:07:30 Done.
+ for (var line in content) {
+ if (versionOnNextLine) return line;
+ if (line.contains("CFBundleShortVersionString")) {
+ versionOnNextLine = true;
+ }
+ }
+ return null;
+ });
+ }
+
+ void _createLaunchHTML(var path, var url) {
+ var file = new File("${path.toString()}/launch.html");
kustermann 2013/05/28 07:42:39 No reason to call 'toString()' explicitly (otherwi
ricow1 2013/05/28 08:07:30 Done.
+ var randomFile = file.openSync(FileMode.WRITE);
+ var content = '<script language="JavaScript">location = "$url"</script>';
+ randomFile.writeStringSync(content);
+ randomFile.close();
+ }
+
+ Future<bool> start(String url) {
+ _logEvent("Starting Safari browser on: $url");
+ // Get the version and log that.
+ return getVersion().then((version) {
+ _logEvent("Got version: $version");
+ var args = ["'$url'"];
+ return new Directory('').createTemp().then((userDir) {
+ _cleanup = () { userDir.delete(recursive: true); };
+ _createLaunchHTML(userDir.path, url);
+ var args = ["${userDir.path}/launch.html"];
+ return startBrowser(binary, args);
+ });
+ }).catchError((e) {
+ _logEvent("Running $binary --version failed with $e");
+ return false;
+ });
+ }
+
+ String toString() => "Safari";
+}
+
+
class Chrome extends Browser {
/**
* The binary used to run chrome - changing this can be nececcary for
@@ -518,6 +582,9 @@
print("could not kill browser $id");
return;
}
+ // We don't want to start a new browser if we are terminating.
+ if (underTermination) return;
kustermann 2013/05/28 07:42:39 We could also assert/throw here, since we never re
ricow1 2013/05/28 08:07:30 Here is what can happen: All tests but one are don
+
var browser;
if (browserName == 'chromeOnAndroid') {
browser = new AndroidChrome(adbDeviceMapping[id]);
@@ -611,6 +678,8 @@
return new Chrome();
} else if (browserName == "ff") {
return new Firefox();
+ } else if (browserName == "safari") {
+ return new Safari();
} else {
throw "Non supported browser for browser controller";
}
@@ -673,11 +742,11 @@
request.response.write(textResponse);
request.listen((_) {}, onDone: request.response.close);
request.response.done.catchError((error) {
- if (!underTermination) {
- print("URI ${request.uri}");
- print("Textresponse $textResponse");
- throw("Error returning content to browser: $error");
- }
+ if (!underTermination) {
+ print("URI ${request.uri}");
+ print("Textresponse $textResponse");
+ throw("Error returning content to browser: $error");
kustermann 2013/05/28 07:42:39 don't use 'throw()' but rather 'throw ""'
ricow1 2013/05/28 08:07:30 Done.
+ }
});
}
void errorHandler(e) {
« no previous file with comments | « no previous file | tools/testing/dart/test_runner.dart » ('j') | tools/testing/dart/test_runner.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698