Add UI test for Dromaeo benchmark.

That required minor modification of Dromaeo benchmark to enable automation.

BUG=none
TEST=none

Committing for Anton Muhin (antonm@chromium.org).

Review URL: http://codereview.chromium.org/274020


Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 19783666440e33def6a060a558a661be245d8144
diff --git a/README.chromium b/README.chromium
index 07aec2a..1adda18 100644
--- a/README.chromium
+++ b/README.chromium
@@ -2,5 +2,12 @@
 
 Dromaeo was developed and released by John Resig (jresig at mozilla.com)/
 
-This copy was fecthed from http://github.com/jeresig/dromaeo (at commit
-0b96e6b0f98996853e1a302b9783f83fc57c5ffa) and built with make web.
+This benchmark was slightly modified to enable Chromium automation.
+
+How to update:
+
+0) remove all the files from this dir, but keep README.chromium
+1) pull new version from git://github.com/antonm/dromaeo.git into a separate
+directory;
+2) run 'make web' to build standalone version;
+4) copy all the files from web dir into this directory.
diff --git a/webrunner.js b/webrunner.js
index faaf514..9473528 100644
--- a/webrunner.js
+++ b/webrunner.js
@@ -230,6 +230,7 @@
 	var time = 0;
 	var title, testName, testID, testSummary = {} , testSummaryNum = {}, maxTotal = 0, maxTotalNum = 0;
 	var nameDone = {};
+	var automated = false;
 	
 	// Query String Parsing
 	var search = (window.location.search || "?").substr(1);
@@ -269,6 +270,8 @@
 		m = /^numTests=(\d+)$/.exec(parts[i]);
 		if (m)
 			numTests = Number(m[1]);
+
+		automated = /^automated$/.exec(parts[i]);
 	}
 
 	jQuery(function(){
@@ -360,17 +363,21 @@
 			updateTimebar();
 	
 			if ( dataStore && dataStore.length ) {
-				$("body").addClass("alldone");
-				var div = jQuery("<div class='results'>Saving...</div>").insertBefore("#overview");
-				jQuery.ajax({
-					type: "POST",
-					url: "store.php",
-					data: "data=" + encodeURIComponent(JSON.stringify(dataStore)) + "&style=" + runStyle,
-					success: function(id){
-						var url = window.location.href.replace(/\?.*$/, "") + "?id=" + id;
-						div.html("Results saved. You can access them at a later time at the following URL:<br/><strong><a href='" + url + "'>" + url + "</a></strong></div>");
-					}
-				});
+				if (!automated) {
+					$("body").addClass("alldone");
+					var div = jQuery("<div class='results'>Saving...</div>").insertBefore("#overview");
+					jQuery.ajax({
+						type: "POST",
+						url: "store.php",
+						data: "data=" + encodeURIComponent(JSON.stringify(dataStore)) + "&style=" + runStyle,
+						success: function(id){
+							var url = window.location.href.replace(/\?.*$/, "") + "?id=" + id;
+							div.html("Results saved. You can access them at a later time at the following URL:<br/><strong><a href='" + url + "'>" + url + "</a></strong></div>");
+						}
+					});
+				} else {
+					window.automation.SetDone();
+				}
 			}
 		}
 	}
@@ -389,20 +396,28 @@
 		time += timePerTest;
 		updateTime();
 		
-		$("#pause")
-			.val("Run")
-			.click(function(){
-				if ( interval ) {
-					interval = null;
-					this.value = "Run";
-				} else {
-					if ( !interval ) {
-						interval = true;
-						dequeue();
+		if (!automated) {
+			$("#pause")
+				.val("Run")
+				.click(function(){
+					if ( interval ) {
+						interval = null;
+						this.value = "Run";
+					} else {
+						if ( !interval ) {
+							interval = true;
+							dequeue();
+						}
+						this.value = "Pause";
 					}
-					this.value = "Pause";
-				}
-			});
+				});
+		} else {
+			$("#pause")
+				.val("Automated")
+				.click(function(){});
+			interval = true;
+			dequeue();
+		}
 	}
 
 	function initTest(curID){
@@ -757,4 +772,25 @@
 
 		updateTestPos({curID: testID, collection: tests[testID] ? tests[testID].name : testID, version: testVersions[testID]}, true);
 	}
+
+	if (automated) {
+		// Add some more stuff if running in automated mode.
+		window.automation = {}
+		window.automation.SetDone = function() {
+			window.document.cookie = "__done=1; path=/";
+		}
+		window.automation.GetScore = function() {
+			return (runStyle === "runs/s" ? Math.pow(Math.E, maxTotal / maxTotalNum) : maxTotal).toString();
+		}
+		window.automation.GetResults = function() {
+			results = {}
+			for (var i = 0; i < dataStore.length; i++) {
+				var data = dataStore[i];
+				// dots are not allowed.
+				var key = (data.collection + "/" + data.name).replace(".", "_");
+				results[key] = data.mean.toString();
+			}
+			return results;
+		}
+	}
 })();