Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / touch / touch-handler-count.html
blob7cf88e8f7ec042942d72359252892e7fcb3d6351
1 <script src="../../../resources/js-test.js"></script>
2 <div id='touchtarget' style='width: 50; height: 50'></div>
3 <script>
4 description("This test checks that we correctly update the touch event handler count as event handlers are added and removed");
6 debug("Test addEventListener/removeEventListener on the document.");
7 (function() {
8 var listener = function() { }
10 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
11 document.addEventListener('touchstart', listener, true);
12 shouldBe('window.internals.touchEventHandlerCount(document)', '1');
13 document.addEventListener('touchmove', listener, true);
14 shouldBe('window.internals.touchEventHandlerCount(document)', '2');
15 document.addEventListener('touchstart', listener, false);
16 shouldBe('window.internals.touchEventHandlerCount(document)', '3');
17 document.removeEventListener('touchmove', listener, true);
18 shouldBe('window.internals.touchEventHandlerCount(document)', '2');
19 document.removeEventListener('touchstart', listener, true);
20 shouldBe('window.internals.touchEventHandlerCount(document)', '1');
22 // Try removing the capturing listener again.
23 document.removeEventListener('touchstart', listener, true);
24 shouldBe('window.internals.touchEventHandlerCount(document)', '1');
25 document.removeEventListener('touchmove', listener, true);
26 shouldBe('window.internals.touchEventHandlerCount(document)', '1');
28 document.removeEventListener('touchstart', listener, false);
29 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
30 })();
32 debug("Test setting touch handlers on the document.");
33 (function() {
34 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
35 document.ontouchstart = function() { }
36 document.ontouchmove = function() {}
37 document.ontouchend = function() {}
38 document.ontouchcancel = function() {}
39 shouldBe('window.internals.touchEventHandlerCount(document)', '4');
40 document.ontouchstart = function() { }
41 shouldBe('window.internals.touchEventHandlerCount(document)', '4');
42 document.ontouchstart = null;
43 shouldBe('window.internals.touchEventHandlerCount(document)', '3');
44 document.ontouchstart = null;
45 shouldBe('window.internals.touchEventHandlerCount(document)', '3');
46 document.ontouchmove = null;
47 document.ontouchend = null;
48 document.ontouchcancel = null;
49 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
50 })();
52 debug("Test addEventListener/removeEventListener on the window.");
53 (function() {
54 var listener = function() { }
56 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
57 window.addEventListener('touchstart', listener, true);
58 shouldBe('window.internals.touchEventHandlerCount(document)', '1');
59 window.addEventListener('touchmove', listener, true);
60 shouldBe('window.internals.touchEventHandlerCount(document)', '2');
61 window.addEventListener('touchstart', listener, false);
62 shouldBe('window.internals.touchEventHandlerCount(document)', '3');
63 window.removeEventListener('touchmove', listener, true);
64 shouldBe('window.internals.touchEventHandlerCount(document)', '2');
65 window.removeEventListener('touchstart', listener, true);
66 shouldBe('window.internals.touchEventHandlerCount(document)', '1');
68 // Try removing the capturing listener again.
69 window.removeEventListener('touchstart', listener, true);
70 shouldBe('window.internals.touchEventHandlerCount(document)', '1');
71 window.removeEventListener('touchmove', listener, true);
72 shouldBe('window.internals.touchEventHandlerCount(document)', '1');
74 window.removeEventListener('touchstart', listener, false);
75 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
76 })();
78 debug("Test setting touch handlers on the window.");
79 (function() {
80 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
81 window.ontouchstart = function() { }
82 window.ontouchmove = function() {}
83 window.ontouchend = function() {}
84 window.ontouchcancel = function() {}
85 shouldBe('window.internals.touchEventHandlerCount(document)', '4');
86 window.ontouchstart = function() { }
87 shouldBe('window.internals.touchEventHandlerCount(document)', '4');
88 window.ontouchstart = null;
89 shouldBe('window.internals.touchEventHandlerCount(document)', '3');
90 window.ontouchstart = null;
91 shouldBe('window.internals.touchEventHandlerCount(document)', '3');
92 window.ontouchmove = null;
93 window.ontouchend = null;
94 window.ontouchcancel = null;
95 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
96 })();
98 debug("Test addEventListener/removeEventListener on a div.");
99 (function() {
100 var listener = function() { }
101 var div = document.getElementById('touchtarget');
103 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
104 div.addEventListener('touchstart', listener, true);
105 shouldBe('window.internals.touchEventHandlerCount(document)', '1');
106 div.addEventListener('touchmove', listener, true);
107 shouldBe('window.internals.touchEventHandlerCount(document)', '2');
108 div.addEventListener('touchstart', listener, false);
109 shouldBe('window.internals.touchEventHandlerCount(document)', '3');
110 div.removeEventListener('touchmove', listener, true);
111 shouldBe('window.internals.touchEventHandlerCount(document)', '2');
112 div.removeEventListener('touchstart', listener, true);
113 shouldBe('window.internals.touchEventHandlerCount(document)', '1');
115 // Try removing the capturing listener again.
116 div.removeEventListener('touchstart', listener, true);
117 shouldBe('window.internals.touchEventHandlerCount(document)', '1');
118 div.removeEventListener('touchmove', listener, true);
119 shouldBe('window.internals.touchEventHandlerCount(document)', '1');
121 div.removeEventListener('touchstart', listener, false);
122 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
123 })();
125 debug("Test setting touch handlers on a div.");
126 (function() {
127 var div = document.getElementById('touchtarget');
129 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
130 div.ontouchstart = function() { }
131 div.ontouchmove = function() { }
132 div.ontouchend = function() { }
133 div.ontouchcancel = function() { }
134 shouldBe('window.internals.touchEventHandlerCount(document)', '4');
135 div.ontouchstart = function() { }
136 shouldBe('window.internals.touchEventHandlerCount(document)', '4');
137 div.ontouchstart = null;
138 shouldBe('window.internals.touchEventHandlerCount(document)', '3');
139 div.ontouchstart = null;
140 shouldBe('window.internals.touchEventHandlerCount(document)', '3');
141 div.ontouchmove = null;
142 div.ontouchend = null;
143 div.ontouchcancel = null;
144 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
145 })();
147 debug("Test redudant addEventListener on a div.");
148 (function() {
149 var listener = function() { }
150 var div = document.getElementById('touchtarget');
152 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
153 div.addEventListener('touchstart', listener, false);
154 shouldBe('window.internals.touchEventHandlerCount(document)', '1');
155 div.addEventListener('touchstart', listener, false);
156 shouldBe('window.internals.touchEventHandlerCount(document)', '1');
158 div.removeEventListener('touchstart', listener, false);
159 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
160 })();
163 debug("Test addEventListener/removeEventListener on a new div.");
164 (function() {
165 var div = document.createElement('div');
166 var touchtarget = document.getElementById('touchtarget');
167 var listener = function() { }
169 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
171 div.addEventListener('touchstart', listener, true);
172 div.addEventListener('touchmove', listener, true);
173 shouldBe('window.internals.touchEventHandlerCount(document)', '2');
175 touchtarget.appendChild(div);
176 shouldBe('window.internals.touchEventHandlerCount(document)', '2');
178 div.addEventListener('touchend', listener, true);
179 shouldBe('window.internals.touchEventHandlerCount(document)', '3');
181 div.removeEventListener('touchstart', listener, true);
182 shouldBe('window.internals.touchEventHandlerCount(document)', '2');
184 touchtarget.removeChild(div);
185 shouldBe('window.internals.touchEventHandlerCount(document)', '2');
187 div.removeEventListener('touchmove', listener, false);
188 shouldBe('window.internals.touchEventHandlerCount(document)', '2');
190 div.removeEventListener('touchmove', listener, true);
191 div.removeEventListener('touchend', listener, true);
192 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
193 })();
195 debug("Test setting touch handlers on a new div.");
196 (function() {
197 var div = document.createElement('div');
198 var touchtarget = document.getElementById('touchtarget');
200 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
202 div.ontouchstart = function() { }
203 div.ontouchmove = function() { }
204 shouldBe('window.internals.touchEventHandlerCount(document)', '2');
206 touchtarget.appendChild(div);
207 shouldBe('window.internals.touchEventHandlerCount(document)', '2');
209 div.ontouchend = function() { }
210 shouldBe('window.internals.touchEventHandlerCount(document)', '3');
212 div.ontouchstart = null;
213 shouldBe('window.internals.touchEventHandlerCount(document)', '2');
215 touchtarget.removeChild(div);
216 shouldBe('window.internals.touchEventHandlerCount(document)', '2');
218 div.ontouchend = null;
219 div.ontouchmove = null;
220 shouldBe('window.internals.touchEventHandlerCount(document)', '0');
221 })();
223 var nestedDocument;
225 debug("Test that nested Documents' touch handlers are properly tracked in their parent Document.");
226 (function() {
227 var iframe = document.createElement('iframe');
228 var touchtarget = document.getElementById('touchtarget');
229 touchtarget.ontouchend = function() {};
231 shouldBe('window.internals.touchEventHandlerCount(document)', '1');
233 touchtarget.appendChild(iframe);
235 nestedDocument = iframe.contentWindow.document;
236 nestedDocument.open('text/html', 'replace');
237 nestedDocument.write('<!DOCTYPE html>\n<script>\nwindow.ontouchstart=function(){};\n</' + 'script>\n' +
238 '<div id=twoHandlers ontouchmove="function(){}" ontouchcancel="function(){}"></div>');
239 shouldBe('window.internals.touchEventHandlerCount(nestedDocument)', '4');
240 shouldBe('window.internals.touchEventHandlerCount(document)', '4');
242 nestedDocument.write('<script>window.ontouchstart=undefined</' + 'script>\n');
243 shouldBe('window.internals.touchEventHandlerCount(nestedDocument)', '3');
244 shouldBe('window.internals.touchEventHandlerCount(document)', '3');
246 nestedDocument.write('<script>document.addEventListener("touchmove", function(){});</' + 'script>\n');
247 shouldBe('window.internals.touchEventHandlerCount(nestedDocument)', '4');
248 shouldBe('window.internals.touchEventHandlerCount(document)', '4');
250 nestedDocument.write('<script>document.getElementById("twoHandlers").remove();</' + 'script>\n');
251 gc();
252 shouldBe('window.internals.touchEventHandlerCount(nestedDocument)', '2');
253 shouldBe('window.internals.touchEventHandlerCount(document)', '2');
254 nestedDocument.close();
256 touchtarget.removeChild(iframe);
257 shouldBe('window.internals.touchEventHandlerCount(document)', '1');
258 })();
259 </script>
260 </body>