tor-browser

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

browser_pip_closes_once.js (1446B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * See https://wicg.github.io/document-picture-in-picture/
      8 * When the PiP document is destroyed, we should run
      9 * #close-any-associated-document-picture-in-picture-windows.
     10 * But that usually means the PiP is going away, so if we aren't careful
     11 * we might dispatch DOMWindowClose twice.
     12 */
     13 add_task(async function closing_pip_sends_exactly_one_DOMWindowClosed() {
     14  const [tab, chromePiP] = await newTabWithPiP();
     15 
     16  // Note: Counting DOMWindowClose in the parent process isn't the same.
     17  // - The parent might have multiple, i.e. for closing tab and native window
     18  // - Sending the second event up to the parent might fail if closing has progressed far enough
     19  await SpecialPowers.spawn(chromePiP.gBrowser.selectedBrowser, [], () => {
     20    content.opener.closeCount = 0;
     21    SpecialPowers.addChromeEventListener(
     22      "DOMWindowClose",
     23      () => content.opener.closeCount++,
     24      true,
     25      false
     26    );
     27  });
     28 
     29  // close PiP
     30  await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
     31    content.documentPictureInPicture.window.close();
     32  });
     33  await BrowserTestUtils.windowClosed(chromePiP);
     34 
     35  const closeCount = await SpecialPowers.spawn(
     36    tab.linkedBrowser,
     37    [],
     38    () => content.closeCount
     39  );
     40  is(closeCount, 1, "Received a single DOMWindowClosed");
     41 
     42  BrowserTestUtils.removeTab(tab);
     43 });