Add support for statically linking to a specific test
authorjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Mar 2016 17:58:11 +0000 (17:58 +0000)
committerjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Mar 2016 17:58:11 +0000 (17:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=155631

Rubber-stamped by Darin Adler.

* Animometer/developer.html: Update to call restartBenchmark instead so that it works for
both the preset and the manually set test sessions.
* Animometer/resources/debug-runner/animometer.css:
(.tree .link): Style the "link" UI.
* Animometer/resources/debug-runner/animometer.js: Move updateDisplay from suitesManager
to optionsManager since this is a visual option and has nothing to do with the suites
settings. Update the construction of the test UI by including a "link" after each test.
Clicking on that link brings up a JS prompt with a URL and a query string with the current
parameters of the controller, and selected test. Pasting this URL into the location bar will
automatically start running the selected test.
(suitesManager.suitesFromQueryString): Iterate through the Suites and tests and find the one
that matches the provided parameters. Returns an object similar to the form in
suitesManager.updateLocalStorageFromUI.
(benchmarkController.initialize): After settings up the events and options, try parsing the
query string and running the benchmark immediately. Otherwise, fall back to the form.
(benchmarkController.startBenchmark): Store the options and suites into member variables for
reuse in restartBenchmark.
(benchmarkController.startBenchmarkImmediatelyIfEncoded): Convert the query string to an object.
If that's successful, find the suite and test referenced in the query string. Start the benchmark if
the search for the test succeeded.
* Animometer/resources/extensions.js:
(Utilities.stripNonASCIICharacters): Helper method to convert the name of the suite and test
into a query-string-friendly version.
(Utilities.convertObjectToQueryString): Helper method to convert an object to query string
format.
(Utilities.convertQueryStringToObject): Helper method to convert query string into an object
with properties and values.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198428 268f45cc-cd09-0410-ab3c-d52691b4dbfc

PerformanceTests/Animometer/developer.html
PerformanceTests/Animometer/resources/debug-runner/animometer.css
PerformanceTests/Animometer/resources/debug-runner/animometer.js
PerformanceTests/Animometer/resources/extensions.js
PerformanceTests/ChangeLog

index d2a8d6f..b502a67 100644 (file)
@@ -93,7 +93,7 @@
                 </div>
                 <table id="results-header"></table>
             </div>
-            <button onclick="benchmarkController.startBenchmark()">Test Again</button>
+            <button onclick="benchmarkController.restartBenchmark()">Test Again</button>
             <p>
                 'j': Show JSON results<br/>
                 's': Select various results for copy/paste (use repeatedly to cycle)
index 8adc48b..470cf4a 100644 (file)
@@ -104,6 +104,13 @@ label.tree-label {
     content: '\25BC';
 }
 
+.tree .link {
+    cursor: pointer;
+    color: #999;
+    font-style: italic;
+    margin-left: 2em;
+}
+
 @media screen and (max-device-width: 414px) {
     .tree {
         padding-left: 1em;
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()
index d26d3b6..1806670 100644 (file)
@@ -118,6 +118,35 @@ Utilities =
         element.style[property] = element.style[this.browserPrefix().js + property[0].toUpperCase() + property.substr(1)] = value;
     },
 
+    stripNonASCIICharacters: function(inputString)
+    {
+        return inputString.replace(/[ .,]/g, '');
+    },
+
+    convertObjectToQueryString: function(object)
+    {
+        var queryString = [];
+        for (var property in object) {
+            if (object.hasOwnProperty(property))
+                queryString.push(encodeURIComponent(property) + "=" + encodeURIComponent(object[property]));
+        }
+        return "?" + queryString.join("&");
+    },
+
+    convertQueryStringToObject: function(queryString)
+    {
+        queryString = queryString.substring(1);
+        if (!queryString)
+            return null;
+
+        var object = {};
+        queryString.split("&").forEach(function(parameter) {
+            var components = parameter.split("=");
+            object[components[0]] = components[1];
+        });
+        return object;
+    },
+
     progressValue: function(value, min, max)
     {
         return (value - min) / (max - min);
index e3481ca..9cfed53 100644 (file)
@@ -1,3 +1,38 @@
+2016-03-18  Jon Lee  <jonlee@apple.com>
+
+        Add support for statically linking to a specific test
+        https://bugs.webkit.org/show_bug.cgi?id=155631
+
+        Rubber-stamped by Darin Adler.
+
+        * Animometer/developer.html: Update to call restartBenchmark instead so that it works for
+        both the preset and the manually set test sessions.
+        * Animometer/resources/debug-runner/animometer.css:
+        (.tree .link): Style the "link" UI.
+        * Animometer/resources/debug-runner/animometer.js: Move updateDisplay from suitesManager
+        to optionsManager since this is a visual option and has nothing to do with the suites
+        settings. Update the construction of the test UI by including a "link" after each test.
+        Clicking on that link brings up a JS prompt with a URL and a query string with the current
+        parameters of the controller, and selected test. Pasting this URL into the location bar will
+        automatically start running the selected test.
+        (suitesManager.suitesFromQueryString): Iterate through the Suites and tests and find the one
+        that matches the provided parameters. Returns an object similar to the form in
+        suitesManager.updateLocalStorageFromUI.
+        (benchmarkController.initialize): After settings up the events and options, try parsing the
+        query string and running the benchmark immediately. Otherwise, fall back to the form.
+        (benchmarkController.startBenchmark): Store the options and suites into member variables for
+        reuse in restartBenchmark.
+        (benchmarkController.startBenchmarkImmediatelyIfEncoded): Convert the query string to an object.
+        If that's successful, find the suite and test referenced in the query string. Start the benchmark if
+        the search for the test succeeded.
+        * Animometer/resources/extensions.js:
+        (Utilities.stripNonASCIICharacters): Helper method to convert the name of the suite and test
+        into a query-string-friendly version.
+        (Utilities.convertObjectToQueryString): Helper method to convert an object to query string
+        format.
+        (Utilities.convertQueryStringToObject): Helper method to convert query string into an object
+        with properties and values.
+
 2016-03-16  Jon Lee  <jonlee@apple.com>
 
         Add a new benchmark test