summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/xpcshell
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:40:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:40:09 +0000
commitc1701504b2366542c32c5e6eeff1ba62cc75f8f6 (patch)
tree81b15ef2846efcdbb09422dd283399e769cb7ef9 /toolkit/components/extensions/test/xpcshell
parentReleasing progress-linux version 115.10.0esr-1~progress7.99u1. (diff)
downloadfirefox-esr-c1701504b2366542c32c5e6eeff1ba62cc75f8f6.tar.xz
firefox-esr-c1701504b2366542c32c5e6eeff1ba62cc75f8f6.zip
Merging upstream version 115.11.0esr.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--toolkit/components/extensions/test/xpcshell/test_ext_background_script_and_service_worker.js81
-rw-r--r--toolkit/components/extensions/test/xpcshell/xpcshell-common.ini1
2 files changed, 82 insertions, 0 deletions
diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_background_script_and_service_worker.js b/toolkit/components/extensions/test/xpcshell/test_ext_background_script_and_service_worker.js
new file mode 100644
index 0000000000..fc59b1810d
--- /dev/null
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_background_script_and_service_worker.js
@@ -0,0 +1,81 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+"use strict";
+
+async function testExtensionWithBackground({
+ with_scripts = false,
+ with_service_worker = false,
+ with_page = false,
+ expected_background_type,
+ expected_manifest_warnings = [],
+}) {
+ let background = {};
+ if (with_scripts) {
+ background.scripts = ["scripts.js"];
+ }
+ if (with_service_worker) {
+ background.service_worker = "sw.js";
+ }
+ if (with_page) {
+ background.page = "page.html";
+ }
+ let extension = ExtensionTestUtils.loadExtension({
+ manifest: { background },
+ files: {
+ "scripts.js": () => {
+ browser.test.sendMessage("from_bg", "scripts");
+ },
+ "sw.js": () => {
+ browser.test.sendMessage("from_bg", "service_worker");
+ },
+ "page.html": `<!DOCTYPE html><script src="page.js"></script>`,
+ "page.js": () => {
+ browser.test.sendMessage("from_bg", "page");
+ },
+ },
+ });
+ ExtensionTestUtils.failOnSchemaWarnings(false);
+ await extension.startup();
+ ExtensionTestUtils.failOnSchemaWarnings(true);
+ Assert.deepEqual(
+ extension.extension.warnings,
+ expected_manifest_warnings,
+ "Expected manifest warnings"
+ );
+ info("Waiting for background to start");
+ Assert.equal(
+ await extension.awaitMessage("from_bg"),
+ expected_background_type,
+ "Expected background type"
+ );
+ await extension.unload();
+}
+
+add_task(async function test_page_and_scripts() {
+ await testExtensionWithBackground({
+ with_page: true,
+ with_scripts: true,
+ // Should be expected_background_type: "scripts", not "page".
+ // https://github.com/w3c/webextensions/issues/282#issuecomment-1443332913
+ // ... but changing that may potentially affect backcompat of existing
+ // Firefox add-ons.
+ expected_background_type: "page",
+ expected_manifest_warnings: [
+ "Reading manifest: Warning processing background.scripts: An unexpected property was found in the WebExtension manifest.",
+ ],
+ });
+});
+
+add_task(
+ { skip_if: () => WebExtensionPolicy.backgroundServiceWorkerEnabled },
+ async function test_scripts_and_service_worker_when_sw_disabled() {
+ await testExtensionWithBackground({
+ with_scripts: true,
+ with_service_worker: true,
+ expected_background_type: "scripts",
+ expected_manifest_warnings: [
+ "Reading manifest: Warning processing background.service_worker: An unexpected property was found in the WebExtension manifest.",
+ ],
+ });
+ }
+);
diff --git a/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini b/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
index f76456124d..81beee5810 100644
--- a/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
+++ b/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
@@ -25,6 +25,7 @@ skip-if = os == "android" # Bug 1700482
skip-if = os == "android" # Android does not use Places for history.
[test_ext_background_private_browsing.js]
[test_ext_background_runtime_connect_params.js]
+[test_ext_background_script_and_service_worker.js]
[test_ext_background_sub_windows.js]
[test_ext_background_teardown.js]
[test_ext_background_telemetry.js]