mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-02 16:33:13 +00:00
70 lines
1.8 KiB
JavaScript
70 lines
1.8 KiB
JavaScript
var __outputElement = null;
|
|
let __alreadyCalledTest = false;
|
|
function __preventMultipleTestFunctions() {
|
|
if (__alreadyCalledTest) {
|
|
throw new Error("You must only call test() or asyncTest() once per page");
|
|
}
|
|
__alreadyCalledTest = true;
|
|
}
|
|
|
|
if (globalThis.internals === undefined) {
|
|
internals = {
|
|
signalTextTestIsDone: function () {},
|
|
};
|
|
}
|
|
|
|
function println(s) {
|
|
__outputElement.appendChild(document.createTextNode(s + "\n"));
|
|
}
|
|
|
|
function printElement(e) {
|
|
let element_string = `<${e.nodeName} `;
|
|
if (e.id) element_string += `id="${e.id}" `;
|
|
element_string += ">";
|
|
println(element_string);
|
|
}
|
|
|
|
function animationFrame() {
|
|
const { promise, resolve } = Promise.withResolvers();
|
|
requestAnimationFrame(resolve);
|
|
return promise;
|
|
}
|
|
|
|
function timeout(ms) {
|
|
const { promise, resolve } = Promise.withResolvers();
|
|
setTimeout(resolve, ms);
|
|
return promise;
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
__outputElement = document.createElement("pre");
|
|
__outputElement.setAttribute("id", "out");
|
|
document.body.appendChild(__outputElement);
|
|
});
|
|
|
|
function test(f) {
|
|
__preventMultipleTestFunctions();
|
|
document.addEventListener("DOMContentLoaded", f);
|
|
window.addEventListener("load", () => {
|
|
internals.signalTextTestIsDone();
|
|
});
|
|
}
|
|
|
|
function asyncTest(f) {
|
|
const done = () => {
|
|
__preventMultipleTestFunctions();
|
|
internals.signalTextTestIsDone();
|
|
};
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
f(done);
|
|
});
|
|
}
|
|
|
|
function promiseTest(f) {
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
f().then(() => {
|
|
__preventMultipleTestFunctions();
|
|
internals.signalTextTestIsDone();
|
|
});
|
|
});
|
|
}
|