Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /html/semantics/document-metadata/the-link-element/stylesheet-media-change-no-fetch.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset="utf-8">
<title>stylesheet should not re-fetch when media changes. The media change should apply immediately</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/semantics.html#processing-the-media-attribute">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
p {
color: red;
}
</style>
<body></body>
<script>
promise_test(async t => {
const link = document.createElement("link");
function waitForStylesheet() {
return new Promise(resolve => link.addEventListener("load", resolve, {once: true}));
}
link.media = "none";
link.rel = "stylesheet";
link.href = "resources/good.css";
const p = document.createElement("p");
p.textContent = "hello";
document.body.appendChild(p);
document.body.appendChild(link);
await waitForStylesheet();
assert_equals(getComputedStyle(p).color, "rgb(255, 0, 0)");
link.media = "all";
assert_equals(getComputedStyle(p).color, "rgb(0, 128, 0)");
const loaded = waitForStylesheet().then(() => "load");
const timeout = new Promise(resolve => t.step_timeout(() => resolve("timeout"), 100));
const result = await Promise.race([loaded, timeout]);
assert_equals(result, "timeout");
});
</script>