summaryrefslogtreecommitdiffstats
path: root/dom/security/test/general/browser_test_framing_error_pages.js
blob: 16e67eb702b7a63d0d680a9cfe32bf533444577c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"use strict";

const kTestPath = getRootDirectory(gTestPath).replace(
  "chrome://mochitests/content",
  "https://example.com"
);
const kTestXFrameOptionsURI = kTestPath + "file_framing_error_pages_xfo.html";
const kTestXFrameOptionsURIFrame =
  kTestPath + "file_framing_error_pages.sjs?xfo";

const kTestFrameAncestorsURI = kTestPath + "file_framing_error_pages_csp.html";
const kTestFrameAncestorsURIFrame =
  kTestPath + "file_framing_error_pages.sjs?csp";

add_task(async function open_test_xfo_error_page() {
  await BrowserTestUtils.withNewTab("about:blank", async function (browser) {
    let loaded = BrowserTestUtils.browserLoaded(
      browser,
      true,
      kTestXFrameOptionsURIFrame,
      true
    );
    BrowserTestUtils.loadURIString(browser, kTestXFrameOptionsURI);
    await loaded;

    await SpecialPowers.spawn(browser, [], async function () {
      const iframeDoc =
        content.document.getElementById("testframe").contentDocument;
      let errorPage = iframeDoc.body.innerHTML;
      ok(errorPage.includes("csp-xfo-error-title"), "xfo error page correct");
    });
  });
});

add_task(async function open_test_csp_frame_ancestor_error_page() {
  await BrowserTestUtils.withNewTab("about:blank", async function (browser) {
    let loaded = BrowserTestUtils.browserLoaded(
      browser,
      true,
      kTestFrameAncestorsURIFrame,
      true
    );
    BrowserTestUtils.loadURIString(browser, kTestFrameAncestorsURI);
    await loaded;

    await SpecialPowers.spawn(browser, [], async function () {
      const iframeDoc =
        content.document.getElementById("testframe").contentDocument;
      let errorPage = iframeDoc.body.innerHTML;
      ok(errorPage.includes("csp-xfo-error-title"), "csp error page correct");
    });
  });
});