stylesheet-title.html (1401B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>CSS Test: StyleSheet's title attribute</title> 4 <link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io"> 5 <link rel="help" href="https://drafts.csswg.org/cssom/#preferred-css-style-sheet-set-name"> 6 <link rel="help" href="https://html.spec.whatwg.org/multipage/#attr-style-title"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <style></style> 10 <style title=""></style> 11 <style title="Preferred"> 12 p { color: green; } 13 </style> 14 <style title="Not preferred"> 15 p { color: red; } 16 </style> 17 <p id="test-element">Should be green</p> 18 <script> 19 test(function() { 20 assert_equals( 21 getComputedStyle(document.getElementById("test-element")).color, 22 "rgb(0, 128, 0)", 23 "Preferred style should apply" 24 ); 25 }, "Preferred style sheet name"); 26 27 test(function() { 28 let sheets = document.styleSheets; 29 let styleElements = Array.from(document.querySelectorAll("style")); 30 assert_equals(sheets.length, styleElements.length); 31 for (let i = 0; i < sheets.length; ++i) { 32 let titleAttr = styleElements[i].getAttribute("title"); 33 if (titleAttr === null || titleAttr === "") 34 assert_equals(sheets[i].title, null, "Empty title returns null"); 35 else 36 assert_equals(sheets[i].title, titleAttr, "Selected title is properly reflected"); 37 } 38 }, "StyleSheet.title"); 39 </script>