Bug 1454627 - Run "onclick" event of menu with user input r=mixedpuppy
☠☠ backed out by c6b4c044da81 ☠ ☠
authorRob Wu <rob@robwu.nl>
Fri, 27 Jul 2018 19:06:00 +0200
changeset 429379 44b38de7dc3d2e062e31035298e5ad99708d0138
parent 429378 22de883763acb05328b556944169ce478e1d1a44
child 429380 38d9cbe6e3d20e9099807a00bf1335a8451a9764
push id34363
push userbtara@mozilla.com
push dateTue, 31 Jul 2018 21:56:15 +0000
treeherdermozilla-central@929ceb6c82fa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1454627
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 1454627 - Run "onclick" event of menu with user input r=mixedpuppy MozReview-Commit-ID: r1URJfOKUB
browser/components/extensions/child/ext-menus.js
browser/components/extensions/test/browser/browser_ext_user_events.js
--- a/browser/components/extensions/child/ext-menus.js
+++ b/browser/components/extensions/child/ext-menus.js
@@ -27,17 +27,17 @@ class ContextMenusClickPropHandler {
   // A listener on contextMenus.onClicked that forwards the event to the only
   // listener, if any.
   dispatchEvent(info, tab) {
     let onclick = this.onclickMap.get(info.menuItemId);
     if (onclick) {
       // No need for runSafe or anything because we are already being run inside
       // an event handler -- the event is just being forwarded to the actual
       // handler.
-      onclick(info, tab);
+      withHandlingUserInput(this.context.contentWindow, () => onclick(info, tab));
     }
   }
 
   // Sets the `onclick` handler for the given menu item.
   // The `onclick` function MUST be owned by `this.context`.
   setListener(id, onclick) {
     if (this.onclickMap.size === 0) {
       this.context.childManager.getParentEvent("menusInternal.onClicked").addListener(this.dispatchEvent);
--- a/browser/components/extensions/test/browser/browser_ext_user_events.js
+++ b/browser/components/extensions/test/browser/browser_ext_user_events.js
@@ -42,28 +42,37 @@ add_task(async function testSources() {
         }
       }
 
       let tabs = await browser.tabs.query({active: true, currentWindow: true});
       await browser.pageAction.show(tabs[0].id);
 
       browser.pageAction.onClicked.addListener(() => request("bookmarks"));
       browser.browserAction.onClicked.addListener(() => request("tabs"));
-      browser.contextMenus.onClicked.addListener(() => request("webNavigation"));
 
       browser.test.onMessage.addListener(msg => {
+        if (msg === "contextMenus.update") {
+          browser.contextMenus.onClicked.addListener(() => request("webNavigation"));
+          browser.contextMenus.update("menu", {
+            title: "test user events in onClicked",
+            onclick: null,
+          }, () => browser.test.sendMessage("contextMenus.update-done"));
+        }
         if (msg === "openOptionsPage") {
           browser.runtime.openOptionsPage();
         }
       });
 
       browser.contextMenus.create({
         id: "menu",
-        title: "test user events",
+        title: "test user events in onclick",
         contexts: ["page"],
+        onclick() {
+          request("cookies");
+        },
       }, () => {
         browser.test.sendMessage("actions-ready");
       });
     },
 
     files: {
       "options.html": `<!DOCTYPE html>
         <html lang="en">
@@ -106,17 +115,17 @@ add_task(async function testSources() {
         }, {once: true});
       },
     },
 
     manifest: {
       browser_action: {default_title: "test"},
       page_action: {default_title: "test"},
       permissions: ["contextMenus"],
-      optional_permissions: ["bookmarks", "tabs", "webNavigation", "webRequest"],
+      optional_permissions: ["bookmarks", "tabs", "webNavigation", "webRequest", "cookies"],
       options_ui: {page: "options.html"},
       content_security_policy: "script-src 'self' https://example.com; object-src 'none';",
     },
 
     useAddonManager: "temporary",
   });
 
   async function check(what) {
@@ -148,20 +157,28 @@ add_task(async function testSources() {
   promisePopupNotificationShown("addon-webext-permissions").then(panel => {
     panel.button.click();
   });
 
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
   gBrowser.selectedTab = tab;
 
   let menu = await openContextMenu("body");
-  let items = menu.getElementsByAttribute("label", "test user events");
+  let items = menu.getElementsByAttribute("label", "test user events in onclick");
   is(items.length, 1, "Found context menu item");
   EventUtils.synthesizeMouseAtCenter(items[0], {});
-  await check("context menu click");
+  await check("context menu in onclick");
+
+  extension.sendMessage("contextMenus.update");
+  await extension.awaitMessage("contextMenus.update-done");
+  menu = await openContextMenu("body");
+  items = menu.getElementsByAttribute("label", "test user events in onClicked");
+  is(items.length, 1, "Found context menu item again");
+  EventUtils.synthesizeMouseAtCenter(items[0], {});
+  await check("context menu in onClicked");
 
   extension.sendMessage("openOptionsPage");
   promisePopupNotificationShown("addon-webext-permissions").then(panel => {
     panel.button.click();
   });
   await check("options page link click");
 
   await BrowserTestUtils.removeTab(gBrowser.selectedTab);