summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_hittest_basic.html
blob: a9e9f0c07f5aeb3bac3ae762e2858263b36f70ba (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
133
134
135
136
137
138
139
140
141
<!DOCTYPE HTML>
<html>
<head>
  <title>Various tests to exercise the APZ hit-testing codepaths</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"/>
</head>
<body>
 <div id="scroller" style="width: 300px; height: 300px; overflow:scroll; margin-top: 100px; margin-left: 50px">
  <div id="contents" style="width: 500px; height: 500px; background-image: linear-gradient(blue,red)">
   <div id="apzaware" style="position: relative; width: 100px; height: 100px; top: 300px; background-color: red" onwheel="return false;"></div>
  </div>
 </div>
 <div id="make_root_scrollable" style="height: 5000px"></div>
</body>
<script type="application/javascript">

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

  var scroller = document.getElementById("scroller");
  var apzaware = document.getElementById("apzaware");

  let expectedHitInfo = APZHitResultFlags.VISIBLE;
  if (!config.activateAllScrollFrames) {
    expectedHitInfo |= APZHitResultFlags.INACTIVE_SCROLLFRAME;
  }
  checkHitResult(hitTest(centerOf(scroller)),
                 expectedHitInfo,
                 (config.activateAllScrollFrames ? utils.getViewId(scroller)
                                                 : utils.getViewId(document.scrollingElement)),
                 utils.getLayersId(),
                 "inactive scrollframe");

  // The apz-aware div (which has a non-passive wheel listener) is not visible
  // and so the hit-test should just return the root scrollframe area that's
  // covering it
  checkHitResult(hitTest(centerOf(apzaware)),
                 APZHitResultFlags.VISIBLE,
                 utils.getViewId(document.scrollingElement),
                 utils.getLayersId(),
                 "inactive scrollframe - apzaware block");

  // Hit test where the scroll thumbs should be.
  hitTestScrollbar({
    element: scroller,
    directions: { vertical: true, horizontal: true },
    expectedScrollId: utils.getViewId(document.scrollingElement),
    expectedLayersId: utils.getLayersId(),
    trackLocation: ScrollbarTrackLocation.START,
    expectThumb: true,
    layerState: LayerState.INACTIVE,
  });

  // activate the scrollframe but keep the main-thread scroll position at 0.
  // also apply a async scroll offset in the y-direction such that the
  // scrollframe scrolls to the bottom of its range.
  utils.setDisplayPortForElement(0, 0, 500, 500, scroller, 1);
  await promiseApzFlushedRepaints();
  var scrollY = scroller.scrollTopMax;
  utils.setAsyncScrollOffset(scroller, 0, scrollY);
  // Tick the refresh driver once to make sure the compositor has applied the
  // async scroll offset (for WebRender hit-testing we need to make sure WR has
  // the latest info).
  utils.advanceTimeAndRefresh(16);
  utils.restoreNormalRefresh();

  var scrollerViewId = utils.getViewId(scroller);

  // Now we again test the middle of the scrollframe, which is now active
  checkHitResult(hitTest(centerOf(scroller)),
                 APZHitResultFlags.VISIBLE,
                 scrollerViewId,
                 utils.getLayersId(),
                 "active scrollframe");

  // Test the apz-aware block
  var apzawarePosition = centerOf(apzaware); // main thread position
  apzawarePosition.y -= scrollY; // APZ position
  checkHitResult(hitTest(apzawarePosition),
                 APZHitResultFlags.VISIBLE |
                 APZHitResultFlags.APZ_AWARE_LISTENERS,
                 scrollerViewId,
                 utils.getLayersId(),
                 "active scrollframe - apzaware block");

  // Test the scrollbars. Note that this time the vertical scrollthumb is
  // going to be at the bottom of the track. We'll test both the top and the
  // bottom.

  // top of scrollbar track
  hitTestScrollbar({
    element: scroller,
    directions: { vertical: true },
    expectedScrollId: scrollerViewId,
    expectedLayersId: utils.getLayersId(),
    trackLocation: ScrollbarTrackLocation.START,
    expectThumb: false,
    layerState: LayerState.ACTIVE,
  });
  // bottom of scrollbar track (scrollthumb)
  hitTestScrollbar({
    element: scroller,
    directions: { vertical: true },
    expectedScrollId: scrollerViewId,
    expectedLayersId: utils.getLayersId(),
    trackLocation: ScrollbarTrackLocation.END,
    expectThumb: true,
    layerState: LayerState.ACTIVE,
  });
  // left part of scrollbar track (has scrollthumb)
  hitTestScrollbar({
    element: scroller,
    directions: { horizontal: true },
    expectedScrollId: scrollerViewId,
    expectedLayersId: utils.getLayersId(),
    trackLocation: ScrollbarTrackLocation.START,
    expectThumb: true,
    layerState: LayerState.ACTIVE,
  });
  // right part of scrollbar track
  hitTestScrollbar({
    element: scroller,
    directions: { horizontal: true },
    expectedScrollId: scrollerViewId,
    expectedLayersId: utils.getLayersId(),
    trackLocation: ScrollbarTrackLocation.END,
    expectThumb: false,
    layerState: LayerState.ACTIVE,
  });
}

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

</script>
</html>