diff --git a/browser/components/extensions/test/browser/browser_ext_tabs_sendMessage.js b/browser/components/extensions/test/browser/browser_ext_tabs_sendMessage.js index 5699813fb7aa..edf0a34283c1 100644 --- a/browser/components/extensions/test/browser/browser_ext_tabs_sendMessage.js +++ b/browser/components/extensions/test/browser/browser_ext_tabs_sendMessage.js @@ -21,11 +21,6 @@ add_task(function* tabsSendMessageReply() { if (msg == "content-script-ready") { let tabId = sender.tab.id; - browser.tabs.sendMessage(tabId, "respond-never", response => { - browser.test.fail(`Got unexpected response callback: ${response}`); - browser.test.notifyFail("sendMessage"); - }); - Promise.all([ promiseResponse, @@ -34,12 +29,15 @@ add_task(function* tabsSendMessageReply() { new Promise(resolve => browser.tabs.sendMessage(tabId, "respond-soon", resolve)), browser.tabs.sendMessage(tabId, "respond-promise"), browser.tabs.sendMessage(tabId, "respond-never"), + new Promise(resolve => { + browser.runtime.sendMessage("respond-never", response => { resolve(response); }); + }), browser.tabs.sendMessage(tabId, "respond-error").catch(error => Promise.resolve({error})), browser.tabs.sendMessage(tabId, "throw-error").catch(error => Promise.resolve({error})), browser.tabs.sendMessage(firstTab, "no-listener").catch(error => Promise.resolve({error})), - ]).then(([response, respondNow, respondNow2, respondSoon, respondPromise, respondNever, respondError, throwError, noListener]) => { + ]).then(([response, respondNow, respondNow2, respondSoon, respondPromise, respondNever, respondNever2, respondError, throwError, noListener]) => { browser.test.assertEq("expected-response", response, "Content script got the expected response"); browser.test.assertEq("respond-now", respondNow, "Got the expected immediate response"); @@ -47,6 +45,7 @@ add_task(function* tabsSendMessageReply() { browser.test.assertEq("respond-soon", respondSoon, "Got the expected delayed response"); browser.test.assertEq("respond-promise", respondPromise, "Got the expected promise response"); browser.test.assertEq(undefined, respondNever, "Got the expected no-response resolution"); + browser.test.assertEq(undefined, respondNever2, "Got the expected no-response resolution"); browser.test.assertEq("respond-error", respondError.error.message, "Got the expected error response"); browser.test.assertEq("throw-error", throwError.error.message, "Got the expected thrown error response"); diff --git a/toolkit/components/extensions/ExtensionUtils.jsm b/toolkit/components/extensions/ExtensionUtils.jsm index f32336a75e29..3372d6702f1b 100644 --- a/toolkit/components/extensions/ExtensionUtils.jsm +++ b/toolkit/components/extensions/ExtensionUtils.jsm @@ -1219,14 +1219,7 @@ Messenger.prototype = { .catch(error => { if (error.result == MessageChannel.RESULT_NO_HANDLER) { return Promise.reject({message: "Could not establish connection. Receiving end does not exist."}); - } else if (error.result == MessageChannel.RESULT_NO_RESPONSE) { - if (responseCallback) { - // As a special case, we don't call the callback variant if we - // receive no response. So return a promise which will never - // resolve. - return new Promise(() => {}); - } - } else { + } else if (error.result != MessageChannel.RESULT_NO_RESPONSE) { return Promise.reject({message: error.message}); } }); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_runtime_sendMessage.js b/toolkit/components/extensions/test/xpcshell/test_ext_runtime_sendMessage.js index a85b7fb7299f..a4298ef527e4 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_runtime_sendMessage.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_runtime_sendMessage.js @@ -29,26 +29,25 @@ add_task(function* tabsSendMessageReply() { } }); - browser.runtime.sendMessage("respond-never", response => { - browser.test.fail(`Got unexpected response callback: ${response}`); - browser.test.notifyFail("sendMessage"); - }); - Promise.all([ browser.runtime.sendMessage("respond-now"), browser.runtime.sendMessage("respond-now-2"), new Promise(resolve => browser.runtime.sendMessage("respond-soon", resolve)), browser.runtime.sendMessage("respond-promise"), browser.runtime.sendMessage("respond-never"), + new Promise(resolve => { + browser.runtime.sendMessage("respond-never", response => { resolve(response); }); + }), browser.runtime.sendMessage("respond-error").catch(error => Promise.resolve({error})), browser.runtime.sendMessage("throw-error").catch(error => Promise.resolve({error})), - ]).then(([respondNow, respondNow2, respondSoon, respondPromise, respondNever, respondError, throwError]) => { + ]).then(([respondNow, respondNow2, respondSoon, respondPromise, respondNever, respondNever2, respondError, throwError]) => { browser.test.assertEq("respond-now", respondNow, "Got the expected immediate response"); browser.test.assertEq("respond-now-2", respondNow2, "Got the expected immediate response from the second listener"); browser.test.assertEq("respond-soon", respondSoon, "Got the expected delayed response"); browser.test.assertEq("respond-promise", respondPromise, "Got the expected promise response"); browser.test.assertEq(undefined, respondNever, "Got the expected no-response resolution"); + browser.test.assertEq(undefined, respondNever2, "Got the expected no-response resolution"); browser.test.assertEq("respond-error", respondError.error.message, "Got the expected error response"); browser.test.assertEq("throw-error", throwError.error.message, "Got the expected thrown error response");