Bug 1313459 support CUI areas for browserAction, r=aswan
☠☠ backed out by e52cd3f75ebf ☠ ☠
authorShane Caraveo <scaraveo@mozilla.com>
Tue, 21 Feb 2017 10:00:06 -0800
changeset 393087 14dbbe36e676e23b54c7e2b4a2c29ce4f24bba66
parent 393086 e85a00771f868560e43662d1dd349ddae1237924
child 393088 024b338f6d2db3fc242d66daf1f3f0abe4f62ff3
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1313459
milestone54.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 1313459 support CUI areas for browserAction, r=aswan MozReview-Commit-ID: IoPOCv6M0qy
browser/components/extensions/ext-browserAction.js
browser/components/extensions/schemas/browser_action.json
browser/components/extensions/test/browser/browser-common.ini
browser/components/extensions/test/browser/browser_ext_browserAction_area.js
--- a/browser/components/extensions/ext-browserAction.js
+++ b/browser/components/extensions/ext-browserAction.js
@@ -33,17 +33,24 @@ function isAncestorOrSelf(target, node) 
     if (node === target) {
       return true;
     }
   }
   return false;
 }
 
 // WeakMap[Extension -> BrowserAction]
-var browserActionMap = new WeakMap();
+const browserActionMap = new WeakMap();
+
+const browserAreas = {
+  "navbar": CustomizableUI.AREA_NAVBAR,
+  "menupanel": CustomizableUI.AREA_PANEL,
+  "tabstrip": CustomizableUI.AREA_TABSTRIP,
+  "personaltoolbar": CustomizableUI.AREA_BOOKMARKS,
+};
 
 // Responsible for the browser_action section of the manifest as well
 // as the associated popup.
 function BrowserAction(options, extension) {
   this.extension = extension;
 
   let widgetId = makeWidgetId(extension.id);
   this.id = `${widgetId}-browser-action`;
@@ -57,16 +64,17 @@ function BrowserAction(options, extensio
 
   this.defaults = {
     enabled: true,
     title: options.default_title || extension.name,
     badgeText: "",
     badgeBackgroundColor: null,
     icon: IconDetails.normalize({path: options.default_icon}, extension),
     popup: options.default_popup || "",
+    area: browserAreas[options.default_area || "navbar"],
   };
 
   this.browserStyle = options.browser_style || false;
   if (options.browser_style === null) {
     this.extension.logger.warn("Please specify whether you want browser_style " +
                                "or not in your browser_action options.");
   }
 
@@ -80,17 +88,17 @@ BrowserAction.prototype = {
   build() {
     let widget = CustomizableUI.createWidget({
       id: this.id,
       viewId: this.viewId,
       type: "view",
       removable: true,
       label: this.defaults.title || this.extension.name,
       tooltiptext: this.defaults.title || "",
-      defaultArea: CustomizableUI.AREA_NAVBAR,
+      defaultArea: this.defaults.area,
 
       onBeforeCreated: document => {
         let view = document.createElementNS(XUL_NS, "panelview");
         view.id = this.viewId;
         view.setAttribute("flex", "1");
 
         document.getElementById("PanelUI-multiView").appendChild(view);
         document.addEventListener("popupshowing", this);
--- a/browser/components/extensions/schemas/browser_action.json
+++ b/browser/components/extensions/schemas/browser_action.json
@@ -26,16 +26,22 @@
                 "type": "string",
                 "format": "relativeUrl",
                 "optional": true,
                 "preprocess": "localize"
               },
               "browser_style": {
                 "type": "boolean",
                 "optional": true
+              },
+              "default_area": {
+                "description": "Defines the location the browserAction will appear by default.  The default location is navbar.",
+                "type": "string",
+                "enum": ["navbar", "menupanel", "tabstrip", "personaltoolbar"],
+                "optional": true
               }
             },
             "optional": true
           }
         }
       }
     ]
   },
--- a/browser/components/extensions/test/browser/browser-common.ini
+++ b/browser/components/extensions/test/browser/browser-common.ini
@@ -19,16 +19,17 @@ support-files =
   file_dummy.html
   file_inspectedwindow_reload_target.sjs
   file_serviceWorker.html
   serviceWorker.js
   searchSuggestionEngine.xml
   searchSuggestionEngine.sjs
   ../../../../../toolkit/components/extensions/test/mochitest/head_webrequest.js
 
+[browser_ext_browserAction_area.js]
 [browser_ext_browserAction_context.js]
 [browser_ext_browserAction_disabled.js]
 [browser_ext_browserAction_pageAction_icon.js]
 [browser_ext_browserAction_pageAction_icon_permissions.js]
 [browser_ext_browserAction_popup.js]
 [browser_ext_browserAction_popup_preload.js]
 [browser_ext_browserAction_popup_resize.js]
 [browser_ext_browserAction_simple.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_area.js
@@ -0,0 +1,73 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+"use strict";
+
+var browserAreas = {
+  "navbar": CustomizableUI.AREA_NAVBAR,
+  "menupanel": CustomizableUI.AREA_PANEL,
+  "tabstrip": CustomizableUI.AREA_TABSTRIP,
+  "personaltoolbar": CustomizableUI.AREA_BOOKMARKS,
+};
+
+function* testInArea(area) {
+  let manifest = {
+    "browser_action": {
+      "default_popup": "popup.html",
+      "browser_style": true,
+    },
+  };
+  if (area) {
+    manifest.browser_action.default_area = area;
+  }
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest,
+    files: {
+      "popup.html": `
+      <!DOCTYPE html>
+      <html><head>
+      <meta charset="utf-8"/>
+      <script src="popup.js"></script>
+      </head><body>
+      </body></html>
+      `,
+
+      "popup.js": function() {
+        window.onload = () => {
+          browser.test.sendMessage("from-popup");
+        };
+      },
+    },
+  });
+  yield extension.startup();
+  let widget = getBrowserActionWidget(extension);
+  let placement = CustomizableUI.getPlacementOfWidget(widget.id);
+  is(placement && placement.area, browserAreas[area || "navbar"], `widget located in correct area`);
+
+  clickBrowserAction(extension);
+
+  yield extension.awaitMessage("from-popup");
+
+  yield extension.unload();
+}
+
+add_task(function* testBrowserActionDefaultArea() {
+  yield testInArea();
+});
+
+add_task(function* testBrowserActionInToolbar() {
+  yield testInArea("navbar");
+});
+
+add_task(function* testBrowserActionInMenuPanel() {
+  yield testInArea("menupanel");
+});
+
+add_task(function* testBrowserActionInTabStrip() {
+  yield testInArea("tabstrip");
+});
+
+add_task(function* testBrowserActionInPersonalToolbar() {
+  CustomizableUI.setToolbarVisibility("PersonalToolbar", true);
+  yield testInArea("personaltoolbar");
+  CustomizableUI.setToolbarVisibility("PersonalToolbar", false);
+});