From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../test_ext_scripting_contentScripts_file.js | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 toolkit/components/extensions/test/xpcshell/test_ext_scripting_contentScripts_file.js (limited to 'toolkit/components/extensions/test/xpcshell/test_ext_scripting_contentScripts_file.js') diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_scripting_contentScripts_file.js b/toolkit/components/extensions/test/xpcshell/test_ext_scripting_contentScripts_file.js new file mode 100644 index 0000000000..3c806439ce --- /dev/null +++ b/toolkit/components/extensions/test/xpcshell/test_ext_scripting_contentScripts_file.js @@ -0,0 +1,77 @@ +"use strict"; + +const FILE_DUMMY_URL = Services.io.newFileURI( + do_get_file("data/dummy_page.html") +).spec; + +// ExtensionContent.jsm needs to know when it's running from xpcshell, to use +// the right timeout for content scripts executed at document_idle. +ExtensionTestUtils.mockAppInfo(); + +Services.prefs.setBoolPref("extensions.manifestV3.enabled", true); + +const makeExtension = ({ manifest: manifestProps, ...otherProps }) => { + return ExtensionTestUtils.loadExtension({ + manifest: { + manifest_version: 3, + permissions: ["scripting"], + host_permissions: [""], + granted_host_permissions: true, + ...manifestProps, + }, + temporarilyInstalled: true, + ...otherProps, + }); +}; + +add_task(async function test_registered_content_script_with_files() { + let extension = makeExtension({ + async background() { + const MATCHES = [ + { id: "script-1", matches: [""] }, + { id: "script-2", matches: ["file:///*"] }, + { id: "script-3", matches: ["file://*/*dummy_page.html"] }, + { id: "fail-if-executed", matches: ["*://*/*"] }, + ]; + + await browser.scripting.registerContentScripts( + MATCHES.map(({ id, matches }) => ({ + id, + js: [`${id}.js`], + matches, + persistAcrossSessions: false, + })) + ); + + browser.test.sendMessage("background-ready"); + }, + files: { + "script-1.js": () => { + browser.test.sendMessage("script-1-ran"); + }, + "script-2.js": () => { + browser.test.sendMessage("script-2-ran"); + }, + "script-3.js": () => { + browser.test.sendMessage("script-3-ran"); + }, + "fail-if-executed.js": () => { + browser.test.fail("this script should not be executed"); + }, + }, + }); + + await extension.startup(); + await extension.awaitMessage("background-ready"); + + let contentPage = await ExtensionTestUtils.loadContentPage(FILE_DUMMY_URL); + + await Promise.all([ + extension.awaitMessage("script-1-ran"), + extension.awaitMessage("script-2-ran"), + extension.awaitMessage("script-3-ran"), + ]); + + await contentPage.close(); + await extension.unload(); +}); -- cgit v1.2.3