Bug 1315872: Refactor browser_ext_tabs_cookieStoreId. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Mon, 07 Nov 2016 22:08:24 -0800
changeset 435222 6209a00f1dc055785ef2c6deafd2352b1d63914a
parent 435221 f6ebc5d9665d33993d1d627c654e6f2484eb21c2
child 536240 cf36d12eb3803905b2e4b90fcfe7617d84b2d60b
push id34962
push usermaglione.k@gmail.com
push dateTue, 08 Nov 2016 06:10:49 +0000
reviewersaswan
bugs1315872
milestone52.0a1
Bug 1315872: Refactor browser_ext_tabs_cookieStoreId. r?aswan MozReview-Commit-ID: J4diktOFIQR
browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js
--- a/browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js
@@ -40,25 +40,27 @@ add_task(function* () {
         browser.test.assertTrue(data.success, "we want a success");
         browser.test.assertTrue(!!tab, "we have a tab");
         browser.test.assertEq(data.expectedCookieStoreId, tab.cookieStoreId, "tab should have the correct cookieStoreId");
       }
 
       async function runTest(data) {
         try {
           // Tab Creation
-          let tab = await browser.tabs.create({
-            windowId: data.privateTab ? this.privateWindowId : this.defaultWindowId,
-            cookieStoreId: data.cookieStoreId,
-          }).then((tab) => {
-            // Tests for tab creation
-            testTab(data, tab);
-            return tab;
-          }, (error) => {
+          let tab;
+          try {
+            tab = await browser.tabs.create({
+              windowId: data.privateTab ? this.privateWindowId : this.defaultWindowId,
+              cookieStoreId: data.cookieStoreId,
+            });
+
+            browser.test.assertTrue(!data.failure, "we want a success");
+          } catch (error) {
             browser.test.assertTrue(!!data.failure, "we want a failure");
+
             if (data.failure == "illegal") {
               browser.test.assertTrue(/Illegal cookieStoreId/.test(error.message),
                                       "runtime.lastError should report the expected error message");
             } else if (data.failure == "defaultToPrivate") {
               browser.test.assertTrue("Illegal to set private cookieStorageId in a non private window",
                                       error.message,
                                       "runtime.lastError should report the expected error message");
             } else if (data.failure == "privateToDefault") {
@@ -67,38 +69,40 @@ add_task(function* () {
                                       "runtime.lastError should report the expected error message");
             } else if (data.failure == "exist") {
               browser.test.assertTrue(/No cookie store exists/.test(error.message),
                                       "runtime.lastError should report the expected error message");
             } else {
               browser.test.fail("The test is broken");
             }
 
-            return null;
-          });
+            browser.test.sendMessage("test-done");
+            return;
+          }
 
-          if (tab) {
-            {
-              // Tests for tab querying
-              let [tab] = await browser.tabs.query({
-                windowId: data.privateTab ? this.privateWindowId : this.defaultWindowId,
-                cookieStoreId: data.cookieStoreId,
-              });
+          // Tests for tab creation
+          testTab(data, tab);
 
-              browser.test.assertTrue(tab != undefined, "Tab found!");
-              testTab(data, tab);
-            }
-
-            let stores = await browser.cookies.getAllCookieStores();
+          {
+            // Tests for tab querying
+            let [tab] = await browser.tabs.query({
+              windowId: data.privateTab ? this.privateWindowId : this.defaultWindowId,
+              cookieStoreId: data.cookieStoreId,
+            });
 
-            let store = stores.find(store => store.id === tab.cookieStoreId);
-            browser.test.assertTrue(!!store, "We have a store for this tab.");
+            browser.test.assertTrue(tab != undefined, "Tab found!");
+            testTab(data, tab);
+          }
 
-            await browser.tabs.remove(tab.id);
-          }
+          let stores = await browser.cookies.getAllCookieStores();
+
+          let store = stores.find(store => store.id === tab.cookieStoreId);
+          browser.test.assertTrue(!!store, "We have a store for this tab.");
+
+          await browser.tabs.remove(tab.id);
 
           browser.test.sendMessage("test-done");
         } catch (e) {
           browser.test.fail("An exception has been thrown");
         }
       }
 
       async function initialize() {