Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- Manifest: dom/html/test/mochitest.toml
<html>
<head>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script>
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async () => {
const object = document.createElement("object");
object.setAttribute("type", "text/html");
object.setAttribute("width", "200");
object.setAttribute("height", "200");
document.body.appendChild(object);
const promiseLoadObject = new Promise(resolve => {
object.addEventListener("load", resolve, {once: true});
});
object.setAttribute("data", "object_bug556645.html");
await promiseLoadObject;
runTest(object);
object.remove();
const embed = document.createElement("embed");
embed.setAttribute("type", "text/html");
embed.setAttribute("width", "200");
embed.setAttribute("height", "200");
document.body.appendChild(embed);
const promiseLoadEmbed = new Promise(resolve => {
embed.addEventListener("load", resolve, {once: true});
});
embed.setAttribute("src", "object_bug556645.html");
await promiseLoadEmbed;
runTest(embed);
embed.remove();
SimpleTest.finish();
});
function runTest(aObjectOrEmbed)
{
const desc = `<${aObjectOrEmbed.tagName.toLowerCase()}>`;
const childDoc = aObjectOrEmbed.contentDocument || aObjectOrEmbed.getSVGDocument();
const body = childDoc.body;
is(document.activeElement, document.body, `${desc}: focus in parent before`);
is(childDoc.activeElement, body, `${desc}: focus in child before`);
const button = childDoc.querySelector("button");
button.focus();
childDoc.defaultView.focus();
is(document.activeElement, aObjectOrEmbed, `${desc}: focus in parent after focus()`);
is(childDoc.activeElement, button, `${desc}: focus in child after focus()`);
button.blur();
const pbutton = document.getElementById("pbutton");
pbutton.focus();
let canTabMoveFocusToRootElement = !SpecialPowers.getBoolPref("dom.disable_tab_focus_to_root_element");
if (canTabMoveFocusToRootElement) {
synthesizeKey("KEY_Tab");
is(document.activeElement, aObjectOrEmbed, `${desc}: focus in parent after tab`);
is(childDoc.activeElement, childDoc.documentElement, `${desc}: focus in child after tab`);
}
synthesizeKey("KEY_Tab");
is(document.activeElement, aObjectOrEmbed, `${desc}: focus in parent after tab 2`);
is(childDoc.activeElement, button, `${desc}: focus in child after tab 2`);
}
</script>
<button id="pbutton">Parent</button>
</body>
</html>