summaryrefslogtreecommitdiffstats
path: root/layout/base/tests/test_bug993936.html
blob: 9d62831ea5836798658e872052657244f098fba3 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=993936
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 993936</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <script type="application/javascript">

  /** Test for Bug 993936 **/

var currentId = 0;
var evictedTouchesCount = 0;

function testtouch(aOptions) {
  if (!aOptions)
    aOptions = {};
  this.identifier = aOptions.identifier || 0;
  this.target = aOptions.target || 0;
  this.page = aOptions.page || {x: 0, y: 0};
  this.radius = aOptions.radius || {x: 0, y: 0};
  this.rotationAngle = aOptions.rotationAngle || 0;
  this.force = aOptions.force || 1;
}

function touchEvent(aOptions) {
  if (!aOptions) {
    aOptions = {};
  }
  this.ctrlKey = aOptions.ctrlKey || false;
  this.altKey = aOptions.altKey || false;
  this.shiftKey = aOptions.shiftKey || false;
  this.metaKey = aOptions.metaKey || false;
  this.touches = aOptions.touches || [];
  this.targetTouches = aOptions.targetTouches || [];
  this.changedTouches = aOptions.changedTouches || [];
}

function sendTouchEvent(windowUtils, aType, aEvent, aModifiers) {
  var ids = [], xs=[], ys=[], rxs = [], rys = [],
      rotations = [], forces = [];

  for (var touchType of ["touches", "changedTouches", "targetTouches"]) {
    for (var i = 0; i < aEvent[touchType].length; i++) {
      if (ids.indexOf(aEvent[touchType][i].identifier) == -1) {
        ids.push(aEvent[touchType][i].identifier);
        xs.push(aEvent[touchType][i].page.x);
        ys.push(aEvent[touchType][i].page.y);
        rxs.push(aEvent[touchType][i].radius.x);
        rys.push(aEvent[touchType][i].radius.y);
        rotations.push(aEvent[touchType][i].rotationAngle);
        forces.push(aEvent[touchType][i].force);
      }
    }
  }
  return windowUtils.sendTouchEvent(aType,
                                    ids, xs, ys, rxs, rys,
                                    rotations, forces,
                                    ids.length, aModifiers, 0);
}

function getSingleTouchEventForTarget(target, cwu) {
  currentId++;
  var bcr = target.getBoundingClientRect();
  var touch = new testtouch({
    page: {x: Math.round(bcr.left + bcr.width/2),
           y: Math.round(bcr.top  + bcr.height/2)},
    target: target,
    identifier: currentId,
  });
  var event = new touchEvent({
    touches: [touch],
    targetTouches: [touch],
    changedTouches: [touch]
  });
  return event;
}

function getMultiTouchEventForTarget(target, cwu) {
  currentId++;
  var bcr = target.getBoundingClientRect();
  var touch1 = new testtouch({
    page: {x: Math.round(bcr.left + bcr.width/2),
           y: Math.round(bcr.top  + bcr.height/2)},
    target: target,
    identifier: currentId,
  });
  currentId++;
  var touch2 = new testtouch({
    page: {x: Math.round(bcr.left + bcr.width),
           y: Math.round(bcr.top  + bcr.height)},
    target: target,
    identifier: currentId,
  });
  var event = new touchEvent({
    touches: [touch1, touch2],
    targetTouches: [touch1, touch2],
    changedTouches: [touch1, touch2]
  });
  return event;
}

function runTests() {
  var cwu = SpecialPowers.getDOMWindowUtils(window);

  var event1 = getMultiTouchEventForTarget(d0, cwu);
  sendTouchEvent(cwu, "touchstart", event1, 0);
  sendTouchEvent(cwu, "touchmove", event1, 0);
  is(evictedTouchesCount, 0, "Still no evicted touches");

  var event2 = getSingleTouchEventForTarget(d0, cwu);
  sendTouchEvent(cwu, "touchstart", event2, 0);

  // By now we should get touchend event
  ok(evictedTouchesCount > 0, "Got evicted touch");

  finishTest();
}

function finishTest() {
  // Let window.onerror have a chance to fire
  setTimeout(function() {
    SimpleTest.finish();
  }, 0);
}

SimpleTest.waitForExplicitFinish();

  </script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=993936">Mozilla Bug 993936</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
</pre>
<div id="d0">
    Test div
</div>

<script>
var d0 = document.getElementById("d0");

d0.addEventListener("touchend", function(ev) {
  evictedTouchesCount++;
});

window.onload = function () {
  setTimeout(function() {
    runTests();
  }, 0);
}

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