chromium/chrome/test/data/dromaeo/patches/webrunner.patch

diff --git a/chrome/test/data/dromaeo/webrunner.js b/chrome/test/data/dromaeo/webrunner.js
index 63d777b..598998b 100644
--- a/chrome/test/data/dromaeo/webrunner.js
+++ b/chrome/test/data/dromaeo/webrunner.js
@@ -230,6 +230,8 @@
 	var time = 0;
 	var title, testName, testID, testSummary = {} , testSummaryNum = {}, maxTotal = 0, maxTotalNum = 0;
 	var nameDone = {};
+	var automated = false;
+	var post_json = false;
 	
 	// Query String Parsing
 	var search = window.limitSearch || (window.location.search || "?").substr(1);
@@ -269,6 +271,11 @@
 		m = /^numTests=(\d+)$/.exec(parts[i]);
 		if (m)
 			numTests = Number(m[1]);
+
+		if (/^automated$/.exec(parts[i]))
+			automated = true;
+		if (/^post_json$/.exec(parts[i]))
+			post_json = true;
 	}
 
 	jQuery(function(){
@@ -377,17 +384,28 @@
 				}
 	
 			} else 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 if (post_json) {
+					jQuery.ajax({
+						type: "POST",
+						url: "store.php",
+						data: "data=" + encodeURIComponent(JSON.stringify(window.automation.GetResults()))
+					});
+				}
+				else {
+					window.automation.SetDone();
+				}
 			}
 		}
 	}
@@ -406,20 +424,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();
+		}
 
 		if ( window.limitSearch ) {
 			$("#pause").click();
@@ -778,4 +804,45 @@
 
 		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() {
+			console.log("Total: " + this.GetScore());
+			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() {
+			var results = {};
+			var aggregated = {};
+			function normalizeName(name) {
+				// At least for ui_tests, dots are not allowed.
+				return name.replace(".", "_");
+			}
+			function appendToAggregated(name, value) {
+				name = normalizeName(name);
+				(aggregated[name] || (aggregated[name] = [])).push(Math.log(value));
+			}
+
+			for (var i = 0; i < dataStore.length; i++) {
+				var data = dataStore[i];
+				var topName = data.collection.split("-", 1)[0];
+				appendToAggregated(topName, data.mean);
+				appendToAggregated(data.collection, data.mean);
+				results[normalizeName(data.collection + "/" + data.name)] = data.mean.toString();
+			}
+
+			for (var name in aggregated) {
+				var means = aggregated[name];
+				var sum = 0;
+				for (var i = 0; i < means.length; i++) sum += means[i];
+				results[name] = Math.pow(Math.E, sum/means.length).toString();
+			}
+
+			return results;
+		}
+	}
 })();
-- 
2.8.0.rc3.226.g39d4020