| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <style> | 3 <style> |
| 4 * { font-size: 16px; } | 4 * { font-size: 16px; } |
| 5 svg, rect { font-family: 'Ahem'; } | 5 svg, rect { font-family: 'Ahem'; } |
| 6 div { font-size: 8px; } | 6 div { font-size: 8px; } |
| 7 </style> | 7 </style> |
| 8 <html> | 8 <html> |
| 9 <svg id="svg" width="0" height="0"></svg> | 9 <svg id="svg" width="0" height="0"></svg> |
| 10 <script src="../../resources/js-test.js"></script> | 10 <script src="../../resources/js-test.js"></script> |
| 11 <script> | 11 <script> |
| 12 description("Test that 'length' presentation attribute values are parsed with CS
S presentation rules."); | 12 description("Test that 'length' presentation attribute values are parsed with CS
S presentation rules."); |
| 13 | 13 |
| 14 function computedStyle(property, value) { | 14 function computedStyle(elementname, property, value) { |
| 15 var rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect'); | 15 var elm = document.createElementNS('http://www.w3.org/2000/svg', elementname); |
| 16 document.getElementById('svg').appendChild(rect); | 16 document.getElementById('svg').appendChild(elm); |
| 17 rect.setAttribute(property, value); | 17 elm.setAttribute(property, value); |
| 18 var computedValue = getComputedStyle(rect).getPropertyValue(property); | 18 var computedValue = getComputedStyle(elm).getPropertyValue(property); |
| 19 document.getElementById('svg').removeChild(rect); | 19 document.getElementById('svg').removeChild(elm); |
| 20 return computedValue; | 20 return computedValue; |
| 21 } | 21 } |
| 22 | 22 |
| 23 function testComputed(property, value, expected) { | 23 function testComputed(elementname, property, value, expected) { |
| 24 shouldBeEqualToString('computedStyle("' + property + '", "' + value + '")',
expected); | 24 shouldBeEqualToString('computedStyle("' + elementname + '", "' + property + '"
, "' + value + '")', expected); |
| 25 } | 25 } |
| 26 | 26 |
| 27 function negativeTest(property, value) { | 27 function negativeTest(elementname, property, value) { |
| 28 testComputed(property, value, "auto"); | 28 testComputed(elementname, property, value, "auto"); |
| 29 } | 29 } |
| 30 | 30 |
| 31 function negativeTestZero(property, value) { | 31 function negativeTestZero(elementname, property, value) { |
| 32 testComputed(property, value, "0px"); | 32 testComputed(elementname, property, value, "0px"); |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Test 'x'. | 35 function testAttributeOnElement(elementname, attributename) { |
| 36 testComputed("x", " 100", "100px"); | 36 testComputed(elementname, attributename, " 100", "100px"); |
| 37 testComputed("x", "100 ", "100px"); | 37 testComputed(elementname, attributename, "100 ", "100px"); |
| 38 testComputed("x", "100px", "100px"); | 38 testComputed(elementname, attributename, "100px", "100px"); |
| 39 testComputed("x", "1em", "16px"); | 39 testComputed(elementname, attributename, "1em", "16px"); |
| 40 // testComputed("x", "1ex", "12.8000001907349px"); // enable this again once htt
p://crbug.com/441840 is fixed | 40 // testComputed(elementname, attributename, "1ex", "12.8000001907349px"); // e
nable this again once http://crbug.com/441840 is fixed |
| 41 testComputed("x", "20%", "20%"); | 41 testComputed(elementname, attributename, "20%", "20%"); |
| 42 testComputed("x", "-200px", "-200px"); | 42 testComputed(elementname, attributename, "-200px", "-200px"); |
| 43 | 43 |
| 44 // Test 'y'. | 44 negativeTestZero(elementname, attributename, "auto", "auto"); |
| 45 testComputed("y", " 100", "100px"); | 45 negativeTestZero(elementname, attributename, "100 px"); |
| 46 testComputed("y", "100 ", "100px"); | 46 negativeTestZero(elementname, attributename, "100px;"); |
| 47 testComputed("y", "100px", "100px"); | 47 negativeTestZero(elementname, attributename, "100px !important"); |
| 48 testComputed("y", "1em", "16px"); | 48 negativeTestZero(elementname, attributename, "{ 100px }"); |
| 49 // testComputed("y", "1ex", "12.8000001907349px"); // enable this again once htt
p://crbug.com/441840 is fixed | 49 } |
| 50 testComputed("y", "20%", "20%"); | |
| 51 testComputed("y", "-200px", "-200px"); | |
| 52 | 50 |
| 53 // Negative tests for 'x'. | 51 var xyelements = [ "mask", "svg", "rect", "image", "foreignObject" ]; |
| 54 negativeTestZero("x", "auto", "auto"); | 52 for (var elm of xyelements) { |
| 55 negativeTestZero("x", "100 px"); | 53 testAttributeOnElement(elm, "x"); |
| 56 negativeTestZero("x", "100px;"); | 54 testAttributeOnElement(elm, "y"); |
| 57 negativeTestZero("x", "100px !important"); | 55 } |
| 58 negativeTestZero("x", "{ 100px }"); | |
| 59 | 56 |
| 60 // Negative tests for 'y'. | 57 var rxryelements = [ "rect", "ellipse" ]; |
| 61 negativeTestZero("y", "auto"); | 58 for (var elm of rxryelements) { |
| 62 negativeTestZero("y", "100 px"); | 59 testAttributeOnElement(elm, "rx"); |
| 63 negativeTestZero("y", "100px;"); | 60 testAttributeOnElement(elm, "ry"); |
| 64 negativeTestZero("y", "100px !important"); | 61 } |
| 65 negativeTestZero("y", "{ 100px }"); | |
| 66 | 62 |
| 67 // Test 'rx'. | 63 testAttributeOnElement("circle", "r"); |
| 68 testComputed("rx", " 100", "100px"); | |
| 69 testComputed("rx", "100 ", "100px"); | |
| 70 testComputed("rx", "100px", "100px"); | |
| 71 testComputed("rx", "1em", "16px"); | |
| 72 // testComputed("rx", "1ex", "12.8000001907349px"); // enable this again once ht
tp://crbug.com/441840 is fixed | |
| 73 testComputed("rx", "20%", "20%"); | |
| 74 testComputed("rx", "-200px", "-200px"); | |
| 75 | |
| 76 // Test 'ry'. | |
| 77 testComputed("ry", " 100", "100px"); | |
| 78 testComputed("ry", "100 ", "100px"); | |
| 79 testComputed("ry", "100px", "100px"); | |
| 80 testComputed("ry", "1em", "16px"); | |
| 81 // testComputed("ry", "1ex", "12.8000001907349px"); // enable this again once ht
tp://crbug.com/441840 is fixed | |
| 82 testComputed("ry", "20%", "20%"); | |
| 83 testComputed("ry", "-200px", "-200px"); | |
| 84 | |
| 85 // Negative tests for 'rx'. | |
| 86 negativeTestZero("rx", "auto", "auto"); | |
| 87 negativeTestZero("rx", "100 px"); | |
| 88 negativeTestZero("rx", "100px;"); | |
| 89 negativeTestZero("rx", "100px !important"); | |
| 90 negativeTestZero("rx", "{ 100px }"); | |
| 91 | |
| 92 // Negative tests for 'ry'. | |
| 93 negativeTestZero("ry", "auto"); | |
| 94 negativeTestZero("ry", "100 px"); | |
| 95 negativeTestZero("ry", "100px;"); | |
| 96 negativeTestZero("ry", "100px !important"); | |
| 97 negativeTestZero("ry", "{ 100px }"); | |
| 98 </script> | 64 </script> |
| 99 </body> | 65 </body> |
| 100 </html> | 66 </html> |
| OLD | NEW |