Bug 1469897 - Add a complex pointer-events hit-testing test. r=botond
authorKartikaya Gupta <kgupta@mozilla.com>
Mon, 18 Mar 2019 23:05:59 +0000
changeset 465035 31f675dd6c707c2e3c488a35ced02c043cd328cb
parent 465034 3fef04ae16fdec2f909464d380f309e7dc1342cb
child 465036 82e0ac6d662e14a1868c2fb7ac067b4205c965dc
push id35730
push userrmaries@mozilla.com
push dateTue, 19 Mar 2019 21:51:47 +0000
treeherdermozilla-central@4f6d8ed9e948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1469897
milestone68.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 1469897 - Add a complex pointer-events hit-testing test. r=botond Differential Revision: https://phabricator.services.mozilla.com/D23910
gfx/layers/apz/test/mochitest/helper_hittest_pointerevents_svg.html
gfx/layers/apz/test/mochitest/test_group_hittest.html
new file mode 100644
--- /dev/null
+++ b/gfx/layers/apz/test/mochitest/helper_hittest_pointerevents_svg.html
@@ -0,0 +1,167 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Hit-testing a scrollframe covered by nonrectangular and pointer-events:none things</title>
+  <script type="application/javascript" src="apz_test_utils.js"></script>
+  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/paint_listener.js"></script>
+  <meta name="viewport" content="width=device-width"/>
+  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+<style>
+    .scroller {
+        overflow: scroll;
+        width: 100px;
+        height: 100px;
+    }
+
+    .scroller > div {
+        height: 200px;
+        background-image: linear-gradient(#fff,#000);
+    }
+</style>
+</head>
+<body>
+<div id="testcase1">
+  <div style="width: 100px;height: 50px;display: inline-block;">
+    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="overflow: visible;background-color: #aa6666;">
+      <circle cx="80" cy="50" r="50"></circle>
+    </svg>
+  </div>
+  <div class="scroller" style="display: inline-block;"><div></div></div>
+  <div style="width: 100px; height: 100px; display: inline-block; position:relative;">
+    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="overflow: visible;background-color: #aa6666;">
+      <circle cx="20" cy="50" r="50"></circle>
+    </svg>
+  </div>
+</div>
+
+<div id="testcase2" style="position:relative; height: 110px;">
+  <div style="width: 100px;height: 100px;position:absolute;pointer-events:none;left: 25px;">
+    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="background-color: #aa6666;pointer-events: none;">
+      <circle cx="75" cy="50" r="50" style="pointer-events: auto;"></circle>
+    </svg>
+  </div>
+  <div class="scroller" style="position: absolute; left: 100px;"><div></div></div>
+  <div style="width: 100px;height: 100px; position:absolute;pointer-events:none;left: 175px;">
+    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="background-color: #aa6666;pointer-events: none;">
+      <circle cx="45" cy="50" r="50" style="pointer-events: auto;"></circle>
+    </svg>
+  </div>
+</div>
+
+<div id="testcase3">
+  <div style="width: 100px;height: 50px;display: inline-block;">
+    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="overflow: visible;background-color: #aa6666;">
+      <rect x="25" y="25" width="100" height="50"></rect>
+    </svg>
+  </div>
+  <div class="scroller" style="display: inline-block;"><div></div></div>
+  <div style="width: 100px; height: 100px; display: inline-block; position:relative;">
+    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="overflow: visible;background-color: #aa6666;">
+      <rect x="-30" y="25" width="100" height="50"></rect>
+    </svg>
+  </div>
+</div>
+
+<div id="testcase4" style="position:relative; height: 110px;">
+  <div style="width: 100px;height: 100px;position:absolute;pointer-events:none;left: 25px;">
+    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="background-color: #aa6666;pointer-events: none;">
+      <rect x="25" y="25" width="100" height="50" style="pointer-events: auto;"></rect>
+    </svg>
+  </div>
+  <div class="scroller" style="position: absolute; left: 100px;"><div></div></div>
+  <div style="width: 100px;height: 100px; position:absolute;pointer-events:none;left: 175px;">
+    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="background-color: #aa6666;pointer-events: none;">
+      <rect x="-25" y="25" width="100" height="50" style="pointer-events: auto;"></rect>
+    </svg>
+  </div>
+</div>
+
+<div style="width: 40em;">
+  Each of the gradients should be scrollable, except where the black stuff on the right cover them.
+  The brown square should not prevent scrolling. Similarly, the content on the left (which goes
+  underneath the scroller) shouldn't matter.
+</div>
+<script>
+
+function* test(testDriver) {
+  var config = getHitTestConfig();
+  var utils = config.utils;
+
+  // layerize the scrollable frames
+  for (var scroller of document.querySelectorAll(".scroller")) {
+    utils.setDisplayPortForElement(0, 0, 100, 200, scroller, 1);
+  }
+  yield waitForApzFlushedRepaints(testDriver);
+
+  var rootViewId = utils.getViewId(document.scrollingElement);
+  for (var testId = 1; testId <= 4; testId++) {
+    var target = document.querySelector(`#testcase${testId} .scroller`);
+    var scrollerViewId = utils.getViewId(target);
+    checkHitResult(hitTest(centerOf(target)),
+                   APZHitResultFlags.VISIBLE,
+                   scrollerViewId,
+                   `center of scroller in testcase ${testId}`);
+
+    var bounds = target.getBoundingClientRect();
+    var verticalScrollbarWidth = bounds.width - target.clientWidth;
+    var horizontalScrollbarHeight = bounds.height - target.clientHeight;
+
+    // these points should all hit the target scroller
+    checkHitResult(hitTest({x: bounds.x + 1, y: bounds.y + 1}),
+                   APZHitResultFlags.VISIBLE,
+                   scrollerViewId,
+                   `top left of scroller in testcase ${testId}`);
+    checkHitResult(hitTest({x: bounds.x + 1, y: bounds.y + (bounds.height / 2)}),
+                   APZHitResultFlags.VISIBLE,
+                   scrollerViewId,
+                   `middle left of scroller in testcase ${testId}`);
+    checkHitResult(hitTest({x: bounds.x + 1, y: bounds.bottom - horizontalScrollbarHeight - 1}),
+                   APZHitResultFlags.VISIBLE,
+                   scrollerViewId,
+                   `bottom left (excluding scrollbar) of scroller in testcase ${testId}`);
+    if (horizontalScrollbarHeight > 0) {
+      checkHitResult(hitTest({x: bounds.x + 1, y: bounds.bottom - 1}),
+                     APZHitResultFlags.VISIBLE | APZHitResultFlags.SCROLLBAR,
+                     scrollerViewId,
+                     `bottom left of scroller in testcase ${testId}`);
+    }
+
+    // With the first two cases (circle masks) both WebRender and non-WebRender
+    // emit dispatch-to-content regions for the right side, so for now we just
+    // test for that. Eventually WebRender should be able to stop emitting DTC
+    // and we can update this test to be more precise in that case.
+    // For the two rectangular test cases we get precise results rather than
+    // dispatch-to-content.
+    if (testId == 1 || testId == 2) {
+      checkHitResult(hitTest({x: bounds.right - verticalScrollbarWidth - 1, y: bounds.y + 1}),
+                     APZHitResultFlags.VISIBLE | APZHitResultFlags.DISPATCH_TO_CONTENT,
+                     rootViewId,
+                     `top right of scroller in testcase ${testId}`);
+      checkHitResult(hitTest({x: bounds.right - verticalScrollbarWidth - 1, y: bounds.bottom - horizontalScrollbarHeight - 1}),
+                     APZHitResultFlags.VISIBLE | APZHitResultFlags.DISPATCH_TO_CONTENT,
+                     rootViewId,
+                     `bottom right of scroller in testcase ${testId}`);
+    } else {
+      checkHitResult(hitTest({x: bounds.right - verticalScrollbarWidth - 1, y: bounds.y + 1}),
+                     APZHitResultFlags.VISIBLE,
+                     scrollerViewId,
+                     `top right of scroller in testcase ${testId}`);
+      checkHitResult(hitTest({x: bounds.right - verticalScrollbarWidth - 1, y: bounds.bottom - horizontalScrollbarHeight - 1}),
+                     APZHitResultFlags.VISIBLE,
+                     scrollerViewId,
+                     `bottom right of scroller in testcase ${testId}`);
+    }
+
+    checkHitResult(hitTest({x: bounds.right - 1, y: bounds.y + (bounds.height / 2)}),
+                   APZHitResultFlags.VISIBLE | APZHitResultFlags.DISPATCH_TO_CONTENT,
+                   rootViewId,
+                   `middle right of scroller in testcase ${testId}`);
+  }
+}
+
+waitUntilApzStable()
+    .then(runContinuation(test))
+    .then(subtestDone);
+</script>
+</body></html>
--- a/gfx/layers/apz/test/mochitest/test_group_hittest.html
+++ b/gfx/layers/apz/test/mochitest/test_group_hittest.html
@@ -32,16 +32,17 @@ var subtests = [
   {"file": "helper_hittest_float_bug1434846.html", "prefs": prefs},
   {"file": "helper_hittest_float_bug1443518.html", "prefs": prefs},
   {"file": "helper_hittest_checkerboard.html", "prefs": prefs},
   {"file": "helper_hittest_backface_hidden.html", "prefs": prefs},
   {"file": "helper_hittest_touchaction.html", "prefs": prefs},
   {"file": "helper_hittest_nested_transforms_bug1459696.html", "prefs": prefs},
   {"file": "helper_hittest_sticky_bug1478304.html", "prefs": prefs},
   {"file": "helper_hittest_clipped_fixed_modal.html", "prefs": prefs},
+  {"file": "helper_hittest_pointerevents_svg.html", "prefs": prefs},
 ];
 
 if (isApzEnabled()) {
   SimpleTest.waitForExplicitFinish();
   window.onload = function() {
     runSubtestsSeriallyInFreshWindows(subtests)
     .then(SimpleTest.finish, SimpleTest.finish);
   };