| 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..9ca680ec6b49ae31b7264afc79f7e20c0620eb3a 100644
|
| --- a/LayoutTests/fast/events/scroll-event-handler-count.html
|
| +++ b/LayoutTests/fast/events/scroll-event-handler-count.html
|
| @@ -33,5 +33,116 @@ 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() {
|
| + 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);
|
| +
|
| + // Since we only track event handlers on documents that attached to a page,
|
| + // |doc| should not have any registered handlers at this point.
|
| + shouldBe('window.internals.scrollEventHandlerCount(doc)', '0');
|
| + shouldBe('window.internals.scrollEventHandlerCount(document)', '0');
|
| +
|
| + // 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;
|
| + doc = 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>
|
|
|