Bug 1314674 - Maintain badge style in new windows and customize r=mixedpuppy

MozReview-Commit-ID: 8f99d6Uqtx1

--HG--
extra : rebase_source : 66da5414a5baf68f276915258947c5886e030f7d
This commit is contained in:
Mark Striemer 2017-09-20 17:27:48 -05:00
parent 8801f82f5e
commit a84f31e137
3 changed files with 51 additions and 9 deletions

View File

@ -442,14 +442,12 @@ this.browserAction = class extends ExtensionAPI {
node.setAttribute("disabled", "true");
}
let badgeNode = node.ownerDocument.getAnonymousElementByAttribute(node,
"class", "toolbarbutton-badge");
if (badgeNode) {
let color = tabData.badgeBackgroundColor;
if (color) {
color = `rgba(${color[0]}, ${color[1]}, ${color[2]}, ${color[3] / 255})`;
}
badgeNode.style.backgroundColor = color || "";
let color = tabData.badgeBackgroundColor;
if (color) {
color = `rgba(${color[0]}, ${color[1]}, ${color[2]}, ${color[3] / 255})`;
node.setAttribute("badgeStyle", `background-color: ${color};`);
} else {
node.removeAttribute("badgeStyle");
}
let {style, legacy} = this.iconData.get(tabData.icon);

View File

@ -407,3 +407,47 @@ add_task(async function testDefaultTitle() {
},
});
});
add_task(async function testBadgeColorPersistence() {
const extension = ExtensionTestUtils.loadExtension({
background() {
browser.test.onMessage.addListener((msg, arg) => {
browser.browserAction[msg](arg);
});
},
manifest: {
browser_action: {},
},
});
await extension.startup();
function getBadgeForWindow(win) {
const widget = getBrowserActionWidget(extension).forWindow(win).node;
return document.getAnonymousElementByAttribute(widget, "class", "toolbarbutton-badge");
}
let badge = getBadgeForWindow(window);
const badgeChanged = new Promise((resolve) => {
const observer = new MutationObserver(() => resolve());
observer.observe(badge, {attributes: true, attributeFilter: ["style"]});
});
extension.sendMessage("setBadgeText", {text: "hi"});
extension.sendMessage("setBadgeBackgroundColor", {color: [0, 255, 0, 255]});
await badgeChanged;
is(badge.value, "hi", "badge text is set in first window");
is(badge.style.backgroundColor, "rgb(0, 255, 0)", "badge color is set in first window");
let windowOpenedPromise = BrowserTestUtils.waitForNewWindow();
let win = OpenBrowserWindow();
await windowOpenedPromise;
badge = getBadgeForWindow(win);
is(badge.value, "hi", "badge text is set in new window");
is(badge.style.backgroundColor, "rgb(0, 255, 0)", "badge color is set in new window");
await BrowserTestUtils.closeWindow(win);
await extension.unload();
});

View File

@ -88,7 +88,7 @@
<children includes="observes|template|menupopup|panel|tooltip"/>
<xul:stack class="toolbarbutton-badge-stack">
<xul:image class="toolbarbutton-icon" xbl:inherits="validate,src=image,label,consumeanchor"/>
<xul:label class="toolbarbutton-badge" xbl:inherits="value=badge" top="0" end="0" crop="none"/>
<xul:label class="toolbarbutton-badge" xbl:inherits="value=badge,style=badgeStyle" top="0" end="0" crop="none"/>
</xul:stack>
<xul:label class="toolbarbutton-text" crop="right" flex="1"
xbl:inherits="value=label,accesskey,crop,wrap"/>