Bug 1408129 - Treat webextension commands as user input. r=aswan
authorTom Schuster <evilpies@gmail.com>
Thu, 09 Aug 2018 23:15:19 +0200
changeset 486057 e89fb659271cf500cfddb3c776067ce06ce9001f
parent 486056 cb71f8efdaca50cfe2e4062477c177fab7e07f75
child 486058 253e2e30634e8bb9f7a09249f20f9c11a8813321
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1408129
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 1408129 - Treat webextension commands as user input. r=aswan
browser/components/extensions/parent/ext-commands.js
browser/components/extensions/test/browser/browser_ext_user_events.js
--- a/browser/components/extensions/parent/ext-commands.js
+++ b/browser/components/extensions/parent/ext-commands.js
@@ -356,16 +356,17 @@ this.commands = class extends ExtensionA
             commands.set(name, {...manifestCommands.get(name)});
             ExtensionSettingsStore.removeSetting(extension.id, "commands", name);
             this.registerKeys(commands);
           }
         },
         onCommand: new EventManager({
           context,
           name: "commands.onCommand",
+          inputHandling: true,
           register: fire => {
             let listener = (eventName, commandName) => {
               fire.async(commandName);
             };
             this.on("command", listener);
             return () => {
               this.off("command", listener);
             };
--- a/browser/components/extensions/test/browser/browser_ext_user_events.js
+++ b/browser/components/extensions/test/browser/browser_ext_user_events.js
@@ -42,16 +42,17 @@ 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.commands.onCommand.addListener(() => request("downloads"));
 
       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"));
@@ -118,19 +119,27 @@ add_task(async function testSources() {
         });
       },
     },
 
     manifest: {
       browser_action: {default_title: "test"},
       page_action: {default_title: "test"},
       permissions: ["contextMenus"],
-      optional_permissions: ["bookmarks", "tabs", "webNavigation", "webRequest", "cookies"],
+      optional_permissions: ["bookmarks", "tabs", "webNavigation", "webRequest",
+                             "cookies", "downloads"],
       options_ui: {page: "options.html"},
       content_security_policy: "script-src 'self' https://example.com; object-src 'none';",
+      commands: {
+        command: {
+          suggested_key: {
+            "default": "Alt+Shift+J",
+          },
+        },
+      },
     },
 
     useAddonManager: "temporary",
   });
 
   async function check(what) {
     let result = await extension.awaitMessage("request");
     ok(result.success, `request() did not throw when called from ${what}`);
@@ -173,16 +182,22 @@ add_task(async function testSources() {
   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");
 
+  EventUtils.synthesizeKey("j", {altKey: true, shiftKey: true});
+  promisePopupNotificationShown("addon-webext-permissions").then(panel => {
+    panel.button.click();
+  });
+  await check("commands shortcut");
+
   promisePopupNotificationShown("addon-webext-permissions").then(panel => {
     panel.button.click();
   });
   extension.sendMessage("openOptionsPage");
   await check("options page link click");
 
   await BrowserTestUtils.removeTab(gBrowser.selectedTab);
   await BrowserTestUtils.removeTab(tab);