Bug 1256128 - Update test to handle a tricky race condition where the input event processing is delayed a little. r=botond a=test-only
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 20 Sep 2016 09:05:38 -0400
changeset 350368 aee0f090712afdefc44ddf6198515d31d3053a1b
parent 350367 49788f46f9b6ffb93bb524556f59b20aa2c7dc8a
child 350369 0d060a21dd5df7a3b3c557dfb61a52ac5fdda2d3
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond, test-only
bugs1256128
milestone50.0
Bug 1256128 - Update test to handle a tricky race condition where the input event processing is delayed a little. r=botond a=test-only MozReview-Commit-ID: H7YOhSLYkpF
gfx/layers/apz/test/mochitest/test_layerization.html
--- a/gfx/layers/apz/test/mochitest/test_layerization.html
+++ b/gfx/layers/apz/test/mochitest/test_layerization.html
@@ -146,21 +146,36 @@ function* test(testDriver) {
   ok(!isLayerized('outer2'), "outer2 got de-layerized with inner2");
 
   // Scroll on inner3. inner3 isn't layerized, and this will cause it to
   // get layerized, but it will also trigger displayport expiration for inner3
   // which will eventually trigger displayport expiration on inner3 and outer3.
   // Note that the displayport expiration might actually happen before the wheel
   // input is processed in the compositor (see bug 1246480 comment 3), and so
   // we make sure not to wait for a scroll event here, since it may never fire.
-  yield scrollWheelOver(document.getElementById('outer3').contentDocument.getElementById('inner3'), false, testDriver);
+  // However, if we do get a scroll event while waiting for the expiry, we need
+  // to restart the expiry timer because the displayport expiry got reset. There's
+  // no good way that I can think of to deterministically avoid doing this.
+  let inner3 = document.getElementById('outer3').contentDocument.getElementById('inner3');
+  yield scrollWheelOver(inner3, false, testDriver);
   yield waitForAllPaints(function() {
     flushApzRepaints(testDriver);
   });
-  yield setTimeout(testDriver, DISPLAYPORT_EXPIRY);
+  var timerId = setTimeout(testDriver, DISPLAYPORT_EXPIRY);
+  var timeoutResetter = function() {
+    ok(true, "Got a scroll event; resetting timer...");
+    clearTimeout(timerId);
+    setTimeout(testDriver, DISPLAYPORT_EXPIRY);
+    // by not updating timerId we ensure that this listener resets the timeout
+    // at most once.
+  };
+  inner3.addEventListener('scroll', timeoutResetter, false);
+  yield; // wait for the setTimeout to elapse
+  inner3.removeEventListener('scroll', timeoutResetter, false);
+
   yield waitForAllPaints(asyncWrapper(testDriver));
   ok(!isLayerized('inner3'), "inner3 becomes unlayerized after expiry");
   yield setTimeout(testDriver, DISPLAYPORT_EXPIRY);
   yield waitForAllPaints(asyncWrapper(testDriver));
   ok(!isLayerized('outer3'), "outer3 is no longer layerized after inner3 triggered expiry");
 
   // Scroll outer4 and wait for the expiry. It should NOT get expired because
   // inner4 is still layerized