gfx/layers/apz/test/mochitest/helper_bug1509575.html
author Jan Henning <jh+bugzilla@buttercookie.de>
Fri, 11 Jan 2019 21:21:41 +0000
changeset 453568 0355f47af6ce
permissions -rw-r--r--
Bug 1517976 - Test that resetting WindowUtils.isFirstPaint doesn't clobber APZ scroll position. r=botond We need to setup a case where the visual viewport is smaller than the layout viewport. Faking a pinch zoom through touch events is imprecise, whereas calling windowUtils.setResolutionAndScaleTo(value > 1) to simulate the equivalent effect of a pinch-zoom on the page led to the subsequent scroll attempt failing quite often even after calling waitForApzFlushedRepaints(). So instead, we set up a very wide layout viewport through the meta viewport tag, which on Desktop means additionally enabling the dom.meta-viewport.enabled pref. Differential Revision: https://phabricator.services.mozilla.com/D15791

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1509575
-->
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=2000, initial-scale=1.0">
  <title>Test for Bug 1509575</title>
  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
  <script type="application/javascript" src="apz_test_utils.js"></script>
  <script type="application/javascript" src="/tests/SimpleTest/paint_listener.js"></script>
  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="application/javascript">

function* test(testDriver) {
  // This listener will trigger the test to continue once APZ is done with
  // processing the scroll.
  SpecialPowers.Services.obs.addObserver(testDriver, "APZ:TransformEnd");

  synthesizeNativeTouchDrag(document.body, 10, 100, -100, 0);
  dump("Finished native drag, waiting for transform-end observer...\n");

  // Wait for the APZ:TransformEnd to be fired after touch events are processed.
  yield true;

  // We get here once the APZ:TransformEnd has fired, so we don't need that
  // observer any more.
  SpecialPowers.Services.obs.removeObserver(testDriver, "APZ:TransformEnd");

  // Flush state.
  yield waitForApzFlushedRepaints(testDriver);

  is(window.scrollX, 0, "layout viewport didn't scroll");
  is(window.visualViewport.pageLeft, 100, "visual viewport did scroll");

  let topWinUtils;
  const isE10s = SpecialPowers.Services.appinfo.browserTabsRemoteAutostart;
  // We need to reset the first paint flag on the root document in the process
  // this test is loaded in.
  if (!isE10s) {
    // For non-e10s, such as in Fennec, this means we need the *chrome* window
    // as the topmost entitiy in this process.
    topWinUtils = SpecialPowers.getDOMWindowUtils(
        SpecialPowers._getTopChromeWindow(window));
  } else {
    topWinUtils = SpecialPowers.getDOMWindowUtils(window);
  }
  window.addEventListener("MozAfterPaint",
                          () => setTimeout(testDriver, 0), {once: true});
  ok(topWinUtils.isFirstPaint === false, "first paint not set");
  topWinUtils.isFirstPaint = true;
  // do something that forces a paint *and* an APZ update.
  document.getElementById("expand").style.width = "6000px";

  // Wait for the event listener to fire.
  yield true;
  ok(true, "MozAfterPaint fired");

  // Flush state just to be sure.
  yield waitForApzFlushedRepaints(testDriver);

  todo_is(window.visualViewport.pageLeft, 100, "visual viewport remains unchanged");
}

waitUntilApzStable()
.then(runContinuation(test))
.then(subtestDone);

  </script>
</head>
<body>
 <div id="expand" style="background-color: paleturquoise ;">
  Now you're scrolled, now you're not?
 </div>
</body>
</html>