OLD | NEW |
---|---|
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!DOCTYPE HTML> |
2 <html> | 2 <title>SVGLength, converting from 'px' to other units (detached)</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 var cssPixelsPerInch = 96; |
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; |
9 <script src="script-tests/SVGLength-px.js"></script> | 9 function setup() { |
fs
2016/08/26 09:03:07
Use testharness setup():
setup(function() {
win
Shanmuga Pandi
2016/09/01 11:59:56
Done.
fs
2016/09/01 12:31:12
Doesn't look done to me. Having as clean a slate a
Shanmuga Pandi
2016/09/01 13:18:17
Could you please check this now.?
fs
2016/09/01 13:22:54
Still the same, did you forget to upload? What I m
Shanmuga Pandi
2016/09/01 14:00:36
Ok. There was some misunderstanding. I will upload
Shanmuga Pandi
2016/09/01 14:13:03
Done. Please check now. Thanks
fs
2016/09/01 14:14:58
No, that one is fine as is because it needs to be
| |
10 </body> | 10 length = svgElement.createSVGLength(); |
11 </html> | 11 // Set value to be 2px |
12 length.valueAsString = "2px"; | |
13 } | |
14 | |
15 test(function() { | |
16 setup(); | |
17 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX); | |
18 assert_equals(length.value, 2); | |
19 assert_equals(length.valueInSpecifiedUnits, 2); | |
20 assert_equals(length.valueAsString, "2px"); | |
21 }, "Check initial value to be 2px"); | |
fs
2016/08/26 09:03:07
I'd suggest the following format for testnames:
d
Shanmuga Pandi
2016/09/01 11:59:56
Done.
| |
22 | |
23 test(function() { | |
24 setup(); | |
25 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_NUMBER); | |
26 assert_equals(length.valueAsString, "2"); | |
27 assert_equals(length.value, 2); | |
28 assert_equals(length.valueInSpecifiedUnits, 2); | |
29 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_NUMBER); | |
30 }, "Convert from px to unitless"); | |
31 | |
32 test(function() { | |
33 setup(); | |
34 // Try converting from px to percentage, should fail as the SVGLength is not a ssociated with a SVGSVGElement, and thus no viewport information is available. | |
35 assert_throws("NotSupportedError", function() { length.convertToSpecifiedUnits (SVGLength.SVG_LENGTHTYPE_PERCENTAGE); }); | |
36 assert_equals(length.valueAsString, "2px"); | |
37 assert_equals(length.value, 2); | |
38 assert_equals(length.valueInSpecifiedUnits, 2); | |
39 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX); | |
40 }, "Convert from px to percentage"); | |
41 | |
42 test(function() { | |
43 setup(); | |
44 // Try converting from px to ems, should fail as the SVGLength is not associat ed with a SVGSVGElement, and thus no font-size information is available. | |
45 assert_throws("NotSupportedError", function() { length.convertToSpecifiedUnits (SVGLength.SVG_LENGTHTYPE_EMS); }); | |
46 assert_equals(length.valueAsString, "2px"); | |
47 assert_equals(length.value, 2); | |
48 assert_equals(length.valueInSpecifiedUnits, 2); | |
49 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX); | |
50 }, "Convert from px to ems"); | |
51 | |
52 test(function() { | |
53 setup(); | |
54 // Try converting from px to exs, should fail as the SVGLength is not associat ed with a SVGSVGElement, and thus no font-size information is available. | |
55 assert_throws("NotSupportedError", function() { length.convertToSpecifiedUnits (SVGLength.SVG_LENGTHTYPE_EXS); }); | |
56 assert_equals(length.valueAsString, "2px"); | |
57 assert_equals(length.value, 2); | |
58 assert_equals(length.valueInSpecifiedUnits, 2); | |
59 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PX); | |
60 }, "Convert from px to exs"); | |
61 | |
62 test(function() { | |
63 setup(); | |
64 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_CM); | |
65 referenceValue = Number(2 * 2.54 / cssPixelsPerInch).toFixed(7); | |
66 assert_equals(length.valueAsString, referenceValue + "cm"); | |
67 assert_equals(length.valueInSpecifiedUnits.toFixed(7), referenceValue); | |
68 assert_equals(length.value.toFixed(1), "2.0"); | |
69 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_CM); | |
70 }, "Convert from px to cm"); | |
71 | |
72 test(function() { | |
73 setup(); | |
74 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_MM); | |
75 referenceValue = Number(2 * 25.4 / cssPixelsPerInch).toFixed(6); | |
76 assert_equals(length.valueAsString, referenceValue + "mm"); | |
77 assert_equals(length.valueInSpecifiedUnits.toFixed(6), referenceValue); | |
78 assert_equals(length.value.toFixed(1), "2.0"); | |
79 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_MM); | |
80 }, "Convert from px to mm"); | |
81 | |
82 test(function() { | |
83 setup(); | |
84 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_IN); | |
85 referenceValue = Number(2 / cssPixelsPerInch).toFixed(7); | |
86 assert_equals(length.valueAsString, referenceValue + "in"); | |
87 assert_equals(length.valueInSpecifiedUnits.toFixed(7), referenceValue); | |
88 assert_equals(length.value.toFixed(1), "2.0"); | |
89 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_IN); | |
90 }, "Convert from px to in"); | |
91 | |
92 test(function() { | |
93 setup(); | |
94 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PT); | |
95 referenceValue = Number(2 / cssPixelsPerInch * 72); | |
96 assert_equals(length.valueAsString, referenceValue + "pt"); | |
97 assert_equals(length.valueInSpecifiedUnits, referenceValue); | |
98 assert_equals(length.value.toFixed(1), "2.0"); | |
99 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PT); | |
100 }, "Convert from px to pt"); | |
101 | |
102 test(function() { | |
103 setup(); | |
104 length.convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PC); | |
105 referenceValue = Number(2 / cssPixelsPerInch * 6).toFixed(3); | |
106 // Don't check valueAsString here, it's unreliable across browsers. | |
107 assert_equals(length.valueInSpecifiedUnits.toFixed(3), referenceValue); | |
108 assert_equals(length.value.toFixed(1), "2.0"); | |
109 assert_equals(length.unitType, SVGLength.SVG_LENGTHTYPE_PC); | |
110 }, "Convert from px to pc"); | |
111 </script> | |
OLD | NEW |