blob: 51d13f0399f40ff49f93076980533d9c56b8e293 [file]
<!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>
<iframe id="frame" src="data:text/html,<body><button id='upper_target'>Upper Target</button><div style='border: 1px solid %23000; height: 5000px;'>5000-pixel box</div><button id='lower_target'>Lower Target</button></body>"></iframe>
<script>
var output = "Tests that scrolling to make an element visible successfully scrolls an iframe.\n\n";
window.jsTestIsAsync = true;
async function waitForAXFocus(domElement) {
domElement.focus();
var axElement;
await waitFor(() => {
axElement = accessibilityController.focusedElement;
return axElement && axElement.domIdentifier === domElement.id;
});
return axElement;
}
function runTest() {
window.frame = document.getElementById("frame");
window.frameWindow = frame.contentWindow;
window.frameDoc = frameWindow.document;
var upperTarget = frameDoc.getElementById("upper_target");
var lowerTarget = frameDoc.getElementById("lower_target");
var lowerTargetAccessibleObject;
var upperTargetAccessibleObject;
setTimeout(async function() {
lowerTargetAccessibleObject = await waitForAXFocus(lowerTarget);
upperTargetAccessibleObject = await waitForAXFocus(upperTarget);
// Reset the initial scroll position (since calling focus() can scroll the page too).
frameWindow.scrollTo(0, 0);
output += expect("frameWindow.pageYOffset", "0");
// Scroll to make lower target visible and check.
lowerTargetAccessibleObject.scrollToMakeVisible();
await waitFor(() => {
window.minYOffset = lowerTarget.offsetTop + lowerTarget.offsetHeight - frameWindow.innerHeight;
window.maxYOffset = lowerTarget.offsetTop;
return frameWindow.pageYOffset >= minYOffset && frameWindow.pageYOffset <= maxYOffset;
});
output += expect("frameWindow.pageYOffset >= minYOffset", "true");
output += expect("frameWindow.pageYOffset <= maxYOffset", "true");
// Scroll to make upper target visible and check.
upperTargetAccessibleObject.scrollToMakeVisible();
await waitFor(() => {
window.minYOffset = upperTarget.offsetTop + upperTarget.offsetHeight - frameWindow.innerHeight;
window.maxYOffset = upperTarget.offsetTop;
return frameWindow.pageYOffset >= minYOffset && frameWindow.pageYOffset <= maxYOffset;
});
output += expect("frameWindow.pageYOffset >= minYOffset", "true");
output += expect("frameWindow.pageYOffset <= maxYOffset", "true");
debug(output);
finishJSTest();
}, 0);
}
window.addEventListener("load", function() {
setTimeout(runTest, 0);
}, false);
</script>
</body>
</html>