tor-browser

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

cssstyledeclaration-csstext.html (4507B)


      1 <!DOCTYPE html>
      2 <html>
      3    <head>
      4        <title>CSSOM Test: CSSStyleDeclaration.cssText Test</title>
      5        <link rel="author" title="kkoichi" href="mailto:coarse.ground@gmail.com">
      6        <link rel="reviewer" title="Simon Pieters" href="mailto:simonp@opera.com"><!-- 06-27-2013 -->
      7        <link rel="help" href="https://drafts.csswg.org/cssom-1/#dom-cssstyledeclaration-csstext">
      8        <meta name="assert" content="CSS declarations is serialized as expected">
      9        <meta name="flags" content="dom">
     10        <script src="/resources/testharness.js"></script>
     11        <script src="/resources/testharnessreport.js"></script>
     12    </head>
     13    <body>
     14    <div id="log"></div>
     15    <script>
     16        function newElm() {
     17            return document.body.appendChild(document.createElement('div'));
     18        }
     19 
     20        test(function(){
     21            var style = newElm().style;
     22            style.COLOR = 'red';
     23 
     24            assert_equals(style.cssText, '');
     25 
     26        }, 'uppercase property');
     27 
     28        test(function(){
     29            var style = newElm().style;
     30            style.color = 'RED';
     31 
     32            // https://www.w3.org/Bugs/Public/show_bug.cgi?id=29317
     33            assert_any(assert_equals, style.cssText, ['color: red;', 'color: RED;']);
     34 
     35        }, 'uppercase value');
     36 
     37        test(function(){
     38            var style = newElm().style;
     39 
     40            style.color = 'red';
     41 
     42            style.color = 'unknown color';
     43 
     44            assert_equals(style.cssText, 'color: red;');
     45 
     46        }, 'overwriting with invalid value');
     47 
     48        test(function(){
     49            var style = newElm().style;
     50            style.color = 'rgb(255, 0, 0)';
     51 
     52            assert_equals(style.cssText, 'color: rgb(255, 0, 0);');
     53 
     54        }, 'use rgb');
     55 
     56        test(function(){
     57            var e = newElm();
     58            var style = e.style;
     59 
     60            style.color = 'red';
     61            style.fontSize = '10pt';
     62            style.fontWeight = 'bold';
     63 
     64            assert_equals(style.cssText, 'color: red; font-size: 10pt; font-weight: bold;');
     65 
     66        }, 'cssText order');
     67 
     68        test(function(){
     69            var e = newElm();
     70            var style = e.style;
     71 
     72            style.fontWeight = 'bold';
     73            style.color = 'red';
     74            style.fontSize = '10pt';
     75 
     76            assert_equals(style.cssText, 'font-weight: bold; color: red; font-size: 10pt;');
     77 
     78        }, 'another cssText order (non-alphabetical order)');
     79 
     80        test(function(){
     81            var style = newElm().style;
     82 
     83            style.color = '   red';
     84            style.fontSize = '10pt   ';
     85 
     86            assert_equals(style.cssText, 'color: red; font-size: 10pt;');
     87 
     88        }, 'whitespaces in value');
     89 
     90        test(function(){
     91            var style = newElm().style;
     92 
     93            style.color = 'red';
     94            style.unknown = 'unknown';
     95            style.fontSize = '10pt';
     96            assert_equals(style.cssText, 'color: red; font-size: 10pt;');
     97 
     98        }, 'invalid property does not appear');
     99 
    100        test(function(){
    101            var style = newElm().style;
    102            style.cssText = "margin: 10px; margin-inline: 10px; margin-block: 10px; margin-inline-end: 10px; margin-bottom: 10px;";
    103            assert_equals(style.cssText, "margin-top: 10px; margin-right: 10px; margin-left: 10px; margin-inline-start: 10px; margin-block: 10px; margin-inline-end: 10px; margin-bottom: 10px;");
    104        }, 'Shorthands aren\'t serialized if there are other properties with different logical groups in between');
    105 
    106        test(function(){
    107            var style = newElm().style;
    108            style.cssText = "margin-top: 10px; margin-left: 10px; margin-right: 10px; margin-bottom: 10px; margin-inline-start: 10px; margin-inline-end: 10px; margin-block-start: 10px; margin-block-end: 10px;";
    109            assert_equals(style.cssText, "margin: 10px; margin-inline: 10px; margin-block: 10px;");
    110        }, 'Shorthands _are_ serialized if there are no other properties with different logical groups in between');
    111 
    112        // https://github.com/w3c/csswg-drafts/issues/1033
    113        test(function() {
    114            var elm = newElm();
    115            var style = elm.style;
    116 
    117            style.color = 'red';
    118            style.unknown = 'unknown';
    119            style.fontSize = '10pt';
    120 
    121            assert_not_equals(getComputedStyle(elm).length, 0, "Should have a style");
    122            assert_equals(getComputedStyle(elm).cssText, "", "cssText is empty");
    123        }, 'cssText on computed style declaration returns the empty string');
    124    </script>
    125    </body>
    126 </html>