Bug 1506497 - Add a mochitest. r=botond
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 15 Mar 2019 18:11:29 +0000
changeset 464424 e925aaf5ac9a8a9f4e9dcf493bd2e04f46bb757f
parent 464423 db7eb307e78b6d4831dd36804f5c1b5933a093f8
child 464425 1f911d12fd0737a2107c8b0cc98cf3d62165d7db
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
bugs1506497
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 1506497 - Add a mochitest. r=botond Depends on D23570 Differential Revision: https://phabricator.services.mozilla.com/D23571
gfx/layers/apz/test/mochitest/apz_test_utils.js
gfx/layers/apz/test/mochitest/helper_bug1506497_touch_action_fixed_on_fixed.html
gfx/layers/apz/test/mochitest/test_group_touchevents-3.html
gfx/layers/apz/test/mochitest/test_group_touchevents-4.html
--- a/gfx/layers/apz/test/mochitest/apz_test_utils.js
+++ b/gfx/layers/apz/test/mochitest/apz_test_utils.js
@@ -749,16 +749,22 @@ function getPrefs(ident) {
         // The helper_div_pan's div gets a displayport on scroll, but if the
         // test takes too long the displayport can expire before the new scroll
         // position is synced back to the main thread. So we disable displayport
         // expiry for these tests.
         ["apz.displayport_expiry_ms", 0],
         // All of test cases should define viewport meta tag.
         ["dom.meta-viewport.enabled", true],
       ];
+    case "TOUCH_ACTION":
+      return [
+        ...getPrefs("TOUCH_EVENTS:PAN"),
+        ["layout.css.touch_action.enabled", true],
+        ["apz.test.fails_with_native_injection", getPlatform() == "windows"],
+      ];
     default:
       return [];
   }
 }
 
 var ApzCleanup = {
   _cleanups: [],
 
new file mode 100644
--- /dev/null
+++ b/gfx/layers/apz/test/mochitest/helper_bug1506497_touch_action_fixed_on_fixed.html
@@ -0,0 +1,90 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <meta name="viewport" content="width=device-width; initial-scale=1.0">
+  <title>Test for Bug 1506497</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) {
+  document.getElementById("overlay").addEventListener("touchstart", function(e) {
+    // no need to do anything here. Just having a non-passive touchstart
+    // listener will force APZ to wait for the main thread to handle the
+    // touch event. The bug is that the touch-action:none property on the
+    // overlay gets ignored in this case and the body gets scrolled.
+  }, {passive: false});
+
+  // Ensure that APZ gets updated hit-test info
+  yield waitForAllPaints(testDriver);
+
+  // Register a listener that fails the test if the APZ:TransformEnd event fires,
+  // because this test shouldn't actually be triggering any transforms
+  SpecialPowers.Services.obs.addObserver(function() {
+    ok(false, "The test fired an unexpected APZ:TransformEnd");
+  }, "APZ:TransformEnd");
+
+  // Listen for changes to the visual viewport offset.
+  let visScrEvtInternal = new EventCounter(window, "mozvisualscroll",
+                                           { mozSystemGroup: true });
+
+  // This listener will continue the test after the main thread has processed
+  // all the synthesized touch events.
+  var waitForTouchEnd = function(e) {
+    dump("touchend listener hit\n");
+    setTimeout(testDriver, 0);
+  };
+  document.documentElement.addEventListener("touchend", waitForTouchEnd, {passive: true, once: true});
+
+  synthesizeNativeTouchDrag(document.getElementById("boxOnTop"), 5, 5, 0, -50);
+  dump("finished drag, waiting for touchend listener...");
+  yield;
+
+  // Flush state.
+  yield waitForApzFlushedRepaints(testDriver);
+
+  // Check that the touch was prevented, per the touch-action
+  is(window.scrollY, 0, "window didn't scroll");
+  is(document.scrollingElement.scrollTop, 0, "scrollingElement didn't scroll");
+  visScrEvtInternal.unregister();
+  is(visScrEvtInternal.count, 0, "visual viewport didn't scroll");
+}
+
+waitUntilApzStable()
+.then(runContinuation(test))
+.then(subtestDone);
+
+  </script>
+  <style>
+    #filler {
+        height: 3000px;
+        background-image: linear-gradient(red, blue, green);
+    }
+    #overlay {
+        position: fixed;
+        width: 100%;
+        height: 100%;
+        left: 0;
+        top: 0;
+        touch-action: none;
+    }
+    #boxOnTop {
+        position: fixed;
+        background-color: coral;
+        width: 20vw;
+        height: 20vh;
+        left: 40%;
+        top: 40%;
+    }
+  </style>
+</head>
+<body>
+ <div id="filler"></div>
+ <div id="overlay">
+   <div id="boxOnTop">Touch here and drag up</div>
+ </div>
+</body>
+</html>
--- a/gfx/layers/apz/test/mochitest/test_group_touchevents-3.html
+++ b/gfx/layers/apz/test/mochitest/test_group_touchevents-3.html
@@ -4,21 +4,17 @@
   <meta charset="utf-8">
   <title>Various touch tests that spawn in new windows (3)</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 touch_action_prefs = [
-  ...getPrefs("TOUCH_EVENTS:PAN"),
-  ["layout.css.touch_action.enabled", true],
-  ["apz.test.fails_with_native_injection", getPlatform() == "windows"],
-];
+var touch_action_prefs = getPrefs("TOUCH_ACTION");
 
 var subtests = [
   // Simple test to exercise touch-action CSS property
   {"file": "helper_touch_action.html", "prefs": touch_action_prefs},
   // More complex touch-action tests, with overlapping regions and such
   {"file": "helper_touch_action_complex.html", "prefs": touch_action_prefs},
   // Tests that touch-action CSS properties are handled in APZ without waiting
   // on the main-thread, when possible
--- a/gfx/layers/apz/test/mochitest/test_group_touchevents-4.html
+++ b/gfx/layers/apz/test/mochitest/test_group_touchevents-4.html
@@ -5,22 +5,25 @@
   <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 touch_action_prefs = getPrefs("TOUCH_ACTION");
 
 var subtests = [
   // clicking on element with :active::after CSS property
   {"file": "helper_bug1473108.html", "prefs": [["dom.meta-viewport.enabled", true]]},
   // Resetting isFirstPaint shouldn't clobber the visual viewport
   {"file": "helper_bug1509575.html", "prefs": basic_pan_prefs},
+  // Exercise one of the main-thread touch-action determination codepaths.
+  {"file": "helper_bug1506497_touch_action_fixed_on_fixed.html", "prefs": touch_action_prefs},
   // 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") {