Bug 1307551: Don't attempt to pre-load popup for disabled browserAction. r?bsilverberg draft
authorKris Maglione <maglione.k@gmail.com>
Tue, 01 Nov 2016 09:41:30 -0700
changeset 432341 8f0fa63b813f77bc8cde28aa1878c880ac96a3df
parent 432301 4cde141bbedfd7355bdf3e9ac41740fb8fa2f06d
child 535611 281d6233be6e940ae5d338d8f451571077ac4ee4
push id34269
push usermaglione.k@gmail.com
push dateTue, 01 Nov 2016 18:01:44 +0000
reviewersbsilverberg
bugs1307551
milestone52.0a1
Bug 1307551: Don't attempt to pre-load popup for disabled browserAction. r?bsilverberg MozReview-Commit-ID: 8imoqD1Xoja
browser/components/extensions/ext-browserAction.js
browser/components/extensions/test/browser/browser_ext_browserAction_popup.js
--- 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();
+});