helper_basic_scrollend.html (2538B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <script src="apz_test_utils.js"></script> 6 <script src="apz_test_native_event_utils.js"></script> 7 <script src="/tests/SimpleTest/EventUtils.js"></script> 8 <script src="/tests/SimpleTest/paint_listener.js"></script> 9 <style> 10 html, body { margin: 0; } 11 12 body { 13 height: 10000px; 14 } 15 </style> 16 <script> 17 const searchParams = new URLSearchParams(location.search); 18 19 async function test() { 20 var scrollendCount = 0; 21 22 function onScrollend() { 23 scrollendCount += 1; 24 } 25 26 switch (searchParams.get("chrome-only")) { 27 case "true": 28 // Add chrome-only event listener. 29 SpecialPowers.addChromeEventListener("scrollend", onScrollend, true); 30 break; 31 case "false": 32 // Add document event listener. 33 document.addEventListener("scrollend", onScrollend); 34 break; 35 default: 36 ok(false, "Unsupported chrome-only value: " + searchParams.get("chrome-only")); 37 break; 38 } 39 40 is(scrollendCount, 0, "A scrollend event should not be triggered yet"); 41 42 await promiseFrame(); 43 44 let wheelScrollTransformEndPromise = promiseTransformEnd(); 45 46 await promiseMoveMouseAndScrollWheelOver(document.scrollingElement, 100, 100); 47 48 await wheelScrollTransformEndPromise; 49 50 await promiseFrame(); 51 52 is(scrollendCount, 1, "A scrollend event should be triggered after user scroll"); 53 54 scrollendCount = 0; 55 56 // Call the scrollTo function without behavior: smooth to trigger an instant 57 // programatic scroll. 58 scrollTo({ top: 500, left: 0 }); 59 60 // Ensure the refresh driver has ticked. 61 await promiseFrame(); 62 63 // A scrollend event should be posted after the refresh driver has ticked. 64 is(scrollendCount, 1, "A scrollend event should be triggered after instant scroll"); 65 66 // If smooth scrolls are enabled, repeat the test with a smooth scroll. 67 if (SpecialPowers.getBoolPref("general.smoothScroll")) { 68 69 scrollendCount = 0; 70 71 let smoothScrollTransformEndPromise = promiseTransformEnd(); 72 73 // Call the scrollTo function with behavior: smooth to trigger a programmatic 74 // scroll that should require some form of async transform. 75 scrollTo({ top: 1000, left: 0, behavior: "smooth" }); 76 77 // Ensure the smooth scroll transform has finished. 78 await smoothScrollTransformEndPromise; 79 80 await promiseFrame(); 81 82 is(scrollendCount, 1, "A scrollend event should be triggered after smooth scroll"); 83 } 84 } 85 waitUntilApzStable() 86 .then(test) 87 .then(subtestDone, subtestFailed); 88 </script> 89 </head> 90 <body> 91 </body> 92 </html>