зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1290117: Call sendMessage response callback when there are no replies. r=robwu
MozReview-Commit-ID: 1BYD1CgZmvD --HG-- extra : rebase_source : dc6297a85062c6713fa808f935ec7051d8668dc1 extra : amend_source : e398638f70f95835c7a8f8e94ea6945fa763ccb6
This commit is contained in:
Родитель
78ec753b6f
Коммит
617494218f
|
@ -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");
|
||||
|
|
|
@ -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});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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");
|
||||
|
|
Загрузка…
Ссылка в новой задаче