Bug 1451909 - Adding in icon and color validation for contextualIdentities.update web extension method. r=aswan
authorJonathan Kingston <jkt@mozilla.com>
Sat, 07 Apr 2018 15:15:45 +0100
changeset 779665 c318860e517952a8b6726b2df179c63cf22d171a
parent 779664 c97f808251564c7a5e442d70601235a2edcabbd7
child 779666 085c62e04558eea099732b66fbbde71625cbb772
push id105836
push userbmo:ato@sny.no
push dateTue, 10 Apr 2018 12:07:22 +0000
reviewersaswan
bugs1451909
milestone61.0a1
Bug 1451909 - Adding in icon and color validation for contextualIdentities.update web extension method. r=aswan MozReview-Commit-ID: 6JkSbMnJzTd
toolkit/components/extensions/parent/ext-contextualIdentities.js
toolkit/components/extensions/test/xpcshell/test_ext_contextual_identities.js
--- a/toolkit/components/extensions/parent/ext-contextualIdentities.js
+++ b/toolkit/components/extensions/parent/ext-contextualIdentities.js
@@ -181,20 +181,22 @@ this.contextualIdentities = class extend
             throw new ExtensionError(`Invalid contextual identity: ${cookieStoreId}`);
           }
 
           if (details.name !== null) {
             identity.name = details.name;
           }
 
           if (details.color !== null) {
+            getContainerColor(details.color);
             identity.color = details.color;
           }
 
           if (details.icon !== null) {
+            getContainerIcon(details.icon);
             identity.icon = details.icon;
           }
 
           if (!ContextualIdentityService.update(identity.userContextId,
                                                 identity.name, identity.icon,
                                                 identity.color)) {
             throw new ExtensionError(`Contextual identity failed to update: ${cookieStoreId}`);
           }
--- a/toolkit/components/extensions/test/xpcshell/test_ext_contextual_identities.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_contextual_identities.js
@@ -195,16 +195,28 @@ add_task(async function test_contextualI
     browser.test.assertEq(5, cis.length, "we should still have have 5 containers");
 
     ci = await browser.contextualIdentities.get(ci.cookieStoreId);
     browser.test.assertTrue(!!ci, "We have an identity");
     browser.test.assertEq("foobar", ci.name, "identity.name is correct");
     browser.test.assertEq("red", ci.color, "identity.color is correct");
     browser.test.assertEq("gift", ci.icon, "identity.icon is correct");
 
+    browser.test.assertRejects(
+      browser.contextualIdentities.update(ci.cookieStoreId, {name: "foobar", color: "red", icon: "firefox"}),
+      "Invalid icon firefox for container",
+      "Create container called with an invalid icon"
+    );
+
+    browser.test.assertRejects(
+      browser.contextualIdentities.update(ci.cookieStoreId, {name: "foobar", color: "firefox-orange", icon: "gift"}),
+      "Invalid color name firefox-orange for container",
+      "Create container called with an invalid color"
+    );
+
     cis = await browser.contextualIdentities.query({});
     browser.test.assertEq(5, cis.length, "now we have 5 identities");
 
     ci = await browser.contextualIdentities.update(ci.cookieStoreId, {name: "barfoo", color: "blue", icon: "cart"});
     browser.test.assertTrue(!!ci, "We have an identity");
     browser.test.assertEq("barfoo", ci.name, "identity.name is correct");
     browser.test.assertEq("blue", ci.color, "identity.color is correct");
     browser.test.assertEq("cart", ci.icon, "identity.icon is correct");