Bug 1547813 - Part 12: Add some tests for partitioning third-party storage/messaging with dynamic FPI; r=baku
☠☠ backed out by 8fea66166287 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 09 May 2019 07:14:19 +0000
changeset 532065 98989127264bd94ee0030809e1a9019832198a8f
parent 532064 f9d790139a26b2733cb1f83bdecce06633f4f94a
child 532066 e925cef1cadfa7dc2dff699ae3d980a11705196c
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1547813
milestone68.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 1547813 - Part 12: Add some tests for partitioning third-party storage/messaging with dynamic FPI; r=baku This patch doesn't port all of the existing tests because some of them do not pass yet and some others need more work to be ported. This will happen in follow-up bugs. Differential Revision: https://phabricator.services.mozilla.com/D30401
toolkit/components/antitracking/test/browser/3rdPartyStorage.html
toolkit/components/antitracking/test/browser/browser.ini
toolkit/components/antitracking/test/browser/browser_partitionedCookies.js
toolkit/components/antitracking/test/browser/browser_partitionedIndexedDB.js
toolkit/components/antitracking/test/browser/browser_partitionedMessaging.js
toolkit/components/antitracking/test/browser/browser_partitionedServiceWorkers.js
toolkit/components/antitracking/test/browser/dynamicfpi_head.js
toolkit/components/antitracking/test/browser/head.js
toolkit/components/antitracking/test/browser/partitionedstorage_head.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,30 +14,36 @@ 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();
-    await runnable.call(this, this, win, true /* allowed */);
+    // 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 */);
 
     win.close();
     parent.postMessage({ type: "finish" }, "*");
   };
 };
 
 </script>
 </body>
--- a/toolkit/components/antitracking/test/browser/browser.ini
+++ b/toolkit/components/antitracking/test/browser/browser.ini
@@ -5,16 +5,18 @@ prefs =
   dom.storage_access.prompt.testing.allow=true
   dom.testing.sync-content-blocking-notifications=true
 
 support-files =
   container.html
   embedder.html
   head.js
   antitracking_head.js
+  dynamicfpi_head.js
+  partitionedstorage_head.js
   storageprincipal_head.js
   image.sjs
   imageCacheWorker.js
   page.html
   3rdParty.html
   3rdPartySVG.html
   3rdPartyUI.html
   3rdPartyWO.html
--- a/toolkit/components/antitracking/test/browser/browser_partitionedCookies.js
+++ b/toolkit/components/antitracking/test/browser/browser_partitionedCookies.js
@@ -1,11 +1,11 @@
-/* import-globals-from storageprincipal_head.js */
+/* import-globals-from partitionedstorage_head.js */
 
-StoragePrincipalHelper.runTest("HTTP Cookies",
+PartitionedStorageHelper.runTest("HTTP Cookies",
   async (win3rdParty, win1stParty, allowed) => {
     await win3rdParty.fetch("cookies.sjs?3rd").then(r => r.text());
     await win3rdParty.fetch("cookies.sjs").then(r => r.text()).then(text => {
       is(text, "cookie:foopy=3rd", "3rd party cookie set");
     });
 
     await win1stParty.fetch("cookies.sjs?first").then(r => r.text());
     await win1stParty.fetch("cookies.sjs").then(r => r.text()).then(text => {
@@ -22,17 +22,17 @@ StoragePrincipalHelper.runTest("HTTP Coo
   },
 
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
     });
   });
 
-StoragePrincipalHelper.runTest("DOM Cookies",
+PartitionedStorageHelper.runTest("DOM Cookies",
   async (win3rdParty, win1stParty, allowed) => {
     win3rdParty.document.cookie = "foo=3rd";
     is(win3rdParty.document.cookie, "foo=3rd", "3rd party cookie set");
 
     win1stParty.document.cookie = "foo=first";
     is(win1stParty.document.cookie, "foo=first", "First party cookie set");
 
     if (allowed) {
--- a/toolkit/components/antitracking/test/browser/browser_partitionedIndexedDB.js
+++ b/toolkit/components/antitracking/test/browser/browser_partitionedIndexedDB.js
@@ -1,11 +1,11 @@
-/* import-globals-from storageprincipal_head.js */
+/* import-globals-from partitionedstorage_head.js */
 
-StoragePrincipalHelper.runTest("IndexedDB",
+PartitionedStorageHelper.runTest("IndexedDB",
   async (win3rdParty, win1stParty, allowed) => {
     await new Promise(resolve => {
       let a = win1stParty.indexedDB.open("test", 1);
       ok(!!a, "IDB should not be blocked in 1st party contexts");
 
       a.onsuccess = e => {
         let db = e.target.result;
         is(db.objectStoreNames.length, 1, "We have 1 objectStore");
--- a/toolkit/components/antitracking/test/browser/browser_partitionedMessaging.js
+++ b/toolkit/components/antitracking/test/browser/browser_partitionedMessaging.js
@@ -1,11 +1,11 @@
-/* import-globals-from storageprincipal_head.js */
+/* import-globals-from partitionedstorage_head.js */
 
-StoragePrincipalHelper.runTest("BroadcastChannel",
+PartitionedStorageHelper.runTest("BroadcastChannel",
   async (win3rdParty, win1stParty, allowed) => {
     let a = new win3rdParty.BroadcastChannel("hello");
     ok(!!a, "BroadcastChannel should be created by 3rd party iframe");
 
     let b = new win1stParty.BroadcastChannel("hello");
     ok(!!b, "BroadcastChannel should be created by 1st party iframe");
 
     // BroadcastChannel uses the incument global, this means that its CTOR will
--- a/toolkit/components/antitracking/test/browser/browser_partitionedServiceWorkers.js
+++ b/toolkit/components/antitracking/test/browser/browser_partitionedServiceWorkers.js
@@ -1,11 +1,11 @@
-/* import-globals-from storageprincipal_head.js */
+/* import-globals-from partitionedstorage_head.js */
 
-StoragePrincipalHelper.runTest("ServiceWorkers",
+PartitionedStorageHelper.runTest("ServiceWorkers",
   async (win3rdParty, win1stParty, allowed) => {
     // ServiceWorkers are not supported. Always blocked.
     await win3rdParty.navigator.serviceWorker.register("empty.js").then(
       _ => { ok(allowed, "Success: ServiceWorker cannot be used!"); },
       _ => { ok(!allowed, "Failed: ServiceWorker cannot be used!"); });
 
     await win1stParty.navigator.serviceWorker.register("empty.js").then(
       _ => { ok(true, "Success: ServiceWorker should be available!"); },
@@ -18,17 +18,17 @@ StoragePrincipalHelper.runTest("ServiceW
     });
   },
 
   [["dom.serviceWorkers.exemptFromPerDomainMax", true],
    ["dom.ipc.processCount", 1],
    ["dom.serviceWorkers.enabled", true],
    ["dom.serviceWorkers.testing.enabled", true]]);
 
-StoragePrincipalHelper.runTest("ServiceWorkers - MatchAll",
+PartitionedStorageHelper.runTest("ServiceWorkers - MatchAll",
   async (win3rdParty, win1stParty, allowed) => {
     if (!win1stParty.sw) {
       let reg = await win1stParty.navigator.serviceWorker.register("matchAll.js");
       if (reg.installing.state !== "activated") {
         await new Promise(resolve => {
             let w = reg.installing;
             w.addEventListener("statechange", function onStateChange() {
               if (w.state === "activated") {
copy from toolkit/components/antitracking/test/browser/storageprincipal_head.js
copy to toolkit/components/antitracking/test/browser/dynamicfpi_head.js
--- a/toolkit/components/antitracking/test/browser/storageprincipal_head.js
+++ b/toolkit/components/antitracking/test/browser/dynamicfpi_head.js
@@ -2,48 +2,46 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* import-globals-from head.js */
 
 "use strict";
 
-this.StoragePrincipalHelper = {
+this.DynamicFPIHelper = {
   runTest(name, callback, cleanupFunction, extraPrefs) {
     add_task(async _ => {
-      info("Starting test `" + name + "'...");
+      info("Starting test `" + name + "' with dynamic FPI...");
 
       await SpecialPowers.flushPrefEnv();
       await SpecialPowers.pushPrefEnv({"set": [
         ["dom.storage_access.enabled", true],
-        ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
+        ["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", true],
+        ["privacy.storagePrincipal.enabledForTrackers", false],
         ["privacy.restrict3rdpartystorage.userInteractionRequiredForHosts", "tracking.example.com,tracking.example.org"],
       ]});
 
       if (extraPrefs && Array.isArray(extraPrefs) && extraPrefs.length) {
         await SpecialPowers.pushPrefEnv({"set": extraPrefs });
       }
 
-      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);
 
       info("Creating a 3rd party content");
       await ContentTask.spawn(browser, {
-                                page: TEST_3RD_PARTY_STORAGE_PAGE,
+                                page: TEST_4TH_PARTY_STORAGE_PAGE,
                                 callback: callback.toString(),
                               },
                               async obj => {
         await new content.Promise(resolve => {
           let ifr = content.document.createElement("iframe");
           ifr.onload = __ => {
             is(ifr.contentWindow.document.nodePrincipal.originAttributes.firstPartyDomain, "", "We don't have first-party set on nodePrincipal");
             is(ifr.contentWindow.document.effectiveStoragePrincipal.originAttributes.firstPartyDomain, "example.net", "We have first-party set on storagePrincipal");
@@ -79,12 +77,13 @@ this.StoragePrincipalHelper = {
       info("Removing the tab");
       BrowserTestUtils.removeTab(tab);
     });
 
     add_task(async _ => {
       info("Cleaning up.");
       if (cleanupFunction) {
         await cleanupFunction();
+        UrlClassifierTestUtils.cleanupTestTrackers();
       }
     });
   },
 };
--- a/toolkit/components/antitracking/test/browser/head.js
+++ b/toolkit/components/antitracking/test/browser/head.js
@@ -28,26 +28,27 @@ 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 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);
 
 const {UrlClassifierTestUtils} = ChromeUtils.import("resource://testing-common/UrlClassifierTestUtils.jsm");
 
 Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/toolkit/components/antitracking/test/browser/antitracking_head.js",
   this);
 
 Services.scriptloader.loadSubScript(
-  "chrome://mochitests/content/browser/toolkit/components/antitracking/test/browser/storageprincipal_head.js",
+  "chrome://mochitests/content/browser/toolkit/components/antitracking/test/browser/partitionedstorage_head.js",
   this);
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/partitionedstorage_head.js
@@ -0,0 +1,25 @@
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* import-globals-from head.js */
+
+"use strict";
+
+/* import-globals-from dynamicfpi_head.js */
+Services.scriptloader.loadSubScript(
+  "chrome://mochitests/content/browser/toolkit/components/antitracking/test/browser/dynamicfpi_head.js",
+  this);
+
+/* import-globals-from storageprincipal_head.js */
+Services.scriptloader.loadSubScript(
+  "chrome://mochitests/content/browser/toolkit/components/antitracking/test/browser/storageprincipal_head.js",
+  this);
+
+this.PartitionedStorageHelper = {
+  runTest(name, callback, cleanupFunction, extraPrefs) {
+    DynamicFPIHelper.runTest(name, callback, cleanupFunction, extraPrefs);
+    StoragePrincipalHelper.runTest(name, callback, cleanupFunction, extraPrefs);
+  },
+};
--- a/toolkit/components/antitracking/test/browser/storageprincipal_head.js
+++ b/toolkit/components/antitracking/test/browser/storageprincipal_head.js
@@ -5,17 +5,17 @@
 
 /* import-globals-from head.js */
 
 "use strict";
 
 this.StoragePrincipalHelper = {
   runTest(name, callback, cleanupFunction, extraPrefs) {
     add_task(async _ => {
-      info("Starting test `" + name + "'...");
+      info("Starting test `" + name + "' with storage principal...");
 
       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],
@@ -79,12 +79,13 @@ this.StoragePrincipalHelper = {
       info("Removing the tab");
       BrowserTestUtils.removeTab(tab);
     });
 
     add_task(async _ => {
       info("Cleaning up.");
       if (cleanupFunction) {
         await cleanupFunction();
+        UrlClassifierTestUtils.cleanupTestTrackers();
       }
     });
   },
 };