OLD | NEW |
---|---|
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 Loading... | |
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); | |
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
| |
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 | |
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 div = document.createElement('div'); | |
107 div.addEventListener('scroll', function() { }); | |
108 document.body.appendChild(div); | |
109 | |
110 var iframe = document.createElement('iframe'); | |
111 div.appendChild(iframe); | |
112 var nestedDocument = iframe.contentWindow.document; | |
113 nestedDocument.open('text/html', 'replace'); | |
114 nestedDocument.write('<!DOCTYPE html>\n<script>\ndocument.onscroll=function( ){};\n</' + 'script>\n'); | |
115 | |
116 shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); | |
117 | |
118 var unattachedDoc = document.implementation.createHTMLDocument(''); | |
119 unattachedDoc.body.appendChild(div); | |
120 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); | |
121 })(); | |
122 debug('Test moving a scroll event listener between documents belonging to the sa me page'); | |
123 (function() { | |
124 var iframe = document.createElement('iframe'); | |
125 document.body.appendChild(iframe); | |
126 var nestedDocument = iframe.contentWindow.document; | |
127 nestedDocument.open('text/html', 'replace'); | |
128 nestedDocument.write('<!DOCTYPE html><div id=foo></div>'); | |
129 | |
130 var element = frames[0].document.getElementById('foo'); | |
131 var listener = function() { } | |
132 element.addEventListener('scroll', listener, false); | |
133 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); | |
134 | |
135 document.body.appendChild(element); | |
136 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); | |
137 | |
138 element.removeEventListener('scroll', listener, false); | |
139 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); | |
140 })(); | |
36 </script> | 141 </script> |
37 </body> | 142 </body> |
OLD | NEW |