Bug 1273070 P2 Execute fetch() mochitests in nested workers. r=khuey
authorBen Kelly <ben@wanderview.com>
Thu, 19 May 2016 11:39:13 -0700
changeset 298192 00218374a90cfbb6b66a9a1bf8e5483efcb18661
parent 298191 5733b66fdedf6e27d46bd9cc485f4960cc778334
child 298193 fbdb4502afd5c41559189e50fc020d586697991c
push id30273
push userkwierso@gmail.com
push dateFri, 20 May 2016 21:08:12 +0000
treeherdermozilla-central@c403ac05b8f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs1273070
milestone49.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 1273070 P2 Execute fetch() mochitests in nested workers. r=khuey
dom/tests/mochitest/fetch/fetch_test_framework.js
dom/tests/mochitest/fetch/mochitest.ini
dom/tests/mochitest/fetch/nested_worker_wrapper.js
--- a/dom/tests/mochitest/fetch/fetch_test_framework.js
+++ b/dom/tests/mochitest/fetch/fetch_test_framework.js
@@ -31,16 +31,37 @@ function testScript(script) {
       worker.onerror = function(event) {
         reject("Worker error: " + event.message);
       };
 
       worker.postMessage({ "script": script });
     });
   }
 
+  function nestedWorkerTest() {
+    return new Promise(function(resolve, reject) {
+      var worker = new Worker("nested_worker_wrapper.js");
+      worker.onmessage = function(event) {
+        if (event.data.context != "NestedWorker") {
+          return;
+        }
+        if (event.data.type == 'finish') {
+          resolve();
+        } else if (event.data.type == 'status') {
+          ok(event.data.status, event.data.context + ": " + event.data.msg);
+        }
+      }
+      worker.onerror = function(event) {
+        reject("Nested Worker error: " + event.message);
+      };
+
+      worker.postMessage({ "script": script });
+    });
+  }
+
   function serviceWorkerTest() {
     var isB2G = !navigator.userAgent.includes("Android") &&
                 /Mobile|Tablet/.test(navigator.userAgent);
     if (isB2G) {
       // TODO B2G doesn't support running service workers for now due to bug 1137683.
       dump("Skipping running the test in SW until bug 1137683 gets fixed.\n");
       return Promise.resolve();
     }
@@ -108,16 +129,19 @@ function testScript(script) {
   setupPrefs()
     .then(function() {
       return windowTest();
     })
     .then(function() {
       return workerTest();
     })
     .then(function() {
+      return nestedWorkerTest();
+    })
+    .then(function() {
       return serviceWorkerTest();
     })
     .catch(function(e) {
       ok(false, "Some test failed in " + script);
       info(e);
       info(e.message);
       return Promise.resolve();
     })
--- a/dom/tests/mochitest/fetch/mochitest.ini
+++ b/dom/tests/mochitest/fetch/mochitest.ini
@@ -5,16 +5,17 @@ support-files =
   test_fetch_basic.js
   test_fetch_basic_http.js
   test_fetch_cors.js
   test_formdataparsing.js
   test_headers_common.js
   test_request.js
   test_response.js
   utils.js
+  nested_worker_wrapper.js
   worker_wrapper.js
   message_receiver.html
   reroute.html
   reroute.js
   reroute.js^headers^
   sw_reroute.js
   empty.js
   empty.js^headers^
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/fetch/nested_worker_wrapper.js
@@ -0,0 +1,25 @@
+addEventListener('message', function nestedWorkerWrapperOnMessage(evt) {
+  removeEventListener('message', nestedWorkerWrapperOnMessage);
+
+  var worker = new Worker('worker_wrapper.js');
+
+  worker.addEventListener('message', function(evt) {
+    self.postMessage({
+      context: 'NestedWorker',
+      type: evt.data.type,
+      status: evt.data.status,
+      msg: evt.data.msg,
+    });
+  });
+
+  worker.addEventListener('error', function(evt) {
+    self.postMessage({
+      context: 'NestedWorker',
+      type: 'status',
+      status: false,
+      msg: 'Nested worker error: ' + evt.message,
+    });
+  });
+
+  worker.postMessage(evt.data);
+});