Bug 1536110 - StorageAccess should be propagated to workers, r=Ehsan

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-03-20 01:06:33 +00:00
parent 69f980ffee
commit 1b6bfa6413
4 changed files with 149 additions and 0 deletions

View File

@ -6811,6 +6811,8 @@ void nsGlobalWindowInner::ForgetSharedWorker(SharedWorker* aSharedWorker) {
}
void nsGlobalWindowInner::StorageAccessGranted() {
PropagateFirstPartyStorageAccessGrantedToWorkers(this);
// If we have a partitioned localStorage, it's time to replace it with a real
// one in order to receive notifications.

View File

@ -87,3 +87,5 @@ support-files = localStorage.html
[browser_partitionedLocalStorage.js]
[browser_partitionedLocalStorage_events.js]
support-files = localStorageEvents.html
[browser_workerPropagation.js]
support-files = workerIframe.html

View File

@ -0,0 +1,74 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/* eslint-disable mozilla/no-arbitrary-setTimeout */
add_task(async function() {
info("Starting subResources test");
await SpecialPowers.flushPrefEnv();
await SpecialPowers.pushPrefEnv({"set": [
["browser.contentblocking.allowlist.annotations.enabled", true],
["browser.contentblocking.allowlist.storage.enabled", true],
[ContentBlocking.prefIntroCount, ContentBlocking.MAX_INTROS],
["dom.storage_access.auto_grants", true],
["dom.storage_access.auto_grants.delayed", false],
["dom.storage_access.enabled", true],
["dom.storage_access.prompt.testing", false],
["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
["privacy.trackingprotection.enabled", false],
["privacy.trackingprotection.pbmode.enabled", false],
["privacy.trackingprotection.annotate_channels", true],
["privacy.restrict3rdpartystorage.userInteractionRequiredForHosts", "tracking.example.com,tracking.example.org"],
]});
await UrlClassifierTestUtils.addTestTrackers();
info("Creating a new tab");
let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE);
gBrowser.selectedTab = tab;
let browser = gBrowser.getBrowserForTab(tab);
await BrowserTestUtils.browserLoaded(browser);
// Let's create an iframe and run the test there.
let page = TEST_3RD_PARTY_DOMAIN + TEST_PATH + "workerIframe.html";
await ContentTask.spawn(browser, page, async function(page) {
await new content.Promise(resolve => {
let ifr = content.document.createElement("iframe");
ifr.id = "test";
content.addEventListener("message", e => {
if (e.data.type == "finish") {
resolve();
return;
}
if (e.data.type == "info") {
info(e.data.msg);
return;
}
if (e.data.type == "ok") {
ok(e.data.what, e.data.msg);
return;
}
ok(false, "Unknown message");
});
content.document.body.appendChild(ifr);
ifr.src = page;
});
});
info("Removing the tab");
BrowserTestUtils.removeTab(tab);
});
add_task(async function() {
info("Cleaning up.");
await new Promise(resolve => {
Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
});
});

View File

@ -0,0 +1,71 @@
<html>
<head>
<title>3rd party content!</title>
<script type="text/javascript" src="https://example.com/browser/toolkit/components/antitracking/test/browser/storageAccessAPIHelpers.js"></script>
</head>
<body>
<h1>Here the 3rd party content!</h1>
<script>
function info(msg) {
parent.postMessage({ type: "info", msg }, "*");
}
function ok(what, msg) {
parent.postMessage({ type: "ok", what: !!what, msg }, "*");
}
function is(a, b, msg) {
ok(a === b, msg);
}
async function runTest() {
function workerCode() {
onmessage = e => {
try {
indexedDB.open("test", "1");
postMessage(true);
} catch (e) {
postMessage(false);
}
};
}
/* import-globals-from storageAccessAPIHelpers.js */
await noStorageAccessInitially();
info("Initialized");
let blob = new Blob([workerCode.toString() + "; workerCode();"]);
let blobURL = URL.createObjectURL(blob);
info("Blob created");
let w = new Worker(blobURL);
info("Worker created");
await new Promise(resolve => {
w.addEventListener("message", e => {
ok(!e.data, "IDB is disabled");
resolve();
}, { once: true });
w.postMessage("go");
});
/* import-globals-from storageAccessAPIHelpers.js */
await callRequestStorageAccess();
await new Promise(resolve => {
w.addEventListener("message", e => {
ok(e.data, "IDB is enabled");
resolve();
}, { once: true });
w.postMessage("go");
});
parent.postMessage({ type: "finish" }, "*");
}
runTest();
</script>
</body>
</html>