From 6cd7d5e81330afa5171e4f95bc80ec6dd0eb9dd8 Mon Sep 17 00:00:00 2001 From: Shane Caraveo Date: Thu, 2 Nov 2017 15:49:38 -0700 Subject: [PATCH] Bug 1413648 fix default extension icon use, r=aswan MozReview-Commit-ID: 3Dh2DjGIAgn --HG-- extra : rebase_source : da88dcede96fa8f89cca1e9abf9baabb78a73855 --- .../components/extensions/ext-pageAction.js | 19 ++++++++++++++----- ...owser_ext_browserAction_pageAction_icon.js | 12 ++++++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/browser/components/extensions/ext-pageAction.js b/browser/components/extensions/ext-pageAction.js index 9ebdf134e0b1..fac6d28404ac 100644 --- a/browser/components/extensions/ext-pageAction.js +++ b/browser/components/extensions/ext-pageAction.js @@ -67,7 +67,7 @@ this.pageAction = class extends ExtensionAPI { this.browserPageAction = PageActions.addAction(new PageActions.Action({ id: widgetId, title: this.defaults.title, - iconURL: this.defaults.icon, + iconURL: this.getIconData(this.defaults.icon), shownInUrlbar: true, disabled: true, onCommand: (event, buttonNode) => { @@ -137,14 +137,23 @@ this.pageAction = class extends ExtensionAPI { if (typeof(tabData.icon) == "string") { iconURL = IconDetails.escapeUrl(tabData.icon); } else { - iconURL = Object.entries(tabData.icon).reduce((memo, [size, url]) => { - memo[size] = IconDetails.escapeUrl(url); - return memo; - }, {}); + iconURL = this.getIconData(tabData.icon); } this.browserPageAction.setIconURL(iconURL, window); } + getIconData(icons) { + let getIcon = size => { + let {icon} = IconDetails.getPreferredIcon(icons, this.extension, size); + // TODO: implement theme based icon for pageAction (Bug 1398156) + return IconDetails.escapeUrl(icon); + }; + return { + "16": getIcon(16), + "32": getIcon(32), + }; + } + /** * Triggers this page action for the given window, with the same effects as * if it were clicked by a user. diff --git a/browser/components/extensions/test/browser/browser_ext_browserAction_pageAction_icon.js b/browser/components/extensions/test/browser/browser_ext_browserAction_pageAction_icon.js index 2831fc64abd1..e809ef21799e 100644 --- a/browser/components/extensions/test/browser/browser_ext_browserAction_pageAction_icon.js +++ b/browser/components/extensions/test/browser/browser_ext_browserAction_pageAction_icon.js @@ -264,16 +264,20 @@ add_task(async function testDetailsObjects() { let browserActionWidget = getBrowserActionWidget(extension); let tests = await extension.awaitMessage("ready"); + + // The initial icon should be the default icon since no icon is in the manifest. + const DEFAULT_ICON = "chrome://browser/content/extension.svg"; + let browserActionButton = browserActionWidget.forWindow(window).node; + let pageActionImage = document.getElementById(pageActionId); + is(getListStyleImage(browserActionButton), DEFAULT_ICON, `browser action has the correct default image`); + is(getListStyleImage(pageActionImage), DEFAULT_ICON, `page action has the correct default image`); + for (let test of tests) { extension.sendMessage("setIcon", test); await extension.awaitMessage("iconSet"); await promiseAnimationFrame(); - let browserActionButton = browserActionWidget.forWindow(window).node; - let pageActionImage = document.getElementById(pageActionId); - - // Test icon sizes in the toolbar/urlbar. for (let resolution of Object.keys(test.resolutions)) { await SpecialPowers.pushPrefEnv({set: [[RESOLUTION_PREF, resolution]]});