diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index bcae67de82e3..21da24b7b048 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -15511,23 +15511,12 @@ already_AddRefed Document::RequestStorageAccess( // user settings, anti-clickjacking heuristics, or prompting the // user for explicit permission. Reject if some rule is not fulfilled. - if (nsContentUtils::IsInPrivateBrowsing(this)) { - // If the document is in PB mode, it doesn't have access to its persistent - // cookie jar, so reject the promise here. - promise->MaybeRejectWithUndefined(); - return promise.forget(); - } - if (CookieSettings()->GetRejectThirdPartyTrackers() && inner) { // Only do something special for third-party tracking content. if (StorageDisabledByAntiTracking(this, nullptr)) { // Note: If this has returned true, the top-level document is guaranteed // to not be on the Content Blocking allow list. DebugOnly isOnAllowList = false; - // If we have a parent document, it has to be non-private since we - // verified earlier that our own document is non-private and a private - // document can never have a non-private document as its child. - MOZ_ASSERT_IF(parent, !nsContentUtils::IsInPrivateBrowsing(parent)); MOZ_ASSERT_IF( NS_SUCCEEDED(AntiTrackingCommon::IsOnContentBlockingAllowList( parent->GetDocumentURI(), false, isOnAllowList)), diff --git a/toolkit/components/antitracking/test/browser/browser.ini b/toolkit/components/antitracking/test/browser/browser.ini index f3314117ed03..9109442fff1f 100644 --- a/toolkit/components/antitracking/test/browser/browser.ini +++ b/toolkit/components/antitracking/test/browser/browser.ini @@ -89,8 +89,6 @@ support-files = tracker.js [browser_userInteraction.js] [browser_storageAccessDoorHanger.js] skip-if = fission -[browser_storageAccessPrivateWindow.js] -skip-if = fission || serviceworker_e10s [browser_storageAccessPromiseRejectHandlerUserInteraction.js] skip-if = fission [browser_storageAccessPromiseResolveHandlerUserInteraction.js] diff --git a/toolkit/components/antitracking/test/browser/browser_blockingCookies.js b/toolkit/components/antitracking/test/browser/browser_blockingCookies.js index 651c8cd3dea7..44177dedc399 100644 --- a/toolkit/components/antitracking/test/browser/browser_blockingCookies.js +++ b/toolkit/components/antitracking/test/browser/browser_blockingCookies.js @@ -56,7 +56,7 @@ AntiTracking.runTestInNormalAndPrivateMode( } ); -AntiTracking.runTest( +AntiTracking.runTestInNormalAndPrivateMode( "Cookies and Storage Access API", // Blocking callback async _ => { diff --git a/toolkit/components/antitracking/test/browser/browser_blockingIndexedDb.js b/toolkit/components/antitracking/test/browser/browser_blockingIndexedDb.js index 6d3dbd75ce07..61f578da2315 100644 --- a/toolkit/components/antitracking/test/browser/browser_blockingIndexedDb.js +++ b/toolkit/components/antitracking/test/browser/browser_blockingIndexedDb.js @@ -27,7 +27,7 @@ AntiTracking.runTestInNormalAndPrivateMode( } ); -AntiTracking.runTest( +AntiTracking.runTestInNormalAndPrivateMode( "IndexedDB and Storage Access API", // blocking callback async _ => { diff --git a/toolkit/components/antitracking/test/browser/browser_blockingIndexedDbInWorkers.js b/toolkit/components/antitracking/test/browser/browser_blockingIndexedDbInWorkers.js index 1b467914ba9f..16d0dfe76f38 100644 --- a/toolkit/components/antitracking/test/browser/browser_blockingIndexedDbInWorkers.js +++ b/toolkit/components/antitracking/test/browser/browser_blockingIndexedDbInWorkers.js @@ -73,7 +73,7 @@ AntiTracking.runTestInNormalAndPrivateMode( } ); -AntiTracking.runTest( +AntiTracking.runTestInNormalAndPrivateMode( "IndexedDB in workers and Storage Access API", async _ => { function blockCode() { diff --git a/toolkit/components/antitracking/test/browser/browser_blockingLocalStorage.js b/toolkit/components/antitracking/test/browser/browser_blockingLocalStorage.js index df920afaaa04..2914a3bf9abb 100644 --- a/toolkit/components/antitracking/test/browser/browser_blockingLocalStorage.js +++ b/toolkit/components/antitracking/test/browser/browser_blockingLocalStorage.js @@ -25,7 +25,7 @@ AntiTracking.runTestInNormalAndPrivateMode( } ); -AntiTracking.runTest( +AntiTracking.runTestInNormalAndPrivateMode( "localStorage and Storage Access API", async _ => { /* import-globals-from storageAccessAPIHelpers.js */ diff --git a/toolkit/components/antitracking/test/browser/browser_blockingMessaging.js b/toolkit/components/antitracking/test/browser/browser_blockingMessaging.js index 7a8c40668c09..4819cce197e5 100644 --- a/toolkit/components/antitracking/test/browser/browser_blockingMessaging.js +++ b/toolkit/components/antitracking/test/browser/browser_blockingMessaging.js @@ -97,7 +97,7 @@ AntiTracking.runTestInNormalAndPrivateMode( } ); -AntiTracking.runTest( +AntiTracking.runTestInNormalAndPrivateMode( "BroadcastChannel and Storage Access API", async _ => { /* import-globals-from storageAccessAPIHelpers.js */ @@ -160,7 +160,7 @@ AntiTracking.runTest( false ); -AntiTracking.runTest( +AntiTracking.runTestInNormalAndPrivateMode( "BroadcastChannel in workers and Storage Access API", async _ => { function blockingCode() { diff --git a/toolkit/components/antitracking/test/browser/browser_blockingSessionStorage.js b/toolkit/components/antitracking/test/browser/browser_blockingSessionStorage.js index 955a346fa023..d802fe8df3ad 100644 --- a/toolkit/components/antitracking/test/browser/browser_blockingSessionStorage.js +++ b/toolkit/components/antitracking/test/browser/browser_blockingSessionStorage.js @@ -40,7 +40,7 @@ AntiTracking.runTestInNormalAndPrivateMode( 0 ); -AntiTracking.runTest( +AntiTracking.runTestInNormalAndPrivateMode( "sessionStorage and Storage Access API", async _ => { /* import-globals-from storageAccessAPIHelpers.js */ diff --git a/toolkit/components/antitracking/test/browser/browser_blockingSharedWorkers.js b/toolkit/components/antitracking/test/browser/browser_blockingSharedWorkers.js index e85afbf1b3c8..aabe1124e1a9 100644 --- a/toolkit/components/antitracking/test/browser/browser_blockingSharedWorkers.js +++ b/toolkit/components/antitracking/test/browser/browser_blockingSharedWorkers.js @@ -26,7 +26,7 @@ AntiTracking.runTestInNormalAndPrivateMode( } ); -AntiTracking.runTest( +AntiTracking.runTestInNormalAndPrivateMode( "SharedWorkers and Storage Access API", async _ => { /* import-globals-from storageAccessAPIHelpers.js */ diff --git a/toolkit/components/antitracking/test/browser/browser_partitionedCookies.js b/toolkit/components/antitracking/test/browser/browser_partitionedCookies.js index eb0c4f47daba..e9c4d26f5059 100644 --- a/toolkit/components/antitracking/test/browser/browser_partitionedCookies.js +++ b/toolkit/components/antitracking/test/browser/browser_partitionedCookies.js @@ -1,6 +1,6 @@ /* import-globals-from partitionedstorage_head.js */ -PartitionedStorageHelper.runTest( +PartitionedStorageHelper.runTestInNormalAndPrivateMode( "HTTP Cookies", async (win3rdParty, win1stParty, allowed) => { await win3rdParty.fetch("cookies.sjs?3rd").then(r => r.text()); @@ -48,7 +48,7 @@ PartitionedStorageHelper.runTest( } ); -PartitionedStorageHelper.runTest( +PartitionedStorageHelper.runTestInNormalAndPrivateMode( "DOM Cookies", async (win3rdParty, win1stParty, allowed) => { win3rdParty.document.cookie = "foo=3rd"; @@ -81,7 +81,7 @@ PartitionedStorageHelper.runTest( } ); -PartitionedStorageHelper.runPartitioningTest( +PartitionedStorageHelper.runPartitioningTestInNormalAndPrivateMode( "Partitioned tabs - DOM Cookies", // getDataCallback @@ -105,7 +105,7 @@ PartitionedStorageHelper.runPartitioningTest( } ); -PartitionedStorageHelper.runPartitioningTest( +PartitionedStorageHelper.runPartitioningTestInNormalAndPrivateMode( "Partitioned tabs - Network Cookies", // getDataCallback diff --git a/toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage.js b/toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage.js index 403dcb46c76d..72e8bf167272 100644 --- a/toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage.js +++ b/toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage.js @@ -1,7 +1,7 @@ /* import-globals-from antitracking_head.js */ /* import-globals-from partitionedstorage_head.js */ -AntiTracking.runTest( +AntiTracking.runTestInNormalAndPrivateMode( "localStorage and Storage Access API", async _ => { /* import-globals-from storageAccessAPIHelpers.js */ @@ -93,7 +93,7 @@ AntiTracking.runTest( false ); -PartitionedStorageHelper.runPartitioningTest( +PartitionedStorageHelper.runPartitioningTestInNormalAndPrivateMode( "Partitioned tabs - localStorage", // getDataCallback diff --git a/toolkit/components/antitracking/test/browser/browser_partitionedMessaging.js b/toolkit/components/antitracking/test/browser/browser_partitionedMessaging.js index 4238847c299c..7e706f220a57 100644 --- a/toolkit/components/antitracking/test/browser/browser_partitionedMessaging.js +++ b/toolkit/components/antitracking/test/browser/browser_partitionedMessaging.js @@ -1,6 +1,6 @@ /* import-globals-from partitionedstorage_head.js */ -PartitionedStorageHelper.runTest( +PartitionedStorageHelper.runTestInNormalAndPrivateMode( "BroadcastChannel", async (win3rdParty, win1stParty, allowed) => { let a = new win3rdParty.BroadcastChannel("hello"); diff --git a/toolkit/components/antitracking/test/browser/browser_partitionedSharedWorkers.js b/toolkit/components/antitracking/test/browser/browser_partitionedSharedWorkers.js index f909445225fd..9c00477ff5a3 100644 --- a/toolkit/components/antitracking/test/browser/browser_partitionedSharedWorkers.js +++ b/toolkit/components/antitracking/test/browser/browser_partitionedSharedWorkers.js @@ -1,6 +1,6 @@ /* import-globals-from partitionedstorage_head.js */ -PartitionedStorageHelper.runTest( +PartitionedStorageHelper.runTestInNormalAndPrivateMode( "SharedWorkers", async (win3rdParty, win1stParty, allowed) => { // This test fails if run with an HTTPS 3rd-party URL because the shared worker @@ -53,7 +53,7 @@ PartitionedStorageHelper.runTest( } ); -PartitionedStorageHelper.runPartitioningTest( +PartitionedStorageHelper.runPartitioningTestInNormalAndPrivateMode( "Partitioned tabs - SharedWorker", // getDataCallback diff --git a/toolkit/components/antitracking/test/browser/browser_storageAccessPrivateWindow.js b/toolkit/components/antitracking/test/browser/browser_storageAccessPrivateWindow.js deleted file mode 100644 index cbc7d1a19de4..000000000000 --- a/toolkit/components/antitracking/test/browser/browser_storageAccessPrivateWindow.js +++ /dev/null @@ -1,28 +0,0 @@ -/* import-globals-from antitracking_head.js */ - -AntiTracking.runTest( - "Storage Access API called in a private window", - // blocking callback - async _ => { - /* import-globals-from storageAccessAPIHelpers.js */ - let [threw, rejected] = await callRequestStorageAccess(); - ok(!threw, "requestStorageAccess should not throw"); - ok(rejected, "requestStorageAccess shouldn't be available"); - }, - - null, // non-blocking callback - // cleanup function - async _ => { - await new Promise(resolve => { - Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => - resolve() - ); - }); - }, - [["dom.storage_access.enabled", true]], // extra prefs - false, // no window open test - false, // no user-interaction test - 0, // no blocking notifications - true, // run in private window - null // iframe sandbox -); diff --git a/toolkit/components/antitracking/test/browser/dynamicfpi_head.js b/toolkit/components/antitracking/test/browser/dynamicfpi_head.js index 31098af669f0..e21940ed80e7 100644 --- a/toolkit/components/antitracking/test/browser/dynamicfpi_head.js +++ b/toolkit/components/antitracking/test/browser/dynamicfpi_head.js @@ -8,9 +8,15 @@ "use strict"; this.DynamicFPIHelper = { - runTest(name, callback, cleanupFunction, extraPrefs) { + runTest(name, callback, cleanupFunction, extraPrefs, runInPrivateWindow) { add_task(async _ => { - info("Starting test `" + name + "' with dynamic FPI..."); + info( + "Starting test `" + + name + + "' with dynamic FPI running in a " + + (runInPrivateWindow ? "private" : "normal") + + " window..." + ); await SpecialPowers.flushPrefEnv(); await SpecialPowers.pushPrefEnv({ @@ -35,11 +41,17 @@ this.DynamicFPIHelper = { await SpecialPowers.pushPrefEnv({ set: extraPrefs }); } - info("Creating a new tab"); - let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE); - gBrowser.selectedTab = tab; + let win = window; + if (runInPrivateWindow) { + win = OpenBrowserWindow({ private: true }); + await TestUtils.topicObserved("browser-delayed-startup-finished"); + } - let browser = gBrowser.getBrowserForTab(tab); + info("Creating a new tab"); + let tab = BrowserTestUtils.addTab(win.gBrowser, TEST_TOP_PAGE); + win.gBrowser.selectedTab = tab; + + let browser = win.gBrowser.getBrowserForTab(tab); await BrowserTestUtils.browserLoaded(browser); info("Creating a 3rd party content"); @@ -97,6 +109,10 @@ this.DynamicFPIHelper = { info("Removing the tab"); BrowserTestUtils.removeTab(tab); + + if (runInPrivateWindow) { + win.close(); + } }); add_task(async _ => { diff --git a/toolkit/components/antitracking/test/browser/partitionedstorage_head.js b/toolkit/components/antitracking/test/browser/partitionedstorage_head.js index 31a5468e47f1..0823eff2163a 100644 --- a/toolkit/components/antitracking/test/browser/partitionedstorage_head.js +++ b/toolkit/components/antitracking/test/browser/partitionedstorage_head.js @@ -20,25 +20,84 @@ Services.scriptloader.loadSubScript( ); this.PartitionedStorageHelper = { - runTest(name, callback, cleanupFunction, extraPrefs) { - DynamicFPIHelper.runTest(name, callback, cleanupFunction, extraPrefs); - StoragePrincipalHelper.runTest(name, callback, cleanupFunction, extraPrefs); + runTestInNormalAndPrivateMode(name, callback, cleanupFunction, extraPrefs) { + // Normal mode + this.runTest(name, callback, cleanupFunction, extraPrefs, false); + + // Private mode + this.runTest(name, callback, cleanupFunction, extraPrefs, true); }, - runPartitioningTest(name, getDataCallback, addDataCallback, cleanupFunction) { + runTest( + name, + callback, + cleanupFunction, + extraPrefs, + runInPrivateWindow = false + ) { + DynamicFPIHelper.runTest( + name, + callback, + cleanupFunction, + extraPrefs, + runInPrivateWindow + ); + StoragePrincipalHelper.runTest( + name, + callback, + cleanupFunction, + extraPrefs, + runInPrivateWindow + ); + }, + + runPartitioningTestInNormalAndPrivateMode( + name, + getDataCallback, + addDataCallback, + cleanupFunction + ) { + // Normal mode + this.runPartitioningTest( + name, + getDataCallback, + addDataCallback, + cleanupFunction, + false + ); + + // Private mode + this.runPartitioningTest( + name, + getDataCallback, + addDataCallback, + cleanupFunction, + true + ); + }, + + runPartitioningTest( + name, + getDataCallback, + addDataCallback, + cleanupFunction, + runInPrivateWindow = false + ) { this.runPartitioningTestInner( name, getDataCallback, addDataCallback, cleanupFunction, - "normal" + "normal", + runInPrivateWindow ); this.runPartitioningTestInner( name, getDataCallback, addDataCallback, cleanupFunction, - "initial-aboutblank" + "initial-aboutblank", + runInPrivateWindow ); }, @@ -47,7 +106,8 @@ this.PartitionedStorageHelper = { getDataCallback, addDataCallback, cleanupFunction, - variant + variant, + runInPrivateWindow ) { add_task(async _ => { info( @@ -55,7 +115,9 @@ this.PartitionedStorageHelper = { name + "' variant `" + variant + - "' to check that 2 tabs are correctly partititioned" + "' in a " + + (runInPrivateWindow ? "private" : "normal") + + " window to check that 2 tabs are correctly partititioned" ); await SpecialPowers.flushPrefEnv(); @@ -77,28 +139,34 @@ this.PartitionedStorageHelper = { ], }); - info("Creating the first tab"); - let tab1 = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE); - gBrowser.selectedTab = tab1; + let win = window; + if (runInPrivateWindow) { + win = OpenBrowserWindow({ private: true }); + await TestUtils.topicObserved("browser-delayed-startup-finished"); + } - let browser1 = gBrowser.getBrowserForTab(tab1); + info("Creating the first tab"); + let tab1 = BrowserTestUtils.addTab(win.gBrowser, TEST_TOP_PAGE); + win.gBrowser.selectedTab = tab1; + + let browser1 = win.gBrowser.getBrowserForTab(tab1); await BrowserTestUtils.browserLoaded(browser1); info("Creating the second tab"); - let tab2 = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE_6); - gBrowser.selectedTab = tab2; + let tab2 = BrowserTestUtils.addTab(win.gBrowser, TEST_TOP_PAGE_6); + win.gBrowser.selectedTab = tab2; - let browser2 = gBrowser.getBrowserForTab(tab2); + let browser2 = win.gBrowser.getBrowserForTab(tab2); await BrowserTestUtils.browserLoaded(browser2); info("Creating the third tab"); let tab3 = BrowserTestUtils.addTab( - gBrowser, + win.gBrowser, TEST_4TH_PARTY_PARTITIONED_PAGE ); - gBrowser.selectedTab = tab3; + win.gBrowser.selectedTab = tab3; - let browser3 = gBrowser.getBrowserForTab(tab3); + let browser3 = win.gBrowser.getBrowserForTab(tab3); await BrowserTestUtils.browserLoaded(browser3); async function getDataFromThirdParty(browser, result) { @@ -256,6 +324,10 @@ this.PartitionedStorageHelper = { BrowserTestUtils.removeTab(tab1); BrowserTestUtils.removeTab(tab2); BrowserTestUtils.removeTab(tab3); + + if (runInPrivateWindow) { + win.close(); + } }); add_task(async _ => { diff --git a/toolkit/components/antitracking/test/browser/storageprincipal_head.js b/toolkit/components/antitracking/test/browser/storageprincipal_head.js index cdc63cec85a0..09c61eb7137b 100644 --- a/toolkit/components/antitracking/test/browser/storageprincipal_head.js +++ b/toolkit/components/antitracking/test/browser/storageprincipal_head.js @@ -8,9 +8,15 @@ "use strict"; this.StoragePrincipalHelper = { - runTest(name, callback, cleanupFunction, extraPrefs) { + runTest(name, callback, cleanupFunction, extraPrefs, runInPrivateWindow) { add_task(async _ => { - info("Starting test `" + name + "' with storage principal..."); + info( + "Starting test `" + + name + + "' with storage principal running in a " + + (runInPrivateWindow ? "private" : "normal") + + " window..." + ); await SpecialPowers.flushPrefEnv(); await SpecialPowers.pushPrefEnv({ @@ -37,11 +43,17 @@ this.StoragePrincipalHelper = { await UrlClassifierTestUtils.addTestTrackers(); - info("Creating a new tab"); - let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE); - gBrowser.selectedTab = tab; + let win = window; + if (runInPrivateWindow) { + win = OpenBrowserWindow({ private: true }); + await TestUtils.topicObserved("browser-delayed-startup-finished"); + } - let browser = gBrowser.getBrowserForTab(tab); + info("Creating a new tab"); + let tab = BrowserTestUtils.addTab(win.gBrowser, TEST_TOP_PAGE); + win.gBrowser.selectedTab = tab; + + let browser = win.gBrowser.getBrowserForTab(tab); await BrowserTestUtils.browserLoaded(browser); info("Creating a 3rd party content"); @@ -99,6 +111,10 @@ this.StoragePrincipalHelper = { info("Removing the tab"); BrowserTestUtils.removeTab(tab); + + if (runInPrivateWindow) { + win.close(); + } }); add_task(async _ => {