Bug 1313459 support CUI areas for browserAction, r=aswan
☠☠ backed out by 1fc93c32ef2e ☠ ☠
authorShane Caraveo <scaraveo@mozilla.com>
Mon, 20 Feb 2017 15:31:34 -0800
changeset 392902 3d9ddc7244ad9eb306efa802773c6e30a4b645f0
parent 392857 ddf86248e3013a84b69f4890f1c2969c731edfd0
child 392903 9f04fef720ecdedfc9ecc0aa27f1a3e07b6c4054
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": {
+                "type": "string",
+                "default": "navbar",
+                "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);
+});