Add support for statically linking to a specific test
[WebKit-https.git] / PerformanceTests / Animometer / resources / debug-runner / animometer.js
index ffc71ba..173bd55 100644 (file)
@@ -190,8 +190,13 @@ window.optionsManager =
         }
 
         return options;
+    },
+
+    updateDisplay: function()
+    {
+        document.body.className = "display-" + optionsManager.valueForOption("display");
     }
-}
+};
 
 window.suitesManager =
 {
@@ -299,7 +304,29 @@ window.suitesManager =
         testCheckbox.suiteCheckbox = suiteCheckbox;
 
         suiteCheckbox.testsElements.push(testElement);
-        span.appendChild(document.createTextNode(" " + test.name));
+        span.appendChild(document.createTextNode(" " + test.name + " "));
+
+        testElement.appendChild(document.createTextNode(" "));
+        var link = Utilities.createElement("span", {}, testElement);
+        link.classList.add("link");
+        link.textContent = "link";
+        link.suiteName = Utilities.stripNonASCIICharacters(suiteCheckbox.suite.name);
+        link.testName = test.name;
+        link.onclick = function(event) {
+            var element = event.target;
+            var title = "Link to run “" + element.testName + "” with current options:";
+            var url = location.href.split(/[?#]/)[0];
+            var options = optionsManager.updateLocalStorageFromUI();
+            Utilities.extendObject(options, {
+                "suite-name": element.suiteName,
+                "test-name": Utilities.stripNonASCIICharacters(element.testName)
+            });
+            var complexity = suitesManager._editElement(element.parentNode).value;
+            if (complexity)
+                options.complexity = complexity;
+            prompt(title, url + Utilities.convertObjectToQueryString(options));
+        };
+
         var complexity = Utilities.createElement("input", { type: "number" }, testElement);
         complexity.relatedCheckbox = testCheckbox;
         complexity.oninput = function(event) {
@@ -320,7 +347,7 @@ window.suitesManager =
             var suiteCheckbox = this._checkboxElement(suiteElement);
 
             suite.tests.forEach(function(test) {
-                var testElement = this._createTestElement(listElement, test, suiteCheckbox);
+                this._createTestElement(listElement, test, suiteCheckbox);
             }, this);
         }, this);
     },
@@ -339,11 +366,6 @@ window.suitesManager =
         }
     },
 
-    updateDisplay: function()
-    {
-        document.body.className = "display-" + optionsManager.valueForOption("display");
-    },
-
     updateUIFromLocalStorage: function()
     {
         var suitesElements = this._suitesElements();
@@ -407,6 +429,35 @@ window.suitesManager =
         return suites;
     },
 
+    suitesFromQueryString: function(suiteName, testName)
+    {
+        var suites = [];
+        var suiteRegExp = new RegExp(suiteName, "i");
+        var testRegExp = new RegExp(testName, "i");
+
+        for (var i = 0; i < Suites.length; ++i) {
+            var suite = Suites[i];
+            if (!Utilities.stripNonASCIICharacters(suite.name).match(suiteRegExp))
+                continue;
+
+            var test;
+            for (var j = 0; j < suite.tests.length; ++j) {
+                suiteTest = suite.tests[j];
+                if (Utilities.stripNonASCIICharacters(suiteTest.name).match(testRegExp)) {
+                    test = suiteTest;
+                    break;
+                }
+            }
+
+            if (!test)
+                continue;
+
+            suites.push(new Suite(suiteName, [test]));
+        };
+
+        return suites;
+    },
+
     updateLocalStorageFromJSON: function(results)
     {
         for (var suiteName in results[Strings.json.results.tests]) {
@@ -433,9 +484,13 @@ Utilities.extendObject(window.benchmarkController, {
         document.forms["time-graph-options"].addEventListener("change", benchmarkController.onTimeGraphOptionsChanged, true);
         document.forms["complexity-graph-options"].addEventListener("change", benchmarkController.onComplexityGraphOptionsChanged, true);
         optionsManager.updateUIFromLocalStorage();
+        optionsManager.updateDisplay();
+
+        if (benchmarkController.startBenchmarkImmediatelyIfEncoded())
+            return;
+
         suitesManager.createElements();
         suitesManager.updateUIFromLocalStorage();
-        suitesManager.updateDisplay();
         suitesManager.updateEditsElementsState();
 
         var dropTarget = document.getElementById("drop-target");
@@ -466,7 +521,6 @@ Utilities.extendObject(window.benchmarkController, {
             reader.readAsText(file);
             document.title = "File: " + reader.filename;
         }, false);
-
     },
 
     onBenchmarkOptionsChanged: function(event)
@@ -476,15 +530,36 @@ Utilities.extendObject(window.benchmarkController, {
             return;
         }
         if (event.target.name == "display") {
-            suitesManager.updateDisplay();
+            optionsManager.updateDisplay();
         }
     },
 
     startBenchmark: function()
     {
-        var options = optionsManager.updateLocalStorageFromUI();
-        var suites = suitesManager.updateLocalStorageFromUI();
-        this._startBenchmark(suites, options, "running-test");
+        benchmarkController.options = optionsManager.updateLocalStorageFromUI();
+        benchmarkController.suites = suitesManager.updateLocalStorageFromUI();
+        this._startBenchmark(benchmarkController.suites, benchmarkController.options, "running-test");
+    },
+
+    startBenchmarkImmediatelyIfEncoded: function()
+    {
+        benchmarkController.options = Utilities.convertQueryStringToObject(location.search);
+        if (!benchmarkController.options)
+            return false;
+
+        benchmarkController.suites = suitesManager.suitesFromQueryString(benchmarkController.options["suite-name"], benchmarkController.options["test-name"]);
+        if (!benchmarkController.suites.length)
+            return false;
+
+        setTimeout(function() {
+            this._startBenchmark(benchmarkController.suites, benchmarkController.options, "running-test");
+        }.bind(this), 0);
+        return true;
+    },
+
+    restartBenchmark: function()
+    {
+        this._startBenchmark(benchmarkController.suites, benchmarkController.options, "running-test");
     },
 
     showResults: function()