Refactor test suites to a separate class.
authorjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Oct 2015 23:22:23 +0000 (23:22 +0000)
committerjonlee@apple.com <jonlee@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Oct 2015 23:22:23 +0000 (23:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150053
<rdar://problem/23078645>

Reviewed by Dean Jackson.

Create a Suite class to refactor out prepare() and run().
Generate the checkboxes representing the suites using Suites
instead of maintaining a separate list. Also, save the
selections out to localStorage.

* Animometer/runner/animometer.html: Remove the explicitly listed
suites. These will be generated from Suites instead.
* Animometer/runner/resources/animometer.js:
(populateSettings): Iterate through Suites, and create the
label and checkbox. Attach the Suite object to the checkbox so
when the benchmark is started, we get direct access. Initialize
the checkmark based on its value in localStorage. Set this to
run when DOMContentLoaded is dispatched.
(startBenchmark): Grab all of the checkboxes, inspect their
values, add it to enabledSuites if selected. Remember whether
the suite was enabled in localStorage, so that it's easy to do
repeated runs.
* Animometer/runner/resources/tests.js:
(Suite): Create a new Suite class. Refactor out prepare() and
run(), since all of them have the same implementation. Populate
Suites with Suite instances instead of generic objects.

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

PerformanceTests/Animometer/runner/animometer.html
PerformanceTests/Animometer/runner/resources/animometer.js
PerformanceTests/Animometer/runner/resources/tests.js
PerformanceTests/ChangeLog

index 6ea78ac..d8d586c 100644 (file)
                 to tune their complexities to stay close to 50 FPS.
             </p>
             <div class="options">
-                <div class="column">
-                    <label><input id="html-suite" type="checkbox" checked> HTML elements suite</label><br>
-                    <label><input id="canvas-suite" type="checkbox" checked> Canvas drawings suite</label><br>
-                    <label><input id="svg-suite" type="checkbox" checked> SVG elements suite</label><br>
-                    <label><input id="examples-suite" type="checkbox"> Examples suite</label><br>
-                    <label><input id="template-suite" type="checkbox"> Template suite</label>
+                <div id="suites" class="column">
                 </div>
                 <div>
                     <label>Test interval: <input id="test-interval" type="number" value="30"> seconds</label><br>
index 42c102f..b893b86 100644 (file)
@@ -59,13 +59,16 @@ function showSection(sectionIdentifier, pushState)
 
 function startBenchmark()
 {
-    var checkboxes = [ 
-        document.getElementById("html-suite"), 
-        document.getElementById("canvas-suite"), 
-        document.getElementById("svg-suite"),
-        document.getElementById("examples-suite"),
-        document.getElementById("template-suite"),
-    ];
+    var enabledSuites = [];
+    var checkboxes = document.querySelectorAll("#suites input");
+    for (var i = 0; i < checkboxes.length; ++i) {
+        var checkbox = checkboxes[i];
+        if (checkbox.checked) {
+            enabledSuites.push(checkbox.suite);
+        }
+        localStorage.setItem(checkbox.suite.name, +checkbox.checked);
+    }
+
     var enabledSuites = Suites.filter(function (suite, index) { return !suite.disabled && checkboxes[index].checked; });
     var testsCount = enabledSuites.reduce(function (testsCount, suite) { return testsCount + suite.tests.length; }, 0);
     benchmarkRunnerClient.testsCount = benchmarkRunnerClient.iterationCount * testsCount;
@@ -110,3 +113,25 @@ function showGraph(testName, axes, samples, samplingTimeOffset)
     graph("#graphContainer", new Point(700, 400), new Insets(20, 50, 20, 50), axes, samples, samplingTimeOffset);
     showSection("graph", true);    
 }
+
+function populateSettings() {
+    var suitesDiv = document.getElementById("suites");
+    Suites.forEach(function(suite) {
+        var suiteDiv = document.createDocumentFragment();
+
+        var label = document.createElement("label");
+        var checkbox = document.createElement("input");
+        checkbox.setAttribute("type", "checkbox");
+        checkbox.suite = suite;
+        if (+localStorage.getItem(suite.name)) {
+            checkbox.checked = true;
+        }
+        label.appendChild(checkbox);
+        label.appendChild(document.createTextNode(" " + suite.name));
+
+        suiteDiv.appendChild(label);
+        suiteDiv.appendChild(document.createElement("br"));
+        suitesDiv.appendChild(suiteDiv);
+    });
+}
+document.addEventListener("DOMContentLoaded", populateSettings);
\ No newline at end of file
index 6f77dd7..d722af8 100644 (file)
@@ -38,24 +38,27 @@ var Titles = [
     }
 ];
 
-var Suites = [];
+var Suite = function(name, tests) {
+    this.name = name;
+    this.titles = Titles;
+    this.tests = tests;
+};
+Suite.prototype.prepare = function(runner, contentWindow, contentDocument)
+{
+    return runner.waitForElement("#stage").then(function (element) {
+        return element;
+    });
+};
+Suite.prototype.run = function(contentWindow, test, options, recordTable, progressBar)
+{
+    return contentWindow.runBenchmark(this, test, options, recordTable, progressBar);
+};
 
-Suites.push({
-    name: "HTML Bouncing Particles",
-    prepare: function(runner, contentWindow, contentDocument)
-    {
-        return runner.waitForElement("#stage").then(function (element) {
-            return element;
-        });
-    },
-    
-    run: function(contentWindow, test, options, recordTable, progressBar)
-    {
-        return contentWindow.runBenchmark(this, test, options, recordTable, progressBar);
-    },
 
-    titles: Titles,
-    tests: [
+var Suites = [];
+
+Suites.push(new Suite("HTML suite",
+    [
         { 
             url: "../tests/bouncing-particles/bouncing-css-shapes.html?gain=1&addLimit=100&removeLimit=5&particleWidth=12&particleHeight=12&shape=circle",
             name: "CSS bouncing circles"
@@ -81,24 +84,10 @@ Suites.push({
             name: "CSS layering text"
         },
     ]
-});
+));
 
-Suites.push({
-    name: "Canvas Bouncing Particles",
-    prepare: function(runner, contentWindow, contentDocument)
-    {
-        return runner.waitForElement("#stage").then(function (element) {
-            return element;
-        });
-    },  
-    
-    run: function(contentWindow, test, options, recordTable, progressBar)
-    {
-        return contentWindow.runBenchmark(this, test, options, recordTable, progressBar);
-    },
-    
-    titles: Titles,
-    tests: [
+Suites.push(new Suite("Canvas suite",
+    [
         { 
             url: "../tests/bouncing-particles/bouncing-canvas-shapes.html?gain=4&addLimit=100&removeLimit=1000&particleWidth=12&particleHeight=12&shape=circle",
             name: "canvas bouncing circles"
@@ -120,24 +109,10 @@ Suites.push({
             name: "canvas bouncing PNG images"
         },
     ]
-});
+));
 
-Suites.push({
-    name: "SVG Bouncing Particles",
-    prepare: function(runner, contentWindow, contentDocument)
-    {
-        return runner.waitForElement("#stage").then(function (element) {
-            return element;
-        });
-    },
-    
-    run: function(contentWindow, test, options, recordTable, progressBar)
-    {
-        return contentWindow.runBenchmark(this, test, options, recordTable, progressBar);
-    },
-    
-    titles: Titles,
-    tests: [
+Suites.push(new Suite("SVG suite",
+    [
         {
             url: "../tests/bouncing-particles/bouncing-svg-shapes.html?gain=6&addLimit=100&removeLimit=1000&particleWidth=12&particleHeight=12&shape=circle",
             name: "SVG bouncing circles",
@@ -159,24 +134,10 @@ Suites.push({
             name: "SVG bouncing PNG images"
         },
     ]
-});
+));
 
-Suites.push({
-    name: "More complex examples",
-    prepare: function(runner, contentWindow, contentDocument)
-    {
-        return runner.waitForElement("#stage").then(function (element) {
-            return element;
-        });
-    },
-    
-    run: function(contentWindow, test, options, recordTable, progressBar)
-    {
-        return contentWindow.runBenchmark(this, test, options, recordTable, progressBar);
-    },
-    
-    titles: Titles,
-    tests: [
+Suites.push(new Suite("Complex examples",
+    [
         {
             url: "../tests/examples/canvas-electrons.html?gain=1&addLimit=100&removeLimit=10",
             name: "canvas electrons"
@@ -186,24 +147,10 @@ Suites.push({
             name: "canvas stars"
         },
     ]
-});
+));
 
-Suites.push({
-    name: "Stage Templates (Can be used for new tests)",
-    prepare: function(runner, contentWindow, contentDocument)
-    {
-        return runner.waitForElement("#stage").then(function (element) {
-            return element;
-        });
-    },
-    
-    run: function(contentWindow, test, options, recordTable, progressBar)
-    {
-        return contentWindow.runBenchmark(this, test, options, recordTable, progressBar);
-    },
-    
-    titles: Titles,
-    tests: [
+Suites.push(new Suite("Test Templates",
+    [
         {
             url: "../tests/template/template-css.html?gain=1&addLimit=100&removeLimit=5",
             name: "CSS template"
@@ -217,7 +164,7 @@ Suites.push({
             name: "SVG template"
         },
     ]
-});
+));
 
 function suiteFromName(name)
 {
index c6d973b..c9fe6c6 100644 (file)
@@ -1,5 +1,49 @@
 2015-10-12  Jon Lee  <jonlee@apple.com>
 
+        Refactor test suites to a separate class.
+        https://bugs.webkit.org/show_bug.cgi?id=150053
+        <rdar://problem/23078645>
+
+        Reviewed by Dean Jackson.
+
+        Create a Suite class to refactor out prepare() and run().
+        Generate the checkboxes representing the suites using Suites
+        instead of maintaining a separate list. Also, save the
+        selections out to localStorage.
+
+        * Animometer/runner/animometer.html: Remove the explicitly listed
+        suites. These will be generated from Suites instead.
+        * Animometer/runner/resources/animometer.js:
+        (populateSettings): Iterate through Suites, and create the
+        label and checkbox. Attach the Suite object to the checkbox so
+        when the benchmark is started, we get direct access. Initialize
+        the checkmark based on its value in localStorage. Set this to
+        run when DOMContentLoaded is dispatched.
+        (startBenchmark): Grab all of the checkboxes, inspect their
+        values, add it to enabledSuites if selected. Remember whether
+        the suite was enabled in localStorage, so that it's easy to do
+        repeated runs.
+        * Animometer/runner/resources/tests.js:
+        (Suite): Create a new Suite class. Refactor out prepare() and
+        run(), since all of them have the same implementation. Populate
+        Suites with Suite instances instead of generic objects.
+
+2015-10-12  Jon Lee  <jonlee@apple.com>
+
+        Update graph styles for legibility.
+        https://bugs.webkit.org/show_bug.cgi?id=150052
+        <rdar://problem/23078503>
+
+        Reviewed by Dean Jackson.
+
+        * Animometer/runner/resources/animometer.css: Update colors and
+        stroke thicknesses to make the graphs easier to read.
+        (.smaple-time): Correct to .sample-time
+        * Animometer/runner/resources/graph.js:
+        (graph): Ditto.
+
+2015-10-12  Jon Lee  <jonlee@apple.com>
+
         Update graph styles for legibility.
         https://bugs.webkit.org/show_bug.cgi?id=150052
         <rdar://problem/23078503>