Bug 1437295 - Ensure that we have a compositor APZ testdata before running the test. r?botond draft
authorKartikaya Gupta <kgupta@mozilla.com>
Sat, 10 Mar 2018 23:26:28 -0500
changeset 765931 d88fe185c2351c5330ee8f14b77d158217b9dcc2
parent 765930 cc23cdb7eaa0c7ce3298bdaaebc8b6c1b76ee662
push id102181
push userkgupta@mozilla.com
push dateSun, 11 Mar 2018 04:27:20 +0000
reviewersbotond
bugs1437295
milestone60.0a1
Bug 1437295 - Ensure that we have a compositor APZ testdata before running the test. r?botond MozReview-Commit-ID: zV4J3pChIy
gfx/layers/apz/test/mochitest/apz_test_utils.js
gfx/layers/apz/test/mochitest/helper_bug1151663.html
--- a/gfx/layers/apz/test/mochitest/apz_test_utils.js
+++ b/gfx/layers/apz/test/mochitest/apz_test_utils.js
@@ -335,16 +335,39 @@ async function waitUntilApzStable() {
     await waitUntilApzStable.chromeHelper.promiseOneMessage("apz-flush-done");
   }
 
   await SimpleTest.promiseFocus(window);
   await promiseAllPaintsDone();
   await promiseApzRepaintsFlushed();
 }
 
+// This function returns a promise that is resolved after at least one paint
+// has been sent and processed by the compositor. This function can force
+// such a paint to happen if none are pending. This is useful to run after
+// the waitUntilApzStable() but before reading the compositor-side APZ test
+// data, because the test data for the content layers id only gets populated
+// on content layer tree updates *after* the root layer tree has a RefLayer
+// pointing to the contnet layer tree. waitUntilApzStable itself guarantees
+// that the root layer tree is pointing to the content layer tree, but does
+// not guarantee the subsequent paint; this function does that job.
+async function forceLayerTreeToCompositor() {
+  var utils = SpecialPowers.getDOMWindowUtils(window);
+  if (!utils.isMozAfterPaintPending) {
+    dump("Forcing a paint since none was pending already...\n");
+    var testMode = utils.isTestControllingRefreshes;
+    utils.advanceTimeAndRefresh(0);
+    if (!testMode) {
+      utils.restoreNormalRefresh();
+    }
+  }
+  await promiseAllPaintsDone();
+  await promiseApzRepaintsFlushed();
+}
+
 function isApzEnabled() {
   var enabled = SpecialPowers.getDOMWindowUtils(window).asyncPanZoomEnabled;
   if (!enabled) {
     // All tests are required to have at least one assertion. Since APZ is
     // disabled, and the main test is presumably not going to run, we stick in
     // a dummy assertion here to keep the test passing.
     SimpleTest.ok(true, "APZ is not enabled; this test will be skipped");
   }
--- a/gfx/layers/apz/test/mochitest/helper_bug1151663.html
+++ b/gfx/layers/apz/test/mochitest/helper_bug1151663.html
@@ -21,47 +21,45 @@ https://bugzilla.mozilla.org/show_bug.cg
     //
     // In this test we have a simple page which is scrollable, with a 
     // scrollable <div> which is also scrollable. We test that the
     // <div> does not get an initial APZC, since primary scrollable
     // frame is the page's root scroll frame.
     // --------------------------------------------------------------------
 
     function testBug1151663() {
-      // Get the content- and compositor-side test data from nsIDOMWindowUtils.
-      var contentTestData = utils.getContentAPZTestData();
+      // Get the compositor-side test data from nsIDOMWindowUtils.
       var compositorTestData = utils.getCompositorAPZTestData();
 
       // Get the sequence number of the last paint on the compositor side.
       // We do this before converting the APZ test data because the conversion
       // loses the order of the paints.
       SimpleTest.ok(compositorTestData.paints.length > 0,
                     "expected at least one paint in compositor test data");
       var lastCompositorPaint = compositorTestData.paints[compositorTestData.paints.length - 1];
       var lastCompositorPaintSeqNo = lastCompositorPaint.sequenceNumber;
 
       // Convert the test data into a representation that's easier to navigate.
-      contentTestData = convertTestData(contentTestData);
       compositorTestData = convertTestData(compositorTestData);
       var paint = compositorTestData.paints[lastCompositorPaintSeqNo];
 
       // Reconstruct the APZC tree structure in the last paint.
       var apzcTree = buildApzcTree(paint);
 
       // The apzc tree for this page should consist of a single root APZC,
       // which either is the RCD with no child APZCs (e10s/B2G case) or has a
       // single child APZC which is for the RCD (fennec case).
       var rcd = findRcdNode(apzcTree);
       SimpleTest.ok(rcd != null, "found the RCD node");
       SimpleTest.is(rcd.children.length, 0, "expected no children on the RCD");
 
       window.opener.finishTest();
     }
 
-    waitUntilApzStable().then(testBug1151663);
+    waitUntilApzStable().then(forceLayerTreeToCompositor).then(testBug1151663);
   </script>
 </head>
 <body style="height: 500px; overflow: scroll">
   <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1151663">Mozilla Bug 1151663</a>
   <div style="height: 50px; width: 50px; overflow: scroll">
     <!-- Put enough content into the subframe to make it have a nonzero scroll range -->
     <div style="height: 100px; width: 50px"></div>
   </div>