Bug 1256128 - Update test to handle a tricky race condition where the input event processing is delayed a little. r?botond draft
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 20 Sep 2016 09:05:38 -0400
changeset 415518 43b23869726bf740025b8a4063a69c5fc220a3f9
parent 415495 62f79d676e0e11b3ad59a5425b3ebb3ec5bbefb5
child 531626 702e69539fd48df353c53d437c60902c46b75524
push id29889
push userkgupta@mozilla.com
push dateTue, 20 Sep 2016 13:06:31 +0000
reviewersbotond
bugs1256128
milestone52.0a1
Bug 1256128 - Update test to handle a tricky race condition where the input event processing is delayed a little. r?botond 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