tor-browser

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

browser_popup_close_main_window.js (2530B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Check that if we close the 1 remaining window, we treat it as quitting on
      8 * non-mac.
      9 *
     10 * Sets the window type for the main browser test window to something else to
     11 * avoid having to actually close the main browser window.
     12 */
     13 add_task(async function closing_last_window_equals_quitting() {
     14  if (navigator.platform.startsWith("Mac")) {
     15    ok(true, "Not testing on mac");
     16    return;
     17  }
     18 
     19  BrowserTestUtils.concealWindow(window, { signal: testSignal });
     20 
     21  let observed = 0;
     22  function obs() {
     23    observed++;
     24  }
     25  Services.obs.addObserver(obs, "browser-lastwindow-close-requested");
     26  let newWin = await BrowserTestUtils.openNewBrowserWindow();
     27  let closedPromise = BrowserTestUtils.windowClosed(newWin);
     28  newWin.BrowserCommands.tryToCloseWindow();
     29  await closedPromise;
     30  is(observed, 1, "Got a notification for closing the normal window.");
     31  Services.obs.removeObserver(obs, "browser-lastwindow-close-requested");
     32 });
     33 
     34 /**
     35 * Check that if we close the 1 remaining window and also have a popup open,
     36 * we don't treat it as quitting.
     37 *
     38 * Sets the window type for the main browser test window to something else to
     39 * avoid having to actually close the main browser window.
     40 */
     41 add_task(async function closing_last_window_equals_quitting() {
     42  if (navigator.platform.startsWith("Mac")) {
     43    ok(true, "Not testing on mac");
     44    return;
     45  }
     46 
     47  BrowserTestUtils.concealWindow(window, { signal: testSignal });
     48  let observed = 0;
     49  function obs() {
     50    observed++;
     51  }
     52  Services.obs.addObserver(obs, "browser-lastwindow-close-requested");
     53  let newWin = await BrowserTestUtils.openNewBrowserWindow();
     54  let popupPromise = BrowserTestUtils.waitForNewWindow("https://example.com/");
     55  SpecialPowers.spawn(newWin.gBrowser.selectedBrowser, [], function () {
     56    content.open("https://example.com/", "_blank", "height=500");
     57  });
     58  let popupWin = await popupPromise;
     59  let closedPromise = BrowserTestUtils.windowClosed(newWin);
     60  newWin.BrowserCommands.tryToCloseWindow();
     61  await closedPromise;
     62  is(observed, 0, "Got no notification for closing the normal window.");
     63 
     64  closedPromise = BrowserTestUtils.windowClosed(popupWin);
     65  popupWin.BrowserCommands.tryToCloseWindow();
     66  await closedPromise;
     67  is(
     68    observed,
     69    0,
     70    "Got no notification now that we're closing the last window, as it's a popup."
     71  );
     72  Services.obs.removeObserver(obs, "browser-lastwindow-close-requested");
     73 });