Bug 1305444 - Add test for dispatched method throwing an error; r?Yoric draft
authorGregory Szorc <gps@mozilla.com>
Sat, 24 Sep 2016 19:31:48 -0700
changeset 417660 a9602a88ed5fde307f5b9c58d5913c4cd27d7bc8
parent 417659 e2bf76dd2b69a5f1d845c6b49124048f78cced37
child 532133 07acb332af8514f2fe739d15a48726e042404cc7
push id30450
push userbmo:gps@mozilla.com
push dateMon, 26 Sep 2016 15:33:36 +0000
reviewersYoric
bugs1305444
milestone52.0a1
Bug 1305444 - Add test for dispatched method throwing an error; r?Yoric We didn't have explicit test coverage of this before, surprisingly. MozReview-Commit-ID: 32ZnxZYLXDg
toolkit/components/promiseworker/tests/xpcshell/data/worker.js
toolkit/components/promiseworker/tests/xpcshell/test_Promise.js
--- a/toolkit/components/promiseworker/tests/xpcshell/data/worker.js
+++ b/toolkit/components/promiseworker/tests/xpcshell/data/worker.js
@@ -21,10 +21,14 @@ worker.close = function() {
 worker.log = function(...args) {
   dump("Worker: " + args.join(" ") + "\n");
 };
 self.addEventListener("message", msg => worker.handleMessage(msg));
 
 var Agent = {
   bounce: function(...args) {
     return args;
-  }
+  },
+
+  throwError: function(msg, ...args) {
+     throw new Error(msg);
+  },
 };
--- a/toolkit/components/promiseworker/tests/xpcshell/test_Promise.js
+++ b/toolkit/components/promiseworker/tests/xpcshell/test_Promise.js
@@ -101,8 +101,17 @@ add_task(function* test_transfer_with_me
   Assert.equal(Object.prototype.toString.call(result), "[object Uint8Array]",
                "The result appears to be a Typed Array");
   Assert.equal(result.byteLength, 4, "The result has the right size");
 
   for (let i = 0; i < 4; ++i) {
     Assert.equal(result[i], i);
   }
 });
+
+add_task(function* test_throw_error() {
+  try {
+    yield worker.post("throwError", ["error message"]);
+    Assert.ok(false, "should have thrown");
+  } catch (ex) {
+    Assert.equal(ex.message, "Error: error message");
+  }
+});