helper_scrollend_bubbles.html (2817B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <script src="apz_test_utils.js"></script> 6 <script src="/tests/SimpleTest/EventUtils.js"></script> 7 <script src="/tests/SimpleTest/paint_listener.js"></script> 8 <style> 9 html, body { margin: 0; } 10 11 body { 12 height: 10000px; 13 } 14 15 #container { 16 height: 500px; 17 width: 500px; 18 overflow: scroll; 19 } 20 21 .spacer { 22 height: 5000px; 23 width: 100%; 24 } 25 </style> 26 <script> 27 const searchParams = new URLSearchParams(location.search); 28 29 async function test() { 30 let scrollendCount = 0; 31 32 // When scrollend is fired at the document, the document and 33 // window event listeners should be fired. 34 let expectedScrollendCount = 2; 35 let scrollTarget = document.scrollingElement; 36 37 // The scrollend event should not bubble if the target is not Document. 38 function onElementScrollend(e) { 39 scrollendCount += 1; 40 is(e.bubbles, false, "Event bubbles should be false for Element"); 41 } 42 43 // The scrollend event should bubble if the target is Document. 44 function onDocumentScrollend(e) { 45 scrollendCount += 1; 46 is(e.bubbles, true, "Event bubbles should be true for Document"); 47 } 48 49 function failOnScrollend(e) { 50 ok(false, e.target + ": should not receive a scrollend event"); 51 } 52 53 switch (searchParams.get("scroll-target")) { 54 case "document": 55 // The window and the document event listeners should be triggered. 56 document.addEventListener("scrollend", onDocumentScrollend); 57 window.addEventListener("scrollend", onDocumentScrollend); 58 59 // Fail if the element receives a scrollend event. 60 container.addEventListener("scrollend", failOnScrollend); 61 break; 62 case "element": 63 scrollTarget = document.getElementById("container"); 64 expectedScrollendCount = 1; 65 66 // Only the the element event listener should be triggered. 67 container.addEventListener("scrollend", onElementScrollend); 68 69 // Fail if the document or window receive a scrollend event. 70 document.addEventListener("scrollend", failOnScrollend); 71 window.addEventListener("scrollend", failOnScrollend); 72 break; 73 default: 74 ok(false, "Unsupported scroll-target: " + searchParams.get("scroll-target")); 75 break; 76 } 77 78 // Call the scrollTo function on the target to trigger the scrollend. 79 scrollTarget.scrollBy({ top: 500, left: 0 }); 80 81 // Ensure the refresh driver has ticked. 82 await promiseFrame(); 83 84 // A scrollend event should be posted after the refresh driver has ticked. 85 is(scrollendCount, expectedScrollendCount, 86 "Trigger the expected number of scrollend events"); 87 } 88 waitUntilApzStable() 89 .then(test) 90 .then(subtestDone, subtestFailed); 91 </script> 92 </head> 93 <body> 94 <div id="container"> 95 <div class="spacer"> 96 </div> 97 </div> 98 </body> 99 </html>