tor-browser

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

activeelement-after-nested-loses-focus.html (2862B)


      1 <!doctype html>
      2 <head>
      3 <meta charset=utf-8>
      4 <title>Use focusout and click events to test ancestors' activeElements are cleared and updated correctly when nested child loses focus</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-vendor.js"></script>
      9 </head>
     10 <body>
     11 <h1 id="my-h1">text</h1>
     12 
     13 <iframe
     14  id="first-iframe"
     15  src="about:blank"
     16  srcdoc="
     17    <!DOCTYPE html>
     18    <html>
     19      <body id='iframe-body' contentEditable='true'>
     20        lorem ipsum
     21        <iframe
     22          id='nested-iframe'
     23          srcdoc='
     24            <html>
     25              <body id=&quot;iframe-body-2&quot; contentEditable=&quot;true&quot;>
     26                nested lorem ipsum
     27              </body>
     28            </html>'>
     29        </iframe>
     30      </body>
     31    </html>
     32  ">
     33 </iframe>
     34 
     35 <script>
     36  async_test(t => {
     37    window.onload = function() {
     38      const iframe = document.querySelector("iframe");
     39      const nestedIframe = iframe.contentDocument.getElementById("nested-iframe");
     40 
     41      nestedIframe.contentDocument.getElementById("iframe-body-2").addEventListener('focusout', () => {
     42        t.step(function() {
     43          assert_equals(
     44            nestedIframe.contentDocument.activeElement,
     45            nestedIframe.contentDocument.body,
     46            "nestedIframe should still have focus on its body");
     47          assert_equals(
     48            iframe.contentDocument.activeElement, nestedIframe,
     49            "iframe should still think the nestedIframe is focused");
     50          assert_equals(
     51            document.activeElement, iframe,
     52            "top level document should still think the iframe is focused");
     53        });
     54      });
     55 
     56      const h1 = document.getElementById("my-h1");
     57      h1.addEventListener("click", t.step_func_done(function() {
     58          assert_equals(
     59            nestedIframe.contentDocument.activeElement,
     60            nestedIframe.contentDocument.body,
     61            "nestedIframe originally has the focus on its body, and should still have the focus on its body after it loses the focus");
     62          assert_equals(
     63            iframe.contentDocument.activeElement,
     64            iframe.contentDocument.body,
     65            "Since nestedIframe loses the focus, iframe's activeElement should move from the nestedIframe to be its body"
     66          );
     67          assert_equals(
     68            document.activeElement, document.body,
     69            "top level document gains the focus");
     70      }));
     71 
     72      // Step 1: Focus the body of the nestedIframe
     73      nestedIframe.contentDocument.body.focus();
     74 
     75      // Step 2: Click focus the <h1> in the top level document
     76      test_driver.click(h1);
     77 
     78      // Now the focusout event for nestedIframe, and the
     79      // click event for h1 should be triggered.
     80    }
     81  })
     82 </script>
     83 </body>