Bug 1325942 - Fix test_fetch_cors_sw_empty_reroute.html. r=ehsan, a=test-only FIREFOX_53_0b8_BUILD1 FIREFOX_53_0b8_RELEASE
☠☠ backed out by fe3e3c0ea489 ☠ ☠
authorCatalin Badea <catalin.badea392@gmail.com>
Wed, 29 Mar 2017 01:49:00 +0800
changeset 558107 0a36cc120d6e7b8bc19176f5efac6b00dd9ad072
parent 558106 a2e8b78114bcc1577b8d2ca67d30562a3288be51
child 558108 fe3e3c0ea489cea724da1bd56ce20fe843d96a9e
push id52846
push usernthomas@mozilla.com
push dateFri, 07 Apr 2017 10:33:06 +0000
reviewersehsan, test-only
bugs1325942
milestone53.0
Bug 1325942 - Fix test_fetch_cors_sw_empty_reroute.html. r=ehsan, a=test-only
dom/tests/mochitest/fetch/fetch_test_framework.js
dom/tests/mochitest/fetch/worker_wrapper.js
--- a/dom/tests/mochitest/fetch/fetch_test_framework.js
+++ b/dom/tests/mochitest/fetch/fetch_test_framework.js
@@ -12,16 +12,17 @@ function testScript(script) {
   }
 
   function setupPrefs() {
     return new Promise(function(resolve, reject) {
       SpecialPowers.pushPrefEnv({
         "set": [["dom.requestcontext.enabled", true],
                 ["dom.serviceWorkers.enabled", true],
                 ["dom.serviceWorkers.testing.enabled", true],
+                ["dom.serviceWorkers.idle_timeout", 0],
                 ["dom.serviceWorkers.exemptFromPerDomainMax", true]]
       }, resolve);
     });
   }
 
   function workerTest() {
     return new Promise(function(resolve, reject) {
       var worker = new Worker("worker_wrapper.js");
--- a/dom/tests/mochitest/fetch/worker_wrapper.js
+++ b/dom/tests/mochitest/fetch/worker_wrapper.js
@@ -11,48 +11,55 @@ function is(a, b, msg) {
   client.postMessage({type: 'status', status: a === b,
                       msg: a + " === " + b + ": " + msg, context: context});
 }
 
 addEventListener('message', function workerWrapperOnMessage(e) {
   removeEventListener('message', workerWrapperOnMessage);
   var data = e.data;
 
-  function loadTest() {
-    var done = function() {
+  function loadTest(event) {
+    var done = function(res) {
       client.postMessage({ type: 'finish', context: context });
+      return res;
     }
 
     try {
       importScripts(data.script);
       // runTest() is provided by the test.
-      runTest().then(done, done);
+      var result = runTest().then(done, done);
+      if ('waitUntil' in event) {
+        event.waitUntil(result);
+      }
     } catch(e) {
       client.postMessage({
         type: 'status',
         status: false,
         msg: 'worker failed to import ' + data.script + "; error: " + e.message,
         context: context
       });
       done();
     }
   }
 
   if ("ServiceWorker" in self) {
-    self.clients.matchAll().then(function(clients) {
+    // Fetch requests from a service worker are not intercepted.
+    self.isSWPresent = false;
+
+    e.waitUntil(self.clients.matchAll().then(function(clients) {
       for (var i = 0; i < clients.length; ++i) {
         if (clients[i].url.indexOf("message_receiver.html") > -1) {
           client = clients[i];
           break;
         }
       }
       if (!client) {
         dump("We couldn't find the message_receiver window, the test will fail\n");
       }
       context = "ServiceWorker";
-      loadTest();
-    });
+      loadTest(e);
+    }));
   } else {
     client = self;
     context = "Worker";
-    loadTest();
+    loadTest(e);
   }
 });