tor-browser

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

focus-opener.https.html (1669B)


      1 <!DOCTYPE html>
      2 <title>Test that a document picture-in-picture window can use Window's focus()
      3  API to focus its opener window</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/resources/testdriver.js"></script>
      7 <script src="/resources/testdriver-vendor.js"></script>
      8 <body>
      9  <iframe></iframe>
     10 <script>
     11 promise_test(async (t) => {
     12  // Ensure this window is blurred so that we can detect that the
     13  // document PiP window has focused us.
     14  const blurPromise = new Promise(async (resolve) => {
     15    window.addEventListener('blur', resolve, { once: true });
     16  });
     17 
     18  await test_driver.bless('request PiP window from top window');
     19  const pipWindow = await documentPictureInPicture.requestWindow();
     20 
     21  // The PiP might be focused automatically.
     22  // But to be safe that this window is blured, focus the iframe.
     23  await test_driver.bless('focus inner iframe to blur window');
     24  document.getElementsByTagName('iframe')[0].focus();
     25  await blurPromise;
     26 
     27  // Now focus this window from the document picture-in-picture window's
     28  // context.
     29  const focusPromise = new Promise(async (resolve) => {
     30    window.addEventListener('focus', resolve, { once: true });
     31    await test_driver.bless('focus opener window', pipWindow);
     32    const focusScript = pipWindow.document.createElement('script');
     33    // Resolve URI so that we don't implicitly test the base URI of the PIP
     34    const scriptURI = new URL('support/focus-opener.js', document.baseURI).href;
     35    focusScript.setAttribute('src', scriptURI);
     36    pipWindow.document.body.append(focusScript);
     37  });
     38  return focusPromise;
     39 });
     40 </script>
     41 </body>