Bug 1551055 - StoragePrincipal should be supported by localStorage - part 2 - tests, r=asuth
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 14 May 2019 05:49:49 +0000
changeset 473730 df4c74e2ecf7f94ea48cb16896d0be1e6c675ae4
parent 473729 386a0b72c793860f7b40fdf7383b7a9078f02091
child 473731 83e3da605798ac92bb8d283d3fc1523c1dd50222
push id36012
push useraiakab@mozilla.com
push dateTue, 14 May 2019 09:42:36 +0000
treeherdermozilla-central@db99095ae0b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1551055
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 1551055 - StoragePrincipal should be supported by localStorage - part 2 - tests, r=asuth Differential Revision: https://phabricator.services.mozilla.com/D30802
toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage_events.js
--- a/toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage_events.js
+++ b/toolkit/components/antitracking/test/browser/browser_partitionedLocalStorage_events.js
@@ -1,530 +1,564 @@
-// A same origin (and same-process via setting "dom.ipc.processCount" to 1)
-// top-level window with access to real localStorage does not share storage
-// with an ePartitionOrDeny iframe that should have PartitionedLocalStorage and
-// no storage events are received in either direction.  (Same-process in order
-// to avoid having to worry about any e10s propagation issues.)
-add_task(async _ => {
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["dom.ipc.processCount", 1],
-    ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
-    ["privacy.trackingprotection.enabled", false],
-    ["privacy.trackingprotection.pbmode.enabled", false],
-    ["privacy.trackingprotection.annotate_channels", true],
-    ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"],
-  ]});
+function runAllTests(withStoragePrincipalEnabled, lsngEnabled) {
+  // A same origin (and same-process via setting "dom.ipc.processCount" to 1)
+  // top-level window with access to real localStorage does not share storage
+  // with an ePartitionOrDeny iframe that should have PartitionedLocalStorage and
+  // no storage events are received in either direction.  (Same-process in order
+  // to avoid having to worry about any e10s propagation issues.)
+  add_task(async _ => {
+    await SpecialPowers.pushPrefEnv({"set": [
+      ["dom.ipc.processCount", 1],
+      ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
+      ["privacy.trackingprotection.enabled", false],
+      ["privacy.trackingprotection.pbmode.enabled", false],
+      ["privacy.trackingprotection.annotate_channels", true],
+      ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"],
+      ["privacy.storagePrincipal.enabledForTrackers", withStoragePrincipalEnabled],
+      ["dom.storage.next_gen", lsngEnabled],
+    ]});
 
-  await UrlClassifierTestUtils.addTestTrackers();
+    await UrlClassifierTestUtils.addTestTrackers();
 
-  info("Creating a non-tracker top-level context");
-  let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html");
-  let normalBrowser = gBrowser.getBrowserForTab(normalTab);
-  await BrowserTestUtils.browserLoaded(normalBrowser);
+    info("Creating a non-tracker top-level context");
+    let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html");
+    let normalBrowser = gBrowser.getBrowserForTab(normalTab);
+    await BrowserTestUtils.browserLoaded(normalBrowser);
 
-  info("Creating a tracker top-level context");
-  let trackerTab = BrowserTestUtils.addTab(gBrowser, TEST_3RD_PARTY_DOMAIN + TEST_PATH + "page.html");
-  let trackerBrowser = gBrowser.getBrowserForTab(trackerTab);
-  await BrowserTestUtils.browserLoaded(trackerBrowser);
+    info("Creating a tracker top-level context");
+    let trackerTab = BrowserTestUtils.addTab(gBrowser, TEST_3RD_PARTY_DOMAIN + TEST_PATH + "page.html");
+    let trackerBrowser = gBrowser.getBrowserForTab(trackerTab);
+    await BrowserTestUtils.browserLoaded(trackerBrowser);
 
-  info("The non-tracker page opens a tracker iframe");
-  await ContentTask.spawn(normalBrowser, {
-      page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html",
-    }, async obj => {
-      let ifr = content.document.createElement("iframe");
-      ifr.setAttribute("id", "ifr");
-      ifr.setAttribute("src", obj.page);
+    info("The non-tracker page opens a tracker iframe");
+    await ContentTask.spawn(normalBrowser, {
+        page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html",
+      }, async obj => {
+        let ifr = content.document.createElement("iframe");
+        ifr.setAttribute("id", "ifr");
+        ifr.setAttribute("src", obj.page);
 
-      info("Iframe loading...");
-      await new content.Promise(resolve => {
-        ifr.onload = resolve;
-        content.document.body.appendChild(ifr);
-      });
+        info("Iframe loading...");
+        await new content.Promise(resolve => {
+          ifr.onload = resolve;
+          content.document.body.appendChild(ifr);
+        });
 
-      info("Setting localStorage value...");
-      ifr.contentWindow.postMessage("setValue", "*");
+        info("Setting localStorage value...");
+        ifr.contentWindow.postMessage("setValue", "*");
 
-      info("Getting the value...");
-      let value = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr.contentWindow.postMessage("getValue", "*");
-      });
+        info("Getting the value...");
+        let value = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr.contentWindow.postMessage("getValue", "*");
+        });
 
-      ok(value.startsWith("tracker-"), "The value is correctly set by the tracker");
-    }
-  );
+        ok(value.startsWith("tracker-"), "The value is correctly set by the tracker");
+      }
+    );
 
-  info("The tracker page should not have received events");
-  await ContentTask.spawn(trackerBrowser, null, async _ => {
-      is(content.localStorage.foo, undefined, "Undefined value!");
-      content.localStorage.foo = "normal-" + Math.random();
-    }
-  );
+    info("The tracker page should not have received events");
+    await ContentTask.spawn(trackerBrowser, null, async _ => {
+        is(content.localStorage.foo, undefined, "Undefined value!");
+        content.localStorage.foo = "normal-" + Math.random();
+      }
+    );
 
-  info("Let's see if non-tracker page has received events");
-  await ContentTask.spawn(normalBrowser, null, async _ => {
-      let ifr = content.document.getElementById("ifr");
+    info("Let's see if non-tracker page has received events");
+    await ContentTask.spawn(normalBrowser, null, async _ => {
+        let ifr = content.document.getElementById("ifr");
 
-      info("Getting the value...");
-      let value = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr.contentWindow.postMessage("getValue", "*");
-      });
+        info("Getting the value...");
+        let value = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr.contentWindow.postMessage("getValue", "*");
+        });
 
-      ok(value.startsWith("tracker-"), "The value is correctly set by the tracker");
+        ok(value.startsWith("tracker-"), "The value is correctly set by the tracker");
 
-      info("Getting the events...");
-      let events = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr.contentWindow.postMessage("getEvents", "*");
-      });
+        info("Getting the events...");
+        let events = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr.contentWindow.postMessage("getEvents", "*");
+        });
 
-      is(events, 0, "No events");
-    }
-  );
+        is(events, 0, "No events");
+      }
+    );
 
-  BrowserTestUtils.removeTab(trackerTab);
-  BrowserTestUtils.removeTab(normalTab);
-});
+    BrowserTestUtils.removeTab(trackerTab);
+    BrowserTestUtils.removeTab(normalTab);
+  });
 
-// Two ePartitionOrDeny iframes in the same tab in the same origin don"t see
-// the same localStorage values and no storage events are received from each
-// other.
-add_task(async _ => {
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["dom.ipc.processCount", 1],
-    ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
-    ["privacy.trackingprotection.enabled", false],
-    ["privacy.trackingprotection.pbmode.enabled", false],
-    ["privacy.trackingprotection.annotate_channels", true],
-    ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"],
-  ]});
+  // Two ePartitionOrDeny iframes in the same tab in the same origin don't see
+  // the same localStorage values and no storage events are received from each
+  // other.
+  add_task(async _ => {
+    await SpecialPowers.pushPrefEnv({"set": [
+      ["dom.ipc.processCount", 1],
+      ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
+      ["privacy.trackingprotection.enabled", false],
+      ["privacy.trackingprotection.pbmode.enabled", false],
+      ["privacy.trackingprotection.annotate_channels", true],
+      ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"],
+      ["privacy.storagePrincipal.enabledForTrackers", withStoragePrincipalEnabled],
+    ]});
 
-  await UrlClassifierTestUtils.addTestTrackers();
+    await UrlClassifierTestUtils.addTestTrackers();
 
-  info("Creating a non-tracker top-level context");
-  let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html");
-  let normalBrowser = gBrowser.getBrowserForTab(normalTab);
-  await BrowserTestUtils.browserLoaded(normalBrowser);
+    info("Creating a non-tracker top-level context");
+    let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html");
+    let normalBrowser = gBrowser.getBrowserForTab(normalTab);
+    await BrowserTestUtils.browserLoaded(normalBrowser);
 
-  info("The non-tracker page opens a tracker iframe");
-  await ContentTask.spawn(normalBrowser, {
-      page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html",
-    }, async obj => {
-      let ifr1 = content.document.createElement("iframe");
-      ifr1.setAttribute("id", "ifr1");
-      ifr1.setAttribute("src", obj.page);
+    info("The non-tracker page opens a tracker iframe");
+    await ContentTask.spawn(normalBrowser, {
+        page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html",
+        withStoragePrincipalEnabled,
+      }, async obj => {
+        let ifr1 = content.document.createElement("iframe");
+        ifr1.setAttribute("id", "ifr1");
+        ifr1.setAttribute("src", obj.page);
 
-      info("Iframe 1 loading...");
-      await new content.Promise(resolve => {
-        ifr1.onload = resolve;
-        content.document.body.appendChild(ifr1);
-      });
+        info("Iframe 1 loading...");
+        await new content.Promise(resolve => {
+          ifr1.onload = resolve;
+          content.document.body.appendChild(ifr1);
+        });
 
-      let ifr2 = content.document.createElement("iframe");
-      ifr2.setAttribute("id", "ifr2");
-      ifr2.setAttribute("src", obj.page);
+        let ifr2 = content.document.createElement("iframe");
+        ifr2.setAttribute("id", "ifr2");
+        ifr2.setAttribute("src", obj.page);
 
-      info("Iframe 2 loading...");
-      await new content.Promise(resolve => {
-        ifr2.onload = resolve;
-        content.document.body.appendChild(ifr2);
-      });
-
-      info("Setting localStorage value in ifr1...");
-      ifr1.contentWindow.postMessage("setValue", "*");
+        info("Iframe 2 loading...");
+        await new content.Promise(resolve => {
+          ifr2.onload = resolve;
+          content.document.body.appendChild(ifr2);
+        });
 
-      info("Getting the value from ifr1...");
-      let value = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr1.contentWindow.postMessage("getValue", "*");
-      });
+        info("Setting localStorage value in ifr1...");
+        ifr1.contentWindow.postMessage("setValue", "*");
 
-      ok(value.startsWith("tracker-"), "The value is correctly set in ifr1");
+        info("Getting the value from ifr1...");
+        let value = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr1.contentWindow.postMessage("getValue", "*");
+        });
 
-      info("Getting the value from ifr2...");
-      value = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr2.contentWindow.postMessage("getValue", "*");
-      });
+        ok(value.startsWith("tracker-"), "The value is correctly set in ifr1");
 
-      is(value, null, "The value is nt set in ifr2");
+        info("Getting the value from ifr2...");
+        value = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr2.contentWindow.postMessage("getValue", "*");
+        });
 
-      info("Getting the events received by ifr2...");
-      let events = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr2.contentWindow.postMessage("getEvents", "*");
-      });
-
-      is(events, 0, "No events");
-    }
-  );
+        if (obj.withStoragePrincipalEnabled) {
+          ok(value.startsWith("tracker-"), "The value is correctly set in ifr2");
+        } else {
+          is(value, null, "The value is not set in ifr2");
+        }
 
-  BrowserTestUtils.removeTab(normalTab);
-});
+        info("Getting the events received by ifr2...");
+        let events = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr2.contentWindow.postMessage("getEvents", "*");
+        });
 
-// Same as the previous test but with a cookie behavior of BEHAVIOR_ACCEPT
-// instead of BEHAVIOR_REJECT_TRACKER so the iframes get real, persistent
-// localStorage instead of partitioned localStorage.
-add_task(async _ => {
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["dom.ipc.processCount", 1],
-    ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_ACCEPT],
-    ["privacy.trackingprotection.enabled", false],
-    ["privacy.trackingprotection.pbmode.enabled", false],
-    ["privacy.trackingprotection.annotate_channels", true],
-    ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"],
-  ]});
+        if (obj.withStoragePrincipalEnabled) {
+          is(events, 1, "1 event received");
+        } else {
+          is(events, 0, "No events");
+        }
+      }
+    );
 
-  await UrlClassifierTestUtils.addTestTrackers();
+    BrowserTestUtils.removeTab(normalTab);
+  });
 
-  info("Creating a non-tracker top-level context");
-  let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html");
-  let normalBrowser = gBrowser.getBrowserForTab(normalTab);
-  await BrowserTestUtils.browserLoaded(normalBrowser);
+  // Same as the previous test but with a cookie behavior of BEHAVIOR_ACCEPT
+  // instead of BEHAVIOR_REJECT_TRACKER so the iframes get real, persistent
+  // localStorage instead of partitioned localStorage.
+  add_task(async _ => {
+    await SpecialPowers.pushPrefEnv({"set": [
+      ["dom.ipc.processCount", 1],
+      ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_ACCEPT],
+      ["privacy.trackingprotection.enabled", false],
+      ["privacy.trackingprotection.pbmode.enabled", false],
+      ["privacy.trackingprotection.annotate_channels", true],
+      ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"],
+      ["privacy.storagePrincipal.enabledForTrackers", withStoragePrincipalEnabled],
+    ]});
 
-  info("The non-tracker page opens a tracker iframe");
-  await ContentTask.spawn(normalBrowser, {
-      page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html",
-    }, async obj => {
-      let ifr1 = content.document.createElement("iframe");
-      ifr1.setAttribute("id", "ifr1");
-      ifr1.setAttribute("src", obj.page);
+    await UrlClassifierTestUtils.addTestTrackers();
 
-      info("Iframe 1 loading...");
-      await new content.Promise(resolve => {
-        ifr1.onload = resolve;
-        content.document.body.appendChild(ifr1);
-      });
+    info("Creating a non-tracker top-level context");
+    let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html");
+    let normalBrowser = gBrowser.getBrowserForTab(normalTab);
+    await BrowserTestUtils.browserLoaded(normalBrowser);
 
-      let ifr2 = content.document.createElement("iframe");
-      ifr2.setAttribute("id", "ifr2");
-      ifr2.setAttribute("src", obj.page);
+    info("The non-tracker page opens a tracker iframe");
+    await ContentTask.spawn(normalBrowser, {
+        page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html",
+      }, async obj => {
+        let ifr1 = content.document.createElement("iframe");
+        ifr1.setAttribute("id", "ifr1");
+        ifr1.setAttribute("src", obj.page);
 
-      info("Iframe 2 loading...");
-      await new content.Promise(resolve => {
-        ifr2.onload = resolve;
-        content.document.body.appendChild(ifr2);
-      });
+        info("Iframe 1 loading...");
+        await new content.Promise(resolve => {
+          ifr1.onload = resolve;
+          content.document.body.appendChild(ifr1);
+        });
 
-      info("Setting localStorage value in ifr1...");
-      ifr1.contentWindow.postMessage("setValue", "*");
+        let ifr2 = content.document.createElement("iframe");
+        ifr2.setAttribute("id", "ifr2");
+        ifr2.setAttribute("src", obj.page);
 
-      info("Getting the value from ifr1...");
-      let value1 = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr1.contentWindow.postMessage("getValue", "*");
-      });
+        info("Iframe 2 loading...");
+        await new content.Promise(resolve => {
+          ifr2.onload = resolve;
+          content.document.body.appendChild(ifr2);
+        });
+
+        info("Setting localStorage value in ifr1...");
+        ifr1.contentWindow.postMessage("setValue", "*");
 
-      ok(value1.startsWith("tracker-"), "The value is correctly set in ifr1");
+        info("Getting the value from ifr1...");
+        let value1 = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr1.contentWindow.postMessage("getValue", "*");
+        });
+
+        ok(value1.startsWith("tracker-"), "The value is correctly set in ifr1");
 
-      info("Getting the value from ifr2...");
-      let value2 = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr2.contentWindow.postMessage("getValue", "*");
-      });
+        info("Getting the value from ifr2...");
+        let value2 = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr2.contentWindow.postMessage("getValue", "*");
+        });
 
-      is(value2, value1, "The values match");
+        is(value2, value1, "The values match");
 
-      info("Getting the events received by ifr2...");
-      let events = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr2.contentWindow.postMessage("getEvents", "*");
-      });
+        info("Getting the events received by ifr2...");
+        let events = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr2.contentWindow.postMessage("getEvents", "*");
+        });
 
-      is(events, 1, "One event");
-    }
-  );
+        is(events, 1, "One event");
+      }
+    );
 
-  BrowserTestUtils.removeTab(normalTab);
-});
+    BrowserTestUtils.removeTab(normalTab);
+  });
 
-// An ePartitionOrDeny iframe navigated between two distinct pages on the same
-// origin does not see the values stored by the previous iframe.
-add_task(async _ => {
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["dom.ipc.processCount", 1],
-    ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
-    ["privacy.trackingprotection.enabled", false],
-    ["privacy.trackingprotection.pbmode.enabled", false],
-    ["privacy.trackingprotection.annotate_channels", true],
-    ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"],
-  ]});
+  // An ePartitionOrDeny iframe navigated between two distinct pages on the same
+  // origin does not see the values stored by the previous iframe.
+  add_task(async _ => {
+    await SpecialPowers.pushPrefEnv({"set": [
+      ["dom.ipc.processCount", 1],
+      ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
+      ["privacy.trackingprotection.enabled", false],
+      ["privacy.trackingprotection.pbmode.enabled", false],
+      ["privacy.trackingprotection.annotate_channels", true],
+      ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"],
+      ["privacy.storagePrincipal.enabledForTrackers", withStoragePrincipalEnabled],
+    ]});
+
+    await UrlClassifierTestUtils.addTestTrackers();
 
-  await UrlClassifierTestUtils.addTestTrackers();
-
-  info("Creating a non-tracker top-level context");
-  let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html");
-  let normalBrowser = gBrowser.getBrowserForTab(normalTab);
-  await BrowserTestUtils.browserLoaded(normalBrowser);
+    info("Creating a non-tracker top-level context");
+    let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html");
+    let normalBrowser = gBrowser.getBrowserForTab(normalTab);
+    await BrowserTestUtils.browserLoaded(normalBrowser);
 
-  info("The non-tracker page opens a tracker iframe");
-  await ContentTask.spawn(normalBrowser, {
-      page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html",
-    }, async obj => {
-      let ifr = content.document.createElement("iframe");
-      ifr.setAttribute("id", "ifr");
-      ifr.setAttribute("src", obj.page);
+    info("The non-tracker page opens a tracker iframe");
+    await ContentTask.spawn(normalBrowser, {
+        page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html",
+        withStoragePrincipalEnabled,
+      }, async obj => {
+        let ifr = content.document.createElement("iframe");
+        ifr.setAttribute("id", "ifr");
+        ifr.setAttribute("src", obj.page);
+
+        info("Iframe loading...");
+        await new content.Promise(resolve => {
+          ifr.onload = resolve;
+          content.document.body.appendChild(ifr);
+        });
 
-      info("Iframe loading...");
-      await new content.Promise(resolve => {
-        ifr.onload = resolve;
-        content.document.body.appendChild(ifr);
-      });
+        info("Setting localStorage value in ifr...");
+        ifr.contentWindow.postMessage("setValue", "*");
 
-      info("Setting localStorage value in ifr...");
-      ifr.contentWindow.postMessage("setValue", "*");
+        info("Getting the value from ifr...");
+        let value = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr.contentWindow.postMessage("getValue", "*");
+        });
 
-      info("Getting the value from ifr...");
-      let value = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr.contentWindow.postMessage("getValue", "*");
-      });
+        ok(value.startsWith("tracker-"), "The value is correctly set in ifr");
 
-      ok(value.startsWith("tracker-"), "The value is correctly set in ifr");
-
-      info("Navigate...");
-      await new content.Promise(resolve => {
-        ifr.onload = resolve;
-        ifr.setAttribute("src", obj.page + "?" + Math.random());
-      });
+        info("Navigate...");
+        await new content.Promise(resolve => {
+          ifr.onload = resolve;
+          ifr.setAttribute("src", obj.page + "?" + Math.random());
+        });
 
-      info("Getting the value from ifr...");
-      value = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr.contentWindow.postMessage("getValue", "*");
-      });
+        info("Getting the value from ifr...");
+        let value2 = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr.contentWindow.postMessage("getValue", "*");
+        });
 
-      is(value, null, "The value is undefined");
-    }
-  );
+        if (obj.withStoragePrincipalEnabled) {
+          is(value, value2, "The value is received");
+        } else {
+          is(value2, null, "The value is undefined");
+        }
+      }
+    );
 
-  BrowserTestUtils.removeTab(normalTab);
-});
+    BrowserTestUtils.removeTab(normalTab);
+  });
 
-// Like the previous test, but accepting trackers
-add_task(async _ => {
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["dom.ipc.processCount", 1],
-    ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_ACCEPT],
-    ["privacy.trackingprotection.enabled", false],
-    ["privacy.trackingprotection.pbmode.enabled", false],
-    ["privacy.trackingprotection.annotate_channels", true],
-    ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"],
-  ]});
+  // Like the previous test, but accepting trackers
+  add_task(async _ => {
+    await SpecialPowers.pushPrefEnv({"set": [
+      ["dom.ipc.processCount", 1],
+      ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_ACCEPT],
+      ["privacy.trackingprotection.enabled", false],
+      ["privacy.trackingprotection.pbmode.enabled", false],
+      ["privacy.trackingprotection.annotate_channels", true],
+      ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"],
+      ["privacy.storagePrincipal.enabledForTrackers", withStoragePrincipalEnabled],
+    ]});
 
-  await UrlClassifierTestUtils.addTestTrackers();
+    await UrlClassifierTestUtils.addTestTrackers();
 
-  info("Creating a non-tracker top-level context");
-  let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html");
-  let normalBrowser = gBrowser.getBrowserForTab(normalTab);
-  await BrowserTestUtils.browserLoaded(normalBrowser);
+    info("Creating a non-tracker top-level context");
+    let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html");
+    let normalBrowser = gBrowser.getBrowserForTab(normalTab);
+    await BrowserTestUtils.browserLoaded(normalBrowser);
 
-  info("The non-tracker page opens a tracker iframe");
-  await ContentTask.spawn(normalBrowser, {
-      page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html",
-    }, async obj => {
-      let ifr = content.document.createElement("iframe");
-      ifr.setAttribute("id", "ifr");
-      ifr.setAttribute("src", obj.page);
+    info("The non-tracker page opens a tracker iframe");
+    await ContentTask.spawn(normalBrowser, {
+        page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html",
+      }, async obj => {
+        let ifr = content.document.createElement("iframe");
+        ifr.setAttribute("id", "ifr");
+        ifr.setAttribute("src", obj.page);
 
-      info("Iframe loading...");
-      await new content.Promise(resolve => {
-        ifr.onload = resolve;
-        content.document.body.appendChild(ifr);
-      });
+        info("Iframe loading...");
+        await new content.Promise(resolve => {
+          ifr.onload = resolve;
+          content.document.body.appendChild(ifr);
+        });
 
-      info("Setting localStorage value in ifr...");
-      ifr.contentWindow.postMessage("setValue", "*");
+        info("Setting localStorage value in ifr...");
+        ifr.contentWindow.postMessage("setValue", "*");
 
-      info("Getting the value from ifr...");
-      let value = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr.contentWindow.postMessage("getValue", "*");
-      });
+        info("Getting the value from ifr...");
+        let value = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr.contentWindow.postMessage("getValue", "*");
+        });
 
-      ok(value.startsWith("tracker-"), "The value is correctly set in ifr");
+        ok(value.startsWith("tracker-"), "The value is correctly set in ifr");
 
-      info("Navigate...");
-      await new content.Promise(resolve => {
-        ifr.onload = resolve;
-        ifr.setAttribute("src", obj.page + "?" + Math.random());
-      });
+        info("Navigate...");
+        await new content.Promise(resolve => {
+          ifr.onload = resolve;
+          ifr.setAttribute("src", obj.page + "?" + Math.random());
+        });
 
-      info("Getting the value from ifr...");
-      let value2 = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr.contentWindow.postMessage("getValue", "*");
-      });
+        info("Getting the value from ifr...");
+        let value2 = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr.contentWindow.postMessage("getValue", "*");
+        });
 
-      is(value, value2, "The value is undefined");
-    }
-  );
+        is(value, value2, "The value is received");
+      }
+    );
 
-  BrowserTestUtils.removeTab(normalTab);
-});
+    BrowserTestUtils.removeTab(normalTab);
+  });
 
-// An ePartitionOrDeny iframe on the same origin that is navigated to itself
-// via window.location.reload() or equivalent does not see the values stored by
-// its previous self.
-add_task(async _ => {
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["dom.ipc.processCount", 1],
-    ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
-    ["privacy.trackingprotection.enabled", false],
-    ["privacy.trackingprotection.pbmode.enabled", false],
-    ["privacy.trackingprotection.annotate_channels", true],
-    ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"],
-  ]});
+  // An ePartitionOrDeny iframe on the same origin that is navigated to itself
+  // via window.location.reload() or equivalent does not see the values stored
+  // by its previous self.
+  add_task(async _ => {
+    await SpecialPowers.pushPrefEnv({"set": [
+      ["dom.ipc.processCount", 1],
+      ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
+      ["privacy.trackingprotection.enabled", false],
+      ["privacy.trackingprotection.pbmode.enabled", false],
+      ["privacy.trackingprotection.annotate_channels", true],
+      ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"],
+      ["privacy.storagePrincipal.enabledForTrackers", withStoragePrincipalEnabled],
+    ]});
 
-  await UrlClassifierTestUtils.addTestTrackers();
+    await UrlClassifierTestUtils.addTestTrackers();
 
-  info("Creating a non-tracker top-level context");
-  let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html");
-  let normalBrowser = gBrowser.getBrowserForTab(normalTab);
-  await BrowserTestUtils.browserLoaded(normalBrowser);
+    info("Creating a non-tracker top-level context");
+    let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html");
+    let normalBrowser = gBrowser.getBrowserForTab(normalTab);
+    await BrowserTestUtils.browserLoaded(normalBrowser);
 
-  info("The non-tracker page opens a tracker iframe");
-  await ContentTask.spawn(normalBrowser, {
-      page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html",
-    }, async obj => {
-      let ifr = content.document.createElement("iframe");
-      ifr.setAttribute("id", "ifr");
-      ifr.setAttribute("src", obj.page);
+    info("The non-tracker page opens a tracker iframe");
+    await ContentTask.spawn(normalBrowser, {
+        page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html",
+        withStoragePrincipalEnabled,
+      }, async obj => {
+        let ifr = content.document.createElement("iframe");
+        ifr.setAttribute("id", "ifr");
+        ifr.setAttribute("src", obj.page);
 
-      info("Iframe loading...");
-      await new content.Promise(resolve => {
-        ifr.onload = resolve;
-        content.document.body.appendChild(ifr);
-      });
+        info("Iframe loading...");
+        await new content.Promise(resolve => {
+          ifr.onload = resolve;
+          content.document.body.appendChild(ifr);
+        });
 
-      info("Setting localStorage value in ifr...");
-      ifr.contentWindow.postMessage("setValue", "*");
+        info("Setting localStorage value in ifr...");
+        ifr.contentWindow.postMessage("setValue", "*");
 
-      info("Getting the value from ifr...");
-      let value = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr.contentWindow.postMessage("getValue", "*");
-      });
+        info("Getting the value from ifr...");
+        let value = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr.contentWindow.postMessage("getValue", "*");
+        });
 
-      ok(value.startsWith("tracker-"), "The value is correctly set in ifr");
+        ok(value.startsWith("tracker-"), "The value is correctly set in ifr");
+
+        info("Reload...");
+        await new content.Promise(resolve => {
+          ifr.onload = resolve;
+          ifr.contentWindow.postMessage("reload", "*");
+        });
 
-      info("Reload...");
-      await new content.Promise(resolve => {
-        ifr.onload = resolve;
-        ifr.contentWindow.postMessage("reload", "*");
-      });
+        info("Getting the value from ifr...");
+        let value2 = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr.contentWindow.postMessage("getValue", "*");
+        });
 
-      info("Getting the value from ifr...");
-      value = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr.contentWindow.postMessage("getValue", "*");
-      });
+        if (obj.withStoragePrincipalEnabled) {
+          is(value, value2, "The value is equal");
+        } else {
+          is(value2, null, "The value is undefined");
+        }
+      }
+    );
 
-      is(value, null, "The value is undefined");
-    }
-  );
-
-  BrowserTestUtils.removeTab(normalTab);
-});
+    BrowserTestUtils.removeTab(normalTab);
+  });
 
-// Like the previous test, but accepting trackers
-add_task(async _ => {
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["dom.ipc.processCount", 1],
-    ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_ACCEPT],
-    ["privacy.trackingprotection.enabled", false],
-    ["privacy.trackingprotection.pbmode.enabled", false],
-    ["privacy.trackingprotection.annotate_channels", true],
-    ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"],
-  ]});
+  // Like the previous test, but accepting trackers
+  add_task(async _ => {
+    await SpecialPowers.pushPrefEnv({"set": [
+      ["dom.ipc.processCount", 1],
+      ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_ACCEPT],
+      ["privacy.trackingprotection.enabled", false],
+      ["privacy.trackingprotection.pbmode.enabled", false],
+      ["privacy.trackingprotection.annotate_channels", true],
+      ["privacy.restrict3rdpartystorage.partitionedHosts", "tracking.example.org,tracking.example.com"],
+      ["privacy.storagePrincipal.enabledForTrackers", withStoragePrincipalEnabled],
+    ]});
 
-  await UrlClassifierTestUtils.addTestTrackers();
+    await UrlClassifierTestUtils.addTestTrackers();
 
-  info("Creating a non-tracker top-level context");
-  let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html");
-  let normalBrowser = gBrowser.getBrowserForTab(normalTab);
-  await BrowserTestUtils.browserLoaded(normalBrowser);
+    info("Creating a non-tracker top-level context");
+    let normalTab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "page.html");
+    let normalBrowser = gBrowser.getBrowserForTab(normalTab);
+    await BrowserTestUtils.browserLoaded(normalBrowser);
 
-  info("The non-tracker page opens a tracker iframe");
-  await ContentTask.spawn(normalBrowser, {
-      page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html",
-    }, async obj => {
-      let ifr = content.document.createElement("iframe");
-      ifr.setAttribute("id", "ifr");
-      ifr.setAttribute("src", obj.page);
+    info("The non-tracker page opens a tracker iframe");
+    await ContentTask.spawn(normalBrowser, {
+        page: TEST_3RD_PARTY_DOMAIN + TEST_PATH + "localStorageEvents.html",
+      }, async obj => {
+        let ifr = content.document.createElement("iframe");
+        ifr.setAttribute("id", "ifr");
+        ifr.setAttribute("src", obj.page);
 
-      info("Iframe loading...");
-      await new content.Promise(resolve => {
-        ifr.onload = resolve;
-        content.document.body.appendChild(ifr);
-      });
+        info("Iframe loading...");
+        await new content.Promise(resolve => {
+          ifr.onload = resolve;
+          content.document.body.appendChild(ifr);
+        });
 
-      info("Setting localStorage value in ifr...");
-      ifr.contentWindow.postMessage("setValue", "*");
+        info("Setting localStorage value in ifr...");
+        ifr.contentWindow.postMessage("setValue", "*");
 
-      info("Getting the value from ifr...");
-      let value = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr.contentWindow.postMessage("getValue", "*");
-      });
+        info("Getting the value from ifr...");
+        let value = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr.contentWindow.postMessage("getValue", "*");
+        });
 
-      ok(value.startsWith("tracker-"), "The value is correctly set in ifr");
+        ok(value.startsWith("tracker-"), "The value is correctly set in ifr");
 
-      info("Reload...");
-      await new content.Promise(resolve => {
-        ifr.onload = resolve;
-        ifr.contentWindow.postMessage("reload", "*");
-      });
+        info("Reload...");
+        await new content.Promise(resolve => {
+          ifr.onload = resolve;
+          ifr.contentWindow.postMessage("reload", "*");
+        });
 
-      info("Getting the value from ifr...");
-      let value2 = await new Promise(resolve => {
-        content.addEventListener("message", e => {
-          resolve(e.data);
-        }, {once: true});
-        ifr.contentWindow.postMessage("getValue", "*");
-      });
+        info("Getting the value from ifr...");
+        let value2 = await new Promise(resolve => {
+          content.addEventListener("message", e => {
+            resolve(e.data);
+          }, {once: true});
+          ifr.contentWindow.postMessage("getValue", "*");
+        });
+
+        is(value, value2, "The value is equal");
+      }
+    );
 
-      is(value, value2, "The value is undefined");
-    }
-  );
-
-  BrowserTestUtils.removeTab(normalTab);
-});
+    BrowserTestUtils.removeTab(normalTab);
+  });
 
-// Cleanup data.
-add_task(async _ => {
-  await new Promise(resolve => {
-    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
+  // Cleanup data.
+  add_task(async _ => {
+    await new Promise(resolve => {
+      Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
+    });
   });
-});
+}
+
+runAllTests(false, true);
+runAllTests(false, false);
+runAllTests(true, true);
+runAllTests(true, false);