diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /toolkit/components/extensions/test/mochitest/test_ext_tabs_executeScript_good.html | |
parent | Initial commit. (diff) | |
download | firefox-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/mochitest/test_ext_tabs_executeScript_good.html')
-rw-r--r-- | toolkit/components/extensions/test/mochitest/test_ext_tabs_executeScript_good.html | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/toolkit/components/extensions/test/mochitest/test_ext_tabs_executeScript_good.html b/toolkit/components/extensions/test/mochitest/test_ext_tabs_executeScript_good.html new file mode 100644 index 0000000000..9b0f41f789 --- /dev/null +++ b/toolkit/components/extensions/test/mochitest/test_ext_tabs_executeScript_good.html @@ -0,0 +1,167 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Tabs executeScript Test</title> + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script> + <script type="text/javascript" src="head.js"></script> + <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> +</head> +<body> + +<script type="text/javascript"> +"use strict"; + +async function testHasPermission(params) { + let contentSetup = params.contentSetup || (() => Promise.resolve()); + + async function background(contentSetup) { + browser.runtime.onMessage.addListener((msg, sender) => { + browser.test.assertEq(msg, "script ran", "script ran"); + browser.test.notifyPass("executeScript"); + }); + + browser.test.onMessage.addListener(msg => { + browser.test.assertEq(msg, "execute-script"); + + browser.tabs.executeScript({ + file: "script.js", + }); + }); + + await contentSetup(); + + browser.test.sendMessage("ready"); + } + + let extension = ExtensionTestUtils.loadExtension({ + manifest: params.manifest, + + background: `(${background})(${contentSetup})`, + + files: { + "panel.html": `<!DOCTYPE html> + <html> + <head><meta charset="utf-8"></head> + <body> + </body> + </html>`, + "script.js": function() { + browser.runtime.sendMessage("script ran"); + }, + }, + }); + + await extension.startup(); + await extension.awaitMessage("ready"); + + if (params.setup) { + await params.setup(extension); + } + + extension.sendMessage("execute-script"); + + await extension.awaitFinish("executeScript"); + + if (params.tearDown) { + await params.tearDown(extension); + } + + await extension.unload(); +} + +add_task(async function testGoodPermissions() { + let tab = await AppTestDelegate.openNewForegroundTab( + window, + "http://mochi.test:8888/", + true + ); + + info("Test explicit host permission"); + await testHasPermission({ + manifest: { permissions: ["http://mochi.test/"] }, + }); + + info("Test explicit host subdomain permission"); + await testHasPermission({ + manifest: { permissions: ["http://*.mochi.test/"] }, + }); + + info("Test explicit <all_urls> permission"); + await testHasPermission({ + manifest: { permissions: ["<all_urls>"] }, + }); + + info("Test activeTab permission with a browser action click"); + await testHasPermission({ + manifest: { + permissions: ["activeTab"], + browser_action: {}, + }, + contentSetup: function() { + browser.browserAction.onClicked.addListener(() => { + browser.test.log("Clicked."); + }); + return Promise.resolve(); + }, + setup: extension => AppTestDelegate.clickBrowserAction(window, extension), + tearDown: extension => AppTestDelegate.closeBrowserAction(window, extension), + }); + + info("Test activeTab permission with a page action click"); + await testHasPermission({ + manifest: { + permissions: ["activeTab"], + page_action: {}, + }, + contentSetup: async () => { + let [tab] = await browser.tabs.query({ + active: true, + currentWindow: true, + }); + await browser.pageAction.show(tab.id); + }, + setup: extension => AppTestDelegate.clickPageAction(window, extension), + tearDown: extension => AppTestDelegate.closePageAction(window, extension), + }); + + info("Test activeTab permission with a browser action w/popup click"); + await testHasPermission({ + manifest: { + permissions: ["activeTab"], + browser_action: { default_popup: "panel.html" }, + }, + setup: async extension => { + let promise = AppTestDelegate.awaitExtensionPanel(window, extension); + await AppTestDelegate.clickBrowserAction(window, extension); + await promise; + }, + tearDown: extension => AppTestDelegate.closeBrowserAction(window, extension), + }); + + info("Test activeTab permission with a page action w/popup click"); + await testHasPermission({ + manifest: { + permissions: ["activeTab"], + page_action: { default_popup: "panel.html" }, + }, + contentSetup: async () => { + let [tab] = await browser.tabs.query({ + active: true, + currentWindow: true, + }); + await browser.pageAction.show(tab.id); + }, + setup: async extension => { + let promise = AppTestDelegate.awaitExtensionPanel(window, extension); + await AppTestDelegate.clickPageAction(window, extension); + await promise; + }, + tearDown: extension => AppTestDelegate.closePageAction(window, extension), + }); + + await AppTestDelegate.removeTab(window, tab); +}); +</script> +</body> +</html> |