Bug 1369360 - (Intermittent intersection-observer/timestamp.html) Calculate timeSkew more reliable for low frame rates. r=jgraham
authorTobias Schneider <schneider@jancona.com>
Tue, 01 Aug 2017 13:21:42 -0700
changeset 423344 8bf8ee2bd98c1ce676eac43ffc2ff6f127b06f40
parent 423343 f4b029e2a35de47ca02a59677821d5770ccdffae
child 423345 2e349fb7c36b7b091ae1786b0acf6a4f35d14923
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgraham
bugs1369360
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1369360 - (Intermittent intersection-observer/timestamp.html) Calculate timeSkew more reliable for low frame rates. r=jgraham
testing/web-platform/tests/intersection-observer/timestamp.html
--- a/testing/web-platform/tests/intersection-observer/timestamp.html
+++ b/testing/web-platform/tests/intersection-observer/timestamp.html
@@ -13,30 +13,38 @@ pre, #log {
   height: calc(100vh + 100px);
 }
 
 </style>
 <div id="leading-space" class="spacer"></div>
 <div id="trailing-space" class="spacer"></div>
 
 <script>
-// Pick this number to be comfortably greater than the length of two frames at 60Hz.
-var timeSkew = 40;
-
 var topWindowEntries = [];
 var iframeWindowEntries = [];
 var targetIframe;
+var topWindowTimeOnTestStart;
+var topWindowTimeBeforeCreatingIframe;
 var topWindowTimeBeforeNotification;
 var iframeWindowTimeBeforeNotification;
+var timeSkew;
+
+function waitFor(numFrames, callback) {
+  if (numFrames <= 0) {
+    callback();
+    return;
+  }
+  window.requestAnimationFrame(waitFor.bind(null, numFrames - 1, callback));
+}
 
 async_test(function(t) {
-  // assert_equals(window.innerWidth, 800, "Window must be 800 pixels wide.");
-  // assert_equals(window.innerHeight, 600, "Window must be 600 pixels high.");
-
-  t.step_timeout(function() {
+  topWindowTimeOnTestStart = performance.now();
+  waitFor(3, function () {
+    topWindowTimeBeforeCreatingIframe = performance.now();
+    timeSkew = topWindowTimeBeforeCreatingIframe - topWindowTimeOnTestStart;
     targetIframe = document.createElement("iframe");
     assert_true(!!targetIframe, "iframe exists");
     targetIframe.src = "resources/timestamp-subframe.html";
     var trailingSpace = document.getElementById("trailing-space");
     assert_true(!!trailingSpace, "trailing-space exists");
     trailingSpace.parentNode.insertBefore(targetIframe, trailingSpace);
     targetIframe.onload = function() {
       var target = targetIframe.contentDocument.getElementById("target");
@@ -53,17 +61,17 @@ async_test(function(t) {
       // from iframe window.
       observer = targetIframe.contentDocument.createObserver(function(newEntries) {
         iframeWindowEntries = iframeWindowEntries.concat(newEntries);
       });
       observer.observe(target);
       runTestCycle(step1, "First rAF after iframe is loaded.");
       t.done();
     };
-  }, timeSkew);
+  });
 }, "Check that timestamps correspond to the to execution context that created the observer.");
 
 function step1() {
   document.scrollingElement.scrollTop = 200;
   targetIframe.contentDocument.scrollingElement.scrollTop = 250;
   topWindowTimeBeforeNotification = performance.now();
   iframeWindowTimeBeforeNotification = targetIframe.contentWindow.performance.now();
   runTestCycle(step2, "Generate notifications.");