Bug 1435992 - Disabled page actions still show extension context menu items. r?mixedpuppy
MozReview-Commit-ID: JmC6PXtW1SK
--- a/browser/components/extensions/ext-pageAction.js
+++ b/browser/components/extensions/ext-pageAction.js
@@ -184,17 +184,18 @@ this.pageAction = class extends Extensio
handleEvent(event) {
switch (event.type) {
case "popupshowing":
const menu = event.target;
const trigger = menu.triggerNode;
if (menu.id === "pageActionContextMenu" &&
trigger &&
- trigger.getAttribute("actionid") === this.browserPageAction.id) {
+ trigger.getAttribute("actionid") === this.browserPageAction.id &&
+ !this.browserPageAction.getDisabled(trigger.ownerGlobal)) {
global.actionContextMenu({
extension: this.extension,
onPageAction: true,
menu: menu,
});
}
break;
}
--- a/browser/components/extensions/test/browser/browser_ext_menus.js
+++ b/browser/components/extensions/test/browser/browser_ext_menus.js
@@ -1,15 +1,26 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const PAGE = "http://mochi.test:8888/browser/browser/components/extensions/test/browser/context.html";
+async function openContextMenuInPageActionPanel(extension, win = window) {
+ SetPageProxyState("valid");
+ await promiseAnimationFrame(win);
+ const mainPanelshown = BrowserTestUtils.waitForEvent(BrowserPageActions.panelNode, "popupshown");
+ EventUtils.synthesizeMouseAtCenter(BrowserPageActions.mainButtonNode, {}, win);
+ await mainPanelshown;
+ let buttonID = "#" + BrowserPageActions.panelButtonNodeIDForActionID(makeWidgetId(extension.id));
+ let menuID = "pageActionContextMenu";
+ return openChromeContextMenu(menuID, buttonID, win);
+}
+
add_task(async function test_permissions() {
function background() {
browser.test.sendMessage("apis", {
menus: typeof browser.menus,
contextMenus: typeof browser.contextMenus,
menusInternal: typeof browser.menusInternal,
});
}
@@ -94,16 +105,63 @@ add_task(async function test_actionConte
is(info.pageUrl, "http://example.com/", "Click info pageUrl is correct");
is(tab.id, tabId, "Click event tab ID is correct");
}
await BrowserTestUtils.removeTab(tab);
await extension.unload();
});
+add_task(async function test_hiddenPageActionContextMenu() {
+ const manifest = {
+ page_action: {},
+ permissions: ["menus"],
+ };
+
+ async function background() {
+ const contexts = ["page_action"];
+
+ const parentId = browser.menus.create({contexts, title: "parent"});
+ await browser.menus.create({parentId, title: "click A"});
+ await browser.menus.create({parentId, title: "click B"});
+
+ for (let i = 1; i < 9; i++) {
+ await browser.menus.create({contexts, id: `${i}`, title: `click ${i}`});
+ }
+
+ const [tab] = await browser.tabs.query({active: true});
+ await browser.pageAction.hide(tab.id);
+ browser.test.sendMessage("ready", tab.id);
+ }
+
+ const extension = ExtensionTestUtils.loadExtension({manifest, background});
+ const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com/");
+
+ await extension.startup();
+ await extension.awaitMessage("ready");
+
+ const menu = await openContextMenuInPageActionPanel(extension);
+ const menuItems = Array.filter(menu.childNodes, node => {
+ return window.getComputedStyle(node).visibility == "visible";
+ });
+
+ is(menuItems.length, 3, "Correct number of children");
+ const [dontShowItem, separator, manageItem] = menuItems;
+
+ is(dontShowItem.label, "Don\u2019t Show in Address Bar", "Correct first child");
+ is(separator.tagName, "menuseparator", "Correct second child");
+ is(manageItem.label, "Manage Extension\u2026", "Correct third child");
+
+ await closeChromeContextMenu(menu.id);
+ await closeChromeContextMenu(BrowserPageActions.panelNode.id);
+
+ await BrowserTestUtils.removeTab(tab);
+ await extension.unload();
+});
+
add_task(async function test_tabContextMenu() {
const first = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["menus"],
},
async background() {
await browser.menus.create({
id: "alpha-beta-parent", title: "alpha-beta parent", contexts: ["tab"],