Bug 1358213 - Give WebExtension created menuitems in the context menu an ID. r?kmag draft
authorMark Banner <standard8@mozilla.com>
Thu, 20 Apr 2017 20:48:16 +0100
changeset 566809 d377a8f405038cb4df394d495ce1856c010000d4
parent 566789 8e969cc9aff49f845678cba5b35d9dd8aa340f16
child 625434 2b9854bb7b013fa51c0ceda1d7411c5d7c7f76c7
push id55345
push userbmo:standard8@mozilla.com
push dateSun, 23 Apr 2017 20:41:09 +0000
reviewerskmag
bugs1358213
milestone55.0a1
Bug 1358213 - Give WebExtension created menuitems in the context menu an ID. r?kmag This matches the rest of the context menu and is better for unit tests. MozReview-Commit-ID: 509HH4wnClN
browser/components/extensions/ext-contextMenus.js
browser/components/extensions/test/browser/browser_ext_contextMenus_chrome.js
--- a/browser/components/extensions/ext-contextMenus.js
+++ b/browser/components/extensions/ext-contextMenus.js
@@ -189,16 +189,21 @@ var gMenuBuilder = {
           selection = selection.substring(0, maxSelectionLength - 3) + "...";
         }
         label = label.replace(/%s/g, selection);
       }
 
       element.setAttribute("label", label);
     }
 
+    if (item.id && item.extension && item.extension.id) {
+      element.setAttribute("id",
+        `${makeWidgetId(item.extension.id)}_${item.id}`);
+    }
+
     if (item.type == "checkbox") {
       element.setAttribute("type", "checkbox");
       if (item.checked) {
         element.setAttribute("checked", "true");
       }
     } else if (item.type == "radio") {
       element.setAttribute("type", "radio");
       element.setAttribute("name", item.groupName);
--- a/browser/components/extensions/test/browser/browser_ext_contextMenus_chrome.js
+++ b/browser/components/extensions/test/browser/browser_ext_contextMenus_chrome.js
@@ -13,17 +13,17 @@ add_task(function* test_actionContextMen
   async function background() {
     const contexts = ["page_action", "browser_action"];
 
     const parentId = browser.contextMenus.create({contexts, title: "parent"});
     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}`});
+      await browser.contextMenus.create({contexts, id: `${i}`, title: `click ${i}`});
     }
 
     browser.contextMenus.onClicked.addListener((info, tab) => {
       browser.test.sendMessage("click", {info, tab});
     });
 
     const [tab] = await browser.tabs.query({active: true});
     await browser.pageAction.show(tab.id);
@@ -42,20 +42,24 @@ add_task(function* test_actionContextMen
 
     is(submenu.tagName, "menu", "Correct submenu type");
     is(submenu.label, "parent", "Correct submenu title");
 
     const popup = yield openSubmenu(submenu);
     is(popup, submenu.firstChild, "Correct submenu opened");
     is(popup.children.length, 2, "Correct number of submenu items");
 
+    let idPrefix = `${makeWidgetId(extension.id)}_`;
+
     is(second.tagName, "menuitem", "Second menu item type is correct");
     is(second.label, "click 1", "Second menu item title is correct");
+    is(second.id, `${idPrefix}1`, "Second menu item id is correct");
 
     is(last.label, "click 5", "Last menu item title is correct");
+    is(last.id, `${idPrefix}5`, "Last menu item id is correct");
     is(separator.tagName, "menuseparator", "Separator after last menu item");
 
     yield closeActionContextMenu(popup.firstChild);
     const {info, tab} = yield extension.awaitMessage("click");
     is(info.pageUrl, "http://example.com/", "Click info pageUrl is correct");
     is(tab.id, tabId, "Click event tab ID is correct");
   }