tor-browser

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

test_focus_display_none_xorigin_iframe.html (4288B)


      1 <!DOCTYPE html>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1716762
      5 -->
      6 <head>
      7 <meta charset="utf-8">
      8 <title>Test for Bug 1716762</title>
      9 <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1716762">Mozilla Bug 1716762</a><br>
     14 <input></input><br>
     15 <div id="target" style="display: none;">
     16 <iframe src="http://example.org/tests/dom/base/test/file_focus_display_none_xorigin_iframe_inner.html"></iframe>
     17 </div>
     18 <script type="text/javascript">
     19 
     20 let waitForMessage = function(aMsg) {
     21  return new Promise(reslove => {
     22    window.addEventListener("message", function handler(e) {
     23      info(`main received message: ${e.data}`);
     24      if (e.data === aMsg) {
     25        window.removeEventListener("message", handler);
     26        reslove();
     27      }
     28    });
     29  });
     30 };
     31 
     32 let sendMessage = async function(aWindow, aMsg) {
     33  aWindow.postMessage(aMsg, "*");
     34  await waitForMessage("done");
     35 }
     36 
     37 let getFocus = function(aWindow) {
     38  return new Promise(reslove => {
     39    window.addEventListener("message", function handler(e) {
     40      info(e.data);
     41      reslove(e.data);
     42    }, { once: true });
     43    aWindow.postMessage("getfocus", "*");
     44  });
     45 }
     46 
     47 /** Test for Bug 1716762  */
     48 
     49 let input = document.querySelector("input");
     50 let iframe = document.querySelector("iframe");
     51 
     52 add_task(async function test_ancestor_display_none_init() {
     53  // focus input element
     54  input.focus();
     55  is(document.activeElement.tagName, "INPUT", "focus should move to input element");
     56 
     57  // focus input element in hidden iframe
     58  await sendMessage(iframe.contentWindow, "focus");
     59  is(document.activeElement.tagName, "INPUT", "focus should stay on input element");
     60 });
     61 
     62 add_task(async function test_remove_ancestor_display_none() {
     63  // remove `display: none` from the ancestor of iframe
     64  document.getElementById("target").style = "";
     65  document.body.offsetWidth;
     66 
     67  // focus input element
     68  input.focus();
     69  is(document.activeElement.tagName, "INPUT", "focus should move to input element");
     70 
     71  // focus input element in hidden iframe
     72  await sendMessage(iframe.contentWindow, "focus");
     73  is(document.activeElement.tagName, "IFRAME", "focus should move to iframe element");
     74 });
     75 
     76 add_task(async function test_ancestor_display_none() {
     77  // add `display: none` to the ancestor of iframe back
     78  document.getElementById("target").style = "display: none;";
     79  document.body.offsetWidth;
     80 
     81  // focus input element
     82  input.focus();
     83  is(document.activeElement.tagName, "INPUT", "focus should move to input element");
     84 
     85  // focus input element in hidden iframe
     86  await sendMessage(iframe.contentWindow, "focus");
     87  is(document.activeElement.tagName, "INPUT", "focus should stay on input element");
     88 });
     89 
     90 add_task(async function test_remove_ancestor_display_none_again() {
     91  // remove `display: none` from the ancestor of iframe
     92  document.getElementById("target").style = "";
     93  document.body.offsetWidth;
     94 
     95  // focus input element
     96  input.focus();
     97  is(document.activeElement.tagName, "INPUT", "focus should move to input element");
     98 
     99  // focus input element in hidden iframe
    100  await sendMessage(iframe.contentWindow, "focus");
    101  is(document.activeElement.tagName, "IFRAME", "focus should move to iframe element");
    102 });
    103 
    104 add_task(async function test_iframe_display_none() {
    105  // add `display: none` to iframe
    106  iframe.style = "display: none;";
    107  document.body.offsetWidth;
    108 
    109  // focus input element
    110  input.focus();
    111  is(document.activeElement.tagName, "INPUT", "focus should move to input element");
    112 
    113  // focus input element in hidden iframe
    114  await sendMessage(iframe.contentWindow, "focus");
    115  is(document.activeElement.tagName, "INPUT", "focus should stay on input element");
    116 });
    117 
    118 add_task(async function test_remove_iframe_display_none() {
    119  // remove `display: none` from iframe
    120  iframe.style = "";
    121  document.body.offsetWidth;
    122 
    123  // focus input element
    124  input.focus();
    125  is(document.activeElement.tagName, "INPUT", "focus should move to input element");
    126 
    127  // focus input element in hidden iframe
    128  await sendMessage(iframe.contentWindow, "focus");
    129  is(document.activeElement.tagName, "IFRAME", "focus should move to iframe element");
    130 });
    131 
    132 </script>
    133 </body>
    134 </html>