Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(487)

Side by Side Diff: third_party/WebKit/LayoutTests/svg/parser/whitespace-length-invalid-3.html

Issue 2454413002: Break svg/parser/whitespace tests apart some more. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!doctype html> 1 <!doctype html>
2 <title>Whitespace in attribute values tests</title> 2 <title>Whitespace in attribute values tests</title>
3 <script src=../../resources/testharness.js></script> 3 <script src=../../resources/testharness.js></script>
4 <script src=../../resources/testharnessreport.js></script> 4 <script src=../../resources/testharnessreport.js></script>
5 <script src=resources/whitespace-helper.js></script>
5 <svg id="testcontainer"> 6 <svg id="testcontainer">
6 </svg> 7 </svg>
7 <div id=log></div> 8 <div id=log></div>
8 <script> 9 <script>
9 var svg = document.querySelector("svg"); 10 var svg = document.querySelector("svg");
10 11
11 // test length values 12 // test length values
12 var EPSILON = Math.pow(2, -24); // float epsilon 13 var EPSILON = Math.pow(2, -24); // float epsilon
13 var whitespace = [ "", " ", " ", "\r\n\t ", "\f" ]; 14 var whitespace = [ "", " ", " ", "\r\n\t ", "\f" ];
14 var validunits = [ "", "em", "ex", "px", "in", "cm", "mm", "pt", "pc", "%" ]; 15 var validunits = [ "", "em", "ex", "px", "in", "cm", "mm", "pt", "pc", "%" ];
15 16
16 // This test was split out from whitespace-length.html because the trybots were too slow. 17 // This test was split out from whitespace-length.html because the trybots were too slow.
17 18
18 /** 19 testInvalidType("<length>",
19 * Tests attribute parsing and handling of whitespace in attribute values.
20 *
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 invali d 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 value s array
30 * @param assert_invalid_custom A function for asserting that an invalid value r esults in the expected default value, arguments passed to this function: the ele ment and the expected value
31 */
32 function testTypeLocal(type, target, attribute, expected, whitespace, valid, inv alid, 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').repla ce(/(\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), valueS tr);
44 assert_invalid_custom(target, expected);
45 }
46 finally {
47 target.removeAttribute(attribute);
48 }
49 }, "Test " + type + " invalid value: " + escapedValueStr);
50 });
51 });
52 });
53 });
54 }
55
56 testTypeLocal("<length>",
57 svg, 20 svg,
58 "x", 21 "x",
59 0, // expected default value 22 0, // expected default value
60 whitespace, 23 whitespace,
61 [], // valid
62 [ "-", "+", "-.", ".-" ], // invalid 24 [ "-", "+", "-.", ".-" ], // invalid
63 validunits, 25 validunits,
64 [], // garbage
65 function(elm, value) { assert_approx_equals(elm.x.baseVal.value InSpecifiedUnits, parseFloat(value), EPSILON); }, 26 function(elm, value) { assert_approx_equals(elm.x.baseVal.value InSpecifiedUnits, parseFloat(value), EPSILON); },
66 function(elm, expected) { assert_approx_equals(elm.x.baseVal.va lue, expected, EPSILON); } ); 27 function(elm, expected) { assert_approx_equals(elm.x.baseVal.va lue, expected, EPSILON); } );
67 28
68 </script> 29 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698