Bug 1526225 - Fix anti-tracking tests when checking worker messages, r=Ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 08 Feb 2019 16:53:20 +0000
changeset 458504 587db27dbdda91e2b5c2001e22636d4a20aa452f
parent 458503 1e8fa611b7ae159304697d3de11aeae23c715bfa
child 458505 6377703a7428a1b3ad491ad9c1a368f3f05688ea
push id111855
push userbtara@mozilla.com
push dateMon, 11 Feb 2019 22:01:49 +0000
treeherdermozilla-inbound@42a097167d36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1526225
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 1526225 - Fix anti-tracking tests when checking worker messages, r=Ehsan Differential Revision: https://phabricator.services.mozilla.com/D19127
toolkit/components/antitracking/test/browser/browser_blockingIndexedDbInWorkers.js
toolkit/components/antitracking/test/browser/browser_blockingMessaging.js
--- a/toolkit/components/antitracking/test/browser/browser_blockingIndexedDbInWorkers.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingIndexedDbInWorkers.js
@@ -15,22 +15,26 @@ AntiTracking.runTest("IndexedDB in worke
     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) {
+        if (e.data) {
           resolve();
         } else {
           reject();
         }
       };
+
+      worker.onerror = function(e) {
+        reject();
+      };
     });
   },
   async _ => {
     function nonBlockCode() {
       indexedDB.open("test", "1");
       postMessage(true);
     }
 
@@ -40,22 +44,26 @@ AntiTracking.runTest("IndexedDB in worke
     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) {
+        if (e.data) {
           resolve();
         } else {
           reject();
         }
       };
+
+      worker.onerror = function(e) {
+        reject();
+      };
     });
   },
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
     });
   });
 
@@ -83,22 +91,26 @@ AntiTracking.runTest("IndexedDB in worke
     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) {
+        if (e.data) {
           resolve();
         } else {
           reject();
         }
       };
+
+      worker.onerror = function(e) {
+        reject();
+      };
     });
 
     /* import-globals-from storageAccessAPIHelpers.js */
     await callRequestStorageAccess();
 
     if (SpecialPowers.Services.prefs.getIntPref("network.cookie.cookieBehavior") == SpecialPowers.Ci.nsICookieService.BEHAVIOR_REJECT) {
       blob = new Blob([blockCode.toString() + "; blockCode();"]);
     } else {
@@ -109,22 +121,26 @@ AntiTracking.runTest("IndexedDB in worke
     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) {
+        if (e.data) {
           resolve();
         } else {
           reject();
         }
       };
+
+      worker.onerror = function(e) {
+        reject();
+      };
     });
   },
   async _ => {
     function nonBlockCode() {
       indexedDB.open("test", "1");
       postMessage(true);
     }
 
@@ -137,40 +153,48 @@ AntiTracking.runTest("IndexedDB in worke
     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) {
+        if (e.data) {
           resolve();
         } else {
           reject();
         }
       };
+
+      worker.onerror = function(e) {
+        reject();
+      };
     });
 
     /* import-globals-from storageAccessAPIHelpers.js */
     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) {
-        if (e) {
+        if (e.data) {
           resolve();
         } else {
           reject();
         }
       };
+
+      worker.onerror = function(e) {
+        reject();
+      };
     });
   },
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
     });
   },
   null, false, false);
--- a/toolkit/components/antitracking/test/browser/browser_blockingMessaging.js
+++ b/toolkit/components/antitracking/test/browser/browser_blockingMessaging.js
@@ -35,22 +35,26 @@ AntiTracking.runTest("BroadcastChannel i
     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) {
+        if (e.data) {
           resolve();
         } else {
           reject();
         }
       };
+
+      worker.onerror = function(e) {
+        reject();
+      };
     });
   },
   async _ => {
     function nonBlockingCode() {
       new BroadcastChannel("hello");
       postMessage(true);
     }
 
@@ -60,22 +64,26 @@ AntiTracking.runTest("BroadcastChannel i
     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) {
+        if (e.data) {
           resolve();
         } else {
           reject();
         }
       };
+
+      worker.onerror = function(e) {
+        reject();
+      };
     });
   },
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
     });
   });
 
@@ -152,22 +160,26 @@ AntiTracking.runTest("BroadcastChannel i
     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) {
+        if (e.data) {
           resolve();
         } else {
           reject();
         }
       };
+
+      worker.onerror = function(e) {
+        reject();
+      };
     });
 
     /* import-globals-from storageAccessAPIHelpers.js */
     await callRequestStorageAccess();
 
     if (SpecialPowers.Services.prefs.getIntPref("network.cookie.cookieBehavior") == SpecialPowers.Ci.nsICookieService.BEHAVIOR_REJECT) {
       blob = new Blob([blockingCode.toString() + "; blockingCode();"]);
     } else {
@@ -179,22 +191,26 @@ AntiTracking.runTest("BroadcastChannel i
     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) {
+        if (e.data) {
           resolve();
         } else {
           reject();
         }
       };
+
+      worker.onerror = function(e) {
+        reject();
+      };
     });
   },
   async _ => {
     function nonBlockingCode() {
       new BroadcastChannel("hello");
       postMessage(true);
     }
 
@@ -207,40 +223,48 @@ AntiTracking.runTest("BroadcastChannel i
     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) {
+        if (e.data) {
           resolve();
         } else {
           reject();
         }
       };
+
+      worker.onerror = function(e) {
+        reject();
+      };
     });
 
     /* import-globals-from storageAccessAPIHelpers.js */
     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) {
-        if (e) {
+        if (e.data) {
           resolve();
         } else {
           reject();
         }
       };
+
+      worker.onerror = function(e) {
+        reject();
+      };
     });
   },
   async _ => {
     await new Promise(resolve => {
       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
     });
   },
   null, false, false);