tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug556645.html (2259B)


      1 <html>
      2 <head>
      3  <title>Test for Bug 556645 and Bug 1848196</title>
      4  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      5  <script src="/tests/SimpleTest/EventUtils.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7 </head>
      8 <body>
      9 <script>
     10 SimpleTest.waitForExplicitFinish();
     11 SimpleTest.waitForFocus(async () => {
     12  const object = document.createElement("object");
     13  object.setAttribute("type", "text/html");
     14  object.setAttribute("width", "200");
     15  object.setAttribute("height", "200");
     16  document.body.appendChild(object);
     17  const promiseLoadObject = new Promise(resolve => {
     18    object.addEventListener("load", resolve, {once: true});
     19  });
     20  object.setAttribute("data", "object_bug556645.html");
     21  await promiseLoadObject;
     22  runTest(object);
     23  object.remove();
     24 
     25  const embed = document.createElement("embed");
     26  embed.setAttribute("type", "text/html");
     27  embed.setAttribute("width", "200");
     28  embed.setAttribute("height", "200");
     29  document.body.appendChild(embed);
     30  const promiseLoadEmbed = new Promise(resolve => {
     31    embed.addEventListener("load", resolve, {once: true});
     32  });
     33  embed.setAttribute("src", "object_bug556645.html");
     34  await promiseLoadEmbed;
     35  runTest(embed);
     36  embed.remove();
     37 
     38  SimpleTest.finish();
     39 });
     40 
     41 function runTest(aObjectOrEmbed)
     42 {
     43  const desc = `<${aObjectOrEmbed.tagName.toLowerCase()}>`;
     44  const childDoc = aObjectOrEmbed.contentDocument || aObjectOrEmbed.getSVGDocument();
     45  const body = childDoc.body;
     46  is(document.activeElement, document.body, `${desc}: focus in parent before`);
     47  is(childDoc.activeElement, body, `${desc}: focus in child before`);
     48 
     49  const button = childDoc.querySelector("button");
     50  button.focus();
     51  childDoc.defaultView.focus();
     52  is(document.activeElement, aObjectOrEmbed, `${desc}: focus in parent after focus()`);
     53  is(childDoc.activeElement, button, `${desc}: focus in child after focus()`);
     54 
     55  button.blur();
     56  const pbutton = document.getElementById("pbutton");
     57  pbutton.focus();
     58 
     59  synthesizeKey("KEY_Tab");
     60  is(document.activeElement, aObjectOrEmbed, `${desc}: focus in parent after tab 2`);
     61  is(childDoc.activeElement, button, `${desc}: focus in child after tab 2`);
     62 }
     63 
     64 </script>
     65 
     66 <button id="pbutton">Parent</button>
     67 
     68 </body>
     69 </html>