mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:47:34 +00:00
Base: Add a test page for async functions + XMLHttpRequest
This commit is contained in:
parent
ccf713bf23
commit
0652774783
2 changed files with 57 additions and 0 deletions
56
Base/res/html/misc/async-js.html
Normal file
56
Base/res/html/misc/async-js.html
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Async JavaScript function test page</title>
|
||||||
|
<style>
|
||||||
|
.pass {
|
||||||
|
background-color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fail {
|
||||||
|
background-color: red;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script>
|
||||||
|
responseText = "";
|
||||||
|
|
||||||
|
async function loadFromURL(url) {
|
||||||
|
let result = await new Promise((resolve, reject) => {
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("GET", url);
|
||||||
|
xhr.addEventListener("load", function () {
|
||||||
|
if (this.status >= 200 && this.status <= 299)
|
||||||
|
resolve(this.responseText);
|
||||||
|
else
|
||||||
|
reject();
|
||||||
|
});
|
||||||
|
xhr.addEventListener("error", () => reject());
|
||||||
|
xhr.send();
|
||||||
|
});
|
||||||
|
responseText = result;
|
||||||
|
document.getElementById("response-text").innerText = responseText;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function testURL(url) {
|
||||||
|
responseText = "";
|
||||||
|
let shouldBeEmpty = false;
|
||||||
|
try {
|
||||||
|
await loadFromURL(url);
|
||||||
|
} catch {
|
||||||
|
shouldBeEmpty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((responseText !== "") ^ shouldBeEmpty)
|
||||||
|
document.getElementById("result").innerHTML = "<p class=pass>PASS!</p>";
|
||||||
|
else
|
||||||
|
document.getElementById("result").innerHTML = "<p class=fail>FAIL!</p>";
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<input id="url" type="text" value="http://man.serenityos.org/man4/zero.html">
|
||||||
|
<a href="javascript:testURL(document.getElementById('url').value)">Click me for fun</a>
|
||||||
|
<br>
|
||||||
|
<div id="result"></div>
|
||||||
|
<pre id="response-text"></pre>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -147,6 +147,7 @@
|
||||||
<li><a href="set-interval.html">setInterval()</a></li>
|
<li><a href="set-interval.html">setInterval()</a></li>
|
||||||
<li><a href="location.html">window.location property</a></li>
|
<li><a href="location.html">window.location property</a></li>
|
||||||
<li><a href="script-preparation-test.html">Test for the early return steps 6-8 of the "prepare a script" algorithm</a></li>
|
<li><a href="script-preparation-test.html">Test for the early return steps 6-8 of the "prepare a script" algorithm</a></li>
|
||||||
|
<li><a href="async-js.html">Basic test for async functions and their integration with the LibWeb event loop</a></li>
|
||||||
<li><h3>Canvas</h3></li>
|
<li><h3>Canvas</h3></li>
|
||||||
<li><a href="canvas.html">canvas 2D test</a></li>
|
<li><a href="canvas.html">canvas 2D test</a></li>
|
||||||
<li><a href="canvas-rotate.html">canvas rotate()</a></li>
|
<li><a href="canvas-rotate.html">canvas rotate()</a></li>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue