Bug 1511040 - Handle errors in test_readableStreams.html. r=baku
authorJason Orendorff <jorendorff@mozilla.com>
Thu, 29 Nov 2018 22:44:46 +0000
changeset 508084 7a24e1e35a7e4a372f719463ca367882bb6de5dd
parent 508083 7180b12513ad5f0a0d1edf3188610a848b3b6ebf
child 508085 77764799fba3b6f29fb7b5ce15e4ba73f263832f
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1511040
milestone65.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 1511040 - Handle errors in test_readableStreams.html. r=baku Differential Revision: https://phabricator.services.mozilla.com/D13410
dom/tests/mochitest/fetch/common_readableStreams.js
dom/tests/mochitest/fetch/iframe_readableStreams.html
dom/tests/mochitest/fetch/test_readableStreams.html
dom/tests/mochitest/fetch/worker_readableStreams.js
--- a/dom/tests/mochitest/fetch/common_readableStreams.js
+++ b/dom/tests/mochitest/fetch/common_readableStreams.js
@@ -12,37 +12,35 @@ function makeBuffer(size) {
     buffer.set([++value % 255], i);
   }
 
   return buffer;
 }
 
 function apply_compartment(compartment, data) {
   if (compartment == SAME_COMPARTMENT) {
-    self[data.func](data.args, self);
-    return;
+    return self[data.func](data.args, self);
   }
 
   if (compartment == IFRAME_COMPARTMENT) {
     const iframe = document.querySelector("#iframe").contentWindow;
-    iframe[data.func](data.args, self);
-    return;
+    return iframe[data.func](data.args, self);
   }
 
   ok(false, "Invalid compartment value");
 }
 
 async function test_nativeStream(compartment) {
   info("test_nativeStream");
 
   let r = await fetch('/');
 
-  apply_compartment(compartment,
-                    { func: "test_nativeStream_continue",
-                      args: r });
+  return apply_compartment(compartment,
+                           { func: "test_nativeStream_continue",
+                             args: r });
 }
 
 async function test_nativeStream_continue(r, that) {
   that.ok(r.body instanceof that.ReadableStream, "We have a ReadableStream");
 
   let a = r.clone();
   that.ok(a instanceof that.Response, "We have a cloned Response");
   that.ok(a.body instanceof that.ReadableStream, "We have a ReadableStream");
@@ -55,59 +53,56 @@ async function test_nativeStream_continu
 
   that.ok(blob instanceof Blob, "We have a blob");
   let d = await a.body.getReader().read();
 
   that.ok(!d.done, "We have read something!");
   blob = await b.blob();
 
   that.ok(blob instanceof Blob, "We have a blob");
-
-  that.next();
 }
 
 async function test_timeout(compartment) {
   info("test_timeout");
 
   let blob = new Blob([""]);
   let r = await fetch(URL.createObjectURL(blob));
 
-  apply_compartment(compartment,
-                    { func: "test_timeout_continue",
-                      args: r });
+  return apply_compartment(compartment,
+                           { func: "test_timeout_continue",
+                             args: r });
 }
 
 async function test_timeout_continue(r, that) {
   await r.body.getReader().read();
 
-  setTimeout(() => {
-    r.blob().then(b => {
-      that.ok(false, "We cannot have a blob here!");
-    }, () => {
-      that.ok(true, "We cannot have a blob here!");
-    }).then(() => {
-      that.next();
-    });
-  }, 0);
+  await new Promise(resolve => setTimeout(resolve, 0));
+
+  try {
+    await r.blob();
+    that.ok(false, "We cannot have a blob here!");
+  } catch (exc) {
+    that.ok(true, "We cannot have a blob here!");
+  }
 }
 
 async function test_nonNativeStream(compartment) {
   info("test_nonNativeStream");
 
   let buffer = makeBuffer(BIG_BUFFER_SIZE);
   info("Buffer size: " + buffer.byteLength);
 
   let r = new Response(new ReadableStream({start : controller => {
     controller.enqueue(buffer);
     controller.close();
   }}));
 
-  apply_compartment(compartment,
-                    { func: "test_nonNativeStream_continue",
-                      args: { r, buffer } });
+  return apply_compartment(compartment,
+                           { func: "test_nonNativeStream_continue",
+                             args: { r, buffer } });
 }
 
 async function test_nonNativeStream_continue(data, that) {
   that.ok(data.r.body instanceof that.ReadableStream, "We have a ReadableStream");
 
   let a = data.r.clone();
   that.ok(a instanceof that.Response, "We have a cloned Response");
   that.ok(a.body instanceof that.ReadableStream, "We have a ReadableStream");
@@ -121,95 +116,90 @@ async function test_nonNativeStream_cont
   that.ok(blob instanceof Blob, "We have a blob");
   let d = await a.body.getReader().read();
 
   that.ok(!d.done, "We have read something!");
   blob = await b.blob();
 
   that.ok(blob instanceof Blob, "We have a blob");
   that.is(blob.size, data.buffer.byteLength, "Blob size matches");
-
-  that.next();
 }
 
 async function test_noUint8Array(compartment) {
   info("test_noUint8Array");
 
   let r = new Response(new ReadableStream({start : controller => {
     controller.enqueue('hello world!');
     controller.close();
   }}));
 
-  apply_compartment(compartment,
-                    { func: "test_noUint8Array_continue",
-                      args: r });
+  return apply_compartment(compartment,
+                           { func: "test_noUint8Array_continue",
+                             args: r });
 }
 
 async function test_noUint8Array_continue(r, that) {
   that.ok(r.body instanceof that.ReadableStream, "We have a ReadableStream");
 
-  r.blob().then(b => {
+  try {
+    await r.blob();
     that.ok(false, "We cannot have a blob here!");
-  }, () => {
+  } catch {
     that.ok(true, "We cannot have a blob here!");
-  }).then(that.next);
+  }
 }
 
 async function test_pendingStream(compartment) {
   let r = new Response(new ReadableStream({start : controller => {
     controller.enqueue(makeBuffer(BIG_BUFFER_SIZE));
     // Let's keep this controler open.
     self.ccc = controller;
   }}));
 
-  apply_compartment(compartment,
-                    { func: "test_pendingStream_continue",
-                      args: r });
+  return apply_compartment(compartment,
+                           { func: "test_pendingStream_continue",
+                             args: r });
 }
 
 async function test_pendingStream_continue(r, that) {
   let d = await r.body.getReader().read();
 
   that.ok(!d.done, "We have read something!");
 
   if ("close" in that) {
     that.close();
   }
-
-  that.next();
 }
 
 async function test_nativeStream_cache(compartment) {
   info("test_nativeStream_cache");
 
   let origBody = '123456789abcdef';
   let url = '/nativeStream';
 
   let cache = await caches.open('nativeStream');
 
   info("Storing a body as a string");
   await cache.put(url, new Response(origBody));
 
-  apply_compartment(compartment,
-                    { func: "test_nativeStream_cache_continue",
-                      args: { caches, cache, url, origBody } });
+  return apply_compartment(compartment,
+                           { func: "test_nativeStream_cache_continue",
+                             args: { caches, cache, url, origBody } });
 }
 
 async function test_nativeStream_cache_continue(data, that) {
   that.info("Retrieving the stored value");
   let cacheResponse = await data.cache.match(data.url);
 
   that.info("Converting the response to text");
   let cacheBody = await cacheResponse.text();
 
   that.is(data.origBody, cacheBody, "Bodies match");
 
   await data.caches.delete('nativeStream');
-
-  that.next();
 };
 
 async function test_nonNativeStream_cache(compartment) {
   info("test_nonNativeStream_cache");
 
   let url = '/nonNativeStream';
 
   let cache = await caches.open('nonNativeStream');
@@ -217,19 +207,19 @@ async function test_nonNativeStream_cach
   info("Buffer size: " + buffer.byteLength);
 
   info("Storing a body as a string");
   let r = new Response(new ReadableStream({start : controller => {
     controller.enqueue(buffer);
     controller.close();
   }}));
 
-  apply_compartment(compartment,
-                    { func: "test_nonNativeStream_cache_continue",
-                      args: { caches, cache, buffer, r } });
+  return apply_compartment(compartment,
+                           { func: "test_nonNativeStream_cache_continue",
+                             args: { caches, cache, buffer, r } });
 }
 
 async function test_nonNativeStream_cache_continue(data, that) {
   await data.cache.put(data.url, data.r);
 
   that.info("Retrieving the stored value");
   let cacheResponse = await data.cache.match(data.url);
 
@@ -240,35 +230,33 @@ async function test_nonNativeStream_cach
   that.is(cacheBody.byteLength, BIG_BUFFER_SIZE, "Body length is correct");
 
   let value = 0;
   for (let i = 0; i < 1000000; i+= 1000) {
     that.is(new Uint8Array(cacheBody)[i], ++value % 255, "byte in position " + i + " is correct");
   }
 
   await data.caches.delete('nonNativeStream');
-
-  that.next();
 };
 
 async function test_codeExecution(compartment) {
   info("test_codeExecution");
 
   let r = new Response(new ReadableStream({
     start(c) {
       controller = c
     },
     pull() {
       console.log("pull called");
     }
   }));
 
-  apply_compartment(compartment,
-                    { func: "test_codeExecution_continue",
-                      args: r });
+  return apply_compartment(compartment,
+                           { func: "test_codeExecution_continue",
+                             args: r });
 }
 
 async function test_codeExecution_continue(r, that) {
   function consoleListener() {
     that.SpecialPowers.addObserver(this, "console-api-log-event");
   }
 
   var promise = new Promise(resolve => {
@@ -286,18 +274,16 @@ async function test_codeExecution_contin
       }
     }
   });
 
   var cl = new consoleListener();
 
   r.body.getReader().read();
   await promise;
-
-  that.next();
 };
 
 async function test_global(compartment) {
   info("test_global: " + compartment);
 
   self.foo = 42;
   self.iter = ITER_MAX;
 
@@ -315,50 +301,53 @@ async function test_global(compartment) 
       self.controller.enqueue(buffer);
 
       if (--self.iter == 0) {
         controller.close();
       }
     }
   }));
 
-  apply_compartment(compartment,
-                    { func: "test_global_continue",
-                    args: r });
+  return apply_compartment(compartment,
+                           { func: "test_global_continue",
+                             args: r });
 }
 
 async function test_global_continue(r, that) {
   let a = await r.arrayBuffer();
 
   that.is(Object.getPrototypeOf(a), that.ArrayBuffer.prototype, "Body is an array buffer");
   that.is(a.byteLength, ITER_MAX, "Body length is correct");
 
   for (let i = 0; i < ITER_MAX; ++i) {
     that.is(new Uint8Array(a)[i], 42, "Byte " + i + " is correct");
   }
-
-  that.next();
 };
 
 function workify(func) {
-  info("Workifing " + func);
+  info("Workifying " + func);
 
-  let worker = new Worker('worker_readableStreams.js');
-  worker.postMessage(func);
-  worker.onmessage = function(e) {
-    if (e.data.type == 'done') {
-      next();
-      return;
-    }
+  return new Promise((resolve, reject) => {
+    let worker = new Worker('worker_readableStreams.js');
+    worker.postMessage(func);
+    worker.onmessage = function(e) {
+      if (e.data.type == 'done') {
+        resolve();
+        return;
+      }
 
-    if (e.data.type == 'test') {
-      ok(e.data.test, e.data.message);
-      return;
-    }
+      if (e.data.type == 'error') {
+        reject(e.data.message);
+        return;
+      }
 
-    if (e.data.type == 'info') {
-      info(e.data.message);
-      return;
+      if (e.data.type == 'test') {
+        ok(e.data.test, e.data.message);
+        return;
+      }
+
+      if (e.data.type == 'info') {
+        info(e.data.message);
+        return;
+      }
     }
-  }
-
-  return worker;
+  });
 }
--- a/dom/tests/mochitest/fetch/iframe_readableStreams.html
+++ b/dom/tests/mochitest/fetch/iframe_readableStreams.html
@@ -1,4 +1,4 @@
 <script type="application/javascript" src="common_readableStreams.js"></script>
 <script>
-parent.next();
+parent.runTests();
 </script>
--- a/dom/tests/mochitest/fetch/test_readableStreams.html
+++ b/dom/tests/mochitest/fetch/test_readableStreams.html
@@ -5,69 +5,67 @@
   <title>Test for ReadableStreams and Fetch</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="common_readableStreams.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
   <script type="application/javascript">
 
-let tests = [
-  function() {
-    SpecialPowers.pushPrefEnv({
-      "set": [["dom.caches.enabled", true],
-              ["dom.caches.testing.enabled", true],
-              ["dom.quotaManager.testing", true]]
-    }, next);
-  },
+async function tests() {
+  await SpecialPowers.pushPrefEnv({
+    "set": [["dom.caches.enabled", true],
+            ["dom.caches.testing.enabled", true],
+            ["dom.quotaManager.testing", true]]
+  });
+
+  await test_nativeStream(SAME_COMPARTMENT);
+  await test_nativeStream(IFRAME_COMPARTMENT);
+  await workify('test_nativeStream');
 
-  function() { test_nativeStream(SAME_COMPARTMENT); },
-  function() { test_nativeStream(IFRAME_COMPARTMENT); },
-  function() { workify('test_nativeStream'); },
-
-  function() { test_timeout(SAME_COMPARTMENT); },
-  function() { test_timeout(IFRAME_COMPARTMENT); },
-  function() { workify('test_timeout'); },
+  await test_timeout(SAME_COMPARTMENT);
+  await test_timeout(IFRAME_COMPARTMENT);
+  await workify('test_timeout');
 
-  function() { test_nonNativeStream(SAME_COMPARTMENT); },
-  function() { test_nonNativeStream(IFRAME_COMPARTMENT); },
-  function() { workify('test_nonNativeStream'); },
+  await test_nonNativeStream(SAME_COMPARTMENT);
+  await test_nonNativeStream(IFRAME_COMPARTMENT);
+  await workify('test_nonNativeStream');
 
-  function() { test_pendingStream(SAME_COMPARTMENT); },
-  function() { test_pendingStream(IFRAME_COMPARTMENT); },
-  function() { workify('test_pendingStream'); },
+  await test_pendingStream(SAME_COMPARTMENT);
+  await test_pendingStream(IFRAME_COMPARTMENT);
+  await workify('test_pendingStream');
 
-  function() { test_noUint8Array(SAME_COMPARTMENT); },
-  function() { test_noUint8Array(IFRAME_COMPARTMENT); },
-  function() { workify('test_noUint8Array'); },
+  await test_noUint8Array(SAME_COMPARTMENT);
+  await test_noUint8Array(IFRAME_COMPARTMENT);
+  await workify('test_noUint8Array');
 
-  function() { test_nativeStream_cache(SAME_COMPARTMENT); },
-  function() { test_nativeStream_cache(IFRAME_COMPARTMENT); },
-  function() { workify('test_nativeStream_cache'); },
+  await test_nativeStream_cache(SAME_COMPARTMENT);
+  await test_nativeStream_cache(IFRAME_COMPARTMENT);
+  await workify('test_nativeStream_cache');
 
-  function() { test_nonNativeStream_cache(SAME_COMPARTMENT); },
-  function() { test_nonNativeStream_cache(IFRAME_COMPARTMENT); },
-  function() { workify('test_nonNativeStream_cache'); },
+  await test_nonNativeStream_cache(SAME_COMPARTMENT);
+  await test_nonNativeStream_cache(IFRAME_COMPARTMENT);
+  await workify('test_nonNativeStream_cache');
 
-  function() { test_codeExecution(SAME_COMPARTMENT); },
-  function() { test_codeExecution(IFRAME_COMPARTMENT); },
+  await test_codeExecution(SAME_COMPARTMENT);
+  await test_codeExecution(IFRAME_COMPARTMENT);
 
-  function() { test_global(SAME_COMPARTMENT); },
-  function() { test_global(IFRAME_COMPARTMENT); },
-  function() { workify('test_global'); },
-];
+  await test_global(SAME_COMPARTMENT);
+  await test_global(IFRAME_COMPARTMENT);
+  await workify('test_global');
+}
 
-function next() {
-  if (!tests.length) {
+async function runTests() {
+  try {
+    await tests();
+  } catch (exc) {
+    ok(false, exc.toString());
+  } finally {
     SimpleTest.finish();
-    return;
   }
-
-  let test = tests.shift();
-  test();
 }
 
 SimpleTest.waitForExplicitFinish();
 // The iframe starts the tests by calling parent.next() when it loads.
   </script>
   <iframe src="iframe_readableStreams.html" id="iframe"></iframe>
 </body>
 </html>
--- a/dom/tests/mochitest/fetch/worker_readableStreams.js
+++ b/dom/tests/mochitest/fetch/worker_readableStreams.js
@@ -7,15 +7,17 @@ function info(message) {
 function ok(a, message) {
   postMessage({type: 'test', test: !!a, message });
 }
 
 function is(a, b, message) {
   ok(a === b, message);
 }
 
-function next() {
-  postMessage({type: 'done'});
+onmessage = function(e) {
+  self[e.data](SAME_COMPARTMENT).then(ok => {
+    postMessage({type: 'done'});
+  }, exc => {
+    dump(exc);
+    dump(exc.stack);
+    postMessage({type: 'error', message: exc.toString()});
+  });
 }
-
-onmessage = function(e) {
-  self[e.data](SAME_COMPARTMENT);
-}