helper_scroll_into_view_bug1562757.html (2590B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <meta name="viewport" content="width=device-width"> 6 <title>Test for bug 1562757: "scroll into view" in iframe respects bounds on layout scroll position</title> 7 <script type="application/javascript" src="apz_test_utils.js"></script> 8 <script src="/tests/SimpleTest/paint_listener.js"></script> 9 <style> 10 #iframe { 11 width: 100px; 12 height: 100px; 13 margin-left: 50%; 14 margin-right: 50%; 15 background: cyan; 16 display: block; 17 } 18 </style> 19 </head> 20 <body> 21 <iframe id="iframe" scrolling="no" frameborder="no" srcdoc="<div id='target' style='width:100px;height:100px;'></div>"></iframe> 22 23 <script> 24 let vv = window.visualViewport; 25 function getVisualScrollRange() { 26 let rootScroller = document.scrollingElement; 27 return { 28 width: rootScroller.scrollWidth - vv.width, 29 height: rootScroller.scrollHeight - vv.height, 30 }; 31 } 32 async function test() { 33 is(window.scrollMaxX, 0, "page should have a zero horizontal layout scroll range"); 34 is(window.scrollMaxY, 0, "page should have a zero vertical layout scroll range"); 35 let visualScrollRange = getVisualScrollRange(); 36 ok(visualScrollRange.width > 0, "page should have a nonzero horizontal visual scroll range"); 37 ok(visualScrollRange.height > 0, "page should have a nonzero vertical visual scroll range"); 38 let target = iframe.contentDocument.getElementById("target"); 39 40 // Scroll target element into view. Wait until any visual scrolling is done before doing checks. 41 let scrollPromise = new Promise(resolve => { 42 vv.addEventListener("scroll", resolve, { once: true }); 43 }); 44 target.scrollIntoView(); 45 await scrollPromise; // wait for visual viewport "scroll" event 46 await promiseApzFlushedRepaints(); 47 48 // Test that scrollIntoView() respected the layout scroll range. 49 is(window.scrollX, 0, "page should not layout-scroll with a zero layout scroll range"); 50 is(window.scrollY, 0, "page should not layout-scroll with a zero layout scroll range"); 51 52 // Test that scrollIntoView() did perform visual scrolling. 53 let vvRect = getVisualViewportRect(vv); 54 let targetBounds = iframe.getBoundingClientRect(); 55 assertRectContainment(vvRect, "visual viewport", targetBounds, "iframe having the target element bounding rect"); 56 } 57 SpecialPowers.getDOMWindowUtils(window).setResolutionAndScaleTo(2.0); 58 59 waitUntilApzStable() 60 .then(test) 61 .then(subtestDone, subtestFailed); 62 </script> 63 </body> 64 </html>