OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE HTML> |
| 2 <script src="../resources/testharness.js"></script> |
| 3 <script src="../resources/testharnessreport.js"></script> |
| 4 |
| 5 <style> |
| 6 #inner { |
| 7 --length: 10px; |
| 8 --color: red; |
| 9 } |
| 10 #outer { |
| 11 --color: blue; |
| 12 } |
| 13 </style> |
| 14 |
| 15 <div id=inner></div> |
| 16 |
| 17 <script> |
| 18 var computedStyle = getComputedStyle(inner); |
| 19 var inlineStyle = inner.style; |
| 20 var sheetStyle = document.styleSheets[0].cssRules[0].style; |
| 21 |
| 22 test(function() { |
| 23 // Nothing registered yet, whatever you specify works |
| 24 assert_equals(computedStyle.getPropertyValue('--length'), ' 10px'); |
| 25 assert_equals(computedStyle.getPropertyValue('--color'), ' red'); |
| 26 |
| 27 inlineStyle.setProperty('--length', '5'); |
| 28 inlineStyle.setProperty('--color', 'hello'); |
| 29 |
| 30 assert_equals(inlineStyle.getPropertyValue('--length'), '5'); |
| 31 assert_equals(inlineStyle.getPropertyValue('--color'), 'hello'); |
| 32 assert_equals(computedStyle.getPropertyValue('--length'), '5'); |
| 33 assert_equals(computedStyle.getPropertyValue('--color'), 'hello'); |
| 34 }, "CSSOM setters function as expected for unregistered properties"); |
| 35 |
| 36 CSS.registerProperty({name: '--length', syntax: '<length>', initialValue: '0px'}
); |
| 37 CSS.registerProperty({name: '--color', syntax: '<color>', initialValue: 'white',
inherits: true}); |
| 38 |
| 39 test(function() { |
| 40 assert_equals(inlineStyle.getPropertyValue('--length'), '5'); |
| 41 assert_equals(inlineStyle.getPropertyValue('--color'), 'hello'); |
| 42 assert_equals(computedStyle.getPropertyValue('--length'), '0px'); |
| 43 assert_equals(computedStyle.getPropertyValue('--color'), 'white'); |
| 44 }, "Formerly valid values are still readable from inline styles but are computed
as the unset value"); |
| 45 |
| 46 test(function() { |
| 47 inlineStyle.setProperty('--length', 'hi'); |
| 48 inlineStyle.setProperty('--color', '20'); |
| 49 assert_equals(inlineStyle.getPropertyValue('--length'), '5'); |
| 50 assert_equals(inlineStyle.getPropertyValue('--color'), 'hello'); |
| 51 }, "Values not matching the registered type can't be set"); |
| 52 |
| 53 test(function() { |
| 54 inlineStyle.removeProperty('--length'); |
| 55 inlineStyle.setProperty('--color', ''); |
| 56 assert_equals(inlineStyle.getPropertyValue('--length'), ''); |
| 57 assert_equals(inlineStyle.getPropertyValue('--color'), ''); |
| 58 assert_equals(computedStyle.getPropertyValue('--length'), '10px'); |
| 59 assert_equals(computedStyle.getPropertyValue('--color'), 'red'); |
| 60 }, "Values can be removed from inline styles"); |
| 61 |
| 62 test(function() { |
| 63 sheetStyle.setProperty('--length', 'banana'); // Invalid, no change |
| 64 assert_equals(computedStyle.getPropertyValue('--length'), '10px'); |
| 65 sheetStyle.setProperty('--length', '20px'); |
| 66 assert_equals(computedStyle.getPropertyValue('--length'), '20px'); |
| 67 }, "Stylesheets can be modified by CSSOM"); |
| 68 |
| 69 test(function() { |
| 70 inlineStyle.setProperty('--length', '30px'); |
| 71 inlineStyle.setProperty('--color', 'pink'); |
| 72 assert_equals(inlineStyle.getPropertyValue('--length'), '30px'); |
| 73 assert_equals(inlineStyle.getPropertyValue('--color'), 'pink'); |
| 74 assert_equals(computedStyle.getPropertyValue('--length'), '30px'); |
| 75 assert_equals(computedStyle.getPropertyValue('--color'), 'pink'); |
| 76 }, "Valid values can be set on inline styles"); |
| 77 </script> |
OLD | NEW |