Bug 1517976 - Test that resetting WindowUtils.isFirstPaint doesn't clobber APZ scroll position. r=botond
☠☠ backed out by 80aa2eb75893 ☠ ☠
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 11 Jan 2019 21:21:41 +0000
changeset 453568 0355f47af6ce
parent 453567 b9d64807cd97
child 453569 e69490bbd056
push id35360
push usernbeleuzu@mozilla.com
push dateSat, 12 Jan 2019 09:39:47 +0000
treeherdermozilla-central@cb35977ae7a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1517976
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
gfx/layers/apz/test/mochitest/helper_bug1509575.html
gfx/layers/apz/test/mochitest/test_group_touchevents-4.html
new file mode 100644
--- /dev/null
+++ b/gfx/layers/apz/test/mochitest/helper_bug1509575.html
@@ -0,0 +1,77 @@
+<!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>
--- a/gfx/layers/apz/test/mochitest/test_group_touchevents-4.html
+++ b/gfx/layers/apz/test/mochitest/test_group_touchevents-4.html
@@ -4,19 +4,23 @@
   <meta charset="utf-8">
   <title>Various touch tests that spawn in new windows (4)</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
   <script type="application/javascript" src="apz_test_utils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript">
 
+var basic_pan_prefs = getPrefs("TOUCH_EVENTS:PAN");
+
 var subtests = [
   // clicking on element with :active::after CSS property
   {"file": "helper_bug1473108.html"},
+  // Resetting isFirstPaint shouldn't clobber the visual viewport
+  {"file": "helper_bug1509575.html", "prefs": [...basic_pan_prefs, ["dom.meta-viewport.enabled", true]]},
   // Add new subtests here. If this starts timing out because it's taking too
   // long, create a test_group_touchevents-5.html file. Refer to 1423011#c57
   // for more details.
 ];
 
 if (isApzEnabled()) {
   ok(window.TouchEvent, "Check if TouchEvent is supported (it should be, the test harness forces it on everywhere)");
   if (getPlatform() == "android") {