summaryrefslogtreecommitdiffstats
path: root/browser/components/extensions
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--browser/components/extensions/parent/ext-browser.js8
-rw-r--r--browser/components/extensions/parent/ext-chrome-settings-overrides.js2
-rw-r--r--browser/components/extensions/parent/ext-commands.js7
-rw-r--r--browser/components/extensions/parent/ext-devtools-panels.js42
-rw-r--r--browser/components/extensions/parent/ext-tabs.js8
-rw-r--r--browser/components/extensions/schemas/commands.json6
-rw-r--r--browser/components/extensions/schemas/tabs.json4
-rw-r--r--browser/components/extensions/test/browser/browser.toml10
-rw-r--r--browser/components/extensions/test/browser/browser_ext_browserAction_context.js6
-rw-r--r--browser/components/extensions/test/browser/browser_ext_browserAction_contextMenu.js6
-rw-r--r--browser/components/extensions/test/browser/browser_ext_browserAction_popup_preload_smoketest.js2
-rw-r--r--browser/components/extensions/test/browser/browser_ext_chrome_settings_overrides_home.js10
-rw-r--r--browser/components/extensions/test/browser/browser_ext_commands_onCommand.js14
-rw-r--r--browser/components/extensions/test/browser/browser_ext_contentscript_nontab_connect.js6
-rw-r--r--browser/components/extensions/test/browser/browser_ext_contentscript_sender_url.js21
-rw-r--r--browser/components/extensions/test/browser/browser_ext_contextMenus_icons.js6
-rw-r--r--browser/components/extensions/test/browser/browser_ext_tabs_onCreated.js2
-rw-r--r--browser/components/extensions/test/browser/browser_ext_url_overrides_newtab.js2
-rw-r--r--browser/components/extensions/test/browser/browser_unified_extensions.js4
19 files changed, 114 insertions, 52 deletions
diff --git a/browser/components/extensions/parent/ext-browser.js b/browser/components/extensions/parent/ext-browser.js
index 7b01d15101..d2f72d4f46 100644
--- a/browser/components/extensions/parent/ext-browser.js
+++ b/browser/components/extensions/parent/ext-browser.js
@@ -67,8 +67,12 @@ global.openOptionsPage = extension => {
return Promise.reject({ message: "No browser window available" });
}
- if (extension.manifest.options_ui.open_in_tab) {
- window.switchToTabHavingURI(extension.manifest.options_ui.page, true, {
+ const { optionsPageProperties } = extension;
+ if (!optionsPageProperties) {
+ return Promise.reject({ message: "No options page" });
+ }
+ if (optionsPageProperties.open_in_tab) {
+ window.switchToTabHavingURI(optionsPageProperties.page, true, {
triggeringPrincipal: extension.principal,
});
return Promise.resolve();
diff --git a/browser/components/extensions/parent/ext-chrome-settings-overrides.js b/browser/components/extensions/parent/ext-chrome-settings-overrides.js
index 1fbb794b51..3d1b7d363e 100644
--- a/browser/components/extensions/parent/ext-chrome-settings-overrides.js
+++ b/browser/components/extensions/parent/ext-chrome-settings-overrides.js
@@ -56,7 +56,7 @@ ChromeUtils.defineLazyGetter(this, "homepagePopup", () => {
Services.prefs.addObserver(HOMEPAGE_PREF, async function prefObserver() {
Services.prefs.removeObserver(HOMEPAGE_PREF, prefObserver);
let loaded = waitForTabLoaded(tab);
- win.BrowserHome();
+ win.BrowserCommands.home();
await loaded;
// Manually trigger an event in case this is controlled again.
popup.open();
diff --git a/browser/components/extensions/parent/ext-commands.js b/browser/components/extensions/parent/ext-commands.js
index 328f05a802..5b2b5f11b2 100644
--- a/browser/components/extensions/parent/ext-commands.js
+++ b/browser/components/extensions/parent/ext-commands.js
@@ -13,8 +13,13 @@ ChromeUtils.defineESModuleGetters(this, {
this.commands = class extends ExtensionAPIPersistent {
PERSISTENT_EVENTS = {
onCommand({ fire }) {
+ const { extension } = this;
+ const { tabManager } = extension;
+
let listener = (eventName, commandName) => {
- fire.async(commandName);
+ let nativeTab = tabTracker.activeTab;
+ tabManager.addActiveTabPermission(nativeTab);
+ fire.async(commandName, tabManager.convert(nativeTab));
};
this.on("command", listener);
return {
diff --git a/browser/components/extensions/parent/ext-devtools-panels.js b/browser/components/extensions/parent/ext-devtools-panels.js
index 6b83ea5dbb..4b88b91eab 100644
--- a/browser/components/extensions/parent/ext-devtools-panels.js
+++ b/browser/components/extensions/parent/ext-devtools-panels.js
@@ -104,20 +104,21 @@ class BaseDevToolsPanel {
/**
* Represents an addon devtools panel in the main process.
- *
- * @param {ExtensionChildProxyContext} context
- * A devtools extension proxy context running in a main process.
- * @param {object} options
- * @param {string} options.id
- * The id of the addon devtools panel.
- * @param {string} options.icon
- * The icon of the addon devtools panel.
- * @param {string} options.title
- * The title of the addon devtools panel.
- * @param {string} options.url
- * The url of the addon devtools panel, relative to the extension base URL.
*/
class ParentDevToolsPanel extends BaseDevToolsPanel {
+ /**
+ * @param {DevToolsExtensionPageContextParent} context
+ * A devtools extension proxy context running in a main process.
+ * @param {object} panelOptions
+ * @param {string} panelOptions.id
+ * The id of the addon devtools panel.
+ * @param {string} panelOptions.icon
+ * The icon of the addon devtools panel.
+ * @param {string} panelOptions.title
+ * The title of the addon devtools panel.
+ * @param {string} panelOptions.url
+ * The url of the addon devtools panel, relative to the extension base URL.
+ */
constructor(context, panelOptions) {
super(context, panelOptions);
@@ -339,16 +340,17 @@ class DevToolsSelectionObserver extends EventEmitter {
/**
* Represents an addon devtools inspector sidebar in the main process.
- *
- * @param {ExtensionChildProxyContext} context
- * A devtools extension proxy context running in a main process.
- * @param {object} options
- * @param {string} options.id
- * The id of the addon devtools sidebar.
- * @param {string} options.title
- * The title of the addon devtools sidebar.
*/
class ParentDevToolsInspectorSidebar extends BaseDevToolsPanel {
+ /**
+ * @param {DevToolsExtensionPageContextParent} context
+ * A devtools extension proxy context running in a main process.
+ * @param {object} panelOptions
+ * @param {string} panelOptions.id
+ * The id of the addon devtools sidebar.
+ * @param {string} panelOptions.title
+ * The title of the addon devtools sidebar.
+ */
constructor(context, panelOptions) {
super(context, panelOptions);
diff --git a/browser/components/extensions/parent/ext-tabs.js b/browser/components/extensions/parent/ext-tabs.js
index 128a42439b..4b8d296d67 100644
--- a/browser/components/extensions/parent/ext-tabs.js
+++ b/browser/components/extensions/parent/ext-tabs.js
@@ -1026,7 +1026,13 @@ this.tabs = class extends ExtensionAPIPersistent {
? windowTracker.getTopWindow(context)
: windowTracker.getWindow(windowId, context);
- let tab = tabManager.wrapTab(window.gBrowser.selectedTab);
+ let tab = tabManager.getWrapper(window.gBrowser.selectedTab);
+ if (
+ !extension.hasPermission("<all_urls>") &&
+ !tab.hasActiveTabPermission
+ ) {
+ throw new ExtensionError("Missing activeTab permission");
+ }
await tabListener.awaitTabReady(tab.nativeTab);
let zoom = window.ZoomManager.getZoomForBrowser(
diff --git a/browser/components/extensions/schemas/commands.json b/browser/components/extensions/schemas/commands.json
index 19e8e122f9..30942d0aab 100644
--- a/browser/components/extensions/schemas/commands.json
+++ b/browser/components/extensions/schemas/commands.json
@@ -104,6 +104,12 @@
{
"name": "command",
"type": "string"
+ },
+ {
+ "name": "tab",
+ "$ref": "tags.Tab",
+ "optional": true,
+ "description": "Details of the $(ref:tabs.Tab) where the command was activated."
}
]
},
diff --git a/browser/components/extensions/schemas/tabs.json b/browser/components/extensions/schemas/tabs.json
index ee7cd3dd93..55fccee0b5 100644
--- a/browser/components/extensions/schemas/tabs.json
+++ b/browser/components/extensions/schemas/tabs.json
@@ -1198,8 +1198,8 @@
{
"name": "captureVisibleTab",
"type": "function",
- "description": "Captures an area of the currently active tab in the specified window. You must have $(topic:declare_permissions)[&lt;all_urls&gt;] permission to use this method.",
- "permissions": ["<all_urls>"],
+ "description": "Captures an area of the currently active tab in the specified window. You must have &lt;all_urls&gt; or activeTab permission to use this method.",
+ "permissions": ["<all_urls>", "activeTab"],
"async": "callback",
"parameters": [
{
diff --git a/browser/components/extensions/test/browser/browser.toml b/browser/components/extensions/test/browser/browser.toml
index 417bad7e31..570a51eeb4 100644
--- a/browser/components/extensions/test/browser/browser.toml
+++ b/browser/components/extensions/test/browser/browser.toml
@@ -46,10 +46,13 @@ support-files = [
"empty.xpi",
"../../../../../toolkit/components/extensions/test/mochitest/head_webrequest.js",
"../../../../../toolkit/components/extensions/test/mochitest/redirection.sjs",
- "../../../../../toolkit/components/reader/test/readerModeNonArticle.html",
- "../../../../../toolkit/components/reader/test/readerModeArticle.html",
+ "../../../../../toolkit/components/reader/tests/browser/readerModeNonArticle.html",
+ "../../../../../toolkit/components/reader/tests/browser/readerModeArticle.html",
+]
+skip-if = [
+ "os == 'linux' && os_version == '18.04' && asan", # Bug 1721945 - Software WebRender
+ "os == 'linux' && os_version == '18.04' && tsan", # manifest runs too long
]
-skip-if = ["os == 'linux' && os_version == '18.04' && asan"] # Bug 1721945 - Software WebRender
["browser_AMBrowserExtensionsImport.js"]
@@ -700,7 +703,6 @@ tags = "fullscreen"
["browser_toolbar_prefers_color_scheme.js"]
["browser_unified_extensions.js"]
-fail-if = ["a11y_checks"] # Bug 1854460 clicked browser may not be accessible
["browser_unified_extensions_accessibility.js"]
diff --git a/browser/components/extensions/test/browser/browser_ext_browserAction_context.js b/browser/components/extensions/test/browser/browser_ext_browserAction_context.js
index e5d315c5d2..a55952e610 100644
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_context.js
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_context.js
@@ -184,7 +184,11 @@ async function runTests(options) {
is(getListStyleImage(button), details.icon, "icon URL is correct");
is(button.getAttribute("tooltiptext"), title, "image title is correct");
is(button.getAttribute("label"), title, "image label is correct");
- is(button.getAttribute("badge"), details.badge, "badge text is correct");
+ is(
+ button.getAttribute("badge") || "",
+ details.badge,
+ "badge text is correct"
+ );
is(
button.getAttribute("disabled") == "true",
!details.enabled,
diff --git a/browser/components/extensions/test/browser/browser_ext_browserAction_contextMenu.js b/browser/components/extensions/test/browser/browser_ext_browserAction_contextMenu.js
index 8e89457904..26d1536de1 100644
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_contextMenu.js
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_contextMenu.js
@@ -430,9 +430,6 @@ async function browseraction_contextmenu_remove_extension_helper() {
},
useAddonManager: "temporary",
});
- let brand = Services.strings
- .createBundle("chrome://branding/locale/brand.properties")
- .GetStringFromName("brandShorterName");
let { prompt } = Services;
let promptService = {
_response: 1,
@@ -466,9 +463,6 @@ async function browseraction_contextmenu_remove_extension_helper() {
await closeChromeContextMenu(menuId, removeExtension);
let args = await confirmArgs;
is(args[1], `Remove ${name}?`);
- if (!Services.prefs.getBoolPref("prompts.windowPromptSubDialog", false)) {
- is(args[2], `Remove ${name} from ${brand}?`);
- }
is(args[4], "Remove");
return menu;
}
diff --git a/browser/components/extensions/test/browser/browser_ext_browserAction_popup_preload_smoketest.js b/browser/components/extensions/test/browser/browser_ext_browserAction_popup_preload_smoketest.js
index 98e66e6c7a..289cbf8a88 100644
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_popup_preload_smoketest.js
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_popup_preload_smoketest.js
@@ -50,7 +50,7 @@ async function installTestAddon(addonId, unpacked = false) {
// 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 = `mochitest_unpacked_addons_${random}`;
let tmpExtPath = FileUtils.getDir("TmpD", [tmpDirName]);
diff --git a/browser/components/extensions/test/browser/browser_ext_chrome_settings_overrides_home.js b/browser/components/extensions/test/browser/browser_ext_chrome_settings_overrides_home.js
index b67952c03c..1c9ee9a6c1 100644
--- a/browser/components/extensions/test/browser/browser_ext_chrome_settings_overrides_home.js
+++ b/browser/components/extensions/test/browser/browser_ext_chrome_settings_overrides_home.js
@@ -388,7 +388,7 @@ add_task(async function test_doorhanger_homepage_button() {
await ext2.startup();
let popupShown = promisePopupShown(panel);
- BrowserHome();
+ BrowserCommands.home();
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, () =>
gURLBar.value.endsWith("ext2.html")
);
@@ -410,7 +410,7 @@ add_task(async function test_doorhanger_homepage_button() {
popupShown = promisePopupShown(panel);
await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
let openHomepage = TestUtils.topicObserved("browser-open-homepage-start");
- BrowserHome();
+ BrowserCommands.home();
await openHomepage;
await popupShown;
await TestUtils.waitForCondition(
@@ -432,7 +432,7 @@ add_task(async function test_doorhanger_homepage_button() {
BrowserTestUtils.removeTab(gBrowser.selectedTab);
openHomepage = TestUtils.topicObserved("browser-open-homepage-start");
- BrowserHome();
+ BrowserCommands.home();
await openHomepage;
is(getHomePageURL(), defaultHomePage, "The homepage is set back to default");
@@ -507,7 +507,7 @@ add_task(async function test_doorhanger_new_window() {
let popupShown = promisePopupShown(panel);
await BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:blank");
let openHomepage = TestUtils.topicObserved("browser-open-homepage-start");
- win.BrowserHome();
+ win.BrowserCommands.home();
await openHomepage;
await popupShown;
@@ -547,7 +547,7 @@ async function testHomePageWindow(options = {}) {
let panel = ExtensionControlledPopup._getAndMaybeCreatePanel(doc);
let popupShown = options.expectPanel && promisePopupShown(panel);
- win.BrowserHome();
+ win.BrowserCommands.home();
await Promise.all([
BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser),
openHomepage,
diff --git a/browser/components/extensions/test/browser/browser_ext_commands_onCommand.js b/browser/components/extensions/test/browser/browser_ext_commands_onCommand.js
index db900f7ea4..abde8f90f7 100644
--- a/browser/components/extensions/test/browser/browser_ext_commands_onCommand.js
+++ b/browser/components/extensions/test/browser/browser_ext_commands_onCommand.js
@@ -226,7 +226,16 @@ add_task(async function test_user_defined_commands() {
}
function background() {
- browser.commands.onCommand.addListener(commandName => {
+ browser.commands.onCommand.addListener(async (commandName, tab) => {
+ let [expectedTab] = await browser.tabs.query({
+ currentWindow: true,
+ active: true,
+ });
+ browser.test.assertEq(
+ tab.id,
+ expectedTab.id,
+ "Expected onCommand listener to pass the current tab"
+ );
browser.test.sendMessage("oncommand", commandName);
});
browser.test.sendMessage("ready");
@@ -408,8 +417,9 @@ add_task(async function test_commands_event_page() {
},
},
background() {
- browser.commands.onCommand.addListener(name => {
+ browser.commands.onCommand.addListener((name, tab) => {
browser.test.assertEq(name, "toggle-feature", "command received");
+ browser.test.assertTrue(!!tab, "tab received");
browser.test.sendMessage("onCommand");
});
browser.test.sendMessage("ready");
diff --git a/browser/components/extensions/test/browser/browser_ext_contentscript_nontab_connect.js b/browser/components/extensions/test/browser/browser_ext_contentscript_nontab_connect.js
index 548c35399f..33ad85f268 100644
--- a/browser/components/extensions/test/browser/browser_ext_contentscript_nontab_connect.js
+++ b/browser/components/extensions/test/browser/browser_ext_contentscript_nontab_connect.js
@@ -8,11 +8,17 @@ function extensionScript() {
let FRAME_URL = browser.runtime.getManifest().content_scripts[0].matches[0];
// Cannot use :8888 in the manifest because of bug 1468162.
FRAME_URL = FRAME_URL.replace("mochi.test", "mochi.test:8888");
+ let FRAME_ORIGIN = new URL(FRAME_URL).origin;
browser.runtime.onConnect.addListener(port => {
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");
diff --git a/browser/components/extensions/test/browser/browser_ext_contentscript_sender_url.js b/browser/components/extensions/test/browser/browser_ext_contentscript_sender_url.js
index f751c3c202..08f19013c4 100644
--- a/browser/components/extensions/test/browser/browser_ext_contentscript_sender_url.js
+++ b/browser/components/extensions/test/browser/browser_ext_contentscript_sender_url.js
@@ -2,12 +2,16 @@
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
+const FILE_URL = Services.io.newFileURI(
+ new FileUtils.File(getTestFilePath("file_dummy.html"))
+).spec;
+
add_task(async function test_sender_url() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
content_scripts: [
{
- matches: ["http://mochi.test/*"],
+ matches: ["http://mochi.test/*", "file:///*"],
run_at: "document_start",
js: ["script.js"],
},
@@ -18,6 +22,7 @@ add_task(async function test_sender_url() {
browser.runtime.onMessage.addListener((msg, sender) => {
browser.test.log("Message received.");
browser.test.sendMessage("sender.url", sender.url);
+ browser.test.sendMessage("sender.origin", sender.origin);
});
},
@@ -53,6 +58,9 @@ add_task(async function test_sender_url() {
let url = await extension.awaitMessage("sender.url");
is(url, image, `Correct sender.url: ${url}`);
+ let origin = await extension.awaitMessage("sender.origin");
+ is(origin, "http://mochi.test:8888", `Correct sender.origin: ${origin}`);
+
let wentBack = awaitNewTab();
await browser.goBack();
await wentBack;
@@ -60,6 +68,17 @@ add_task(async function test_sender_url() {
await browser.goForward();
url = await extension.awaitMessage("sender.url");
is(url, image, `Correct sender.url: ${url}`);
+
+ origin = await extension.awaitMessage("sender.origin");
+ is(origin, "http://mochi.test:8888", `Correct sender.origin: ${origin}`);
+ });
+
+ await BrowserTestUtils.withNewTab(FILE_URL, async () => {
+ let url = await extension.awaitMessage("sender.url");
+ ok(url.endsWith("/file_dummy.html"), `Correct sender.url: ${url}`);
+
+ let origin = await extension.awaitMessage("sender.origin");
+ is(origin, "null", `Correct sender.origin: ${origin}`);
});
await extension.unload();
diff --git a/browser/components/extensions/test/browser/browser_ext_contextMenus_icons.js b/browser/components/extensions/test/browser/browser_ext_contextMenus_icons.js
index 30d4d528b2..cb81d9a93b 100644
--- a/browser/components/extensions/test/browser/browser_ext_contextMenus_icons.js
+++ b/browser/components/extensions/test/browser/browser_ext_contextMenus_icons.js
@@ -269,7 +269,7 @@ add_task(async function test_manifest_without_icons() {
let items = menu.getElementsByAttribute("label", "first item");
is(items.length, 1, "Found first item");
// manifest.json does not declare icons, so the root menu item shouldn't have an icon either.
- is(items[0].getAttribute("image"), "", "Root menu must not have an icon");
+ is(items[0].getAttribute("image"), null, "Root menu must not have an icon");
await closeExtensionContextMenu(items[0]);
await extension.awaitMessage("added-second-item");
@@ -281,7 +281,7 @@ add_task(async function test_manifest_without_icons() {
is(items.length, 1, "Auto-generated root item exists");
is(
items[0].getAttribute("image"),
- "",
+ null,
"Auto-generated menu root must not have an icon"
);
@@ -464,7 +464,7 @@ add_task(async function test_child_icon_update() {
contextMenuChild2 = contextMenu.getElementsByAttribute("label", "child2")[0];
is(
contextMenuChild2.getAttribute("image"),
- "",
+ null,
"Second child should not have an icon"
);
diff --git a/browser/components/extensions/test/browser/browser_ext_tabs_onCreated.js b/browser/components/extensions/test/browser/browser_ext_tabs_onCreated.js
index 0004f60853..014b6dddf2 100644
--- a/browser/components/extensions/test/browser/browser_ext_tabs_onCreated.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_onCreated.js
@@ -26,7 +26,7 @@ add_task(async function test_onCreated_active() {
await extension.startup();
await extension.awaitMessage("ready");
- BrowserOpenTab();
+ BrowserCommands.openTab();
let tab = await extension.awaitMessage("onCreated");
is(true, tab.active, "Tab should be active");
diff --git a/browser/components/extensions/test/browser/browser_ext_url_overrides_newtab.js b/browser/components/extensions/test/browser/browser_ext_url_overrides_newtab.js
index 988f44bd5d..a3ccc5a521 100644
--- a/browser/components/extensions/test/browser/browser_ext_url_overrides_newtab.js
+++ b/browser/components/extensions/test/browser/browser_ext_url_overrides_newtab.js
@@ -45,7 +45,7 @@ async function promiseNewTab(expectUrl = AboutNewTab.newTabURL, win = window) {
`Should open correct new tab url ${expectUrl}.`
);
- win.BrowserOpenTab();
+ win.BrowserCommands.openTab();
const newTabCreatedPromise = newTabStartPromise;
const browser = await newTabCreatedPromise;
await newtabShown;
diff --git a/browser/components/extensions/test/browser/browser_unified_extensions.js b/browser/components/extensions/test/browser/browser_unified_extensions.js
index 7ab7753c0e..2c65f47c4e 100644
--- a/browser/components/extensions/test/browser/browser_unified_extensions.js
+++ b/browser/components/extensions/test/browser/browser_unified_extensions.js
@@ -1222,7 +1222,11 @@ add_task(async function test_hover_message_when_button_updates_itself() {
// Move cursor to the center of the entire browser UI to avoid issues with
// other focus/hover checks. We do this to avoid intermittent test failures.
+ // We intentionally turn off this a11y check, because the following click
+ // is purposefully targeting a non-interactive content of the page.
+ AccessibilityUtils.setEnv({ mustHaveAccessibleRule: false });
EventUtils.synthesizeMouseAtCenter(document.documentElement, {});
+ AccessibilityUtils.resetEnv();
await extension.unload();
});