Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
-
CI results over the last 21 days
- This test gets skipped with pattern: !nightly_build
- Manifest: dom/promise/tests/mochitest.toml
<!DOCTYPE HTML>
<!-- Any copyright is dedicated to the Public Domain.
<html>
<head>
<meta charset="utf-8">
<title>Safe promise resolution warns once per document</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
</head>
<body>
<script>
async function checkWarnings(action, expected) {
let count = 0;
const checked = new Promise(resolve => {
SpecialPowers.registerConsoleListener(message => {
if (message.message === "SENTINEL") {
resolve();
} else if (message.message?.includes("The execution of microtasks on this page")) {
count++;
ok(message.isWarning, "The diagnostic is a warning");
}
});
});
await action();
SpecialPowers.postConsoleSentinel();
await checked;
is(count, expected, "Expected number of safe resolution warnings");
}
async function loadFrame(frame) {
const loaded = new Promise(resolve => {
frame.addEventListener("load", resolve, { once: true });
});
frame.srcdoc = "<!DOCTYPE html><title>Promise resolution target</title>";
await loaded;
}
add_task(async function test_warning_lifetime() {
await SpecialPowers.pushPrefEnv({
set: [["dom.promise.experimental_safe_resolve", true]],
});
const frame = document.createElement("iframe");
document.body.appendChild(frame);
await loadFrame(frame);
const fetchResponse = () => frame.contentWindow.fetch("data:text/plain,ok");
const deferResolution = () => {
Object.defineProperty(frame.contentWindow.Response.prototype, "then", {
configurable: true,
get() { return undefined; },
});
};
await checkWarnings(fetchResponse, 0);
deferResolution();
await checkWarnings(fetchResponse, 1);
await checkWarnings(async () => {
await fetchResponse();
await fetchResponse();
}, 0);
await loadFrame(frame);
deferResolution();
await checkWarnings(fetchResponse, 1);
frame.remove();
});
</script>
</body>
</html>