Bug 1406695 - Fail if a browser.test.onMessage handler throws an error. r=aswan
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sat, 07 Oct 2017 19:24:32 +0900
changeset 679149 6f83e51a6d78b812e9dac2ae3c3638af1b0c86c1
parent 679148 3cd2fab7b31ffe5e8c89cf9632f1ed6c8b3651f4
child 679150 a337a84a9160784eaac60956aac72fc891c4579e
push id84141
push userbmo:schien@mozilla.com
push dateThu, 12 Oct 2017 11:13:04 +0000
reviewersaswan
bugs1406695
milestone58.0a1
Bug 1406695 - Fail if a browser.test.onMessage handler throws an error. r=aswan MozReview-Commit-ID: BXOrdtla1qE
toolkit/components/extensions/ext-c-test.js
--- a/toolkit/components/extensions/ext-c-test.js
+++ b/toolkit/components/extensions/ext-c-test.js
@@ -80,16 +80,28 @@ this.test = class extends ExtensionAPI {
     function getStack() {
       return new context.cloneScope.Error().stack.replace(/^/gm, "    ");
     }
 
     function assertTrue(value, msg) {
       extension.emit("test-result", Boolean(value), String(msg), getStack());
     }
 
+    class TestEventManager extends EventManager {
+      addListener(callback, ...args) {
+        super.addListener(function(...args) {
+          try {
+            callback.call(this, ...args);
+          } catch (e) {
+            assertTrue(false, `${e}\n${e.stack}`);
+          }
+        }, ...args);
+      }
+    }
+
     return {
       test: {
         sendMessage(...args) {
           extension.emit("test-message", ...args);
         },
 
         notifyPass(msg) {
           extension.emit("test-done", true, msg, getStack());
@@ -163,17 +175,17 @@ this.test = class extends ExtensionAPI {
             let errorMessage = toSource(error && error.message);
 
             assertTrue(errorMatches(error, expectedError, context),
                        `Function threw, expecting error to match ${toSource(expectedError)}` +
                        `got ${errorMessage}${msg}`);
           }
         },
 
-        onMessage: new EventManager(context, "test.onMessage", fire => {
+        onMessage: new TestEventManager(context, "test.onMessage", fire => {
           let handler = (event, ...args) => {
             fire.async(...args);
           };
 
           extension.on("test-harness-message", handler);
           return () => {
             extension.off("test-harness-message", handler);
           };