Bug 1469714 - Part 7: Add tests for the Storage Access API interaction with worker APIs; r=baku
☠☠ backed out by dc31941ced58 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 12 Sep 2018 19:28:11 -0400
changeset 436794 453370408672ef251d80342390da9e1f183c7381
parent 436793 ff443966e3d9c8f638a0596a2ab2a52b0eeb6c56
child 436795 61dc8b46e7f62fa523d6b7a090b72c8ad6c23592
push id34660
push userbtara@mozilla.com
push dateMon, 17 Sep 2018 21:58:52 +0000
treeherdermozilla-central@87a95e1b7ec6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1469714
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 1469714 - Part 7: Add tests for the Storage Access API interaction with worker APIs; r=baku Differential Revision: https://phabricator.services.mozilla.com/D5816
toolkit/components/antitracking/test/browser/browser_blockingWorkers.js
--- a/toolkit/components/antitracking/test/browser/browser_blockingWorkers.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingWorkers.js
@@ -1,8 +1,10 @@
+requestLongerTimeout(2);
+
 AntiTracking.runTest("SharedWorkers",
   async _ => {
     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.");
@@ -15,17 +17,17 @@ AntiTracking.runTest("SharedWorkers",
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
     });
   });
 
 AntiTracking.runTest("ServiceWorkers",
   async _ => {
-    await navigator.serviceWorker.register("empty.js", { scope: "/" }).then(
+    await navigator.serviceWorker.register("empty.js").then(
       _ => { ok(false, "ServiceWorker cannot be used!"); },
       _ => { ok(true, "ServiceWorker cannot be used!"); });
   },
   null,
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
     });
@@ -45,8 +47,213 @@ AntiTracking.runTest("DOM Cache",
       _ => { ok(true, "DOM Cache can be used!"); },
       _ => { ok(false, "DOM Cache can be used!"); });
   },
   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");
+
+    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");
+
+    new SharedWorker("a.js", "foo");
+    ok(true, "SharedWorker is allowed");
+  },
+  async _ => {
+    let hasAccess = await document.hasStorageAccess();
+    ok(!hasAccess, "Doesn't yet have storage access");
+
+    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");
+
+    // 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());
+    });
+  },
+  null, false, false);
+
+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 navigator.serviceWorker.register("empty.js").then(
+      _ => { ok(false, "ServiceWorker cannot be used!"); },
+      _ => { ok(true, "ServiceWorker 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 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"); });
+  },
+  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 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"); });
+
+    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");
+
+    // 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"); });
+  },
+  async _ => {
+    await new Promise(resolve => {
+      Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
+    });
+  },
+  [["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 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 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 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");
+
+    // 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 => {
+      Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
+    });
+  },
+  null, false, false);