--- a/browser/components/extensions/ext-browserAction.js
+++ b/browser/components/extensions/ext-browserAction.js
@@ -188,18 +188,19 @@ BrowserAction.prototype = {
switch (event.type) {
case "mousedown":
if (event.button == 0) {
// Begin pre-loading the browser for the popup, so it's more likely to
// be ready by the time we get a complete click.
let tab = window.gBrowser.selectedTab;
let popupURL = this.getProperty(tab, "popup");
+ let enabled = this.getProperty(tab, "enabled");
- if (popupURL) {
+ if (popupURL && enabled) {
this.pendingPopup = this.getPopup(window, popupURL);
window.addEventListener("mouseup", this, true);
} else {
this.clearPopup();
}
}
break;
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_popup.js
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_popup.js
@@ -268,17 +268,17 @@ add_task(function* testBrowserActionClic
isnot(browserAction.pendingPopup, null, "Have pending popup");
is(browserAction.pendingPopup.window, window, "Have pending popup for the correct window");
is(browserAction.pendingPopupTimeout, null, "Have no pending popup timeout");
// We need to do these tests during the mouseup event cycle, since the click
// and command events will be dispatched immediately after mouseup, and void
// the results.
- let mouseUpPromise = BrowserTestUtils.waitForEvent(widget.node, "mouseup", event => {
+ let mouseUpPromise = BrowserTestUtils.waitForEvent(widget.node, "mouseup", false, event => {
isnot(browserAction.pendingPopup, null, "Pending popup was not cleared");
isnot(browserAction.pendingPopupTimeout, null, "Have a pending popup timeout");
return true;
});
EventUtils.synthesizeMouseAtCenter(widget.node, {type: "mouseup", button: 0}, window);
yield mouseUpPromise;
@@ -286,8 +286,79 @@ add_task(function* testBrowserActionClic
is(browserAction.pendingPopup, null, "Pending popup was cleared");
is(browserAction.pendingPopupTimeout, null, "Pending popup timeout was cleared");
yield promisePopupShown(getBrowserActionPopup(extension));
yield closeBrowserAction(extension);
yield extension.unload();
});
+
+add_task(function* testBrowserActionDisabled() {
+ let extension = ExtensionTestUtils.loadExtension({
+ manifest: {
+ "browser_action": {
+ "default_popup": "popup.html",
+ "browser_style": true,
+ },
+ },
+
+ background() {
+ browser.browserAction.disable();
+ },
+
+ files: {
+ "popup.html": `<!DOCTYPE html><html><head><meta charset="utf-8"><script src="popup.js"></script></head></html>`,
+ "popup.js"() {
+ browser.test.fail("Should not get here");
+ },
+ },
+ });
+
+ yield extension.startup();
+
+ const {GlobalManager, Management: {global: {browserActionFor}}} = Cu.import("resource://gre/modules/Extension.jsm", {});
+
+ let ext = GlobalManager.extensionMap.get(extension.id);
+ let browserAction = browserActionFor(ext);
+
+ let widget = getBrowserActionWidget(extension).forWindow(window);
+
+ // Test canceled click.
+ EventUtils.synthesizeMouseAtCenter(widget.node, {type: "mousedown", button: 0}, window);
+
+ is(browserAction.pendingPopup, null, "Have no pending popup");
+ is(browserAction.pendingPopupTimeout, null, "Have no pending popup timeout");
+
+ EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mouseup", button: 0}, window);
+
+ is(browserAction.pendingPopup, null, "Have no pending popup");
+ is(browserAction.pendingPopupTimeout, null, "Have no pending popup timeout");
+
+
+ // Test completed click.
+ EventUtils.synthesizeMouseAtCenter(widget.node, {type: "mousedown", button: 0}, window);
+
+ is(browserAction.pendingPopup, null, "Have no pending popup");
+ is(browserAction.pendingPopupTimeout, null, "Have no pending popup timeout");
+
+ // We need to do these tests during the mouseup event cycle, since the click
+ // and command events will be dispatched immediately after mouseup, and void
+ // the results.
+ let mouseUpPromise = BrowserTestUtils.waitForEvent(widget.node, "mouseup", false, event => {
+ is(browserAction.pendingPopup, null, "Have no pending popup");
+ is(browserAction.pendingPopupTimeout, null, "Have no pending popup timeout");
+ return true;
+ });
+
+ EventUtils.synthesizeMouseAtCenter(widget.node, {type: "mouseup", button: 0}, window);
+
+ yield mouseUpPromise;
+
+ is(browserAction.pendingPopup, null, "Have no pending popup");
+ is(browserAction.pendingPopupTimeout, null, "Have no pending popup timeout");
+
+ // Give the popup a chance to load and trigger a failure, if it was
+ // erroneously opened.
+ yield new Promise(resolve => setTimeout(resolve, 250));
+
+ yield extension.unload();
+});