Source code
Revision control
Copy as Markdown
Other Tools
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Tests that zoomToFocuedInput scrolls visually with the non-zero root scroll offset</title>
<script src="apz_test_native_event_utils.js"></script>
<script src="apz_test_utils.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<style>
html {
height: 10000px;
scroll-behavior: auto; /* to make scrolling instant */
}
#fixed {
position: fixed;
bottom: 0px;
height: 50vh;
width: 100vw;
overflow: scroll;
background-color: gray;
}
input {
height: 20px;
}
</style>
</head>
<body>
<div id="fixed">
<div style="height: calc(80vh - 40px)"></div>
<input type="text" id="name" />
</div>
<script>
async function test() {
is(window.scrollY, 0, "The initial scroll offset should be 0");
is(visualViewport.scale, 2.0, "The document should get scaled by 2.0");
is(visualViewport.pageTop, 0, "The initial visual viewport pageTop should be 0");
// Scroll the root scroll container.
window.scrollTo(0, 2000);
is(window.scrollY, 2000, "Now the scroll offset should be 2000");
const expectedPageTop = visualViewport.pageTop;
const scrollPromise =
new Promise(resolve => visualViewport.addEventListener("scroll", resolve));
document.querySelector("#name").focus();
SpecialPowers.DOMWindowUtils.zoomToFocusedInput();
await scrollPromise;
await promiseApzFlushedRepaints();
ok(visualViewport.pageTop > expectedPageTop,
`visual viewport should have scrolled ` +
`the current pageTop: ${visualViewport.pageTop}, ` +
`the previous pageTop: ${expectedPageTop}`);
}
SpecialPowers.getDOMWindowUtils(window).setResolutionAndScaleTo(2.0);
waitUntilApzStable()
.then(test)
.then(subtestDone, subtestFailed);
</script>
</body>
</html>