Chromium Code Reviews| Index: LayoutTests/fast/events/scroll-event-handler-count.html |
| diff --git a/LayoutTests/fast/events/scroll-event-handler-count.html b/LayoutTests/fast/events/scroll-event-handler-count.html |
| index 7c757ab313869cccb09b79f1656ad16e01499805..c710da9bc2d92c400ae1f3331be1793cfadcca22 100644 |
| --- a/LayoutTests/fast/events/scroll-event-handler-count.html |
| +++ b/LayoutTests/fast/events/scroll-event-handler-count.html |
| @@ -33,5 +33,110 @@ description("This test checks that we correctly update the scroll event handler |
| document.onscroll = null; |
| shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| })(); |
| +debug("Test that nested Documents' scroll handlers are properly tracked in their parent Document."); |
| +(function() { |
| + var iframe = document.createElement('iframe'); |
| + var scrolltarget = document.getElementById('scrolltarget'); |
| + scrolltarget.onscroll = function() {}; |
| + |
| + shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| + |
| + scrolltarget.appendChild(iframe); |
| + |
| + nestedDocument = iframe.contentWindow.document; |
| + nestedDocument.open('text/html', 'replace'); |
| + nestedDocument.write('<!DOCTYPE html>\n<script>\ndocument.onscroll=function(){};\n</' + 'script>\n'); |
| + shouldBe('window.internals.scrollEventHandlerCount(nestedDocument)', '2'); |
| + shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); |
| + |
| + nestedDocument.write('<script>document.onscroll=undefined</' + 'script>\n'); |
| + shouldBe('window.internals.scrollEventHandlerCount(nestedDocument)', '1'); |
| + shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| + |
| + nestedDocument.close(); |
| + |
| + scrolltarget.removeChild(iframe); |
| + shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| + scrolltarget.onscroll = undefined; |
| +})(); |
| +debug("Test that detaching a nested Document with handlers works properly."); |
| +(function() { |
| + var iframe = document.createElement('iframe'); |
| + var scrolltarget = document.getElementById('scrolltarget'); |
| + |
| + scrolltarget.appendChild(iframe); |
| + |
| + nestedDocument = iframe.contentWindow.document; |
| + nestedDocument.open('text/html', 'replace'); |
| + nestedDocument.write('<!DOCTYPE html>\n<script>\ndocument.onscroll=function(){};\n</' + 'script>\n'); |
| + shouldBe('window.internals.scrollEventHandlerCount(nestedDocument)', '1'); |
| + shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| + |
| + nestedDocument.close(); |
| + scrolltarget.removeChild(iframe); |
| + shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| +})(); |
| +debug('Test moving event listeners from an unattached document to an attached one'); |
| +(function() { |
| + var doc = document.implementation.createHTMLDocument(''); |
| + var div = doc.createElement('div'); |
| + var childDiv = doc.createElement('div'); |
| + |
| + div.addEventListener('scroll', function() { }); |
| + childDiv.addEventListener('scroll', function() { }); |
| + div.appendChild(childDiv); |
|
Rick Byers
2014/04/30 17:28:50
perhaps it's worth verifying here that the event h
Sami
2014/05/01 13:29:34
Yes, good ideas all around. |doc| will have zero h
|
| + |
| + // Move the top level div into the current document. Both event handlers should |
| + // get registered. |
| + document.body.appendChild(div); |
| + shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); |
| + |
| + // Removing the div from the document does not affect the event handler count. |
| + document.body.removeChild(div); |
| + shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); |
| + |
| + // Once the divs are destroyed the handlers go away. |
| + div = null; |
| + childDiv = null; |
| + gc(); |
| + shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| +})(); |
| +debug('Test moving event listeners from an attached document to an unattached one'); |
| +(function() { |
| + var div = document.createElement('div'); |
| + div.addEventListener('scroll', function() { }); |
| + document.body.appendChild(div); |
| + |
| + var iframe = document.createElement('iframe'); |
| + div.appendChild(iframe); |
| + var nestedDocument = iframe.contentWindow.document; |
| + nestedDocument.open('text/html', 'replace'); |
| + nestedDocument.write('<!DOCTYPE html>\n<script>\ndocument.onscroll=function(){};\n</' + 'script>\n'); |
| + |
| + shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); |
| + |
| + var unattachedDoc = document.implementation.createHTMLDocument(''); |
| + unattachedDoc.body.appendChild(div); |
| + shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| +})(); |
| +debug('Test moving a scroll event listener between documents belonging to the same page'); |
| +(function() { |
| + var iframe = document.createElement('iframe'); |
| + document.body.appendChild(iframe); |
| + var nestedDocument = iframe.contentWindow.document; |
| + nestedDocument.open('text/html', 'replace'); |
| + nestedDocument.write('<!DOCTYPE html><div id=foo></div>'); |
| + |
| + var element = frames[0].document.getElementById('foo'); |
| + var listener = function() { } |
| + element.addEventListener('scroll', listener, false); |
| + shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| + |
| + document.body.appendChild(element); |
| + shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| + |
| + element.removeEventListener('scroll', listener, false); |
| + shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| +})(); |
| </script> |
| </body> |