summaryrefslogtreecommitdiffstats
path: root/devtools/client/jsonview/test/browser_json_refresh.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/client/jsonview/test/browser_json_refresh.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/jsonview/test/browser_json_refresh.js')
-rw-r--r--devtools/client/jsonview/test/browser_json_refresh.js97
1 files changed, 97 insertions, 0 deletions
diff --git a/devtools/client/jsonview/test/browser_json_refresh.js b/devtools/client/jsonview/test/browser_json_refresh.js
new file mode 100644
index 0000000000..0fbebbae57
--- /dev/null
+++ b/devtools/client/jsonview/test/browser_json_refresh.js
@@ -0,0 +1,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"
+ );
+ }
+ );
+});