self-utils.html (1657B)
1 <!DOCTYPE html> 2 <title>Self-test for utils.js</title> 3 <link rel="help" href="https://drafts.css-houdini.org/css-properties-values-api-1/"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="./resources/utils.js"></script> 7 <div id=outer><div id=inner></div></div> 8 <script> 9 10 test(function(){ 11 let syntaxes = all_syntaxes().concat([ 12 'foo', 13 'bar | <length>', 14 '<angle> | <length>' 15 ]); 16 // Don't throw: 17 syntaxes.forEach(generate_property); 18 }, 'Default initial values of generated properties are valid (self-test).'); 19 20 test(function(){ 21 try { 22 let inherited = generate_property({ syntax: '<length>', inherits: true }); 23 let non_inherited = generate_property({ syntax: '<length>', inherits: false, initialValue: '5px' }); 24 outer.style = `${inherited}: 10px; ${non_inherited}: 11px;`; 25 assert_equals(getComputedStyle(outer).getPropertyValue(inherited), '10px'); 26 assert_equals(getComputedStyle(outer).getPropertyValue(non_inherited), '11px'); 27 assert_equals(getComputedStyle(inner).getPropertyValue(inherited), '10px'); 28 assert_equals(getComputedStyle(inner).getPropertyValue(non_inherited), '5px'); 29 } finally { 30 outer.style = ''; 31 inner.style = ''; 32 } 33 }, 'Generated properties respect inherits flag'); 34 35 test(function(){ 36 assert_throws_js(Error, () => generate_property({syntax: '<length>', foo: 1})); 37 assert_throws_js(Error, () => generate_property({syntax: '<length>', inherited: false})); 38 assert_throws_js(Error, () => generate_property({syntax: '<length>', initial: '10px'})); 39 }, 'Can\'t generate property with unknown fields'); 40 41 </script>