tor-browser

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

focus-event-after-focusing-iframes.html (1767B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>Test focus event after focusing iframe</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 function start(w) {
     19  w.postMessage("start", "*");
     20 }
     21 
     22 function focusIframe(w) {
     23  w.postMessage("focus", "*");
     24 }
     25 
     26 // This will send message to outer frame and also inner frame to ask them
     27 // send the log they collect back, the logs of outer and inner will be
     28 // concatenated.
     29 async function getLog(w) {
     30  let log = "";
     31  step_timeout(function() {
     32    w.postMessage("getlog", "*");
     33  }, 0);
     34  await waitForEvent(window, "message", (e) => {
     35    log = e.data;
     36    return true;
     37  });
     38  return log;
     39 }
     40 
     41 async function runTest(t, url) {
     42  let w = window.open(url);
     43  t.add_cleanup(() => { w.close(); });
     44  await waitForEvent(window, "message", e => e.data === "ready");
     45  start(w);
     46  focusIframe(w);
     47  assert_equals(await getLog(w), 'outerlog:willfocusiframe,windowblur,didfocusiframe,innerlog:windowfocus,');
     48  focusIframe(w);
     49  assert_equals(await getLog(w), 'outerlog:willfocusiframe,windowblur,didfocusiframe,willfocusiframe,didfocusiframe,innerlog:windowfocus,');
     50 }
     51 
     52 promise_test(async t => {
     53  await runTest(t, "support/focus-event-after-focusing-different-site-iframes-outer.sub.html");
     54 }, "Check focus event after focusing different site iframe");
     55 
     56 promise_test(async t => {
     57  await runTest(t, "support/focus-event-after-focusing-same-site-iframes-outer.html");
     58 }, "Check focus event after focusing same site iframe");
     59 
     60 </script>