tor-browser

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

focus-previous-iframe.tentative.html (1682B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <meta name="viewport" content="width=device-width,initial-scale=1">
      4 <title>Test focus is moved to the previously focused element when dialog is closed</title>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="/resources/testdriver.js"></script>
      8 <script src="/resources/testdriver-actions.js"></script>
      9 <script src="/resources/testdriver-vendor.js"></script>
     10 
     11 <body>
     12 <dialog>Dialog in parent</dialog>
     13 
     14 <iframe srcdoc="<input><dialog> Dialog in child </dialog>"></iframe>
     15 
     16 <input>
     17 <script>
     18 test(() => {
     19  window.onload = function() {
     20    const iframe = document.querySelector("iframe");
     21    const input = iframe.contentDocument.querySelector("input");
     22    // <input> in the child document is focused
     23    input.focus();
     24 
     25    const dialog = document.querySelector("dialog");
     26    // <dialog> in the parent document is opened
     27    dialog.showModal();
     28    dialog.close();
     29 
     30    assert_equals(document.activeElement, iframe);
     31    assert_equals(iframe.contentDocument.activeElement, input);
     32  }
     33 }, "Focus should move back from parent document to child document");
     34 
     35 test(() => {
     36  window.onload = function() {
     37    const iframe = document.querySelector("iframe");
     38    const input = document.querySelector("input");
     39    // <input> in the parent document is focused
     40    input.focus();
     41 
     42    const dialog = iframe.contentDocument.querySelector("dialog");
     43 
     44    // <dialog> in the child document is focused
     45    dialog.showModal();
     46    dialog.close();
     47 
     48    assert_equals(document.activeElement, input);
     49  }
     50 }, "Focus should move back from child document to parent document");
     51 </script>
     52 </body>