summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_scrollbarbutton_repeat.html
blob: 723b250bd897e124284aca6eda44a4b429f6e768 (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width; initial-scale=1.0">
  <title>Basic test that click and hold on a scrollbar button works as expected</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>
  <script type="text/javascript">


async function test() {
  let utils = SpecialPowers.getDOMWindowUtils(window);
  let scroller = document.getElementById('scroller');
  let w = {}, h = {};
  utils.getScrollbarSizes(scroller, w, h);
  let verticalScrollbarWidth = w.value;
  if (verticalScrollbarWidth == 0) {
    ok(false, "No scrollbar, test will fail");
  }
  let downArrowHeight = verticalScrollbarWidth; // assume square scrollbar buttons
  var mouseX = scroller.clientWidth + verticalScrollbarWidth / 2;
  let mouseY = scroller.clientHeight - (downArrowHeight / 2);

  let waitForScroll = waitForScrollEvent(scroller);

  info("Synthesizing click at (" + mouseX + ", " + mouseY);
  await promiseNativeMouseEventWithAPZ({
    type: "click",
    target: scroller,
    offsetX: mouseX,
    offsetY: mouseY,
  });

  await waitForScroll;

  // Sanity-check: we should have scrolled.
  ok(scroller.scrollTop > 0, "Should have scrolled by clicking the scrollbar button");

  let startPos = scroller.scrollTop;

  info("scroller.scrollTop " + scroller.scrollTop);

  // mouse move over the scrollbar button
  await promiseNativeMouseEventWithAPZ({
    type: "mousemove",
    target: scroller,
    offsetX: mouseX,
    offsetY: mouseY,
  });
  // mouse down
  await promiseNativeMouseEventWithAPZ({
    type: "mousedown",
    target: scroller,
    offsetX: mouseX,
    offsetY: mouseY,
  });

  info("sent mouse down");

  info("scroller.scrollTop " + scroller.scrollTop);

  // mouse down on the scrollbar button and then wait until
  // we scroll more 2x the distance of one click.
  while ((scroller.scrollTop - startPos) < 2*startPos) {
    let waitForScroll2 = waitForScrollEvent(scroller);
    // Wait a bit
    await SpecialPowers.promiseTimeout(50);
    await waitForScroll2;
    info("loop scroller.scrollTop " + scroller.scrollTop);
  }

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

  ok(true, "got enough scroll");
}

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

  </script>
  <style>
    .spacer {
      background-color: #212121;
      height: 9000vh;
    }
  </style>
</head>
<body>
  <div id="scroller" style="overflow: auto; width: 200px; height: 200px;">
    <div class="spacer"></div>
  </div>
</body>
</html>