tor-browser

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

browser_947914_button_newPrivateWindow.js (1905B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 add_task(async function () {
      8  info("Check private browsing button existence and functionality");
      9  CustomizableUI.addWidgetToArea(
     10    "privatebrowsing-button",
     11    CustomizableUI.AREA_FIXED_OVERFLOW_PANEL
     12  );
     13  registerCleanupFunction(() => CustomizableUI.reset());
     14 
     15  await waitForOverflowButtonShown();
     16 
     17  await document.getElementById("nav-bar").overflowable.show();
     18  info("Menu panel was opened");
     19 
     20  let windowWasHandled = false;
     21  let privateWindow = null;
     22 
     23  let observerWindowOpened = {
     24    observe(aSubject, aTopic) {
     25      if (aTopic == "domwindowopened") {
     26        privateWindow = aSubject;
     27        privateWindow.addEventListener(
     28          "load",
     29          function () {
     30            is(
     31              privateWindow.location.href,
     32              AppConstants.BROWSER_CHROME_URL,
     33              "A new browser window was opened"
     34            );
     35            ok(
     36              PrivateBrowsingUtils.isWindowPrivate(privateWindow),
     37              "Window is private"
     38            );
     39            windowWasHandled = true;
     40          },
     41          { once: true }
     42        );
     43      }
     44    },
     45  };
     46 
     47  Services.ww.registerNotification(observerWindowOpened);
     48 
     49  let privateBrowsingButton = document.getElementById("privatebrowsing-button");
     50  ok(privateBrowsingButton, "Private browsing button exists in Panel Menu");
     51  privateBrowsingButton.click();
     52 
     53  try {
     54    await TestUtils.waitForCondition(() => windowWasHandled);
     55    await promiseWindowClosed(privateWindow);
     56    info("The new private window was closed");
     57  } catch (e) {
     58    ok(false, "The new private browser window was not properly handled");
     59  } finally {
     60    Services.ww.unregisterNotification(observerWindowOpened);
     61  }
     62 });