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

Side by Side 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: One more test. Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | LayoutTests/fast/events/scroll-event-handler-count-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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);
(...skipping 15 matching lines...) Expand all
26 // Test setting onscroll on the document. 26 // Test setting onscroll on the document.
27 27
28 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); 28 shouldBe('window.internals.scrollEventHandlerCount(document)', '0');
29 document.onscroll = function() { } 29 document.onscroll = function() { }
30 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); 30 shouldBe('window.internals.scrollEventHandlerCount(document)', '1');
31 document.onscroll = function() { } 31 document.onscroll = function() { }
32 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); 32 shouldBe('window.internals.scrollEventHandlerCount(document)', '1');
33 document.onscroll = null; 33 document.onscroll = null;
34 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); 34 shouldBe('window.internals.scrollEventHandlerCount(document)', '0');
35 })(); 35 })();
36 debug("Test that nested Documents' scroll handlers are properly tracked in their parent Document.");
37 (function() {
38 var iframe = document.createElement('iframe');
39 var scrolltarget = document.getElementById('scrolltarget');
40 scrolltarget.onscroll = function() {};
41
42 shouldBe('window.internals.scrollEventHandlerCount(document)', '1');
43
44 scrolltarget.appendChild(iframe);
45
46 nestedDocument = iframe.contentWindow.document;
47 nestedDocument.open('text/html', 'replace');
48 nestedDocument.write('<!DOCTYPE html>\n<script>\ndocument.onscroll=function( ){};\n</' + 'script>\n');
49 shouldBe('window.internals.scrollEventHandlerCount(nestedDocument)', '2');
50 shouldBe('window.internals.scrollEventHandlerCount(document)', '2');
51
52 nestedDocument.write('<script>document.onscroll=undefined</' + 'script>\n');
53 shouldBe('window.internals.scrollEventHandlerCount(nestedDocument)', '1');
54 shouldBe('window.internals.scrollEventHandlerCount(document)', '1');
55
56 nestedDocument.close();
57
58 scrolltarget.removeChild(iframe);
59 shouldBe('window.internals.scrollEventHandlerCount(document)', '1');
60 scrolltarget.onscroll = undefined;
61 })();
62 debug("Test that detaching a nested Document with handlers works properly.");
63 (function() {
64 var iframe = document.createElement('iframe');
65 var scrolltarget = document.getElementById('scrolltarget');
66
67 scrolltarget.appendChild(iframe);
68
69 nestedDocument = iframe.contentWindow.document;
70 nestedDocument.open('text/html', 'replace');
71 nestedDocument.write('<!DOCTYPE html>\n<script>\ndocument.onscroll=function( ){};\n</' + 'script>\n');
72 shouldBe('window.internals.scrollEventHandlerCount(nestedDocument)', '1');
73 shouldBe('window.internals.scrollEventHandlerCount(document)', '1');
74
75 nestedDocument.close();
76 scrolltarget.removeChild(iframe);
77 shouldBe('window.internals.scrollEventHandlerCount(document)', '0');
78 })();
79 debug('Test moving event listeners from an unattached document to an attached on e');
80 (function() {
81 var doc = document.implementation.createHTMLDocument('');
82 var div = doc.createElement('div');
83 var childDiv = doc.createElement('div');
84
85 div.addEventListener('scroll', function() { });
86 childDiv.addEventListener('scroll', function() { });
87 div.appendChild(childDiv);
88
89 // Move the top level div into the current document. Both event handlers sho uld
90 // get registered.
91 document.body.appendChild(div);
92 shouldBe('window.internals.scrollEventHandlerCount(document)', '2');
93
94 // Removing the div from the document does not affect the event handler coun t.
95 document.body.removeChild(div);
96 shouldBe('window.internals.scrollEventHandlerCount(document)', '2');
97
Rick Byers 2014/04/29 15:41:12 I agree this is a little surprising. What if the
98 // Once the divs are destroyed the handlers go away.
99 div = null;
100 childDiv = null;
101 gc();
102 shouldBe('window.internals.scrollEventHandlerCount(document)', '0');
103 })();
104 debug('Test moving event listeners from an attached document to an unattached on e');
105 (function() {
106 var doc = document.implementation.createHTMLDocument('');
107 var div = document.createElement('div');
108
109 div.addEventListener('scroll', function() { });
110 shouldBe('window.internals.scrollEventHandlerCount(document)', '1');
111
112 doc.body.appendChild(div);
113 shouldBe('window.internals.scrollEventHandlerCount(document)', '0');
114 })();
115 debug('Test moving a scroll event listener between documents belonging to the sa me page');
116 (function() {
117 var iframe = document.createElement('iframe');
118 document.body.appendChild(iframe);
119 var nestedDocument = iframe.contentWindow.document;
120 nestedDocument.open('text/html', 'replace');
121 nestedDocument.write('<!DOCTYPE html><div id=foo></div>');
122
123 var element = frames[0].document.getElementById('foo');
124 var listener = function() { }
125 element.addEventListener('scroll', listener, false);
126 shouldBe('window.internals.scrollEventHandlerCount(document)', '1');
127
128 document.body.appendChild(element);
129 shouldBe('window.internals.scrollEventHandlerCount(document)', '1');
130
131 element.removeEventListener('scroll', listener, false);
132 shouldBe('window.internals.scrollEventHandlerCount(document)', '0');
133 })();
36 </script> 134 </script>
37 </body> 135 </body>
OLDNEW
« 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