Bug 1466479 - Cleanup damp from its unused frontend. r=jdescottes draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Fri, 01 Jun 2018 00:22:45 -0700
changeset 806954 0f757437db50e93ec46ad8cf4a96e942da0d9825
parent 806884 75a32b57132f8cba42779555662a057a0416a313
child 806955 a0dee03ae9b2c1c8ca531a9800cc2c0a38828e69
push id113002
push userbmo:poirot.alex@gmail.com
push dateTue, 12 Jun 2018 23:19:12 +0000
reviewersjdescottes
bugs1466479
milestone62.0a1
Bug 1466479 - Cleanup damp from its unused frontend. r=jdescottes MozReview-Commit-ID: GmJ2EmLpfb2
testing/talos/talos/tests/devtools/addon/bootstrap.js
testing/talos/talos/tests/devtools/addon/content/addon-test-frontend.js
testing/talos/talos/tests/devtools/addon/content/damp-tests.js
testing/talos/talos/tests/devtools/addon/content/damp.html
testing/talos/talos/tests/devtools/addon/content/damp.js
testing/talos/talos/tests/devtools/addon/content/initialize_browser.js
--- a/testing/talos/talos/tests/devtools/addon/bootstrap.js
+++ b/testing/talos/talos/tests/devtools/addon/bootstrap.js
@@ -6,17 +6,16 @@
 //
 // The canonical version of this file lives in testing/talos/talos, and
 // is duplicated in a number of test add-ons in directories below it.
 // Please do not update one withput updating all.
 
 // Reads the chrome.manifest from a legacy non-restartless extension and loads
 // its overlays into the appropriate top-level windows.
 
-ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 const windowTracker = {
   init() {
     Services.ww.registerNotification(this);
   },
 
   async observe(window, topic, data) {
@@ -30,22 +29,16 @@ const windowTracker = {
       if (documentURI !== "chrome://browser/content/browser.xul") {
         return;
       }
       initializeBrowser(window);
     }
   },
 };
 
-function readSync(uri) {
-  let channel = NetUtil.newChannel({uri, loadUsingSystemPrincipal: true});
-  let buffer = NetUtil.readInputStream(channel.open2());
-  return new TextDecoder().decode(buffer);
-}
-
 function startup(data, reason) {
   Services.scriptloader.loadSubScript(data.resourceURI.resolve("content/initialize_browser.js"));
   windowTracker.init();
 }
 
 function shutdown(data, reason) {}
 function install(data, reason) {}
 function uninstall(data, reason) {}
--- a/testing/talos/talos/tests/devtools/addon/content/addon-test-frontend.js
+++ b/testing/talos/talos/tests/devtools/addon/content/addon-test-frontend.js
@@ -1,17 +1,11 @@
 // This file is the common bits for the test runner frontend, originally
 // extracted out of the tart.html frontend when creating the damp test.
 
-/* globals updateConfig, defaultConfig, config */ /* from damp.html */
-
-function $(id) {
-  return document.getElementById(id);
-}
-
 // Executes command at the chrome process.
 // Limited to one argument (data), which is enough for TART.
 // doneCallback will be called once done and, if applicable, with the result as argument.
 // Execution might finish quickly (e.g. when setting prefs) or
 // take a while (e.g. when triggering the test run)
 function chromeExec(commandName, data, doneCallback) {
   // dispatch an event to the framescript which will take it from there.
   doneCallback = doneCallback || function dummy() {};
@@ -24,141 +18,17 @@ function chromeExec(commandName, data, d
           data,
         },
         doneCallback
       }
     })
   );
 }
 
-function toClipboard(text) {
-  chromeExec("toClipboard", text);
-}
-
 function runTest(config, doneCallback) {
   chromeExec("runTest", config, doneCallback);
 }
 
-function sum(values) {
-  return values.reduce(function(a, b) { return a + b; });
-}
-
-function average(values) {
-  return values.length ? sum(values) / values.length : 999999999;
-}
-
-function stddev(values, avg) {
-  if (undefined == avg) avg = average(values);
-  if (values.length <= 1) return 0;
-
-  return Math.sqrt(
-    values.map(function(v) { return Math.pow(v - avg, 2); })
-          .reduce(function(a, b) { return a + b; }) / (values.length - 1));
-}
-
-var lastResults = '["[no results collected]"]';
-
-function doneTest(dispResult) {
-  $("hide-during-run").style.display = "block";
-  $("show-during-run").style.display = "none";
-  if (dispResult) {
-    // Array of test results, each element has .name and .value (test name and test result).
-    // Test result may also be an array of numeric values (all the intervals)
-
-    lastResults = JSON.stringify(dispResult); // for "Copy to clipboard" button
-
-    var stats = {}; // Used for average, stddev when repeat!=1
-    var isRepeat = false;
-
-    for (var i in dispResult) {
-      var di = dispResult[i];
-      var disp = [].concat(di.value).map(function(a) { return " " + (isNaN(a) ? -1 : a.toFixed(1)); }).join("&nbsp;&nbsp;");
-      dispResult[i] = String(di.name) + ": " + disp;
-      if (di.name.includes(".half") || di.name.includes(".all"))
-        dispResult[i] = "<b>" + dispResult[i] + "</b>";
-      if (di.name.includes(".raw"))
-        dispResult[i] = "<br/>" + dispResult[i]; // Add space before raw results (which are the first result of an animation)
-
-      // stats:
-      if (!di.name.includes(".raw")) {
-        if (!stats[di.name]) {
-          stats[di.name] = [];
-        } else {
-          isRepeat = true;
-        }
-
-        stats[di.name].push(di.value);
-      }
-    }
-
-    var dispStats = "";
-    if (isRepeat) {
-      dispStats = "<hr/><b>Aggregated</b>:<br/>";
-      for (var s in stats) {
-        if (s.includes(".half") )
-          dispStats += "<br/>";
-        dispStats += s + "&nbsp;&nbsp;&nbsp;&nbsp;Average (" + stats[s].length + "): " + average(stats[s]).toFixed(2) + " stddev: " + stddev(stats[s]).toFixed(2) + "<br/>";
-      }
-
-      dispStats += "<hr/><b>Individual animations</b>:<br/>";
-    }
-
-    // eslint-disable-next-line no-unsanitized/property
-    $("run-results").innerHTML = "<hr/><br/>Results <button onclick='toClipboard(lastResults)'>[ Copy to clipboard as JSON ]</button>:<br/>" + dispStats + dispResult.join("<br/>");
-  }
-}
-
-function triggerStart() {
-  updateConfig();
-  $("hide-during-run").style.display = "none";
-  $("show-during-run").style.display = "block";
-  $("run-results").innerHTML = "";
-
-  runTest(config, doneTest);
-}
-
-function deselectAll() {
-  for (var test of defaultConfig.subtests) {
-    $("subtest-" + test.name).checked = false;
-  }
-}
-
-// E.g. returns "world" for key "hello", "2014" for key "year", and "" for key "dummy":
-// http://localhost/x.html#hello=world&x=12&year=2014
-function getUriHashValue(key) {
-  var k = String(key) + "=";
-  var uriVars = unescape(document.location.hash).substr(1).split("&");
-  for (var i in uriVars) {
-    if (uriVars[i].indexOf(k) == 0)
-      return uriVars[i].substr(k.length);
-  }
-  return "";
-}
-
-// URL e.g. chrome://devtools/content/devtools.html#auto&tests=["simple","iconFadeDpiCurrent"]
-// Note - there's no error checking for arguments parsing errors.
-//        Any errors will express as either javascript errors or not reading the args correctly.
-//        This is not an "official" part of the UI, and when used in talos, will fail early
-//        enough to not cause "weird" issues too late.
-function updateOptionsFromUrl() {
-  var uriTests = getUriHashValue("tests");
-  var tests = uriTests ? JSON.parse(uriTests) : [];
-
-  if (tests.length) {
-    for (var test of defaultConfig.subtests) {
-      $("subtest-" + test.name).checked = false;
-      for (var t in tests) {
-        if (tests[t] == test.name) {
-          $("subtest-" + test.name).checked = true;
-        }
-      }
-    }
-  }
-}
-
 function init() {
-  updateOptionsFromUrl();
-  if (document.location.hash.indexOf("#auto") == 0) {
-    triggerStart();
-  }
+  runTest();
 }
 
 addEventListener("load", init);
--- a/testing/talos/talos/tests/devtools/addon/content/damp-tests.js
+++ b/testing/talos/talos/tests/devtools/addon/content/damp-tests.js
@@ -1,28 +1,30 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
+/* globals module */
+
 /**
  * This is the registry for all DAMP tests. Tests will be run in the order specified by
  * the DAMP_TESTS array.
  *
  * A test is defined with the following properties:
  * - {String} name: the name of the test (should match the path when possible)
  * - {String} path: the path to the test file under
  *   testing/talos/talos/tests/devtools/addon/content/tests/
  * - {String} description: Test description
  * - {Boolean} disabled: set to true to skip the test
  * - {Boolean} cold: set to true to run the test only during the first run of the browser
  */
 
-window.DAMP_TESTS = [
+module.exports = [
   {
     name: "inspector.cold-open",
     path: "inspector/cold-open.js",
     description: "Measure first open toolbox on inspector panel",
     cold: true
   },
   // Run all tests against "simple" document
   {
--- a/testing/talos/talos/tests/devtools/addon/content/damp.html
+++ b/testing/talos/talos/tests/devtools/addon/content/damp.html
@@ -1,68 +1,11 @@
 <html>
   <head>
-<meta charset="UTF-8"/>
-<title>DAMP - Devtools At Maximum Performance</title>
-
-<script src="damp-tests.js"></script>
-<script type="application/x-javascript">
-// Empty subtests interpreted as all subtests, since otherwise meaningless.
-var config = {subtests: [], repeat: 1};
-
-var defaultConfig = {
-  repeat: 1,
-  rest: 100,
-  subtests: window.DAMP_TESTS // from damp-tests.js
-};
+  <meta charset="UTF-8"/>
+  <title>DAMP - Devtools At Maximum Performance</title>
 
-function updateConfig() {
-  config = {subtests: []};
-  for (var test of defaultConfig.subtests) {
-    if ($("subtest-" + test.name).checked) { // eslint-disable-line no-undef
-      config.subtests.push(test);
-    }
-  }
-
-  var repeat = $("repeat").value; // eslint-disable-line no-undef
-  config.repeat = isNaN(repeat) ? 1 : repeat;
-
-  // use 1ms rest as a minimum.
-  var rest = $("rest").value; // eslint-disable-line no-undef
-  config.rest = Math.max(1, isNaN(rest) ? defaultConfig.rest : rest);
-}
-</script>
-<script src="addon-test-frontend.js"></script>
+  <script src="addon-test-frontend.js"></script>
 </head>
 <body style="font-family:sans-serif;">
-<h4>DAMP - Devtools At Maximum Performance</h4>
-<div id="hide-during-run">
-   Visit <a href="https://wiki.mozilla.org/Buildbot/Talos/Tests#DAMP">talos/TART</a> for detailed info.<br/>
-  <ul>
-    <li><b>If you just opened the browser</b> - give Firefox few seconds to settle down before testing.</li>
-  </ul>
-
-Utilities:
-  <a href="pages/simple.html">simple page</a>&nbsp;&nbsp;&nbsp;
-  <a href="http://localhost/tests/tp5n/bild.de/www.bild.de/index.html">complicated page</a>&nbsp;&nbsp;&nbsp;
-<br/><br/>
-<b>Configure DAMP</b> (CTRL-F5 to reset to talos defaults) <button type="button" onclick="deselectAll()">Deselect all tests</button><br/>
-<script>
-  for (let test of defaultConfig.subtests) {
-    let checked = test.disabled ? "unchecked" : "checked";
-    // eslint-disable-next-line no-unsanitized/method
-    document.write(`<input type="checkbox" id="subtest-${test.name}" ${checked}>
-                      ${test.name}
-                    </input>
-                    <span style="color:grey">&nbsp;&nbsp;&nbsp;${test.description}</span>
-                    <br/>`);
-  }
-</script>
-  <br/>
-  Repeat: <input id="repeat" type="text" size=2 value="1" onchange="updateConfig()"/> times<br/>
-  Delay before starting a measured animation: <input id="rest" type="text" size=4 value="10"/> ms<br/>
-
-  <button type="button" id="start-test-button" onclick="triggerStart()">Start Devtools At Maximum Performance tests</button>&nbsp;&nbsp;&nbsp;
-  <div id="run-results"></div>
-</div>
-<div id="show-during-run" style="display:none">Testing in progress ...</div>
+  <h4>DAMP - Devtools At Maximum Performance</h4>
 </body>
 </html>
--- a/testing/talos/talos/tests/devtools/addon/content/damp.js
+++ b/testing/talos/talos/tests/devtools/addon/content/damp.js
@@ -194,17 +194,17 @@ Damp.prototype = {
       }
       browser.reload();
     });
   },
 
   async testSetup(url) {
     let tab = await this.addTab(url);
     await new Promise(resolve => {
-      setTimeout(resolve, this._config.rest);
+      setTimeout(resolve, 100);
     });
     return tab;
   },
 
   async testTeardown(url) {
     this.closeCurrentTab();
 
     // Force freeing memory now so that it doesn't happen during the next test
@@ -214,17 +214,16 @@ Damp.prototype = {
     dump(`${this._currentTest} took ${duration}ms.\n`);
 
     this._runNextTest();
   },
 
   _win: undefined,
   _dampTab: undefined,
   _results: [],
-  _config: {subtests: [], repeat: 1, rest: 100},
   _nextTestIndex: 0,
   _tests: [],
   _onSequenceComplete: 0,
 
   // Timeout ID to guard against current test never finishing
   _timeout: null,
 
   // The unix time at which the current test started (ms)
@@ -392,58 +391,56 @@ Damp.prototype = {
       requestIdleCallback(resolve, { timeout: 15000 });
     });
 
     // Free memory before running the first test, otherwise we may have a GC
     // related to Firefox startup or DAMP setup during the first test.
     await this.garbageCollect();
   },
 
-  startTest(doneCallback, config) {
+  startTest(doneCallback) {
     try {
       dump("Initialize the head file with a reference to this DAMP instance\n");
       let head = require("chrome://damp/content/tests/head.js");
       head.initialize(this);
 
       this._onTestComplete = function(results) {
         TalosParentProfiler.pause("DAMP - end");
         doneCallback(results);
       };
-      this._config = config;
 
       this._win = Services.wm.getMostRecentWindow("navigator:browser");
       this._dampTab = this._win.gBrowser.selectedTab;
       this._win.gBrowser.selectedBrowser.focus(); // Unfocus the URL bar to avoid caret blink
 
       TalosParentProfiler.resume("DAMP - start");
 
       // Filter tests via `./mach --subtests filter` command line argument
       let filter = Services.prefs.getCharPref("talos.subtests", "");
 
-      let tests = config.subtests.filter(test => !test.disabled)
-                                 .filter(test => test.name.includes(filter));
+      let DAMP_TESTS = require("chrome://damp/content/damp-tests.js");
+      let tests = DAMP_TESTS.filter(test => !test.disabled)
+                            .filter(test => test.name.includes(filter));
 
       if (tests.length === 0) {
         this.error(`Unable to find any test matching '${filter}'`);
       }
 
       // Run cold test only once
       let topWindow = getMostRecentBrowserWindow();
       if (topWindow.coldRunDAMPDone) {
         tests = tests.filter(test => !test.cold);
       } else {
         topWindow.coldRunDAMPDone = true;
       }
 
       // Construct the sequence array while filtering tests
       let sequenceArray = [];
       for (let test of tests) {
-        for (let r = 0; r < config.repeat; r++) {
-          sequenceArray.push(test.path);
-        }
+        sequenceArray.push(test.path);
       }
 
      this.waitBeforeRunningTests().then(() => {
         this._doSequence(sequenceArray, this._doneInternal);
       }).catch(e => {
         this.exception(e);
       });
     } catch (e) {
--- a/testing/talos/talos/tests/devtools/addon/content/initialize_browser.js
+++ b/testing/talos/talos/tests/devtools/addon/content/initialize_browser.js
@@ -4,22 +4,16 @@ function initializeBrowser(win) {
 
   const PREFIX = "damp@mozilla.org:";
 
   // "services" which the framescript can execute at the chrome process
   var proxiedServices = {
     runTest(config, callback) {
       (new win.Damp()).startTest(callback, config);
     },
-
-    toClipboard(text) {
-      const gClipboardHelper = Cc["@mozilla.org/widget/clipboardhelper;1"]
-                                   .getService(Ci.nsIClipboardHelper);
-      gClipboardHelper.copyString(text);
-    }
   };
 
   var groupMM = win.getGroupMessageManager("browsers");
   groupMM.loadFrameScript("chrome://damp/content/framescript.js", true);
 
   // listener/executor on the chrome process for damp.html
   groupMM.addMessageListener(PREFIX + "chrome-exec-message", function listener(m) {
     function sendResult(result) {