summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_click_interrupt_animation.html
blob: 8884bb2e0d343f732e33f9bcbd677d8a161d4b4f (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Clicking on the content (not scrollbar) should interrupt animations</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 src="/tests/SimpleTest/EventUtils.js"></script>

  <script type="application/javascript">

async function test() {
  var scroller = document.documentElement;
  var verticalScrollbarWidth = window.innerWidth - scroller.clientWidth;

  if (verticalScrollbarWidth == 0) {
    ok(true, "Scrollbar width is zero on this platform, test is useless here");
    return;
  }

  // The anchor is the fixed-pos div that we use to calculate coordinates to
  // click on the scrollbar. That way we don't have to recompute coordinates
  // as the page scrolls. The anchor is at the bottom-right corner of the
  // content area.
  var anchor = document.getElementById('anchor');

  var xoffset = (verticalScrollbarWidth / 2);
  // Get a y-coord near the bottom of the vertical scrollbar track. Assume the
  // vertical thumb is near the top of the scrollback track (since scroll
  // position starts off at zero) and won't get in the way. Also assume the
  // down arrow button, if there is one, is square.
  var yoffset = 0 - verticalScrollbarWidth - 5;

  // Take control of the refresh driver
  let utils = SpecialPowers.getDOMWindowUtils(window);
  utils.advanceTimeAndRefresh(0);

  // Click at the bottom of the scrollbar track to trigger a page-down kind of
  // scroll. This should use "desktop zooming" scrollbar code which should
  // trigger an APZ scroll animation.
  await promiseNativeClick(anchor, xoffset, yoffset);

  // Run a few frames, that should be enough to let the scroll animation
  // start. We check to make sure the scroll position has changed.
  for (let i = 0; i < 5; i++) {
    utils.advanceTimeAndRefresh(16);
  }
  await promiseApzRepaintsFlushed();

  let curPos = scroller.scrollTop;
  ok(curPos > 0,
     `Scroll offset has moved down some, to ${curPos}`);

  // Now we click on the content, which should cancel the animation. Run
  // everything to reach a stable state.
  await promiseNativeClick(anchor, -5, -5);
  for (let i = 0; i < 1000; i++) {
    utils.advanceTimeAndRefresh(16);
  }
  await promiseApzRepaintsFlushed();

  // Ensure the scroll position hasn't changed since the last time we checked,
  // which indicates the animation got interrupted.
  is(scroller.scrollTop, curPos, `Scroll position hasn't changed again`);

  utils.restoreNormalRefresh();
}

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

  </script>
</head>
<body>
 <div style="position:fixed; bottom: 0; right: 0; width: 1px; height: 1px" id="anchor"></div>
 <div style="height: 300vh; margin-bottom: 10000px; background-image: linear-gradient(red,blue)"></div>
  The above div is sized to 3x screen height so the linear gradient is more steep in terms of
  color/pixel. We only scroll a few pages worth so we don't need the gradient all the way down.
  And then we use a bottom-margin to make the page really big so the scrollthumb is
  relatively small, giving us lots of space to click on the scrolltrack.
</body>
</html>