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

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: Oilpan build fix. 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 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 // Since we only track event handlers on documents that attached to a page,
90 // |doc| should not have any registered handlers at this point.
91 shouldBe('window.internals.scrollEventHandlerCount(doc)', '0');
92 shouldBe('window.internals.scrollEventHandlerCount(document)', '0');
93
94 // Move the top level div into the current document. Both event handlers sho uld
95 // get registered.
96 document.body.appendChild(div);
97 shouldBe('window.internals.scrollEventHandlerCount(document)', '2');
98
99 // Removing the div from the document does not affect the event handler coun t.
100 document.body.removeChild(div);
101 shouldBe('window.internals.scrollEventHandlerCount(document)', '2');
102
103 // Once the divs are destroyed the handlers go away.
104 div = null;
105 childDiv = null;
106 doc = null;
107 gc();
108 shouldBe('window.internals.scrollEventHandlerCount(document)', '0');
109 })();
110 debug('Test moving event listeners from an attached document to an unattached on e');
111 (function() {
112 var div = document.createElement('div');
113 div.addEventListener('scroll', function() { });
114 document.body.appendChild(div);
115
116 var iframe = document.createElement('iframe');
117 div.appendChild(iframe);
118 var nestedDocument = iframe.contentWindow.document;
119 nestedDocument.open('text/html', 'replace');
120 nestedDocument.write('<!DOCTYPE html>\n<script>\ndocument.onscroll=function( ){};\n</' + 'script>\n');
121
122 shouldBe('window.internals.scrollEventHandlerCount(document)', '2');
123
124 var unattachedDoc = document.implementation.createHTMLDocument('');
125 unattachedDoc.body.appendChild(div);
126 shouldBe('window.internals.scrollEventHandlerCount(document)', '0');
127 })();
128 debug('Test moving a scroll event listener between documents belonging to the sa me page');
129 (function() {
130 var iframe = document.createElement('iframe');
131 document.body.appendChild(iframe);
132 var nestedDocument = iframe.contentWindow.document;
133 nestedDocument.open('text/html', 'replace');
134 nestedDocument.write('<!DOCTYPE html><div id=foo></div>');
135
136 var element = frames[0].document.getElementById('foo');
137 var listener = function() { }
138 element.addEventListener('scroll', listener, false);
139 shouldBe('window.internals.scrollEventHandlerCount(document)', '1');
140
141 document.body.appendChild(element);
142 shouldBe('window.internals.scrollEventHandlerCount(document)', '1');
143
144 element.removeEventListener('scroll', listener, false);
145 shouldBe('window.internals.scrollEventHandlerCount(document)', '0');
146 })();
36 </script> 147 </script>
37 </body> 148 </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