Bug 1302697 - Containers and WebExtensions - part 3 - getAllCookieStores, r=kmag
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 28 Oct 2016 10:16:32 +0200
changeset 319974 4c05c0ff09ba00d59b0a5de16a395ef0ef9d87a6
parent 319973 691162eba71737f765cb0dda5470a3a516e0d47d
child 319975 b010bc73909323e71acf61edfb0750f611e68f97
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1302697
milestone52.0a1
Bug 1302697 - Containers and WebExtensions - part 3 - getAllCookieStores, r=kmag
browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js
toolkit/components/extensions/ext-cookies.js
--- a/browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js
@@ -77,21 +77,38 @@ add_task(function* () {
         // Tests for tab querying
         .then((tab) => {
           if (tab) {
             return browser.tabs.query({windowId: data.privateTab ? this.privateWindowId : this.defaultWindowId,
                                        cookieStoreId: data.cookieStoreId})
                    .then((tabs) => {
                      browser.test.assertTrue(tabs.length >= 1, "Tab found!");
                      testTab(data, tabs[0]);
-                     return browser.tabs.remove(tab.id);
+                     return tab;
                    });
           }
         })
 
+        .then((tab) => {
+          if (tab) {
+            return browser.cookies.getAllCookieStores()
+                   .then(stores => {
+                     let store = stores.find(store => store.id === tab.cookieStoreId);
+                     browser.test.assertTrue(!!store, "We have a store for this tab.");
+                     return tab;
+                   });
+          }
+        })
+
+        .then((tab) => {
+          if (tab) {
+            return browser.tabs.remove(tab.id);
+          }
+        })
+
         .then(() => {
           browser.test.sendMessage("test-done");
         }, () => {
           browser.test.fail("An exception has ben thrown");
         });
       }
 
       function initialize() {
--- a/toolkit/components/extensions/ext-cookies.js
+++ b/toolkit/components/extensions/ext-cookies.js
@@ -411,34 +411,30 @@ extensions.registerSchemaAPI("cookies", 
             storeId,
           });
         }
 
         return Promise.resolve(null);
       },
 
       getAllCookieStores: function() {
-        let defaultTabs = [];
-        let privateTabs = [];
+        let data = {};
         for (let window of WindowListManager.browserWindows()) {
           let tabs = TabManager.for(extension).getTabs(window);
           for (let tab of tabs) {
-            if (tab.incognito) {
-              privateTabs.push(tab.id);
-            } else {
-              defaultTabs.push(tab.id);
+            if (!(tab.cookieStoreId in data)) {
+              data[tab.cookieStoreId] = [];
             }
+            data[tab.cookieStoreId].push(tab);
           }
         }
+
         let result = [];
-        if (defaultTabs.length > 0) {
-          result.push({id: DEFAULT_STORE, tabIds: defaultTabs});
-        }
-        if (privateTabs.length > 0) {
-          result.push({id: PRIVATE_STORE, tabIds: privateTabs});
+        for (let key in data) {
+          result.push({id: key, tabIds: data[key], incognito: key == PRIVATE_STORE});
         }
         return Promise.resolve(result);
       },
 
       onChanged: new EventManager(context, "cookies.onChanged", fire => {
         let observer = (subject, topic, data) => {
           let notify = (removed, cookie, cause) => {
             cookie.QueryInterface(Ci.nsICookie2);