Closed Bug 1642671 Opened 8 months ago Closed 8 months ago

Add test to verify that falsey return values from runtime.onMessage are not ignored


(WebExtensions :: General, defect, P1)



(firefox79 fixed)

Tracking Status
firefox79 --- fixed


(Reporter: robwu, Assigned: robwu)



(1 file)

This doesn't look right:

A consequence of the value && value check is that falsey return values are ignored, and the caller will receive undefined due to the ultimate fallback.

I'll fix this and add some tests.

I was mistaken about the meaning of that line.

zombie clarified: that's not a bug, that listener returns an array of response values, or undefined if there are no listeners.

This bug is only about writing tests then, if we don't have them already.

No longer regressed by: 1583484
Summary: falsey return values from runtime.onMessage are ignored → Add test to verify that falsey return values from runtime.onMessage are not ignored

I patched MessageEvent.emit by triggering a failure when runtime.onMessage's callback returns a falsey value other than undefined. Surprisingly out of all extension tests, only one test failed, because its onMessage handler coincidentally received a null value. The caller didn't check the returned result though. So I have added a test to make sure that we have sufficient coverage for the scenario of receiving a falsey result in onMessage.

This is the patch that I used to run the check:

diff --git a/toolkit/components/extensions/ExtensionChild.jsm b/toolkit/components/extensions/ExtensionChild.jsm
index a9e8a2c576576..14a1b2462f579 100644
--- a/toolkit/components/extensions/ExtensionChild.jsm
+++ b/toolkit/components/extensions/ExtensionChild.jsm
@@ -181,6 +181,17 @@ class MessageEvent extends SimpleEventAPI {
       .map(fire => this.wrapResponse(fire, message, sender))
       .filter(x => x !== undefined);
+    const abort = (msg) => {
+      (this.context.chromeObj || this.context.cloneScope.wrappedJSObject.browser);
+    };
+    all.forEach(x => {
+      if (x && x instanceof Promise) {
+        x.then(v => {
+          v || v === undefined || abort("FALSEY??? " + v);
+        }, () => {});
+      }
+    });
     return all.length ? Promise.race(all).then(v => [v]) : [];

Pushed by
Add tests for falsey result from runtime.onMessage r=zombie,geckoview-reviewers,agi
Closed: 8 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla79
You need to log in before you can comment on or make changes to this bug.