tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

CSSStyleRule.html (4409B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4    <title>CSSOM CSSRule CSSStyleRule interface</title>
      5    <link rel="author" title="Letitia Lew" href="mailto:lew.letitia@gmail.com">
      6    <link rel="help" href="http://www.w3.org/TR/cssom-1/#css-rules">
      7    <link rel="help" href="http://www.w3.org/TR/cssom-1/#the-cssrule-interface">
      8    <link rel="help" href="http://www.w3.org/TR/cssom-1/#the-cssstylerule-interface">
      9    <meta name="flags" content="dom">
     10    <meta name="assert" content="All properties for this CSSStyleRule instance of CSSRule are initialized correctly">
     11    <script src="/resources/testharness.js"></script>
     12    <script src="/resources/testharnessreport.js"></script>
     13 
     14    <style id="styleElement" type="text/css">
     15        div { margin: 10px; padding: 0px; }
     16    </style>
     17 </head>
     18 <body>
     19    <div id="log"></div>
     20 
     21    <script type="text/javascript">
     22        var rule;
     23        setup(function() {
     24            var styleSheet = document.getElementById("styleElement").sheet;
     25            var ruleList = styleSheet.cssRules;
     26            rule = ruleList[0];
     27        });
     28 
     29        test(function() {
     30            assert_true(rule instanceof CSSRule);
     31            assert_true(rule instanceof CSSStyleRule);
     32        }, "CSSRule and CSSStyleRule types");
     33 
     34        test(function() {
     35            assert_equals(rule.STYLE_RULE, 1);
     36            assert_equals(rule.IMPORT_RULE, 3);
     37            assert_equals(rule.MEDIA_RULE, 4);
     38            assert_equals(rule.FONT_FACE_RULE, 5);
     39            assert_equals(rule.PAGE_RULE, 6);
     40            assert_equals(rule.NAMESPACE_RULE, 10);
     41            assert_idl_attribute(rule, "type");
     42            assert_equals(typeof rule.type, "number");
     43        }, "Type of CSSRule#type and constant values");
     44 
     45        test(function() {
     46            assert_true(rule instanceof CSSRule);
     47            assert_idl_attribute(rule, "cssText");
     48            assert_idl_attribute(rule, "parentRule");
     49            assert_idl_attribute(rule, "parentStyleSheet");
     50        }, "Existence of CSSRule attributes");
     51 
     52        test(function() {
     53            assert_readonly(rule, "type");
     54            assert_readonly(rule, "parentRule");
     55            assert_readonly(rule, "parentStyleSheet");
     56        }, "Writability of CSSRule attributes");
     57 
     58        test(function() {
     59            assert_equals(rule.type, rule.STYLE_RULE);
     60            assert_equals(typeof rule.cssText, "string");
     61            assert_equals(rule.cssText, "div { margin: 10px; padding: 0px; }");
     62            assert_equals(rule.parentRule, null);
     63            assert_true(rule.parentStyleSheet instanceof CSSStyleSheet);
     64        }, "Values of CSSRule attributes");
     65 
     66        test(function() {
     67            assert_idl_attribute(rule, "selectorText");
     68            assert_equals(typeof rule.selectorText, "string");
     69            assert_idl_attribute(rule, "style");
     70        }, "Existence and type of CSSStyleRule attributes");
     71 
     72        test(function() {
     73            // CSSStyleRule.style has PutForwards=cssText and SameObject.
     74            var initial = rule.style.cssText;
     75            var style = rule.style;
     76 
     77            rule.style = "";
     78            assert_equals(rule.style.cssText, "");
     79            assert_equals(rule.style, style);
     80 
     81            rule.style = "margin: 42px;";
     82            assert_equals(rule.style.margin, "42px");
     83            assert_equals(rule.style, style);
     84 
     85            rule.style = initial;
     86            assert_equals(rule.style, style);
     87        }, "Assigning to CSSStyleRule.style assigns to cssText; CSSStyleRule.style returns the same object");
     88 
     89        test(function() {
     90            assert_equals(rule.selectorText, "div");
     91            assert_true(rule.style instanceof CSSStyleDeclaration);
     92        }, "Values of CSSStyleRule attributes");
     93 
     94        test(function() {
     95            assert_equals(rule.style.margin, "10px");
     96            assert_equals(rule.style.padding, "0px");
     97 
     98            rule.style.padding = "5px";
     99            rule.style.border = "1px solid";
    100 
    101            assert_equals(rule.style.padding, "5px");
    102            assert_equals(rule.style.border, "1px solid");
    103        }, "Mutability of CSSStyleRule's style attribute");
    104 
    105        test(function() {
    106            rule.style = "margin: 15px; padding: 2px;";
    107 
    108            assert_equals(rule.style.margin, "15px", "margin");
    109            assert_equals(rule.style.padding, "2px", "padding");
    110        }, "CSSStyleRule's style has [PutForwards]");
    111    </script>
    112 </body>
    113 </html>