tor-browser

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

browser_about_blank_same_document_tabswitch.js (2656B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 ChromeUtils.defineESModuleGetters(this, {
      7  UrlbarTestUtils: "resource://testing-common/UrlbarTestUtils.sys.mjs",
      8 });
      9 
     10 const TEST_PATH = getRootDirectory(gTestPath).replace(
     11  "chrome://mochitests/content",
     12  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     13  "http://example.org"
     14 );
     15 
     16 const TEST_PAGE = TEST_PATH + "open-self-from-frame.html";
     17 
     18 add_task(async function test_identityBlock_inherited_blank() {
     19  await BrowserTestUtils.withNewTab("https://example.com", async browser => {
     20    let identityBox = document.getElementById("identity-box");
     21    // Ensure we remove the 3rd party storage permission for example.org, or
     22    // it'll mess up other tests:
     23    let principal = browser.contentPrincipal;
     24    registerCleanupFunction(() => {
     25      Services.perms.removeFromPrincipal(
     26        principal,
     27        "3rdPartyStorage^http://example.org"
     28      );
     29    });
     30    is(
     31      identityBox.className,
     32      "verifiedDomain",
     33      "Should indicate a secure site."
     34    );
     35    // Open a popup from the web content.
     36    let popupPromise = BrowserTestUtils.waitForNewWindow();
     37    await SpecialPowers.spawn(browser, [TEST_PAGE], testPage => {
     38      content.open(testPage, "_blank", "height=300,width=300");
     39    });
     40    // Open a tab back in the main window:
     41    let popup = await popupPromise;
     42    info("Opened popup");
     43    let popupBC = popup.gBrowser.selectedBrowser.browsingContext;
     44    await TestUtils.waitForCondition(
     45      () => popupBC.children[0]?.currentWindowGlobal
     46    );
     47 
     48    info("Waiting for button to appear");
     49    await SpecialPowers.spawn(popupBC.children[0], [], async () => {
     50      await ContentTaskUtils.waitForCondition(() =>
     51        content.document.querySelector("button")
     52      );
     53    });
     54 
     55    info("Got frame contents.");
     56 
     57    let otherTabPromise = BrowserTestUtils.waitForLocationChange(
     58      gBrowser,
     59      TEST_PAGE
     60    );
     61    info("Clicking button");
     62    await BrowserTestUtils.synthesizeMouseAtCenter(
     63      "button",
     64      {},
     65      popupBC.children[0]
     66    );
     67    info("Waiting for tab");
     68    await otherTabPromise;
     69 
     70    ok(
     71      gURLBar.value.startsWith(
     72        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     73        UrlbarTestUtils.trimURL("http://example.org/")
     74      ),
     75      "URL bar value should be correct, was " + gURLBar.value
     76    );
     77    is(
     78      identityBox.className,
     79      "unknownIdentity",
     80      "Identity box should have been updated."
     81    );
     82 
     83    await BrowserTestUtils.removeTab(gBrowser.selectedTab);
     84    await BrowserTestUtils.closeWindow(popup);
     85  });
     86 });