tor-browser

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

Document-parseHTMLUnsafe-style-attribute.html (2026B)


      1 <!doctype html>
      2 <link rel=author href="mailto:jarhar@chromium.org">
      3 <!-- This test was adapted from style_attribute_html.html -->
      4 <meta charset=utf-8>
      5 <title>Style attribute in HTML</title>
      6 <script src=/resources/testharness.js></script>
      7 <script src=/resources/testharnessreport.js></script>
      8 <script>
      9 
     10 var div;
     11 setup(function() {
     12    var input = '<div style="color: red">Foo</div>';
     13    var doc = Document.parseHTMLUnsafe(input);
     14    div = doc.querySelector('div');
     15 });
     16 
     17 test(function() {
     18    var style = div.style;
     19    assert_equals(style.cssText, 'color: red;');
     20    assert_equals(style.color, 'red');
     21    assert_equals(div.getAttribute("style"), 'color: red',
     22                  'Value of style attribute should match the string value that was set');
     23 }, 'Parsing of initial style attribute');
     24 
     25 test(function() {
     26    var style = div.style;
     27    div.setAttribute('style', 'color:: invalid');
     28    assert_equals(style.cssText, '');
     29    assert_equals(style.color, '');
     30    assert_equals(div.getAttribute('style'), 'color:: invalid',
     31                  'Value of style attribute should match the string value that was set');
     32 }, 'Parsing of invalid style attribute');
     33 
     34 test(function() {
     35    var style = div.style;
     36    div.setAttribute('style', 'color: green');
     37    assert_equals(style.cssText, 'color: green;');
     38    assert_equals(style.color, 'green');
     39    assert_equals(div.getAttribute('style'), 'color: green',
     40                  'Value of style attribute should match the string value that was set');
     41 }, 'Parsing of style attribute');
     42 
     43 test(function() {
     44    var style = div.style;
     45    style.backgroundColor = 'blue';
     46    assert_equals(style.cssText, 'color: green; background-color: blue;',
     47                  'Should not drop the existing style');
     48    assert_equals(style.color, 'green',
     49                  'Should not drop the existing style');
     50    assert_equals(div.getAttribute('style'), 'color: green; background-color: blue;',
     51                  'Should update style attribute');
     52 }, 'Update style.backgroundColor');
     53 
     54 </script>