Bug 1447723 - fix triggering pageAction when using pattern matching, r?rpl
MozReview-Commit-ID: 8B8QR2ltYmr
--- a/browser/components/extensions/ext-pageAction.js
+++ b/browser/components/extensions/ext-pageAction.js
@@ -227,19 +227,18 @@ this.pageAction = class extends Extensio
* Triggers this page action for the given window, with the same effects as
* if it were clicked by a user.
*
* This has no effect if the page action is hidden for the selected tab.
*
* @param {Window} window
*/
triggerAction(window) {
- let pageAction = pageActionMap.get(this.extension);
- if (pageAction.getProperty(window.gBrowser.selectedTab, "show")) {
- pageAction.handleClick(window);
+ if (this.isShown(window.gBrowser.selectedTab)) {
+ this.handleClick(window);
}
}
handleEvent(event) {
switch (event.type) {
case "popupshowing":
const menu = event.target;
const trigger = menu.triggerNode;
--- a/browser/components/extensions/test/browser/browser_ext_commands_execute_page_action.js
+++ b/browser/components/extensions/test/browser/browser_ext_commands_execute_page_action.js
@@ -1,12 +1,14 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
+const scriptPage = url => `<html><head><meta charset="utf-8"><script src="${url}"></script></head><body>Test Popup</body></html>`;
+
add_task(async function test_execute_page_action_without_popup() {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"commands": {
"_execute_page_action": {
"suggested_key": {
"default": "Alt+Shift+J",
},
@@ -54,34 +56,33 @@ add_task(async function test_execute_pag
});
await extension.startup();
await extension.awaitFinish("page-action-without-popup");
await extension.unload();
});
add_task(async function test_execute_page_action_with_popup() {
- let scriptPage = url => `<html><head><meta charset="utf-8"><script src="${url}"></script></head><body>Test Popup</body></html>`;
-
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"commands": {
"_execute_page_action": {
"suggested_key": {
"default": "Alt+Shift+J",
},
},
"send-keys-command": {
"suggested_key": {
"default": "Alt+Shift+3",
},
},
},
"page_action": {
"default_popup": "popup.html",
+ "browser_style": true,
},
},
files: {
"popup.html": scriptPage("popup.js"),
"popup.js": function() {
browser.runtime.sendMessage("popup-opened");
},
@@ -126,8 +127,43 @@ add_task(async function test_execute_pag
EventUtils.synthesizeKey("j", {altKey: true, shiftKey: true});
EventUtils.synthesizeKey("3", {altKey: true, shiftKey: true});
});
await extension.startup();
await extension.awaitFinish("page-action-with-popup");
await extension.unload();
});
+
+add_task(async function test_execute_page_action_with_matching() {
+ let extension = ExtensionTestUtils.loadExtension({
+ manifest: {
+ "commands": {
+ "_execute_page_action": {
+ "suggested_key": {
+ "default": "Alt+Shift+J",
+ },
+ },
+ },
+ "page_action": {
+ "default_popup": "popup.html",
+ "show_matches": ["<all_urls>"],
+ "browser_style": true,
+ },
+ },
+
+ files: {
+ "popup.html": scriptPage("popup.js"),
+ "popup.js": function() {
+ window.addEventListener("load", () => {
+ browser.test.notifyPass("page-action-with-popup");
+ }, {once: true});
+ },
+ },
+ });
+
+ await extension.startup();
+ let tab = await BrowserTestUtils.openNewForegroundTab(window.gBrowser, "http://example.com/");
+ EventUtils.synthesizeKey("j", {altKey: true, shiftKey: true});
+ await extension.awaitFinish("page-action-with-popup");
+ await extension.unload();
+ BrowserTestUtils.removeTab(tab);
+});