Bug 1442515 Refactor test_eventTimeStamp.html to pass r?baku draft
authorTom Ritter <tom@mozilla.com>
Tue, 06 Mar 2018 10:18:12 -0600
changeset 763736 47f6e866e7407fcfba681bb3181e6a206c3fd40c
parent 763735 2e94febd1f0986c8397122e476dbd18fa0b6d557
child 763744 7bf4504d33788af5e8d1702a7c7dcd6249d85dc8
push id101542
push userbmo:tom@mozilla.com
push dateTue, 06 Mar 2018 16:18:41 +0000
reviewersbaku
bugs1442515
milestone60.0a1
Bug 1442515 Refactor test_eventTimeStamp.html to pass r?baku Previously, we waited for the load event and used that event timestamp. But as far as I can tell the intent of this test is not to test the load event specifically, but just event timestamps. In opt builds, the reduceTimerPrecision pref was not being populated fast enough to take effect during the load process, and was causing (a lot of) intermittent failures. We refactor the test to use PushPrefEnv and test a different event. MozReview-Commit-ID: ILJYHRhUHnM
dom/events/test/test_eventTimeStamp.html
old mode 100644
new mode 100755
--- a/dom/events/test/test_eventTimeStamp.html
+++ b/dom/events/test/test_eventTimeStamp.html
@@ -30,54 +30,44 @@ https://bugzilla.mozilla.org/show_bug.cg
   };
 </script>
 <script type="application/javascript">
 "use strict";
 
 SimpleTest.waitForExplicitFinish();
 SimpleTest.requestFlakyTimeout("untriaged");
 
-// We don't use SpecialPowers.pushPrefEnv since it can delay the test
-// function until after the load event has fired which means we can't
-// test the timestamp of the load event.
-const kHighResTimestampsPrefName = "dom.event.highrestimestamp.enabled";
-var highRestimerPrevPrefValue = SpecialPowers.getBoolPref(kHighResTimestampsPrefName);
-SpecialPowers.setBoolPref(kHighResTimestampsPrefName, true);
-
 // This file performs tests that normalize the timeOrigin within a worker
 // and compare it to the page. When this occurs, time can appear to go backwards.
-// This is a known (and accepted) regression.
-const kReduceTimePrecisionPrefName = "privacy.reduceTimerPrecision";
-var reduceTimePrecisionPrevPrefValue = SpecialPowers.getBoolPref(kReduceTimePrecisionPrefName);
-SpecialPowers.setBoolPref(kReduceTimePrecisionPrefName, false);
-testRegularEvents();
+// This is a known (and accepted) regression of privacy.reduceTimerPrecision so
+// we need to turn it off.
+SpecialPowers.pushPrefEnv({ "set": [
+    ["privacy.reduceTimerPrecision", false],
+    ["dom.event.highrestimestamp.enabled", true]
+  ]}, testRegularEvents);
 
 // Event.timeStamp should be relative to the time origin which is:
 //
 //   Non-worker context: navigation start
 //   Dedicated worker: navigation start of the document that created the worker
 //   Shared worker: creation time of the shared worker
 //
 // See: https://w3c.github.io/web-performance/specs/HighResolutionTime2/Overview.html#sec-time-origin
 
 function testRegularEvents() {
-  if (document.readyState === "complete") {
-    ok(false, "Onload event has already fired");
-    finishTests();
-    return;
-  }
   var timeBeforeEvent = performance.now();
-  addEventListener("load", function(evt) {
+  document.getElementById('test').addEventListener("click", function(evt) {
     var timeAfterEvent = performance.now();
     ok(evt.timeStamp >= timeBeforeEvent &&
        evt.timeStamp <= timeAfterEvent,
        "Event timestamp (" + evt.timeStamp + ") is in expected range: [" +
          timeBeforeEvent + ", " + timeAfterEvent + "]");
     testWorkerEvents();
   });
+  document.getElementById('test').click();
 }
 
 function testWorkerEvents() {
   var blob = new Blob([ document.getElementById("worker-src").textContent ],
                       { type: "text/javascript" });
   var worker = new Worker(URL.createObjectURL(blob));
   worker.onmessage = function(evt) {
     var timeAfterEvent = performance.now() + performance.timeOrigin;
@@ -102,28 +92,26 @@ function testSharedWorkerEvents() {
   setTimeout(function() {
   var timeBeforeEvent = performance.now() + performance.timeOrigin;
     var worker = new SharedWorker(URL.createObjectURL(blob));
     worker.port.onmessage = function(evt) {
       var timeAfterEvent = performance.now() + performance.timeOrigin;
       ok(evt.data >= timeBeforeEvent &&
          evt.data <= timeAfterEvent,
          "Event timestamp in shared worker (" + evt.data +
-           ") is in expected range: (0, " +
-           timeBeforeEvent + ", " + timeAfterEvent + ")");
+           ") is in expected range: [" +
+           timeBeforeEvent + ", " + timeAfterEvent + "]");
       worker.port.close();
       finishTests();
     };
     worker.port.start();
     worker.port.postMessage("");
   }, 500);
 }
 
 var finishTests = function() {
-  SpecialPowers.setBoolPref(kHighResTimestampsPrefName, highRestimerPrevPrefValue);
-  SpecialPowers.setBoolPref(kReduceTimePrecisionPrefName, reduceTimePrecisionPrevPrefValue);
   SimpleTest.finish();
 };
 
 </script>
 </pre>
 </body>
 </html>