Bug 1454627 - Run "onclick" event of menu with user input. r=mixedpuppy, a=test-only
authorRob Wu <rob@robwu.nl>
Fri, 27 Jul 2018 19:06:00 +0200
changeset 480812 5c573fbddd4b2b5dc6d3812b24685c989e2fc85d
parent 480811 30a17d2d7779b6e32b5e9bb4d013a8cfa1934f14
child 480813 fd81c0f6fb7f78e637235744e980d9498b58b77b
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy, test-only
bugs1454627
milestone62.0
Bug 1454627 - Run "onclick" event of menu with user input. r=mixedpuppy, a=test-only 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);