Files
ladybird/Tests/LibWeb/Text/input/link-element-rel-preload-load-event.html
Aliaksandr Kalenik 5bbf2ddc5b Tests: Make preload link load/error event test order-independent
This changes `link-element-rel-preload-load-event.html`, so the test no
longer depends on the relative ordering of load and error events.

This is required for the upcoming change that makes fetching unbuffered
by default, as the test would otherwise become flaky.
2025-11-20 06:29:13 -05:00

42 lines
1.2 KiB
HTML

<!DOCTYPE html>
<script src="include.js"></script>
<script>
asyncTest(done => {
const logs = [];
const printLogs = () => {
logs.sort();
for (const log of logs) {
println(log);
}
};
let goodLink = document.createElement("link");
goodLink.setAttribute("rel", "preload");
goodLink.setAttribute("href", "valid.css");
goodLink.setAttribute("as", "style");
goodLink.addEventListener("load", function () {
logs.push("Got load event");
if (logs.length == 2) {
printLogs();
done();
}
});
document.head.appendChild(goodLink);
let badLink = document.createElement("link");
badLink.setAttribute("rel", "preload");
badLink.setAttribute("href", "this-file-does-not-exist-and-so-is-invalid.css");
badLink.setAttribute("as", "style");
badLink.addEventListener("error", function () {
logs.push("Got error event");
if (logs.length == 2) {
printLogs();
done();
}
});
document.head.appendChild(badLink);
});
</script>