scrollend-event-fired-for-programmatic-scroll.html (4295B)
1 <!DOCTYPE HTML> 2 <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1"> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/resources/testdriver.js"></script> 6 <script src="/resources/testdriver-actions.js"></script> 7 <script src="/resources/testdriver-vendor.js"></script> 8 <script src="/common/subset-tests-by-key.js"></script> 9 <meta name="variant" content="?include=subframe-scrollTo-auto"/> 10 <meta name="variant" content="?include=subframe-scrollTo-smooth"/> 11 <meta name="variant" content="?include=subframe-scrollBy-auto"/> 12 <meta name="variant" content="?include=subframe-scrollBy-smooth"/> 13 <meta name="variant" content="?include=root-scrollTo-auto"/> 14 <meta name="variant" content="?include=root-scrollTo-smooth"/> 15 <meta name="variant" content="?include=root-scrollBy-auto"/> 16 <meta name="variant" content="?include=root-scrollBy-smooth"/> 17 <script src="scroll_support.js"></script> 18 <style> 19 html { 20 height: 3000px; 21 width: 3000px; 22 } 23 #targetDiv { 24 width: 200px; 25 height: 200px; 26 overflow: scroll; 27 } 28 29 #innerDiv { 30 width: 400px; 31 height: 400px; 32 } 33 </style> 34 35 <body style="margin:0" onload=runTest()> 36 <div id="targetDiv"> 37 <div id="innerDiv"> 38 </div> 39 </div> 40 </body> 41 <script> 42 let invalid_scrollend_arrived = false; 43 44 function onInvalidScrollEnd(event) { 45 invalid_scrollend_arrived = true; 46 } 47 48 let scroll_fn_variants = [ 49 { 50 key: "subframe-scrollTo-auto", 51 target: targetDiv, 52 fn: "scrollTo", 53 behavior: "auto", 54 title: "Tests scrollend event for calling scrollTo with behavior 'auto' on subframe." 55 }, 56 { 57 key: "subframe-scrollTo-smooth", 58 target: targetDiv, 59 fn: "scrollTo", 60 behavior: "smooth", 61 title: "Tests scrollend event for calling scrollTo with behavior 'smooth' on subframe." 62 }, 63 { 64 key: "subframe-scrollBy-auto", 65 target: targetDiv, 66 fn: "scrollBy", 67 behavior: "auto", 68 title: "Tests scrollend event for calling scrollBy with behavior 'auto' on subframe." 69 }, 70 { 71 key: "subframe-scrollBy-smooth", 72 target: targetDiv, 73 fn: "scrollBy", 74 behavior: "smooth", 75 title: "Tests scrollend event for calling scrollBy with behavior 'smooth' on subframe." 76 }, 77 { 78 key: "root-scrollTo-auto", 79 target: document.scrollingElement, 80 fn: "scrollTo", 81 behavior: "auto", 82 title: "Tests scrollend event for calling scrollTo with behavior 'auto' on root." 83 }, 84 { 85 key: "root-scrollTo-smooth", 86 target: document.scrollingElement, 87 fn: "scrollTo", 88 behavior: "smooth", 89 title: "Tests scrollend event for calling scrollTo with behavior 'smooth' on root." 90 }, 91 { 92 key: "root-scrollBy-auto", 93 target: document.scrollingElement, 94 fn: "scrollBy", 95 behavior: "auto", 96 title: "Tests scrollend event for calling scrollBy with behavior 'auto' on root." 97 }, 98 { 99 key: "root-scrollBy-smooth", 100 target: document.scrollingElement, 101 fn: "scrollBy", 102 behavior: "smooth", 103 title: "Tests scrollend event for calling scrollBy with behavior 'smooth' on root." 104 }, 105 ]; 106 107 function runTest() { 108 109 async function testScrollFn(testInfo, t) { 110 await waitForCompositorCommit(); 111 112 let scrollendPromise = null; 113 if (testInfo.target == document.scrollingElement) { 114 targetDiv.addEventListener("scrollend", onInvalidScrollEnd); 115 scrollendPromise = createScrollendPromiseForTarget(t, document, 2000, true); 116 } else { 117 document.addEventListener("scrollend", onInvalidScrollEnd); 118 scrollendPromise = createScrollendPromiseForTarget(t, targetDiv, 2000, false); 119 } 120 121 testInfo.target[testInfo.fn]({ top: 200, left: 200, 122 behavior: testInfo.behavior }); 123 124 await scrollendPromise; 125 assert_false(invalid_scrollend_arrived, "Scrollend should not fire to target that has not scrolled"); 126 127 assert_equals(testInfo.target.scrollLeft, 200, 128 testInfo.target.tagName + "." + testInfo.fn + " scrollLeft"); 129 assert_equals(testInfo.target.scrollTop, 200, 130 testInfo.target.tagName + "." + testInfo.fn + " scrollTop"); 131 } 132 133 scroll_fn_variants.forEach((testInfo) => { 134 subsetTestByKey(testInfo.key, promise_test, 135 async (t) => testScrollFn(testInfo, t), testInfo.title); 136 }); 137 138 } 139 </script>