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.
This commit is contained in:
Timothy Flynn 2024-10-02 12:58:07 -04:00 committed by Tim Flynn
parent 96082d6ae1
commit c9cbaeb59d
Notes: github-actions[bot] 2024-10-03 11:08:36 +00:00
10 changed files with 32 additions and 12 deletions

View file

@ -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>

View file

@ -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");

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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);
});