Bug 1359704 - "page" context items should not appear in "tab" context. r=mixedpuppy, a=gchang
authorTomislav Jovanovic <tomica@gmail.com>
Thu, 27 Apr 2017 15:59:32 +0200
changeset 396096 fe9c7ccfd5fb004a20153fe925fac3a2cd0e85f8
parent 396095 7d4d2b3c80021631958ba58fb086de69777d76b6
child 396097 4c630b9a7d2f7bce143ea7ffcd9a42b44de59d2c
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy, gchang
bugs1359704
milestone54.0
Bug 1359704 - "page" context items should not appear in "tab" context. r=mixedpuppy, a=gchang MozReview-Commit-ID: 9Lz8ZzzbNhq
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
@@ -306,23 +306,26 @@ function getContexts(contextData) {
   if (contextData.onPageAction) {
     contexts.add("page_action");
   }
 
   if (contextData.onBrowserAction) {
     contexts.add("browser_action");
   }
 
+  if (contextData.onTab) {
+    contexts.add("tab");
+  }
+
   if (contexts.size === 0) {
     contexts.add("page");
   }
 
-  if (contextData.onTab) {
-    contexts.add("tab");
-  } else {
+  // New non-content contexts supported in Firefox are not part of "all".
+  if (!contextData.onTab) {
     contexts.add("all");
   }
 
   return contexts;
 }
 
 function MenuItem(extension, createProperties, isRoot = false) {
   this.extension = extension;
--- a/browser/components/extensions/test/browser/browser_ext_contextMenus_chrome.js
+++ b/browser/components/extensions/test/browser/browser_ext_contextMenus_chrome.js
@@ -67,19 +67,22 @@ add_task(function* test_tabContextMenu()
   const first = ExtensionTestUtils.loadExtension({
     manifest: {
       permissions: ["contextMenus"],
     },
     async background() {
       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"});
 
+      await browser.contextMenus.create({title: "dummy", contexts: ["page"]});
+
       browser.contextMenus.onClicked.addListener((info, tab) => {
         browser.test.sendMessage("click", {info, tab});
       });
 
       const [tab] = await browser.tabs.query({active: true});
       browser.test.sendMessage("ready", tab.id);
     },
   });
@@ -103,16 +106,18 @@ add_task(function* test_tabContextMenu()
 
   const menu = yield openTabContextMenu();
   const [separator, submenu, gamma] = Array.from(menu.children).slice(-3);
   is(separator.tagName, "menuseparator", "Separator before first extension item");
 
   is(submenu.tagName, "menu", "Correct submenu type");
   is(submenu.label, "alpha-beta parent", "Correct submenu title");
 
+  isnot(gamma.label, "dummy", "`page` context menu item should not appear here");
+
   is(gamma.tagName, "menuitem", "Third menu item type is correct");
   is(gamma.label, "gamma", "Third menu item label is correct");
 
   const popup = yield openSubmenu(submenu);
   is(popup, submenu.firstChild, "Correct submenu opened");
   is(popup.children.length, 2, "Correct number of submenu items");
 
   const [alpha, beta] = popup.children;