Bug 1473720: Fix firing menus.onShown for bookmark items r=mixedpuppy
authorPeter Simonyi <pts@petersimonyi.ca>
Thu, 05 Jul 2018 16:43:15 -0400
changeset 425452 4561d6ed48b68262a53c37193119fec3a5ab3aa6
parent 425451 65b56d7813c07ec8e5beca0c236944818683d4b8
child 425463 b0111088608390a0ab4baa3727e5e6fb06cd9f31
push id34249
push useraiakab@mozilla.com
push dateSun, 08 Jul 2018 10:23:15 +0000
treeherdermozilla-central@4561d6ed48b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1473720
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1473720: Fix firing menus.onShown for bookmark items r=mixedpuppy 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"],