summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_scrollbartrack_click_overshoot.html
blob: 7ee9f3f052c9fc15cf815d5a5a6bea89e213df32 (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width; initial-scale=1.0">
  <title>Scrolling with mouse down on the scrollbar</title>
  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
  <script type="application/javascript" src="apz_test_utils.js"></script>
  <script src="/tests/SimpleTest/paint_listener.js"></script>
  <style>
    .content {
      width: 1000px;
      height: 20000px;
    }
  </style>
  <script type="text/javascript">

async function test() {
  var targetElement = elementForTarget(window);
  var w = {},
    h = {};
  utilsForTarget(window).getScrollbarSizes(targetElement, w, h);
  var verticalScrollbarWidth = w.value;
  var mouseX = targetElement.clientWidth + verticalScrollbarWidth / 2;
  var mouseY = targetElement.clientHeight - 100; // 100 pixels above the bottom of the scrollbar track

  let scrollEndPromise = promiseScrollend();

  // Click and hold the mouse. Thumb should start scrolling towards the click location.
  await promiseNativeMouseEventWithAPZ({
    target: window,
    offsetX: mouseX,
    offsetY: mouseY,
    type: "mousemove",
  });
  // mouse down
  await promiseNativeMouseEventWithAPZ({
    target: window,
    offsetX: mouseX,
    offsetY: mouseY,
    type: "mousedown",
  });

  // Wait for scrolling to complete
  await scrollEndPromise;

  // Work around bug 1825879: we may get an extra scrollend
  // event too early.
  if (window.scrollY < (window.scrollMaxY / 2)) {
    scrollEndPromise = promiseScrollend();
    await scrollEndPromise;
  }

  // Flush everything just to be safe
  await promiseOnlyApzControllerFlushed();

  var result = hitTest({x: mouseX, y: mouseY});

  // Check that the scroll thumb is under the cursor.
  // If the bug occurs, the thumb will scroll too far and
  // will not be under the cursor.
  ok((result.hitInfo & APZHitResultFlags.SCROLLBAR_THUMB) != 0, "Scrollbar thumb hit");

  await promiseNativeMouseEventWithAPZ({
    target: window,
    offsetX: mouseX,
    offsetY: mouseY,
    type: "mouseup",
  });
}

if (getPlatform() == "mac") {
  ok(true, "Skipping test on Mac (bug 1851423)");
  subtestDone();
} else {
  // Note: on Linux, if the gtk-primary-button-warps-slider setting
  // is enabled, this test will not exercise the codepath it intends
  // to test (the thumb will jump immediately under the cursor, causing
  // the test to pass trivially). However, the test should still not fail.
  waitUntilApzStable()
  .then(test)
  .then(subtestDone, subtestFailed);
}

  </script>
</head>
<body>
  <div class="content">Some content to ensure the root scrollframe is scrollable</div>
</body>
</html>