Source code
Revision control
Copy as Markdown
Other Tools
<!DOCTYPE>
<html>
<head>
<title>Checking zoomToFocusedInput scrolls that focused non-input element is visible position</title>
<script type="application/javascript" src="apz_test_utils.js"></script>
<script type="application/javascript" src="apz_test_native_event_utils.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
</head>
<body>
<div style="height: 8000px;">ABC</div>
<div id="content">
</div>
<!-- Leave additional room below the element so it can be scrolled to the center -->
<div style="height: 1000px;">ABC</div>
<script type="application/javascript">
async function test() {
let utils = SpecialPowers.getDOMWindowUtils(window);
// contenteditable
let div = document.createElement("div");
div.setAttribute("contenteditable", "true");
for (let i = 0; i < 200; i++) {
div.innerHTML += "foo<br>";
}
div.innerHTML += "<span id=last>bar</span>";
document.getElementById("content").appendChild(div);
let selection = window.getSelection();
selection.collapse(div.firstChild, 0);
window.scrollTo(0, 0);
await waitToClearOutAnyPotentialScrolls(window);
is(0, window.scrollY, "scroll position is reset");
let scrollendPromise = promiseScrollend();
utils.zoomToFocusedInput();
await scrollendPromise;
await promiseApzFlushedRepaints();
ok(window.scrollY > 0, "scroll position isn't top");
let prevY = window.scrollY;
selection.collapse(document.getElementById("last").firstChild, 0);
window.scrollTo(0, 0);
await waitToClearOutAnyPotentialScrolls(window);
is(0, window.scrollY, "scroll position is reset");
scrollendPromise = promiseScrollend();
utils.zoomToFocusedInput();
await scrollendPromise;
await promiseApzFlushedRepaints();
ok(prevY < window.scrollY, "scroll position is visibile position of caret");
document.getElementById("content").removeChild(div);
// <textarea> element
let textarea = document.createElement("textarea");
textarea.rows = 200;
for (let i = 0; i < 200; i++) {
textarea.value += "foo\n";
}
document.getElementById("content").appendChild(textarea);
textarea.focus();
await waitToClearOutAnyPotentialScrolls(window);
textarea.setSelectionRange(0, 0);
window.scrollTo(0, 0);
await waitToClearOutAnyPotentialScrolls(window);
is(0, window.scrollY, "scroll position is reset");
scrollendPromise = promiseScrollend();
utils.zoomToFocusedInput();
await scrollendPromise;
await promiseApzFlushedRepaints();
ok(window.scrollY > 0, "scroll position isn't top");
prevY = window.scrollY;
textarea.setSelectionRange(textarea.value.length, textarea.value.length);
window.scrollTo(0, 0);
await waitToClearOutAnyPotentialScrolls(window);
is(0, window.scrollY, "scroll position is reset");
scrollendPromise = promiseScrollend();
utils.zoomToFocusedInput();
await scrollendPromise;
await promiseApzFlushedRepaints();
ok(prevY < window.scrollY, "scroll position is visibile position of caret");
document.getElementById("content").removeChild(textarea);
}
waitUntilApzStable().then(test).then(subtestDone, subtestFailed);
</script>
</body>
</html>