Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / svg / parser / whitespace-length-invalid-1.html
blobd1d082f6cbc6d424bf872aa068a6f0b94e7b6f25
1 <!doctype html>
2 <title>Whitespace in attribute values tests</title>
3 <script src=../../resources/testharness.js></script>
4 <script src=../../resources/testharnessreport.js></script>
5 <svg id="testcontainer">
6 </svg>
7 <div id=log></div>
8 <script>
9 var svg = document.querySelector("svg");
11 // test length values
12 var EPSILON = Math.pow(2, -24); // float epsilon
13 var whitespace = [ "", " ", " ", "\r\n\t ", "\f" ];
14 var validunits = [ "", "em", "ex", "px", "in", "cm", "mm", "pt", "pc", "%" ];
16 // This test was split out from whitespace-length.html because the trybots were too slow.
18 /**
19 * Tests attribute parsing and handling of whitespace in attribute values.
21 * @param type Name of the type being tested (only for test output)
22 * @param target The element that should be tested
23 * @param attribute The name of the attribute that should be tested
24 * @param expected The fallback/default value that is the expectation for invalid values
25 * @param whitespace An array of strings that are valid whitespace characters
26 * @param valid An array of strings containing valid attribute values
27 * @param invalid An array of strings containing invalid attribute values
28 * @param garbage An array of strings containing values that would make a valid value invalid when concatenated
29 * @param assert_valid_custom A function for asserting validity of a valid value, arguments passed to this function: the element and the string from valid values array
30 * @param assert_invalid_custom A function for asserting that an invalid value results in the expected default value, arguments passed to this function: the element and the expected value
32 function testTypeLocal(type, target, attribute, expected, whitespace, valid, invalid, validunits, garbage, assert_valid_custom, assert_invalid_custom) {
33 whitespace.forEach(function(leading) {
34 whitespace.forEach(function(trailing) {
35 // test invalid values
36 invalid.forEach(function(value) {
37 validunits.forEach(function(unit) {
38 var valueStr = leading + value + unit + trailing;
39 var escapedValueStr = valueStr.replace(/(\r)/g, '\\r').replace(/(\n)/g, '\\n').replace(/(\t)/g, '\\t').replace(/(\f)/g, '\\f');
40 test(function() {
41 try {
42 target.setAttribute(attribute, valueStr);
43 assert_equals(target.getAttribute(attribute), valueStr);
44 assert_invalid_custom(target, expected);
46 finally {
47 target.removeAttribute(attribute);
49 }, "Test " + type + " invalid value: " + escapedValueStr);
50 });
51 });
52 });
53 });
56 testTypeLocal("<length>",
57 svg,
58 "x",
59 0, // expected default value
60 whitespace,
61 [], // valid
62 [ Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY, "fnord", "E", "e" ], // invalid
63 validunits,
64 [], // garbage
65 function(elm, value) { assert_approx_equals(elm.x.baseVal.valueInSpecifiedUnits, parseFloat(value), EPSILON); },
66 function(elm, expected) { assert_approx_equals(elm.x.baseVal.value, expected, EPSILON); } );
68 </script>