Bug 1473720: Fix firing menus.onShown for bookmark items draft
authorPeter Simonyi <pts@petersimonyi.ca>
Thu, 05 Jul 2018 16:43:15 -0400
changeset 814654 1be7a7f8c2aaf54538aa32bf0078ab32fd72762e
parent 814584 e8b7331398910233e3adaaed01cad6b75bb562a2
push id115303
push userbmo:pts+bmo@petersimonyi.ca
push dateThu, 05 Jul 2018 21:38:59 +0000
bugs1473720
milestone63.0a1
Bug 1473720: Fix firing menus.onShown for bookmark items MozReview-Commit-ID: BzZ61Zfh7Oq
browser/components/extensions/parent/ext-menus.js
browser/components/extensions/test/browser/browser_ext_menus.js
--- a/browser/components/extensions/parent/ext-menus.js
+++ b/browser/components/extensions/parent/ext-menus.js
@@ -823,19 +823,20 @@ this.menusInternal = class extends Exten
               contexts: Array.from(getMenuContexts(contextData)),
             };
 
             let nativeTab = contextData.tab;
 
             // The menus.onShown event is fired before the user has consciously
             // interacted with an extension, so we require permissions before
             // exposing sensitive contextual data.
+            let contextUrl = contextData.inFrame ? contextData.frameUrl : contextData.pageUrl;
             let includeSensitiveData =
               (nativeTab && extension.tabManager.hasActiveTabPermission(nativeTab)) ||
-              extension.whiteListedHosts.matches(contextData.inFrame ? contextData.frameUrl : contextData.pageUrl);
+              (contextUrl && extension.whiteListedHosts.matches(contextUrl));
 
             addMenuEventInfo(info, contextData, includeSensitiveData);
 
             let tab = nativeTab && extension.tabManager.convert(nativeTab);
             fire.sync(info, tab);
           };
           gOnShownSubscribers.add(extension);
           extension.on("webext-menu-shown", listener);
--- a/browser/components/extensions/test/browser/browser_ext_menus.js
+++ b/browser/components/extensions/test/browser/browser_ext_menus.js
@@ -152,16 +152,55 @@ add_task(async function test_hiddenPageA
 
   await closeChromeContextMenu(menu.id);
   await closeChromeContextMenu(BrowserPageActions.panelNode.id);
 
   BrowserTestUtils.removeTab(tab);
   await extension.unload();
 });
 
+add_task(async function test_bookmarkContextMenu() {
+  async function showBookmarksToolbar(visible = true) {
+    let bt = document.getElementById("PersonalToolbar");
+    let transitionPromise =
+      BrowserTestUtils.waitForEvent(bt, "transitionend",
+                                    e => e.propertyName == "max-height");
+    setToolbarVisibility(bt, visible);
+    await transitionPromise;
+  }
+
+  const ext = ExtensionTestUtils.loadExtension({
+    manifest: {
+      permissions: ["menus", "bookmarks"],
+    },
+    async background() {
+      await browser.menus.create({title: "blarg", contexts: ["bookmark"]});
+      browser.menus.onShown.addListener(() => {
+        browser.test.sendMessage("hello");
+      });
+      browser.test.sendMessage("ready");
+    },
+  });
+
+  await showBookmarksToolbar();
+  await ext.startup();
+  await ext.awaitMessage("ready");
+
+  let menu = await openChromeContextMenu("placesContext",
+      "#PlacesToolbarItems .bookmark-item");
+  let children = Array.from(menu.children);
+  let item = children[children.length - 1];
+  is(item.label, "blarg", "Menu item label is correct");
+  await ext.awaitMessage("hello"); // onShown listener fired
+
+  closeChromeContextMenu("placesContext", item);
+  await ext.unload();
+  await showBookmarksToolbar(false);
+});
+
 add_task(async function test_tabContextMenu() {
   const first = ExtensionTestUtils.loadExtension({
     manifest: {
       permissions: ["menus"],
     },
     async background() {
       await browser.menus.create({
         id: "alpha-beta-parent", title: "alpha-beta parent", contexts: ["tab"],