Bug 1469714 - Part 3: Add tests for the Storage Access API interaction with cookies; r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 12 Sep 2018 19:22:23 -0400
changeset 436820 86d154372afeeeef100fd80732f44b0152df4198
parent 436819 c5c95129eeb3d2a1da3345d660a6ea0547791ea3
child 436821 a01d787f48f3470fc6c9bb379ec98d2583b02041
push id34660
push userbtara@mozilla.com
push dateMon, 17 Sep 2018 21:58:52 +0000
treeherdermozilla-central@87a95e1b7ec6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1469714
milestone64.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 1469714 - Part 3: Add tests for the Storage Access API interaction with cookies; r=baku Differential Revision: https://phabricator.services.mozilla.com/D5812
toolkit/components/antitracking/test/browser/browser_blockingCookies.js
toolkit/components/antitracking/test/browser/head.js
--- a/toolkit/components/antitracking/test/browser/browser_blockingCookies.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingCookies.js
@@ -38,8 +38,96 @@ AntiTracking.runTest("Set/Get Cookies",
   },
 
   // Cleanup callback
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
     });
   });
+
+AntiTracking.runTest("Cookies and Storage Access API",
+  // Blocking callback
+  async _ => {
+    let hasAccess = await document.hasStorageAccess();
+    ok(!hasAccess, "Doesn't yet have storage access");
+    is(document.cookie, "", "No cookies for me");
+    document.cookie = "name=value";
+    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");
+    });
+    // Let's do it twice.
+    await fetch("server.sjs").then(r => r.text()).then(text => {
+      is(text, "cookie-not-present", "We should not have cookies");
+    });
+
+    is(document.cookie, "", "Still no cookies for me");
+
+    let dwu = SpecialPowers.getDOMWindowUtils(window);
+    let helper = dwu.setHandlingUserInput(true);
+
+    let p;
+    try {
+      p = document.requestStorageAccess();
+    } finally {
+      helper.destruct();
+    }
+    await p;
+
+    hasAccess = await document.hasStorageAccess();
+    ok(hasAccess, "Now has storage access");
+    is(document.cookie, "", "No cookies for me");
+    document.cookie = "name=value";
+    is(document.cookie, "name=value", "I have the cookies!");
+  },
+
+  // Non blocking callback
+  async _ => {
+    let hasAccess = await document.hasStorageAccess();
+    ok(!hasAccess, "Doesn't yet have storage access");
+
+    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";
+    ok(document.cookie.includes("name=value"), "Some cookies for me");
+    ok(document.cookie.includes("foopy=1"), "Some cookies for me");
+
+    await fetch("server.sjs").then(r => r.text()).then(text => {
+      is(text, "cookie-present", "We should have cookies");
+    });
+
+    ok(document.cookie.length, "Some Cookies for me");
+
+    hasAccess = await document.hasStorageAccess();
+    ok(!hasAccess, "Doesn't yet have storage access");
+
+    let dwu = SpecialPowers.getDOMWindowUtils(window);
+    let helper = dwu.setHandlingUserInput(true);
+
+    let p;
+    try {
+      p = document.requestStorageAccess();
+    } finally {
+      helper.destruct();
+    }
+    await p;
+
+    hasAccess = await document.hasStorageAccess();
+    ok(hasAccess, "Now has storage access");
+    // For non-tracking windows, calling the API is a no-op
+    ok(document.cookie.length, "Still some Cookies for me");
+    ok(document.cookie.includes("name=value"), "Some cookies for me");
+    ok(document.cookie.includes("foopy=1"), "Some cookies for me");
+  },
+
+  // Cleanup callback
+  async _ => {
+    await new Promise(resolve => {
+      Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
+    });
+  },
+  null, false, false);
--- a/toolkit/components/antitracking/test/browser/head.js
+++ b/toolkit/components/antitracking/test/browser/head.js
@@ -196,16 +196,17 @@ this.AntiTracking = {
         this._createCleanupTask(cleanupFunction);
       }
     }
   },
 
   async _setupTest(win, cookieBehavior, blockingByContentBlocking, extraPrefs) {
     await SpecialPowers.flushPrefEnv();
     await SpecialPowers.pushPrefEnv({"set": [
+      ["dom.storage_access.enabled", true],
       ["browser.contentblocking.enabled", blockingByContentBlocking],
       ["network.cookie.cookieBehavior", cookieBehavior],
       ["privacy.trackingprotection.enabled", false],
       ["privacy.trackingprotection.pbmode.enabled", false],
       ["privacy.trackingprotection.annotate_channels", cookieBehavior != BEHAVIOR_ACCEPT],
       [win.ContentBlocking.prefIntroCount, win.ContentBlocking.MAX_INTROS],
       ["browser.fastblock.enabled", false], // prevent intermittent failures
     ]});