OLD | NEW |
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!DOCTYPE HTML> |
2 <html> | 2 <title>SVGLength interface</title> |
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. |
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("NotSupportedError", function() { length.convertToSpecifiedUnits
(SVGLength.SVG_LENGTHTYPE_UNKNOWN); }); |
| 25 assert_throws("NotSupportedError", function() { length.convertToSpecifiedUnits
(-1); }); |
| 26 assert_throws("NotSupportedError", function() { length.convertToSpecifiedUnits
(11); }); |
| 27 assert_throws("NotSupportedError", function() { length.convertToSpecifiedUnits
('aString'); }); |
| 28 assert_throws("NotSupportedError", function() { length.convertToSpecifiedUnits
(length); }); |
| 29 assert_throws("NotSupportedError", 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.valueAsString, "2px"); |
| 35 |
| 36 // Check invalid arguments for 'newValueSpecifiedUnits'. |
| 37 assert_throws("NotSupportedError", function() { length.newValueSpecifiedUnits(
SVGLength.SVG_LENGTHTYPE_UNKNOWN, 4); }); |
| 38 assert_throws("NotSupportedError", function() { length.newValueSpecifiedUnits(
-1, 4); }); |
| 39 assert_throws("NotSupportedError", 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("NotSupportedError", function() { length.newValueSpecifiedUnits(
'aString', 4); }); |
| 56 assert_throws("NotSupportedError", function() { length.newValueSpecifiedUnits(
length, 4); }); |
| 57 assert_throws("NotSupportedError", 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.valueAsString, "2px"); |
| 65 |
| 66 // Check setting invalid 'valueAsString' arguments. |
| 67 assert_throws("SyntaxError", function() { length.valueAsString = '10deg'; }); |
| 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("SyntaxError", function() { length.valueAsString = ',5 em'; }); |
| 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("SyntaxError", function() { length.valueAsString = null; }); |
| 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> |
OLD | NEW |