Source code
Revision control
Copy as Markdown
Other Tools
<!DOCTYPE>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Checking zoomToFocusedInput scrolls that focused element is into iframe</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>
<iframe style="height: 30em;"></iframe>
</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 isCrossOrigin = (location.search == "?cross-origin");
let iframeURL =
SimpleTest.getTestFileURL("helper_iframe_textarea.html")
if (isCrossOrigin) {
}
let iframe = document.querySelector("iframe");
const iframeLoadPromise = promiseOneEvent(iframe, "load", null);
iframe.src = iframeURL;
await iframeLoadPromise;
await SpecialPowers.spawn(iframe, [], async () => {
await content.wrappedJSObject.waitUntilApzStable();
});
iframe.focus();
await SpecialPowers.spawn(iframe, [], async () => {
let textarea = content.document.querySelector("textarea");
for (let i = 0; i < 20; i++) {
textarea.value += "foo\n";
}
textarea.focus();
});
await SpecialPowers.spawn(iframe, [], async () => {
await content.wrappedJSObject.waitToClearOutAnyPotentialScrolls(content.window);
});
await SpecialPowers.spawn(iframe, [], async () => {
let textarea = content.document.querySelector("textarea");
textarea.setSelectionRange(0, 0);
});
window.scrollTo(0, 0);
await SpecialPowers.spawn(iframe, [], async () => {
await content.wrappedJSObject.waitToClearOutAnyPotentialScrolls(content.window);
});
is(0, window.scrollY, "scroll position is reset");
let scrollendPromise = promiseScrollend();
await SpecialPowers.spawn(iframe, [], async () => {
SpecialPowers.DOMWindowUtils.zoomToFocusedInput();
});
await promiseApzFlushedRepaints();
ok(window.scrollY > 0, "scroll position isn't top");
let iframeWindowScrollY = await SpecialPowers.spawn(iframe, [], () => {
return content.window.scrollY;
});
ok(iframeWindowScrollY > 0, "scroll position into iframe isn't top");
await scrollendPromise;
let prevPosY = window.scrollY;
await promiseApzFlushedRepaints();
window.scrollTo(0, 0);
await SpecialPowers.spawn(iframe, [], async () => {
await content.wrappedJSObject.waitToClearOutAnyPotentialScrolls(content.window);
});
is(0, window.scrollY, "scroll position is reset");
SpecialPowers.spawn(iframe, [], async () => {
let textarea = content.document.querySelector("textarea");
textarea.setSelectionRange(textarea.value.length, textarea.value.length);
});
scrollendPromise = promiseScrollend();
await SpecialPowers.spawn(iframe, [], async () => {
SpecialPowers.DOMWindowUtils.zoomToFocusedInput();
});
await scrollendPromise;
await promiseApzFlushedRepaints();
ok(window.scrollY > 0, "scroll position isn't top");
iframeWindowScrollY = await SpecialPowers.spawn(iframe, [], () => {
return content.window.scrollY;
});
ok(iframeWindowScrollY > 0, "scroll position into iframe isn't top");
ok(prevPosY < window.scrollY,
"scroll position is different from first line of textarea");
}
waitUntilApzStable().then(test).then(subtestDone, subtestFailed);
</script>
</body>
</html>