tor-browser

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

browser_resources_last_private_context_exit.js (2757B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Verify that LAST_PRIVATE_CONTEXT_EXIT fires when closing the last opened private window
      5 
      6 "use strict";
      7 
      8 const NON_PRIVATE_TEST_URI =
      9  "data:text/html;charset=utf8,<!DOCTYPE html>Not private";
     10 const PRIVATE_TEST_URI = `data:text/html;charset=utf8,<!DOCTYPE html>Test in private windows`;
     11 
     12 add_task(async function () {
     13  await pushPref("devtools.browsertoolbox.scope", "everything");
     14  const { commands } = await initMultiProcessResourceCommand();
     15  const { resourceCommand } = commands;
     16 
     17  const availableResources = [];
     18  await resourceCommand.watchResources(
     19    [resourceCommand.TYPES.LAST_PRIVATE_CONTEXT_EXIT],
     20    {
     21      onAvailable(resources) {
     22        availableResources.push(resources);
     23      },
     24    }
     25  );
     26  is(
     27    availableResources.length,
     28    0,
     29    "We do not get any LAST_PRIVATE_CONTEXT_EXIT after initialization"
     30  );
     31 
     32  await addTab(NON_PRIVATE_TEST_URI);
     33 
     34  info("Open a new private window and select the new tab opened in it");
     35  const privateWindow = await BrowserTestUtils.openNewBrowserWindow({
     36    private: true,
     37  });
     38  ok(PrivateBrowsingUtils.isWindowPrivate(privateWindow), "window is private");
     39  const privateBrowser = privateWindow.gBrowser;
     40  privateBrowser.selectedTab = BrowserTestUtils.addTab(
     41    privateBrowser,
     42    PRIVATE_TEST_URI
     43  );
     44 
     45  info("private tab opened");
     46  ok(
     47    PrivateBrowsingUtils.isBrowserPrivate(privateBrowser.selectedBrowser),
     48    "tab window is private"
     49  );
     50 
     51  info("Open a second tab in the private window");
     52  await addTab(PRIVATE_TEST_URI, { window: privateWindow });
     53 
     54  // Let a chance to an unexpected async event to be fired
     55  await wait(1000);
     56 
     57  is(
     58    availableResources.length,
     59    0,
     60    "We do not get any LAST_PRIVATE_CONTEXT_EXIT when opening a private window"
     61  );
     62 
     63  info("Open a second private browsing window");
     64  const secondPrivateWindow = await BrowserTestUtils.openNewBrowserWindow({
     65    private: true,
     66  });
     67 
     68  info("Close the second private window");
     69  secondPrivateWindow.BrowserCommands.tryToCloseWindow();
     70 
     71  // Let a chance to an unexpected async event to be fired
     72  await wait(1000);
     73 
     74  is(
     75    availableResources.length,
     76    0,
     77    "We do not get any LAST_PRIVATE_CONTEXT_EXIT when closing the second private window only"
     78  );
     79 
     80  info(
     81    "close the private window and check if LAST_PRIVATE_CONTEXT_EXIT resource is sent"
     82  );
     83  privateWindow.BrowserCommands.tryToCloseWindow();
     84 
     85  info("Wait for LAST_PRIVATE_CONTEXT_EXIT");
     86  await waitFor(() => availableResources.length == 1);
     87  is(
     88    availableResources.length,
     89    1,
     90    "We get one LAST_PRIVATE_CONTEXT_EXIT when closing the last opened private window"
     91  );
     92 
     93  await commands.destroy();
     94 });