Bug 1536411 - StoragePrincipal - part 5 - Tests, r=Ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 12 Apr 2019 05:30:56 +0000
changeset 469238 ed51986b7628c1791c384c5aaaadd5ddf5c46ab7
parent 469237 8593e3e867723fd4d52147fe3236f0c01498ff2b
child 469239 c1074e3a0d5fbc17d6763d02593203ab0cccb4e7
push id112776
push usershindli@mozilla.com
push dateFri, 12 Apr 2019 16:20:17 +0000
treeherdermozilla-inbound@b4501ced5619 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1536411
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 1536411 - StoragePrincipal - part 5 - Tests, r=Ehsan Differential Revision: https://phabricator.services.mozilla.com/D24029
toolkit/components/antitracking/test/browser/3rdPartyStorage.html
toolkit/components/antitracking/test/browser/3rdPartyStorageWO.html
toolkit/components/antitracking/test/browser/antitracking_head.js
toolkit/components/antitracking/test/browser/browser.ini
toolkit/components/antitracking/test/browser/browser_allowListSeparationInPrivateAndNormalWindows.js
toolkit/components/antitracking/test/browser/browser_allowPermissionForTracker.js
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_blockingNoOpener.js
toolkit/components/antitracking/test/browser/browser_blockingServiceWorkers.js
toolkit/components/antitracking/test/browser/browser_blockingServiceWorkersStorageAccessAPI.js
toolkit/components/antitracking/test/browser/browser_blockingSessionStorage.js
toolkit/components/antitracking/test/browser/browser_blockingSharedWorkers.js
toolkit/components/antitracking/test/browser/browser_denyPermissionForTracker.js
toolkit/components/antitracking/test/browser/browser_partitionedIndexedDB.js
toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage.js
toolkit/components/antitracking/test/browser/browser_partitionedMessaging.js
toolkit/components/antitracking/test/browser/browser_permissionInNormalWindows.js
toolkit/components/antitracking/test/browser/browser_permissionInPrivateWindows.js
toolkit/components/antitracking/test/browser/browser_script.js
toolkit/components/antitracking/test/browser/browser_siteSpecificWorkArounds.js
toolkit/components/antitracking/test/browser/browser_storageAccessPrivateWindow.js
toolkit/components/antitracking/test/browser/browser_storageAccessPromiseRejectHandlerUserInteraction.js
toolkit/components/antitracking/test/browser/browser_storageAccessPromiseResolveHandlerUserInteraction.js
toolkit/components/antitracking/test/browser/browser_storageAccessRemovalNavigateSubframe.js
toolkit/components/antitracking/test/browser/browser_storageAccessSandboxed.js
toolkit/components/antitracking/test/browser/browser_storageAccessWithHeuristics.js
toolkit/components/antitracking/test/browser/head.js
toolkit/components/antitracking/test/browser/imageCacheWorker.js
toolkit/components/antitracking/test/browser/storageprincipal_head.js
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/3rdPartyStorage.html
@@ -0,0 +1,44 @@
+<html>
+<head>
+  <title>3rd party content!</title>
+  <script type="text/javascript" src="https://example.com/browser/toolkit/components/antitracking/test/browser/storageAccessAPIHelpers.js"></script>
+</head>
+<body>
+<h1>Here the 3rd party content!</h1>
+<script>
+
+function info(msg) {
+  parent.postMessage({ type: "info", msg }, "*");
+}
+
+function ok(what, msg) {
+  parent.postMessage({ type: "ok", what: !!what, msg }, "*");
+}
+
+function is(a, b, msg) {
+  ok(a === b, msg);
+}
+
+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 */);
+
+    win.close();
+    parent.postMessage({ type: "finish" }, "*");
+  };
+};
+
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/3rdPartyStorageWO.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+  <title>1st party content!</title>
+</head>
+<body>
+<h1>Here the 1st party content!</h1>
+</body>
+</html>
copy from toolkit/components/antitracking/test/browser/head.js
copy to toolkit/components/antitracking/test/browser/antitracking_head.js
--- a/toolkit/components/antitracking/test/browser/head.js
+++ b/toolkit/components/antitracking/test/browser/antitracking_head.js
@@ -1,48 +1,19 @@
-const TEST_DOMAIN = "http://example.net/";
-const TEST_DOMAIN_2 = "http://xn--exmple-cua.test/";
-const TEST_DOMAIN_3 = "https://xn--hxajbheg2az3al.xn--jxalpdlp/";
-const TEST_DOMAIN_4 = "http://prefixexample.com/";
-const TEST_DOMAIN_5 = "http://test/";
-const TEST_DOMAIN_6 = "http://mochi.test:8888/";
-const TEST_3RD_PARTY_DOMAIN = "https://tracking.example.org/";
-const TEST_3RD_PARTY_DOMAIN_TP = "https://tracking.example.com/";
-const TEST_4TH_PARTY_DOMAIN = "http://not-tracking.example.com/";
-const TEST_ANOTHER_3RD_PARTY_DOMAIN = "https://another-tracking.example.net/";
-
-const TEST_PATH = "browser/toolkit/components/antitracking/test/browser/";
+/* 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/. */
 
-const TEST_TOP_PAGE = TEST_DOMAIN + TEST_PATH + "page.html";
-const TEST_TOP_PAGE_2 = TEST_DOMAIN_2 + TEST_PATH + "page.html";
-const TEST_TOP_PAGE_3 = TEST_DOMAIN_3 + TEST_PATH + "page.html";
-const TEST_TOP_PAGE_4 = TEST_DOMAIN_4 + TEST_PATH + "page.html";
-const TEST_TOP_PAGE_5 = TEST_DOMAIN_5 + TEST_PATH + "page.html";
-const TEST_TOP_PAGE_6 = TEST_DOMAIN_6 + TEST_PATH + "page.html";
-const TEST_EMBEDDER_PAGE = TEST_DOMAIN + TEST_PATH + "embedder.html";
-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";
+/* import-globals-from head.js */
 
-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;
+"use strict";
 
 var gFeatures = undefined;
 
-let {UrlClassifierTestUtils} = ChromeUtils.import("resource://testing-common/UrlClassifierTestUtils.jsm");
-
-requestLongerTimeout(3);
-
 this.AntiTracking = {
   runTest(name, callbackTracking, callbackNonTracking, cleanupFunction, extraPrefs,
           windowOpenTest = true, userInteractionTest = true,
           expectedBlockingNotifications = Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER,
           runInPrivateWindow = false, iframeSandbox = null, accessRemoval = null,
           callbackAfterRemoval = null) {
     // Here we want to test that a 3rd party context is simply blocked.
     this._createTask({
@@ -728,8 +699,9 @@ this.AntiTracking = {
       BrowserTestUtils.removeTab(tab);
 
       if (runInPrivateWindow) {
         win.close();
       }
     });
   },
 };
+
--- a/toolkit/components/antitracking/test/browser/browser.ini
+++ b/toolkit/components/antitracking/test/browser/browser.ini
@@ -4,30 +4,34 @@ prefs =
   dom.storage_access.prompt.testing=true
   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
+  storageprincipal_head.js
   image.sjs
   imageCacheWorker.js
   page.html
   3rdParty.html
   3rdPartySVG.html
   3rdPartyUI.html
   3rdPartyWO.html
   3rdPartyOpen.html
   3rdPartyOpenUI.html
   empty.js
   empty.html
   popup.html
   server.sjs
   storageAccessAPIHelpers.js
+  3rdPartyStorage.html
+  3rdPartyStorageWO.html
   !/browser/modules/test/browser/head.js
 
 [browser_allowListNotifications.js]
 skip-if = serviceworker_e10s
 support-files = subResources.sjs
 [browser_addonHostPermissionIgnoredInTP.js]
 [browser_allowListSeparationInPrivateAndNormalWindows.js]
 skip-if = os == "mac" && !debug # Bug 1503778
@@ -82,8 +86,10 @@ skip-if = serviceworker_e10s
 [browser_localStorageEvents.js]
 support-files = localStorage.html
 [browser_partitionedLocalStorage.js]
 [browser_partitionedLocalStorage_events.js]
 support-files = localStorageEvents.html
 [browser_workerPropagation.js]
 support-files = workerIframe.html
 [browser_cookieBetweenTabs.js]
+[browser_partitionedMessaging.js]
+[browser_partitionedIndexedDB.js]
--- a/toolkit/components/antitracking/test/browser/browser_allowListSeparationInPrivateAndNormalWindows.js
+++ b/toolkit/components/antitracking/test/browser/browser_allowListSeparationInPrivateAndNormalWindows.js
@@ -5,16 +5,19 @@
 // the pages loaded under this test in the allow list, which would result in
 // the test not passing because no blocking notifications would be observed.
 
 // Testing the reverse case would also be interesting, but unfortunately there
 // isn't a super easy way to do that with our antitracking test framework since
 // private windows wouldn't send any blocking notifications as they don't have
 // storage access in the first place.
 
+/* import-globals-from antitracking_head.js */
+
+"use strict";
 add_task(async _ => {
   let uri = Services.io.newURI("https://example.net");
   Services.perms.add(uri, "trackingprotection-pb",
                      Services.perms.ALLOW_ACTION);
 
   registerCleanupFunction(_ => {
     Services.perms.removeAll();
   });
--- a/toolkit/components/antitracking/test/browser/browser_allowPermissionForTracker.js
+++ b/toolkit/components/antitracking/test/browser/browser_allowPermissionForTracker.js
@@ -1,11 +1,13 @@
 // This test works by setting up an exception for the tracker domain, which
 // disables all the anti-tracking tests.
 
+/* import-globals-from antitracking_head.js */
+
 add_task(async _ => {
   Services.perms.add(Services.io.newURI("https://tracking.example.org"),
                      "cookie", Services.perms.ALLOW_ACTION);
   Services.perms.add(Services.io.newURI("https://tracking.example.com"),
                      "cookie", Services.perms.ALLOW_ACTION);
 
   registerCleanupFunction(_ => {
     Services.perms.removeAll();
--- a/toolkit/components/antitracking/test/browser/browser_blockingCookies.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingCookies.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 AntiTracking.runTest("Set/Get Cookies",
   // Blocking callback
   async _ => {
     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 => {
--- a/toolkit/components/antitracking/test/browser/browser_blockingDOMCache.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingDOMCache.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 requestLongerTimeout(2);
 
 AntiTracking.runTest("DOM Cache",
   async _ => {
     await caches.open("wow").then(
       _ => { ok(false, "DOM Cache cannot be used!"); },
       _ => { ok(true, "DOM Cache cannot be used!"); });
   },
--- a/toolkit/components/antitracking/test/browser/browser_blockingIndexedDb.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingIndexedDb.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 AntiTracking.runTest("IndexedDB",
   // blocking callback
   async _ => {
     try {
       indexedDB.open("test", "1");
       ok(false, "IDB should be blocked");
     } catch (e) {
       ok(true, "IDB should be blocked");
--- a/toolkit/components/antitracking/test/browser/browser_blockingIndexedDbInWorkers.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingIndexedDbInWorkers.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 AntiTracking.runTest("IndexedDB in workers",
   async _ => {
     function blockCode() {
       try {
         indexedDB.open("test", "1");
         postMessage(false);
       } catch (e) {
         postMessage(e.name == "SecurityError");
--- a/toolkit/components/antitracking/test/browser/browser_blockingLocalStorage.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingLocalStorage.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 AntiTracking.runTest("localStorage",
   async _ => {
     is(window.localStorage, null, "LocalStorage is null");
     try {
       localStorage.foo = 42;
       ok(false, "LocalStorage cannot be used!");
     } catch (e) {
       ok(true, "LocalStorage cannot be used!");
--- a/toolkit/components/antitracking/test/browser/browser_blockingMessaging.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingMessaging.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 AntiTracking.runTest("BroadcastChannel",
   async _ => {
     try {
       new BroadcastChannel("hello");
       ok(false, "BroadcastChannel cannot be used!");
     } catch (e) {
       ok(true, "BroadcastChannel cannot be used!");
       is(e.name, "SecurityError", "We want a security error message.");
--- a/toolkit/components/antitracking/test/browser/browser_blockingNoOpener.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingNoOpener.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 gFeatures = "noopener";
 
 AntiTracking.runTest("Blocking in the case of noopener windows",
   async _ => {
     is(window.localStorage, null, "LocalStorage is null");
     try {
       localStorage.foo = 42;
       ok(false, "LocalStorage cannot be used!");
--- a/toolkit/components/antitracking/test/browser/browser_blockingServiceWorkers.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingServiceWorkers.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 AntiTracking.runTest("ServiceWorkers",
   async _ => {
     await navigator.serviceWorker.register("empty.js").then(
       _ => { ok(false, "ServiceWorker cannot be used!"); },
       _ => { ok(true, "ServiceWorker cannot be used!"); }).
       catch(e => ok(false, "Promise rejected: " + e));
   },
   null,
--- a/toolkit/components/antitracking/test/browser/browser_blockingServiceWorkersStorageAccessAPI.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingServiceWorkersStorageAccessAPI.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 requestLongerTimeout(2);
 
 AntiTracking.runTest("ServiceWorkers and Storage Access API",
   async _ => {
     /* import-globals-from storageAccessAPIHelpers.js */
     await noStorageAccessInitially();
 
     await navigator.serviceWorker.register("empty.js").then(
--- a/toolkit/components/antitracking/test/browser/browser_blockingSessionStorage.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingSessionStorage.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 AntiTracking.runTest("sessionStorage",
   async _ => {
     let shouldThrow = SpecialPowers.Services.prefs.getIntPref("network.cookie.cookieBehavior") == SpecialPowers.Ci.nsICookieService.BEHAVIOR_REJECT;
 
     let hasThrown;
     try {
       sessionStorage.foo = 42;
       hasThrown = false;
--- a/toolkit/components/antitracking/test/browser/browser_blockingSharedWorkers.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingSharedWorkers.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 requestLongerTimeout(2);
 
 AntiTracking.runTest("SharedWorkers",
   async _ => {
     try {
       new SharedWorker("a.js", "foo");
       ok(false, "SharedWorker cannot be used!");
     } catch (e) {
--- a/toolkit/components/antitracking/test/browser/browser_denyPermissionForTracker.js
+++ b/toolkit/components/antitracking/test/browser/browser_denyPermissionForTracker.js
@@ -1,11 +1,13 @@
 // This test works by setting up an exception for the tracker domain, which
 // disables all the anti-tracking tests.
 
+/* import-globals-from antitracking_head.js */
+
 add_task(async _ => {
   Services.perms.add(Services.io.newURI("https://tracking.example.org"),
                      "cookie", Services.perms.DENY_ACTION);
   Services.perms.add(Services.io.newURI("https://tracking.example.com"),
                      "cookie", Services.perms.DENY_ACTION);
 
   registerCleanupFunction(_ => {
     Services.perms.removeAll();
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/browser_partitionedIndexedDB.js
@@ -0,0 +1,46 @@
+/* import-globals-from storageprincipal_head.js */
+
+StoragePrincipalHelper.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");
+        is(db.objectStoreNames[0], "foobar", "We have 'foobar' objectStore");
+        resolve();
+      };
+
+      a.onupgradeneeded = e => {
+        let db = e.target.result;
+        is(db.objectStoreNames.length, 0, "We have 0 objectStores");
+        db.createObjectStore("foobar", { keyPath: "test" });
+      };
+    });
+
+    await new Promise(resolve => {
+      let a = win3rdParty.indexedDB.open("test", 1);
+      ok(!!a, "IDB should not be blocked in 3rd party contexts");
+
+      a.onsuccess = e => {
+        let db = e.target.result;
+
+        if (allowed) {
+          is(db.objectStoreNames.length, 1, "We have 1 objectStore");
+          is(db.objectStoreNames[0], "foobar", "We have 'foobar' objectStore");
+        } else {
+          is(db.objectStoreNames.length, 0, "We have 0 objectStore");
+        }
+        resolve();
+      };
+    });
+  },
+
+  async _ => {
+    await new Promise(resolve => {
+      Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
+    });
+  });
+
--- a/toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage.js
+++ b/toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 AntiTracking.runTest("localStorage and Storage Access API",
   async _ => {
     /* import-globals-from storageAccessAPIHelpers.js */
     await noStorageAccessInitially();
 
     let shouldThrow = SpecialPowers.Services.prefs.getIntPref("network.cookie.cookieBehavior") == SpecialPowers.Ci.nsICookieService.BEHAVIOR_REJECT;
 
     is(window.localStorage == null, shouldThrow,
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/browser_partitionedMessaging.js
@@ -0,0 +1,18 @@
+/* import-globals-from storageprincipal_head.js */
+
+StoragePrincipalHelper.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
+    // always use the 3rd party iframe's window as global.
+  },
+  async _ => {
+    await new Promise(resolve => {
+      Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
+    });
+  });
--- a/toolkit/components/antitracking/test/browser/browser_permissionInNormalWindows.js
+++ b/toolkit/components/antitracking/test/browser/browser_permissionInNormalWindows.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 AntiTracking.runTest("Test whether we receive any persistent permissions in normal windows",
   // Blocking callback
   async _ => {
     // Nothing to do here!
   },
 
   // Non blocking callback
   async _ => {
--- a/toolkit/components/antitracking/test/browser/browser_permissionInPrivateWindows.js
+++ b/toolkit/components/antitracking/test/browser/browser_permissionInPrivateWindows.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 AntiTracking.runTest("Test whether we receive any persistent permissions in private windows",
   // Blocking callback
   async _ => {
     // Nothing to do here!
   },
 
   // Non blocking callback
   async _ => {
--- a/toolkit/components/antitracking/test/browser/browser_script.js
+++ b/toolkit/components/antitracking/test/browser/browser_script.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 add_task(async function() {
   info("Starting subResources test");
 
   await SpecialPowers.flushPrefEnv();
   await SpecialPowers.pushPrefEnv({"set": [
     ["browser.contentblocking.allowlist.annotations.enabled", true],
     ["browser.contentblocking.allowlist.storage.enabled", true],
     ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
--- a/toolkit/components/antitracking/test/browser/browser_siteSpecificWorkArounds.js
+++ b/toolkit/components/antitracking/test/browser/browser_siteSpecificWorkArounds.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 AntiTracking.runTest("localStorage with a tracker that is whitelisted via a pref",
   async _ => {
     let shouldThrow = SpecialPowers.Services.prefs.getIntPref("network.cookie.cookieBehavior") == SpecialPowers.Ci.nsICookieService.BEHAVIOR_REJECT;
 
     let hasThrown;
     try {
       localStorage.foo = 42;
       hasThrown = false;
--- a/toolkit/components/antitracking/test/browser/browser_storageAccessPrivateWindow.js
+++ b/toolkit/components/antitracking/test/browser/browser_storageAccessPrivateWindow.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 AntiTracking.runTest("Storage Access API called in a private window",
   // blocking callback
   async _ => {
     /* import-globals-from storageAccessAPIHelpers.js */
     let [threw, rejected] = await callRequestStorageAccess();
     ok(!threw, "requestStorageAccess should not throw");
     ok(rejected, "requestStorageAccess shouldn't be available");
   },
--- a/toolkit/components/antitracking/test/browser/browser_storageAccessPromiseRejectHandlerUserInteraction.js
+++ b/toolkit/components/antitracking/test/browser/browser_storageAccessPromiseRejectHandlerUserInteraction.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 AntiTracking.runTest("Storage Access API returns promises that maintain user activation for calling its reject handler",
   // blocking callback
   async _ => {
     /* import-globals-from storageAccessAPIHelpers.js */
     let [threw, rejected] = await callRequestStorageAccess(dwu => {
       ok(dwu.isHandlingUserInput,
          "Promise reject handler must run as if we're handling user input");
     }, true);
--- a/toolkit/components/antitracking/test/browser/browser_storageAccessPromiseResolveHandlerUserInteraction.js
+++ b/toolkit/components/antitracking/test/browser/browser_storageAccessPromiseResolveHandlerUserInteraction.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 AntiTracking.runTest("Storage Access API returns promises that maintain user activation",
   // blocking callback
   async _ => {
     /* import-globals-from storageAccessAPIHelpers.js */
     let [threw, rejected] = await callRequestStorageAccess(dwu => {
       ok(dwu.isHandlingUserInput,
          "Promise handler must run as if we're handling user input");
     });
--- a/toolkit/components/antitracking/test/browser/browser_storageAccessRemovalNavigateSubframe.js
+++ b/toolkit/components/antitracking/test/browser/browser_storageAccessRemovalNavigateSubframe.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 AntiTracking.runTest("Storage Access is removed when subframe navigates",
   // blocking callback
   async _ => {
     /* import-globals-from storageAccessAPIHelpers.js */
     await noStorageAccessInitially();
   },
 
   // non-blocking callback
--- a/toolkit/components/antitracking/test/browser/browser_storageAccessSandboxed.js
+++ b/toolkit/components/antitracking/test/browser/browser_storageAccessSandboxed.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 let counter = 0;
 
 AntiTracking.runTest("Storage Access API called in a sandboxed iframe",
   // blocking callback
   async _ => {
     /* import-globals-from storageAccessAPIHelpers.js */
     let [threw, rejected] = await callRequestStorageAccess();
     ok(!threw, "requestStorageAccess should not throw");
--- a/toolkit/components/antitracking/test/browser/browser_storageAccessWithHeuristics.js
+++ b/toolkit/components/antitracking/test/browser/browser_storageAccessWithHeuristics.js
@@ -1,8 +1,10 @@
+/* import-globals-from antitracking_head.js */
+
 add_task(async function() {
   info("Starting subResources test");
 
   await SpecialPowers.flushPrefEnv();
   await SpecialPowers.pushPrefEnv({"set": [
     ["dom.storage_access.enabled", true],
     ["browser.contentblocking.allowlist.annotations.enabled", true],
     ["browser.contentblocking.allowlist.storage.enabled", true],
--- a/toolkit/components/antitracking/test/browser/head.js
+++ b/toolkit/components/antitracking/test/browser/head.js
@@ -1,8 +1,15 @@
+/* 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/. */
+
+"use strict";
+
 const TEST_DOMAIN = "http://example.net/";
 const TEST_DOMAIN_2 = "http://xn--exmple-cua.test/";
 const TEST_DOMAIN_3 = "https://xn--hxajbheg2az3al.xn--jxalpdlp/";
 const TEST_DOMAIN_4 = "http://prefixexample.com/";
 const TEST_DOMAIN_5 = "http://test/";
 const TEST_DOMAIN_6 = "http://mochi.test:8888/";
 const TEST_3RD_PARTY_DOMAIN = "https://tracking.example.org/";
 const TEST_3RD_PARTY_DOMAIN_TP = "https://tracking.example.com/";
@@ -20,716 +27,27 @@ const TEST_TOP_PAGE_6 = TEST_DOMAIN_6 + 
 const TEST_EMBEDDER_PAGE = TEST_DOMAIN + TEST_PATH + "embedder.html";
 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 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;
 
-var gFeatures = undefined;
-
-let {UrlClassifierTestUtils} = ChromeUtils.import("resource://testing-common/UrlClassifierTestUtils.jsm");
-
 requestLongerTimeout(3);
 
-this.AntiTracking = {
-  runTest(name, callbackTracking, callbackNonTracking, cleanupFunction, extraPrefs,
-          windowOpenTest = true, userInteractionTest = true,
-          expectedBlockingNotifications = Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER,
-          runInPrivateWindow = false, iframeSandbox = null, accessRemoval = null,
-          callbackAfterRemoval = null) {
-    // Here we want to test that a 3rd party context is simply blocked.
-    this._createTask({
-      name,
-      cookieBehavior: BEHAVIOR_REJECT_TRACKER,
-      blockingByContentBlockingRTUI: true,
-      allowList: false,
-      callback: callbackTracking,
-      extraPrefs,
-      expectedBlockingNotifications,
-      runInPrivateWindow,
-      iframeSandbox,
-      accessRemoval,
-      callbackAfterRemoval,
-    });
-    this._createCleanupTask(cleanupFunction);
-
-    this._createTask({
-      name,
-      cookieBehavior: BEHAVIOR_REJECT_TRACKER,
-      blockingByContentBlockingRTUI: false,
-      allowList: true,
-      callback: callbackTracking,
-      extraPrefs,
-      expectedBlockingNotifications,
-      runInPrivateWindow,
-      iframeSandbox,
-      accessRemoval,
-      callbackAfterRemoval,
-    });
-    this._createCleanupTask(cleanupFunction);
-
-    if (callbackNonTracking) {
-      let runExtraTests = true;
-      let options = {};
-      if (typeof callbackNonTracking == "object") {
-        options.callback = callbackNonTracking.callback;
-        runExtraTests = callbackNonTracking.runExtraTests;
-        if ("cookieBehavior" in callbackNonTracking) {
-          options.cookieBehavior = callbackNonTracking.cookieBehavior;
-        } else {
-          options.cookieBehavior = BEHAVIOR_ACCEPT;
-        }
-        if ("blockingByContentBlockingRTUI" in callbackNonTracking) {
-          options.blockingByContentBlockingRTUI =
-            callbackNonTracking.blockingByContentBlockingRTUI;
-        } else {
-          options.blockingByContentBlockingRTUI = false;
-        }
-        if ("blockingByAllowList" in callbackNonTracking) {
-          options.blockingByAllowList =
-            callbackNonTracking.blockingByAllowList;
-        } else {
-          options.blockingByAllowList = false;
-        }
-        callbackNonTracking = options.callback;
-        options.accessRemoval = null;
-        options.callbackAfterRemoval = null;
-      }
-
-      // Phase 1: Here we want to test that a 3rd party context is not blocked if pref is off.
-      if (runExtraTests) {
-        // There are five ways in which the third-party context may not be blocked:
-        //   * If the cookieBehavior pref causes it to not be blocked.
-        //   * If the contentBlocking pref causes it to not be blocked.
-        //   * If both of these prefs cause it to not be blocked.
-        //   * If the top-level page is on the content blocking allow list.
-        //   * If the contentBlocking third-party cookies UI pref is off, the allow list will be ignored.
-        // All of these cases are tested here.
-        this._createTask({
-          name,
-          cookieBehavior: BEHAVIOR_ACCEPT,
-          blockingByContentBlockingRTUI: true,
-          allowList: false,
-          callback: callbackNonTracking,
-          extraPrefs,
-          expectedBlockingNotifications: 0,
-          runInPrivateWindow,
-          iframeSandbox,
-          accessRemoval: null, // only passed with non-blocking callback
-          callbackAfterRemoval: null,
-        });
-        this._createCleanupTask(cleanupFunction);
-
-        this._createTask({
-          name,
-          cookieBehavior: BEHAVIOR_ACCEPT,
-          blockingByContentBlockingRTUI: false,
-          allowList: true,
-          callback: callbackNonTracking,
-          extraPrefs,
-          expectedBlockingNotifications: 0,
-          runInPrivateWindow,
-          iframeSandbox,
-          accessRemoval: null, // only passed with non-blocking callback
-          callbackAfterRemoval: null,
-        });
-        this._createCleanupTask(cleanupFunction);
-
-        this._createTask({
-          name,
-          cookieBehavior: BEHAVIOR_ACCEPT,
-          blockingByContentBlockingRTUI: false,
-          allowList: false,
-          callback: callbackNonTracking,
-          extraPrefs,
-          expectedBlockingNotifications: 0,
-          runInPrivateWindow,
-          iframeSandbox,
-          accessRemoval: null, // only passed with non-blocking callback
-          callbackAfterRemoval: null,
-        });
-        this._createCleanupTask(cleanupFunction);
-
-        this._createTask({
-          name,
-          cookieBehavior: BEHAVIOR_REJECT,
-          blockingByContentBlockingRTUI: true,
-          allowList: false,
-          callback: callbackTracking,
-          extraPrefs,
-          expectedBlockingNotifications: 0,
-          runInPrivateWindow,
-          iframeSandbox,
-          accessRemoval: null, // only passed with non-blocking callback
-          callbackAfterRemoval: null,
-        });
-        this._createCleanupTask(cleanupFunction);
-
-        this._createTask({
-          name,
-          cookieBehavior: BEHAVIOR_LIMIT_FOREIGN,
-          blockingByContentBlockingRTUI: true,
-          allowList: true,
-          callback: callbackNonTracking,
-          extraPrefs,
-          expectedBlockingNotifications: 0,
-          runInPrivateWindow,
-          iframeSandbox,
-          accessRemoval: null, // only passed with non-blocking callback
-          callbackAfterRemoval: null,
-        });
-        this._createCleanupTask(cleanupFunction);
-
-        this._createTask({
-          name,
-          cookieBehavior: BEHAVIOR_REJECT_FOREIGN,
-          blockingByContentBlockingRTUI: true,
-          allowList: true,
-          callback: callbackNonTracking,
-          extraPrefs,
-          expectedBlockingNotifications: 0,
-          runInPrivateWindow,
-          iframeSandbox,
-          accessRemoval: null, // only passed with non-blocking callback
-          callbackAfterRemoval: null,
-        });
-        this._createCleanupTask(cleanupFunction);
-
-        this._createTask({
-          name,
-          cookieBehavior: BEHAVIOR_REJECT_TRACKER,
-          blockingByContentBlockingRTUI: true,
-          allowList: true,
-          callback: callbackNonTracking,
-          extraPrefs,
-          expectedBlockingNotifications: 0,
-          runInPrivateWindow,
-          iframeSandbox,
-          accessRemoval,
-          callbackAfterRemoval,
-        });
-        this._createCleanupTask(cleanupFunction);
-
-        this._createTask({
-          name,
-          cookieBehavior: BEHAVIOR_REJECT_TRACKER,
-          blockingByContentBlockingRTUI: false,
-          allowList: false,
-          callback: callbackNonTracking,
-          extraPrefs,
-          expectedBlockingNotifications: false,
-          runInPrivateWindow,
-          iframeSandbox,
-          accessRemoval: null, // only passed with non-blocking callback
-          callbackAfterRemoval: null,
-          thirdPartyPage: TEST_ANOTHER_3RD_PARTY_PAGE,
-        });
-        this._createCleanupTask(cleanupFunction);
-      }
-
-      // Phase 2: Here we want to test that a third-party context doesn't
-      // get blocked with when the same origin is opened through window.open().
-      if (windowOpenTest) {
-        this._createWindowOpenTask(name, callbackTracking, callbackNonTracking,
-                                   runInPrivateWindow, iframeSandbox, extraPrefs);
-        this._createCleanupTask(cleanupFunction);
-      }
-
-      // Phase 3: Here we want to test that a third-party context doesn't
-      // get blocked with user interaction present
-      if (userInteractionTest) {
-        this._createUserInteractionTask(name, callbackTracking, callbackNonTracking,
-                                        runInPrivateWindow, iframeSandbox, extraPrefs);
-        this._createCleanupTask(cleanupFunction);
-      }
-    }
-  },
-
-  async interactWithTracker() {
-    let windowClosed = new Promise(resolve => {
-      Services.ww.registerNotification(function notification(aSubject, aTopic, aData) {
-        if (aTopic == "domwindowclosed") {
-          Services.ww.unregisterNotification(notification);
-          resolve();
-        }
-      });
-    });
-
-    info("Let's interact with the tracker");
-    window.open(TEST_3RD_PARTY_DOMAIN + TEST_PATH + "3rdPartyOpenUI.html");
-    await windowClosed;
-  },
-
-  async _setupTest(win, cookieBehavior, blockingByContentBlockingRTUI,
-                   extraPrefs) {
-    await SpecialPowers.flushPrefEnv();
-    await SpecialPowers.pushPrefEnv({"set": [
-      ["dom.storage_access.enabled", true],
-      ["browser.contentblocking.allowlist.annotations.enabled", blockingByContentBlockingRTUI],
-      ["browser.contentblocking.allowlist.storage.enabled", blockingByContentBlockingRTUI],
-      ["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],
-      ["privacy.restrict3rdpartystorage.userInteractionRequiredForHosts", "tracking.example.com,tracking.example.org"],
-    ]});
-
-    if (extraPrefs && Array.isArray(extraPrefs) && extraPrefs.length) {
-      await SpecialPowers.pushPrefEnv({"set": extraPrefs });
-
-      for (let item of extraPrefs) {
-        // When setting up skip URLs, we need to wait to ensure our prefs
-        // actually take effect.  In order to do this, we set up a skip list
-        // observer and wait until it calls us back.
-        if (item[0] == "urlclassifier.trackingAnnotationSkipURLs") {
-          info("Waiting for the skip list service to initialize...");
-          let classifier = Cc["@mozilla.org/url-classifier/dbservice;1"]
-                             .getService(Ci.nsIURIClassifier);
-          let feature = classifier.getFeatureByName("tracking-annotation");
-          await TestUtils.waitForCondition(() => feature.skipHostList == item[1].toLowerCase(),
-                                           "Skip list service initialized");
-          break;
-        }
-      }
-    }
-
-    await UrlClassifierTestUtils.addTestTrackers();
-  },
-
-  _createTask(options) {
-    add_task(async function() {
-      info("Starting " + (options.cookieBehavior != BEHAVIOR_ACCEPT ? "blocking" : "non-blocking") + " cookieBehavior (" + options.cookieBehavior + ") and " +
-                         (options.blockingByContentBlockingRTUI ? "" : "no") + " contentBlocking third-party cookies UI with" +
-                         (options.allowList ? "" : "out") + " allow list test " + options.name +
-                         " running in a " + (options.runInPrivateWindow ? "private" : "normal") + " window " +
-                         " with iframe sandbox set to " + options.iframeSandbox +
-                         " and access removal set to " + options.accessRemoval +
-                         (typeof options.thirdPartyPage == "string" ? (
-                            " and third party page set to " + options.thirdPartyPage) : ""));
-
-      is(!!options.callbackAfterRemoval, !!options.accessRemoval,
-         "callbackAfterRemoval must be passed when accessRemoval is non-null");
-
-      let win = window;
-      if (options.runInPrivateWindow) {
-        win = OpenBrowserWindow({private: true});
-        await TestUtils.topicObserved("browser-delayed-startup-finished");
-      }
-
-      await AntiTracking._setupTest(win, options.cookieBehavior,
-                                    options.blockingByContentBlockingRTUI,
-                                    options.extraPrefs);
-
-      let cookieBlocked = 0;
-      let listener = {
-        onContentBlockingEvent(webProgress, request, event) {
-          if ((event & options.expectedBlockingNotifications)) {
-            ++cookieBlocked;
-          }
-        },
-      };
-      win.gBrowser.addProgressListener(listener);
-
-      info("Creating a new tab");
-      let tab = BrowserTestUtils.addTab(win.gBrowser, TEST_TOP_PAGE);
-      win.gBrowser.selectedTab = tab;
-
-      let browser = win.gBrowser.getBrowserForTab(tab);
-      await BrowserTestUtils.browserLoaded(browser);
-
-      if (options.allowList) {
-        info("Disabling content blocking for this page");
-        win.ContentBlocking.disableForCurrentPage();
-
-        // The previous function reloads the browser, so wait for it to load again!
-        await BrowserTestUtils.browserLoaded(browser);
-      }
+const {UrlClassifierTestUtils} = ChromeUtils.import("resource://testing-common/UrlClassifierTestUtils.jsm");
 
-      info("Creating a 3rd party content");
-      let doAccessRemovalChecks = typeof options.accessRemoval == "string" &&
-                                  options.cookieBehavior == BEHAVIOR_REJECT_TRACKER &&
-                                  options.blockingByContentBlockingRTUI &&
-                                  !options.allowList;
-      let thirdPartyPage;
-      if (typeof options.thirdPartyPage == "string") {
-        thirdPartyPage = options.thirdPartyPage;
-      } else {
-        thirdPartyPage = TEST_3RD_PARTY_PAGE;
-      }
-      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");
-            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);
-              resolve();
-              return;
-            }
-
-            if (event.data.type == "ok") {
-              ok(event.data.what, event.data.msg);
-              return;
-            }
-
-            if (event.data.type == "info") {
-              info(event.data.msg);
-              return;
-            }
-
-            ok(false, "Unknown message");
-          });
-
-          content.document.body.appendChild(ifr);
-          ifr.src = obj.page;
-        });
-
-        if (obj.doAccessRemovalChecks) {
-          info(`Running after removal checks (${obj.accessRemoval})`);
-          switch (obj.accessRemoval) {
-          case "navigate-subframe":
-            await new content.Promise(resolve => {
-              let ifr = content.document.getElementById(id);
-              let oldWindow = ifr.contentWindow;
-              ifr.onload = function() {
-                info("Sending code to the old 3rd party content");
-                oldWindow.postMessage(obj.callbackAfterRemoval, "*");
-              };
-              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);
-                  resolve();
-                  return;
-                }
-
-                if (event.data.type == "ok") {
-                  ok(event.data.what, event.data.msg);
-                  return;
-                }
-
-                if (event.data.type == "info") {
-                  info(event.data.msg);
-                  return;
-                }
-
-                ok(false, "Unknown message");
-              });
-
-              ifr.src = obj.nextPage;
-            });
-            break;
-          default:
-            ok(false, "Unexpected accessRemoval code passed: " + obj.accessRemoval);
-            break;
-          }
-        }
-      });
-
-      if (options.allowList) {
-        info("Enabling content blocking for this page");
-        win.ContentBlocking.enableForCurrentPage();
-
-        // The previous function reloads the browser, so wait for it to load again!
-        await BrowserTestUtils.browserLoaded(browser);
-      }
-
-      win.gBrowser.removeProgressListener(listener);
-
-      is(!!cookieBlocked, !!options.expectedBlockingNotifications, "Checking cookie blocking notifications");
-
-      info("Removing the tab");
-      BrowserTestUtils.removeTab(tab);
-
-      if (options.runInPrivateWindow) {
-        win.close();
-      }
-    });
-  },
-
-  _createCleanupTask(cleanupFunction) {
-    add_task(async function() {
-      info("Cleaning up.");
-      if (cleanupFunction) {
-        await cleanupFunction();
-      }
-    });
-  },
-
-  _createWindowOpenTask(name, blockingCallback, nonBlockingCallback, runInPrivateWindow,
-                        iframeSandbox, extraPrefs) {
-    add_task(async function() {
-      info("Starting window-open test " + name);
-
-      let win = window;
-      if (runInPrivateWindow) {
-        win = OpenBrowserWindow({private: true});
-        await TestUtils.topicObserved("browser-delayed-startup-finished");
-      }
-
-      await AntiTracking._setupTest(win, BEHAVIOR_REJECT_TRACKER, true, extraPrefs);
-
-      info("Creating a new tab");
-      let tab = BrowserTestUtils.addTab(win.gBrowser, TEST_TOP_PAGE);
-      win.gBrowser.selectedTab = tab;
-
-      let browser = win.gBrowser.getBrowserForTab(tab);
-      await BrowserTestUtils.browserLoaded(browser);
-
-      let pageURL = TEST_3RD_PARTY_PAGE_WO;
-      if (gFeatures == "noopener") {
-        pageURL += "?noopener";
-      }
-
-      info("Creating a 3rd party content");
-      await ContentTask.spawn(browser,
-                              { page: pageURL,
-                                blockingCallback: blockingCallback.toString(),
-                                nonBlockingCallback: nonBlockingCallback.toString(),
-                                iframeSandbox,
-                              },
-                              async function(obj) {
-        await new content.Promise(resolve => {
-          let ifr = content.document.createElement("iframe");
-          ifr.onload = function() {
-            info("Sending code to the 3rd party content");
-            ifr.contentWindow.postMessage(obj, "*");
-          };
-          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);
-              resolve();
-              return;
-            }
-
-            if (event.data.type == "ok") {
-              ok(event.data.what, event.data.msg);
-              return;
-            }
+Services.scriptloader.loadSubScript(
+  "chrome://mochitests/content/browser/toolkit/components/antitracking/test/browser/antitracking_head.js",
+  this);
 
-            if (event.data.type == "info") {
-              info(event.data.msg);
-              return;
-            }
-
-            ok(false, "Unknown message");
-          });
-
-          content.document.body.appendChild(ifr);
-          ifr.src = obj.page;
-        });
-      });
-
-      info("Removing the tab");
-      BrowserTestUtils.removeTab(tab);
-
-      if (runInPrivateWindow) {
-        win.close();
-      }
-    });
-  },
-
-  _createUserInteractionTask(name, blockingCallback, nonBlockingCallback,
-                             runInPrivateWindow, iframeSandbox, extraPrefs) {
-    add_task(async function() {
-      info("Starting user-interaction test " + name);
-
-      let win = window;
-      if (runInPrivateWindow) {
-        win = OpenBrowserWindow({private: true});
-        await TestUtils.topicObserved("browser-delayed-startup-finished");
-      }
-
-      await AntiTracking._setupTest(win, BEHAVIOR_REJECT_TRACKER, true, extraPrefs);
-
-      info("Creating a new tab");
-      let tab = BrowserTestUtils.addTab(win.gBrowser, TEST_TOP_PAGE);
-      win.gBrowser.selectedTab = tab;
-
-      let browser = win.gBrowser.getBrowserForTab(tab);
-      await BrowserTestUtils.browserLoaded(browser);
-
-      info("Creating a 3rd party content");
-      await ContentTask.spawn(browser,
-                              { page: TEST_3RD_PARTY_PAGE_UI,
-                                popup: TEST_POPUP_PAGE,
-                                blockingCallback: blockingCallback.toString(),
-                                iframeSandbox,
-                              },
-                              async function(obj) {
-        let ifr = content.document.createElement("iframe");
-        let loading = new content.Promise(resolve => { ifr.onload = resolve; });
-        if (typeof obj.iframeSandbox == "string") {
-          ifr.setAttribute("sandbox", obj.iframeSandbox);
-        }
-        content.document.body.appendChild(ifr);
-        ifr.src = obj.page;
-        await loading;
-
-        info("The 3rd party content should not have access to first party storage.");
-        await new content.Promise(resolve => {
-          content.addEventListener("message", function msg(event) {
-            if (event.data.type == "finish") {
-              content.removeEventListener("message", msg);
-              resolve();
-              return;
-            }
-
-            if (event.data.type == "ok") {
-              ok(event.data.what, event.data.msg);
-              return;
-            }
-
-            if (event.data.type == "info") {
-              info(event.data.msg);
-              return;
-            }
-
-            ok(false, "Unknown message");
-          });
-          ifr.contentWindow.postMessage({ callback: obj.blockingCallback }, "*");
-        });
-
-        let windowClosed = new content.Promise(resolve => {
-          Services.ww.registerNotification(function notification(aSubject, aTopic, aData) {
-            if (aTopic == "domwindowclosed") {
-              Services.ww.unregisterNotification(notification);
-              resolve();
-            }
-          });
-        });
-
-        info("Opening a window from the iframe.");
-        ifr.contentWindow.open(obj.popup);
-
-        info("Let's wait for the window to be closed");
-        await windowClosed;
-
-        info("First time, the 3rd party content should not have access to first party storage " +
-             "because the tracker did not have user interaction");
-        await new content.Promise(resolve => {
-          content.addEventListener("message", function msg(event) {
-            if (event.data.type == "finish") {
-              content.removeEventListener("message", msg);
-              resolve();
-              return;
-            }
-
-            if (event.data.type == "ok") {
-              ok(event.data.what, event.data.msg);
-              return;
-            }
-
-            if (event.data.type == "info") {
-              info(event.data.msg);
-              return;
-            }
-
-            ok(false, "Unknown message");
-          });
-          ifr.contentWindow.postMessage({ callback: obj.blockingCallback }, "*");
-        });
-      });
-
-      await AntiTracking.interactWithTracker();
-
-      await ContentTask.spawn(browser,
-                              { page: TEST_3RD_PARTY_PAGE_UI,
-                                popup: TEST_POPUP_PAGE,
-                                nonBlockingCallback: nonBlockingCallback.toString(),
-                                iframeSandbox,
-                              },
-                              async function(obj) {
-        let ifr = content.document.createElement("iframe");
-        let loading = new content.Promise(resolve => { ifr.onload = resolve; });
-        if (typeof obj.iframeSandbox == "string") {
-          ifr.setAttribute("sandbox", obj.iframeSandbox);
-        }
-        content.document.body.appendChild(ifr);
-        ifr.src = obj.page;
-        await loading;
-
-        let windowClosed = new content.Promise(resolve => {
-          Services.ww.registerNotification(function notification(aSubject, aTopic, aData) {
-            if (aTopic == "domwindowclosed") {
-              Services.ww.unregisterNotification(notification);
-              resolve();
-            }
-          });
-        });
-
-        info("Opening a window from the iframe.");
-        ifr.contentWindow.open(obj.popup);
-
-        info("Let's wait for the window to be closed");
-        await windowClosed;
-
-        info("The 3rd party content should now have access to first party storage.");
-        await new content.Promise(resolve => {
-          content.addEventListener("message", function msg(event) {
-            if (event.data.type == "finish") {
-              content.removeEventListener("message", msg);
-              resolve();
-              return;
-            }
-
-            if (event.data.type == "ok") {
-              ok(event.data.what, event.data.msg);
-              return;
-            }
-
-            if (event.data.type == "info") {
-              info(event.data.msg);
-              return;
-            }
-
-            ok(false, "Unknown message");
-          });
-          ifr.contentWindow.postMessage({ callback: obj.nonBlockingCallback }, "*");
-        });
-      });
-
-      info("Removing the tab");
-      BrowserTestUtils.removeTab(tab);
-
-      if (runInPrivateWindow) {
-        win.close();
-      }
-    });
-  },
-};
+Services.scriptloader.loadSubScript(
+  "chrome://mochitests/content/browser/toolkit/components/antitracking/test/browser/storageprincipal_head.js",
+  this);
--- a/toolkit/components/antitracking/test/browser/imageCacheWorker.js
+++ b/toolkit/components/antitracking/test/browser/imageCacheWorker.js
@@ -1,10 +1,12 @@
 /* import-globals-from head.js */
+/* import-globals-from antitracking_head.js */
 /* import-globals-from browser_imageCache4.js */
+
 AntiTracking.runTest("Image cache - should load the image three times.",
   // blocking callback
   async _ => {
     // Let's load the image twice here.
     let img = document.createElement("img");
     document.body.appendChild(img);
     img.src = "https://tracking.example.org/browser/toolkit/components/antitracking/test/browser/image.sjs";
     await new Promise(resolve => { img.onload = resolve; });
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/storageprincipal_head.js
@@ -0,0 +1,89 @@
+/* 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";
+
+this.StoragePrincipalHelper = {
+  runTest(name, callback, cleanupFunction, extraPrefs) {
+    add_task(async _ => {
+      info("Starting test `" + name + "'...");
+
+      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],
+      ]});
+
+      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,
+                                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");
+            info("Sending code to the 3rd party content");
+            ifr.contentWindow.postMessage(obj.callback, "*");
+          };
+
+          content.addEventListener("message", function msg(event) {
+            if (event.data.type == "finish") {
+              content.removeEventListener("message", msg);
+              resolve();
+              return;
+            }
+
+            if (event.data.type == "ok") {
+              ok(event.data.what, event.data.msg);
+              return;
+            }
+
+            if (event.data.type == "info") {
+              info(event.data.msg);
+              return;
+            }
+
+            ok(false, "Unknown message");
+          });
+
+          content.document.body.appendChild(ifr);
+          ifr.src = obj.page;
+        });
+      });
+
+      info("Removing the tab");
+      BrowserTestUtils.removeTab(tab);
+    });
+
+    add_task(async _ => {
+      info("Cleaning up.");
+      if (cleanupFunction) {
+        await cleanupFunction();
+      }
+    });
+  },
+};