summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/xpcshell/test_ext_xhr_capabilities.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /toolkit/components/extensions/test/xpcshell/test_ext_xhr_capabilities.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/extensions/test/xpcshell/test_ext_xhr_capabilities.js')
-rw-r--r--toolkit/components/extensions/test/xpcshell/test_ext_xhr_capabilities.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_xhr_capabilities.js b/toolkit/components/extensions/test/xpcshell/test_ext_xhr_capabilities.js
new file mode 100644
index 0000000000..0728946817
--- /dev/null
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_xhr_capabilities.js
@@ -0,0 +1,72 @@
+"use strict";
+
+const server = createHttpServer({ hosts: ["example.com"] });
+server.registerDirectory("/data/", do_get_file("data"));
+
+add_task(async function test_xhr_capabilities() {
+ let extension = ExtensionTestUtils.loadExtension({
+ background() {
+ let xhr = new XMLHttpRequest();
+ xhr.open("GET", browser.runtime.getURL("bad.xml"));
+
+ browser.test.sendMessage("result", {
+ name: "Background script XHRs should not be privileged",
+ result: xhr.channel === undefined,
+ });
+
+ xhr.onload = () => {
+ browser.test.sendMessage("result", {
+ name: "Background script XHRs should not yield <parsererrors>",
+ result: xhr.responseXML === null,
+ });
+ };
+ xhr.send();
+ },
+
+ manifest: {
+ content_scripts: [
+ {
+ matches: ["http://example.com/data/file_sample.html"],
+ js: ["content_script.js"],
+ },
+ ],
+ web_accessible_resources: ["bad.xml"],
+ },
+
+ files: {
+ "bad.xml": "<xml",
+ "content_script.js"() {
+ let xhr = new XMLHttpRequest();
+ xhr.open("GET", browser.runtime.getURL("bad.xml"));
+
+ browser.test.sendMessage("result", {
+ name: "Content script XHRs should not be privileged",
+ result: xhr.channel === undefined,
+ });
+
+ xhr.onload = () => {
+ browser.test.sendMessage("result", {
+ name: "Content script XHRs should not yield <parsererrors>",
+ result: xhr.responseXML === null,
+ });
+ };
+ xhr.send();
+ },
+ },
+ });
+
+ await extension.startup();
+
+ let contentPage = await ExtensionTestUtils.loadContentPage(
+ "http://example.com/data/file_sample.html"
+ );
+
+ // We expect four test results from the content/background scripts.
+ for (let i = 0; i < 4; ++i) {
+ let result = await extension.awaitMessage("result");
+ ok(result.result, result.name);
+ }
+
+ await contentPage.close();
+ await extension.unload();
+});