| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE HTML> | |
| 2 <script src="../resources/testharness.js"></script> | |
| 3 <script src="../resources/testharnessreport.js"></script> | |
| 4 | |
| 5 <style> | |
| 6 #div1 { | |
| 7 --length: 5px; | |
| 8 --color: notacolor; | |
| 9 } | |
| 10 #div2 { | |
| 11 --color: pink; | |
| 12 } | |
| 13 </style> | |
| 14 | |
| 15 <div id=div1></div> | |
| 16 <div id=div2></div> | |
| 17 <div id=div3></div> | |
| 18 | |
| 19 <script> | |
| 20 test(function() { | |
| 21 var reregisterError = {name: 'InvalidModificationError'}; | |
| 22 var unregisterError = {name: 'NotFoundError'}; | |
| 23 CSS.registerProperty({name: '--property'}); | |
| 24 assert_throws(reregisterError, () => CSS.registerProperty({name: '--property
'})); | |
| 25 assert_throws(unregisterError, () => CSS.unregisterProperty({name: '--proper
ty2'})); | |
| 26 | |
| 27 CSS.registerProperty({name: '--property2', syntax: '<length>', initialValue:
'5px'}); | |
| 28 assert_throws(reregisterError, () => CSS.registerProperty({name: '--property
2'})); | |
| 29 assert_throws(reregisterError, () => CSS.registerProperty({name: '--property
'})); | |
| 30 | |
| 31 CSS.unregisterProperty('--property'); | |
| 32 assert_throws(unregisterError, () => CSS.unregisterProperty({name: '--proper
ty'})); | |
| 33 assert_throws(reregisterError, () => CSS.registerProperty({name: '--property
2'})); | |
| 34 CSS.registerProperty({name: '--property'}); | |
| 35 assert_throws(reregisterError, () => CSS.registerProperty({name: '--property
'})); | |
| 36 | |
| 37 CSS.unregisterProperty('--property2'); | |
| 38 assert_throws(unregisterError, () => CSS.unregisterProperty({name: '--proper
ty2'})); | |
| 39 }, "Registration state is correctly managed and correct errors are thrown"); | |
| 40 | |
| 41 test(function() { | |
| 42 computedStyle1 = getComputedStyle(div1); | |
| 43 computedStyle2 = getComputedStyle(div2); | |
| 44 assert_equals(computedStyle1.getPropertyValue('--length'), ' 5px'); | |
| 45 assert_equals(computedStyle1.getPropertyValue('--color'), ' notacolor'); | |
| 46 assert_equals(computedStyle2.getPropertyValue('--length'), ''); | |
| 47 assert_equals(computedStyle2.getPropertyValue('--color'), ' pink'); | |
| 48 | |
| 49 CSS.registerProperty({name: '--length', syntax: '<length>', initialValue: '1
0px'}); | |
| 50 CSS.registerProperty({name: '--color', syntax: '<color>', initialValue: 'red
'}); | |
| 51 assert_equals(computedStyle1.getPropertyValue('--length'), '5px'); | |
| 52 assert_equals(computedStyle1.getPropertyValue('--color'), 'red'); | |
| 53 assert_equals(computedStyle2.getPropertyValue('--length'), '10px'); | |
| 54 assert_equals(computedStyle2.getPropertyValue('--color'), 'pink'); | |
| 55 | |
| 56 CSS.unregisterProperty('--length'); | |
| 57 CSS.unregisterProperty('--color'); | |
| 58 assert_equals(computedStyle1.getPropertyValue('--length'), ' 5px'); | |
| 59 assert_equals(computedStyle1.getPropertyValue('--color'), ' notacolor'); | |
| 60 assert_equals(computedStyle2.getPropertyValue('--length'), ''); | |
| 61 assert_equals(computedStyle2.getPropertyValue('--color'), ' pink'); | |
| 62 }, "Unregistration correctly updates computed style"); | |
| 63 | |
| 64 test(function() { | |
| 65 computedStyle = getComputedStyle(div3); | |
| 66 assert_equals(computedStyle.getPropertyValue('--x'), ''); | |
| 67 | |
| 68 CSS.registerProperty({name: '--x', syntax: '<length>', initialValue: '10px'}
); | |
| 69 assert_equals(computedStyle.getPropertyValue('--x'), '10px'); | |
| 70 | |
| 71 CSS.unregisterProperty('--x'); | |
| 72 assert_equals(computedStyle.getPropertyValue('--x'), ''); | |
| 73 | |
| 74 CSS.registerProperty({name: '--x', syntax: '<color>', initialValue: 'purple'
}); | |
| 75 div3.style.setProperty('--x', '5px'); | |
| 76 assert_equals(computedStyle.getPropertyValue('--x'), 'purple'); | |
| 77 }, "Property can be re-registered with different type"); | |
| 78 </script> | |
| OLD | NEW |