From 5fe91a90f55dbcd4c976e17a08fe5d8993076a8b Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Sat, 10 Mar 2018 23:26:28 -0500 Subject: [PATCH] Bug 1437295 - Ensure that we have a compositor APZ testdata before running the test. r=botond MozReview-Commit-ID: zV4J3pChIy --HG-- extra : rebase_source : c4e267f7543525fffda5c27f38b99321e3b9556c --- .../apz/test/mochitest/apz_test_utils.js | 23 +++++++++++++++++++ .../apz/test/mochitest/helper_bug1151663.html | 6 ++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/gfx/layers/apz/test/mochitest/apz_test_utils.js b/gfx/layers/apz/test/mochitest/apz_test_utils.js index 8611ac306a0b..96ad1433e5a1 100644 --- a/gfx/layers/apz/test/mochitest/apz_test_utils.js +++ b/gfx/layers/apz/test/mochitest/apz_test_utils.js @@ -340,6 +340,29 @@ async function waitUntilApzStable() { 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) { diff --git a/gfx/layers/apz/test/mochitest/helper_bug1151663.html b/gfx/layers/apz/test/mochitest/helper_bug1151663.html index a98fc690b7d5..d343ddb7c5c9 100644 --- a/gfx/layers/apz/test/mochitest/helper_bug1151663.html +++ b/gfx/layers/apz/test/mochitest/helper_bug1151663.html @@ -26,8 +26,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1151663 // -------------------------------------------------------------------- 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. @@ -39,7 +38,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1151663 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]; @@ -56,7 +54,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1151663 window.opener.finishTest(); } - waitUntilApzStable().then(testBug1151663); + waitUntilApzStable().then(forceLayerTreeToCompositor).then(testBug1151663);