From 2be53ae148b2a6d52f7761564bde5155f05d9e68 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 7 Nov 2016 22:08:24 -0800 Subject: [PATCH] Bug 1315872: Refactor browser_ext_tabs_cookieStoreId. r=aswan MozReview-Commit-ID: J4diktOFIQR --HG-- extra : rebase_source : 56de8d0b34022ec82f6550b9cfcb34bb870e38ab extra : histedit_source : c0ae98a25ed447226e44bc3c18700850fe70865c --- .../browser/browser_ext_tabs_cookieStoreId.js | 62 ++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js b/browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js index 19b8a6b71acf..dc0647e3cc3f 100644 --- a/browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js +++ b/browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js @@ -45,15 +45,17 @@ add_task(function* () { 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"); @@ -72,29 +74,31 @@ add_task(function* () { browser.test.fail("The test is broken"); } - return null; - }); - - if (tab) { - { - // Tests for tab querying - let [tab] = await browser.tabs.query({ - windowId: data.privateTab ? this.privateWindowId : this.defaultWindowId, - cookieStoreId: data.cookieStoreId, - }); - - browser.test.assertTrue(tab != undefined, "Tab found!"); - testTab(data, tab); - } - - 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"); + return; } + // Tests for tab creation + testTab(data, tab); + + { + // Tests for tab querying + let [tab] = await browser.tabs.query({ + windowId: data.privateTab ? this.privateWindowId : this.defaultWindowId, + cookieStoreId: data.cookieStoreId, + }); + + browser.test.assertTrue(tab != undefined, "Tab found!"); + testTab(data, tab); + } + + 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");