Bug 1324429 - Context menu items without contexts should inherit it from their parent. r=kmag

MozReview-Commit-ID: 9BKDdFZ6Hdd

--HG--
extra : rebase_source : 79d6fdc46caa0599160e2f797e103c0bf179c3e1
This commit is contained in:
Luca Greco 2016-12-21 16:44:30 -05:00
parent 0fb5c6dc68
commit 60d15646a3
2 changed files with 15 additions and 5 deletions

View File

@ -324,6 +324,7 @@ function MenuItem(extension, createProperties, isRoot = false) {
this.setDefaults();
this.setProps(createProperties);
if (!this.hasOwnProperty("_id")) {
this.id = gNextMenuItemID++;
}
@ -351,6 +352,12 @@ MenuItem.prototype = {
if (createProperties.targetUrlPatterns != null) {
this.targetUrlMatchPattern = new MatchPattern(this.targetUrlPatterns);
}
// If a child MenuItem does not specify any contexts, then it should
// inherit the contexts specified from its parent.
if (createProperties.parentId && !createProperties.contexts) {
this.contexts = this.parent.contexts;
}
},
setDefaults() {

View File

@ -14,8 +14,8 @@ add_task(function* test_actionContextMenus() {
const contexts = ["page_action", "browser_action"];
const parentId = browser.contextMenus.create({contexts, title: "parent"});
await browser.contextMenus.create({contexts, parentId, title: "click A"});
await browser.contextMenus.create({contexts, parentId, title: "click B"});
await browser.contextMenus.create({parentId, title: "click A"});
await browser.contextMenus.create({parentId, title: "click B"});
for (let i = 1; i < 9; i++) {
await browser.contextMenus.create({contexts, title: `click ${i}`});
@ -69,8 +69,11 @@ add_task(function* test_tabContextMenu() {
permissions: ["contextMenus"],
},
async background() {
await browser.contextMenus.create({title: "alpha", contexts: ["tab"]});
await browser.contextMenus.create({title: "beta", contexts: ["tab"]});
await browser.contextMenus.create({
id: "alpha-beta-parent", title: "alpha-beta parent", contexts: ["tab"],
});
await browser.contextMenus.create({parentId: "alpha-beta-parent", title: "alpha"});
await browser.contextMenus.create({parentId: "alpha-beta-parent", title: "beta"});
browser.contextMenus.onClicked.addListener((info, tab) => {
browser.test.sendMessage("click", {info, tab});
@ -103,7 +106,7 @@ add_task(function* test_tabContextMenu() {
is(separator.tagName, "menuseparator", "Separator before first extension item");
is(submenu.tagName, "menu", "Correct submenu type");
is(submenu.label, "Generated extension", "Correct submenu title");
is(submenu.label, "alpha-beta parent", "Correct submenu title");
is(gamma.tagName, "menuitem", "Third menu item type is correct");
is(gamma.label, "gamma", "Third menu item label is correct");