LibWeb: Convert some sync tests to be async

The events tested here are decidedly async. We also can't really write
sync tests of the form "test(async () => {})". Nothing will await the
async callback.

(cherry picked from commit c9cbaeb59d6f699b33bf3924688987b3ca917fee)
This commit is contained in:
Timothy Flynn authored and Nico Weber committed 2024-11-24 22:42:15 -05:00
1 parent 8b4b8d914c
commit 0446c98053
10 files changed
+32 -12

No files matched your search

@@ -1,6 +1,6 @@
<script src="../include.js"></script>
<script>
test(() => {
asyncTest(done => {
const data = "param-a=value-a&param-b=value-b&param-c=value-c1&param-c=value-c2";
const response = new Response(data, {
headers: {
@@ -12,6 +12,7 @@
println(formData.get("param-a"));
println(formData.get("param-b"));
println(formData.getAll("param-c"));
done();
});
});
</script>
@@ -1,10 +1,11 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
test(() => {
asyncTest(done => {
const video = document.createElement("video");
video.textTracks.addEventListener("addtrack", () => {
println(`addtrack event called`);
done();
});
const track = video.addTextTrack("subtitles", "demo label", "en-GB");
@@ -1,6 +1,6 @@
<script src="../include.js"></script>
<script>
test(async () => {
asyncTest(async done => {
let dataTransfer = new DataTransfer();
println(`dropEffect: ${dataTransfer.dropEffect}`);
println(`effectAllowed: ${dataTransfer.effectAllowed}`);
@@ -50,5 +50,7 @@
if (dataTransferItemList[2] !== undefined) {
println("FAILED");
}
done();
});
</script>
@@ -18,13 +18,13 @@
}
}
test(async () => {
asyncTest(done => {
const asyncIterable = {
[Symbol.asyncIterator]: asyncGenerator,
};
const readableStream = ReadableStream.from(asyncIterable);
await readStream(readableStream);
readStream(readableStream).then(done);
});
</script>
@@ -7,9 +7,10 @@
<body>
<script src="include.js"></script>
<script>
test(() => {
asyncTest(done => {
window.onload = () => {
println("document background: " + getComputedStyle(document.body).backgroundColor);
done();
};
});
</script>
@@ -5,7 +5,7 @@
</style>
<script src="include.js"></script>
<script>
test(() => {
asyncTest(done => {
let link = document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("href", "body-background-color-red.css");
@@ -14,6 +14,7 @@
window.onload = function () {
println("document background: " + getComputedStyle(document.body).backgroundColor);
done();
};
});
</script>
@@ -6,9 +6,10 @@
<body>
<script src="include.js"></script>
<script>
test(() => {
asyncTest(done => {
window.onload = function () {
println("document background: " + getComputedStyle(document.body).backgroundColor);
done();
};
});
</script>
@@ -6,9 +6,10 @@
<body>
<script src="include.js"></script>
<script>
test(() => {
asyncTest(done => {
window.onload = function () {
println("document background: " + getComputedStyle(document.body).backgroundColor);
done();
};
});
</script>
@@ -1,11 +1,13 @@
<script src="include.js"></script>
<script>
test(() => {
asyncTest(done => {
globalThis.done = done;
let link = document.createElement("link");
link.setAttribute("rel", "preload");
link.setAttribute("href", "valid.css");
link.setAttribute("as", "style");
link.setAttribute("onload", "println('link element onload')");
link.setAttribute("onload", "println('link element onload'); done();");
document.head.appendChild(link);
});
</script>
@@ -1,12 +1,18 @@
<script src="include.js"></script>
<script>
test(() => {
asyncTest(done => {
let eventCount = 0;
let goodLink = document.createElement("link");
goodLink.setAttribute("rel", "preload");
goodLink.setAttribute("href", "valid.css");
goodLink.setAttribute("as", "style");
goodLink.addEventListener("load", function () {
println("Got load event");
if (++eventCount == 2) {
done();
}
});
document.head.appendChild(goodLink);
@@ -16,6 +22,10 @@
badLink.setAttribute("as", "style");
badLink.addEventListener("error", function () {
println("Got error event");
if (++eventCount == 2) {
done();
}
});
document.head.appendChild(badLink);
});