blob: 7099736f6513d4648e03a59183338e6248ed58a2 [file] [edit]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../resources/accessibility-helper.js"></script>
<script src="../resources/js-test.js"></script>
</head>
<body>
<div id="container" style="width: 100px; overflow: scroll">
<div style="border: 1px solid #000; width: 1000px; height: 5000px;">5000-pixel box</div>
<button id="target1">Target</button>
<button id="target2">Target</button>
<button id="target3">Target</button>
<div style="border: 1px solid #000; width: 1000px; height: 5000px;">5000-pixel box</div>
</div>
<script>
var output = "Tests that scrolling to make an element visible works when the inner scroll container doesn't need to be scrolled, but the other one does.\n\n";
if (window.accessibilityController) {
window.jsTestIsAsync = true;
window.container = document.getElementById("container");
window.target1 = document.getElementById("target1");
window.target2 = document.getElementById("target2");
window.target3 = document.getElementById("target3");
var target1AccessibleObject, target2AccessibleObject, target3AccessibleObject;
setTimeout(async function() {
target1AccessibleObject = await waitForFocus("target1");
target2AccessibleObject = await waitForFocus("target2");
target3AccessibleObject = await waitForFocus("target3");;
// Reset the initial scroll positions (since calling focus() can scroll the page too).
window.scrollTo(0, 0);
container.scrollTop = 0;
output += expect("window.pageYOffset", "0");
output += expect("container.scrollTop", "0");
output += expect("target1.getBoundingClientRect().top >= 5000", "true");
// Scroll to make the middle target visible.
target2AccessibleObject.scrollToMakeVisible();
// Instead of testing the exact scroll offsets of the two containers, just test that
// the new absolute position of the target is on-screen.
output += await expectAsync("window.innerHeight >= target2.getBoundingClientRect().bottom", "true");
// Make sure that calling scrollToMakeVisible on target1 and target3 don't result in any
// scrolling, because they should already be within the viewport.
window.target2top = target2.getBoundingClientRect().top;
target1AccessibleObject.scrollToMakeVisible();
// Sleep a bit to allow the bug to happen (if our implementation is wrong).
await sleep(60);
output += expect("target2top", "target2.getBoundingClientRect().top");
target3AccessibleObject.scrollToMakeVisible();
await sleep(60);
output += expect("target2top", "target2.getBoundingClientRect().top");
debug(output);
finishJSTest();
}, 0);
}
</script>
</body>
</html>