Bug 1554781 - Part 3: Add tests for the storage access API and the associated heuristics for dynamic FPI; r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 28 May 2019 12:06:38 +0000
changeset 475944 ece4def4fd82ec30ac258028858e93a5b1d88630
parent 475943 452b8c9f9a1349f44e523711f2f0f32dc927ba3c
child 475945 a8973dc65dc4963a209a84d7650da970ad44470e
push id86554
push usereakhgari@mozilla.com
push dateTue, 28 May 2019 20:48:16 +0000
treeherderautoland@ece4def4fd82 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1554781
milestone69.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 1554781 - Part 3: Add tests for the storage access API and the associated heuristics for dynamic FPI; r=baku Differential Revision: https://phabricator.services.mozilla.com/D32767
toolkit/components/antitracking/test/browser/3rdPartyStorage.html
toolkit/components/antitracking/test/browser/dynamicfpi_head.js
toolkit/components/antitracking/test/browser/head.js
toolkit/components/antitracking/test/browser/storageAccessAPIHelpers.js
toolkit/components/antitracking/test/browser/storageprincipal_head.js
--- a/toolkit/components/antitracking/test/browser/3rdPartyStorage.html
+++ b/toolkit/components/antitracking/test/browser/3rdPartyStorage.html
@@ -14,36 +14,30 @@ function info(msg) {
 function ok(what, msg) {
   parent.postMessage({ type: "ok", what: !!what, msg }, "*");
 }
 
 function is(a, b, msg) {
   ok(a === b, msg);
 }
 
-let areWeFourthParty = location.search == "?4th";
-
 onmessage = function(e) {
   let data = e.data;
   let runnableStr = `(() => {return (${data});})();`;
   let runnable = eval(runnableStr); // eslint-disable-line no-eval
 
   let win = window.open("3rdPartyStorageWO.html");
   win.onload = async _ => {
     /* import-globals-from storageAccessAPIHelpers.js */
     await noStorageAccessInitially();
 
     await runnable.call(this, this, win, false /* allowed */);
     /* import-globals-from storageAccessAPIHelpers.js */
     await callRequestStorageAccess();
-    // If we're "fourth party" (which is true when running dynamic FPI tests)
-    // then assume that the storage access API doesn't grant first-party
-    // storage yet.
-    // TODO: Make sure storage access API is available for dynamic FPI too.
-    await runnable.call(this, this, win, !areWeFourthParty /* allowed */);
+    await runnable.call(this, this, win, true /* allowed */);
 
     win.close();
     parent.postMessage({ type: "finish" }, "*");
   };
 };
 
 </script>
 </body>
--- a/toolkit/components/antitracking/test/browser/dynamicfpi_head.js
+++ b/toolkit/components/antitracking/test/browser/dynamicfpi_head.js
@@ -15,17 +15,17 @@ this.DynamicFPIHelper = {
       await SpecialPowers.flushPrefEnv();
       await SpecialPowers.pushPrefEnv({"set": [
         ["dom.storage_access.enabled", true],
         ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN],
         ["privacy.trackingprotection.enabled", false],
         ["privacy.trackingprotection.pbmode.enabled", false],
         ["privacy.trackingprotection.annotate_channels", true],
         ["privacy.storagePrincipal.enabledForTrackers", false],
-        ["privacy.restrict3rdpartystorage.userInteractionRequiredForHosts", "tracking.example.com,tracking.example.org"],
+        ["privacy.restrict3rdpartystorage.userInteractionRequiredForHosts", "not-tracking.example.com"],
       ]});
 
       if (extraPrefs && Array.isArray(extraPrefs) && extraPrefs.length) {
         await SpecialPowers.pushPrefEnv({"set": extraPrefs });
       }
 
       info("Creating a new tab");
       let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE);
--- a/toolkit/components/antitracking/test/browser/head.js
+++ b/toolkit/components/antitracking/test/browser/head.js
@@ -28,17 +28,17 @@ const TEST_EMBEDDER_PAGE = TEST_DOMAIN +
 const TEST_POPUP_PAGE = TEST_DOMAIN + TEST_PATH + "popup.html";
 const TEST_3RD_PARTY_PAGE = TEST_3RD_PARTY_DOMAIN + TEST_PATH + "3rdParty.html";
 const TEST_3RD_PARTY_PAGE_WO = TEST_3RD_PARTY_DOMAIN + TEST_PATH + "3rdPartyWO.html";
 const TEST_3RD_PARTY_PAGE_UI = TEST_3RD_PARTY_DOMAIN + TEST_PATH + "3rdPartyUI.html";
 const TEST_3RD_PARTY_PAGE_WITH_SVG = TEST_3RD_PARTY_DOMAIN + TEST_PATH + "3rdPartySVG.html";
 const TEST_4TH_PARTY_PAGE = TEST_4TH_PARTY_DOMAIN + TEST_PATH + "3rdParty.html";
 const TEST_ANOTHER_3RD_PARTY_PAGE = TEST_ANOTHER_3RD_PARTY_DOMAIN + TEST_PATH + "3rdParty.html";
 const TEST_3RD_PARTY_STORAGE_PAGE = TEST_3RD_PARTY_DOMAIN + TEST_PATH + "3rdPartyStorage.html";
-const TEST_4TH_PARTY_STORAGE_PAGE = TEST_4TH_PARTY_DOMAIN + TEST_PATH + "3rdPartyStorage.html?4th";
+const TEST_4TH_PARTY_STORAGE_PAGE = TEST_4TH_PARTY_DOMAIN + TEST_PATH + "3rdPartyStorage.html";
 
 const BEHAVIOR_ACCEPT         = Ci.nsICookieService.BEHAVIOR_ACCEPT;
 const BEHAVIOR_REJECT         = Ci.nsICookieService.BEHAVIOR_REJECT;
 const BEHAVIOR_LIMIT_FOREIGN  = Ci.nsICookieService.BEHAVIOR_LIMIT_FOREIGN;
 const BEHAVIOR_REJECT_FOREIGN = Ci.nsICookieService.BEHAVIOR_REJECT_FOREIGN;
 const BEHAVIOR_REJECT_TRACKER = Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER;
 
 requestLongerTimeout(3);
--- a/toolkit/components/antitracking/test/browser/storageAccessAPIHelpers.js
+++ b/toolkit/components/antitracking/test/browser/storageAccessAPIHelpers.js
@@ -13,18 +13,20 @@ async function noStorageAccessInitially(
 async function callRequestStorageAccess(callback, expectFail) {
   let dwu = SpecialPowers.getDOMWindowUtils(window);
   let helper = dwu.setHandlingUserInput(true);
 
   let origin = new URL(location.href).origin;
 
   let success = true;
   // We only grant storage exceptions when the reject tracker behavior is enabled.
-  let rejectTrackers = SpecialPowers.Services.prefs.getIntPref("network.cookie.cookieBehavior") ==
-                         SpecialPowers.Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER &&
+  let rejectTrackers = [SpecialPowers.Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER,
+                        SpecialPowers.Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN].
+
+                         includes(SpecialPowers.Services.prefs.getIntPref("network.cookie.cookieBehavior")) &&
                        !isOnContentBlockingAllowList();
   // With another-tracking.example.net, we're same-eTLD+1, so the first try succeeds.
   if (origin != "https://another-tracking.example.net") {
     if (rejectTrackers) {
       let p;
       let threw = false;
       try {
         p = document.requestStorageAccess();
@@ -115,17 +117,17 @@ async function callRequestStorageAccess(
   is(hasAccess, success,
      "Should " + (success ? "" : "not ") + "have storage access now");
   if (success && rejectTrackers &&
       window.location.search != "?disableWaitUntilPermission" &&
       origin != "https://another-tracking.example.net") {
     // Wait until the permission is visible in our process to avoid race
     // conditions.
     await waitUntilPermission("http://example.net/browser/toolkit/components/antitracking/test/browser/page.html",
-                              "3rdPartyStorage^https://tracking.example.org");
+                              "3rdPartyStorage^" + window.origin);
   }
 
   return [threw, rejected];
 }
 
 async function waitUntilPermission(url, name) {
   await new Promise(resolve => {
     let id = setInterval(_ => {
@@ -140,22 +142,21 @@ async function waitUntilPermission(url, 
   });
 }
 
 async function interactWithTracker() {
   await new Promise(resolve => {
     onmessage = resolve;
 
     info("Let's interact with the tracker");
-    window.open("https://tracking.example.org/browser/toolkit/components/antitracking/test/browser/3rdPartyOpenUI.html?messageme");
+    window.open("/browser/toolkit/components/antitracking/test/browser/3rdPartyOpenUI.html?messageme");
   });
 
   // Wait until the user interaction permission becomes visible in our process
-  await waitUntilPermission("https://tracking.example.org",
-                            "storageAccessAPI");
+  await waitUntilPermission(window.origin, "storageAccessAPI");
 }
 
 function isOnContentBlockingAllowList() {
   let prefs = ["browser.contentblocking.allowlist.storage.enabled",
                "browser.contentblocking.allowlist.annotations.enabled"];
   function allEnabled(prev, pref) {
     return pref &&
            SpecialPowers.Services.prefs.getBoolPref(pref);
--- a/toolkit/components/antitracking/test/browser/storageprincipal_head.js
+++ b/toolkit/components/antitracking/test/browser/storageprincipal_head.js
@@ -15,17 +15,17 @@ this.StoragePrincipalHelper = {
       await SpecialPowers.flushPrefEnv();
       await SpecialPowers.pushPrefEnv({"set": [
         ["dom.storage_access.enabled", true],
         ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
         ["privacy.trackingprotection.enabled", false],
         ["privacy.trackingprotection.pbmode.enabled", false],
         ["privacy.trackingprotection.annotate_channels", true],
         ["privacy.storagePrincipal.enabledForTrackers", true],
-        ["privacy.restrict3rdpartystorage.userInteractionRequiredForHosts", "tracking.example.com,tracking.example.org"],
+        ["privacy.restrict3rdpartystorage.userInteractionRequiredForHosts", "tracking.example.org"],
       ]});
 
       if (extraPrefs && Array.isArray(extraPrefs) && extraPrefs.length) {
         await SpecialPowers.pushPrefEnv({"set": extraPrefs });
       }
 
       await UrlClassifierTestUtils.addTestTrackers();