Bug 1494476 - Part 2: Refactor calls to the storage access API into a helper script file r=baku
☠☠ backed out by 68f1999b78a1 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 10 Oct 2018 14:50:37 +0000
changeset 498984 3c38fad722a64d3aef996f70faffcc1ccd96dbfc
parent 498983 47336225032067d3fa8d5bf1af22c3809eaa2143
child 498985 f89516a277dcd86555f8334cce9bb1ea9bc47e24
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1494476
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1494476 - Part 2: Refactor calls to the storage access API into a helper script file r=baku Depends on D8155 Differential Revision: https://phabricator.services.mozilla.com/D8156
toolkit/components/antitracking/test/browser/3rdParty.html
toolkit/components/antitracking/test/browser/3rdPartyUI.html
toolkit/components/antitracking/test/browser/3rdPartyWO.html
toolkit/components/antitracking/test/browser/browser.ini
toolkit/components/antitracking/test/browser/browser_blockingCookies.js
toolkit/components/antitracking/test/browser/browser_blockingIndexedDb.js
toolkit/components/antitracking/test/browser/browser_blockingLocalStorage.js
toolkit/components/antitracking/test/browser/browser_blockingMessaging.js
toolkit/components/antitracking/test/browser/browser_blockingSessionStorage.js
toolkit/components/antitracking/test/browser/browser_blockingWorkers.js
toolkit/components/antitracking/test/browser/browser_storageAccessPrivateWindow.js
toolkit/components/antitracking/test/browser/browser_storageAccessPromiseResolveHandlerUserInteraction.js
toolkit/components/antitracking/test/browser/browser_storageAccessSandboxed.js
toolkit/components/antitracking/test/browser/browser_storageAccessWithHeuristics.js
toolkit/components/antitracking/test/browser/head.js
toolkit/components/antitracking/test/browser/storageAccessAPIHelpers.js
--- a/toolkit/components/antitracking/test/browser/3rdParty.html
+++ b/toolkit/components/antitracking/test/browser/3rdParty.html
@@ -1,11 +1,12 @@
 <html>
 <head>
   <title>3rd party content!</title>
+  <script type="text/javascript" src="https://example.com/browser/toolkit/components/antitracking/test/browser/storageAccessAPIHelpers.js"></script>
 </head>
 <body>
 <h1>Here the 3rd party content!</h1>
 <script>
 
 function info(msg) {
   parent.postMessage({ type: "info", msg }, "*");
 }
--- a/toolkit/components/antitracking/test/browser/3rdPartyUI.html
+++ b/toolkit/components/antitracking/test/browser/3rdPartyUI.html
@@ -1,11 +1,12 @@
 <html>
 <head>
   <title>Tracker</title>
+  <script type="text/javascript" src="https://example.com/browser/toolkit/components/antitracking/test/browser/storageAccessAPIHelpers.js"></script>
 </head>
 <body>
 <h1>Tracker</h1>
 <script>
 
 function info(msg) {
   parent.postMessage({ type: "info", msg }, "*");
 }
--- a/toolkit/components/antitracking/test/browser/3rdPartyWO.html
+++ b/toolkit/components/antitracking/test/browser/3rdPartyWO.html
@@ -1,11 +1,12 @@
 <html>
 <head>
   <title>Interact with me!</title>
+  <script type="text/javascript" src="https://example.com/browser/toolkit/components/antitracking/test/browser/storageAccessAPIHelpers.js"></script>
 </head>
 <body>
 <h1>Interact with me!</h1>
 <script>
 
 function info(msg) {
   parent.postMessage({ type: "info", msg }, "*");
 }
--- a/toolkit/components/antitracking/test/browser/browser.ini
+++ b/toolkit/components/antitracking/test/browser/browser.ini
@@ -8,16 +8,17 @@ support-files =
   3rdParty.html
   3rdPartySVG.html
   3rdPartyUI.html
   3rdPartyWO.html
   3rdPartyOpen.html
   3rdPartyOpenUI.html
   empty.js
   popup.html
+  storageAccessAPIHelpers.js
 
 [browser_backgroundImageAssertion.js]
 [browser_blockingCookies.js]
 support-files = server.sjs
 [browser_blockingIndexedDb.js]
 [browser_blockingLocalStorage.js]
 skip-if = serviceworker_e10s
 [browser_blockingSessionStorage.js]
--- a/toolkit/components/antitracking/test/browser/browser_blockingCookies.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingCookies.js
@@ -42,54 +42,42 @@ AntiTracking.runTest("Set/Get Cookies",
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
     });
   });
 
 AntiTracking.runTest("Cookies and Storage Access API",
   // Blocking callback
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
+
     is(document.cookie, "", "No cookies for me");
     document.cookie = "name=value";
     is(document.cookie, "", "No cookies for me");
 
     await fetch("server.sjs").then(r => r.text()).then(text => {
       is(text, "cookie-not-present", "We should not have cookies");
     });
     // Let's do it twice.
     await fetch("server.sjs").then(r => r.text()).then(text => {
       is(text, "cookie-not-present", "We should not have cookies");
     });
 
     is(document.cookie, "", "Still no cookies for me");
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
+    await callRequestStorageAccess();
 
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
     is(document.cookie, "", "No cookies for me");
     document.cookie = "name=value";
     is(document.cookie, "name=value", "I have the cookies!");
   },
 
   // Non blocking callback
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     is(document.cookie, "", "No cookies for me");
 
     await fetch("server.sjs").then(r => r.text()).then(text => {
       is(text, "cookie-not-present", "We should not have cookies");
     });
 
     document.cookie = "name=value";
@@ -97,32 +85,18 @@ AntiTracking.runTest("Cookies and Storag
     ok(document.cookie.includes("foopy=1"), "Some cookies for me");
 
     await fetch("server.sjs").then(r => r.text()).then(text => {
       is(text, "cookie-present", "We should have cookies");
     });
 
     ok(document.cookie.length, "Some Cookies for me");
 
-    hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
-
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
+    await callRequestStorageAccess();
 
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
     // For non-tracking windows, calling the API is a no-op
     ok(document.cookie.length, "Still some Cookies for me");
     ok(document.cookie.includes("name=value"), "Some cookies for me");
     ok(document.cookie.includes("foopy=1"), "Some cookies for me");
   },
 
   // Cleanup callback
   async _ => {
--- a/toolkit/components/antitracking/test/browser/browser_blockingIndexedDb.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingIndexedDb.js
@@ -80,63 +80,45 @@ AntiTracking.runTest("IndexedDB in worke
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
     });
   });
 
 AntiTracking.runTest("IndexedDB and Storage Access API",
   // blocking callback
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
+
     try {
       indexedDB.open("test", "1");
       ok(false, "IDB should be blocked");
     } catch (e) {
       ok(true, "IDB should be blocked");
       is(e.name, "SecurityError", "We want a security error message.");
     }
 
     let dwu = SpecialPowers.getDOMWindowUtils(window);
     let helper = dwu.setHandlingUserInput(true);
 
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
+    await callRequestStorageAccess();
 
     indexedDB.open("test", "1");
     ok(true, "IDB should be allowed");
   },
   // non-blocking callback
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
+
     indexedDB.open("test", "1");
     ok(true, "IDB should be allowed");
 
     let dwu = SpecialPowers.getDOMWindowUtils(window);
     let helper = dwu.setHandlingUserInput(true);
 
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
+    await callRequestStorageAccess();
 
     // For non-tracking windows, calling the API is a no-op
     indexedDB.open("test", "1");
     ok(true, "IDB should be allowed");
   },
   // Cleanup callback
   async _ => {
     await new Promise(resolve => {
@@ -155,18 +137,17 @@ AntiTracking.runTest("IndexedDB in worke
         postMessage(e.name == "SecurityError");
       }
     }
     function nonBlockCode() {
       indexedDB.open("test", "1");
       postMessage(true);
     }
 
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     let blob = new Blob([blockCode.toString() + "; blockCode();"]);
     ok(blob, "Blob has been created");
 
     let blobURL = URL.createObjectURL(blob);
     ok(blobURL, "Blob URL has been created");
 
     let worker = new Worker(blobURL);
@@ -177,29 +158,17 @@ AntiTracking.runTest("IndexedDB in worke
         if (e) {
           resolve();
         } else {
           reject();
         }
       };
     });
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
+    await callRequestStorageAccess();
 
     blob = new Blob([nonBlockCode.toString() + "; nonBlockCode();"]);
     ok(blob, "Blob has been created");
 
     blobURL = URL.createObjectURL(blob);
     ok(blobURL, "Blob URL has been created");
 
     worker = new Worker(blobURL);
@@ -216,18 +185,17 @@ AntiTracking.runTest("IndexedDB in worke
     });
   },
   async _ => {
     function nonBlockCode() {
       indexedDB.open("test", "1");
       postMessage(true);
     }
 
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     let blob = new Blob([nonBlockCode.toString() + "; nonBlockCode();"]);
     ok(blob, "Blob has been created");
 
     let blobURL = URL.createObjectURL(blob);
     ok(blobURL, "Blob URL has been created");
 
     let worker = new Worker(blobURL);
@@ -238,29 +206,17 @@ AntiTracking.runTest("IndexedDB in worke
         if (e) {
           resolve();
         } else {
           reject();
         }
       };
     });
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
+    await callRequestStorageAccess();
 
     // For non-tracking windows, calling the API is a no-op
 
     worker = new Worker(blobURL);
     ok(worker, "Worker has been created");
 
     await new Promise((resolve, reject) => {
       worker.onmessage = function(e) {
--- a/toolkit/components/antitracking/test/browser/browser_blockingLocalStorage.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingLocalStorage.js
@@ -15,64 +15,38 @@ AntiTracking.runTest("localStorage",
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
     });
   });
 
 AntiTracking.runTest("localStorage and Storage Access API",
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     try {
       localStorage.foo = 42;
       ok(false, "LocalStorage cannot be used!");
     } catch (e) {
       ok(true, "LocalStorage cannot be used!");
       is(e.name, "SecurityError", "We want a security error message.");
     }
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
+    await callRequestStorageAccess();
 
     localStorage.foo = 42;
     ok(true, "LocalStorage is allowed");
   },
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     localStorage.foo = 42;
     ok(true, "LocalStorage is allowed");
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
+    await callRequestStorageAccess();
 
     // For non-tracking windows, calling the API is a no-op
     localStorage.foo = 42;
     ok(true, "LocalStorage is allowed");
   },
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
--- a/toolkit/components/antitracking/test/browser/browser_blockingMessaging.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingMessaging.js
@@ -76,61 +76,39 @@ AntiTracking.runTest("BroadcastChannel i
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
     });
   });
 
 AntiTracking.runTest("BroadcastChannel and Storage Access API",
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
+
     try {
       new BroadcastChannel("hello");
       ok(false, "BroadcastChannel cannot be used!");
     } catch (e) {
       ok(true, "BroadcastChannel cannot be used!");
       is(e.name, "SecurityError", "We want a security error message.");
     }
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
+    await callRequestStorageAccess();
 
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
     new BroadcastChannel("hello");
     ok(true, "BroadcastChannel can be used");
   },
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
+
     new BroadcastChannel("hello");
     ok(true, "BroadcastChanneli can be used");
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
+    await callRequestStorageAccess();
 
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
     new BroadcastChannel("hello");
     ok(true, "BroadcastChannel can be used");
   },
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
     });
   },
@@ -146,18 +124,17 @@ AntiTracking.runTest("BroadcastChannel i
         postMessage(e.name == "SecurityError");
       }
     }
     function nonBlockingCode() {
       new BroadcastChannel("hello");
       postMessage(true);
     }
 
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     let blob = new Blob([blockingCode.toString() + "; blockingCode();"]);
     ok(blob, "Blob has been created");
 
     let blobURL = URL.createObjectURL(blob);
     ok(blobURL, "Blob URL has been created");
 
     let worker = new Worker(blobURL);
@@ -168,29 +145,17 @@ AntiTracking.runTest("BroadcastChannel i
         if (e) {
           resolve();
         } else {
           reject();
         }
       };
     });
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
+    await callRequestStorageAccess();
 
     blob = new Blob([nonBlockingCode.toString() + "; nonBlockingCode();"]);
     ok(blob, "Blob has been created");
 
     blobURL = URL.createObjectURL(blob);
     ok(blobURL, "Blob URL has been created");
 
     worker = new Worker(blobURL);
@@ -207,18 +172,17 @@ AntiTracking.runTest("BroadcastChannel i
     });
   },
   async _ => {
     function nonBlockingCode() {
       new BroadcastChannel("hello");
       postMessage(true);
     }
 
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     let blob = new Blob([nonBlockingCode.toString() + "; nonBlockingCode();"]);
     ok(blob, "Blob has been created");
 
     let blobURL = URL.createObjectURL(blob);
     ok(blobURL, "Blob URL has been created");
 
     let worker = new Worker(blobURL);
@@ -229,29 +193,17 @@ AntiTracking.runTest("BroadcastChannel i
         if (e) {
           resolve();
         } else {
           reject();
         }
       };
     });
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
+    await callRequestStorageAccess();
 
     // For non-tracking windows, calling the API is a no-op
 
     worker = new Worker(blobURL);
     ok(worker, "Worker has been created");
 
     await new Promise((resolve, reject) => {
       worker.onmessage = function(e) {
--- a/toolkit/components/antitracking/test/browser/browser_blockingSessionStorage.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingSessionStorage.js
@@ -14,59 +14,33 @@ AntiTracking.runTest("sessionStorage",
   },
   [],
   true,
   true,
   false);
 
 AntiTracking.runTest("sessionStorage and Storage Access API",
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     sessionStorage.foo = 42;
     ok(true, "SessionStorage is always allowed");
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
+    await callRequestStorageAccess();
 
     sessionStorage.foo = 42;
     ok(true, "SessionStorage is allowed after calling the storage access API too");
   },
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     sessionStorage.foo = 42;
     ok(true, "SessionStorage is always allowed");
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
+    await callRequestStorageAccess();
 
     // For non-tracking windows, calling the API is a no-op
     sessionStorage.foo = 42;
     ok(true, "SessionStorage is allowed after calling the storage access API too");
   },
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
--- a/toolkit/components/antitracking/test/browser/browser_blockingWorkers.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingWorkers.js
@@ -50,64 +50,38 @@ AntiTracking.runTest("DOM Cache",
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
     });
   });
 
 AntiTracking.runTest("SharedWorkers and Storage Access API",
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     try {
       new SharedWorker("a.js", "foo");
       ok(false, "SharedWorker cannot be used!");
     } catch (e) {
       ok(true, "SharedWorker cannot be used!");
       is(e.name, "SecurityError", "We want a security error message.");
     }
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
+    await callRequestStorageAccess();
 
     new SharedWorker("a.js", "foo");
     ok(true, "SharedWorker is allowed");
   },
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     new SharedWorker("a.js", "foo");
     ok(true, "SharedWorker is allowed");
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
+    await callRequestStorageAccess();
 
     // For non-tracking windows, calling the API is a no-op
     new SharedWorker("a.js", "foo");
     ok(true, "SharedWorker is allowed");
   },
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
@@ -118,75 +92,49 @@ AntiTracking.runTest("SharedWorkers and 
 AntiTracking.runTest("ServiceWorkers and Storage Access API",
   async _ => {
     await SpecialPowers.pushPrefEnv({"set": [
        ["dom.serviceWorkers.exemptFromPerDomainMax", true],
        ["dom.serviceWorkers.enabled", true],
        ["dom.serviceWorkers.testing.enabled", true],
     ]});
 
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     await navigator.serviceWorker.register("empty.js").then(
       _ => { ok(false, "ServiceWorker cannot be used!"); },
       _ => { ok(true, "ServiceWorker cannot be used!"); }).
       catch(e => ok(false, "Promise rejected: " + e));
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
+    await callRequestStorageAccess();
 
     await navigator.serviceWorker.register("empty.js").then(
       reg => { ok(true, "ServiceWorker can be used!"); return reg; },
       _ => { ok(false, "ServiceWorker cannot be used! " + _); }).then(
       reg => reg.unregister(),
       _ => { ok(false, "unregister failed"); }).
       catch(e => ok(false, "Promise rejected: " + e));
   },
   async _ => {
     await SpecialPowers.pushPrefEnv({"set": [
        ["dom.serviceWorkers.exemptFromPerDomainMax", true],
        ["dom.serviceWorkers.enabled", true],
        ["dom.serviceWorkers.testing.enabled", true],
     ]});
 
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     await navigator.serviceWorker.register("empty.js").then(
       reg => { ok(true, "ServiceWorker can be used!"); return reg; },
       _ => { ok(false, "ServiceWorker cannot be used!"); }).then(
       reg => reg.unregister(),
       _ => { ok(false, "unregister failed"); }).
       catch(e => ok(false, "Promise rejected: " + e));
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
+    await callRequestStorageAccess();
 
     // For non-tracking windows, calling the API is a no-op
     await navigator.serviceWorker.register("empty.js").then(
       reg => { ok(true, "ServiceWorker can be used!"); return reg; },
       _ => { ok(false, "ServiceWorker cannot be used!"); }).then(
       reg => reg.unregister(),
       _ => { ok(false, "unregister failed"); }).
       catch(e => ok(false, "Promise rejected: " + e));
@@ -198,62 +146,36 @@ AntiTracking.runTest("ServiceWorkers and
   },
   [["dom.serviceWorkers.exemptFromPerDomainMax", true],
    ["dom.serviceWorkers.enabled", true],
    ["dom.serviceWorkers.testing.enabled", true]],
   false, false);
 
 AntiTracking.runTest("DOM Cache and Storage Access API",
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     await caches.open("wow").then(
       _ => { ok(false, "DOM Cache cannot be used!"); },
       _ => { ok(true, "DOM Cache cannot be used!"); });
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
+    await callRequestStorageAccess();
 
     await caches.open("wow").then(
       _ => { ok(true, "DOM Cache can be used!"); },
       _ => { ok(false, "DOM Cache can be used!"); });
   },
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     await caches.open("wow").then(
       _ => { ok(true, "DOM Cache can be used!"); },
       _ => { ok(false, "DOM Cache can be used!"); });
 
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    try {
-      p = document.requestStorageAccess();
-    } finally {
-      helper.destruct();
-    }
-    await p;
-
-    hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Now has storage access");
+    await callRequestStorageAccess();
 
     // For non-tracking windows, calling the API is a no-op
     await caches.open("wow").then(
       _ => { ok(true, "DOM Cache can be used!"); },
       _ => { ok(false, "DOM Cache can be used!"); });
   },
   async _ => {
     await new Promise(resolve => {
--- a/toolkit/components/antitracking/test/browser/browser_storageAccessPrivateWindow.js
+++ b/toolkit/components/antitracking/test/browser/browser_storageAccessPrivateWindow.js
@@ -1,33 +1,16 @@
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 AntiTracking.runTest("Storage Access API called in a private window",
   // blocking callback
   async _ => {
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    let threw = false;
-    try {
-      p = document.requestStorageAccess();
-    } catch (e) {
-      threw = true;
-    } finally {
-      helper.destruct();
-    }
+    let [threw, rejected] = await callRequestStorageAccess();
     ok(!threw, "requestStorageAccess should not throw");
-    threw = false;
-    try {
-      await p;
-    } catch (e) {
-      threw = true;
-    }
-    ok(threw, "requestStorageAccess shouldn't be available");
+    ok(rejected, "requestStorageAccess shouldn't be available");
   },
 
   null, // non-blocking callback
   null, // cleanup function
   [["dom.storage_access.enabled", true]], // extra prefs
   false, // no window open test
   false, // no user-interaction test
   false, // no blocking notifications
--- a/toolkit/components/antitracking/test/browser/browser_storageAccessPromiseResolveHandlerUserInteraction.js
+++ b/toolkit/components/antitracking/test/browser/browser_storageAccessPromiseResolveHandlerUserInteraction.js
@@ -1,47 +1,24 @@
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 AntiTracking.runTest("Storage Access API returns promises that maintain user activation",
   // blocking callback
   async _ => {
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    let threw = false;
-    try {
-      p = document.requestStorageAccess();
-    } catch (e) {
-      threw = true;
-    } finally {
-      helper.destruct();
-    }
+    let [threw, rejected] = await callRequestStorageAccess(dwu => {
+      ok(dwu.isHandlingUserInput,
+         "Promise handler must run as if we're handling user input");
+    });
     ok(!threw, "requestStorageAccess should not throw");
-    threw = false;
-    await p.then(() => {
-    });
-    threw = false;
-    try {
-      await p.then(() => {
-        ok(dwu.isHandlingUserInput,
-           "Promise handler must run as if we're handling user input");
-      });
-    } catch (e) {
-      threw = true;
-    }
-    ok(!threw, "requestStorageAccess should be available");
+    ok(!rejected, "requestStorageAccess should be available");
   },
 
   null, // non-blocking callback
   // cleanup function
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
     });
   },
-  [["dom.storage_access.enabled", true]], // extra prefs
+  null, // extra prefs
   false, // no window open test
-  false, // no user-interaction test
-  true, // expect blocking notifications
-  false, // run in normal window
-  null // iframe sandbox
+  false // no user-interaction test
 );
--- a/toolkit/components/antitracking/test/browser/browser_storageAccessSandboxed.js
+++ b/toolkit/components/antitracking/test/browser/browser_storageAccessSandboxed.js
@@ -1,71 +1,37 @@
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 let counter = 0;
 
 AntiTracking.runTest("Storage Access API called in a sandboxed iframe",
   // blocking callback
   async _ => {
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    let threw = false;
-    try {
-      p = document.requestStorageAccess();
-    } catch (e) {
-      threw = true;
-    } finally {
-      helper.destruct();
-    }
+    let [threw, rejected] = await callRequestStorageAccess();
     ok(!threw, "requestStorageAccess should not throw");
-    threw = false;
-    try {
-      await p;
-    } catch (e) {
-      threw = true;
-    }
-    ok(threw, "requestStorageAccess shouldn't be available");
+    ok(rejected, "requestStorageAccess shouldn't be available");
   },
 
   null, // non-blocking callback
   null, // cleanup function
   [["dom.storage_access.enabled", true]], // extra prefs
   false, // no window open test
   false, // no user-interaction test
   false, // no blocking notifications
   false, // run in normal window
   "allow-scripts allow-same-origin"
 );
 
 AntiTracking.runTest("Storage Access API called in a sandboxed iframe with" +
                      " allow-storage-access-by-user-activation",
   // blocking callback
   async _ => {
-    let dwu = SpecialPowers.getDOMWindowUtils(window);
-    let helper = dwu.setHandlingUserInput(true);
-
-    let p;
-    let threw = false;
-    try {
-      p = document.requestStorageAccess();
-    } catch (e) {
-      threw = true;
-    } finally {
-      helper.destruct();
-    }
+    let [threw, rejected] = await callRequestStorageAccess();
     ok(!threw, "requestStorageAccess should not throw");
-    threw = false;
-    try {
-      await p;
-    } catch (e) {
-      threw = true;
-    }
-    ok(!threw, "requestStorageAccess should be available");
+    ok(!rejected, "requestStorageAccess should be available");
   },
 
   null, // non-blocking callback
   // cleanup function
   async _ => {
     // The test harness calls this function twice.  Our cleanup function is set
     // up so that the first time that it's called, it would do the cleanup, but
     // the second time it would bail out early.  This ensures that after the
@@ -85,18 +51,17 @@ AntiTracking.runTest("Storage Access API
   true, // expect blocking notifications
   false, // run in normal window
   "allow-scripts allow-same-origin allow-storage-access-by-user-activation"
 );
 
 AntiTracking.runTest("Verify that sandboxed contexts don't get the saved permission",
   // blocking callback
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     try {
       localStorage.foo = 42;
       ok(false, "LocalStorage cannot be used!");
     } catch (e) {
       ok(true, "LocalStorage cannot be used!");
       is(e.name, "SecurityError", "We want a security error message.");
     }
@@ -112,18 +77,17 @@ AntiTracking.runTest("Verify that sandbo
   "allow-scripts allow-same-origin"
 );
 
 AntiTracking.runTest("Verify that sandboxed contexts with" +
                      " allow-storage-access-by-user-activation get the" +
                      " saved permission",
   // blocking callback
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Has storage access");
+    await hasStorageAccessInitially();
 
     localStorage.foo = 42;
     ok(true, "LocalStorage can be used!");
   },
 
   null, // non-blocking callback
   null, // cleanup function
   [["dom.storage_access.enabled", true]], // extra prefs
@@ -132,18 +96,17 @@ AntiTracking.runTest("Verify that sandbo
   false, // no blocking notifications
   false, // run in normal window
   "allow-scripts allow-same-origin allow-storage-access-by-user-activation"
 );
 
 AntiTracking.runTest("Verify that private browsing contexts don't get the saved permission",
   // blocking callback
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(!hasAccess, "Doesn't yet have storage access");
+    await noStorageAccessInitially();
 
     try {
       localStorage.foo = 42;
       ok(false, "LocalStorage cannot be used!");
     } catch (e) {
       ok(true, "LocalStorage cannot be used!");
       is(e.name, "SecurityError", "We want a security error message.");
     }
@@ -158,18 +121,17 @@ AntiTracking.runTest("Verify that privat
   true, // run in private window
   null // iframe sandbox
 );
 
 AntiTracking.runTest("Verify that non-sandboxed contexts get the" +
                      " saved permission",
   // blocking callback
   async _ => {
-    let hasAccess = await document.hasStorageAccess();
-    ok(hasAccess, "Has storage access");
+    await hasStorageAccessInitially();
 
     localStorage.foo = 42;
     ok(true, "LocalStorage can be used!");
   },
 
   null, // non-blocking callback
   // cleanup function
   async _ => {
--- a/toolkit/components/antitracking/test/browser/browser_storageAccessWithHeuristics.js
+++ b/toolkit/components/antitracking/test/browser/browser_storageAccessWithHeuristics.js
@@ -31,23 +31,21 @@ add_task(async function testWindowOpenHe
   await BrowserTestUtils.browserLoaded(browser);
 
   info("Loading tracking scripts");
   await ContentTask.spawn(browser, {
                                      page: TEST_3RD_PARTY_PAGE_WO,
                                    }, async obj => {
     let msg = {};
     msg.blockingCallback = (async _ => {
-      let hasAccess = await document.hasStorageAccess();
-      ok(!hasAccess, "Doesn't yet have storage access");
+      await noStorageAccessInitially();
     }).toString();
 
     msg.nonBlockingCallback = (async _ => {
-      let hasAccess = await document.hasStorageAccess();
-      ok(hasAccess, "Now obtained storage access");
+      await hasStorageAccessInitially();
     }).toString();
 
     info("Checking if storage access is denied");
     await new content.Promise(resolve => {
       let ifr = content.document.createElement("iframe");
       ifr.onload = function() {
         info("Sending code to the 3rd party content");
         ifr.contentWindow.postMessage(msg, "*");
@@ -101,23 +99,21 @@ add_task(async function testUserInteract
 
   info("Loading tracking scripts");
   await ContentTask.spawn(browser, {
                                      page: TEST_3RD_PARTY_PAGE_UI,
                                      popup: TEST_POPUP_PAGE,
                                    }, async obj => {
     let msg = {};
     msg.blockingCallback = (async _ => {
-      let hasAccess = await document.hasStorageAccess();
-      ok(!hasAccess, "Doesn't yet have storage access");
+      await noStorageAccessInitially();
     }).toString();
 
     msg.nonBlockingCallback = (async _ => {
-      let hasAccess = await document.hasStorageAccess();
-      ok(hasAccess, "Now obtained storage access");
+      await hasStorageAccessInitially();
     }).toString();
 
     info("Checking if storage access is denied");
 
     let ifr = content.document.createElement("iframe");
     let loading = new content.Promise(resolve => { ifr.onload = resolve; });
     content.document.body.appendChild(ifr);
     ifr.src = obj.page;
--- a/toolkit/components/antitracking/test/browser/head.js
+++ b/toolkit/components/antitracking/test/browser/head.js
@@ -433,16 +433,20 @@ this.AntiTracking = {
                 is(originLog[0][1], true,
                    "Correct blocking status reported");
                 ok(originLog[0][2] >= 1,
                    "Correct repeat count reported");
               } else {
                 // This branch is needed here because of the tests that use the storage
                 // access API to gain storage access.
                 is(originLog.length, 2, "Correct origin log length");
+                if (originLog.length > 2) {
+                  console.log(originLog);
+                  console.log(originLog.toSource());
+                }
                 is(originLog[0][0], Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER,
                    "Correct blocking type reported");
                 is(originLog[0][1], true,
                    "Correct blocking status reported");
                 ok(originLog[0][2] >= 1,
                    "Correct repeat count reported");
                 is(originLog[1][0], Ci.nsIWebProgressListener.STATE_COOKIES_BLOCKED_TRACKER,
                    "Correct blocking type reported");
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/storageAccessAPIHelpers.js
@@ -0,0 +1,42 @@
+async function hasStorageAccessInitially() {
+  let hasAccess = await document.hasStorageAccess();
+  ok(hasAccess, "Has storage access");
+}
+
+async function noStorageAccessInitially() {
+  let hasAccess = await document.hasStorageAccess();
+  ok(!hasAccess, "Doesn't yet have storage access");
+}
+
+async function callRequestStorageAccess(callback) {
+  let dwu = SpecialPowers.getDOMWindowUtils(window);
+  let helper = dwu.setHandlingUserInput(true);
+
+  let p;
+  let threw = false;
+  try {
+    p = document.requestStorageAccess();
+  } catch (e) {
+    threw = true;
+  } finally {
+    helper.destruct();
+  }
+  let rejected = false;
+  try {
+    if (callback) {
+      await p.then(_ => callback(dwu));
+    } else {
+      await p;
+    }
+  } catch (e) {
+    rejected = true;
+  }
+
+  let success = !threw && !rejected;
+  let hasAccess = await document.hasStorageAccess();
+  is(hasAccess, success,
+     "Should " + (success ? "" : "not ") + "have storage access now");
+
+  return [threw, rejected];
+}
+