Bug 1469714 - Part 5: Add tests for the Storage Access API interaction with messaging APIs; r=baku
☠☠ backed out by dc31941ced58 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 12 Sep 2018 19:22:46 -0400
changeset 436792 88f414c8cecc90ac7db72bdf5ecc6effdc207c9a
parent 436791 36e5c9e69f105f8762b9375c9caf9b322a5a4b51
child 436793 ff443966e3d9c8f638a0596a2ab2a52b0eeb6c56
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 5: Add tests for the Storage Access API interaction with messaging APIs; r=baku Differential Revision: https://phabricator.services.mozilla.com/D5814
toolkit/components/antitracking/test/browser/browser_blockingMessaging.js
--- a/toolkit/components/antitracking/test/browser/browser_blockingMessaging.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingMessaging.js
@@ -33,19 +33,23 @@ AntiTracking.runTest("BroadcastChannel i
     ok(blob, "Blob has been created");
 
     let blobURL = URL.createObjectURL(blob);
     ok(blobURL, "Blob URL has been created");
 
     let worker = new Worker(blobURL);
     ok(worker, "Worker has been created");
 
-    await new Promise(resolve => {
+    await new Promise((resolve, reject) => {
       worker.onmessage = function(e) {
-        resolve();
+        if (e) {
+          resolve();
+        } else {
+          reject();
+        }
       };
     });
   },
   async _ => {
     function nonBlockingCode() {
       new BroadcastChannel("hello");
       postMessage(true);
     }
@@ -54,19 +58,214 @@ AntiTracking.runTest("BroadcastChannel i
     ok(blob, "Blob has been created");
 
     let blobURL = URL.createObjectURL(blob);
     ok(blobURL, "Blob URL has been created");
 
     let worker = new Worker(blobURL);
     ok(worker, "Worker has been created");
 
-    await new Promise(resolve => {
+    await new Promise((resolve, reject) => {
       worker.onmessage = function(e) {
-        resolve();
+        if (e) {
+          resolve();
+        } else {
+          reject();
+        }
       };
     });
   },
   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");
+    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);
+
+    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");
+    new BroadcastChannel("hello");
+    ok(true, "BroadcastChanneli 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");
+    new BroadcastChannel("hello");
+    ok(true, "BroadcastChannel can be used");
+  },
+  async _ => {
+    await new Promise(resolve => {
+      Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
+    });
+  },
+  null, false, false);
+
+AntiTracking.runTest("BroadcastChannel in workers and Storage Access API",
+  async _ => {
+    function blockingCode() {
+      try {
+        new BroadcastChannel("hello");
+        postMessage(false);
+      } catch (e) {
+        postMessage(e.name == "SecurityError");
+      }
+    }
+    function nonBlockingCode() {
+      new BroadcastChannel("hello");
+      postMessage(true);
+    }
+
+    let hasAccess = await document.hasStorageAccess();
+    ok(!hasAccess, "Doesn't yet have storage access");
+
+    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);
+    ok(worker, "Worker has been created");
+
+    await new Promise((resolve, reject) => {
+      worker.onmessage = function(e) {
+        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");
+
+    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);
+    ok(worker, "Worker has been created");
+
+    await new Promise((resolve, reject) => {
+      worker.onmessage = function(e) {
+        if (e) {
+          resolve();
+        } else {
+          reject();
+        }
+      };
+    });
+  },
+  async _ => {
+    function nonBlockingCode() {
+      new BroadcastChannel("hello");
+      postMessage(true);
+    }
+
+    let hasAccess = await document.hasStorageAccess();
+    ok(!hasAccess, "Doesn't yet have storage access");
+
+    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);
+    ok(worker, "Worker has been created");
+
+    await new Promise((resolve, reject) => {
+      worker.onmessage = function(e) {
+        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");
+
+    // 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) {
+        if (e) {
+          resolve();
+        } else {
+          reject();
+        }
+      };
+    });
+  },
+  async _ => {
+    await new Promise(resolve => {
+      Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
+    });
+  },
+  null, false, false);