summaryrefslogtreecommitdiffstats
path: root/dom/html/test/test_bug556645.html
blob: 08a230370f6045f8405fb67db1c6f370e601107e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<html>
<head>
  <title>Test for Bug 556645 and Bug 1848196</title>
  <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>