tor-browser

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

browser_test_framing_error_pages.js (2286B)


      1 "use strict";
      2 
      3 const kTestPath = getRootDirectory(gTestPath).replace(
      4  "chrome://mochitests/content",
      5  "https://example.com"
      6 );
      7 const kTestXFrameOptionsURI = kTestPath + "file_framing_error_pages_xfo.html";
      8 const kTestXFrameOptionsURIFrame =
      9  kTestPath + "file_framing_error_pages.sjs?xfo";
     10 
     11 const kTestFrameAncestorsURI = kTestPath + "file_framing_error_pages_csp.html";
     12 const kTestFrameAncestorsURIFrame =
     13  kTestPath + "file_framing_error_pages.sjs?csp";
     14 
     15 add_task(async function open_test_xfo_error_page() {
     16  await BrowserTestUtils.withNewTab("about:blank", async function (browser) {
     17    let loaded = BrowserTestUtils.browserLoaded(
     18      browser,
     19      true,
     20      kTestXFrameOptionsURIFrame,
     21      true
     22    );
     23    BrowserTestUtils.startLoadingURIString(browser, kTestXFrameOptionsURI);
     24    await loaded;
     25 
     26    await SpecialPowers.spawn(browser, [], async function () {
     27      const getErrorPage = async () =>
     28        ContentTaskUtils.waitForCondition(
     29          () =>
     30            content.document.getElementById("testframe").contentDocument?.body
     31              .innerHTML
     32        );
     33      await ContentTaskUtils.waitForCondition(() =>
     34        getErrorPage()?.then(p => p.includes("csp-xfo-error-title"))
     35      );
     36      const errorPage = await getErrorPage();
     37      ok(errorPage.includes("csp-xfo-error-title"), "xfo error page correct");
     38    });
     39  });
     40 });
     41 
     42 add_task(async function open_test_csp_frame_ancestor_error_page() {
     43  await BrowserTestUtils.withNewTab("about:blank", async function (browser) {
     44    let loaded = BrowserTestUtils.browserLoaded(
     45      browser,
     46      true,
     47      kTestFrameAncestorsURIFrame,
     48      true
     49    );
     50    BrowserTestUtils.startLoadingURIString(browser, kTestFrameAncestorsURI);
     51    await loaded;
     52 
     53    await SpecialPowers.spawn(browser, [], async function () {
     54      const getErrorPage = async () =>
     55        ContentTaskUtils.waitForCondition(
     56          () =>
     57            content.document.getElementById("testframe").contentDocument?.body
     58              .innerHTML
     59        );
     60      await ContentTaskUtils.waitForCondition(() =>
     61        getErrorPage()?.then(p => p.includes("csp-xfo-error-title"))
     62      );
     63      const errorPage = await getErrorPage();
     64      ok(errorPage.includes("csp-xfo-error-title"), "csp error page correct");
     65    });
     66  });
     67 });