WIP api for container icons draft
authorJonathan Kingston <jkt@mozilla.com>
Sun, 27 Aug 2017 00:47:02 +0100
changeset 653701 37c9ed4c1f8c98a77768f720b3b8256c6a556dd7
parent 652907 55dc7c9855eb78cb3fea51555013ca88a805f0ee
child 728387 864f3cf1320f8610ec0417c8d64cd3dcea7f35f3
push id76379
push userjkingston@mozilla.com
push dateSat, 26 Aug 2017 23:48:20 +0000
milestone57.0a1
WIP api for container icons MozReview-Commit-ID: BosKoxM8FMZ
toolkit/components/extensions/ext-contextualIdentities.js
toolkit/components/extensions/test/xpcshell/test_ext_contextual_identities.js
--- a/toolkit/components/extensions/ext-contextualIdentities.js
+++ b/toolkit/components/extensions/ext-contextualIdentities.js
@@ -14,32 +14,38 @@ const CONTAINER_PREF_INSTALL_DEFAULTS = 
   "privacy.userContext.enabled": true,
   "privacy.userContext.longPressBehavior": 2,
   "privacy.userContext.ui.enabled": true,
   "privacy.usercontext.about_newtab_segregation.enabled": true,
 };
 
 const CONTAINERS_ENABLED_SETTING_NAME = "privacy.containers";
 
+function getContainerIcon(iconName) {
+  return `resource://gre-resources/usercontext/${iconName}.svg`;
+}
+
 const convertIdentity = identity => {
   let result = {
     name: ContextualIdentityService.getUserContextLabel(identity.userContextId),
     icon: identity.icon,
+    iconUrl: getContainerIcon(identity.icon),
     color: identity.color,
     cookieStoreId: getCookieStoreIdForContainer(identity.userContextId),
   };
 
   return result;
 };
 
 const convertIdentityFromObserver = wrappedIdentity => {
   let identity = wrappedIdentity.wrappedJSObject;
   let result = {
     name: identity.name,
     icon: identity.icon,
+    iconUrl: getContainerIcon(identity.icon),
     color: identity.color,
     cookieStoreId: getCookieStoreIdForContainer(identity.userContextId),
   };
 
   return result;
 };
 
 ExtensionPreferencesManager.addSetting(CONTAINERS_ENABLED_SETTING_NAME, {
--- a/toolkit/components/extensions/test/xpcshell/test_ext_contextual_identities.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_contextual_identities.js
@@ -44,46 +44,49 @@ add_task(async function test_contextualI
             resolve(change);
           };
           browser.contextualIdentities[type].addListener(listener);
         } catch (e) {
           reject(e);
         }
       });
     }
+    function iconUrl(iconName) {
+      return `resource://gre-resources/usercontext/${iconName}.svg`;
+    }
 
     function assertExpected(expected, container) {
       for (let key of Object.keys(container)) {
         browser.test.assertTrue(key in expected, `found property ${key}`);
         browser.test.assertEq(expected[key], container[key], `property value for ${key} is correct`);
       }
       browser.test.assertEq(Object.keys(expected).length, Object.keys(container).length, "all expected properties found");
     }
 
     let onCreatePromise = createOneTimeListener("onCreated");
 
     let containerObj = {name: "foobar", color: "red", icon: "icon"};
     let ci = await browser.contextualIdentities.create(containerObj);
     browser.test.assertTrue(!!ci, "We have an identity");
     const onCreateListenerResponse = await onCreatePromise;
     const cookieStoreId = ci.cookieStoreId;
-    assertExpected(onCreateListenerResponse.contextualIdentity, Object.assign(containerObj, {cookieStoreId}));
+    assertExpected(onCreateListenerResponse.contextualIdentity, Object.assign(containerObj, {cookieStoreId, iconUrl: iconUrl(containerObj.icon)}));
 
     let onUpdatedPromise = createOneTimeListener("onUpdated");
     let updateContainerObj = {name: "testing", color: "blue", icon: "thing"};
     ci = await browser.contextualIdentities.update(cookieStoreId, updateContainerObj);
     browser.test.assertTrue(!!ci, "We have an update identity");
     const onUpdatedListenerResponse = await onUpdatedPromise;
-    assertExpected(onUpdatedListenerResponse.contextualIdentity, Object.assign(updateContainerObj, {cookieStoreId}));
+    assertExpected(onUpdatedListenerResponse.contextualIdentity, Object.assign(updateContainerObj, {cookieStoreId, iconUrl: iconUrl(containerObj.icon)}));
 
     let onRemovePromise = createOneTimeListener("onRemoved");
     ci = await browser.contextualIdentities.remove(updateContainerObj.cookieStoreId);
     browser.test.assertTrue(!!ci, "We have an remove identity");
     const onRemoveListenerResponse = await onRemovePromise;
-    assertExpected(onRemoveListenerResponse.contextualIdentity, Object.assign(updateContainerObj, {cookieStoreId}));
+    assertExpected(onRemoveListenerResponse.contextualIdentity, Object.assign(updateContainerObj, {cookieStoreId, iconUrl: iconUrl(updateContainerObj.icon)}));
 
     browser.test.notifyPass("contextualIdentities_events");
   }
 
   let extension = ExtensionTestUtils.loadExtension({
     background,
     useAddonManager: "temporary",
     manifest: {