Bug 1525458 - Part 2: Update the anti-tracking tests to expect storage access right away when the top-level document is on the allow list and tracking cookies are being blocked per the cookie policy; r=baku

Depends on D20874

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ehsan Akhgari 2019-02-27 20:38:52 +00:00
Родитель cfb1b88614
Коммит ce044ffb6b
14 изменённых файлов: 79 добавлений и 14 удалений

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

@ -20,7 +20,20 @@ function is(a, b, msg) {
}
onmessage = function(e) {
let runnableStr = `(() => {return (${e.data});})();`;
let data = e.data;
if (data.includes("!!!")) {
// The data argument may be packed with information about whether we are on
// the allow list. In that case, extract that information and prepare it
// for our callbacks to access it.
let parts = data.split("!!!");
// Only consider ourselves allow-listed when the cookie policy is set to
// block third-party trackers, since otherwise we won't obtain storage
// access by default, which is what this data is used for in tests.
window.allowListed = parts[0] === "true" &&
(SpecialPowers.Services.prefs.getIntPref("network.cookie.cookieBehavior") == SpecialPowers.Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER);
data = parts[1];
}
let runnableStr = `(() => {return (${data});})();`;
let runnable = eval(runnableStr); // eslint-disable-line no-eval
runnable.call(this, /* Phase */ 1).then(_ => {
parent.postMessage({ type: "finish" }, "*");

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

@ -78,7 +78,11 @@ AntiTracking.runTest("Cookies and Storage Access API",
// Non blocking callback
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await noStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
is(document.cookie, "", "No cookies for me");

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

@ -37,7 +37,11 @@ AntiTracking.runTest("DOM Cache and Storage Access API",
},
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await noStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
await caches.open("wow").then(
_ => { ok(true, "DOM Cache can be used!"); },

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

@ -54,7 +54,11 @@ AntiTracking.runTest("IndexedDB and Storage Access API",
// non-blocking callback
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await noStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
indexedDB.open("test", "1");
ok(true, "IDB should be allowed");

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

@ -145,7 +145,11 @@ AntiTracking.runTest("IndexedDB in workers and Storage Access API",
}
/* import-globals-from storageAccessAPIHelpers.js */
await noStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
let blob = new Blob([nonBlockCode.toString() + "; nonBlockCode();"]);
ok(blob, "Blob has been created");

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

@ -52,7 +52,11 @@ AntiTracking.runTest("localStorage and Storage Access API",
},
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await noStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
localStorage.foo = 42;
ok(true, "LocalStorage is allowed");

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

@ -118,7 +118,11 @@ AntiTracking.runTest("BroadcastChannel and Storage Access API",
},
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await noStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
new BroadcastChannel("hello");
ok(true, "BroadcastChanneli can be used");
@ -215,7 +219,11 @@ AntiTracking.runTest("BroadcastChannel in workers and Storage Access API",
}
/* import-globals-from storageAccessAPIHelpers.js */
await noStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
let blob = new Blob([nonBlockingCode.toString() + "; nonBlockingCode();"]);
ok(blob, "Blob has been created");

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

@ -61,7 +61,11 @@ AntiTracking.runTest("ServiceWorkers and Storage Access API",
]});
/* import-globals-from storageAccessAPIHelpers.js */
await noStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
await navigator.serviceWorker.register("empty.js").then(
reg => { ok(true, "ServiceWorker can be used!"); return reg; },

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

@ -60,7 +60,11 @@ AntiTracking.runTest("sessionStorage and Storage Access API",
},
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await noStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
sessionStorage.foo = 42;
ok(true, "SessionStorage is always allowed");

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

@ -51,7 +51,11 @@ AntiTracking.runTest("SharedWorkers and Storage Access API",
},
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await noStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
new SharedWorker("a.js", "foo");
ok(true, "SharedWorker is allowed");

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

@ -47,7 +47,11 @@ AntiTracking.runTest("localStorage and Storage Access API",
},
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await noStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
localStorage.foo = 42;
ok(true, "LocalStorage is allowed");

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

@ -8,7 +8,11 @@ AntiTracking.runTest("Storage Access is removed when subframe navigates",
// non-blocking callback
async _ => {
/* import-globals-from storageAccessAPIHelpers.js */
await noStorageAccessInitially();
if (allowListed) {
await hasStorageAccessInitially();
} else {
await noStorageAccessInitially();
}
/* import-globals-from storageAccessAPIHelpers.js */
let [threw, rejected] = await callRequestStorageAccess();

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

@ -357,6 +357,7 @@ this.AntiTracking = {
options.callbackAfterRemoval.toString() : null,
accessRemoval: options.accessRemoval,
iframeSandbox: options.iframeSandbox,
allowList: options.allowList,
doAccessRemovalChecks },
async function(obj) {
let id = "id" + Math.random();
@ -365,7 +366,8 @@ this.AntiTracking = {
ifr.id = id;
ifr.onload = function() {
info("Sending code to the 3rd party content");
ifr.contentWindow.postMessage(obj.callback, "*");
let callback = obj.allowList + "!!!" + obj.callback;
ifr.contentWindow.postMessage(callback, "*");
};
if (typeof obj.iframeSandbox == "string") {
ifr.setAttribute("sandbox", obj.iframeSandbox);

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

@ -1,3 +1,5 @@
/* global allowListed */
async function hasStorageAccessInitially() {
let hasAccess = await document.hasStorageAccess();
ok(hasAccess, "Has storage access");