2017-10-23 17:42:01 +00:00
|
|
|
const {name} = browser.runtime.getManifest();
|
|
|
|
|
2018-05-14 18:38:21 +00:00
|
|
|
async function runTest() {
|
|
|
|
let reply;
|
|
|
|
reply = await browser.runtime.sendMessage("test - sendMessage with returned Promise reply");
|
|
|
|
console.log(name, "test - returned resolved Promise - received", reply);
|
|
|
|
|
|
|
|
reply = await browser.runtime.sendMessage("test - sendMessage with returned value reply");
|
|
|
|
console.log(name, "test - returned value - received", reply);
|
|
|
|
|
|
|
|
reply = await browser.runtime.sendMessage("test - sendMessage with synchronous sendResponse");
|
|
|
|
console.log(name, "test - synchronous sendResponse - received", reply);
|
|
|
|
|
|
|
|
reply = await browser.runtime.sendMessage("test - sendMessage with asynchronous sendResponse");
|
|
|
|
console.log(name, "test - asynchronous sendResponse - received", reply);
|
|
|
|
|
|
|
|
reply = await browser.runtime.sendMessage("test - second listener if the first does not reply");
|
|
|
|
console.log(name, "test - second listener sendResponse - received", reply);
|
|
|
|
|
|
|
|
console.log(name, "content script messages sent");
|
|
|
|
}
|
|
|
|
|
2017-10-23 17:42:01 +00:00
|
|
|
console.log(name, "content script loaded");
|
|
|
|
|
2018-05-14 18:38:21 +00:00
|
|
|
runTest().catch((err) => {
|
|
|
|
console.error("content script error", err);
|
2017-10-23 17:42:01 +00:00
|
|
|
});
|
2018-05-14 17:02:59 +00:00
|
|
|
|
|
|
|
test("sendMessage with returned rejected Promise with Error value", async (t) => {
|
|
|
|
try {
|
|
|
|
const reply = await browser.runtime.sendMessage(
|
|
|
|
"test - sendMessage with returned rejected Promise with Error value");
|
|
|
|
t.fail(`Unexpected successfully reply while expecting a rejected promise`);
|
|
|
|
t.equal(reply, undefined, "Unexpected successfully reply");
|
|
|
|
} catch (err) {
|
|
|
|
t.equal(err.message, "rejected-error-value", "Got an error rejection with the expected message");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test("sendMessage with returned rejected Promise with non-Error value", async (t) => {
|
|
|
|
try {
|
|
|
|
const reply = await browser.runtime.sendMessage(
|
|
|
|
"test - sendMessage with returned rejected Promise with non-Error value");
|
|
|
|
t.fail(`Unexpected successfully reply while expecting a rejected promise`);
|
|
|
|
t.equal(reply, undefined, "Unexpected successfully reply");
|
|
|
|
} catch (err) {
|
|
|
|
// Unfortunately Firefox currently reject an error with an undefined
|
|
|
|
// message, in the meantime we just check that the object rejected is
|
|
|
|
// an instance of Error.
|
|
|
|
t.ok(err instanceof Error, "Got an error object as expected");
|
|
|
|
}
|
|
|
|
});
|