summaryrefslogtreecommitdiffstats
path: root/gfx/layers/apz/test/mochitest/helper_bug1162771.html
blob: 3503341d41ef14f64b00a6fa7b9e29c85bb43e72 (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
102
103
104
105
106
107
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width; initial-scale=1.0">
  <title>Test for touchend on media elements</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="application/javascript">

async function handleTouchStart() {
  let v = document.getElementById("video");
  let d = document.getElementById("div");

  let e = await new Promise(resolve => {
    document.body.addEventListener("touchstart", resolve, {once: true});
  });

  if (e.target === v || e.target === d) {
    e.target.style.display = "none";
    ok(true, "Set display to none on #" + e.target.id);
  } else {
    ok(false, "Got unexpected touchstart on " + e.target);
  }
  await promiseAllPaintsDone();
}

async function handleTouchEnd() {
  let v = document.getElementById("video");
  let d = document.getElementById("div");

  let e = await new Promise(resolve => {
    document.body.addEventListener("touchend", resolve, {once: true});
  });

  if (e.target === v || e.target === d) {
    e.target._gotTouchend = true;
    ok(true, "Got touchend event on #" + e.target.id);
  }
}

async function test() {
  var v = document.getElementById("video");
  var d = document.getElementById("div");

  var utils = SpecialPowers.getDOMWindowUtils(window);

  let startHandledPromise = handleTouchStart();
  let endHandledPromise = handleTouchEnd();
  var pt = await coordinatesRelativeToScreen({ offsetX: 25, offsetY: 5, target: v });
  utils.sendNativeTouchPoint(0, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT, pt.x, pt.y, 1, 90, null);
  await startHandledPromise;
  utils.sendNativeTouchPoint(0, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE, pt.x, pt.y, 1, 90, null);
  await endHandledPromise;
  ok(v._gotTouchend, "Touchend was received on video element");

  startHandledPromise = handleTouchStart();
  endHandledPromise = handleTouchEnd();
  pt = await coordinatesRelativeToScreen({ offsetX: 25, offsetY: 5, target: d });
  utils.sendNativeTouchPoint(0, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT, pt.x, pt.y, 1, 90, null);
  await startHandledPromise;
  utils.sendNativeTouchPoint(0, SpecialPowers.DOMWindowUtils.TOUCH_REMOVE, pt.x, pt.y, 1, 90, null);
  await endHandledPromise;
  ok(d._gotTouchend, "Touchend was received on div element");
}

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

  </script>
  <style>
    * {
      font-size: 24px;
      box-sizing: border-box;
    }

    #video {
      display:block;
      position:absolute;
      top: 100px;
      left:0;
      width: 50%;
      height: 100px;
      border:solid black 1px;
      background-color: #8a8;
    }

    #div {
      display:block;
      position:absolute;
      top: 100px;
      left: 50%;
      width: 50%;
      height: 100px;
      border:solid black 1px;
      background-color: #88a;
    }
  </style>
</head>
<body>
 <p>Tap on the colored boxes to hide them.</p>
 <video id="video"></video>
 <div id="div"></div>
</body>
</html>