Bug 1473720: Fix firing menus.onShown for bookmark items r=mixedpuppy a=lizzard
authorPeter Simonyi <pts@petersimonyi.ca>
Thu, 05 Jul 2018 16:43:15 -0400
changeset 478011 fff218cba849af85e392ca103061b453c581fc87
parent 478010 84f7e9706a491a638585b6329205a015f768b5da
child 478012 6aedd84a5388b511ba15f64e6efeaaec09079c58
push id9499
push userarchaeopteryx@coole-files.de
push dateThu, 19 Jul 2018 06:52:33 +0000
treeherdermozilla-beta@ce18b96ec82b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy, lizzard
bugs1473720
milestone62.0
Bug 1473720: Fix firing menus.onShown for bookmark items r=mixedpuppy a=lizzard 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"],