Bug 1380003 - Enable avoid-Date-timing eslint rule on testing/talos, r?jmaher draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Tue, 11 Jul 2017 12:34:44 -0400
changeset 608417 f85900852f3d285f4ba8d4add08f38b40ac85618
parent 608416 1d83c7cbac4d7fbcfe99ca560e7f7e1fd33180e5
child 637286 e883be06476ad5b084c9317069de6ff1254b83cf
push id68257
push userahalberstadt@mozilla.com
push dateThu, 13 Jul 2017 15:10:41 +0000
reviewersjmaher
bugs1380003
milestone56.0a1
Bug 1380003 - Enable avoid-Date-timing eslint rule on testing/talos, r?jmaher MozReview-Commit-ID: 6b6GtBUpZUZ
testing/talos/.eslintrc.js
testing/talos/talos/pageloader/chrome/pageloader.js
testing/talos/talos/pageloader/chrome/report.js
testing/talos/talos/pageloader/chrome/tscroll.js
testing/talos/talos/startup_test/sessionrestore/addon/content/main.js
testing/talos/talos/startup_test/tresize/addon/content/framescript.js
testing/talos/talos/startup_test/tresize/addon/content/tresize.js
testing/talos/talos/startup_test/tspaint_test.html
testing/talos/talos/talos-powers/chrome/talos-powers-content.js
testing/talos/talos/tests/a11y/dhtml.html
testing/talos/talos/tests/a11y/tablemutation.html
testing/talos/talos/tests/devtools/addon/content/framescript.js
testing/talos/talos/tests/tabpaint/bootstrap.js
testing/talos/talos/tests/tabpaint/content/tabpaint.html
testing/talos/talos/tests/tart/addon/content/framescript.js
--- a/testing/talos/.eslintrc.js
+++ b/testing/talos/.eslintrc.js
@@ -17,10 +17,18 @@ module.exports = {
     "gBrowser": false,
     "removeMessageListener": false,
     "sendAsyncMessage": false,
     "sendSyncMessage": false,
     "TalosPowersContent": true,
     "TalosPowersParent": true,
     "TalosContentProfiler": true,
     "tpRecordTime": true
+  },
+
+  "plugins": [
+    "mozilla"
+  ],
+
+  "rules": {
+    "mozilla/avoid-Date-timing": "error"
   }
 };
--- a/testing/talos/talos/pageloader/chrome/pageloader.js
+++ b/testing/talos/talos/pageloader/chrome/pageloader.js
@@ -1,14 +1,15 @@
 /* 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/. */
 
 /* import-globals-from memory.js */
 /* import-globals-from report.js */
+/* eslint mozilla/avoid-Date-timing: "off" */
 
 try {
   if (Cc === undefined) {
     var Cc = Components.classes;
     var Ci = Components.interfaces;
   }
 } catch (ex) {}
 
--- a/testing/talos/talos/pageloader/chrome/report.js
+++ b/testing/talos/talos/pageloader/chrome/report.js
@@ -75,17 +75,17 @@ Report.prototype.getReport = function() 
   }
   report += "__end_tp_report\n";
 
   if (this.showTotalCCTime) {
     report += "__start_cc_report\n";
     report += "_x_x_mozilla_cycle_collect," + this.totalCCTime + "\n";
     report += "__end_cc_report\n";
   }
-  var now = (new Date()).getTime();
+  var now = (new Date()).getTime();  // eslint-disable-line mozilla/avoid-Date-timing
   report += "__startTimestamp" + now + "__endTimestamp\n"; // timestamp for determning shutdown time, used by talos
 
   return report;
 }
 
 Report.prototype.getReportSummary = function() {
 
   function average(arr) {
--- a/testing/talos/talos/pageloader/chrome/tscroll.js
+++ b/testing/talos/talos/pageloader/chrome/tscroll.js
@@ -81,16 +81,17 @@ function testScroll(target, stepSize, op
       // Provides an alternative tpRecordTime (with some stats display) if running in a browser.
       if (!report && document.head) {
         var imported = document.createElement("script");
         imported.addEventListener("load", function() {
           report = tpRecordTime;
           resolve();
         });
 
+        // eslint-disable-next-line mozilla/avoid-Date-timing
         imported.src = "../../scripts/talos-debug.js?dummy=" + Date.now(); // For some browsers to re-read
         document.head.appendChild(imported);
         return;
       }
 
       resolve();
     });
   }
@@ -111,17 +112,17 @@ function testScroll(target, stepSize, op
     return new Promise(function(resolve) {
       rAF(resolve);
     });
   }
 
   function myNow() {
     return (win.performance && win.performance.now) ?
             win.performance.now() :
-            Date.now();
+            Date.now();  // eslint-disable-line mozilla/avoid-Date-timing
   }
 
   var isWindow = target.self === target;
 
   var getPos =       isWindow ? function() { return target.pageYOffset; }
                               : function() { return target.scrollTop; };
 
   var gotoTop =      isWindow ? function() { target.scroll(0, 0); ensureScroll(); }
--- a/testing/talos/talos/startup_test/sessionrestore/addon/content/main.js
+++ b/testing/talos/talos/startup_test/sessionrestore/addon/content/main.js
@@ -24,17 +24,17 @@ addEventListener("load", function() {
 
       // Report data to Talos, if possible
       dumpLog("__start_report" +
               duration +
               "__end_report\n\n");
 
       // Next one is required by the test harness but not used
       dumpLog("__startTimestamp" +
-              Date.now() +
+              Date.now() +  // eslint-disable-line mozilla/avoid-Date-timing
               "__endTimestamp\n\n");
       goQuitApplication();
   });
 
   // In case the add-on has broadcasted the message before we were loaded,
   // request a second broadcast.
   Services.cpmm.sendAsyncMessage(MSG_REQUEST, {});
 });
--- a/testing/talos/talos/startup_test/tresize/addon/content/framescript.js
+++ b/testing/talos/talos/startup_test/tresize/addon/content/framescript.js
@@ -1,12 +1,13 @@
 (function() {
   const TRESIZE_PREFIX = "tresize@mozilla.org:";
 
   addEventListener(TRESIZE_PREFIX + "chrome-run-event", function(e) {
+    // eslint-disable-next-line mozilla/avoid-Date-timing
     var uniqueMessageId = TRESIZE_PREFIX + content.document.documentURI + Date.now() + Math.random();
 
     addMessageListener(TRESIZE_PREFIX + "chrome-run-reply", function done(reply) {
       if (reply.data.id == uniqueMessageId) {
         removeMessageListener(TRESIZE_PREFIX + "chrome-run-reply", done);
         content.wrappedJSObject.logResults(reply.data.result);
       }
     });
--- a/testing/talos/talos/startup_test/tresize/addon/content/tresize.js
+++ b/testing/talos/talos/startup_test/tresize/addon/content/tresize.js
@@ -45,16 +45,17 @@ function testCompleted() {
     }
     var average = (total / count);
     var retVal = [];
     if (dumpDataSet) {
       retVal.push("__start_reporttresize-test.html," + diffs + "__end_report\n");
     } else {
       retVal.push("__start_report" + average + "__end_report\n");
     }
+    // eslint-disable-next-line mozilla/avoid-Date-timing
     retVal.push("__startTimestamp" + Date.now() + "__endTimestamp\n");
     finish(retVal);
   } catch (ex) { finish([ex + "\n"]); }
 }
 
 function resizeCompleted() {
   count++;
   if (count >= max) {
--- a/testing/talos/talos/startup_test/tspaint_test.html
+++ b/testing/talos/talos/startup_test/tspaint_test.html
@@ -49,16 +49,17 @@ function dumpConsoleAndQuit() {
   }
 
   for (var i = 0; i < messages.value.length; i++)
     dumpLog(messages.value[i].message + "\n");
 
   // Close window asynchronously, there might still be startup operations that still need to run
   window.setTimeout(function() {
     if (window.dump) {
+      // eslint-disable-next-line mozilla/avoid-Date-timing
       dumpLog("__startTimestamp" + Date.now() + "__endTimestamp\n");
     }
     goQuitApplication();
     window.close();
   }, 0);
 }
 
 window.addEventListener("MozAfterPaint", painted, true);
--- a/testing/talos/talos/talos-powers/chrome/talos-powers-content.js
+++ b/testing/talos/talos/talos-powers/chrome/talos-powers-content.js
@@ -95,17 +95,17 @@ addEventListener("TalosPowersContentGetS
  */
 addEventListener("TalosPowers:ParentExec:QueryEvent", function(e) {
   if (content.location.protocol != "file:" &&
       content.location.hostname != "localhost" &&
       content.location.hostname != "127.0.0.1") {
     throw new Error("TalosPowers:ParentExec may only be used with local content");
   }
   let uniqueMessageId = "TalosPowers:ParentExec:"
-                      + content.document.documentURI + Date.now() + Math.random();
+                      + content.document.documentURI + Date.now() + Math.random();  // eslint-disable-line mozilla/avoid-Date-timing
 
   // Listener for the reply from the parent process
   addMessageListener("TalosPowers:ParentExec:ReplyMsg", function done(reply) {
     if (reply.data.id != uniqueMessageId)
       return;
 
     removeMessageListener("TalosPowers:ParentExec:ReplyMsg", done);
 
--- a/testing/talos/talos/tests/a11y/dhtml.html
+++ b/testing/talos/talos/tests/a11y/dhtml.html
@@ -12,17 +12,17 @@
   function doInsertion() {
     if (!initAccessibility()) {
       dump("__FAILinit:AccessibilityUnvailable__FAIL");
       return;
     }
 
     var container = document.getElementById("container");
     var lastchild = document.getElementById("lastchild");
-    var start = new Date();
+    var start = new Date();  // eslint-disable-line mozilla/avoid-Date-timing
     var i, div;
     for (i = 0; i < 2000; i++) {
       div = document.createElement("div");
       div.innerHTML = "<input type='text' value='a bc def g hijkl mn op qrs'/>";
       container.insertBefore(div, lastchild);
     }
     for (i = 0; i < 2000; i++) {
       div = document.createElement("div");
@@ -38,16 +38,16 @@
       container.appendChild(div);
     }
     document.documentElement.offsetLeft; // flush layout
     setTimeout(postProcessingRecord, 0, start);
   }
 
   function postProcessingRecord(s) {
     // alert(new Date() - s);
-    tpRecordTime(new Date() - s, s);
+    tpRecordTime(new Date() - s, s);  // eslint-disable-line mozilla/avoid-Date-timing
   }
 </script>
 </head>
 <body onload="doInsertion();">
   <div id="container" role="application"><div id="lastchild"></div></div>
 </body>
 </html>
--- a/testing/talos/talos/tests/a11y/tablemutation.html
+++ b/testing/talos/talos/tests/a11y/tablemutation.html
@@ -112,24 +112,24 @@ function mutateTable() {
   // Start with a cached accessible tree
   if (!initAccessibility()) {
     dump("__FAILinit:AccessibilityUnvailable__FAIL");
     return;
   }
 
   ensureAccessibleTree("start");
 
-  var start = new Date();
+  var start = new Date();  // eslint-disable-line mozilla/avoid-Date-timing
 
   // Cause all kinds of crazy events
   Range.deleteContents();
   Range.insertNode(Fragment);
 
   document.documentElement.offsetLeft; // flush layout
 
   setTimeout(postProcessingRecord, 0, start);
 }
 
 function postProcessingRecord(s) {
   // alert(new Date() - s);
-  tpRecordTime(new Date() - s, s);
+  tpRecordTime(new Date() - s, s);  // eslint-disable-line mozilla/avoid-Date-timing
 }
 </script>
--- a/testing/talos/talos/tests/devtools/addon/content/framescript.js
+++ b/testing/talos/talos/tests/devtools/addon/content/framescript.js
@@ -2,16 +2,17 @@
   const PREFIX = "damp@mozilla.org:";
 
   addEventListener(PREFIX + "chrome-exec-event", function(e) {
     if (content.document.documentURI.indexOf("chrome://damp/content/damp.html")) {
       // Can have url fragment. Backward compatible version of !str.startsWidth("prefix")
       throw new Error("Cannot be used outside of DAMP's launch page");
     }
 
+    // eslint-disable-next-line mozilla/avoid-Date-timing
     var uniqueMessageId = PREFIX + content.document.documentURI + Date.now() + Math.random();
 
     addMessageListener(PREFIX + "chrome-exec-reply", function done(reply) {
       if (reply.data.id == uniqueMessageId) {
         removeMessageListener(PREFIX + "chrome-exec-reply", done);
         e.detail.doneCallback(reply.data.result);
       }
     });
--- a/testing/talos/talos/tests/tabpaint/bootstrap.js
+++ b/testing/talos/talos/tests/tabpaint/bootstrap.js
@@ -150,16 +150,17 @@ var TabPaint = {
    * @return Promise
    *         Resolves once the tab has been fully removed. Resolves
    *         with the time (in ms) it took to open the tab from the parent.
    */
   openTabFromParent(gBrowser) {
     return new Promise((resolve) => {
       this.Profiler.resume("tabpaint parent start");
 
+      // eslint-disable-next-line mozilla/avoid-Date-timing
       gBrowser.selectedTab = gBrowser.addTab(TARGET_URI + "?" + Date.now(), {
         triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
       });
 
       this.whenTabShown().then(({tab, delta}) => {
         this.Profiler.pause("tabpaint parent end");
         this.removeTab(tab).then(() => {
           resolve(delta);
--- a/testing/talos/talos/tests/tabpaint/content/tabpaint.html
+++ b/testing/talos/talos/tests/tabpaint/content/tabpaint.html
@@ -15,17 +15,17 @@
 
             let { fromParent, fromContent } = msg.data;
 
             tpRecordTime([fromParent, fromContent].join(","), 0, "tabpaint-from-parent, tabpaint-from-content");
           });
 
           mm.addMessageListener("TabPaint:OpenFromContent", function openFromContent() {
             let target = document.getElementById("target");
-            let now = Date.now();
+            let now = Date.now();  // eslint-disable-line mozilla/avoid-Date-timing
             let href = "target.html?" + now;
             target.href = href;
             target.click();
           });
 
           mm.sendAsyncMessage("TabPaint:Go");
         }
       }
--- a/testing/talos/talos/tests/tart/addon/content/framescript.js
+++ b/testing/talos/talos/tests/tart/addon/content/framescript.js
@@ -2,16 +2,17 @@
   const TART_PREFIX = "tart@mozilla.org:";
 
   addEventListener(TART_PREFIX + "chrome-exec-event", function(e) {
     if (content.document.documentURI.indexOf("chrome://tart/content/tart.html")) {
       // Can have url fragment. Backward compatible version of !str.startsWidth("prefix")
       throw new Error("Cannot be used outside of TART's launch page");
     }
 
+    // eslint-disable-next-line mozilla/avoid-Date-timing
     var uniqueMessageId = TART_PREFIX + content.document.documentURI + Date.now() + Math.random();
 
     addMessageListener(TART_PREFIX + "chrome-exec-reply", function done(reply) {
       if (reply.data.id == uniqueMessageId) {
         removeMessageListener(TART_PREFIX + "chrome-exec-reply", done);
         e.detail.doneCallback(reply.data.result);
       }
     });