summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/contextMenu/browser_utilityOverlayPrincipal.js
blob: 5b8252b97342570d82aa49cb1f97761248137dae (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* This Source Code Form is subject to the terms of the Mozilla Public
 *  License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const gTests = [test_openUILink_checkPrincipal];

function test() {
  waitForExplicitFinish();
  executeSoon(runNextTest);
}

function runNextTest() {
  if (gTests.length) {
    let testFun = gTests.shift();
    info("Running " + testFun.name);
    testFun();
  } else {
    finish();
  }
}

function test_openUILink_checkPrincipal() {
  let tab = (gBrowser.selectedTab = BrowserTestUtils.addTab(
    gBrowser,
    // eslint-disable-next-line @microsoft/sdl/no-insecure-url
    "http://example.com/"
  )); // remote tab
  BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(async function () {
    is(
      tab.linkedBrowser.currentURI.spec,
      // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      "http://example.com/",
      "example.com loaded"
    );

    await SpecialPowers.spawn(tab.linkedBrowser, [], function () {
      let channel = content.docShell.currentDocumentChannel;

      const loadingPrincipal = channel.loadInfo.loadingPrincipal;
      is(loadingPrincipal, null, "sanity: correct loadingPrincipal");
      const triggeringPrincipal = channel.loadInfo.triggeringPrincipal;
      ok(
        triggeringPrincipal.isSystemPrincipal,
        "sanity: correct triggeringPrincipal"
      );
      const principalToInherit = channel.loadInfo.principalToInherit;
      ok(
        principalToInherit.isNullPrincipal,
        "sanity: correct principalToInherit"
      );
      ok(
        content.document.nodePrincipal.isContentPrincipal,
        "sanity: correct doc.nodePrincipal"
      );
      is(
        content.document.nodePrincipal.asciiSpec,
        // eslint-disable-next-line @microsoft/sdl/no-insecure-url
        "http://example.com/",
        "sanity: correct doc.nodePrincipal URL"
      );
    });

    gBrowser.removeCurrentTab();
    runNextTest();
  });

  // Ensure we get the correct default of "allowInheritPrincipal: false" from openUILink
  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
  openUILink("http://example.com", null, {
    triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal({}),
  }); // defaults to "current"
}