summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_basic_pan.html
blob: db96e34a7047df8268f0ecaf7696eb2c1444edac (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width; initial-scale=1.0">
  <title>Sanity panning test</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() {
  let scrEvt = new EventCounter(window, "scroll");
  let visScrEvt = new EventCounter(window.visualViewport, "scroll");
  // Our internal visual viewport events aren't restricted to the visual view-
  // port itself, so we can listen on the window itself, however the event
  // listener needs to be in the system group.
  let visScrEvtInternal = new EventCounter(window, "mozvisualscroll",
                                           { mozSystemGroup: true });

  // This listener will trigger the test to continue once APZ is done with
  // processing the scroll.
  let transformEndPromise = promiseTransformEnd();

  await synthesizeNativeTouchDrag(document.body, 10, 100, 0, -50);
  dump("Finished native drag, waiting for transform-end observer...\n");

  // Wait for the APZ:TransformEnd to be fired after touch events are processed.
  await transformEndPromise;

  // Flush state.
  await promiseApzFlushedRepaints();

  is(window.scrollY, 50, "check that the window scrolled");

  // Check we've got the expected events.
  // This page is using "width=device-width; initial-scale=1.0" and we haven't
  // pinch-zoomed any further, so layout and visual viewports have the same
  // size and will scroll together. Therefore we should be getting layout
  // viewport "scroll" events as well.
  scrEvt.unregister();
  ok(scrEvt.count > 0, "Got some layout viewport scroll events");
  // This one is a bit tricky: Visual viewport "scroll" events are supposed to
  // fire only when the relative offset between layout and visual viewport
  // changes. Even when they're both scrolling together, we may update their
  // positions independently, though, leading to some jitter in the offset and
  // triggering the event after all.
  // At least for the case here, where both viewports are the same size and we
  // have a freshly loaded page, we should however be able to keep the offset at
  // a constant zero and therefore not cause any visual viewport scroll events
  // to fire.
  visScrEvt.unregister();
  is(visScrEvt.count, 0, "Got no visual viewport scroll events");
  visScrEvtInternal.unregister();
  // Our internal visual viewport scroll event on the other hand only cares
  // about the absolute offset of the visual viewport and should therefore
  // definitively fire.
  ok(visScrEvtInternal.count > 0, "Got some mozvisualscroll events");
}

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

  </script>
</head>
<body>
 <div style="height: 5000px; background-color: lightgreen;">
  This div makes the page scrollable.
 </div>
</body>
</html>