summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_hittest_overscroll_subframe.html
blob: 36918b3682642e61da98a0b8e7b167c3401bcef2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE HTML>
<html>
<head>
  <title>Test APZ hit-testing while overscrolled</title>
  <script type="application/javascript" src="apz_test_utils.js"></script>
  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
  <script src="/tests/SimpleTest/paint_listener.js"></script>
  <meta name="viewport" content="width=device-width"/>
  <style>
    html, body {
      margin: 0;
      padding: 0;
    }
    #subframe {
      width: 100px;
      height: 100px;
      overflow: scroll;
    }
    .spacer {
      height: 5000px;
    }
    #target {
      margin-left: 20px;
      margin-top: 2px;
      height: 4px;
      width: 4px;
      background: red;
    }
  </style>
</head>
<body>
 <div id="subframe">
   <div id="target"></div>
   <div class="spacer"></div>
 </div>
 <div class="spacer"></div>
</body>
<script type="application/javascript">

async function test() {
  var config = getHitTestConfig();
  var utils = config.utils;

  // Subframe hit testing of overscrolled APZCs does not yet work with WebRender
  // (bug 1701831), so bail out early.
  if (true) {
    todo(false, "This test does not currently pass with WebRender");
    return;
  }

  // Activate the subframe. This both matches reality (if you're
  // scrolling the subframe, it's active), and makes it easier
  // to check for expected hit test outcomes.
  utils.setDisplayPortForElement(0, 0, 500, 500, subframe, 1);
  await promiseApzFlushedRepaints();

  // Overscroll the subframe at the top, creating a gutter.
  // Note that the size of the gutter will only be 8px, because
  // setAsyncScrollOffset() applies the overscroll as a single delta,
  // and current APZ logic that transforms a delta into an overscroll
  // amount limits each delta to at most 8px.
  utils.setAsyncScrollOffset(subframe, 0, -200);

  // Check that the event hits the subframe frame in APZ.
  // This is important because additional pan-gesture events in the gutter
  // should continue to be handled and cause further overscroll (or
  // relieving overscroll, depending on their direction).
  let subframeBounds = subframe.getBoundingClientRect();
  hitResult = hitTest({
    x: subframeBounds.x + 50,
    y: subframeBounds.y + 4
  });
  let subframeViewId = utils.getViewId(subframe);
  checkHitResult(hitResult,
                 APZHitResultFlags.VISIBLE,
                 subframeViewId,
                 utils.getLayersId(),
                 "APZ hit-test in the subframe gutter");

  // Now, perform a click in the gutter and check that APZ prevents
  // the event from reaching Gecko.
  // To be sure that no event was dispatched to Gecko, install the listener
  // on the document, not the subframe.
  // This makes sure we catch the case where the overscroll transform causes
  // the event to incorrectly target the document.
  let receivedClick = false;
  let listener = function(e) {
    receivedClick = true;
  };
  document.addEventListener("click", listener);
  await synthesizeNativeMouseEventWithAPZ({
    type: "click",
    target: subframe,
    offsetX: 50,
    offsetY: 4
  });
  // Wait 10 frames for the event to maybe arrive, and if it
  // hasn't, assume it won't.
  for (let i = 0; i < 10; i++) {
    await promiseFrame();
  }
  info("Finished waiting around for click event");
  ok(!receivedClick, "Gecko received click event when it shouldn't have");
  document.removeEventListener("click", listener);

  // Finally, while still overscrolled, perform a click not in the gutter.
  // This event should successfully go through to the web content, and
  // be untransformed by the overscroll transform (such that it hits the
  // content that is visually under the cursor).
  let clickPromise = new Promise(resolve => {
    document.addEventListener("click", function(e) {
      info("event clientX = " + e.clientX);
      info("event clientY = " + e.clientY);
      is(e.target, target, "Click while overscrolled hit intended target");
      resolve();
    }, { once: true });
  });
  await synthesizeNativeMouseEventWithAPZ({
    type: "click",
    target: window,
    offsetX: 22,
    offsetY: 12
  });
  await clickPromise;
}

waitUntilApzStable()
.then(test)
.then(subtestDone, subtestFailed);

</script>
</html>