| <!DOCTYPE html> |
| <title>Invalid SVG length units</title> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| <svg height="0"><rect/></svg> |
| <script> |
| function test_length_value(lengthString, expectedString) { |
| test(function() { |
| let rect = document.querySelector('rect'); |
| rect.setAttribute('x', "1234"); |
| rect.setAttribute('x', lengthString); |
| assert_equals(rect.x.baseVal.valueAsString, expectedString); |
| }, document.title + ', "' + lengthString + '"'); |
| } |
| |
| // Invalid |
| test_length_value("", "0"); |
| test_length_value(" ", "0"); |
| test_length_value("foo", "0"); |
| test_length_value("10foo", "0"); |
| test_length_value("px", "0"); |
| test_length_value("10 % ", "0"); |
| test_length_value("10 %", "0"); |
| test_length_value("10 px ", "0"); |
| test_length_value("10 px", "0"); |
| |
| // Valid |
| test_length_value("10px ", "10px"); |
| test_length_value("10% ", "10%"); |
| test_length_value("10", "10"); |
| test_length_value("10%", "10%"); |
| test_length_value("10em", "10em"); |
| test_length_value("10ex", "10ex"); |
| test_length_value("10px", "10px"); |
| test_length_value("10cm", "10cm"); |
| test_length_value("10mm", "10mm"); |
| test_length_value("10pt", "10pt"); |
| test_length_value("10pc", "10pc"); |
| </script> |