HTMLLinkElement-disabled-001.html (1691B)
1 <!doctype html> 2 <title><link disabled>, HTMLLinkElement.disabled and CSSStyleSheet.disabled interactions</title> 3 <link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io"> 4 <link rel="author" title="Mozilla" href="https://mozilla.org"> 5 <link rel="help" href="https://html.spec.whatwg.org/#attr-link-disabled"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <link title="alt" rel="stylesheet" disabled href="data:text/css,html { background: green }"> 9 <script> 10 function assert_applies(applies) { 11 (applies ? assert_equals : assert_not_equals)(getComputedStyle(document.documentElement).backgroundColor, "rgb(0, 128, 0)"); 12 } 13 14 const link = document.querySelector("link[disabled]"); 15 16 test(function() { 17 assert_equals(document.styleSheets.length, 0); 18 assert_applies(false); 19 }, "<link disabled> prevents the stylesheet from being in document.styleSheets (from parser)"); 20 21 async_test(function(t) { 22 assert_true(link.disabled); 23 24 link.onload = t.step_func_done(function() { 25 assert_equals(document.styleSheets.length, 1); 26 let sheet = document.styleSheets[0]; 27 assert_equals(sheet.ownerNode, link); 28 assert_applies(true); 29 30 link.disabled = true; 31 assert_equals(sheet.ownerNode, null); 32 assert_false(sheet.disabled); 33 assert_applies(false); 34 assert_true(link.hasAttribute("disabled")); 35 36 assert_equals(document.styleSheets.length, 0); 37 assert_applies(false); 38 }); 39 40 link.disabled = false; 41 assert_true(!link.hasAttribute("disabled")); 42 assert_false(link.disabled); 43 }, "HTMLLinkElement.disabled reflects the <link disabled> attribute, and behaves consistently"); 44 </script>