tor-browser

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

activeelement-after-focusing-different-site-iframe-then-immediately-focusing-back.html (1818B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>activeElement when focusing different-site iframe then immediately focusing back</title>
      4 <script src=/resources/testharness.js></script>
      5 <script src=/resources/testharnessreport.js></script>
      6 <script>
      7 function waitForEvent(target, event, checkFn) {
      8  return new Promise(resolve => {
      9    target.addEventListener(event, e => {
     10      if (checkFn && !checkFn(e)) {
     11        return;
     12      }
     13      resolve();
     14    }, { once: true });
     15  });
     16 }
     17 
     18 // This will send message to outer frame and also inner frame to ask them
     19 // send the log they collect back, the logs of outer and inner will be
     20 // concatenated.
     21 async function getLog(w) {
     22  let log = "";
     23  step_timeout(function() {
     24    w.postMessage("getlog", "*");
     25  }, 0);
     26  await waitForEvent(window, "message", (e) => {
     27    log = e.data;
     28    return true;
     29  });
     30  return log;
     31 }
     32 
     33 // This will send message to outer frame to ask it's activeElement.
     34 async function getActiveElement(w) {
     35  let activeElement = "";
     36  step_timeout(function() {
     37    w.postMessage("getActiveElement", "*");
     38  }, 0);
     39  await waitForEvent(window, "message", (e) => {
     40    activeElement = e.data;
     41    return true;
     42  });
     43  return activeElement;
     44 }
     45 
     46 promise_test(async t => {
     47  let w = window.open("support/activeelement-after-focusing-different-site-iframe-then-immediately-focusing-back-outer.sub.html");
     48  t.add_cleanup(() => { w.close(); });
     49  await waitForEvent(window, "message", e => e.data === "ready");
     50  w.postMessage("focus", "*");
     51  assert_equals(await getLog(w), 'outerlog:willfocusiframe,didfocusiframe,willfocusinput,inputfocus,didfocusinput,innerlog:windowfocus,windowblur,');
     52  assert_equals(await getActiveElement(w), 'INPUT');
     53 }, "Check focus event and active element after focusing different site iframe then immediately focusing back");
     54 </script>