Bug 1659074 - Regression tests for undefined/uncloneable error in onMessage r=zombie,geckoview-reviewers,agi

Differential Revision: https://phabricator.services.mozilla.com/D85644
This commit is contained in:
Rob Wu 2020-08-14 10:23:51 +00:00
Родитель 4e78d2ce23
Коммит 8103eaba24
3 изменённых файлов: 111 добавлений и 1 удалений

Просмотреть файл

@ -48,6 +48,19 @@ add_task(async function tabsSendMessageReply() {
.sendMessage(tabId, "throw-error")
.catch(error => Promise.resolve({ error })),
browser.tabs
.sendMessage(tabId, "respond-uncloneable")
.catch(error => Promise.resolve({ error })),
browser.tabs
.sendMessage(tabId, "reject-uncloneable")
.catch(error => Promise.resolve({ error })),
browser.tabs
.sendMessage(tabId, "reject-undefined")
.catch(error => Promise.resolve({ error })),
browser.tabs
.sendMessage(tabId, "throw-undefined")
.catch(error => Promise.resolve({ error })),
browser.tabs
.sendMessage(firstTab, "no-listener")
.catch(error => Promise.resolve({ error })),
@ -65,6 +78,10 @@ add_task(async function tabsSendMessageReply() {
respondNever2,
respondError,
throwError,
respondUncloneable,
rejectUncloneable,
rejectUndefined,
throwUndefined,
noListener,
]) => {
browser.test.assertEq(
@ -125,6 +142,27 @@ add_task(async function tabsSendMessageReply() {
"Got the expected thrown error response"
);
browser.test.assertEq(
"Could not establish connection. Receiving end does not exist.",
respondUncloneable.error.message,
"An uncloneable response should be ignored"
);
browser.test.assertEq(
"An unexpected error occurred",
rejectUncloneable.error.message,
"Got the expected error for a rejection with an uncloneable value"
);
browser.test.assertEq(
"An unexpected error occurred",
rejectUndefined.error.message,
"Got the expected error for a void rejection"
);
browser.test.assertEq(
"An unexpected error occurred",
throwUndefined.error.message,
"Got the expected error for a void throw"
);
browser.test.assertEq(
"Could not establish connection. Receiving end does not exist.",
noListener.error.message,
@ -175,6 +213,14 @@ add_task(async function tabsSendMessageReply() {
return undefined;
} else if (msg == "respond-error") {
return Promise.reject(new Error(msg));
} else if (msg === "respond-uncloneable") {
return Promise.resolve(window);
} else if (msg === "reject-uncloneable") {
return Promise.reject(window);
} else if (msg == "reject-undefined") {
return Promise.reject();
} else if (msg == "throw-undefined") {
throw undefined; // eslint-disable-line no-throw-literal
} else if (msg == "throw-error") {
throw new Error(msg);
}

Просмотреть файл

@ -55,8 +55,13 @@ add_task(async function tabsSendMessageReply() {
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(tabId, "respond-uncloneable").catch(error => Promise.resolve({ error })),
browser.tabs.sendMessage(tabId, "reject-uncloneable").catch(error => Promise.resolve({ error })),
browser.tabs.sendMessage(tabId, "reject-undefined").catch(error => Promise.resolve({ error })),
browser.tabs.sendMessage(tabId, "throw-undefined").catch(error => Promise.resolve({ error })),
browser.tabs.sendMessage(firstTab, "no-listener").catch(error => Promise.resolve({error})),
]).then(([response, respondNow, respondNow2, respondSoon, respondPromise, respondPromiseFalse, respondFalse, respondNever, respondNever2, respondError, throwError, noListener]) => {
]).then(([response, respondNow, respondNow2, respondSoon, respondPromise, respondPromiseFalse, respondFalse, respondNever, respondNever2, respondError, throwError, respondUncloneable, rejectUncloneable, rejectUndefined, throwUndefined, noListener]) => {
browser.test.assertEq("expected-response", response, "Content script got the expected response");
browser.test.assertEq("respond-now", respondNow, "Got the expected immediate response");
@ -71,6 +76,11 @@ add_task(async function tabsSendMessageReply() {
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");
browser.test.assertEq("Could not establish connection. Receiving end does not exist.", respondUncloneable.error.message, "An uncloneable response should be ignored");
browser.test.assertEq("An unexpected error occurred", rejectUncloneable.error.message, "Got the expected error for a rejection with an uncloneable value");
browser.test.assertEq("An unexpected error occurred", rejectUndefined.error.message, "Got the expected error for a void rejection");
browser.test.assertEq("An unexpected error occurred", throwUndefined.error.message, "Got the expected error for a void throw");
browser.test.assertEq("Could not establish connection. Receiving end does not exist.",
noListener.error.message,
"Got the expected no listener response");
@ -112,6 +122,14 @@ add_task(async function tabsSendMessageReply() {
return undefined;
} else if (msg == "respond-error") {
return Promise.reject(new Error(msg));
} else if (msg === "respond-uncloneable") {
return Promise.resolve(window);
} else if (msg === "reject-uncloneable") {
return Promise.reject(window);
} else if (msg == "reject-undefined") {
return Promise.reject();
} else if (msg == "throw-undefined") {
throw undefined; // eslint-disable-line no-throw-literal
} else if (msg == "throw-error") {
throw new Error(msg);
}

Просмотреть файл

@ -30,6 +30,14 @@ add_task(async function runtimeSendMessageReply() {
return Promise.reject(new Error(msg));
} else if (msg == "throw-error") {
throw new Error(msg);
} else if (msg === "respond-uncloneable") {
return Promise.resolve(window);
} else if (msg === "reject-uncloneable") {
return Promise.reject(window);
} else if (msg == "reject-undefined") {
return Promise.reject();
} else if (msg == "throw-undefined") {
throw undefined; // eslint-disable-line no-throw-literal
}
});
@ -79,6 +87,19 @@ add_task(async function runtimeSendMessageReply() {
browser.runtime
.sendMessage("throw-error")
.catch(error => Promise.resolve({ error })),
browser.runtime
.sendMessage("respond-uncloneable")
.catch(error => Promise.resolve({ error })),
browser.runtime
.sendMessage("reject-uncloneable")
.catch(error => Promise.resolve({ error })),
browser.runtime
.sendMessage("reject-undefined")
.catch(error => Promise.resolve({ error })),
browser.runtime
.sendMessage("throw-undefined")
.catch(error => Promise.resolve({ error })),
])
.then(
([
@ -92,6 +113,10 @@ add_task(async function runtimeSendMessageReply() {
respondNever2,
respondError,
throwError,
respondUncloneable,
rejectUncloneable,
rejectUndefined,
throwUndefined,
]) => {
browser.test.assertEq(
"respond-now",
@ -145,6 +170,27 @@ add_task(async function runtimeSendMessageReply() {
"Got the expected thrown error response"
);
browser.test.assertEq(
"Could not establish connection. Receiving end does not exist.",
respondUncloneable.error.message,
"An uncloneable response should be ignored"
);
browser.test.assertEq(
"An unexpected error occurred",
rejectUncloneable.error.message,
"Got the expected error for a rejection with an uncloneable value"
);
browser.test.assertEq(
"An unexpected error occurred",
rejectUndefined.error.message,
"Got the expected error for a void rejection"
);
browser.test.assertEq(
"An unexpected error occurred",
throwUndefined.error.message,
"Got the expected error for a void throw"
);
browser.test.notifyPass("sendMessage");
}
)