tor-browser

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

browser_947914_button_newWindow.js (1830B)


      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 new window button existence and functionality");
      9  CustomizableUI.addWidgetToArea(
     10    "new-window-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 newWindow = null;
     22 
     23  let observerWindowOpened = {
     24    observe(aSubject, aTopic) {
     25      if (aTopic == "domwindowopened") {
     26        newWindow = aSubject;
     27        newWindow.addEventListener(
     28          "load",
     29          function () {
     30            is(
     31              newWindow.location.href,
     32              AppConstants.BROWSER_CHROME_URL,
     33              "A new browser window was opened"
     34            );
     35            ok(
     36              !PrivateBrowsingUtils.isWindowPrivate(newWindow),
     37              "Window is not private"
     38            );
     39            windowWasHandled = true;
     40          },
     41          { once: true }
     42        );
     43      }
     44    },
     45  };
     46 
     47  Services.ww.registerNotification(observerWindowOpened);
     48 
     49  let newWindowButton = document.getElementById("new-window-button");
     50  ok(newWindowButton, "New Window button exists in Panel Menu");
     51  newWindowButton.click();
     52 
     53  try {
     54    await TestUtils.waitForCondition(() => windowWasHandled);
     55    await promiseWindowClosed(newWindow);
     56    info("The new window was closed");
     57  } catch (e) {
     58    ok(false, "The new browser window was not properly handled");
     59  } finally {
     60    Services.ww.unregisterNotification(observerWindowOpened);
     61  }
     62 });