summaryrefslogtreecommitdiffstats
path: root/devtools/client/jsonview/test/browser_json_refresh.js
blob: 0fbebbae57fda60475fa1a8ba5abbbef03cec6c8 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TEST_JSON_FILE = "simple_json.json";

add_task(async function () {
  info("Test JSON refresh started");

  // generate file:// URI for JSON file and load in new tab
  const dir = getChromeDir(getResolvedURI(gTestPath));
  dir.append(TEST_JSON_FILE);
  dir.normalize();
  const uri = Services.io.newFileURI(dir);
  const tab = await addJsonViewTab(uri.spec);

  // perform sanity checks for URI and principals in loadInfo
  await SpecialPowers.spawn(
    tab.linkedBrowser,
    [{ TEST_JSON_FILE }],
    // eslint-disable-next-line no-shadow
    async function ({ TEST_JSON_FILE }) {
      const channel = content.docShell.currentDocumentChannel;
      const channelURI = channel.URI.spec;
      ok(
        channelURI.startsWith("file://") && channelURI.includes(TEST_JSON_FILE),
        "sanity: correct channel uri"
      );
      const contentPolicyType = channel.loadInfo.externalContentPolicyType;
      is(
        contentPolicyType,
        Ci.nsIContentPolicy.TYPE_DOCUMENT,
        "sanity: correct contentPolicyType"
      );

      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.isNullPrincipal,
        "sanity: correct doc.nodePrincipal"
      );
    }
  );

  // reload the tab
  await reloadBrowser();

  // check principals in loadInfo are still correct
  await SpecialPowers.spawn(
    tab.linkedBrowser,
    [{ TEST_JSON_FILE }],
    // eslint-disable-next-line no-shadow
    async function ({ TEST_JSON_FILE }) {
      // eslint-disable-line
      const channel = content.docShell.currentDocumentChannel;
      const channelURI = channel.URI.spec;
      ok(
        channelURI.startsWith("file://") && channelURI.includes(TEST_JSON_FILE),
        "reloaded: correct channel uri"
      );
      const contentPolicyType = channel.loadInfo.externalContentPolicyType;
      is(
        contentPolicyType,
        Ci.nsIContentPolicy.TYPE_DOCUMENT,
        "reloaded: correct contentPolicyType"
      );

      const loadingPrincipal = channel.loadInfo.loadingPrincipal;
      is(loadingPrincipal, null, "reloaded: correct loadingPrincipal");
      const triggeringPrincipal = channel.loadInfo.triggeringPrincipal;
      ok(
        triggeringPrincipal.isSystemPrincipal,
        "reloaded: correct triggeringPrincipal"
      );
      const principalToInherit = channel.loadInfo.principalToInherit;
      ok(
        principalToInherit.isNullPrincipal,
        "reloaded: correct principalToInherit"
      );
      ok(
        content.document.nodePrincipal.isNullPrincipal,
        "reloaded: correct doc.nodePrincipal"
      );
    }
  );
});