Bug 1512838 - Add mochitests to exercise the one-touch-pinch code. r=botond
☠☠ backed out by 8f2a6dbf221c ☠ ☠
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 15 Mar 2019 20:30:01 +0000
changeset 464444 589f41b2e253
parent 464443 6bd80d61cee8
child 464445 e58902a844dd
push id35716
push useraciure@mozilla.com
push dateSun, 17 Mar 2019 09:42:17 +0000
treeherdermozilla-central@8ee97c045359 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1512838
milestone67.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 1512838 - Add mochitests to exercise the one-touch-pinch code. r=botond The helper_basic_onetouchpinch.html is basically a copy of helper_basic_zoom.html with a few things changed (most importantly, the touch event sequence). Differential Revision: https://phabricator.services.mozilla.com/D23496
gfx/layers/apz/test/mochitest/helper_basic_onetouchpinch.html
gfx/layers/apz/test/mochitest/helper_onetouchpinch_nested.html
gfx/layers/apz/test/mochitest/test_group_zoom.html
new file mode 100644
--- /dev/null
+++ b/gfx/layers/apz/test/mochitest/helper_basic_onetouchpinch.html
@@ -0,0 +1,94 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <meta name="viewport" content="width=device-width">
+  <title>Sanity check for one-touch pinch zooming</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) {
+  let visResEvt = new EventCounter(window.visualViewport, "resize");
+  let visScrEvt = new EventCounter(window.visualViewport, "scroll");
+  // Our internal visual viewport events aren't restricted to the visual view-
+  // port itself, so we can listen on the window itself, however the event
+  // listener needs to be in the system group.
+  let visResEvtInternal = new EventCounter(window, "mozvisualresize",
+                                           { mozSystemGroup: true });
+  let visScrEvtInternal = new EventCounter(window, "mozvisualscroll",
+                                           { mozSystemGroup: true });
+  let visResEvtContent = new EventCounter(window, "mozvisualresize");
+  let visScrEvtContent = new EventCounter(window, "mozvisualscroll");
+
+  var initial_resolution = getResolution();
+  ok(initial_resolution > 0,
+      "The initial_resolution is " + initial_resolution + ", which is some sane value");
+
+  // This listener will trigger the test to continue once APZ is done with
+  // processing the scroll.
+  SpecialPowers.Services.obs.addObserver(testDriver, "APZ:TransformEnd");
+
+  var zoom_in = [
+      [ { x: 150, y: 300 } ],
+      [ null ],
+      [ { x: 150, y: 300 } ],
+      [ { x: 150, y: 305 } ],
+      [ { x: 150, y: 310 } ],
+      [ { x: 150, y: 315 } ],
+      [ { x: 150, y: 320 } ],
+      [ { x: 150, y: 325 } ],
+  ];
+
+  var touchIds = [0];
+  yield* synthesizeNativeTouchSequences(document.body, zoom_in, null, touchIds);
+
+  // 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 and get the resolution we're at now
+  yield waitForApzFlushedRepaints(testDriver);
+  let final_resolution = getResolution();
+  ok(final_resolution > initial_resolution, "The final resolution (" + final_resolution + ") is greater after zooming in");
+
+  // Check we've got the expected events.
+  // Zooming the page should fire visual viewport resize events:
+  visResEvt.unregister();
+  ok(visResEvt.count > 0, "Got some visual viewport resize events");
+  visResEvtInternal.unregister();
+  ok(visResEvtInternal.count > 0, "Got some mozvisualresize events");
+
+  // We're zooming somewhere in the middle of the page, so the visual
+  // viewport's coordinates change, too.
+  // This is true both relative to the page (mozvisualscroll), as well as
+  // relative to the layout viewport (visual viewport "scroll" event).
+  visScrEvt.unregister();
+  ok(visScrEvt.count > 0, "Got some visual viewport scroll events");
+  visScrEvtInternal.unregister();
+  ok(visScrEvtInternal.count > 0, "Got some mozvisualscroll events");
+
+  // Our internal events shouldn't leak to normal content.
+  visResEvtContent.unregister();
+  is(visResEvtContent.count, 0, "Got no mozvisualresize events in content");
+  visScrEvtContent.unregister();
+  is(visScrEvtContent.count, 0, "Got no mozvisualscroll events in content");
+}
+
+waitUntilApzStable()
+.then(runContinuation(test))
+.then(subtestDone);
+
+  </script>
+</head>
+<body>
+  Here is some text to stare at as the test runs. It serves no functional
+  purpose, but gives you an idea of the zoom level. It's harder to tell what
+  the zoom level is when the page is just solid white.
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/gfx/layers/apz/test/mochitest/helper_onetouchpinch_nested.html
@@ -0,0 +1,109 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <meta name="viewport" content="width=device-width">
+  <title>One-touch pinch zooming while on a non-root scroller</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_onetouchpinch(testDriver) {
+  // layerize the scroller so it gets an APZC and GestureEventListener
+  var scroller = document.getElementById("scroller");
+  SpecialPowers.getDOMWindowUtils(window).setDisplayPortForElement(0, 0, 400, 1000, scroller, 1);
+  yield waitForApzFlushedRepaints(testDriver);
+
+  ok(isLayerized("scroller"), "scroller has been successfully layerized");
+
+  var initial_resolution = getResolution();
+  ok(initial_resolution > 0,
+      "The initial_resolution is " + initial_resolution + ", which is some sane value");
+
+  // This listener will trigger the test to continue once APZ is done with
+  // processing the scroll.
+  SpecialPowers.Services.obs.addObserver(testDriver, "APZ:TransformEnd");
+
+  function translateY(point, dy) {
+    return {x: point.x, y: point.y + dy};
+  }
+
+  var zoom_point = centerOf(scroller);
+  var zoom_in = [
+      [ zoom_point ],
+      [ null ],
+      [ zoom_point ],
+      [ translateY(zoom_point, 5) ],
+      [ translateY(zoom_point, 10) ],
+      [ translateY(zoom_point, 15) ],
+      [ translateY(zoom_point, 20) ],
+      [ translateY(zoom_point, 25) ],
+  ];
+
+  var touchIds = [0];
+  yield* synthesizeNativeTouchSequences(scroller, zoom_in, null, touchIds);
+
+  // 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 and get the resolution we're at now
+  yield waitForApzFlushedRepaints(testDriver);
+  let final_resolution = getResolution();
+  ok(final_resolution > initial_resolution, "The final resolution (" + final_resolution + ") is greater after zooming in");
+
+  // Also check that the scroller didn't get scrolled.
+  is(scroller.scrollTop, 0, "scroller didn't y-scroll");
+  is(scroller.scrollLeft, 0, "scroller didn't x-scroll");
+}
+
+function* test(testDriver) {
+  // Run the test with the scrollable div
+  yield* test_onetouchpinch(testDriver);
+  dump("Wrapping scroller in fixed-pos div...\n");
+  // Now wrap the scrollable div inside a fixed-pos div
+  var fixedElement = document.createElement("div");
+  fixedElement.id = "fixed";
+  document.body.appendChild(fixedElement);
+  fixedElement.appendChild(document.getElementById("scroller"));
+  dump("Done wrapping scroller in fixed-pos div.\n");
+  // Now run the test again, with the scrollable div inside a fixed-pos div
+  yield* test_onetouchpinch(testDriver);
+}
+
+waitUntilApzStable()
+.then(runContinuation(test))
+.then(subtestDone);
+
+  </script>
+  <style>
+    #scroller {
+        width: 300px;
+        height: 300px;
+        overflow: scroll;
+    }
+
+    #fixed {
+        background-color: green;
+        position: fixed;
+        width: 300px;
+        height: 300px;
+        left: 100px;
+        top: 100px;
+    }
+  </style>
+</head>
+<body>
+  Here is some text outside the scrollable div.
+  <div id="scroller">
+   Here is some text inside the scrollable div.
+   <div style="height: 2000px">This div actually makes it overflow.</div>
+  </div>
+  <div style="height: 2000px">This div makes the body scrollable.</div>
+</body>
+</html>
--- a/gfx/layers/apz/test/mochitest/test_group_zoom.html
+++ b/gfx/layers/apz/test/mochitest/test_group_zoom.html
@@ -40,23 +40,35 @@ var prefs = [
 // Increase the tap timeouts so the double-tap is still detected in case of
 // random delays during testing.
 var doubletap_prefs = [
   ...prefs,
   ["ui.click_hold_context_menus.delay", 10000],
   ["apz.max_tap_time", 10000],
 ];
 
+// Increase the tap timeouts so the one-touch-pinch gesture is still detected
+// in case of random delays during testing. Also ensure that the feature is
+// actually enabled (which it should be by default, but it's good to be safe).
+var onetouchpinch_prefs = [
+  ...prefs,
+  ["apz.one_touch_pinch.enabled", true],
+  ["ui.click_hold_context_menus.delay", 10000],
+  ["apz.max_tap_time", 10000],
+];
+
 var subtests = [
   {"file": "helper_bug1280013.html", "prefs": prefs},
   {"file": "helper_basic_zoom.html", "prefs": prefs},
+  {"file": "helper_basic_onetouchpinch.html", "prefs": onetouchpinch_prefs},
   {"file": "helper_zoom_prevented.html", "prefs": prefs},
   {"file": "helper_zoomed_pan.html", "prefs": prefs},
   {"file": "helper_fixed_position_scroll_hittest.html", "prefs": prefs},
   {"file": "helper_basic_doubletap_zoom.html", "prefs": doubletap_prefs},
+  {"file": "helper_onetouchpinch_nested.html", "prefs": onetouchpinch_prefs},
 ];
 
 if (isApzEnabled()) {
   // This has a lot of subtests, and Android emulators are slow.
   SimpleTest.requestLongerTimeout(2);
   SimpleTest.waitForExplicitFinish();
   window.onload = function() {
     runSubtestsSeriallyInFreshWindows(subtests)