ladybird/Tests/LibWeb/Text/input/test-http-test-server.html
Cory Virok 39f844f77c LibWeb/Tests: Added example test for how to use http-test-server.py
The example shows how to write a test that depends on custom HTTP
headers in the response. This will be useful for testing browser JS
that depends on how Ladybird processes response headers, eg CORS
headers like Access-Control-Allow-Origin and others.
2024-11-09 13:08:31 -07:00

29 lines
1 KiB
HTML

<script src="./include.js"></script>
<script>
asyncTest(async (done) => {
try {
const httpServer = httpTestServer();
const url = await httpServer.createEcho("GET", "/test-http-test-server", {
status: 200,
headers: {
"Access-Control-Allow-Origin": "*", // necessary when running test using file://...
"Access-Control-Expose-Headers": "X-Custom-Header", // tells the browser which headers to expose to JS
"Content-Type": "text/plain",
"X-Custom-Header": "well hello friends",
},
body: "hello world!",
});
const result = await fetch(url);
const headers = result.headers;
if (headers.get("X-Custom-Header") === "well hello friends") {
println("PASS");
} else {
println("FAIL");
}
} catch (err) {
println("FAIL - " + err);
}
done();
});
</script>