CSSStyleRule-set-selectorText-namespace.html (2155B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>CSSOM StyleRule selectorText property setter with namespaces</title> 4 <link rel="help" href="https://drafts.csswg.org/cssom-1/#dom-cssstylerule-selectortext"> 5 <script src=/resources/testharness.js></script> 6 <script src=/resources/testharnessreport.js></script> 7 8 <style type="text/css" id="styleElement"> 9 @namespace url(http://www.w3.org/1999/xhtml); 10 @namespace svg url(http://www.w3.org/2000/svg); 11 12 svg|*.style0 { background-color: rgb(0, 0, 255) !important; } 13 svg|*.style1 { background-color: rgb(255, 0, 255); } 14 </style> 15 16 <span> 17 <p></p> 18 19 <svg height="30" width="200" id="container" class="style1" lang="zh-CN" language segment="42 43"> 20 <text x="0" y="15">SVG text</text> 21 </svg> 22 </span> 23 24 <script> 25 var styleSheet = document.getElementById("styleElement").sheet; 26 var rule = styleSheet.cssRules[2]; 27 28 var divContainerStyle = getComputedStyle(document.getElementById("container")); 29 30 const originalStyleSelector = "svg|*.style0"; 31 32 var assertColors = function(selectorMatches) { 33 assert_equals(divContainerStyle.getPropertyValue('background-color'), selectorMatches ? "rgb(0, 0, 255)" : "rgb(255, 0, 255)") 34 }; 35 36 [ 37 {selector: ".style1", isMatch: false, }, 38 {selector: "svg|*.style1 ", isMatch: true, normalizedSelector: "svg|*.style1"}, 39 {selector: "*|*.style1 ", isMatch: true, normalizedSelector: "*|*.style1"}, 40 {selector: " *.style1 ", isMatch: false, normalizedSelector: ".style1"}, 41 {selector: "p", isMatch: false}, 42 ].forEach(function(testCase) { 43 test(function() { 44 // Check if starting with the default value. 45 assert_equals(rule.selectorText, originalStyleSelector); 46 47 this.add_cleanup(function() { rule.selectorText = originalStyleSelector; }); 48 49 assertColors(false); 50 51 rule.selectorText = testCase.selector; 52 53 var expectedSelector = testCase.normalizedSelector ? testCase.normalizedSelector : testCase.selector; 54 55 assert_equals(rule.selectorText, expectedSelector); 56 57 assertColors(testCase.isMatch); 58 }, "CSSStyleRule: selectorText value: |" + testCase.selector + "| isMatch: " + testCase.isMatch); 59 }); 60 </script>