Bug 1315872: Refactor browser_ext_tabs_cookieStoreId. r?aswan
MozReview-Commit-ID: J4diktOFIQR
--- 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() {