Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

  • This WPT test may be referenced by the following Test IDs:
<!DOCTYPE html>
<title>link stylesheet with error HTTP status should fire error event and not apply styles</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<div id="target404">Test element for 404</div>
<div id="target503">Test element for 503</div>
<script>
"use strict";
async_test(t => {
const target = document.getElementById("target404");
const initialColor = getComputedStyle(target).color;
const link = document.createElement("link");
link.rel = "stylesheet";
link.onerror = t.step_func_done(() => {
assert_equals(
getComputedStyle(target).color,
initialColor,
"CSS should not be applied from 404 response"
);
});
link.onload = t.step_func(() => {
assert_unreached("load event should not fire for 404 response");
});
link.href = "resources/stylesheet-colors.css?pipe=status(404)";
document.head.append(link);
}, "link stylesheet should fire error event for 404 response and not apply styles");
async_test(t => {
const target = document.getElementById("target503");
const initialColor = getComputedStyle(target).color;
const link = document.createElement("link");
link.rel = "stylesheet";
link.onerror = t.step_func_done(() => {
assert_equals(
getComputedStyle(target).color,
initialColor,
"CSS should not be applied from 503 response"
);
});
link.onload = t.step_func(() => {
assert_unreached("load event should not fire for 503 response");
});
link.href = "resources/stylesheet-colors.css?pipe=status(503)";
document.head.append(link);
}, "link stylesheet should fire error event for 503 response and not apply styles");
</script>
</body>