author Jan Henning <>
Sat, 12 Jan 2019 18:34:54 +0000
changeset 453639 81378c45a359
child 453886 041f9c2bfce5
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:

  <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");
  let visualX = window.visualViewport.pageLeft;
  ok(visualX > 0, "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(
  } else {
    topWinUtils = SpecialPowers.getDOMWindowUtils(window);
                          () => 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, visualX, "visual viewport remains unchanged");


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