Bug 1570802 - Relax the Storage Access API rules to allow calling the API from private browsing mode; r=baku

Differential Revision: https://phabricator.services.mozilla.com/D40883

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ehsan Akhgari 2019-08-07 06:20:35 +00:00
Родитель 5537145c64
Коммит 2aeb59e775
17 изменённых файлов: 151 добавлений и 84 удалений

Просмотреть файл

@ -15511,13 +15511,6 @@ already_AddRefed<mozilla::dom::Promise> 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)) {

Просмотреть файл

@ -91,8 +91,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]

Просмотреть файл

@ -56,7 +56,7 @@ AntiTracking.runTestInNormalAndPrivateMode(
}
);
AntiTracking.runTest(
AntiTracking.runTestInNormalAndPrivateMode(
"Cookies and Storage Access API",
// Blocking callback
async _ => {

Просмотреть файл

@ -27,7 +27,7 @@ AntiTracking.runTestInNormalAndPrivateMode(
}
);
AntiTracking.runTest(
AntiTracking.runTestInNormalAndPrivateMode(
"IndexedDB and Storage Access API",
// blocking callback
async _ => {

Просмотреть файл

@ -73,7 +73,7 @@ AntiTracking.runTestInNormalAndPrivateMode(
}
);
AntiTracking.runTest(
AntiTracking.runTestInNormalAndPrivateMode(
"IndexedDB in workers and Storage Access API",
async _ => {
function blockCode() {

Просмотреть файл

@ -25,7 +25,7 @@ AntiTracking.runTestInNormalAndPrivateMode(
}
);
AntiTracking.runTest(
AntiTracking.runTestInNormalAndPrivateMode(
"localStorage and Storage Access API",
async _ => {
/* import-globals-from storageAccessAPIHelpers.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() {

Просмотреть файл

@ -40,7 +40,7 @@ AntiTracking.runTestInNormalAndPrivateMode(
0
);
AntiTracking.runTest(
AntiTracking.runTestInNormalAndPrivateMode(
"sessionStorage and Storage Access API",
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */

Просмотреть файл

@ -26,7 +26,7 @@ AntiTracking.runTestInNormalAndPrivateMode(
}
);
AntiTracking.runTest(
AntiTracking.runTestInNormalAndPrivateMode(
"SharedWorkers and Storage Access API",
async _ => {
/* import-globals-from storageAccessAPIHelpers.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

Просмотреть файл

@ -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

Просмотреть файл

@ -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");

Просмотреть файл

@ -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

Просмотреть файл

@ -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
);

Просмотреть файл

@ -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 _ => {

Просмотреть файл

@ -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 _ => {

Просмотреть файл

@ -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 _ => {