Bug 1525245 - Stabilize cookiePolicy/cookiePermission for live documents - part 10 - Fix existing tests, r=Ehsan
☠☠ backed out by ca64604d4b78 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 07 Mar 2019 10:18:07 +0000
changeset 520730 fb90d51ba85396becf96418b9ead270055130c11
parent 520729 4772db3625b36cbd3a46cfd0822a563692f42374
child 520731 66e19a0c38dd6aa51d551c1ca4daae7de64faf6a
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1525245
milestone67.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 1525245 - Stabilize cookiePolicy/cookiePermission for live documents - part 10 - Fix existing tests, r=Ehsan Differential Revision: https://phabricator.services.mozilla.com/D18958
dom/indexedDB/test/mochitest.ini
dom/indexedDB/test/test_third_party.html
dom/indexedDB/test/third_party_window.html
dom/serviceworkers/test/mochitest.ini
dom/serviceworkers/test/test_third_party_iframes.html
dom/serviceworkers/test/window_party_iframes.html
dom/tests/mochitest/bugs/mochitest.ini
dom/tests/mochitest/bugs/test_bug1171215.html
dom/tests/mochitest/bugs/window_bug1171215.html
dom/tests/mochitest/general/mochitest.ini
dom/tests/mochitest/general/storagePermissionsUtils.js
dom/tests/mochitest/general/test_storagePermissionsAccept.html
dom/tests/mochitest/general/test_storagePermissionsLimitForeign.html
dom/tests/mochitest/general/test_storagePermissionsReject.html
dom/tests/mochitest/general/test_storagePermissionsRejectForeign.html
dom/tests/mochitest/general/window_storagePermissions.html
dom/tests/mochitest/localstorage/frameLocalStorageCookieSettings.html
dom/tests/mochitest/localstorage/mochitest.ini
dom/tests/mochitest/localstorage/test_cookieBlock.html
dom/tests/mochitest/localstorage/test_localStorageCookieSettings.html
dom/tests/mochitest/localstorage/test_localStorageSessionPrefOverride.html
dom/tests/mochitest/localstorage/windowProxy.html
dom/tests/mochitest/sessionstorage/mochitest.ini
dom/tests/mochitest/sessionstorage/test_cookieSession.html
dom/workers/test/mochitest.ini
dom/workers/test/sharedWorker_thirdparty_window.html
dom/workers/test/test_sharedWorker_thirdparty.html
extensions/cookie/test/unit/test_cookies_thirdparty.js
toolkit/components/antitracking/test/browser/browser_storageAccessWithHeuristics.js
--- a/dom/indexedDB/test/mochitest.ini
+++ b/dom/indexedDB/test/mochitest.ini
@@ -11,18 +11,16 @@ support-files =
   blob_worker_crash_iframe.html
   !/dom/events/test/event_leak_utils.js
   error_events_abort_transactions_iframe.html
   event_propagation_iframe.html
   exceptions_in_events_iframe.html
   file.js
   helpers.js
   leaving_page_iframe.html
-  third_party_iframe1.html
-  third_party_iframe2.html
   unit/test_abort_deleted_index.js
   unit/test_abort_deleted_objectStore.js
   unit/test_add_put.js
   unit/test_add_twice_failure.js
   unit/test_advance.js
   unit/test_autoIncrement.js
   unit/test_autoIncrement_indexes.js
   unit/test_blob_file_backed.js
@@ -251,16 +249,20 @@ skip-if = verify
 [test_setVersion_exclusion.html]
 [test_setVersion_throw.html]
 [test_storage_manager_estimate.html]
 scheme=https
 [test_success_events_after_abort.html]
 [test_table_locks.html]
 [test_table_rollback.html]
 [test_third_party.html]
+support-files =
+  third_party_window.html
+  third_party_iframe1.html
+  third_party_iframe2.html
 skip-if = (os == 'android' && debug) # Bug 1311590
 [test_traffic_jam.html]
 [test_transaction_abort.html]
 [test_transaction_abort_hang.html]
 [test_transaction_duplicate_store_names.html]
 [test_transaction_error.html]
 [test_transaction_lifetimes.html]
 [test_transaction_lifetimes_nested.html]
--- a/dom/indexedDB/test/test_third_party.html
+++ b/dom/indexedDB/test/test_third_party.html
@@ -41,66 +41,63 @@
       window.location.pathname.replace("test_third_party.html",
                                        "third_party_iframe1.html");
     const iframe2URL =
       "http://" + window.location.host +
       window.location.pathname.replace("test_third_party.html",
                                        "third_party_iframe2.html");
 
     let testIndex = 0;
-    let testRunning = false;
-
-    function iframeLoaded() {
-      let message = { source: "parent", href: iframe2URL };
-      let iframe = document.getElementById("iframe1");
-      iframe.contentWindow.postMessage(message.toSource(), "*");
-    }
+    let openedWindow;
 
-    function setiframe() {
-      let iframe = document.getElementById("iframe1");
-
-      if (!testRunning) {
-        testRunning = true;
-        iframe.addEventListener("load", iframeLoaded);
-      }
+    // Cookie preference changes are only applied to top-level tabs/windows
+    // when they are loaded. We need a window-proxy to continue the test.
+    function openWindow() {
       SpecialPowers.pushPrefEnv({
         "set": [
           ["network.cookie.cookieBehavior", testData[testIndex].cookieBehavior],
         ],
       }, () => {
-        iframe.src = testData[testIndex].host + iframe1Path;
+        openedWindow = window.open("third_party_window.html");
+        openedWindow.onload = _ => {
+          openedWindow.postMessage({
+            source: "parent",
+            href: iframe2URL,
+            iframeUrl: testData[testIndex].host + iframe1Path,
+          }, "*");
+        };
       });
-      // SpecialPowers.setIntPref("network.cookie.cookieBehavior", testData[testIndex].cookieBehavior);
     }
 
     function messageListener(event) {
       // eslint-disable-next-line no-eval
       let message = eval(event.data);
 
       is(message.source, "iframe", "Good source");
       is(message.result, testData[testIndex].expectedResult, "Good result");
 
+      openedWindow.close();
+
       if (testIndex < testData.length - 1) {
         testIndex++;
-        setiframe();
+        openWindow();
         return;
       }
 
       SimpleTest.finish();
     }
 
     function runTest() {
       SimpleTest.waitForExplicitFinish();
 
       SpecialPowers.addPermission("indexedDB", true, document);
 
       window.addEventListener("message", messageListener);
-      setiframe();
+      openWindow();
     }
   </script>
 
 </head>
 
 <body onload="runTest();">
-  <iframe id="iframe1"></iframe>
 </body>
 
 </html>
new file mode 100644
--- /dev/null
+++ b/dom/indexedDB/test/third_party_window.html
@@ -0,0 +1,33 @@
+<!--
+  Any copyright is dedicated to the Public Domain.
+  http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html>
+<head>
+  <title>Indexed Database Test</title>
+  <script type="text/javascript">
+    let init = false;
+    onmessage = evt => {
+      if (!init) {
+        init = true;
+
+        let iframe = document.getElementById("iframe1");
+        iframe.src = evt.data.iframeUrl;
+
+        iframe.addEventListener("load", e => {
+          iframe.contentWindow.postMessage(evt.data.toSource(), "*");
+        });
+
+        return;
+      }
+
+      opener.postMessage(evt.data, "*");
+    };
+  </script>
+</head>
+
+<body>
+  <iframe id="iframe1"></iframe>
+</body>
+
+</html>
--- a/dom/serviceworkers/test/mochitest.ini
+++ b/dom/serviceworkers/test/mochitest.ini
@@ -303,16 +303,18 @@ skip-if = serviceworker_e10s
 [test_serviceworker.html]
 [test_service_worker_allowed.html]
 [test_serviceworker_header.html]
 [test_serviceworker_interfaces.html]
 [test_serviceworker_not_sharedworker.html]
 [test_skip_waiting.html]
 [test_strict_mode_warning.html]
 [test_third_party_iframes.html]
+support-files =
+  window_party_iframes.html
 [test_unregister.html]
 [test_unresolved_fetch_interception.html]
 skip-if = verify || serviceworker_e10s
 [test_workerUnregister.html]
 [test_workerUpdate.html]
 [test_workerupdatefoundevent.html]
 [test_xslt.html]
 [test_async_waituntil.html]
--- a/dom/serviceworkers/test/test_third_party_iframes.html
+++ b/dom/serviceworkers/test/test_third_party_iframes.html
@@ -6,21 +6,16 @@
 <html>
 <head>
   <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
   <title>Bug 1152899 - Disallow the interception of third-party iframes using service workers when the third-party cookie preference is set</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
-<p id="display"></p>
-<div id="content" style="display: none">
-<iframe></iframe>
-</div>
-<pre id="test"></pre>
 <script class="testbody" type="text/javascript">
 
 SimpleTest.waitForExplicitFinish();
 SimpleTest.requestLongerTimeout(2);
 
 let index = 0;
 function next() {
   info("Step " + index);
@@ -34,16 +29,17 @@ function next() {
   } catch(ex) {
     ok(false, "Caught exception", ex);
   }
 }
 
 onload = next;
 
 let iframe;
+let proxyWindow;
 let basePath = "/tests/dom/serviceworkers/test/thirdparty/";
 let origin = window.location.protocol + "//" + window.location.host;
 let thirdPartyOrigin = "https://example.com";
 
 function testIframeLoaded() {
   ok(true, "Iframe loaded");
   iframe.removeEventListener("load", testIframeLoaded);
   let message = {
@@ -57,32 +53,36 @@ function loadThirdPartyIframe() {
   let message = {
     source: "parent",
     href: thirdPartyOrigin + basePath + "iframe2.html"
   }
   iframe.contentWindow.postMessage(message.toSource(), "*");
 }
 
 function runTest(aExpectedResponses) {
-  iframe = document.querySelector("iframe");
-  iframe.src = thirdPartyOrigin + basePath + "register.html";
-  let responsesIndex = 0;
-  window.onmessage = function(e) {
-    let status = e.data.status;
-    let expected = aExpectedResponses[responsesIndex];
-    if (status == expected.status) {
-      ok(true, "Received expected " + expected.status);
-      if (expected.next) {
-        expected.next();
+  // Let's use a proxy window to have the new cookie policy applied.
+  proxyWindow = window.open("window_party_iframes.html");
+  proxyWindow.onload = _ => {
+    iframe = proxyWindow.document.querySelector("iframe");
+    iframe.src = thirdPartyOrigin + basePath + "register.html";
+    let responsesIndex = 0;
+    window.onmessage = function(e) {
+      let status = e.data.status;
+      let expected = aExpectedResponses[responsesIndex];
+      if (status == expected.status) {
+        ok(true, "Received expected " + expected.status);
+        if (expected.next) {
+          expected.next();
+        }
+      } else {
+        ok(false, "Expected " + expected.status + " got " + status);
       }
-    } else {
-      ok(false, "Expected " + expected.status + " got " + status);
-    }
-    responsesIndex++;
-  };
+      responsesIndex++;
+    };
+  }
 }
 
 // Verify that we can register and intercept a 3rd party iframe with
 // the given cookie policy.
 function testShouldIntercept(behavior, lifetime, done) {
   SpecialPowers.pushPrefEnv({"set": [
       ["network.cookie.cookieBehavior", behavior],
       ["network.cookie.lifetimePolicy", lifetime],
@@ -108,16 +108,17 @@ function testShouldIntercept(behavior, l
         iframe.src = thirdPartyOrigin + basePath + "unregister.html";
       }
     }, {
       status: "controlled",
     }, {
       status: "unregistrationdone",
       next: function() {
         window.onmessage = null;
+        proxyWindow.close();
         ok(true, "Test finished successfully");
         done();
       }
     }]);
   });
 }
 
 // Verify that we cannot register a service worker in a 3rd party
@@ -139,16 +140,17 @@ function testShouldNotRegister(behavior,
       status: "worker-networkresponse",
       next: loadThirdPartyIframe
     }, {
       status: "networkresponse",
     }, {
       status: "worker-networkresponse",
       next: function() {
         window.onmessage = null;
+        proxyWindow.close();
         ok(true, "Test finished successfully");
         done();
       }
     }]);
   });
 }
 
 // Verify that if a service worker is already registered a 3rd
@@ -159,22 +161,27 @@ function testShouldNotIntercept(behavior
     ["network.cookie.cookieBehavior", BEHAVIOR_ACCEPT],
     ["network.cookie.lifetimePolicy", LIFETIME_EXPIRE],
   ]}, function() {
     runTest([{
       status: "ok"
     }, {
       status: "registrationdone",
       next: function() {
-        iframe.addEventListener("load", testIframeLoaded);
         SpecialPowers.pushPrefEnv({"set": [
             ["network.cookie.cookieBehavior", behavior],
             ["network.cookie.lifetimePolicy", lifetime],
           ]}, function() {
-            iframe.src = origin + basePath + "iframe1.html";
+            proxyWindow.close();
+            proxyWindow = window.open("window_party_iframes.html");
+            proxyWindow.onload = _ => {
+              iframe = proxyWindow.document.querySelector("iframe");
+              iframe.addEventListener("load", testIframeLoaded);
+              iframe.src = origin + basePath + "iframe1.html";
+            }
           });
       }
     }, {
       status: "networkresponse",
     }, {
       status: "worker-networkresponse",
       next: loadThirdPartyIframe
     }, {
@@ -188,25 +195,32 @@ function testShouldNotIntercept(behavior
       status: "uncontrolled",
     }, {
       status: "getregistrationfailed",
       next: function() {
         SpecialPowers.pushPrefEnv({"set": [
             ["network.cookie.cookieBehavior", BEHAVIOR_ACCEPT],
             ["network.cookie.lifetimePolicy", LIFETIME_EXPIRE],
           ]}, function() {
-            iframe.src = thirdPartyOrigin + basePath + "unregister.html";
+            proxyWindow.close();
+            proxyWindow = window.open("window_party_iframes.html");
+            proxyWindow.onload = _ => {
+              iframe = proxyWindow.document.querySelector("iframe");
+              iframe.addEventListener("load", testIframeLoaded);
+              iframe.src = thirdPartyOrigin + basePath + "unregister.html";
+            }
           });
       }
     }, {
       status: "controlled",
     }, {
       status: "unregistrationdone",
       next: function() {
         window.onmessage = null;
+        proxyWindow.close();
         ok(true, "Test finished successfully");
         done();
       }
     }]);
   });
 }
 
 const BEHAVIOR_ACCEPT        = 0;
new file mode 100644
--- /dev/null
+++ b/dom/serviceworkers/test/window_party_iframes.html
@@ -0,0 +1,18 @@
+<!--
+  Any copyright is dedicated to the Public Domain.
+  http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
+</head>
+<body>
+<iframe></iframe>
+<script>
+window.onmessage = e => {
+  opener.postMessage(e.data, "*");
+}
+</script>
+</body>
+</html>
--- a/dom/tests/mochitest/bugs/mochitest.ini
+++ b/dom/tests/mochitest/bugs/mochitest.ini
@@ -144,11 +144,12 @@ skip-if = toolkit == 'android' || os == 
 skip-if = toolkit == 'android' #Windows can't change size on Android
 [test_toJSON.html]
 [test_window_bar.html]
 skip-if = toolkit == 'android'
 [test_bug1022869.html]
 [test_bug1112040.html]
 [test_bug1160342_marquee.html]
 [test_bug1171215.html]
+support-files = window_bug1171215.html
 [test_bug1530292.html]
 [test_no_find_showDialog.html]
 skip-if = toolkit == 'android' # Bug 1358633 - window.find doesn't work for Android
--- a/dom/tests/mochitest/bugs/test_bug1171215.html
+++ b/dom/tests/mochitest/bugs/test_bug1171215.html
@@ -4,86 +4,46 @@
 https://bugzilla.mozilla.org/show_bug.cgi?id=1022869
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 1022869</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="/tests/SimpleTest/AddTask.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-  <iframe src="about:blank"></iframe>
   <script type="text/javascript">
 
-  var f = document.getElementsByTagName("iframe")[0];
-
   SimpleTest.waitForExplicitFinish();
 
   /** Test for Bug 1022869 **/
   function startTest() {
     // Initialize our cookie.
     document.cookie = "a=b";
 
-    // Set a cookie in example.org so we can test that we can't read it in
-    // third-party cases.
-    f.contentWindow.location =
-        "http://example.org/tests/dom/tests/mochitest/bugs/file_prime_cookie.html";
-    waitForLoad().then(function() {
-        // Cookies are set up, disallow third-party cookies and start the test.
-        SpecialPowers.pushPrefEnv({ set: [
-            ["network.cookie.cookieBehavior", 1],
-          ]}, () => { continueTest(); });
-    }).catch((e) => { ok(false, `Got exception: ${e}`) });
-  }
-
-  function waitForLoad() {
-    return new Promise((resolve) => {
-      window.addEventListener("message", function(msg) {
-        info(`got message ${msg.data}`);
-        resolve(msg.data);
-      }, {once: true});
-    });
-  }
-
-  async function continueTest() {
-    var sameOrigin = "http://mochi.test:8888";
-    var thirdParty = "http://example.org";
-    var page = "tests/dom/tests/mochitest/bugs/file_cookieOutputter.html"
-    var redirect = "tests/dom/tests/mochitest/bugs/file_redirector.sjs";
+    SpecialPowers.pushPrefEnv({ set: [["network.cookie.cookieBehavior", 1]] }).then(_ => {
+      let w = window.open("window_bug1171215.html");
+      onmessage = e => {
+        if (e.data.type == "finish") {
+          w.close();
+          SimpleTest.finish();
+          return;
+        }
 
-    function createRedirect(firstOrigin, secondOrigin) {
-      return `${firstOrigin}/${redirect}?${secondOrigin}/${page}`;
-    }
-
-    info("starting test");
-
-    // Same origin to same origin.
-    f.contentWindow.location = createRedirect(sameOrigin, sameOrigin);
-    let cookie = await waitForLoad();
-    is(cookie, "a=b", "got the cookie");
+        if (e.data.type == "info") {
+          info(e.data.msg);
+          return;
+        }
 
-    // Cross origin to cross origin.
-    f.contentWindow.location = createRedirect(thirdParty, thirdParty);
-    cookie = await waitForLoad();
-    is(cookie, "", "no third-party cookies");
+        if (e.data.type == "test") {
+          ok(e.data.test, e.data.msg);
+          return;
+        }
 
-    // Same origin to cross origin.
-    f.contentWindow.location = createRedirect(sameOrigin, thirdParty);
-    cookie = await waitForLoad();
-    is(cookie, "", "no third-party cookies");
-
-    // Cross origin to same origin
-    f.contentWindow.location = createRedirect(thirdParty, sameOrigin);
-    cookie = await waitForLoad();
-    is(cookie, "a=b", "got the cookie");
-
-    SimpleTest.finish();
+        ok(false, "Unknown message");
+      };
+    });
   }
   </script>
 </head>
 <body onload="startTest()">
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1022869">Mozilla Bug 1022869</a>
-<p id="display"></p>
-<div id="content" style="display: none">
-</div>
-<pre id="test">
-</pre>
 </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/bugs/window_bug1171215.html
@@ -0,0 +1,86 @@
+<!DOCTYPE html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1022869
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1022869</title>
+  <iframe src="about:blank"></iframe>
+  <script type="text/javascript">
+
+  function finish() {
+    opener.postMessage({type: "finish" });
+  }
+
+  function info(msg) {
+    opener.postMessage({type: "info", msg });
+  }
+
+  function ok(a, msg) {
+    opener.postMessage({type: "test", test: !!a, msg });
+  }
+
+  function is(a, b, msg) {
+    ok(a === b, msg);
+  }
+
+  var f = document.getElementsByTagName("iframe")[0];
+
+  /** Test for Bug 1022869 **/
+  function startTest() {
+    // Set a cookie in example.org so we can test that we can't read it in
+    // third-party cases.
+    f.contentWindow.location =
+        "http://example.org/tests/dom/tests/mochitest/bugs/file_prime_cookie.html";
+    waitForLoad().then(continueTest).catch((e) => { ok(false, `Got exception: ${e}`) });
+  }
+
+  function waitForLoad() {
+    return new Promise((resolve) => {
+      window.addEventListener("message", function(msg) {
+        info(`got message ${msg.data}`);
+        resolve(msg.data);
+      }, {once: true});
+    });
+  }
+
+  async function continueTest() {
+    var sameOrigin = "http://mochi.test:8888";
+    var thirdParty = "http://example.org";
+    var page = "tests/dom/tests/mochitest/bugs/file_cookieOutputter.html"
+    var redirect = "tests/dom/tests/mochitest/bugs/file_redirector.sjs";
+
+    function createRedirect(firstOrigin, secondOrigin) {
+      return `${firstOrigin}/${redirect}?${secondOrigin}/${page}`;
+    }
+
+    info("starting test");
+
+    // Same origin to same origin.
+    f.contentWindow.location = createRedirect(sameOrigin, sameOrigin);
+    let cookie = await waitForLoad();
+    is(cookie, "a=b", "got the cookie");
+
+    // Cross origin to cross origin.
+    f.contentWindow.location = createRedirect(thirdParty, thirdParty);
+    cookie = await waitForLoad();
+    is(cookie, "", "no third-party cookies");
+
+    // Same origin to cross origin.
+    f.contentWindow.location = createRedirect(sameOrigin, thirdParty);
+    cookie = await waitForLoad();
+    is(cookie, "", "no third-party cookies");
+
+    // Cross origin to same origin
+    f.contentWindow.location = createRedirect(thirdParty, sameOrigin);
+    cookie = await waitForLoad();
+    is(cookie, "a=b", "got the cookie");
+
+    finish();
+  }
+  </script>
+</head>
+<body onload="startTest()">
+</body>
+</html>
--- a/dom/tests/mochitest/general/mochitest.ini
+++ b/dom/tests/mochitest/general/mochitest.ini
@@ -45,16 +45,17 @@ support-files =
   test_interfaces.js
   frameStorageAllowed.html
   frameStoragePrevented.html
   frameStorageChrome.html
   frameStorageNullprincipal.sjs
   workerStorageAllowed.js
   workerStoragePrevented.js
   storagePermissionsUtils.js
+  window_storagePermissions.html
   frameSelectEvents.html
   !/image/test/mochitest/big.png
   !/image/test/mochitest/blue.png
   !/image/test/mochitest/clear.png
   !/image/test/mochitest/damon.jpg
   !/image/test/mochitest/over.png
   !/image/test/mochitest/red.png
   !/dom/base/test/Ahem.ttf
--- a/dom/tests/mochitest/general/storagePermissionsUtils.js
+++ b/dom/tests/mochitest/general/storagePermissionsUtils.js
@@ -237,9 +237,38 @@ function task(fn) {
     gen.then(finishTest, e => {
       ok(false, "An error was thrown while stepping: " + e);
       ok(false, "Stack: " + e.stack);
       finishTest();
     });
   }
 }
 
+// The test will run on a separate window in order to apply the new cookie settings.
+async function runTestInWindow(test) {
+  let w = window.open("window_storagePermissions.html");
+  await new Promise(resolve => {
+    w.onload = e => {
+     resolve();
+    }
+  });
+
+  await new Promise(resolve => {
+    onmessage = e => {
+      if (e.data.type == "finish") {
+        w.close();
+        resolve();
+        return;
+      }
+
+      if (e.data.type == "check") {
+        ok(e.data.test, e.data.msg);
+        return;
+      }
+
+      ok(false, "Unknown message");
+    };
+
+    w.postMessage(test.toString(), "*");
+  });
+}
+
 var thirdparty = "https://example.com/tests/dom/tests/mochitest/general/";
--- a/dom/tests/mochitest/general/test_storagePermissionsAccept.html
+++ b/dom/tests/mochitest/general/test_storagePermissionsAccept.html
@@ -9,34 +9,36 @@
   <body>
     <iframe></iframe>
 
     <script type="text/javascript">
 
 task(async function() {
   await setCookieBehavior(BEHAVIOR_ACCEPT);
 
-  // We should be able to access storage
-  await storageAllowed();
+  await runTestInWindow(async function() {
+    // We should be able to access storage
+    await storageAllowed();
 
-  // Same origin iframes should be allowed, unless they redirect to a URI with the null principal
-  await runIFrame("frameStorageAllowed.html");
-  await runIFrame("frameStorageNullprincipal.sjs");
-  await runIFrame("frameStorageChrome.html?allowed=yes");
+    // Same origin iframes should be allowed, unless they redirect to a URI with the null principal
+    await runIFrame("frameStorageAllowed.html");
+    await runIFrame("frameStorageNullprincipal.sjs");
+    await runIFrame("frameStorageChrome.html?allowed=yes");
 
-  // Sandboxed iframes should have the null principal, and thus can't access storage
-  document.querySelector('iframe').setAttribute('sandbox', 'allow-scripts');
-  await runIFrame("frameStoragePrevented.html#nullprincipal");
-  await runIFrame("frameStorageNullprincipal.sjs");
-  document.querySelector('iframe').removeAttribute('sandbox');
+    // Sandboxed iframes should have the null principal, and thus can't access storage
+    document.querySelector('iframe').setAttribute('sandbox', 'allow-scripts');
+    await runIFrame("frameStoragePrevented.html#nullprincipal");
+    await runIFrame("frameStorageNullprincipal.sjs");
+    document.querySelector('iframe').removeAttribute('sandbox');
 
-  // Thirdparty iframes should be allowed, unless they redirect to a URI with the null principal
-  await runIFrame(thirdparty + "frameStorageAllowed.html");
-  await runIFrame(thirdparty + "frameStorageNullprincipal.sjs");
-  await runIFrame(thirdparty + "frameStorageChrome.html?allowed=yes");
+    // Thirdparty iframes should be allowed, unless they redirect to a URI with the null principal
+    await runIFrame(thirdparty + "frameStorageAllowed.html");
+    await runIFrame(thirdparty + "frameStorageNullprincipal.sjs");
+    await runIFrame(thirdparty + "frameStorageChrome.html?allowed=yes");
 
-  // Workers should be able to access storage
-  await runWorker("workerStorageAllowed.js");
+    // Workers should be able to access storage
+    await runWorker("workerStorageAllowed.js");
+  });
 });
 
     </script>
   </body>
 </html>
--- a/dom/tests/mochitest/general/test_storagePermissionsLimitForeign.html
+++ b/dom/tests/mochitest/general/test_storagePermissionsLimitForeign.html
@@ -9,36 +9,38 @@
   <body>
     <iframe></iframe>
 
     <script type="text/javascript">
 
 task(async function() {
   await setCookieBehavior(BEHAVIOR_LIMIT_FOREIGN);
 
-  // We should be able to access storage
-  await storageAllowed();
+  await runTestInWindow(async function() {
+    // We should be able to access storage
+    await storageAllowed();
 
-  // Same origin iframes should be allowed.
-  await runIFrame("frameStorageAllowed.html");
-  await runIFrame("frameStorageChrome.html?allowed=yes");
+    // Same origin iframes should be allowed.
+    await runIFrame("frameStorageAllowed.html");
+    await runIFrame("frameStorageChrome.html?allowed=yes");
 
-  // Null principal iframes should not.
-  await runIFrame("frameStorageNullprincipal.sjs");
+    // Null principal iframes should not.
+    await runIFrame("frameStorageNullprincipal.sjs");
 
-  // Sandboxed iframes should have the null principal, and thus can't access storage
-  document.querySelector('iframe').setAttribute('sandbox', 'allow-scripts');
-  await runIFrame("frameStoragePrevented.html#nullprincipal");
-  await runIFrame("frameStorageNullprincipal.sjs");
-  document.querySelector('iframe').removeAttribute('sandbox');
+    // Sandboxed iframes should have the null principal, and thus can't access storage
+    document.querySelector('iframe').setAttribute('sandbox', 'allow-scripts');
+    await runIFrame("frameStoragePrevented.html#nullprincipal");
+    await runIFrame("frameStorageNullprincipal.sjs");
+    document.querySelector('iframe').removeAttribute('sandbox');
 
-  // Thirdparty iframes should be blocked, even when accessed from chrome over Xrays.
-  await runIFrame(thirdparty + "frameStoragePrevented.html#thirdparty");
-  await runIFrame(thirdparty + "frameStorageNullprincipal.sjs");
-  await runIFrame(thirdparty + "frameStorageChrome.html?allowed=no");
+    // Thirdparty iframes should be blocked, even when accessed from chrome over Xrays.
+    await runIFrame(thirdparty + "frameStoragePrevented.html#thirdparty");
+    await runIFrame(thirdparty + "frameStorageNullprincipal.sjs");
+    await runIFrame(thirdparty + "frameStorageChrome.html?allowed=no");
 
-  // Workers should be unable to access storage
-  await runWorker("workerStorageAllowed.js");
+    // Workers should be unable to access storage
+    await runWorker("workerStorageAllowed.js");
+  });
 });
 
     </script>
   </body>
 </html>
--- a/dom/tests/mochitest/general/test_storagePermissionsReject.html
+++ b/dom/tests/mochitest/general/test_storagePermissionsReject.html
@@ -9,34 +9,36 @@
   <body>
     <iframe></iframe>
 
     <script type="text/javascript">
 
 task(async function() {
   await setCookieBehavior(BEHAVIOR_REJECT);
 
-  // We should be unable to access storage
-  await storagePrevented();
+  await runTestInWindow(async function() {
+    // We should be unable to access storage
+    await storagePrevented();
 
-  // Same origin iframes should be blocked.
-  await runIFrame("frameStoragePrevented.html");
-  await runIFrame("frameStorageNullprincipal.sjs");
-  await runIFrame("frameStorageChrome.html?allowed=no&blockSessionStorage=yes");
+    // Same origin iframes should be blocked.
+    await runIFrame("frameStoragePrevented.html");
+    await runIFrame("frameStorageNullprincipal.sjs");
+    await runIFrame("frameStorageChrome.html?allowed=no&blockSessionStorage=yes");
 
-  // Sandboxed iframes should have the null principal, and thus can't access storage
-  document.querySelector('iframe').setAttribute('sandbox', 'allow-scripts');
-  await runIFrame("frameStoragePrevented.html#nullprincipal");
-  await runIFrame("frameStorageNullprincipal.sjs");
-  document.querySelector('iframe').removeAttribute('sandbox');
+    // Sandboxed iframes should have the null principal, and thus can't access storage
+    document.querySelector('iframe').setAttribute('sandbox', 'allow-scripts');
+    await runIFrame("frameStoragePrevented.html#nullprincipal");
+    await runIFrame("frameStorageNullprincipal.sjs");
+    document.querySelector('iframe').removeAttribute('sandbox');
 
-  // thirdparty iframes should be blocked.
-  await runIFrame(thirdparty + "frameStoragePrevented.html");
-  await runIFrame(thirdparty + "frameStorageNullprincipal.sjs");
-  await runIFrame(thirdparty + "frameStorageChrome.html?allowed=no&blockSessionStorage=yes");
+    // thirdparty iframes should be blocked.
+    await runIFrame(thirdparty + "frameStoragePrevented.html");
+    await runIFrame(thirdparty + "frameStorageNullprincipal.sjs");
+    await runIFrame(thirdparty + "frameStorageChrome.html?allowed=no&blockSessionStorage=yes");
 
-  // Workers should be unable to access storage
-  await runWorker("workerStoragePrevented.js");
+    // Workers should be unable to access storage
+    await runWorker("workerStoragePrevented.js");
+  });
 });
 
     </script>
   </body>
 </html>
--- a/dom/tests/mochitest/general/test_storagePermissionsRejectForeign.html
+++ b/dom/tests/mochitest/general/test_storagePermissionsRejectForeign.html
@@ -9,34 +9,36 @@
   <body>
     <iframe></iframe>
 
     <script type="text/javascript">
 
 task(async function() {
   await setCookieBehavior(BEHAVIOR_REJECT_FOREIGN);
 
-  // We should be able to access storage
-  await storageAllowed();
+  await runTestInWindow(async function() {
+    // We should be able to access storage
+    await storageAllowed();
 
-  // Same origin iframes should be allowed, unless they redirect to a URI with the null principal
-  await runIFrame("frameStorageAllowed.html");
-  await runIFrame("frameStorageNullprincipal.sjs");
-  await runIFrame("frameStorageChrome.html?allowed=yes");
+    // Same origin iframes should be allowed, unless they redirect to a URI with the null principal
+    await runIFrame("frameStorageAllowed.html");
+    await runIFrame("frameStorageNullprincipal.sjs");
+    await runIFrame("frameStorageChrome.html?allowed=yes");
 
-  // Sandboxed iframes should have the null principal, and thus can't access storage
-  document.querySelector('iframe').setAttribute('sandbox', 'allow-scripts');
-  await runIFrame("frameStoragePrevented.html#nullprincipal");
-  await runIFrame("frameStorageNullprincipal.sjs");
-  document.querySelector('iframe').removeAttribute('sandbox');
+    // Sandboxed iframes should have the null principal, and thus can't access storage
+    document.querySelector('iframe').setAttribute('sandbox', 'allow-scripts');
+    await runIFrame("frameStoragePrevented.html#nullprincipal");
+    await runIFrame("frameStorageNullprincipal.sjs");
+    document.querySelector('iframe').removeAttribute('sandbox');
 
-  // thirdparty iframes should be blocked.
-  await runIFrame(thirdparty + "frameStoragePrevented.html#thirdparty");
-  await runIFrame(thirdparty + "frameStorageNullprincipal.sjs");
-  await runIFrame(thirdparty + "frameStorageChrome.html?allowed=no");
+    // thirdparty iframes should be blocked.
+    await runIFrame(thirdparty + "frameStoragePrevented.html#thirdparty");
+    await runIFrame(thirdparty + "frameStorageNullprincipal.sjs");
+    await runIFrame(thirdparty + "frameStorageChrome.html?allowed=no");
 
-  // Workers should be able to access storage
-  await runWorker("workerStorageAllowed.js");
+    // Workers should be able to access storage
+    await runWorker("workerStorageAllowed.js");
+  });
 });
 
     </script>
   </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/general/window_storagePermissions.html
@@ -0,0 +1,38 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <title>Storage Permission Restrictions</title>
+    <script type="text/javascript" src="storagePermissionsUtils.js"></script>
+  </head>
+  <body>
+    <iframe></iframe>
+
+    <script type="text/javascript">
+
+function ok(a, msg) {
+  opener.postMessage({type: "check", test: !!a, msg }, "*");
+}
+
+function is(a, b, msg) {
+  ok(a === b , msg);
+}
+
+let init = false;
+onmessage = e => {
+  if (!init) {
+    init = true;
+
+    let runnableStr = `(() => {return (${e.data});})();`;
+    let runnable = eval(runnableStr); // eslint-disable-line no-eval
+    runnable.call(this).then(_ => {
+      opener.postMessage({ type: "finish" }, "*");
+    });
+
+    return;
+  }
+
+  parent.postMessage(e.data, "*");
+}
+
+    </script>
+  </body>
+</html>
--- a/dom/tests/mochitest/localstorage/frameLocalStorageCookieSettings.html
+++ b/dom/tests/mochitest/localstorage/frameLocalStorageCookieSettings.html
@@ -1,20 +1,16 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <title>localStorage cookies settings test</title>
 
-<script type="text/javascript" src="interOriginFrame.js"></script>
-
 </head>
 <body>
 <script type="text/javascript">
   try {
     localStorage.setItem("contentkey", "test-value");
     ok(false, "Setting localStorageItem should throw a type error exception");
   } catch(ex) {
     is(ex.name, "TypeError");
   }
-
-  finishTest();
 </script>
 </body>
 </html>
--- a/dom/tests/mochitest/localstorage/mochitest.ini
+++ b/dom/tests/mochitest/localstorage/mochitest.ini
@@ -12,16 +12,17 @@ support-files =
   frameSlaveEqual.html
   frameSlaveNotEqual.html
   interOriginFrame.js
   interOriginTest.js
   interOriginTest2.js
   localStorageCommon.js
   frameLocalStorageSessionOnly.html
   file_tryAccessSessionStorage.html
+  windowProxy.html
 
 [test_brokenUTF-16.html]
 [test_bug600307-DBOps.html]
 [test_bug746272-1.html]
 [test_bug746272-2.html]
 skip-if = os == "android" || verify # bug 962029
 [test_cookieBlock.html]
 [test_embededNulls.html]
@@ -43,9 +44,8 @@ skip-if = toolkit == 'android' #TIMED_OU
 skip-if = toolkit == 'android' #TIMED_OUT
 [test_localStorageQuotaSessionOnly.html]
 skip-if = toolkit == 'android' || (verify && (os == 'linux' || os == 'mac' || os == 'win')) #TIMED_OUT
 [test_localStorageQuotaSessionOnly2.html]
 skip-if = true # bug 1347690
 [test_localStorageReplace.html]
 skip-if = toolkit == 'android'
 [test_storageConstructor.html]
-[test_localStorageSessionPrefOverride.html]
--- a/dom/tests/mochitest/localstorage/test_cookieBlock.html
+++ b/dom/tests/mochitest/localstorage/test_cookieBlock.html
@@ -4,33 +4,38 @@
 
 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 
 <script type="text/javascript">
 
 function startTest()
 {
-  try {
-    localStorage.setItem("blocked", "blockedvalue");
-    ok(false, "Exception for localStorage.setItem, ACCESS_DENY");
-  }
-  catch (ex) {
-    ok(true, "Exception for localStorage.setItem, ACCESS_DENY");
-  }
+  // Let's use a new window to have the cookie permission applied.
+  let w = window.open("windowProxy.html");
+  w.onload = _ => {
+    try {
+      w.localStorage.setItem("blocked", "blockedvalue");
+      ok(false, "Exception for localStorage.setItem, ACCESS_DENY");
+    }
+    catch (ex) {
+      ok(true, "Exception for localStorage.setItem, ACCESS_DENY");
+    }
 
-  try {
-    localStorage.getItem("blocked");
-    ok(false, "Exception for localStorage.getItem, ACCESS_DENY");
+    try {
+      w.localStorage.getItem("blocked");
+      ok(false, "Exception for localStorage.getItem, ACCESS_DENY");
+    }
+    catch (ex) {
+      ok(true, "Exception for localStorage.getItem, ACCESS_DENY");
+    }
+
+    w.close();
+    SimpleTest.finish();
   }
-  catch (ex) {
-    ok(true, "Exception for localStorage.getItem, ACCESS_DENY");
-  }
-
-  SimpleTest.finish();
 }
 
 SimpleTest.waitForExplicitFinish();
 
 // Initialize storage before setting the cookie, otherwise we won't be testing
 // the checks in setItem/getItem methods.
 var storage = localStorage;
 
--- a/dom/tests/mochitest/localstorage/test_localStorageCookieSettings.html
+++ b/dom/tests/mochitest/localstorage/test_localStorageCookieSettings.html
@@ -3,58 +3,65 @@
 <title>localStorage cookies settings test</title>
 
 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
 <script type="text/javascript" src="interOriginTest.js"></script>
 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 
 </head>
 <body>
-<iframe></iframe>
 
 <script type="text/javascript">
 
 SimpleTest.waitForExplicitFinish();
 
 // Set cookies behavior to "always reject".
 SpecialPowers.pushPrefEnv({"set": [
   ["network.cookie.cookieBehavior", 2],
 ]}, test1);
 
 function test1() {
-  try {
-    localStorage.setItem("contentkey", "test-value");
-    ok(false, "Setting localStorageItem should throw a type error exception");
+  let w = window.open("windowProxy.html");
+  w.onload = _ => {
+    try {
+      w.localStorage.setItem("contentkey", "test-value");
+      ok(false, "Setting localStorageItem should throw a security exception");
+    }
+    catch(ex) {
+      is(ex.name, "TypeError");
+    }
+
+    w.close();
+
+    // Set cookies behavior to "reject 3rd party"
+    SpecialPowers.pushPrefEnv({"set": [["network.cookie.cookieBehavior", 1]],
+                               "clear": [["network.cookie.lifetimePolicy"]]},
+                              test2);
   }
-  catch(ex) {
-    is(ex.name, "TypeError");
-  }
-
-  // Set cookies behavior to "reject 3rd party"
-  SpecialPowers.pushPrefEnv({"set": [["network.cookie.cookieBehavior", 1]],
-                             "clear": [["network.cookie.lifetimePolicy"]]},
-                            test3);
 }
 
-function test3() {
-  try {
-    localStorage.setItem("contentkey", "test-value");
-    ok(true, "Setting localStorageItem should not throw a type error exception");
-  }
-  catch(ex) {
-    ok(false, "Setting localStorageItem should not throw a type error exception");
-  }
+function test2() {
+  let w = window.open("windowProxy.html");
+  w.onload = _ => {
+    try {
+      w.localStorage.setItem("contentkey", "test-value");
+      ok(true, "Setting localStorageItem should not throw a security exception");
+    }
+    catch(ex) {
+      ok(false, "Setting localStorageItem should not throw a security exception");
+    }
 
-  var fileTest = (location.protocol + "//example.com" + location.pathname)
-                 .replace("test_l", "frameL");
+    var fileTest = (location.protocol + "//example.com" + location.pathname)
+                   .replace("test_l", "frameL");
 
-  var myframe = document.querySelector("iframe");
-  myframe.src = fileTest;
-}
-
-// Called by interOriginTest.js
-function doNextTest() {
-  SimpleTest.finish();
+    var myframe = w.document.createElement("iframe");
+    w.document.body.appendChild(myframe);
+    myframe.src = fileTest;
+    myframe.onload = _ => {
+      w.close();
+      SimpleTest.finish();
+    }
+  }
 }
 
 </script>
 </body>
 </html>
deleted file mode 100644
--- a/dom/tests/mochitest/localstorage/test_localStorageSessionPrefOverride.html
+++ /dev/null
@@ -1,56 +0,0 @@
-<html>
-  <head>
-    <title>Local Storage Session Pref Override</title>
-    <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-    <script type="text/javascript" src="/tests/SimpleTest/AddTask.js"></script>
-    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-    <script>
-      const ACCEPT_SESSION = 2;
-
-      add_task(async function() {
-        if (SpecialPowers.Services.lsm.nextGenLocalStorageEnabled) {
-          ok(true, "Test ignored when the next gen local storage is enabled.");
-          return;
-        }
-
-        await SpecialPowers.pushPrefEnv({"set": [["network.cookie.lifetimePolicy",
-                                                  ACCEPT_SESSION]]});
-
-        // Before setting permission
-        await new Promise((resolve) => {
-          var frame = document.createElement('iframe');
-          frame.src = "frameLocalStorageSessionOnly.html";
-
-          var listener = (e) => {
-            is(e.data, true, "Before adding permission should be session only");
-            window.removeEventListener('message', listener);
-            resolve();
-          };
-          window.addEventListener('message', listener);
-          document.body.appendChild(frame);
-        });
-
-        // After setting permission
-        await new Promise((resolve) => {
-          SpecialPowers.pushPermissions([{"type": "cookie", "allow": 1, "context": document}],
-                                        resolve);
-        });
-
-        await new Promise((resolve) => {
-          var frame = document.createElement('iframe');
-          frame.src = "frameLocalStorageSessionOnly.html";
-
-          var listener = (e) => {
-            is(e.data, false, "After adding permission should not be session only");
-            window.removeEventListener('message', listener);
-            resolve();
-          };
-          window.addEventListener('message', listener);
-          document.body.appendChild(frame);
-        });
-      });
-    </script>
-  </head>
-  <body>
-  </body>
-</html>
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/localstorage/windowProxy.html
@@ -0,0 +1,3 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<body></body>
+</html>
--- a/dom/tests/mochitest/sessionstorage/mochitest.ini
+++ b/dom/tests/mochitest/sessionstorage/mochitest.ini
@@ -3,17 +3,16 @@ support-files =
   file_http.html
   file_https.html
   frameEqual.html
   frameNotEqual.html
   frameReplace.html
   interOriginSlave.js
   interOriginTest.js
 
-[test_cookieSession.html]
 [test_sessionStorageBase.html]
 [test_sessionStorageBaseSessionOnly.html]
 [test_sessionStorageClone.html]
 skip-if = toolkit == 'android'
 [test_sessionStorageHttpHttps.html]
 skip-if = toolkit == 'android' #TIMED_OUT
 [test_sessionStorageReplace.html]
 [test_sessionStorageUsage.html]
deleted file mode 100644
--- a/dom/tests/mochitest/sessionstorage/test_cookieSession.html
+++ /dev/null
@@ -1,124 +0,0 @@
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<title>cookie per-session only test</title>
-
-<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-
-<script type="text/javascript">
-
-/*
-  Set cookie access to be just per session and store to the sessionStorage.
-  Content stored must prevail only for session of the browser, so it must
-  be accessible in another window we try to access that key in the same
-  storage.
- */
-
-function pushCookie(aValue, aNext) {
-  SpecialPowers.pushPermissions([{'type': 'cookie', 'allow': aValue, 'context': document}], pushPermissionAndTest);
-}
-
-function pushPermissionAndTest() {
-  var test = tests.shift();
-  if (test) {
-    document.getElementById('testframe').onload = test;
-    /* After every permission change, an iframe has to be reloaded,
-       otherwise this test causes failures in b2g (oop) mochitest, because
-       the permission changes don't seem to be always picked up
-       by the code that excercises it */
-    document.getElementById('testframe').contentWindow.location.reload();
-  } else {
-    ok(false, 'should not be reached');
-    SimpleTest.finish();
-  }
-}
-
-function startTest() {
-  pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT);
-}
-
-var tests = [
-  function test1() {
-    sessionStorage.setItem("persistent1", "persistent value 1");
-    sessionStorage.setItem("persistent2", "persistent value 2");
-
-    pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION);
-  },
-
-  function test2() {
-    sessionStorage.setItem("session only", "session value");
-    is(sessionStorage.getItem("session only"), "session value", "Value present when cookies in session-only mode");
-    is(sessionStorage.getItem("persistent1"), "persistent value 1", "Persistent value present");
-    is(sessionStorage.getItem("persistent2"), "persistent value 2", "Persistent value present");
-
-    sessionStorage.setItem("persistent1", "changed persistent value 1");
-    sessionStorage.removeItem("persistent2");
-
-    is(sessionStorage.getItem("session only"), "session value", "Value present when cookies in session-only mode");
-    is(sessionStorage.getItem("persistent1"), "changed persistent value 1", "Persistent value present");
-    is(sessionStorage.getItem("persistent2"), null, "Persistent value removed");
-
-    // This clear has to delete only changes made in session only mode
-    sessionStorage.clear();
-
-    is(sessionStorage.getItem("session only"), null, "Value not present when cookies in session-only mode after delete");
-    is(sessionStorage.getItem("persistent1"), null, "Persistent value not present in session only after delete");
-    is(sessionStorage.getItem("persistent2"), null, "Persistent value not present in session only after delete");
-
-    sessionStorage.setItem("session only 2", "must be deleted on drop of session-only cookies permissions");
-
-    pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT);
-  },
-
-  function test3() {
-    is(sessionStorage.getItem("session only"), null, "No value when cookies are in default mode");
-    is(sessionStorage.getItem("session only 2"), null, "No value when cookies are in default mode");
-    is(sessionStorage.getItem("persistent1"), "persistent value 1", "Persistent value present");
-    is(sessionStorage.getItem("persistent2"), "persistent value 2", "Persistent value present");
-
-    pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION);
-  },
-
-  function test4() {
-    is(sessionStorage.getItem("session only"), null, "Value not present when cookies in session-only mode after delete");
-    is(sessionStorage.getItem("session only 2"), null, "Value not present when cookies in session-only mode after delete");
-    is(sessionStorage.getItem("persistent1"), "persistent value 1", "Persistent value present again");
-    is(sessionStorage.getItem("persistent2"), "persistent value 2", "Persistent value present again");
-
-    pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT);
-  },
-
-  function test5() {
-    sessionStorage.clear();
-
-    is(sessionStorage.getItem("session only"), null, "No value when cookies are in default mode");
-    is(sessionStorage.getItem("persistent1"), null, "Persistent value not present after delete");
-    is(sessionStorage.getItem("persistent2"), null, "Persistent value not present after delete");
-
-    pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION);
-  },
-
-  function test6() {
-    is(sessionStorage.getItem("session only"), null, "Value not present when cookies in session-only mode after delete");
-    is(sessionStorage.getItem("session only 2"), null, "No value when cookies are in default mode");
-    is(sessionStorage.getItem("persistent1"), null, "Persistent value not present in session only after delete");
-    is(sessionStorage.getItem("persistent2"), null, "Persistent value not present in session only after delete");
-
-    pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT);
-  },
-
-  function test7() {
-    SimpleTest.finish();
-  }
-];
-
-SimpleTest.waitForExplicitFinish();
-
-</script>
-
-</head>
-
-<body onload="startTest();">
-<iframe id="testframe" srcdoc="<meta charset=utf-8>"></iframe>
-</body>
-</html>
--- a/dom/workers/test/mochitest.ini
+++ b/dom/workers/test/mochitest.ini
@@ -50,17 +50,16 @@ support-files =
   onLine_worker_child.js
   onLine_worker_head.js
   promise_worker.js
   recursion_worker.js
   recursiveOnerror_worker.js
   redirect_to_foreign.sjs
   rvals_worker.js
   sharedWorker_sharedWorker.js
-  sharedWorker_thirdparty_frame.html
   simpleThread_worker.js
   suspend_window.html
   suspend_worker.js
   terminate_worker.js
   test_csp.html^headers^
   test_csp.js
   referrer_worker.html
   threadErrors_worker1.js
@@ -168,16 +167,19 @@ skip-if = toolkit == 'android'
 [test_promise_resolved_with_string.html]
 [test_recursion.html]
 [test_recursiveOnerror.html]
 [test_resolveWorker.html]
 [test_resolveWorker-assignment.html]
 [test_rvals.html]
 [test_sharedWorker.html]
 [test_sharedWorker_thirdparty.html]
+support-files =
+  sharedWorker_thirdparty_frame.html
+  sharedWorker_thirdparty_window.html
 [test_simpleThread.html]
 [test_suspend.html]
 [test_terminate.html]
 [test_threadErrors.html]
 [test_threadTimeouts.html]
 [test_throwingOnerror.html]
 [test_timeoutTracing.html]
 [test_transferable.html]
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/sharedWorker_thirdparty_window.html
@@ -0,0 +1,26 @@
+<!--
+  Any copyright is dedicated to the Public Domain.
+  http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for SharedWorker in 3rd Party Iframes</title>
+</head>
+<body>
+  <script>
+
+  let url = new URL(window.location);
+
+  let frame = document.createElement('iframe');
+  frame.src =
+    'http://example.org/tests/dom/workers/test/sharedWorker_thirdparty_frame.html?name=' + url.searchParams.get('name');
+  document.body.appendChild(frame);
+  window.addEventListener('message', evt => {
+    frame.remove();
+    opener.postMessage(evt.data, "*");
+  }, {once: true});
+
+  </script>
+</body>
+</html>
--- a/dom/workers/test/test_sharedWorker_thirdparty.html
+++ b/dom/workers/test/test_sharedWorker_thirdparty.html
@@ -6,32 +6,28 @@
 <html>
 <head>
   <title>Test for SharedWorker in 3rd Party Iframes</title>
   <script src="/tests/SimpleTest/SimpleTest.js"> </script>
   <script src="/tests/SimpleTest/AddTask.js"> </script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
 </head>
 <body>
-  <p id="display"></p>
-  <div id="content" style="display: none"></div>
-  <pre id="test">
   <script class="testbody">
 
   function testThirdPartyFrame(name) {
     return new Promise(resolve => {
-      let frame = document.createElement('iframe');
-      frame.src =
-        'http://example.org/tests/dom/workers/test/sharedWorker_thirdparty_frame.html?name=' + name;
-      document.body.appendChild(frame);
+      // Let's use a window, loading the same origin, in order to have the new
+      // cookie-policy applied.
+      let w = window.open("sharedWorker_thirdparty_window.html?name=" + name);
       window.addEventListener('message', function messageListener(evt) {
         if (evt.data.name !== name) {
           return;
         }
-        frame.remove();
+        w.close();
         window.removeEventListener('message', messageListener);
         resolve(evt.data.result);
       });
     });
   }
 
   const COOKIE_BEHAVIOR_ACCEPT        = 0;
   const COOKIE_BEHAVIOR_REJECTFOREIGN = 1;
@@ -50,11 +46,10 @@
       ["network.cookie.cookieBehavior", COOKIE_BEHAVIOR_REJECTFOREIGN]
     ]});
     let result = await testThirdPartyFrame('blocked');
     ok(result === 'blocked',
        'SharedWorker should not be allowed when 3rd party iframes are denied storage');
   });
 
   </script>
-  </pre>
 </body>
 </html>
--- a/extensions/cookie/test/unit/test_cookies_thirdparty.js
+++ b/extensions/cookie/test/unit/test_cookies_thirdparty.js
@@ -1,62 +1,104 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // test third party cookie blocking, for the cases:
 // 1) with null channel
 // 2) with channel, but with no docshell parent
 
 function run_test() {
+  Services.prefs.setBoolPref("network.cookieSettings.unblocked_for_testing", true);
+
   // Create URIs and channels pointing to foo.com and bar.com.
   // We will use these to put foo.com into first and third party contexts.
-  var spec1 = "http://foo.com/foo.html";
-  var spec2 = "http://bar.com/bar.html";
-  var uri1 = NetUtil.newURI(spec1);
-  var uri2 = NetUtil.newURI(spec2);
-  var channel1 = NetUtil.newChannel({uri: uri1, loadUsingSystemPrincipal: true});
-  var channel2 = NetUtil.newChannel({uri: uri2, loadUsingSystemPrincipal: true});
+  let spec1 = "http://foo.com/foo.html";
+  let spec2 = "http://bar.com/bar.html";
+  let uri1 = NetUtil.newURI(spec1);
+  let uri2 = NetUtil.newURI(spec2);
+
+    // test with cookies enabled
+  {
+    Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
 
-  // test with cookies enabled
-  Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
-  do_set_cookies(uri1, channel1, true, [1, 2, 3, 4]);
-  Services.cookies.removeAll();
-  do_set_cookies(uri1, channel2, true, [1, 2, 3, 4]);
-  Services.cookies.removeAll();
+    let channel1 = NetUtil.newChannel({uri: uri1, loadUsingSystemPrincipal: true});
+    let channel2 = NetUtil.newChannel({uri: uri2, loadUsingSystemPrincipal: true});
+
+    do_set_cookies(uri1, channel1, true, [1, 2, 3, 4]);
+    Services.cookies.removeAll();
+    do_set_cookies(uri1, channel2, true, [1, 2, 3, 4]);
+    Services.cookies.removeAll();
+  }
 
   // test with third party cookies blocked
-  Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
-  do_set_cookies(uri1, channel1, true, [0, 0, 0, 0]);
-  Services.cookies.removeAll();
-  do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
-  Services.cookies.removeAll();
+  {
+    Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
+
+    let channel1 = NetUtil.newChannel({uri: uri1, loadUsingSystemPrincipal: true});
+    let channel2 = NetUtil.newChannel({uri: uri2, loadUsingSystemPrincipal: true});
+
+    do_set_cookies(uri1, channel1, true, [0, 0, 0, 0]);
+    Services.cookies.removeAll();
+    do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
+    Services.cookies.removeAll();
+  }
 
   // Force the channel URI to be used when determining the originating URI of
   // the channel.
-  var httpchannel1 = channel1.QueryInterface(Ci.nsIHttpChannelInternal);
-  var httpchannel2 = channel2.QueryInterface(Ci.nsIHttpChannelInternal);
-  httpchannel1.forceAllowThirdPartyCookie = true;
-  httpchannel2.forceAllowThirdPartyCookie = true;
+  // test with third party cookies blocked
 
   // test with cookies enabled
-  Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
-  do_set_cookies(uri1, channel1, true, [1, 2, 3, 4]);
-  Services.cookies.removeAll();
-  do_set_cookies(uri1, channel2, true, [1, 2, 3, 4]);
-  Services.cookies.removeAll();
+  {
+    Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
+
+    let channel1 = NetUtil.newChannel({uri: uri1, loadUsingSystemPrincipal: true});
+    let httpchannel1 = channel1.QueryInterface(Ci.nsIHttpChannelInternal);
+    httpchannel1.forceAllowThirdPartyCookie = true;
+
+    let channel2 = NetUtil.newChannel({uri: uri2, loadUsingSystemPrincipal: true});
+    let httpchannel2 = channel2.QueryInterface(Ci.nsIHttpChannelInternal);
+    httpchannel2.forceAllowThirdPartyCookie = true;
+
+    do_set_cookies(uri1, channel1, true, [1, 2, 3, 4]);
+    Services.cookies.removeAll();
+    do_set_cookies(uri1, channel2, true, [1, 2, 3, 4]);
+    Services.cookies.removeAll();
+  }
 
   // test with third party cookies blocked
-  Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
-  do_set_cookies(uri1, channel1, true, [0, 1, 1, 2]);
-  Services.cookies.removeAll();
-  do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
-  Services.cookies.removeAll();
+  {
+    Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
+
+    let channel1 = NetUtil.newChannel({uri: uri1, loadUsingSystemPrincipal: true});
+    let httpchannel1 = channel1.QueryInterface(Ci.nsIHttpChannelInternal);
+    httpchannel1.forceAllowThirdPartyCookie = true;
+
+    let channel2 = NetUtil.newChannel({uri: uri2, loadUsingSystemPrincipal: true});
+    let httpchannel2 = channel2.QueryInterface(Ci.nsIHttpChannelInternal);
+    httpchannel2.forceAllowThirdPartyCookie = true;
+
+    do_set_cookies(uri1, channel1, true, [0, 1, 1, 2]);
+    Services.cookies.removeAll();
+    do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
+    Services.cookies.removeAll();
+  }
 
   // test with third party cookies limited
-  Services.prefs.setIntPref("network.cookie.cookieBehavior", 3);
-  do_set_cookies(uri1, channel1, true, [0, 1, 2, 3]);
-  Services.cookies.removeAll();
-  do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
-  Services.cookies.removeAll();
-  do_set_single_http_cookie(uri1, channel1, 1);
-  do_set_cookies(uri1, channel2, true, [2, 3, 4, 5]);
-  Services.cookies.removeAll();
+  {
+    Services.prefs.setIntPref("network.cookie.cookieBehavior", 3);
+
+    let channel1 = NetUtil.newChannel({uri: uri1, loadUsingSystemPrincipal: true});
+    let httpchannel1 = channel1.QueryInterface(Ci.nsIHttpChannelInternal);
+    httpchannel1.forceAllowThirdPartyCookie = true;
+
+    let channel2 = NetUtil.newChannel({uri: uri2, loadUsingSystemPrincipal: true});
+    let httpchannel2 = channel2.QueryInterface(Ci.nsIHttpChannelInternal);
+    httpchannel2.forceAllowThirdPartyCookie = true;
+
+    do_set_cookies(uri1, channel1, true, [0, 1, 2, 3]);
+    Services.cookies.removeAll();
+    do_set_cookies(uri1, channel2, true, [0, 0, 0, 0]);
+    Services.cookies.removeAll();
+    do_set_single_http_cookie(uri1, channel1, 1);
+    do_set_cookies(uri1, channel2, true, [2, 3, 4, 5]);
+    Services.cookies.removeAll();
+  }
 }
--- a/toolkit/components/antitracking/test/browser/browser_storageAccessWithHeuristics.js
+++ b/toolkit/components/antitracking/test/browser/browser_storageAccessWithHeuristics.js
@@ -262,53 +262,16 @@ add_task(async function testUserInteract
         }
 
         ok(false, "Unknown message");
       });
       ifr.contentWindow.postMessage({ callback: msg.nonBlockingCallback }, "*");
     });
   });
 
-  info("Now ensure that the storage access is removed if the cookie policy is changed.");
-  await SpecialPowers.pushPrefEnv({"set": [
-    ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT],
-  ]});
-  await ContentTask.spawn(browser, {}, async obj => {
-    await new content.Promise(resolve => {
-      let ifr = content.document.querySelectorAll("iframe");
-      ifr = ifr[ifr.length - 1];
-
-      let msg = {};
-      msg.blockingCallback = (async _ => {
-        await noStorageAccessInitially();
-      }).toString();
-
-      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: msg.blockingCallback }, "*");
-    });
-  });
-
   info("Removing the tab");
   BrowserTestUtils.removeTab(tab);
 });
 
 add_task(async function() {
   info("Cleaning up.");
   await new Promise(resolve => {
     Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());