visual-scrollIntoView-001.html (1997B)
1 <!DOCTYPE html> 2 <html> 3 <meta name="viewport" content="width=device-width,initial-scale=1"> 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="support/action-utils.js"></script> 10 <link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1943865"> 11 <link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1943053"> 12 <link rel="help" href="https://drafts.csswg.org/cssom-view/#perform-a-scroll"> 13 <style> 14 body { 15 margin: 0px; 16 padding: 0px; 17 } 18 </style> 19 <div id="anchor"></div> 20 <div style="position: fixed; bottom: 0;"> 21 <div style="position: absolute; bottom: 0;"> 22 <input type="text" id="name" /> 23 </div> 24 </div> 25 <script> 26 promise_test(async t => { 27 assert_equals(window.scrollY, 0); 28 assert_equals(visualViewport.scale, 1.0); 29 assert_equals(visualViewport.pageTop, 0); 30 31 // Pinch zoom in this document. 32 await pinch_zoom_action(); 33 34 assert_greater_than(visualViewport.scale, 1.0); 35 36 // Suppose that the pinch zoom-in gesture at the center of the document did 37 // move the visual viewport offset. 38 assert_greater_than(visualViewport.pageTop, 0); 39 40 // Move to zero offset of the visual viewport. 41 let scrollPromise = 42 new Promise(resolve => visualViewport.addEventListener("scroll", resolve)); 43 document.querySelector('#anchor').scrollIntoView({ behavior: "instant" }); 44 await scrollPromise; 45 46 assert_equals(visualViewport.pageTop, 0); 47 48 // Now trigger a scrollIntoView call to an element inside a position:fixed element. 49 scrollPromise = 50 new Promise(resolve => visualViewport.addEventListener("scroll", resolve)); 51 document.querySelector('#name').scrollIntoView({ behavior: "instant" }); 52 await scrollPromise; 53 54 assert_greater_than(visualViewport.pageTop, 0); 55 }, "Element.scrollIntoView scrolls visually"); 56 </script>