Bug 1447796 - fix closing page action panels using commands, r?rpl
If commands are used with the page action panel, they will toggle open or
closed. We need to keep a handle on our custom panel so we can close it.
MozReview-Commit-ID: JfxwlyK8g8g
--- a/browser/components/extensions/ext-pageAction.js
+++ b/browser/components/extensions/ext-pageAction.js
@@ -269,21 +269,33 @@ this.pageAction = class extends Extensio
this.tabManager.addActiveTabPermission(tab);
// If the widget has a popup URL defined, we open a popup, but do not
// dispatch a click event to the extension.
// If it has no popup URL defined, we dispatch a click event, but do not
// open a popup.
if (popupURL) {
- let popup = new PanelPopup(this.extension, window.document, popupURL,
- this.browserStyle);
- await popup.contentReady;
+ if (this.popupNode && this.popupNode.panel.state !== "closed") {
+ // The panel is being toggled closed.
+ TelemetryStopwatch.cancel(popupOpenTimingHistogram, this);
+ window.BrowserPageActions.togglePanelForAction(this.browserPageAction,
+ this.popupNode.panel);
+ return;
+ }
+
+ this.popupNode = new PanelPopup(this.extension, window.document, popupURL,
+ this.browserStyle);
+ // Remove popupNode when it is closed.
+ this.popupNode.panel.addEventListener("popuphiding", () => {
+ this.popupNode = undefined;
+ }, {once: true});
+ await this.popupNode.contentReady;
window.BrowserPageActions.togglePanelForAction(this.browserPageAction,
- popup.panel);
+ this.popupNode.panel);
TelemetryStopwatch.finish(popupOpenTimingHistogram, this);
} else {
TelemetryStopwatch.cancel(popupOpenTimingHistogram, this);
this.emit("click", tab);
}
}
/**
--- 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
@@ -158,12 +158,21 @@ add_task(async function test_execute_pag
}, {once: true});
},
},
});
await extension.startup();
let tab = await BrowserTestUtils.openNewForegroundTab(window.gBrowser, "http://example.com/");
EventUtils.synthesizeKey("j", {altKey: true, shiftKey: true});
+ info("Waiting for pageAction open.");
await extension.awaitFinish("page-action-with-popup");
+
+ // Bug 1447796 make sure the key command can close the page action
+ let panel = document.getElementById(`${makeWidgetId(extension.id)}-panel`);
+ let hidden = promisePopupHidden(panel);
+ EventUtils.synthesizeKey("j", {altKey: true, shiftKey: true});
+ info("Waiting for pageAction close.");
+ await hidden;
+
await extension.unload();
BrowserTestUtils.removeTab(tab);
});