Bug 1494135 add pinned option to page_action manifest, r=aswan
authorShane Caraveo <scaraveo@mozilla.com>
Tue, 02 Oct 2018 15:39:16 +0000
changeset 494928 9e5ba5a3b22c2d6ce5cc6bd0c331af5bdec7c6a5
parent 494927 66b90e5af6d162fa2c5d27b5d0df4140f108d84b
child 494929 ac55a8f97f06897ee34d65d6bbfc773091e2341e
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1494135
milestone64.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 1494135 add pinned option to page_action manifest, r=aswan Differential Revision: https://phabricator.services.mozilla.com/D7098
browser/components/extensions/parent/ext-pageAction.js
browser/components/extensions/schemas/page_action.json
browser/components/extensions/test/browser/browser_ext_pageAction_simple.js
browser/components/extensions/test/browser/head.js
--- a/browser/components/extensions/parent/ext-pageAction.js
+++ b/browser/components/extensions/parent/ext-pageAction.js
@@ -60,16 +60,17 @@ this.pageAction = class extends Extensio
     }
 
     this.defaults = {
       show,
       showMatches,
       hideMatches,
       title: options.default_title || extension.name,
       popup: options.default_popup || "",
+      pinned: options.pinned,
     };
 
     this.browserStyle = options.browser_style;
 
     this.tabContext = new TabContext(tab => this.defaults);
 
     this.tabContext.on("location-change", this.handleLocationChange.bind(this)); // eslint-disable-line mozilla/balanced-listeners
 
@@ -82,17 +83,17 @@ this.pageAction = class extends Extensio
     this.lastValues = new DefaultWeakMap(() => ({}));
 
     if (!this.browserPageAction) {
       this.browserPageAction = PageActions.addAction(new PageActions.Action({
         id: widgetId,
         extensionID: extension.id,
         title: this.defaults.title,
         iconURL: this.defaults.icon,
-        pinnedToUrlbar: true,
+        pinnedToUrlbar: this.defaults.pinned,
         disabled: !this.defaults.show,
         onCommand: (event, buttonNode) => {
           this.handleClick(event.target.ownerGlobal);
         },
         onBeforePlacedInWindow: browserWindow => {
           if (this.extension.hasPermission("menus") ||
               this.extension.hasPermission("contextMenus")) {
             browserWindow.document.addEventListener("popupshowing", this);
--- a/browser/components/extensions/schemas/page_action.json
+++ b/browser/components/extensions/schemas/page_action.json
@@ -39,16 +39,21 @@
                 "minItems": 1,
                 "items": { "$ref": "MatchPattern" }
               },
               "hide_matches": {
                 "type": "array",
                 "optional": true,
                 "minItems": 1,
                 "items": { "$ref": "MatchPatternRestricted" }
+              },
+              "pinned": {
+                "type": "boolean",
+                "optional": true,
+                "default": true
               }
             },
             "optional": true
           }
         }
       }
     ]
   },
--- a/browser/components/extensions/test/browser/browser_ext_pageAction_simple.js
+++ b/browser/components/extensions/test/browser/browser_ext_pageAction_simple.js
@@ -1,12 +1,14 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
+ChromeUtils.import("resource:///modules/PageActions.jsm");
+
 add_task(async function test_pageAction_basic() {
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       "page_action": {
         "default_popup": "popup.html",
         "unrecognized_property": "with-a-random-value",
       },
     },
@@ -44,17 +46,63 @@ add_task(async function test_pageAction_
     SimpleTest.monitorConsole(resolve, [{
       message: /Reading manifest: Error processing page_action.unrecognized_property: An unexpected property was found/,
     }]);
   });
 
   await extension.startup();
   await extension.awaitMessage("page-action-shown");
 
+  let elem = await getPageActionButton(extension);
+  let parent = window.document.getElementById("page-action-buttons");
+  is(elem && elem.parentNode, parent, `pageAction pinned to urlbar ${elem.parentNode.getAttribute("id")}`);
+
   clickPageAction(extension);
 
   await extension.awaitMessage("popup");
 
   await extension.unload();
 
   SimpleTest.endMonitorConsole();
   await waitForConsole;
 });
+
+add_task(async function test_pageAction_pinned() {
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      "page_action": {
+        "default_popup": "popup.html",
+        "pinned": false,
+      },
+    },
+
+    files: {
+      "popup.html": `
+      <!DOCTYPE html>
+      <html><body>
+      </body></html>
+      `,
+    },
+
+    background: function() {
+      browser.tabs.query({active: true, currentWindow: true}, tabs => {
+        let tabId = tabs[0].id;
+
+        browser.pageAction.show(tabId).then(() => {
+          browser.test.sendMessage("page-action-shown");
+        });
+      });
+    },
+  });
+
+  await extension.startup();
+  await extension.awaitMessage("page-action-shown");
+
+  let elem = await getPageActionButton(extension);
+  is(elem && elem.parentNode, null, "pageAction is not pinned to urlbar");
+
+  // There are plenty of tests for the main action button, we just verify
+  // that we've properly set the pinned value to false.
+  let action = PageActions.actionForID(makeWidgetId(extension.id));
+  ok(action && !action.pinnedToUrlbar, "pageAction is in main pageaction menu");
+
+  await extension.unload();
+});
--- a/browser/components/extensions/test/browser/head.js
+++ b/browser/components/extensions/test/browser/head.js
@@ -1,16 +1,16 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 /* exported CustomizableUI makeWidgetId focusWindow forceGC
  *          getBrowserActionWidget
  *          clickBrowserAction clickPageAction
- *          getBrowserActionPopup getPageActionPopup
+ *          getBrowserActionPopup getPageActionPopup getPageActionButton
  *          closeBrowserAction closePageAction
  *          promisePopupShown promisePopupHidden
  *          openContextMenu closeContextMenu
  *          openContextMenuInSidebar openContextMenuInPopup
  *          openExtensionContextMenu closeExtensionContextMenu
  *          openActionContextMenu openSubmenu closeActionContextMenu
  *          openTabContextMenu closeTabContextMenu
  *          openToolsMenu closeToolsMenu
@@ -412,17 +412,17 @@ function closeChromeContextMenu(menuId, 
     EventUtils.synthesizeMouseAtCenter(itemToSelect, {}, win);
   } else {
     menu.hidePopup();
   }
   return hidden;
 }
 
 async function openActionContextMenu(extension, kind, win = window) {
-  // See comment from clickPageAction below.
+  // See comment from getPageActionButton below.
   SetPageProxyState("valid");
   await promiseAnimationFrame(win);
   let buttonID;
   let menuID;
   if (kind == "page") {
     buttonID = "#" + BrowserPageActions.urlbarButtonNodeIDForActionID(makeWidgetId(extension.id));
     menuID = "pageActionContextMenu";
   } else {
@@ -445,31 +445,34 @@ function closeTabContextMenu(itemToSelec
   return closeChromeContextMenu("tabContextMenu", itemToSelect, win);
 }
 
 function getPageActionPopup(extension, win = window) {
   let panelId = makeWidgetId(extension.id) + "-panel";
   return win.document.getElementById(panelId);
 }
 
-async function clickPageAction(extension, win = window) {
+async function getPageActionButton(extension, win = window) {
   // This would normally be set automatically on navigation, and cleared
   // when the user types a value into the URL bar, to show and hide page
   // identity info and icons such as page action buttons.
   //
   // Unfortunately, that doesn't happen automatically in browser chrome
   // tests.
   SetPageProxyState("valid");
 
   await promiseAnimationFrame(win);
 
   let pageActionId = BrowserPageActions.urlbarButtonNodeIDForActionID(makeWidgetId(extension.id));
 
-  let elem = win.document.getElementById(pageActionId);
+  return win.document.getElementById(pageActionId);
+}
 
+async function clickPageAction(extension, win = window) {
+  let elem = await getPageActionButton(extension, win);
   EventUtils.synthesizeMouseAtCenter(elem, {}, win);
   return new Promise(SimpleTest.executeSoon);
 }
 
 function closePageAction(extension, win = window) {
   let node = getPageActionPopup(extension, win);
   if (node) {
     return promisePopupShown(node).then(() => {