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
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 21 Feb 2019 14:56:59 -0500
changeset 461870 03f6a90e46bd71ce3f8827c4dfedba6abd509867
parent 461869 d32503125d279a4729ddd5f2e62dd9a1a2f04d65
child 461871 bfadbf643f32e259d45f8b5af88c0300dc17b68f
push id35631
push userrgurzau@mozilla.com
push dateFri, 01 Mar 2019 13:06:03 +0000
treeherdermozilla-central@d4e19870e27f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1525458
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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 Differential Revision: https://phabricator.services.mozilla.com/D20875
toolkit/components/antitracking/test/browser/3rdParty.html
toolkit/components/antitracking/test/browser/browser_blockingCookies.js
toolkit/components/antitracking/test/browser/browser_blockingDOMCache.js
toolkit/components/antitracking/test/browser/browser_blockingIndexedDb.js
toolkit/components/antitracking/test/browser/browser_blockingIndexedDbInWorkers.js
toolkit/components/antitracking/test/browser/browser_blockingLocalStorage.js
toolkit/components/antitracking/test/browser/browser_blockingMessaging.js
toolkit/components/antitracking/test/browser/browser_blockingServiceWorkers.js
toolkit/components/antitracking/test/browser/browser_blockingSessionStorage.js
toolkit/components/antitracking/test/browser/browser_blockingSharedWorkers.js
toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage.js
toolkit/components/antitracking/test/browser/browser_storageAccessRemovalNavigateSubframe.js
toolkit/components/antitracking/test/browser/head.js
toolkit/components/antitracking/test/browser/storageAccessAPIHelpers.js
--- a/toolkit/components/antitracking/test/browser/3rdParty.html
+++ b/toolkit/components/antitracking/test/browser/3rdParty.html
@@ -15,17 +15,30 @@ function ok(what, msg) {
   parent.postMessage({ type: "ok", what: !!what, msg }, "*");
 }
 
 function is(a, b, msg) {
   ok(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" }, "*");
   });
 };
 
 </script>
 </body>
--- a/toolkit/components/antitracking/test/browser/browser_blockingCookies.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingCookies.js
@@ -73,17 +73,21 @@ AntiTracking.runTest("Cookies and Storag
     } else {
       is(document.cookie, "name=value", "I have the cookies!");
     }
   },
 
   // 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");
 
     await fetch("server.sjs").then(r => r.text()).then(text => {
       is(text, "cookie-not-present", "We should not have cookies");
     });
 
     document.cookie = "name=value";
--- a/toolkit/components/antitracking/test/browser/browser_blockingDOMCache.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingDOMCache.js
@@ -32,17 +32,21 @@ AntiTracking.runTest("DOM Cache and Stor
     let shouldThrow = SpecialPowers.Services.prefs.getIntPref("network.cookie.cookieBehavior") == SpecialPowers.Ci.nsICookieService.BEHAVIOR_REJECT;
 
     await caches.open("wow").then(
       _ => { ok(!shouldThrow, "DOM Cache can be used!"); },
       _ => { ok(shouldThrow, "DOM Cache can be used!"); });
   },
   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!"); },
       _ => { ok(false, "DOM Cache can be used!"); });
 
     /* import-globals-from storageAccessAPIHelpers.js */
     await callRequestStorageAccess();
 
--- a/toolkit/components/antitracking/test/browser/browser_blockingIndexedDb.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingIndexedDb.js
@@ -49,17 +49,21 @@ AntiTracking.runTest("IndexedDB and Stor
       is(e.name, "SecurityError", "We want a security error message.");
     }
 
     is(hasThrown, shouldThrow, "IDB should be allowed if not in BEHAVIOR_REJECT");
   },
   // 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");
 
     await callRequestStorageAccess();
 
     // For non-tracking windows, calling the API is a no-op
     indexedDB.open("test", "1");
--- a/toolkit/components/antitracking/test/browser/browser_blockingIndexedDbInWorkers.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingIndexedDbInWorkers.js
@@ -140,17 +140,21 @@ AntiTracking.runTest("IndexedDB in worke
   },
   async _ => {
     function nonBlockCode() {
       indexedDB.open("test", "1");
       postMessage(true);
     }
 
     /* 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");
 
     let blobURL = URL.createObjectURL(blob);
     ok(blobURL, "Blob URL has been created");
 
     let worker = new Worker(blobURL);
--- a/toolkit/components/antitracking/test/browser/browser_blockingLocalStorage.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingLocalStorage.js
@@ -47,17 +47,21 @@ AntiTracking.runTest("localStorage and S
       }
     } else {
       localStorage.foo = 42;
       ok(true, "LocalStorage is allowed");
     }
   },
   async _ => {
     /* import-globals-from storageAccessAPIHelpers.js */
-    await noStorageAccessInitially();
+    if (allowListed) {
+      await hasStorageAccessInitially();
+    } else {
+      await noStorageAccessInitially();
+    }
 
     localStorage.foo = 42;
     ok(true, "LocalStorage is allowed");
 
     /* import-globals-from storageAccessAPIHelpers.js */
     await callRequestStorageAccess();
 
     // For non-tracking windows, calling the API is a no-op
--- a/toolkit/components/antitracking/test/browser/browser_blockingMessaging.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingMessaging.js
@@ -113,17 +113,21 @@ AntiTracking.runTest("BroadcastChannel a
       }
     } else {
       new BroadcastChannel("hello");
       ok(true, "BroadcastChannel can be used");
     }
   },
   async _ => {
     /* import-globals-from storageAccessAPIHelpers.js */
-    await noStorageAccessInitially();
+    if (allowListed) {
+      await hasStorageAccessInitially();
+    } else {
+      await noStorageAccessInitially();
+    }
 
     new BroadcastChannel("hello");
     ok(true, "BroadcastChanneli can be used");
 
     /* import-globals-from storageAccessAPIHelpers.js */
     await callRequestStorageAccess();
 
     new BroadcastChannel("hello");
@@ -210,17 +214,21 @@ AntiTracking.runTest("BroadcastChannel i
   },
   async _ => {
     function nonBlockingCode() {
       new BroadcastChannel("hello");
       postMessage(true);
     }
 
     /* 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");
 
     let blobURL = URL.createObjectURL(blob);
     ok(blobURL, "Blob URL has been created");
 
     let worker = new Worker(blobURL);
--- a/toolkit/components/antitracking/test/browser/browser_blockingServiceWorkers.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingServiceWorkers.js
@@ -56,17 +56,21 @@ AntiTracking.runTest("ServiceWorkers and
     await SpecialPowers.pushPrefEnv({"set": [
        ["dom.serviceWorkers.exemptFromPerDomainMax", true],
        ["dom.ipc.processCount", 1],
        ["dom.serviceWorkers.enabled", true],
        ["dom.serviceWorkers.testing.enabled", true],
     ]});
 
     /* 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; },
       _ => { ok(false, "ServiceWorker cannot be used!"); }).then(
       reg => reg.unregister(),
       _ => { ok(false, "unregister failed"); }).
       catch(e => ok(false, "Promise rejected: " + e));
 
--- a/toolkit/components/antitracking/test/browser/browser_blockingSessionStorage.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingSessionStorage.js
@@ -55,17 +55,21 @@ AntiTracking.runTest("sessionStorage and
       hasThrown = true;
       is(e.name, "SecurityError", "We want a security error message.");
     }
 
     is(hasThrown, shouldThrow, "SessionStorage show thrown only if cookieBehavior is REJECT");
   },
   async _ => {
     /* import-globals-from storageAccessAPIHelpers.js */
-    await noStorageAccessInitially();
+    if (allowListed) {
+      await hasStorageAccessInitially();
+    } else {
+      await noStorageAccessInitially();
+    }
 
     sessionStorage.foo = 42;
     ok(true, "SessionStorage is always allowed");
 
     /* import-globals-from storageAccessAPIHelpers.js */
     await callRequestStorageAccess();
 
     // For non-tracking windows, calling the API is a no-op
--- a/toolkit/components/antitracking/test/browser/browser_blockingSharedWorkers.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingSharedWorkers.js
@@ -46,17 +46,21 @@ AntiTracking.runTest("SharedWorkers and 
       }
     } else {
       new SharedWorker("a.js", "foo");
       ok(true, "SharedWorker is allowed");
     }
   },
   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");
 
     /* import-globals-from storageAccessAPIHelpers.js */
     await callRequestStorageAccess();
 
     // For non-tracking windows, calling the API is a no-op
--- a/toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage.js
+++ b/toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage.js
@@ -42,17 +42,21 @@ AntiTracking.runTest("localStorage and S
 
       localStorage.foo = 42;
       ok(true, "LocalStorage is still allowed");
       is(localStorage.foo, "42", "The value matches");
     }
   },
   async _ => {
     /* import-globals-from storageAccessAPIHelpers.js */
-    await noStorageAccessInitially();
+    if (allowListed) {
+      await hasStorageAccessInitially();
+    } else {
+      await noStorageAccessInitially();
+    }
 
     localStorage.foo = 42;
     ok(true, "LocalStorage is allowed");
     is(localStorage.foo, "42", "The value matches");
 
     var prevLocalStorage = localStorage;
 
     /* import-globals-from storageAccessAPIHelpers.js */
--- a/toolkit/components/antitracking/test/browser/browser_storageAccessRemovalNavigateSubframe.js
+++ b/toolkit/components/antitracking/test/browser/browser_storageAccessRemovalNavigateSubframe.js
@@ -3,17 +3,21 @@ AntiTracking.runTest("Storage Access is 
   async _ => {
     /* import-globals-from storageAccessAPIHelpers.js */
     await noStorageAccessInitially();
   },
 
   // 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();
     ok(!threw, "requestStorageAccess should not throw");
     ok(!rejected, "requestStorageAccess should be available");
   },
   // cleanup function
   async _ => {
--- a/toolkit/components/antitracking/test/browser/head.js
+++ b/toolkit/components/antitracking/test/browser/head.js
@@ -352,25 +352,27 @@ this.AntiTracking = {
       await ContentTask.spawn(browser,
                               { page: thirdPartyPage,
                                 nextPage: TEST_4TH_PARTY_PAGE,
                                 callback: options.callback.toString(),
                                 callbackAfterRemoval: options.callbackAfterRemoval ?
                                   options.callbackAfterRemoval.toString() : null,
                                 accessRemoval: options.accessRemoval,
                                 iframeSandbox: options.iframeSandbox,
+                                allowList: options.allowList,
                                 doAccessRemovalChecks },
                               async function(obj) {
         let id = "id" + Math.random();
         await new content.Promise(resolve => {
           let ifr = content.document.createElement("iframe");
           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);
           }
 
           content.addEventListener("message", function msg(event) {
             if (event.data.type == "finish") {
               content.removeEventListener("message", msg);
--- a/toolkit/components/antitracking/test/browser/storageAccessAPIHelpers.js
+++ b/toolkit/components/antitracking/test/browser/storageAccessAPIHelpers.js
@@ -1,8 +1,10 @@
+/* global allowListed */
+
 async function hasStorageAccessInitially() {
   let hasAccess = await document.hasStorageAccess();
   ok(hasAccess, "Has storage access");
 }
 
 async function noStorageAccessInitially() {
   let hasAccess = await document.hasStorageAccess();
   ok(!hasAccess, "Doesn't yet have storage access");