Bug 1424943 Fix test_error_reporting.html not to race network vs Clients API. r=tt
authorBen Kelly <ben@wanderview.com>
Wed, 13 Dec 2017 09:58:26 -0500
changeset 396239 c885e730dded79619acf357346b4954ef24a79b0
parent 396238 4c8f363c833225ef34bbf10b9f418e2cb8a0c774
child 396240 fd2a2e17aef386ad47cfbd2259b7dd791999d194
push id56955
push userncsoregi@mozilla.com
push dateWed, 13 Dec 2017 22:16:06 +0000
treeherderautoland@2d07da0b4098 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstt
bugs1424943
milestone59.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 1424943 Fix test_error_reporting.html not to race network vs Clients API. r=tt
dom/workers/test/serviceworkers/sw_storage_not_allow.js
--- a/dom/workers/test/serviceworkers/sw_storage_not_allow.js
+++ b/dom/workers/test/serviceworkers/sw_storage_not_allow.js
@@ -1,21 +1,34 @@
 let clientId;
 addEventListener('fetch', function(event) {
-  if (event.request.url.includes('getClients')) {
-    // Excepted to fail since the storage access is not allowed.
-    self.clients.matchAll();
-  } else if (event.request.url.includes('getClient-stage1')) {
-    self.clients.matchAll().then(function(clients) {
+  event.respondWith(async function() {
+    if (event.request.url.includes('getClients')) {
+      // Expected to fail since the storage access is not allowed.
+      try {
+        await self.clients.matchAll();
+      } catch (e) {
+        // expected failure
+      }
+    } else if (event.request.url.includes('getClient-stage1')) {
+      let clients = await self.clients.matchAll();
       clientId = clients[0].id;
-    });
-  } else if (event.request.url.includes('getClient-stage2')) {
-    // Excepted to fail since the storage access is not allowed.
-    self.clients.get(clientId);
-  }
+    } else if (event.request.url.includes('getClient-stage2')) {
+      // Expected to fail since the storage access is not allowed.
+      try {
+        await self.clients.get(clientId);
+      } catch(e) {
+        // expected failure
+      }
+    }
+
+    // Pass through the network request once our various Clients API
+    // promises have completed.
+    return await fetch(event.request);
+  }());
 });
 
 addEventListener('message', function(event) {
   if (event.data === 'claim') {
     event.waitUntil(clients.claim());
   }
 });