Bug 1427107 - Reject setBadgeBackgroundColor promise for invalid string colors r=mixedpuppy
authorOriol Brufau <oriol-bugzilla@hotmail.com>
Thu, 11 Jan 2018 18:56:18 +0100
changeset 453924 bc54bd9b08c8dce6119d90bf437b9167d763e3d9
parent 453923 ec468ee9dfc697960b74d83b6889223e9be8de95
child 453925 2f1762f3233a161c74478174322f7fbb40367b08
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1427107
milestone59.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 1427107 - Reject setBadgeBackgroundColor promise for invalid string colors r=mixedpuppy MozReview-Commit-ID: 1XXiQCDe7Tu
browser/components/extensions/ext-browserAction.js
browser/components/extensions/test/browser/browser_ext_browserAction_context.js
--- a/browser/components/extensions/ext-browserAction.js
+++ b/browser/components/extensions/ext-browserAction.js
@@ -25,16 +25,20 @@ var {
 
 Cu.import("resource://gre/modules/ExtensionParent.jsm");
 
 var {
   IconDetails,
   StartupCache,
 } = ExtensionParent;
 
+var {
+  ExtensionError,
+} = ExtensionUtils;
+
 Cu.importGlobalProperties(["InspectorUtils"]);
 
 const POPUP_PRELOAD_TIMEOUT_MS = 200;
 const POPUP_OPEN_MS_HISTOGRAM = "WEBEXT_BROWSERACTION_POPUP_OPEN_MS";
 const POPUP_RESULT_HISTOGRAM = "WEBEXT_BROWSERACTION_POPUP_PRELOAD_RESULT_COUNT";
 
 var XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
@@ -670,18 +674,21 @@ this.browserAction = class extends Exten
 
           let popup = browserAction.getProperty(tab, "popup");
           return Promise.resolve(popup);
         },
 
         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);
         },
 
         getBadgeBackgroundColor: function(details, callback) {
           let tab = getTab(details.tabId);
 
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_context.js
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_context.js
@@ -489,21 +489,16 @@ add_task(async function testPropertyRemo
          "popup": browser.runtime.getURL("p2.html"),
          "title": "t2",
          "badge": "b2",
          "badgeBackgroundColor": [0x22, 0x22, 0x22, 0xFF]},
         {"icon": contextUri,
          "popup": "",
          "title": "",
          "badge": "",
-         "badgeBackgroundColor": [0x11, 0x11, 0x11, 0xFF]},
-        {"icon": contextUri,
-         "popup": "",
-         "title": "",
-         "badge": "",
          "badgeBackgroundColor": [0x22, 0x22, 0x22, 0xFF]},
         {"icon": browser.runtime.getURL("i3.png"),
          "popup": browser.runtime.getURL("p3.html"),
          "title": "t3",
          "badge": "b3",
          "badgeBackgroundColor": [0x33, 0x33, 0x33, 0xFF]},
       ];
 
@@ -536,28 +531,25 @@ add_task(async function testPropertyRemo
         },
         async expect => {
           browser.test.log("Set empty tab values, expect empty values except for bgcolor.");
           let tabId = tabs[0];
           browser.browserAction.setIcon({tabId, path: ""});
           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];
           browser.browserAction.setIcon({tabId, path: null});
           browser.browserAction.setPopup({tabId, popup: null});
           browser.browserAction.setTitle({tabId, title: null});
           browser.browserAction.setBadgeText({tabId, text: null});
           browser.browserAction.setBadgeBackgroundColor({tabId, color: null});
           await expectGlobals(details[1]);
@@ -565,18 +557,18 @@ add_task(async function testPropertyRemo
         },
         async expect => {
           browser.test.log("Change global values, expect the new values.");
           browser.browserAction.setIcon({path: "i3.png"});
           browser.browserAction.setPopup({popup: "p3.html"});
           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.");
           browser.browserAction.setIcon({path: null});
           browser.browserAction.setPopup({popup: null});
           browser.browserAction.setBadgeText({text: null});
           browser.browserAction.setTitle({title: null});
           browser.browserAction.setBadgeBackgroundColor({color: null});