summaryrefslogtreecommitdiffstats
path: root/dom/events/test/pointerevents/test_bug1420589_2.html
blob: 2bfac2cdfce2376fd86473f51ed2b8d85a5d16f7 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1420589
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1420589</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1420589">Mozilla Bug 1420589</a>
<p id="display"></p>
<div id="div1" style="width: 50px; height: 50px; background: green"></div>
<iframe id="iframe1" src="./bug_1420589_iframe1.html">
</iframe>
<script type="text/javascript">
/*
  Test for Bug 1420589. This test synthesizes touch events with two points. One
  hits the div element on the document and the other hits the iframe element.

  We dispatch all touch events to the same document. If we find any target that
  is not in the same document of the existed target, we try to find the ancestor
  document of the new target which is in the same as the existing target and
  dispatch touch events to it. We check the points of the touch event in reverse
  order. That means we only dispatch touch events to the document which contains
  the div element in this test and expect the div element and iframe element
  receive touch events.

  We dispatch pointer events to the hit targets even when there aren't in the
  same document. This test expects that pointer events are dispatched to the div
  element and the iframe document.
*/
SimpleTest.waitForExplicitFinish();

var rx = 1;
var ry = 1;
var angle = 0;
var force = 1;
var modifiers = 0;
var test1PointerId = 1;
var test2PointerId = 2;

function withoutImplicitlyPointerCaptureForTouch() {
  let expectedEvents = [
    // messages from the document of iframe1
    "iframe1 pointerdown",
    "iframe1 pointermove",
    "iframe1 pointerup",

    // messages from the parent document
    "iframe touchstart",
    "iframe touchmove",
    "iframe touchend",
    "div1 pointerdown",
    "div1 pointermove",
    "div1 pointerup",
    "div1 touchstart",
    "div1 touchmove",
    "div1 touchend",
  ];

  window.addEventListener('message',function(e) {
    ok(expectedEvents.includes(e.data), " don't expect " + e.data);
    expectedEvents = expectedEvents.filter(item => item !== e.data);
    if (e.data == "div1 touchend") {
      ok(!expectedEvents.length, " expect " + expectedEvents);
      SimpleTest.finish();
    }
  })

  let iframe1 = document.getElementById('iframe1');
  let div1 = document.getElementById('div1');

  let events = ["touchstart", "touchmove", "touchend", "pointerdown", "pointermove", "pointerup"];
  events.forEach((event) => {
    div1.addEventListener(event, (e) => {
      postMessage("div1 " + e.type, "*");
    }, { once: true });
    iframe1.addEventListener(event, (e) => {
      postMessage("iframe " + e.type, "*");
    }, { once: true });
  });

  let rect1 = iframe1.getBoundingClientRect();
  let rect2 = div1.getBoundingClientRect();

  let left1 = rect1.left + 5;
  let left2 = rect2.left + 5;

  let top1 = rect1.top + 5;
  let top2 = rect2.top + 5;

  var utils = SpecialPowers.getDOMWindowUtils(window);
  utils.sendTouchEvent('touchstart', [test1PointerId, test2PointerId],
                       [left1, left2], [top1, top2], [rx, rx], [ry, ry],
                       [angle, angle], [force, force], [0, 0], [0, 0],
                       [0, 0], modifiers);

  // Move the touch pointers so that we dispatch all of them to content.
  left1++;
  left2++;
  utils.sendTouchEvent('touchmove', [test1PointerId, test2PointerId],
                       [left1, left2], [top1, top2], [rx, rx], [ry, ry],
                       [angle, angle], [force, force], [0, 0], [0, 0],
                       [0, 0], modifiers);
  utils.sendTouchEvent('touchend', [test1PointerId, test2PointerId],
                       [left1, left2], [top1, top2], [rx, rx], [ry, ry],
                       [angle, angle], [force, force], [0, 0], [0, 0],
                       [0, 0], modifiers);
}

SimpleTest.waitForFocus(() => {
  SpecialPowers.pushPrefEnv({"set": [["dom.w3c_pointer_events.implicit_capture", false]]},
                            withoutImplicitlyPointerCaptureForTouch);
});

</script>
</body>
</html>