| OLD | NEW |
| 1 /** | 1 /** |
| 2 * Tests attribute parsing and handling of whitespace in attribute values. | 2 * Tests attribute parsing and handling of whitespace in attribute values. |
| 3 * | 3 * |
| 4 * @param type Name of the type being tested (only for test output) | 4 * @param type Name of the type being tested (only for test output) |
| 5 * @param target The element that should be tested | 5 * @param target The element that should be tested |
| 6 * @param attribute The name of the attribute that should be tested | 6 * @param attribute The name of the attribute that should be tested |
| 7 * @param expected The fallback/default value that is the expectation for invali
d values | 7 * @param expected The fallback/default value that is the expectation for invali
d values |
| 8 * @param whitespace An array of strings that are valid whitespace characters | 8 * @param whitespace An array of strings that are valid whitespace characters |
| 9 * @param valid An array of strings containing valid attribute values | 9 * @param valid An array of strings containing valid attribute values |
| 10 * @param invalid An array of strings containing invalid attribute values | 10 * @param validUnits An array of strings containing valid unit specifiers |
| 11 * @param garbage An array of strings containing values that would make a valid
value invalid when concatenated | 11 * @param garbage An array of strings containing values that would make a valid
value invalid when concatenated |
| 12 * @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 | 12 * @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 |
| 13 * @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 | 13 * @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 |
| 14 */ | 14 */ |
| 15 function testType(type, target, attribute, expected, whitespace, valid, invalid,
validunits, garbage, assert_valid_custom, assert_invalid_custom) { | 15 function testType(type, target, attribute, expected, whitespace, valid, validuni
ts, garbage, assert_valid_custom, assert_invalid_custom) { |
| 16 whitespace.forEach(function(leading) { | 16 whitespace.forEach(function(leading) { |
| 17 whitespace.forEach(function(trailing) { | 17 whitespace.forEach(function(trailing) { |
| 18 valid.forEach(function(value) { | 18 valid.forEach(function(value) { |
| 19 validunits.forEach(function(unit) { | 19 validunits.forEach(function(unit) { |
| 20 var valueStr = leading + value + unit + trailing; | 20 var valueStr = leading + value + unit + trailing; |
| 21 var escapedValueStr = valueStr.replace(/(\r)/g, '\\r').repla
ce(/(\n)/g, '\\n').replace(/(\t)/g, '\\t').replace(/(\f)/g, '\\f'); | 21 var escapedValueStr = valueStr.replace(/(\r)/g, '\\r').repla
ce(/(\n)/g, '\\n').replace(/(\t)/g, '\\t').replace(/(\f)/g, '\\f'); |
| 22 test(function() { | 22 test(function() { |
| 23 try { | 23 try { |
| 24 target.setAttribute(attribute, valueStr); | 24 target.setAttribute(attribute, valueStr); |
| 25 assert_equals(target.getAttribute(attribute), valueS
tr); | 25 assert_equals(target.getAttribute(attribute), valueS
tr); |
| 26 assert_valid_custom(target, value); | 26 assert_valid_custom(target, value); |
| 27 } | 27 } |
| 28 finally { | 28 finally { |
| 29 target.removeAttribute(attribute); | 29 target.removeAttribute(attribute); |
| 30 } | 30 } |
| 31 }, "Test " + type + " valid value: " + escapedValueStr ); | 31 }, "Test " + type + " valid value: " + escapedValueStr ); |
| 32 }); | 32 }); |
| 33 }); | 33 }); |
| 34 | |
| 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 }); | 34 }); |
| 53 | 35 |
| 54 // test whitespace between value and unit | 36 // test whitespace between value and unit |
| 55 validunits.forEach(function(unit) { | 37 validunits.forEach(function(unit) { |
| 56 if (unit == "" || leading == "") | 38 if (unit == "" || leading == "") |
| 57 return; | 39 return; |
| 58 valid.forEach(function(value) { | 40 valid.forEach(function(value) { |
| 59 var valueStr = value + leading + unit; | 41 var valueStr = value + leading + unit; |
| 60 var escapedValueStr = valueStr.replace(/(\r)/g, '\\r').replace(/
(\n)/g, '\\n').replace(/(\t)/g, '\\t').replace(/(\f)/g, '\\f'); | 42 var escapedValueStr = valueStr.replace(/(\r)/g, '\\r').replace(/
(\n)/g, '\\n').replace(/(\t)/g, '\\t').replace(/(\f)/g, '\\f'); |
| 61 test(function() { | 43 test(function() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 83 assert_invalid_custom(target, expected); | 65 assert_invalid_custom(target, expected); |
| 84 } | 66 } |
| 85 finally { | 67 finally { |
| 86 target.removeAttribute(attribute); | 68 target.removeAttribute(attribute); |
| 87 } | 69 } |
| 88 }, "Test " + type + " trailing garbage, value: " + escapedValueS
tr); | 70 }, "Test " + type + " trailing garbage, value: " + escapedValueS
tr); |
| 89 }); | 71 }); |
| 90 }); | 72 }); |
| 91 }); | 73 }); |
| 92 } | 74 } |
| 75 |
| 76 /** |
| 77 * Tests attribute parsing and handling of invalid whitespace in attribute value
s. |
| 78 * |
| 79 * @param type Name of the type being tested (only for test output) |
| 80 * @param target The element that should be tested |
| 81 * @param attribute The name of the attribute that should be tested |
| 82 * @param expected The fallback/default value that is the expectation for invali
d values |
| 83 * @param whitespace An array of strings that are valid whitespace characters |
| 84 * @param invalid An array of strings containing invalid attribute values * @par
am garbage An array of strings containing values that would make a valid value i
nvalid when concatenated |
| 85 * @param validunits An array of strings containing valid unit specifiers |
| 86 * @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 |
| 87 * @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 |
| 88 */ |
| 89 function testInvalidType(type, target, attribute, expected, whitespace, invalid,
validunits, assert_valid_custom, assert_invalid_custom) { |
| 90 whitespace.forEach(function(leading) { |
| 91 whitespace.forEach(function(trailing) { |
| 92 // test invalid values |
| 93 invalid.forEach(function(value) { |
| 94 validunits.forEach(function(unit) { |
| 95 var valueStr = leading + value + unit + trailing; |
| 96 var escapedValueStr = valueStr.replace(/(\r)/g, '\\r').repla
ce(/(\n)/g, '\\n').replace(/(\t)/g, '\\t').replace(/(\f)/g, '\\f'); |
| 97 test(function() { |
| 98 try { |
| 99 target.setAttribute(attribute, valueStr); |
| 100 assert_equals(target.getAttribute(attribute), valueS
tr); |
| 101 assert_invalid_custom(target, expected); |
| 102 } |
| 103 finally { |
| 104 target.removeAttribute(attribute); |
| 105 } |
| 106 }, "Test " + type + " invalid value: " + escapedValueStr); |
| 107 }); |
| 108 }); |
| 109 }); |
| 110 }); |
| 111 } |
| 112 |
| OLD | NEW |