summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_bug1682170_pointercancel_on_touchaction_pinchzoom.html
blob: b9c31dfe89f70818ae5ce0efa3c0badf4dc068d8 (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width; initial-scale=1.0">
  <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 body = document.body;

  // Event listeners just for logging/debugging purposes
  body.addEventListener("pointerdown", function(e) {
    dump(`Got pointerdown, pointer id ${e.pointerId}\n`);
  });
  body.addEventListener("touchstart", function(e) {
    dump(`Got touchstart with ${e.touches.length} touches\n`);
  }, {passive: true});


  // Event listeners relevant to the test. We want to make sure that a
  // pointercancel event is dispatched to web content, so we listen for that.
  // Also we want to ensure the main thread TouchActionHelper code is run and
  // used, so we add a non-passive touchmove listener that ensures the body has
  // a d-t-c region.
  var gotPointerCancel = false;
  body.addEventListener("pointercancel", function(e) {
    dump(`Got pointercancel, pointer id ${e.pointerId}\n`);
    gotPointerCancel = true;
  });
  body.addEventListener("touchmove", function(e) {
    dump(`Got touchmove with ${e.touches.length} touches\n`);
  }, {passive: false});

  let touchEndPromise = new Promise(resolve => {
    // This listener is just to catch the end of the touch sequence so we can
    // end the test at the right time.
    body.addEventListener("touchend", function(e) {
      dump(`Got touchend with ${e.touches.length} touches\n`);
      if (!e.touches.length) {
        resolve();
      }
    });
  });

  // We can't await this call, because this pinch action doesn't generate a
  // APZ:TransformEnd. Instead we await the touchend.
  pinchZoomOutWithTouchAtCenter();
  await touchEndPromise;

  ok(gotPointerCancel, "Checking that we definitely cancelled the pointerevents");
}

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

  </script>
  <style>
    body {
        height: 5000px;
        touch-action: pinch-zoom;
    }
  </style>
</head>
<body>
  A two-finger pinch action here should trigger browser zoom and trigger a pointercancel to content.
  Note that the code does a zoom-out and the page is already at min zoom, so
  the zoom doesn't produce any visual effect. But the DOM events should be the
  same either way.
</body>
</html>