Bug 1413648 fix default extension icon use, r=aswan

MozReview-Commit-ID: 3Dh2DjGIAgn

--HG--
extra : rebase_source : da88dcede96fa8f89cca1e9abf9baabb78a73855
This commit is contained in:
Shane Caraveo 2017-11-02 15:49:38 -07:00
Родитель e9b3a258b8
Коммит 6cd7d5e813
2 изменённых файлов: 22 добавлений и 9 удалений

Просмотреть файл

@ -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.

Просмотреть файл

@ -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]]});