OLD | NEW |
(Empty) | |
| 1 <script src="../../resources/js-test.js"></script> |
| 2 <script> |
| 3 description("This test checks that we correctly update the scroll event handler
count as event handlers are added and removed"); |
| 4 |
| 5 (function() { |
| 6 // Test addEventListener/removeEventListener on the document. |
| 7 var listener = function() { } |
| 8 |
| 9 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 10 document.addEventListener('scroll', listener, true); |
| 11 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 12 document.addEventListener('scroll', listener, false); |
| 13 shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); |
| 14 document.removeEventListener('scroll', listener, true); |
| 15 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 16 |
| 17 // Try removing the capturing listener again. |
| 18 document.removeEventListener('scroll', listener, true); |
| 19 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 20 |
| 21 document.removeEventListener('scroll', listener, false); |
| 22 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 23 })(); |
| 24 |
| 25 (function() { |
| 26 // Test setting onscroll on the document. |
| 27 |
| 28 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 29 document.onscroll = function() { } |
| 30 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 31 document.onscroll = function() { } |
| 32 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 33 document.onscroll = null; |
| 34 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 35 })(); |
| 36 |
| 37 (function() { |
| 38 // Test addEventListener/removeEventListener on the window. |
| 39 var listener = function() { } |
| 40 |
| 41 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 42 window.addEventListener('scroll', listener, true); |
| 43 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 44 window.addEventListener('scroll', listener, false); |
| 45 shouldBe('window.internals.scrollEventHandlerCount(document)', '2'); |
| 46 window.removeEventListener('scroll', listener, true); |
| 47 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 48 |
| 49 // Try removing the capturing listener again. |
| 50 window.removeEventListener('scroll', listener, true); |
| 51 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 52 |
| 53 window.removeEventListener('scroll', listener, false); |
| 54 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 55 })(); |
| 56 |
| 57 (function() { |
| 58 // Test setting onscroll on the window. |
| 59 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 60 window.onscroll = function() { } |
| 61 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 62 window.onscroll = function() { } |
| 63 shouldBe('window.internals.scrollEventHandlerCount(document)', '1'); |
| 64 window.onscroll = null; |
| 65 shouldBe('window.internals.scrollEventHandlerCount(document)', '0'); |
| 66 })(); |
| 67 |
| 68 </script> |
| 69 </body> |
OLD | NEW |