| OLD | NEW |
| 1 <div id="scrolltarget"> | 1 <div id="scrolltarget"> |
| 2 <script src="../../resources/js-test.js"></script> | 2 <script src="../../resources/js-test.js"></script> |
| 3 <script> | 3 <script> |
| 4 description("This test checks that we correctly update the scroll event handler
count as event handlers are added and removed"); | 4 description('This test checks that we correctly update the scroll event handler
count as event handlers are added and removed'); |
| 5 (function() { | 5 (function() { |
| 6 // Test addEventListener/removeEventListener on the document. | 6 // Test addEventListener/removeEventListener on the document. |
| 7 var listener = function() { } | 7 var listener = function() { } |
| 8 | 8 |
| 9 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); | 9 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 10 document.addEventListener('scroll', listener, true); | 10 document.addEventListener('scroll', listener, true); |
| 11 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); | 11 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 12 document.addEventListener('scroll', listener, false); | 12 document.addEventListener('scroll', listener, false); |
| 13 shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); | 13 shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); |
| 14 document.removeEventListener('scroll', listener, true); | 14 document.removeEventListener('scroll', listener, true); |
| 15 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); | 15 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 16 | 16 |
| 17 // Try removing the capturing listener again. | 17 // Try removing the capturing listener again. |
| 18 document.removeEventListener('scroll', listener, true); | 18 document.removeEventListener('scroll', listener, true); |
| 19 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); | 19 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 20 | 20 |
| 21 document.removeEventListener('scroll', listener, false); | 21 document.removeEventListener('scroll', listener, false); |
| 22 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); | 22 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 23 })(); | 23 })(); |
| 24 | 24 |
| 25 debug('Test setting onscroll on the document.'); |
| 25 (function() { | 26 (function() { |
| 26 // Test setting onscroll on the document. | |
| 27 | |
| 28 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); | 27 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 29 document.onscroll = function() { } | 28 document.onscroll = function() { } |
| 30 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); | 29 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 31 document.onscroll = function() { } | 30 document.onscroll = function() { } |
| 32 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); | 31 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 33 document.onscroll = null; | 32 document.onscroll = null; |
| 34 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); | 33 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 35 })(); | 34 })(); |
| 36 debug("Test that nested Documents' scroll handlers are properly tracked in their
parent Document."); | 35 |
| 36 debug('Test that nested Documents\' scroll handlers are properly tracked in thei
r parent Document.'); |
| 37 (function() { | 37 (function() { |
| 38 var iframe = document.createElement('iframe'); | 38 var iframe = document.createElement('iframe'); |
| 39 var scrolltarget = document.getElementById('scrolltarget'); | 39 var scrolltarget = document.getElementById('scrolltarget'); |
| 40 scrolltarget.onscroll = function() {}; | 40 scrolltarget.onscroll = function() {}; |
| 41 | 41 |
| 42 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); | 42 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 43 | 43 |
| 44 scrolltarget.appendChild(iframe); | 44 scrolltarget.appendChild(iframe); |
| 45 | 45 |
| 46 nestedDocument = iframe.contentWindow.document; | 46 nestedDocument = iframe.contentWindow.document; |
| 47 nestedDocument.open('text/html', 'replace'); | 47 nestedDocument.open('text/html', 'replace'); |
| 48 nestedDocument.write('<!DOCTYPE html>\n<script>\ndocument.onscroll=function(
){};\n</' + 'script>\n'); | 48 nestedDocument.write('<!DOCTYPE html>\n<script>\ndocument.onscroll=function(
){};\n</' + 'script>\n'); |
| 49 shouldBe('window.internals.scrollEventHandlerCount(nestedDocument)', '2'); | 49 shouldBe('window.internals.scrollEventHandlerCount(nestedDocument)', '2'); |
| 50 shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); | 50 shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); |
| 51 | 51 |
| 52 nestedDocument.write('<script>document.onscroll=undefined</' + 'script>\n'); | 52 nestedDocument.write('<script>document.onscroll=undefined</' + 'script>\n'); |
| 53 shouldBe('window.internals.scrollEventHandlerCount(nestedDocument)', '1'); | 53 shouldBe('window.internals.scrollEventHandlerCount(nestedDocument)', '1'); |
| 54 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); | 54 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 55 | 55 |
| 56 nestedDocument.close(); | 56 nestedDocument.close(); |
| 57 | 57 |
| 58 scrolltarget.removeChild(iframe); | 58 scrolltarget.removeChild(iframe); |
| 59 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); | 59 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 60 scrolltarget.onscroll = undefined; | 60 scrolltarget.onscroll = undefined; |
| 61 })(); | 61 })(); |
| 62 debug("Test that detaching a nested Document with handlers works properly."); | 62 |
| 63 debug('Test that detaching a nested Document with handlers works properly.'); |
| 63 (function() { | 64 (function() { |
| 64 var iframe = document.createElement('iframe'); | 65 var iframe = document.createElement('iframe'); |
| 65 var scrolltarget = document.getElementById('scrolltarget'); | 66 var scrolltarget = document.getElementById('scrolltarget'); |
| 66 | 67 |
| 67 scrolltarget.appendChild(iframe); | 68 scrolltarget.appendChild(iframe); |
| 68 | 69 |
| 69 nestedDocument = iframe.contentWindow.document; | 70 nestedDocument = iframe.contentWindow.document; |
| 70 nestedDocument.open('text/html', 'replace'); | 71 nestedDocument.open('text/html', 'replace'); |
| 71 nestedDocument.write('<!DOCTYPE html>\n<script>\ndocument.onscroll=function(
){};\n</' + 'script>\n'); | 72 nestedDocument.write('<!DOCTYPE html>\n<script>\ndocument.onscroll=function(
){};\n' + |
| 72 shouldBe('window.internals.scrollEventHandlerCount(nestedDocument)', '1'); | 73 'window.onscroll=function(){};</' + 'script>\n'); |
| 73 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); | 74 shouldBe('window.internals.scrollEventHandlerCount(nestedDocument)', '2'); |
| 75 shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); |
| 74 | 76 |
| 75 nestedDocument.close(); | 77 nestedDocument.close(); |
| 76 scrolltarget.removeChild(iframe); | 78 scrolltarget.removeChild(iframe); |
| 77 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); | 79 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 78 })(); | 80 })(); |
| 81 |
| 79 debug('Test moving event listeners from an unattached document to an attached on
e'); | 82 debug('Test moving event listeners from an unattached document to an attached on
e'); |
| 80 (function() { | 83 (function() { |
| 81 doc = document.implementation.createHTMLDocument(''); | 84 doc = document.implementation.createHTMLDocument(''); |
| 82 var div = doc.createElement('div'); | 85 var div = doc.createElement('div'); |
| 83 var childDiv = doc.createElement('div'); | 86 var childDiv = doc.createElement('div'); |
| 84 | 87 |
| 85 div.addEventListener('scroll', function() { }); | 88 div.addEventListener('scroll', function() { }); |
| 86 childDiv.addEventListener('scroll', function() { }); | 89 childDiv.addEventListener('scroll', function() { }); |
| 87 div.appendChild(childDiv); | 90 div.appendChild(childDiv); |
| 88 | 91 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 100 document.body.removeChild(div); | 103 document.body.removeChild(div); |
| 101 shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); | 104 shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); |
| 102 | 105 |
| 103 // Once the divs are destroyed the handlers go away. | 106 // Once the divs are destroyed the handlers go away. |
| 104 div = null; | 107 div = null; |
| 105 childDiv = null; | 108 childDiv = null; |
| 106 doc = null; | 109 doc = null; |
| 107 gc(); | 110 gc(); |
| 108 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); | 111 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 109 })(); | 112 })(); |
| 113 |
| 110 debug('Test moving event listeners from an attached document to an unattached on
e'); | 114 debug('Test moving event listeners from an attached document to an unattached on
e'); |
| 111 (function() { | 115 (function() { |
| 112 var div = document.createElement('div'); | 116 var div = document.createElement('div'); |
| 113 div.addEventListener('scroll', function() { }); | 117 div.addEventListener('scroll', function() { }); |
| 114 document.body.appendChild(div); | 118 document.body.appendChild(div); |
| 115 | 119 |
| 116 var iframe = document.createElement('iframe'); | 120 var iframe = document.createElement('iframe'); |
| 117 div.appendChild(iframe); | 121 div.appendChild(iframe); |
| 118 var nestedDocument = iframe.contentWindow.document; | 122 var nestedDocument = iframe.contentWindow.document; |
| 119 nestedDocument.open('text/html', 'replace'); | 123 nestedDocument.open('text/html', 'replace'); |
| 120 nestedDocument.write('<!DOCTYPE html>\n<script>\ndocument.onscroll=function(
){};\n</' + 'script>\n'); | 124 nestedDocument.write('<!DOCTYPE html>\n<script>\ndocument.onscroll=function(
){};\n' + |
| 125 'window.onscroll=function(){};</' + 'script>\n'); |
| 121 | 126 |
| 122 shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); | 127 shouldBe('window.internals.scrollEventHandlerCount(document)', '3'); |
| 123 | 128 |
| 124 var unattachedDoc = document.implementation.createHTMLDocument(''); | 129 var unattachedDoc = document.implementation.createHTMLDocument(''); |
| 125 unattachedDoc.body.appendChild(div); | 130 unattachedDoc.body.appendChild(div); |
| 126 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); | 131 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 127 })(); | 132 })(); |
| 133 |
| 128 debug('Test moving a scroll event listener between documents belonging to the sa
me page'); | 134 debug('Test moving a scroll event listener between documents belonging to the sa
me page'); |
| 129 (function() { | 135 (function() { |
| 130 var iframe = document.createElement('iframe'); | 136 var iframe = document.createElement('iframe'); |
| 131 document.body.appendChild(iframe); | 137 document.body.appendChild(iframe); |
| 132 var nestedDocument = iframe.contentWindow.document; | 138 var nestedDocument = iframe.contentWindow.document; |
| 133 nestedDocument.open('text/html', 'replace'); | 139 nestedDocument.open('text/html', 'replace'); |
| 134 nestedDocument.write('<!DOCTYPE html><div id=foo></div>'); | 140 nestedDocument.write('<!DOCTYPE html><div id=foo></div>'); |
| 135 | 141 |
| 136 var element = frames[0].document.getElementById('foo'); | 142 var element = frames[0].document.getElementById('foo'); |
| 137 var listener = function() { } | 143 var listener = function() { } |
| 138 element.addEventListener('scroll', listener, false); | 144 element.addEventListener('scroll', listener, false); |
| 145 frames[0].window.addEventListener('scroll', listener, false); |
| 146 shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); |
| 147 |
| 148 document.body.appendChild(element); |
| 149 shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); |
| 150 |
| 151 element.removeEventListener('scroll', listener, false); |
| 152 frames[0].window.removeEventListener('scroll', listener, false); |
| 153 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 154 })(); |
| 155 |
| 156 debug('Test addEventListener/removeEventListener on the window.'); |
| 157 (function() { |
| 158 var listener = function() { } |
| 159 |
| 160 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 161 window.addEventListener('scroll', listener, true); |
| 162 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 163 window.addEventListener('scroll', listener, false); |
| 164 shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); |
| 165 window.removeEventListener('scroll', listener, true); |
| 139 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); | 166 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 140 | 167 |
| 141 document.body.appendChild(element); | 168 // Try removing the capturing listener again. |
| 169 window.removeEventListener('scroll', listener, true); |
| 142 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); | 170 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 143 | 171 |
| 144 element.removeEventListener('scroll', listener, false); | 172 window.removeEventListener('scroll', listener, false); |
| 173 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 174 })(); |
| 175 |
| 176 debug('Test setting onscroll on the window.'); |
| 177 (function() { |
| 178 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 179 window.onscroll = function() { } |
| 180 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 181 window.onscroll = function() { } |
| 182 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 183 window.onscroll = null; |
| 145 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); | 184 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 146 })(); | 185 })(); |
| 147 </script> | 186 </script> |
| 148 </body> | 187 </body> |
| OLD | NEW |