blob: cd60fec4186f526557e6fd9492665ef3da3d43e2 [file] [log] [blame] [edit]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../resources/js-test.js"></script>
<script src="../resources/accessibility-helper.js"></script>
</head>
<body id="body">
<div id="background">
<p id="backgroundContent">Other page content with <a href="#">a dummy focusable element</a></p>
<p><a onclick="document.getElementById('dialog').showModal(); return false;" href="#" role="button" id="displayButton">Display a dialog</a></p>
</div>
<div id="dialogParent" role="group">
<dialog id="dialog">
<h3>Just an example.</h3>
<button id="ok" onclick="document.getElementById('dialog').close();" class="close-button">OK</button>
<button onclick="document.getElementById('dialog').close();" class="close-button">Cancel</button>
</dialog>
</div>
<script>
var output = "This tests that dialog.showModal() makes other elements inert.\n\n";
if (window.accessibilityController) {
window.jsTestIsAsync = true;
output += "Dialog is hidden\n";
output += expect("backgroundAccessible()", "true");
document.getElementById("dialog").showModal();
// Background should be unaccessible after loading, since the dialog is displayed.
output += "Dialog is displaying\n";
setTimeout(async function() {
output += await expectAsync("backgroundAccessible()", "false");
// Close the dialog, background should be accessible.
document.getElementById("ok").click();
await waitFor(() => backgroundAccessible());
output += "Dialog is not displaying\n";
output += expect("backgroundAccessible()", "true");
// Non modal <dialog> should allow interactions with background.
document.getElementById("dialog").show();
output += expect("backgroundAccessible()", "true");
await waitFor(() => accessibilityController.accessibleElementById("ok"));
window.okButton = accessibilityController.accessibleElementById("ok");
output += expect("okButton.isIgnored", "false");
document.getElementById("dialog").close();
// Click the display button, dialog shows and background becomes unaccessible.
document.getElementById("displayButton").click();
await waitFor(() => !backgroundAccessible());
output += "Dialog is displaying\n";
output += expect("backgroundAccessible()", "false");
await waitFor(() => accessibilityController.accessibleElementById("ok"));
window.okButton = accessibilityController.accessibleElementById("ok");
output += expect("okButton.isIgnored", "false");
// With the dialog displaying, test that aria-hidden and the opacity don't affect whether the background is accessible or not.
// Dialog is aria hidden
document.getElementById("dialog").setAttribute("aria-hidden", "true");
output += "Dialog is displaying and aria-hidden=true\n"
output += expect("backgroundAccessible()", "false");
// Set aria-hidden=false.
document.getElementById("dialog").setAttribute("aria-hidden", "false");
output += ("Dialog is displaying and aria-hidden=false\n");
output += expect("backgroundAccessible()", "false");
// Set aria-modal=false.
document.getElementById("dialog").setAttribute("aria-modal", "false");
output += "Dialog is displaying and aria-modal=false\n";
output += expect("backgroundAccessible()", "false");
document.getElementById("dialog").removeAttribute("aria-modal");
// Set opacity to 0 which should make the dialog invisible.
document.getElementById("dialog").style.opacity = 0;
output += "Dialog is not displaying with opacity 0\n";
output += expect("backgroundAccessible()", "false");
// Set opacity to 1 which should make the dialog visible again.
document.getElementById("dialog").style.opacity = 1;
output += "Dialog is displaying with opacity 1\n";
output += expect("backgroundAccessible()", "false");
// Test modal dialog is removed from DOM tree.
document.getElementById("dialog").remove();
await waitFor(() => backgroundAccessible());
output += "Dialog is removed from DOM\n";
output += expect("backgroundAccessible()", "true");
debug(output);
finishJSTest();
}, 0);
}
function backgroundAccessible() {
var displayButton = accessibilityController.accessibleElementById("displayButton");
var backgroundContent = accessibilityController.accessibleElementById("backgroundContent");
if (!displayButton || !backgroundContent)
return false;
return !displayButton.isIgnored && !backgroundContent.isIgnored;
}
</script>
</body>
</html>