Bug 1482529 - Support "visible" in menus.create and menus.update r=mixedpuppy

Differential Revision: https://phabricator.services.mozilla.com/D3794

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Rob Wu 2018-08-20 15:16:09 +00:00
Родитель 76da0cced6
Коммит 3a260706b3
4 изменённых файлов: 101 добавлений и 0 удалений

Просмотреть файл

@ -580,6 +580,7 @@ MenuItem.prototype = {
checked: false,
contexts: ["all"],
enabled: true,
visible: true,
});
},
@ -708,6 +709,9 @@ MenuItem.prototype = {
},
enabledForContext(contextData) {
if (!this.visible) {
return false;
}
let contexts = getMenuContexts(contextData);
if (!this.contexts.some(n => contexts.has(n))) {
return false;

Просмотреть файл

@ -197,6 +197,11 @@
"optional": true,
"description": "List of contexts this menu item will appear in. Defaults to ['page'] if not specified."
},
"visible": {
"type": "boolean",
"optional": true,
"description": "Whether the item is visible in the menu."
},
"onclick": {
"type": "function",
"optional": true,
@ -294,6 +299,11 @@
"minItems": 1,
"optional": true
},
"visible": {
"type": "boolean",
"optional": true,
"description": "Whether the item is visible in the menu."
},
"onclick": {
"type": "function",
"optional": "omit-key-if-missing",

Просмотреть файл

@ -115,6 +115,7 @@ skip-if = (verify && (os == 'linux' || os == 'mac'))
[browser_ext_menus_targetElement.js]
[browser_ext_menus_targetElement_extension.js]
[browser_ext_menus_targetElement_shadow.js]
[browser_ext_menus_visible.js]
[browser_ext_omnibox.js]
[browser_ext_openPanel.js]
skip-if = (verify && !debug && (os == 'linux' || os == 'mac'))

Просмотреть файл

@ -0,0 +1,86 @@
/* 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";
add_task(async function visible_false() {
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE);
async function background() {
browser.menus.onShown.addListener(info => {
browser.test.assertEq("[]", JSON.stringify(info.menuIds), "Expected no menu items");
browser.test.sendMessage("done");
});
browser.menus.create({
id: "create-visible-false",
title: "invisible menu item",
visible: false,
});
browser.menus.create({
id: "update-without-params",
title: "invisible menu item",
visible: false,
});
await browser.menus.update("update-without-params", {});
browser.menus.create({
id: "update-visible-to-false",
title: "initially visible menu item",
});
await browser.menus.update("update-visible-to-false", {visible: false});
browser.test.sendMessage("ready");
}
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["menus"],
},
background,
});
await extension.startup();
await extension.awaitMessage("ready");
await openContextMenu();
await extension.awaitMessage("done");
await closeContextMenu();
await extension.unload();
BrowserTestUtils.removeTab(tab);
});
add_task(async function visible_true() {
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE);
async function background() {
browser.menus.onShown.addListener(info => {
browser.test.assertEq(`["update-to-true"]`, JSON.stringify(info.menuIds), "Expected no menu items");
browser.test.sendMessage("done");
});
browser.menus.create({
id: "update-to-true",
title: "invisible menu item",
visible: false,
});
await browser.menus.update("update-to-true", {visible: true});
browser.test.sendMessage("ready");
}
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["menus"],
},
background,
});
await extension.startup();
await extension.awaitMessage("ready");
await openContextMenu();
await extension.awaitMessage("done");
await closeContextMenu();
await extension.unload();
BrowserTestUtils.removeTab(tab);
});