Bug 1427107 - Reject setBadgeBackgroundColor promise for invalid string colors r=mixedpuppy

MozReview-Commit-ID: 1XXiQCDe7Tu

--HG--
extra : rebase_source : df1ab14e9473d1fab42016ea31823274838bffdd
This commit is contained in:
Oriol Brufau 2018-01-11 18:56:18 +01:00
parent 4281f3eea3
commit ac5db38313
2 changed files with 15 additions and 16 deletions

View File

@ -30,6 +30,10 @@ var {
StartupCache,
} = ExtensionParent;
var {
ExtensionError,
} = ExtensionUtils;
Cu.importGlobalProperties(["InspectorUtils"]);
const POPUP_PRELOAD_TIMEOUT_MS = 200;
@ -675,8 +679,11 @@ this.browserAction = class extends ExtensionAPI {
setBadgeBackgroundColor: function(details) {
let tab = getTab(details.tabId);
let color = details.color;
if (!Array.isArray(color)) {
if (typeof color == "string") {
let col = InspectorUtils.colorToRGBA(color);
if (!col) {
throw new ExtensionError(`Invalid badge background color: "${color}"`);
}
color = col && [col.r, col.g, col.b, Math.round(col.a * 255)];
}
browserAction.setProperty(tab, "badgeBackgroundColor", color);

View File

@ -490,11 +490,6 @@ add_task(async function testPropertyRemoval() {
"title": "t2",
"badge": "b2",
"badgeBackgroundColor": [0x22, 0x22, 0x22, 0xFF]},
{"icon": contextUri,
"popup": "",
"title": "",
"badge": "",
"badgeBackgroundColor": [0x11, 0x11, 0x11, 0xFF]},
{"icon": contextUri,
"popup": "",
"title": "",
@ -541,17 +536,14 @@ add_task(async function testPropertyRemoval() {
browser.browserAction.setPopup({tabId, popup: ""});
browser.browserAction.setTitle({tabId, title: ""});
browser.browserAction.setBadgeText({tabId, text: ""});
browser.browserAction.setBadgeBackgroundColor({tabId, color: ""});
await browser.test.assertRejects(
browser.browserAction.setBadgeBackgroundColor({tabId, color: ""}),
/^Invalid badge background color: ""$/,
"Expected invalid badge background color error"
);
await expectGlobals(details[1]);
expect(details[3]);
},
async expect => {
browser.test.log("The invalid color removed tab bgcolor, restore previous tab bgcolor.");
let tabId = tabs[0];
browser.browserAction.setBadgeBackgroundColor({tabId, color: "#222"});
await expectGlobals(details[1]);
expect(details[4]);
},
async expect => {
browser.test.log("Remove tab values, expect global values.");
let tabId = tabs[0];
@ -570,8 +562,8 @@ add_task(async function testPropertyRemoval() {
browser.browserAction.setTitle({title: "t3"});
browser.browserAction.setBadgeText({text: "b3"});
browser.browserAction.setBadgeBackgroundColor({color: "#333"});
await expectGlobals(details[5]);
expect(details[5]);
await expectGlobals(details[4]);
expect(details[4]);
},
async expect => {
browser.test.log("Remove global values, expect defaults.");