| OLD | NEW |
| (Empty) |
| 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 c
ount as event handlers are added and removed"); | |
| 5 | |
| 6 debug("Test addEventListener/removeEventListener on the document."); | |
| 7 (function() { | |
| 8 var listener = function() { } | |
| 9 | |
| 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'); | |
| 21 | |
| 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'); | |
| 27 | |
| 28 document.removeEventListener('touchstart', listener, false); | |
| 29 shouldBe('window.internals.touchEventHandlerCount(document)', '0'); | |
| 30 })(); | |
| 31 | |
| 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 })(); | |
| 51 | |
| 52 debug("Test addEventListener/removeEventListener on the window."); | |
| 53 (function() { | |
| 54 var listener = function() { } | |
| 55 | |
| 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'); | |
| 67 | |
| 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'); | |
| 73 | |
| 74 window.removeEventListener('touchstart', listener, false); | |
| 75 shouldBe('window.internals.touchEventHandlerCount(document)', '0'); | |
| 76 })(); | |
| 77 | |
| 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 })(); | |
| 97 | |
| 98 debug("Test addEventListener/removeEventListener on a div."); | |
| 99 (function() { | |
| 100 var listener = function() { } | |
| 101 var div = document.getElementById('touchtarget'); | |
| 102 | |
| 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'); | |
| 114 | |
| 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'); | |
| 120 | |
| 121 div.removeEventListener('touchstart', listener, false); | |
| 122 shouldBe('window.internals.touchEventHandlerCount(document)', '0'); | |
| 123 })(); | |
| 124 | |
| 125 debug("Test setting touch handlers on a div."); | |
| 126 (function() { | |
| 127 var div = document.getElementById('touchtarget'); | |
| 128 | |
| 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 })(); | |
| 146 | |
| 147 debug("Test redudant addEventListener on a div."); | |
| 148 (function() { | |
| 149 var listener = function() { } | |
| 150 var div = document.getElementById('touchtarget'); | |
| 151 | |
| 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'); | |
| 157 | |
| 158 div.removeEventListener('touchstart', listener, false); | |
| 159 shouldBe('window.internals.touchEventHandlerCount(document)', '0'); | |
| 160 })(); | |
| 161 | |
| 162 | |
| 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() { } | |
| 168 | |
| 169 shouldBe('window.internals.touchEventHandlerCount(document)', '0'); | |
| 170 | |
| 171 div.addEventListener('touchstart', listener, true); | |
| 172 div.addEventListener('touchmove', listener, true); | |
| 173 shouldBe('window.internals.touchEventHandlerCount(document)', '2'); | |
| 174 | |
| 175 touchtarget.appendChild(div); | |
| 176 shouldBe('window.internals.touchEventHandlerCount(document)', '2'); | |
| 177 | |
| 178 div.addEventListener('touchend', listener, true); | |
| 179 shouldBe('window.internals.touchEventHandlerCount(document)', '3'); | |
| 180 | |
| 181 div.removeEventListener('touchstart', listener, true); | |
| 182 shouldBe('window.internals.touchEventHandlerCount(document)', '2'); | |
| 183 | |
| 184 touchtarget.removeChild(div); | |
| 185 shouldBe('window.internals.touchEventHandlerCount(document)', '2'); | |
| 186 | |
| 187 div.removeEventListener('touchmove', listener, false); | |
| 188 shouldBe('window.internals.touchEventHandlerCount(document)', '2'); | |
| 189 | |
| 190 div.removeEventListener('touchmove', listener, true); | |
| 191 div.removeEventListener('touchend', listener, true); | |
| 192 shouldBe('window.internals.touchEventHandlerCount(document)', '0'); | |
| 193 })(); | |
| 194 | |
| 195 debug("Test setting touch handlers on a new div."); | |
| 196 (function() { | |
| 197 var div = document.createElement('div'); | |
| 198 var touchtarget = document.getElementById('touchtarget'); | |
| 199 | |
| 200 shouldBe('window.internals.touchEventHandlerCount(document)', '0'); | |
| 201 | |
| 202 div.ontouchstart = function() { } | |
| 203 div.ontouchmove = function() { } | |
| 204 shouldBe('window.internals.touchEventHandlerCount(document)', '2'); | |
| 205 | |
| 206 touchtarget.appendChild(div); | |
| 207 shouldBe('window.internals.touchEventHandlerCount(document)', '2'); | |
| 208 | |
| 209 div.ontouchend = function() { } | |
| 210 shouldBe('window.internals.touchEventHandlerCount(document)', '3'); | |
| 211 | |
| 212 div.ontouchstart = null; | |
| 213 shouldBe('window.internals.touchEventHandlerCount(document)', '2'); | |
| 214 | |
| 215 touchtarget.removeChild(div); | |
| 216 shouldBe('window.internals.touchEventHandlerCount(document)', '2'); | |
| 217 | |
| 218 div.ontouchend = null; | |
| 219 div.ontouchmove = null; | |
| 220 shouldBe('window.internals.touchEventHandlerCount(document)', '0'); | |
| 221 })(); | |
| 222 | |
| 223 var nestedDocument; | |
| 224 | |
| 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() {}; | |
| 230 | |
| 231 shouldBe('window.internals.touchEventHandlerCount(document)', '1'); | |
| 232 | |
| 233 touchtarget.appendChild(iframe); | |
| 234 | |
| 235 nestedDocument = iframe.contentWindow.document; | |
| 236 nestedDocument.open('text/html', 'replace'); | |
| 237 nestedDocument.write('<!DOCTYPE html>\n<script>\nwindow.ontouchstart=functio
n(){};\n</' + 'script>\n' + | |
| 238 '<div id=twoHandlers ontouchmove="function(){}" ontouchcancel="function(
){}"></div>'); | |
| 239 shouldBe('window.internals.touchEventHandlerCount(nestedDocument)', '3'); | |
| 240 shouldBe('window.internals.touchEventHandlerCount(document)', '2'); | |
| 241 | |
| 242 nestedDocument.write('<script>window.ontouchstart=undefined</' + 'script>\n'
); | |
| 243 shouldBe('window.internals.touchEventHandlerCount(nestedDocument)', '2'); | |
| 244 shouldBe('window.internals.touchEventHandlerCount(document)', '2'); | |
| 245 | |
| 246 nestedDocument.write('<script>document.addEventListener("touchmove", functio
n(){});</' + 'script>\n'); | |
| 247 shouldBe('window.internals.touchEventHandlerCount(nestedDocument)', '3'); | |
| 248 shouldBe('window.internals.touchEventHandlerCount(document)', '2'); | |
| 249 | |
| 250 nestedDocument.write('<script>document.getElementById("twoHandlers").remove(
);</' + 'script>\n'); | |
| 251 gc(); | |
| 252 shouldBe('window.internals.touchEventHandlerCount(nestedDocument)', '1'); | |
| 253 shouldBe('window.internals.touchEventHandlerCount(document)', '2'); | |
| 254 nestedDocument.close(); | |
| 255 | |
| 256 touchtarget.removeChild(iframe); | |
| 257 shouldBe('window.internals.touchEventHandlerCount(document)', '1'); | |
| 258 })(); | |
| 259 </script> | |
| 260 </body> | |
| OLD | NEW |