summaryrefslogtreecommitdiffstats
path: root/dom/security/test/general/browser_test_assert_systemprincipal_documents.js
blob: 25fb2db7355d2652b4b2a6c3d3a90acbf747f163 (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
//"use strict"

const kTestPath = getRootDirectory(gTestPath);
const kTestURI = kTestPath + "file_assert_systemprincipal_documents.html";

add_task(async function setup() {
  // We expect the assertion in function
  // CheckSystemPrincipalLoads as defined in
  // file dom/security/nsContentSecurityManager.cpp
  SimpleTest.expectAssertions(1);

  await SpecialPowers.pushPrefEnv({
    set: [
      ["security.disallow_non_local_systemprincipal_in_tests", true],
      ["security.allow_unsafe_parent_loads", true],
    ],
  });
});

add_task(async function open_test_iframe_in_tab() {
  // This looks at the iframe (load type SUBDOCUMENT)
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: kTestURI },
    async browser => {
      await SpecialPowers.spawn(browser, [], async function() {
        let outerPrincipal = content.document.nodePrincipal;
        ok(
          outerPrincipal.isSystemPrincipal,
          "Sanity: Using SystemPrincipal for test file on chrome://"
        );
        const iframeDoc = content.document.getElementById("testframe")
          .contentDocument;
        is(
          iframeDoc.body.innerHTML,
          "",
          "iframe with systemprincipal should be empty document"
        );
      });
    }
  );
});