Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!DOCTYPE HTML> |
| 2 <html> | 2 <title>Checks the SVGLength API</title> |
|
fs
2016/08/25 10:16:52
Make this just 'SVGLength interface'.
Shanmuga Pandi
2016/08/26 07:35:18
Done.
| |
| 3 <head> | 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 </head> | 5 <script> |
| 6 <body> | 6 test(function() { |
| 7 <p id="description"></p> | 7 var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg") ; |
| 8 <div id="console"></div> | 8 var length = svgElement.createSVGLength(); |
| 9 <script src="script-tests/SVGLength.js"></script> | 9 |
| 10 </body> | 10 // Check initial length values |
|
fs
2016/08/25 10:16:52
End sentences with full stop (".").
Shanmuga Pandi
2016/08/26 07:35:18
Done.
| |
| 11 </html> | 11 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_NUMBER); |
| 12 assert_equals(length.value, 0); | |
| 13 assert_equals(length.valueInSpecifiedUnits, 0); | |
| 14 assert_equals(length.valueAsString, "0"); | |
| 15 | |
| 16 // Set value to be 2px | |
| 17 length.valueAsString = "2px"; | |
| 18 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX); | |
| 19 assert_equals(length.value, 2); | |
| 20 assert_equals(length.valueInSpecifiedUnits, 2); | |
| 21 assert_equals(length.valueAsString, "2px"); | |
| 22 | |
| 23 // Check invalid arguments for 'convertToSpecifiedUnits' | |
| 24 assert_throws(null, function() { length.convertToSpecifiedUnits(SVGLength.SVG_ LENGTHTYPE_UNKNOWN); }); | |
|
fs
2016/08/25 10:16:52
'NotSupportedError'? (same for the following five)
Shanmuga Pandi
2016/08/26 07:35:18
Done.
| |
| 25 assert_throws(null, function() { length.convertToSpecifiedUnits(-1); }); | |
| 26 assert_throws(null, function() { length.convertToSpecifiedUnits(11); }); | |
| 27 assert_throws(null, function() { length.convertToSpecifiedUnits('aString'); }) ; | |
| 28 assert_throws(null, function() { length.convertToSpecifiedUnits(length); }); | |
| 29 assert_throws(null, function() { length.convertToSpecifiedUnits(svgElement); } ); | |
| 30 assert_throws(new TypeError(), function() { length.convertToSpecifiedUnits(); }); | |
| 31 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX); | |
| 32 assert_equals(length.value, 2); | |
| 33 assert_equals(length.valueInSpecifiedUnits, 2); | |
| 34 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX); | |
|
fs
2016/08/25 10:16:52
You can drop one of these two asserts of unitType.
Shanmuga Pandi
2016/08/26 07:35:18
Done.
| |
| 35 | |
| 36 // Check invalid arguments for 'newValueSpecifiedUnits' | |
| 37 assert_throws(null, function() { length.newValueSpecifiedUnits(SVGLength.SVG_L ENGTHTYPE_UNKNOWN, 4); }); | |
|
fs
2016/08/25 10:16:52
'NotSupportedError' (+two more)
Shanmuga Pandi
2016/08/26 07:35:18
Done.
| |
| 38 assert_throws(null, function() { length.newValueSpecifiedUnits(-1, 4); }); | |
| 39 assert_throws(null, function() { length.newValueSpecifiedUnits(11, 4); }); | |
| 40 // ECMA-262, 9.3, "ToNumber" | |
| 41 length.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX, 0); | |
| 42 assert_throws(new TypeError(), function() { length.newValueSpecifiedUnits(SVGL ength.SVG_LENGTHTYPE_PX, 'aString'); }); | |
| 43 assert_equals(length.value, 0); | |
| 44 assert_throws(new TypeError(), function() { length.newValueSpecifiedUnits(SVGL ength.SVG_LENGTHTYPE_PX, length); }); | |
| 45 assert_equals(length.value, 0); | |
| 46 assert_throws(new TypeError(), function() { length.newValueSpecifiedUnits(SVGL ength.SVG_LENGTHTYPE_PX, svgElement); }); | |
| 47 assert_equals(length.value, 0); | |
| 48 assert_throws(new TypeError(), function() { length.newValueSpecifiedUnits(SVGL ength.SVG_LENGTHTYPE_PX, NaN); }); | |
| 49 assert_equals(length.value, 0); | |
| 50 assert_throws(new TypeError(), function() { length.newValueSpecifiedUnits(SVGL ength.SVG_LENGTHTYPE_PX, Infinity); }); | |
| 51 assert_equals(length.value, 0); | |
| 52 assert_throws(new TypeError(), function() { length.newValueSpecifiedUnits(SVGL ength.SVG_LENGTHTYPE_PX); }); | |
| 53 // Reset to original value above. | |
| 54 length.valueAsString = "2px"; | |
| 55 assert_throws(null, function() { length.newValueSpecifiedUnits('aString', 4); }); | |
|
fs
2016/08/25 10:16:52
NotSupportedError (+2)
Shanmuga Pandi
2016/08/26 07:35:18
Done.
| |
| 56 assert_throws(null, function() { length.newValueSpecifiedUnits(length, 4); }); | |
| 57 assert_throws(null, function() { length.newValueSpecifiedUnits(svgElement, 4); }); | |
| 58 assert_throws(new TypeError(), function() { length.newValueSpecifiedUnits('aSt ring', 'aString'); }); | |
| 59 assert_throws(new TypeError(), function() { length.newValueSpecifiedUnits(leng th, length); }); | |
| 60 assert_throws(new TypeError(), function() { length.newValueSpecifiedUnits(svgE lement, svgElement); }); | |
| 61 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX); | |
| 62 assert_equals(length.value, 2); | |
| 63 assert_equals(length.valueInSpecifiedUnits, 2); | |
| 64 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX); | |
|
fs
2016/08/25 10:16:52
Drop one of the unitType asserts. (Or replace with
Shanmuga Pandi
2016/08/26 07:35:19
Done.
| |
| 65 | |
| 66 // Check setting invalid 'valueAsString' arguments | |
| 67 assert_throws(null, function() { length.valueAsString = '10deg'; }); | |
|
fs
2016/08/25 10:16:52
SyntaxError
Shanmuga Pandi
2016/08/26 07:35:19
Done.
| |
| 68 assert_equals(length.valueAsString, "2px"); | |
| 69 assert_equals(length.value, 2); | |
| 70 assert_equals(length.valueInSpecifiedUnits, 2); | |
| 71 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX); | |
| 72 | |
| 73 length.valueAsString = '1pX'; // should not throw exception | |
| 74 assert_equals(length.valueAsString, "1px"); | |
| 75 assert_equals(length.value, 1); | |
| 76 assert_equals(length.valueInSpecifiedUnits, 1); | |
| 77 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX); | |
| 78 | |
| 79 length.valueAsString = "2px"; // reset to 2px | |
| 80 | |
| 81 assert_throws(null, function() { length.valueAsString = ',5 em'; }); | |
|
fs
2016/08/25 10:16:52
SyntaxError
| |
| 82 assert_equals(length.valueAsString, "2px"); | |
| 83 assert_equals(length.value, 2); | |
| 84 assert_equals(length.valueInSpecifiedUnits, 2); | |
| 85 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX); | |
| 86 | |
| 87 assert_throws(null, function() { length.valueAsString = null; }); | |
|
fs
2016/08/25 10:16:52
SyntaxError
| |
| 88 assert_equals(length.valueAsString, "2px"); | |
| 89 assert_equals(length.value, 2); | |
| 90 assert_equals(length.valueInSpecifiedUnits, 2); | |
| 91 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX); | |
| 92 | |
| 93 // Check setting invalid 'value' arguments | |
| 94 assert_throws(new TypeError(), function() { length.value = NaN; }); | |
| 95 assert_throws(new TypeError(), function() { length.value = Infinity; }); | |
| 96 assert_equals(length.value, 2); | |
| 97 assert_equals(length.valueInSpecifiedUnits, 2); | |
| 98 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX); | |
| 99 | |
| 100 // Check setting invalid 'valueInSpecifiedUnits' arguments | |
| 101 assert_throws(new TypeError(), function() { length.valueInSpecifiedUnits = NaN ; }); | |
| 102 assert_throws(new TypeError(), function() { length.valueInSpecifiedUnits = Inf inity; }); | |
| 103 assert_equals(length.value, 2); | |
| 104 assert_equals(length.valueInSpecifiedUnits, 2); | |
| 105 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX); | |
| 106 }); | |
| 107 </script> | |
| 108 | |
|
fs
2016/08/25 10:16:52
Drop blank line.
Shanmuga Pandi
2016/08/26 07:35:18
Done.
| |
| OLD | NEW |