snap-at-user-scroll-end.html (1985B)
1 <!DOCTYPE html> 2 <link rel="help" href="https://drafts.csswg.org/css-scroll-snap-1/#scroll-snap-type" /> 3 <title>Tests that window should snap at user scroll end.</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/resources/testdriver.js"></script> 7 <script src="/resources/testdriver-actions.js"></script> 8 <script src="/resources/testdriver-vendor.js"></script> 9 <script src="/dom/events/scrolling/scroll_support.js"></script> 10 <script src="support/common.js"></script> 11 <style> 12 html { 13 margin: 0px; 14 scroll-snap-type: both mandatory; 15 } 16 #content { 17 width: 2000px; 18 height: 2000px; 19 padding: 0px; 20 margin: 0px; 21 } 22 #target { 23 position: relative; 24 left: 400px; 25 top: 400px; 26 width: 400px; 27 height: 400px; 28 background-color: lightblue; 29 overflow: hidden; 30 scroll-snap-align: start; 31 } 32 </style> 33 <div id="content"> 34 <div id="target"> 35 <!-- CSSScrollSnap 36 Tests that the window snaps at user scroll end. 37 Manual steps: 38 1. Scroll the page once vertically and once horizontally. 39 2. Verify in console (or otherwise) window scroll position is same as 40 target's offset position --> 41 </div> 42 </div> 43 <script> 44 promise_test(async t => { 45 await waitForCompositorReady(); 46 const target = document.getElementById("target"); 47 // Inject scroll actions. 48 const pos_x = 20; 49 const pos_y = 20; 50 const scroll_delta_x = 100; 51 const scroll_delta_y = 100; 52 const wheelPromise = waitForWheelEvent(window); 53 await new test_driver.Actions() 54 .scroll(pos_x, pos_y, scroll_delta_x, scroll_delta_y) 55 .send() 56 await wheelPromise; 57 await waitForAnimationEnd(() => window.scrollY); 58 assert_approx_equals(window.scrollX, target.offsetLeft, 0.5, 59 "window.scrollX should be at snapped position."); 60 assert_approx_equals(window.scrollY, target.offsetTop, 0.5, 61 "window.scrollY should be at snapped position."); 62 }, "Tests that window should snap at user scroll end."); 63 </script>