From a90a5cba08fdf6c0ceb95101c275108a152a3aed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:35:37 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- .../mochitest/test_ext_subframes_privileges.html | 67 ++++++++++++++++------ 1 file changed, 50 insertions(+), 17 deletions(-) (limited to 'toolkit/components/extensions/test/mochitest/test_ext_subframes_privileges.html') diff --git a/toolkit/components/extensions/test/mochitest/test_ext_subframes_privileges.html b/toolkit/components/extensions/test/mochitest/test_ext_subframes_privileges.html index f791d08602..0586275808 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_subframes_privileges.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_subframes_privileges.html @@ -14,6 +14,32 @@ "use strict"; /* eslint-disable mozilla/balanced-listeners */ +const { + WebExtensionPolicy, +} = SpecialPowers.Cu.getGlobalForObject(SpecialPowers.Services); + + +// Some tests load non-moz-extension:-URLs in their extension document. When +// extensions run in-process (extensions.webextensions.remote set to false), +// that fails. +// For details, see: https://bugzilla.mozilla.org/show_bug.cgi?id=1724099 and +// the same function in toolkit/components/extensions/test/xpcshell/head.js +async function allow_unsafe_parent_loads_when_extensions_not_remote() { + if (!WebExtensionPolicy.useRemoteWebExtensions) { + await SpecialPowers.pushPrefEnv({ + set: [["security.allow_unsafe_parent_loads", true]], + }); + } +} + +async function revert_allow_unsafe_parent_loads_when_extensions_not_remote() { + if (!WebExtensionPolicy.useRemoteWebExtensions) { + // Assume that the previous call to pushPrefEnv was from + // allow_unsafe_parent_loads_when_extensions_not_remote. + await SpecialPowers.popPrefEnv(); + } +} + add_task(async function test_webext_tab_subframe_privileges() { function background() { browser.runtime.onMessage.addListener(async ({msg, success, tabId, error}) => { @@ -198,19 +224,25 @@ add_task(async function test_webext_contentscript_iframe_subframe_privileges() { }); add_task(async function test_webext_background_remote_subframe_privileges() { - function backgroundSubframeScript() { + // file_remote_frame.html is opened at the same origin as this test page. + document.cookie = "cookie=monster"; + + function backgroundScript() { window.addEventListener("message", evt => { - browser.test.assertEq("http://mochi.test:8888", evt.origin, "postmessage origin ok"); + browser.test.assertTrue( + evt.origin === "http://mochi.test:8888" || + evt.origin === "https://mochi.test:8888", // using https-first, http2/http3 server. + `postmessage origin ok: ${evt.origin}` + ); browser.test.assertFalse(evt.data.tabs, "remote frame cannot access webextension APIs"); browser.test.assertEq("cookie=monster", evt.data.cookie, "Expected cookie value"); browser.test.notifyPass("webext-background-subframe-privileges"); }, {once: true}); - browser.cookies.set({url: "http://mochi.test:8888", name: "cookie", "value": "monster"}); } let extensionData = { manifest: { - permissions: ["cookies", "*://mochi.test/*", "tabs"], + permissions: ["*://mochi.test/*", "tabs"], background: { page: "background.html", }, @@ -219,32 +251,32 @@ add_task(async function test_webext_background_remote_subframe_privileges() { "background.html": ` -