Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Unified Diff: LayoutTests/fast/events/scroll-event-handler-count.html

Issue 237963014: Track scroll event handlers in nested documents (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Oilpan build fix. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | LayoutTests/fast/events/scroll-event-handler-count-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
« no previous file with comments | « no previous file | LayoutTests/fast/events/scroll-event-handler-count-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698