tor-browser

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

browser_aboutNetError_xfo_iframe.js (2392B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const BLOCKED_PAGE =
      7  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      8  "http://example.org:8000/browser/browser/base/content/test/about/xfo_iframe.sjs";
      9 
     10 add_task(async function test_csp() {
     11  let iFramePage =
     12    getRootDirectory(gTestPath).replace(
     13      "chrome://mochitests/content",
     14      // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     15      "http://example.com"
     16    ) + "iframe_page_xfo.html";
     17 
     18  // Opening the page that contains the iframe
     19  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
     20  let browser = tab.linkedBrowser;
     21  let browserLoaded = BrowserTestUtils.browserLoaded(
     22    browser,
     23    true,
     24    BLOCKED_PAGE,
     25    true
     26  );
     27 
     28  BrowserTestUtils.startLoadingURIString(browser, iFramePage);
     29  await browserLoaded;
     30  info("The error page has loaded!");
     31 
     32  await SpecialPowers.spawn(browser, [], async function () {
     33    let iframe = content.document.getElementById("theIframe");
     34 
     35    await ContentTaskUtils.waitForCondition(() =>
     36      SpecialPowers.spawn(iframe, [], () =>
     37        content.document.body.classList.contains("neterror")
     38      )
     39    );
     40  });
     41 
     42  let iframe = browser.browsingContext.children[0];
     43 
     44  // In the iframe, we see the correct error page
     45  await SpecialPowers.spawn(iframe, [], async function () {
     46    let doc = content.document;
     47 
     48    // aboutNetError.mjs is using async localization to format several
     49    // messages and in result the translation may be applied later.
     50    // We want to return the textContent of the element only after
     51    // the translation completes, so let's wait for it here.
     52    let elements = [doc.getElementById("errorLongDesc")];
     53    await ContentTaskUtils.waitForCondition(() => {
     54      return elements.every(elem => !!elem.textContent.trim().length);
     55    });
     56 
     57    let textLongDescription = doc.getElementById("errorLongDesc").textContent;
     58    let learnMoreLinkLocation = doc.getElementById("learnMoreLink").href;
     59 
     60    Assert.ok(
     61      textLongDescription.includes(
     62        "To see this page, you need to open it in a new window."
     63      ),
     64      "Correct error message found"
     65    );
     66 
     67    Assert.ok(
     68      learnMoreLinkLocation.includes("xframe-neterror-page"),
     69      "Correct Learn More URL for XFO error page"
     70    );
     71  });
     72 
     73  BrowserTestUtils.removeTab(tab);
     74 });