Bug 1274860 - Modify getContexts function so that page context is applied properly. r=kmag
authordjmdev <djmdeveloper060796@gmail.com>
Fri, 11 Nov 2016 17:49:44 +0530
changeset 348851 49d1c7361c57ac096cf28b76a0d9cf887c83a417
parent 348850 d1ef75d52b01dbd1f3185084836f48fda8262691
child 348852 606c7cb149c9609edf694e571922af7cbc8175e7
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1274860
milestone52.0a1
Bug 1274860 - Modify getContexts function so that page context is applied properly. r=kmag
browser/components/extensions/ext-contextMenus.js
browser/components/extensions/test/browser/browser_ext_contextMenus.js
--- a/browser/components/extensions/ext-contextMenus.js
+++ b/browser/components/extensions/ext-contextMenus.js
@@ -218,18 +218,16 @@ var gMenuBuilder = {
 function contextMenuObserver(subject, topic, data) {
   subject = subject.wrappedJSObject;
   gMenuBuilder.build(subject);
 }
 
 function getContexts(contextData) {
   let contexts = new Set(["all"]);
 
-  contexts.add("page");
-
   if (contextData.inFrame) {
     contexts.add("frame");
   }
 
   if (contextData.isTextSelected) {
     contexts.add("selection");
   }
 
@@ -248,16 +246,20 @@ function getContexts(contextData) {
   if (contextData.onVideo) {
     contexts.add("video");
   }
 
   if (contextData.onAudio) {
     contexts.add("audio");
   }
 
+  if (contexts.size == 1) {
+    contexts.add("page");
+  }
+
   return contexts;
 }
 
 function MenuItem(extension, createProperties, isRoot = false) {
   this.extension = extension;
   this.children = [];
   this.parent = null;
   this.tabManager = TabManager.for(extension);
--- a/browser/components/extensions/test/browser/browser_ext_contextMenus.js
+++ b/browser/components/extensions/test/browser/browser_ext_contextMenus.js
@@ -11,35 +11,40 @@ add_task(function* () {
 
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       "permissions": ["contextMenus"],
     },
 
     background: function() {
       browser.contextMenus.create({
-        id: "clickme",
+        id: "clickme-image",
         title: "Click me!",
         contexts: ["image"],
       });
+      browser.contextMenus.create({
+        id: "clickme-page",
+        title: "Click me!",
+        contexts: ["page"],
+      });
       browser.test.notifyPass();
     },
   });
 
   yield extension.startup();
   yield extension.awaitFinish();
 
   let contentAreaContextMenu = yield openContextMenu("#img1");
   let item = contentAreaContextMenu.getElementsByAttribute("label", "Click me!");
   is(item.length, 1, "contextMenu item for image was found");
   yield closeContextMenu();
 
   contentAreaContextMenu = yield openContextMenu("body");
   item = contentAreaContextMenu.getElementsByAttribute("label", "Click me!");
-  is(item.length, 0, "no contextMenu item for image was found");
+  is(item.length, 1, "contextMenu item for page was found");
   yield closeContextMenu();
 
   yield extension.unload();
 
   yield BrowserTestUtils.removeTab(tab1);
 });
 
 add_task(function* () {