From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:35:49 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- .../extensions/test/browser/browser.toml | 1 - .../browser_ext_extension_page_tab_navigated.js | 37 +---- .../test/browser/browser_ext_themes_ntp_colors.js | 95 ++++++++--- .../browser_ext_themes_ntp_colors_perwindow.js | 8 + .../test/browser/browser_ext_themes_pbm.js | 2 +- .../browser/browser_ext_themes_sanitization.js | 5 +- .../test/browser/browser_ext_themes_separators.js | 7 +- .../test/mochitest/test_check_startupcache.html | 2 +- .../test/mochitest/test_ext_async_clipboard.html | 4 +- .../test_ext_contentscript_securecontext.html | 2 + .../test/mochitest/test_ext_runtime_connect.html | 1 + .../test/mochitest/test_ext_runtime_connect2.html | 1 + .../mochitest/test_ext_runtime_connect_iframe.html | 6 + .../test/mochitest/test_ext_tabs_captureTab.html | 135 ++++++++++++++++ .../test/mochitest/test_ext_tabs_sendMessage.html | 180 +++++++++++++++++++++ .../extensions/test/mochitest/test_ext_test.html | 2 +- .../extensions/test/xpcshell/test_csp_validator.js | 4 +- .../test_ext_adoption_with_private_field_xrays.js | 2 +- .../test/xpcshell/test_ext_adoption_with_xrays.js | 2 +- .../xpcshell/test_ext_clear_cached_resources.js | 2 +- .../test_ext_contentscript_dynamic_registration.js | 2 +- .../test_ext_contentscript_triggeringPrincipal.js | 2 +- .../test_ext_contentscript_xorigin_frame.js | 6 + .../test/xpcshell/test_ext_contentscript_xrays.js | 2 +- .../test/xpcshell/test_ext_contexts_gc.js | 2 +- .../test/xpcshell/test_ext_dnr_modifyHeaders.js | 1 + .../test/xpcshell/test_ext_file_access.js | 2 +- .../extensions/test/xpcshell/test_ext_i18n.js | 2 +- .../extensions/test/xpcshell/test_ext_ipcBlob.js | 2 +- .../test/xpcshell/test_ext_permissions.js | 49 +++++- .../test/xpcshell/test_ext_permissions_api.js | 1 + .../test/xpcshell/test_ext_proxy_onauthrequired.js | 2 +- .../test_ext_schemas_manifest_permissions.js | 8 +- .../test/xpcshell/test_ext_schemas_privileged.js | 2 +- .../xpcshell/test_ext_scripting_contentScripts.js | 2 +- .../test_ext_scripting_contentScripts_css.js | 2 +- .../test_ext_scripting_contentScripts_file.js | 2 +- .../test_ext_scripting_updateContentScripts.js | 2 +- .../extensions/test/xpcshell/test_ext_shadowdom.js | 2 +- .../test/xpcshell/test_ext_userScripts.js | 2 +- .../test/xpcshell/test_ext_webRequest_auth.js | 18 ++- .../xpcshell/test_ext_webRequest_permission.js | 21 ++- .../test/xpcshell/test_load_all_api_modules.js | 5 +- .../test/xpcshell/test_native_manifests.js | 2 +- .../test/xpcshell/test_webRequest_ancestors.js | 2 +- .../test/xpcshell/test_webRequest_cookies.js | 2 +- .../test/xpcshell/test_webRequest_filtering.js | 2 +- .../extensions/test/xpcshell/xpcshell-common.toml | 10 +- 48 files changed, 551 insertions(+), 104 deletions(-) (limited to 'toolkit/components/extensions/test') diff --git a/toolkit/components/extensions/test/browser/browser.toml b/toolkit/components/extensions/test/browser/browser.toml index 33d54bddc2..33a3a6dc64 100644 --- a/toolkit/components/extensions/test/browser/browser.toml +++ b/toolkit/components/extensions/test/browser/browser.toml @@ -9,7 +9,6 @@ support-files = [ ["browser_ext_downloads_filters.js"] ["browser_ext_downloads_referrer.js"] -https_first_disabled = true ["browser_ext_eventpage_disableResetIdleForTest.js"] diff --git a/toolkit/components/extensions/test/browser/browser_ext_extension_page_tab_navigated.js b/toolkit/components/extensions/test/browser/browser_ext_extension_page_tab_navigated.js index 429d584a17..f85bbfe595 100644 --- a/toolkit/components/extensions/test/browser/browser_ext_extension_page_tab_navigated.js +++ b/toolkit/components/extensions/test/browser/browser_ext_extension_page_tab_navigated.js @@ -3,10 +3,6 @@ "use strict"; -const { AddonTestUtils } = ChromeUtils.importESModule( - "resource://testing-common/AddonTestUtils.sys.mjs" -); - // The test tasks in this test file tends to trigger an intermittent // exception raised from JSActor::AfterDestroy, because of a race between // when the WebExtensions API event is being emitted from the parent process @@ -18,23 +14,6 @@ PromiseTestUtils.allowMatchingRejectionsGlobally( /Actor 'Conduits' destroyed before query 'RunListener' was resolved/ ); -AddonTestUtils.initMochitest(this); - -const server = AddonTestUtils.createHttpServer({ - hosts: ["example.com", "anotherwebpage.org"], -}); - -server.registerPathHandler("/", (request, response) => { - response.write(` - - - - test webpage - - - `); -}); - function createTestExtPage({ script }) { return ` @@ -55,7 +34,7 @@ function createTestExtPageScript(name) { ); browser.test.sendMessage(`event-received:${pageName}`); }, - { types: ["main_frame"], urls: ["http://example.com/*"] } + { types: ["main_frame"], urls: ["https://example.com/*"] } ); /* eslint-disable mozilla/balanced-listeners */ window.addEventListener("pageshow", () => { @@ -93,7 +72,7 @@ async function triggerWebRequestListener(webPageURL) { add_task(async function test_extension_page_sameprocess_navigation() { const extension = ExtensionTestUtils.loadExtension({ manifest: { - permissions: ["webRequest", "http://example.com/*"], + permissions: ["webRequest", "https://example.com/*"], }, files: { "extpage1.html": createTestExtPage({ script: "extpage1.js" }), @@ -116,7 +95,7 @@ add_task(async function test_extension_page_sameprocess_navigation() { info("Wait for the extension page to be loaded"); await extension.awaitMessage("pageshow:extpage1"); - await triggerWebRequestListener("http://example.com"); + await triggerWebRequestListener("https://example.com"); await extension.awaitMessage("event-received:extpage1"); ok(true, "extpage1 got a webRequest event as expected"); @@ -131,7 +110,7 @@ add_task(async function test_extension_page_sameprocess_navigation() { info( "Trigger a web request event and expect extpage2 to be the only one receiving it" ); - await triggerWebRequestListener("http://example.com"); + await triggerWebRequestListener("https://example.com"); await extension.awaitMessage("event-received:extpage2"); ok(true, "extpage2 got a webRequest event as expected"); @@ -146,7 +125,7 @@ add_task(async function test_extension_page_sameprocess_navigation() { await extension.awaitMessage("pagehide:extpage2"); // We only expect extpage1 to be able to receive API events. - await triggerWebRequestListener("http://example.com"); + await triggerWebRequestListener("https://example.com"); await extension.awaitMessage("event-received:extpage1"); ok(true, "extpage1 got a webRequest event as expected"); @@ -159,7 +138,7 @@ add_task(async function test_extension_page_sameprocess_navigation() { add_task(async function test_extension_page_context_navigated_to_web_page() { const extension = ExtensionTestUtils.loadExtension({ manifest: { - permissions: ["webRequest", "http://example.com/*"], + permissions: ["webRequest", "https://example.com/*"], }, files: { "extpage.html": createTestExtPage({ script: "extpage.js" }), @@ -178,8 +157,8 @@ add_task(async function test_extension_page_context_navigated_to_web_page() { // navigated will be intermittently able to receive an event before it // is navigated to the webpage url (and moved into the BFCache or destroyed) // and trigger an intermittent failure of this test. - const webPageURL = "http://anotherwebpage.org/"; - const triggerWebRequestURL = "http://example.com/"; + const webPageURL = "https://example.net/"; + const triggerWebRequestURL = "https://example.com/"; info("Opening extension page in a new tab"); const extPageTab1 = await BrowserTestUtils.addTab(gBrowser, extPageURL); diff --git a/toolkit/components/extensions/test/browser/browser_ext_themes_ntp_colors.js b/toolkit/components/extensions/test/browser/browser_ext_themes_ntp_colors.js index 8e2f5446c9..4ee92bf798 100644 --- a/toolkit/components/extensions/test/browser/browser_ext_themes_ntp_colors.js +++ b/toolkit/components/extensions/test/browser/browser_ext_themes_ntp_colors.js @@ -26,17 +26,20 @@ async function test_ntp_theme(theme, isBrightText) { }); let browser = gBrowser.selectedBrowser; - let { originalBackground, originalCardBackground, originalColor } = await SpecialPowers.spawn(browser, [], function () { let doc = content.document; ok( !doc.documentElement.hasAttribute("lwt-newtab"), - "New tab page should not have lwt-newtab attribute" + `New tab page should not have lwt-newtab attribute` + ); + ok( + !doc.documentElement.hasAttribute("lwtheme"), + `New tab page should not have lwtheme attribute` ); ok( !doc.documentElement.hasAttribute("lwt-newtab-brighttext"), - `New tab page should not have lwt-newtab-brighttext attribute` + `New tab page not should have lwt-newtab-brighttext attribute` ); return { @@ -64,22 +67,39 @@ async function test_ntp_theme(theme, isBrightText) { Services.ppmm.sharedData.flush(); + let hasNtpColors = !!( + theme.colors.ntp_background || + theme.colors.ntp_text || + theme.colors.ntp_card_background + ); await SpecialPowers.spawn( browser, [ { isBrightText, + hasNtpColors, background: hexToCSS(theme.colors.ntp_background), card_background: hexToCSS(theme.colors.ntp_card_background), color: hexToCSS(theme.colors.ntp_text), }, ], - async function ({ isBrightText, background, card_background, color }) { + async function ({ + isBrightText, + hasNtpColors, + background, + card_background, + color, + }) { let doc = content.document; - ok( + is( doc.documentElement.hasAttribute("lwt-newtab"), + hasNtpColors, "New tab page should have lwt-newtab attribute" ); + ok( + doc.documentElement.hasAttribute("lwtheme"), + "New tab page should have lwtheme attribute" + ); is( doc.documentElement.hasAttribute("lwt-newtab-brighttext"), isBrightText, @@ -88,22 +108,24 @@ async function test_ntp_theme(theme, isBrightText) { } have lwt-newtab-brighttext attribute` ); - is( - content.getComputedStyle(doc.body).backgroundColor, - background, - "New tab page background should be set." - ); - is( - content.getComputedStyle(doc.querySelector(".top-site-outer .tile")) - .backgroundColor, - card_background, - "New tab page card background should be set." - ); - is( - content.getComputedStyle(doc.querySelector(".outer-wrapper")).color, - color, - "New tab page text color should be set." - ); + if (hasNtpColors) { + is( + content.getComputedStyle(doc.body).backgroundColor, + background, + "New tab page background should be set." + ); + is( + content.getComputedStyle(doc.querySelector(".top-site-outer .tile")) + .backgroundColor, + card_background, + "New tab page card background should be set." + ); + is( + content.getComputedStyle(doc.querySelector(".outer-wrapper")).color, + color, + "New tab page text color should be set." + ); + } } ); @@ -126,6 +148,10 @@ async function test_ntp_theme(theme, isBrightText) { !doc.documentElement.hasAttribute("lwt-newtab"), "New tab page should not have lwt-newtab attribute" ); + ok( + !doc.documentElement.hasAttribute("lwtheme"), + "New tab page should not have lwtheme attribute" + ); ok( !doc.documentElement.hasAttribute("lwt-newtab-brighttext"), `New tab page should not have lwt-newtab-brighttext attribute` @@ -151,6 +177,17 @@ async function test_ntp_theme(theme, isBrightText) { ); } +async function waitForDarkMode(value) { + info(`waiting for dark mode: ${value}`); + const mq = matchMedia("(prefers-color-scheme: dark)"); + if (mq.matches == value) { + return; + } + await new Promise(r => { + mq.addEventListener("change", r, { once: true }); + }); +} + add_task(async function test_support_ntp_colors() { await SpecialPowers.pushPrefEnv({ set: [ @@ -163,11 +200,13 @@ add_task(async function test_support_ntp_colors() { ["layout.css.prefers-color-scheme.content-override", 1], // Override the system color scheme to light so this test passes on // machines with dark system color scheme. + // FIXME(emilio): This doesn't seem working reliably, at least on macOS. ["ui.systemUsesDarkTheme", 0], ], }); NewTabPagePreloading.removePreloadedBrowser(window); for (let url of ["about:newtab", "about:home"]) { + await waitForDarkMode(false); info("Opening url: " + url); await BrowserTestUtils.withNewTab({ gBrowser, url }, async browser => { await waitForAboutNewTabReady(browser, url); @@ -185,6 +224,7 @@ add_task(async function test_support_ntp_colors() { url ); + await waitForDarkMode(false); await test_ntp_theme( { colors: { @@ -198,6 +238,19 @@ add_task(async function test_support_ntp_colors() { true, url ); + + // Test a theme without any new tab page colors + await waitForDarkMode(false); + await test_ntp_theme( + { + colors: { + frame: ACCENT_COLOR, + tab_background_text: TEXT_COLOR, + }, + }, + false, + url + ); }); } }); diff --git a/toolkit/components/extensions/test/browser/browser_ext_themes_ntp_colors_perwindow.js b/toolkit/components/extensions/test/browser/browser_ext_themes_ntp_colors_perwindow.js index 3b739322d6..54152d005c 100644 --- a/toolkit/components/extensions/test/browser/browser_ext_themes_ntp_colors_perwindow.js +++ b/toolkit/components/extensions/test/browser/browser_ext_themes_ntp_colors_perwindow.js @@ -39,6 +39,10 @@ function test_ntp_theme(browser, theme, isBrightText) { doc.documentElement.hasAttribute("lwt-newtab"), "New tab page should have lwt-newtab attribute" ); + ok( + doc.documentElement.hasAttribute("lwtheme"), + "New tab page should have lwtheme attribute" + ); is( doc.documentElement.hasAttribute("lwt-newtab-brighttext"), isBrightText, @@ -89,6 +93,10 @@ function test_ntp_default_theme(browser) { !doc.documentElement.hasAttribute("lwt-newtab"), "New tab page should not have lwt-newtab attribute" ); + ok( + !doc.documentElement.hasAttribute("lwtheme"), + "New tab page should not have lwtheme attribute" + ); ok( !doc.documentElement.hasAttribute("lwt-newtab-brighttext"), `New tab page should not have lwt-newtab-brighttext attribute` diff --git a/toolkit/components/extensions/test/browser/browser_ext_themes_pbm.js b/toolkit/components/extensions/test/browser/browser_ext_themes_pbm.js index 3b36a256d0..d2dfb16e72 100644 --- a/toolkit/components/extensions/test/browser/browser_ext_themes_pbm.js +++ b/toolkit/components/extensions/test/browser/browser_ext_themes_pbm.js @@ -336,7 +336,7 @@ add_task(async function test_pbm_dark_page_info() { await BrowserTestUtils.withNewTab( { gBrowser: win.gBrowser, url: "https://example.com" }, async () => { - let pageInfo = win.BrowserPageInfo(null, "securityTab"); + let pageInfo = win.BrowserCommands.pageInfo(null, "securityTab"); await BrowserTestUtils.waitForEvent(pageInfo, "page-info-init"); let prefersColorScheme = await getPrefersColorSchemeInfo({ diff --git a/toolkit/components/extensions/test/browser/browser_ext_themes_sanitization.js b/toolkit/components/extensions/test/browser/browser_ext_themes_sanitization.js index 89ebd3ae68..fdee1eb72d 100644 --- a/toolkit/components/extensions/test/browser/browser_ext_themes_sanitization.js +++ b/toolkit/components/extensions/test/browser/browser_ext_themes_sanitization.js @@ -114,8 +114,9 @@ add_task(async function test_sanitization_transparent() { await extension.startup(); let navbar = document.querySelector("#nav-bar"); - Assert.ok( - window.getComputedStyle(navbar).boxShadow.includes("rgba(0, 0, 0, 0)"), + Assert.equal( + window.getComputedStyle(navbar).borderTopColor, + "rgba(0, 0, 0, 0)", "Top separator should be transparent" ); diff --git a/toolkit/components/extensions/test/browser/browser_ext_themes_separators.js b/toolkit/components/extensions/test/browser/browser_ext_themes_separators.js index 4da4927ccf..1b953269b6 100644 --- a/toolkit/components/extensions/test/browser/browser_ext_themes_separators.js +++ b/toolkit/components/extensions/test/browser/browser_ext_themes_separators.js @@ -48,10 +48,9 @@ add_task(async function test_support_separator_properties() { await deprecatedMessagePromise; let navbar = document.querySelector("#nav-bar"); - Assert.ok( - window - .getComputedStyle(navbar) - .boxShadow.includes(`rgb(${hexToRGB(SEPARATOR_TOP_COLOR).join(", ")})`), + Assert.equal( + window.getComputedStyle(navbar).borderTopColor, + `rgb(${hexToRGB(SEPARATOR_TOP_COLOR).join(", ")})`, "Top separator color properly set" ); diff --git a/toolkit/components/extensions/test/mochitest/test_check_startupcache.html b/toolkit/components/extensions/test/mochitest/test_check_startupcache.html index 8cb529d18d..d1157472ec 100644 --- a/toolkit/components/extensions/test/mochitest/test_check_startupcache.html +++ b/toolkit/components/extensions/test/mochitest/test_check_startupcache.html @@ -41,7 +41,7 @@ add_task(async function check_ExtensionParent_StartupCache_is_non_empty() { let map = await chromeScript.promiseOneMessage("StartupCache_data"); chromeScript.destroy(); - // "manifests" is populated by Extension's parseManifest in Extension.jsm. + // "manifests" is populated by Extension's parseManifest in Extension.sys.mjs. const keys = ["manifests", "mochikit@mozilla.org", "2.0", "en-US"]; for (let key of keys) { map = map.get(key); diff --git a/toolkit/components/extensions/test/mochitest/test_ext_async_clipboard.html b/toolkit/components/extensions/test/mochitest/test_ext_async_clipboard.html index 708b5522c3..e7fdd6aad0 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_async_clipboard.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_async_clipboard.html @@ -354,11 +354,11 @@ add_task(async function test_contentscript_clipboard_nocontents_readtext() { await extension.unload(); }); -// Test that performing read(...) when the clipboard is empty returns an empty ClipboardItem +// Test that performing read(...) when the clipboard is empty returns no ClipboardItem add_task(async function test_contentscript_clipboard_nocontents_read() { function contentScript() { clipboardRead().then(function(items) { - if (items[0].types.length) { + if (items.length) { browser.test.fail("Read read the wrong thing from clipboard, " + "ClipboardItem has this many entries: " + items[0].types.length); } else { diff --git a/toolkit/components/extensions/test/mochitest/test_ext_contentscript_securecontext.html b/toolkit/components/extensions/test/mochitest/test_ext_contentscript_securecontext.html index 093c26898f..f9230c9a5f 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_contentscript_securecontext.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_contentscript_securecontext.html @@ -14,6 +14,8 @@ await SpecialPowers.pushPrefEnv({ "set": [ ["dom.w3c_pointer_events.getcoalescedevents_only_in_securecontext", true], + // Test is intentionally testing in non-secure contexts. + ["dom.security.https_first", false] ] }); }); diff --git a/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect.html b/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect.html index 85f98d5034..d474a7caee 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect.html @@ -18,6 +18,7 @@ function background() { browser.test.assertTrue(port.sender.url.endsWith("file_sample.html"), "URL correct"); browser.test.assertTrue(port.sender.tab.url.endsWith("file_sample.html"), "tab URL correct"); browser.test.assertEq(port.sender.frameId, 0, "frameId of top frame"); + browser.test.assertEq(new URL(port.sender.url).origin, port.sender.origin, "sender origin correct"); let expected = "message 1"; port.onMessage.addListener(msg => { diff --git a/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect2.html b/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect2.html index 13b9029c48..32620b5b3b 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect2.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect2.html @@ -21,6 +21,7 @@ function backgroundScript(token) { browser.runtime.onConnect.addListener(port => { browser.test.assertTrue(port.sender.url.endsWith("file_sample.html"), "sender url correct"); browser.test.assertTrue(port.sender.tab.url.endsWith("file_sample.html"), "sender url correct"); + browser.test.assertEq(new URL(port.sender.url).origin, port.sender.origin, "sender origin correct"); let tabId = port.sender.tab.id; browser.tabs.connect(tabId, {name: token}); diff --git a/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect_iframe.html b/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect_iframe.html index 9c64635063..e3e0e80f2a 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect_iframe.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_runtime_connect_iframe.html @@ -30,12 +30,15 @@ add_task(async function connect_from_background_frame() { } async function background() { const FRAME_URL = "https://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.html"; + const FRAME_ORIGIN = new URL(FRAME_URL).origin; + browser.runtime.onConnect.addListener(port => { // The next two assertions are the reason for this being a mochitest // instead of a xpcshell test. browser.test.assertEq(port.sender.tab, undefined, "Sender is not a tab"); browser.test.assertEq(port.sender.frameId, undefined, "frameId unset"); browser.test.assertEq(port.sender.url, FRAME_URL, "Expected sender URL"); + browser.test.assertEq(port.sender.origin, FRAME_ORIGIN, "Expected sender origin"); port.onMessage.addListener(msg => { browser.test.assertEq("pong", msg, "Reply from content script"); port.disconnect(); @@ -88,6 +91,8 @@ add_task(async function connect_from_content_script_in_frame() { async function background() { const TAB_URL = "https://example.org/tests/toolkit/components/extensions/test/mochitest/file_contains_iframe.html"; const FRAME_URL = "https://example.org/tests/toolkit/components/extensions/test/mochitest/file_contains_img.html"; + const FRAME_ORIGIN = new URL(FRAME_URL).origin; + let createdTab; browser.runtime.onConnect.addListener(port => { // The next two assertions are the reason for this being a mochitest @@ -95,6 +100,7 @@ add_task(async function connect_from_content_script_in_frame() { browser.test.assertEq(port.sender.tab.url, TAB_URL, "Sender is the tab"); browser.test.assertTrue(port.sender.frameId > 0, "frameId is set"); browser.test.assertEq(port.sender.url, FRAME_URL, "Expected sender URL"); + browser.test.assertEq(port.sender.origin, FRAME_ORIGIN, "Expected sender origin"); browser.test.assertEq(createdTab.id, port.sender.tab.id, "Tab to close"); browser.tabs.remove(port.sender.tab.id).then(() => { diff --git a/toolkit/components/extensions/test/mochitest/test_ext_tabs_captureTab.html b/toolkit/components/extensions/test/mochitest/test_ext_tabs_captureTab.html index ab06a965ed..20f368a0ae 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_tabs_captureTab.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_tabs_captureTab.html @@ -319,6 +319,141 @@ add_task(async function testCaptureVisibleTabPermissions() { await extension.awaitFinish("captureVisibleTabPermissions"); await extension.unload(); }); + +add_task(async function testCaptureVisibleTabWithActiveTab() { + let extension = ExtensionTestUtils.loadExtension({ + manifest: { + browser_action: { + default_area: "navbar", + }, + permissions: ["webNavigation", "tabs", "activeTab"], + }, + + async background() { + // Wait for the page (in the test window) to load. + await new Promise(resolve => { + browser.webNavigation.onCompleted.addListener( + () => resolve(), + {url: [{schemes: ["data"]}]}); + }); + + browser.browserAction.onClicked.addListener(async tab => { + await browser.tabs.captureVisibleTab(tab.windowId); + browser.test.notifyPass("captureVisibleTabPermissions"); + }); + + browser.test.sendMessage("ready"); + }, + }); + + let html = ` + + + + + + +

hello

+ + `; + + await extension.startup(); + + let testWindow = window.open(`data:text/html,${encodeURIComponent(html)}#scroll`); + await extension.awaitMessage("ready"); + await AppTestDelegate.clickBrowserAction(testWindow, extension); + await extension.awaitFinish("captureVisibleTabPermissions"); + await AppTestDelegate.closeBrowserAction(testWindow, extension); + testWindow.close(); + + await extension.unload(); +}); + +add_task(async function testCaptureVisibleTabWithActiveTabAndNotUserInteraction() { + let extension = ExtensionTestUtils.loadExtension({ + manifest: { + permissions: ["webNavigation", "tabs", "activeTab"], + }, + + async background() { + // Wait for the page (in the test window) to load. + await new Promise(resolve => { + browser.webNavigation.onCompleted.addListener( + () => resolve(), + {url: [{schemes: ["data"]}]}); + }); + + let [tab] = await browser.tabs.query({ currentWindow: true, active: true }); + await browser.test.assertRejects( + browser.tabs.captureVisibleTab(tab.windowId), + /Missing activeTab permission/, + "Expected rejection because activeTab permission isn't set" + ); + + browser.test.notifyPass("captureVisibleTabPermissions"); + }, + }); + + let html = ` + + + + + + +

hello

+ + `; + + await extension.startup(); + + let testWindow = window.open(`data:text/html,${encodeURIComponent(html)}#scroll`); + await extension.awaitFinish("captureVisibleTabPermissions"); + testWindow.close(); + + await extension.unload(); +}); + +add_task(async function testCaptureVisibleTabWithActiveTabAndAllURLs() { + let extension = ExtensionTestUtils.loadExtension({ + manifest: { + permissions: ["webNavigation", "tabs", "activeTab", ""], + }, + + async background() { + // Wait for the page (in the test window) to load. + await new Promise(resolve => { + browser.webNavigation.onCompleted.addListener( + () => resolve(), + {url: [{schemes: ["data"]}]}); + }); + + let [tab] = await browser.tabs.query({ currentWindow: true, active: true }); + await browser.tabs.captureVisibleTab(tab.windowId); + + browser.test.notifyPass("captureVisibleTabPermissions"); + }, + }); + + let html = ` + + + + + + +

hello

+ + `; + + await extension.startup(); + + let testWindow = window.open(`data:text/html,${encodeURIComponent(html)}#scroll`); + await extension.awaitFinish("captureVisibleTabPermissions"); + testWindow.close(); + + await extension.unload(); +}); diff --git a/toolkit/components/extensions/test/mochitest/test_ext_tabs_sendMessage.html b/toolkit/components/extensions/test/mochitest/test_ext_tabs_sendMessage.html index 4b230c258c..8c6dfeee7c 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_tabs_sendMessage.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_tabs_sendMessage.html @@ -11,6 +11,10 @@ diff --git a/toolkit/components/extensions/test/mochitest/test_ext_test.html b/toolkit/components/extensions/test/mochitest/test_ext_test.html index bf68786465..21093c9abf 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_test.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_test.html @@ -126,7 +126,7 @@ function testScript() { // The WebIDL version of assertDeepEq structurally clones before sending the // params to the main thread. This check verifies that the behavior is - // consistent between the WebIDL and Schemas.jsm-generated API bindings. + // consistent between the WebIDL and Schemas.sys.mjs-generated API bindings. browser.test.assertThrows( () => browser.test.assertDeepEq(obj, obj, "obj with func"), /An unexpected error occurred/, diff --git a/toolkit/components/extensions/test/xpcshell/test_csp_validator.js b/toolkit/components/extensions/test/xpcshell/test_csp_validator.js index 011628f027..0e665b9730 100644 --- a/toolkit/components/extensions/test/xpcshell/test_csp_validator.js +++ b/toolkit/components/extensions/test/xpcshell/test_csp_validator.js @@ -202,8 +202,8 @@ add_task(async function test_csp_validator_extension_pages() { let checkPolicy = (policy, expectedResult) => { info(`Checking policy: ${policy}`); - // While Schemas.jsm uses Ci.nsIAddonContentPolicy.CSP_ALLOW_WASM, we don't - // pass that here because we are only verifying that remote scripts are + // While Schemas.sys.mjs uses Ci.nsIAddonContentPolicy.CSP_ALLOW_WASM, we + // don't pass that here because we are only verifying that remote scripts are // blocked here. let result = cps.validateAddonCSP(policy, 0); equal(result, expectedResult); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_adoption_with_private_field_xrays.js b/toolkit/components/extensions/test/xpcshell/test_ext_adoption_with_private_field_xrays.js index 2d8b02bcd9..76b6644d44 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_adoption_with_private_field_xrays.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_adoption_with_private_field_xrays.js @@ -1,6 +1,6 @@ "use strict"; -// ExtensionContent.jsm needs to know when it's running from xpcshell, +// ExtensionContent.sys.mjs needs to know when it's running from xpcshell, // to use the right timeout for content scripts executed at document_idle. ExtensionTestUtils.mockAppInfo(); const server = createHttpServer(); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_adoption_with_xrays.js b/toolkit/components/extensions/test/xpcshell/test_ext_adoption_with_xrays.js index 9655c157d1..b909223302 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_adoption_with_xrays.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_adoption_with_xrays.js @@ -1,6 +1,6 @@ "use strict"; -// ExtensionContent.jsm needs to know when it's running from xpcshell, +// ExtensionContent.sys.mjs needs to know when it's running from xpcshell, // to use the right timeout for content scripts executed at document_idle. ExtensionTestUtils.mockAppInfo(); const server = createHttpServer(); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_clear_cached_resources.js b/toolkit/components/extensions/test/xpcshell/test_ext_clear_cached_resources.js index 95bef23383..bd05398736 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_clear_cached_resources.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_clear_cached_resources.js @@ -297,7 +297,7 @@ add_task( // This temporary directory is going to be removed from the // cleanup function, but also make it unique as we do for the // other temporary files (e.g. like getTemporaryFile as defined - // in XPInstall.jsm). + // in XPIInstall.sys.mjs). const random = Math.round(Math.random() * 36 ** 3).toString(36); const tmpDirName = `xpcshelltest_unpacked_addons_${random}`; let tmpExtPath = FileUtils.getDir("TmpD", [tmpDirName]); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_dynamic_registration.js b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_dynamic_registration.js index 0133b5d86c..20f6ece95a 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_dynamic_registration.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_dynamic_registration.js @@ -5,7 +5,7 @@ server.registerDirectory("/data/", do_get_file("data")); const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`; -// ExtensionContent.jsm needs to know when it's running from xpcshell, to use +// ExtensionContent.sys.mjs needs to know when it's running from xpcshell, to use // the right timeout for content scripts executed at document_idle. ExtensionTestUtils.mockAppInfo(); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_triggeringPrincipal.js b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_triggeringPrincipal.js index 4ebe6df636..ce7f293142 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_triggeringPrincipal.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_triggeringPrincipal.js @@ -30,7 +30,7 @@ Services.prefs.setBoolPref( false ); -// ExtensionContent.jsm needs to know when it's running from xpcshell, +// ExtensionContent.sys.mjs needs to know when it's running from xpcshell, // to use the right timeout for content scripts executed at document_idle. ExtensionTestUtils.mockAppInfo(); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_xorigin_frame.js b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_xorigin_frame.js index 8a58b2475c..420fa7689c 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_xorigin_frame.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_xorigin_frame.js @@ -5,6 +5,12 @@ const server = createHttpServer({ }); server.registerDirectory("/data/", do_get_file("data")); +// By default, fission.webContentIsolationStrategy=1 (IsolateHighValue). When +// Fission is enabled on Android, the pref value 2 (IsolateHighValue) will be +// used instead. Set to 1 (IsolateEverything) to make sure the subframe in this +// test gets its own process, independently of the default prefs on Android. +Services.prefs.setIntPref("fission.webContentIsolationStrategy", 1); + add_task(async function test_process_switch_cross_origin_frame() { const extension = ExtensionTestUtils.loadExtension({ manifest: { diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_xrays.js b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_xrays.js index 7b92d5c4b7..30ec8ceced 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_xrays.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_xrays.js @@ -1,6 +1,6 @@ "use strict"; -// ExtensionContent.jsm needs to know when it's running from xpcshell, +// ExtensionContent.sys.mjs needs to know when it's running from xpcshell, // to use the right timeout for content scripts executed at document_idle. ExtensionTestUtils.mockAppInfo(); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_contexts_gc.js b/toolkit/components/extensions/test/xpcshell/test_ext_contexts_gc.js index 2a36f51637..b6f955f7ba 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_contexts_gc.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_contexts_gc.js @@ -5,7 +5,7 @@ server.registerDirectory("/data/", do_get_file("data")); const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`; -// ExtensionContent.jsm needs to know when it's running from xpcshell, +// ExtensionContent.sys.mjs needs to know when it's running from xpcshell, // to use the right timeout for content scripts executed at document_idle. ExtensionTestUtils.mockAppInfo(); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_dnr_modifyHeaders.js b/toolkit/components/extensions/test/xpcshell/test_ext_dnr_modifyHeaders.js index 4b7bebe188..df9e9d77ef 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_dnr_modifyHeaders.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_dnr_modifyHeaders.js @@ -29,6 +29,7 @@ server.registerPathHandler("/echoheaders", (req, res) => { dropDefaultHeader("accept-language"); dropDefaultHeader("accept-encoding"); dropDefaultHeader("connection"); + dropDefaultHeader("priority"); res.write(JSON.stringify(headers)); }); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_file_access.js b/toolkit/components/extensions/test/xpcshell/test_ext_file_access.js index c05188cd38..bea1e76c0f 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_file_access.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_file_access.js @@ -4,7 +4,7 @@ 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, +// ExtensionContent.sys.mjs needs to know when it's running from xpcshell, // to use the right timeout for content scripts executed at document_idle. ExtensionTestUtils.mockAppInfo(); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_i18n.js b/toolkit/components/extensions/test/xpcshell/test_ext_i18n.js index 1e46e19527..69ba326f75 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_i18n.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_i18n.js @@ -4,7 +4,7 @@ const { Preferences } = ChromeUtils.importESModule( "resource://gre/modules/Preferences.sys.mjs" ); -// ExtensionContent.jsm needs to know when it's running from xpcshell, +// ExtensionContent.sys.mjs needs to know when it's running from xpcshell, // to use the right timeout for content scripts executed at document_idle. ExtensionTestUtils.mockAppInfo(); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_ipcBlob.js b/toolkit/components/extensions/test/xpcshell/test_ext_ipcBlob.js index dd90d9bbc8..2c5b3378fd 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_ipcBlob.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_ipcBlob.js @@ -5,7 +5,7 @@ server.registerDirectory("/data/", do_get_file("data")); const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`; -// ExtensionContent.jsm needs to know when it's running from xpcshell, +// ExtensionContent.sys.mjs needs to know when it's running from xpcshell, // to use the right timeout for content scripts executed at document_idle. ExtensionTestUtils.mockAppInfo(); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_permissions.js b/toolkit/components/extensions/test/xpcshell/test_ext_permissions.js index 948b75978a..ae6ce3d27e 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_permissions.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_permissions.js @@ -12,8 +12,8 @@ const { ExtensionPermissions } = ChromeUtils.importESModule( Services.prefs.setBoolPref("extensions.manifestV3.enabled", true); -// ExtensionParent.jsm is being imported lazily because when it is imported Services.appinfo will be -// retrieved and cached (as a side-effect of Schemas.jsm being imported), and so Services.appinfo +// ExtensionParent.sys.mjs is being imported lazily because when it is imported Services.appinfo will be +// retrieved and cached (as a side-effect of Schemas.sys.mjs being imported), and so Services.appinfo // will not be returning the version set by AddonTestUtils.createAppInfo and this test will // fail on non-nightly builds (because the cached appinfo.version will be undefined and // AddonManager startup will fail). @@ -704,6 +704,7 @@ const GRANTED_WITHOUT_USER_PROMPT = [ "theme", "unlimitedStorage", "webRequest", + "webRequestAuthProvider", "webRequestBlocking", "webRequestFilterResponse", "webRequestFilterResponse.serviceWorkerScript", @@ -1058,3 +1059,47 @@ add_task(async function test_internal_permissions() { await extension.unload(); }); + +add_task(function test_normalizeOptional() { + const optional1 = { + origins: ["*://site.com/", "*://*.domain.com/"], + permissions: ["downloads", "tabs"], + }; + + function normalize(perms, optional) { + perms = { origins: [], permissions: [], ...perms }; + optional = { origins: [], permissions: [], ...optional }; + return ExtensionPermissions.normalizeOptional(perms, optional); + } + + normalize({ origins: ["http://site.com/"] }, optional1); + normalize({ origins: ["https://site.com/"] }, optional1); + normalize({ origins: ["*://blah.domain.com/"] }, optional1); + normalize({ permissions: ["downloads", "tabs"] }, optional1); + + Assert.throws( + () => normalize({ origins: ["http://www.example.com/"] }, optional1), + /was not declared in the manifest/ + ); + Assert.throws( + () => normalize({ permissions: ["proxy"] }, optional1), + /was not declared in optional_permissions/ + ); + + const optional2 = { + origins: ["", "*://*/*"], + permissions: ["idle", "clipboardWrite"], + }; + + normalize({ origins: ["http://site.com/"] }, optional2); + normalize({ origins: ["https://site.com/"] }, optional2); + normalize({ origins: ["*://blah.domain.com/"] }, optional2); + normalize({ permissions: ["idle", "clipboardWrite"] }, optional2); + + let perms = normalize({ origins: [""] }, optional2); + equal( + perms.origins.sort().join(), + optional2.origins.sort().join(), + `Expect both "all sites" permissions` + ); +}); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_permissions_api.js b/toolkit/components/extensions/test/xpcshell/test_ext_permissions_api.js index 0211787fee..97db78cf81 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_permissions_api.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_permissions_api.js @@ -58,6 +58,7 @@ add_task(async function setup() { "search", "tabHide", "tabs", + "webRequestAuthProvider", "webRequestBlocking", "webRequestFilterResponse", "webRequestFilterResponse.serviceWorkerScript", diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_proxy_onauthrequired.js b/toolkit/components/extensions/test/xpcshell/test_ext_proxy_onauthrequired.js index 4b1128a349..719fd219fe 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_proxy_onauthrequired.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_proxy_onauthrequired.js @@ -251,7 +251,7 @@ add_task(async function test_webRequest_auth_proxy_system() { () => { browser.test.sendMessage("onAuthRequired"); // cancel is silently ignored, if it were not (e.g someone messes up in - // WebRequest.jsm and allows cancel) this test would fail. + // WebRequest.sys.mjs and allows cancel) this test would fail. return { cancel: true, authCredentials: { username: "puser", password: "ppass" }, diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_schemas_manifest_permissions.js b/toolkit/components/extensions/test/xpcshell/test_ext_schemas_manifest_permissions.js index 85e645e67b..e5fc746e60 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_schemas_manifest_permissions.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_schemas_manifest_permissions.js @@ -86,7 +86,7 @@ add_task(async function () { a_manifest_property: {}, }, background() { - // Test hasPermission method implemented in ExtensionChild.jsm. + // Test hasPermission method implemented in ExtensionChild.sys.mjs. browser.test.assertTrue( "testManifestPermission" in browser, "The API namespace is defined as expected" @@ -105,7 +105,7 @@ add_task(async function () { "test-extension-manifest-without-nested-prop" ); - // Test hasPermission method implemented in Extension.jsm. + // Test hasPermission method implemented in Extension.sys.mjs. equal( extension.extension.hasPermission("manifest:a_manifest_property"), true, @@ -129,7 +129,7 @@ add_task(async function () { }, }, background() { - // Test hasPermission method implemented in ExtensionChild.jsm. + // Test hasPermission method implemented in ExtensionChild.sys.mjs. browser.test.assertTrue( "testManifestPermission" in browser, "The API namespace is defined as expected" @@ -146,7 +146,7 @@ add_task(async function () { async extension => { await extension.awaitFinish("test-extension-manifest-with-nested-prop"); - // Test hasPermission method implemented in Extension.jsm. + // Test hasPermission method implemented in Extension.sys.mjs. equal( extension.extension.hasPermission("manifest:a_manifest_property"), true, diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_schemas_privileged.js b/toolkit/components/extensions/test/xpcshell/test_ext_schemas_privileged.js index 14cbca7443..496607968e 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_schemas_privileged.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_schemas_privileged.js @@ -144,7 +144,7 @@ add_task( } ); -// Test that Extension.jsm and schema correctly match. +// Test that Extension.sys.mjs and schema correctly match. add_task(function test_privileged_permissions_match() { const { PRIVILEGED_PERMS } = ChromeUtils.importESModule( "resource://gre/modules/Extension.sys.mjs" diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_scripting_contentScripts.js b/toolkit/components/extensions/test/xpcshell/test_ext_scripting_contentScripts.js index a06f34a1b4..c47cdcad4d 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_scripting_contentScripts.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_scripting_contentScripts.js @@ -5,7 +5,7 @@ server.registerDirectory("/data/", do_get_file("data")); const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`; -// ExtensionContent.jsm needs to know when it's running from xpcshell, to use +// ExtensionContent.sys.mjs needs to know when it's running from xpcshell, to use // the right timeout for content scripts executed at document_idle. ExtensionTestUtils.mockAppInfo(); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_scripting_contentScripts_css.js b/toolkit/components/extensions/test/xpcshell/test_ext_scripting_contentScripts_css.js index 21190d2d59..a3c79b1cc0 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_scripting_contentScripts_css.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_scripting_contentScripts_css.js @@ -5,7 +5,7 @@ server.registerDirectory("/data/", do_get_file("data")); const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`; -// ExtensionContent.jsm needs to know when it's running from xpcshell, to use +// ExtensionContent.sys.mjs needs to know when it's running from xpcshell, to use // the right timeout for content scripts executed at document_idle. ExtensionTestUtils.mockAppInfo(); 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 index 3c806439ce..02ef9b0fa5 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_scripting_contentScripts_file.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_scripting_contentScripts_file.js @@ -4,7 +4,7 @@ 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 +// ExtensionContent.sys.mjs needs to know when it's running from xpcshell, to use // the right timeout for content scripts executed at document_idle. ExtensionTestUtils.mockAppInfo(); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_scripting_updateContentScripts.js b/toolkit/components/extensions/test/xpcshell/test_ext_scripting_updateContentScripts.js index 9d3bf1576c..85c2376715 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_scripting_updateContentScripts.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_scripting_updateContentScripts.js @@ -5,7 +5,7 @@ server.registerDirectory("/data/", do_get_file("data")); const BASE_URL = `http://localhost:${server.identity.primaryPort}/data`; -// ExtensionContent.jsm needs to know when it's running from xpcshell, to use +// ExtensionContent.sys.mjs needs to know when it's running from xpcshell, to use // the right timeout for content scripts executed at document_idle. ExtensionTestUtils.mockAppInfo(); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_shadowdom.js b/toolkit/components/extensions/test/xpcshell/test_ext_shadowdom.js index 626d8de22d..e8316aa652 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_shadowdom.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_shadowdom.js @@ -1,6 +1,6 @@ "use strict"; -// ExtensionContent.jsm needs to know when it's running from xpcshell, +// ExtensionContent.sys.mjs needs to know when it's running from xpcshell, // to use the right timeout for content scripts executed at document_idle. ExtensionTestUtils.mockAppInfo(); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_userScripts.js b/toolkit/components/extensions/test/xpcshell/test_ext_userScripts.js index 3108c7b9b4..57ca08aca3 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_userScripts.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_userScripts.js @@ -200,7 +200,7 @@ add_task(async function test_userScripts_no_webext_apis() { let script = await browser.userScripts.register(userScriptOptions); // Unregister and then register the same js code again, to verify that the last registered - // userScript doesn't get assigned a revoked blob url (otherwise Extensioncontent.jsm + // userScript doesn't get assigned a revoked blob url (otherwise Extensioncontent.sys.mjs // ScriptCache raises an error because it fails to compile the revoked blob url and the user // script will never be loaded). script.unregister(); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_auth.js b/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_auth.js index 578e69ebdf..ef07817d00 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_auth.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_auth.js @@ -63,7 +63,7 @@ server.registerPathHandler("/authenticate.sjs", (request, response) => { } }); -function getExtension(bgConfig) { +function getExtension(bgConfig, permissions = ["webRequestBlocking"]) { function background(config) { let path = config.path; browser.webRequest.onBeforeRequest.addListener( @@ -125,18 +125,18 @@ function getExtension(bgConfig) { return ExtensionTestUtils.loadExtension({ manifest: { - permissions: ["webRequest", "webRequestBlocking", bgConfig.path], + permissions: [bgConfig.path, "webRequest", ...permissions], }, background: `(${background})(${JSON.stringify(bgConfig)})`, }); } -add_task(async function test_webRequest_auth() { +async function test_webRequest_auth(permissions) { let config = { path: `${BASE_URL}/*`, realm: `webRequest_auth${Math.random()}`, onBeforeRequest: { - extra: ["blocking"], + extra: permissions.includes("webRequestBlocking") ? ["blocking"] : [], }, onAuthRequired: { extra: ["blocking"], @@ -149,7 +149,7 @@ add_task(async function test_webRequest_auth() { }, }; - let extension = getExtension(config); + let extension = getExtension(config, permissions); await extension.startup(); let requestUrl = `${BASE_URL}/authenticate.sjs?realm=${config.realm}`; @@ -174,6 +174,14 @@ add_task(async function test_webRequest_auth() { await contentPage.close(); await extension.unload(); +} + +add_task(async function test_webRequest_auth_with_webRequestBlocking() { + await test_webRequest_auth(["webRequestBlocking"]); +}); + +add_task(async function test_webRequest_auth_with_webRequestAuthProvider() { + await test_webRequest_auth(["webRequestAuthProvider"]); }); add_task(async function test_webRequest_auth_cancelled() { diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_permission.js b/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_permission.js index 17c22e156d..97e44498c1 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_permission.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_permission.js @@ -18,6 +18,18 @@ function sendMessage(page, msg, data) { return MessageChannel.sendMessage(page.browser.messageManager, msg, data); } +add_setup(() => { + // Make sure to invalidate WebExtensions API schemas that may be cached + // in the StartupCache when this test runs with conditioned-profiles. + // + // These tests are subject to be hitting failures consistently on + // landing API schema changes to the WebExtensions API permissions. + // or other API schema properties that are explicitly covered by + // this tests (e.g. errors expected to be emitted by postprocess + // helper functions). + Services.obs.notifyObservers(null, "startupcache-invalidate"); +}); + add_task(async function test_permissions() { function background() { browser.webRequest.onBeforeRequest.addListener( @@ -113,11 +125,14 @@ add_task(async function test_permissions() { await contentPage.close(); }); -add_task(async function test_no_webRequestBlocking_error() { +add_task(async function test_missing_required_perm_for_blocking_error() { function background() { const expectedError = "Using webRequest.addListener with the blocking option " + "requires the 'webRequestBlocking' permission."; + const expectedErrorOnAuthRequired = + "Using webRequest.onAuthRequired.addListener with the blocking option " + + "requires either the 'webRequestBlocking' or 'webRequestAuthProvider' permission."; const blockingEvents = [ "onBeforeRequest", @@ -135,7 +150,9 @@ add_task(async function test_no_webRequestBlocking_error() { ["blocking"] ); }, - expectedError, + eventName === "onAuthRequired" + ? expectedErrorOnAuthRequired + : expectedError, `Got the expected exception for a blocking webRequest.${eventName} listener` ); } diff --git a/toolkit/components/extensions/test/xpcshell/test_load_all_api_modules.js b/toolkit/components/extensions/test/xpcshell/test_load_all_api_modules.js index 32299fb04e..3d28971352 100644 --- a/toolkit/components/extensions/test/xpcshell/test_load_all_api_modules.js +++ b/toolkit/components/extensions/test/xpcshell/test_load_all_api_modules.js @@ -18,7 +18,7 @@ let schemaURLs = new Set(); schemaURLs.add("chrome://extensions/content/schemas/experiments.json"); // Helper class used to load the API modules similarly to the apiManager -// defined in ExtensionParent.jsm. +// defined in ExtensionParent.sys.mjs. class FakeAPIManager extends ExtensionCommon.SchemaAPIManager { constructor(processType = "main") { super(processType, Schemas); @@ -102,7 +102,8 @@ class FakeAPIManager extends ExtensionCommon.SchemaAPIManager { } // Specialized helper class used to test loading "child process" modules (similarly to the -// SchemaAPIManagers sub-classes defined in ExtensionPageChild.jsm and ExtensionContent.jsm). +// SchemaAPIManagers sub-classes defined in ExtensionPageChild.sys.mjs and +// ExtensionContent.sys.mjs). class FakeChildProcessAPIManager extends FakeAPIManager { constructor({ processType, categoryScripts }) { super(processType, Schemas); diff --git a/toolkit/components/extensions/test/xpcshell/test_native_manifests.js b/toolkit/components/extensions/test/xpcshell/test_native_manifests.js index 1f5bc88740..d4f3ae7243 100644 --- a/toolkit/components/extensions/test/xpcshell/test_native_manifests.js +++ b/toolkit/components/extensions/test/xpcshell/test_native_manifests.js @@ -248,7 +248,7 @@ add_task( "lookupApplication returns the correct path with platform-native slash" ); // Side note: manifest.path does not contain a platform-native path, - // but it is normalized when used in NativeMessaging.jsm. + // but it is normalized when used in NativeMessaging.sys.mjs. deepEqual( result.manifest, manifest, diff --git a/toolkit/components/extensions/test/xpcshell/test_webRequest_ancestors.js b/toolkit/components/extensions/test/xpcshell/test_webRequest_ancestors.js index 509f821828..abbb814ac7 100644 --- a/toolkit/components/extensions/test/xpcshell/test_webRequest_ancestors.js +++ b/toolkit/components/extensions/test/xpcshell/test_webRequest_ancestors.js @@ -11,7 +11,7 @@ const server = createHttpServer({ hosts: ["example.com"] }); server.registerDirectory("/data/", do_get_file("data")); add_task(async function setup() { - // When WebRequest.jsm is used directly instead of through ext-webRequest.js, + // When WebRequest.sys.mjs is used directly instead of through ext-webRequest.js, // ExtensionParent.apiManager is not automatically initialized. Do it here. await ExtensionParent.apiManager.lazyInit(); }); diff --git a/toolkit/components/extensions/test/xpcshell/test_webRequest_cookies.js b/toolkit/components/extensions/test/xpcshell/test_webRequest_cookies.js index 53ed465786..f4c8d75690 100644 --- a/toolkit/components/extensions/test/xpcshell/test_webRequest_cookies.js +++ b/toolkit/components/extensions/test/xpcshell/test_webRequest_cookies.js @@ -75,7 +75,7 @@ function onResponseStarted(details) { } add_task(async function setup() { - // When WebRequest.jsm is used directly instead of through ext-webRequest.js, + // When WebRequest.sys.mjs is used directly instead of through ext-webRequest.js, // ExtensionParent.apiManager is not automatically initialized. Do it here. await ExtensionParent.apiManager.lazyInit(); }); diff --git a/toolkit/components/extensions/test/xpcshell/test_webRequest_filtering.js b/toolkit/components/extensions/test/xpcshell/test_webRequest_filtering.js index 46a72a5926..86b2410e33 100644 --- a/toolkit/components/extensions/test/xpcshell/test_webRequest_filtering.js +++ b/toolkit/components/extensions/test/xpcshell/test_webRequest_filtering.js @@ -89,7 +89,7 @@ add_task(async function setup() { // Disable rcwn to make cache behavior deterministic. Services.prefs.setBoolPref("network.http.rcwn.enabled", false); - // When WebRequest.jsm is used directly instead of through ext-webRequest.js, + // When WebRequest.sys.mjs is used directly instead of through ext-webRequest.js, // ExtensionParent.apiManager is not automatically initialized. Do it here. await ExtensionParent.apiManager.lazyInit(); }); diff --git a/toolkit/components/extensions/test/xpcshell/xpcshell-common.toml b/toolkit/components/extensions/test/xpcshell/xpcshell-common.toml index 7cf8d79409..6d47012eca 100644 --- a/toolkit/components/extensions/test/xpcshell/xpcshell-common.toml +++ b/toolkit/components/extensions/test/xpcshell/xpcshell-common.toml @@ -533,7 +533,7 @@ skip-if = ["os == 'android'"] # Bug 1564871 ["test_ext_storage_sanitizer.js"] skip-if = [ "appname == 'thunderbird'", - "os == 'android'", # Sanitizer.jsm is not in toolkit. + "os == 'android'", # Sanitizer.sys.mjs is not in toolkit. ] ["test_ext_storage_session.js"] @@ -587,7 +587,9 @@ skip-if = [ ["test_ext_wasm.js"] ["test_ext_webRequest_auth.js"] -skip-if = ["os == 'android' && debug"] +skip-if = [ + "os == 'android' && debug", +] ["test_ext_webRequest_cached.js"] skip-if = ["os == 'android'"] # Bug 1573511 @@ -616,7 +618,9 @@ skip-if = ["os == 'android' && debug"] skip-if = ["tsan"] # Bug 1683730 ["test_ext_webRequest_permission.js"] -skip-if = ["os == 'android' && debug"] +skip-if = [ + "os == 'android' && debug", +] ["test_ext_webRequest_redirectProperty.js"] skip-if = ["os == 'android' && processor == 'x86_64'"] # Bug 1683253 -- cgit v1.2.3