From 431a0117b049b8f9190d780ce84a61432d9123f8 Mon Sep 17 00:00:00 2001 From: Agi Sferro Date: Mon, 19 Apr 2021 19:42:40 +0000 Subject: [PATCH] Bug 1704194 - Add non-about:blank test to tabs_create_cookieStoreId. r=robwu Differential Revision: https://phabricator.services.mozilla.com/D112228 --- .../test_ext_tabs_create_cookieStoreId.html | 47 ++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/toolkit/components/extensions/test/mochitest/test_ext_tabs_create_cookieStoreId.html b/toolkit/components/extensions/test/mochitest/test_ext_tabs_create_cookieStoreId.html index 8768b852e035..b83c683275e5 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_tabs_create_cookieStoreId.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_tabs_create_cookieStoreId.html @@ -134,17 +134,57 @@ add_task(async function valid_cookieStoreId() { cookieStoreId: "firefox-container-1", }, expectedCookieStoreId: "firefox-container-1", - }, + },{ + description: "pass explicit not-blank url", + createProperties: { + url: "http://example.com/", + cookieStoreId: "firefox-container-1", + }, + expectedCookieStoreId: "firefox-container-1", + },{ + description: "pass extension page url", + createProperties: { + url: "blank.html", + cookieStoreId: "firefox-container-1", + }, + expectedCookieStoreId: "firefox-container-1", + } ]; async function background(testCases) { for (let { createProperties, expectedCookieStoreId } of testCases) { - let tab = await browser.tabs.create(createProperties); + const { url } = createProperties; + const updatedPromise = new Promise(resolve => { + const onUpdated = (changedTabId, changed) => { + // Loading an extension page causes two `about:blank` messages + // because of the process switch + if (changed.url && (url == "about:blank" || changed.url != "about:blank")) { + browser.tabs.onUpdated.removeListener(onUpdated); + resolve({tabId: changedTabId, url: changed.url}); + } + }; + browser.tabs.onUpdated.addListener(onUpdated); + }); + + const tab = await browser.tabs.create(createProperties); browser.test.assertEq( expectedCookieStoreId, tab.cookieStoreId, "Expected cookieStoreId for container tab" ); + + if (url && url !== "about:blank") { + // Make sure tab can load successfully + const updated = await updatedPromise; + browser.test.assertEq(tab.id, updated.tabId, `Expected value for tab.id`); + if (updated.url.startsWith("moz-extension")) { + browser.test.assertEq(browser.runtime.getURL(url), updated.url, + `Expected value for extension page url`); + } else { + browser.test.assertEq(url, updated.url, `Expected value for tab.url`); + } + } + await browser.tabs.remove(tab.id); } browser.test.sendMessage("done"); @@ -156,6 +196,9 @@ add_task(async function valid_cookieStoreId() { permissions: ["tabs", "cookies"], applications: { gecko: { id: "cookiestoreid@tests.mozilla.org" } }, }, + files: { + "blank.html": ``, + }, background: `(${background})(${JSON.stringify(testCases)})`, });