Bug 1305444 - Add test for dispatched method throwing an error; r=Yoric
authorGregory Szorc <gps@mozilla.com>
Sat, 24 Sep 2016 19:31:48 -0700
changeset 315390 a75885a39701e5c29b16da7dd0406691e53e850f
parent 315389 87ebfcabb99ac1d7f85b10a595331377cbc3be2e
child 315391 8a0d7d0adf236ad9ddca4996d0c8b90dc2140203
push id30748
push usercbook@mozilla.com
push dateWed, 28 Sep 2016 13:53:19 +0000
treeherdermozilla-central@8c84b7618840 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1305444
milestone52.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 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");
+  }
+});