2 <title>SVGlength tests
</title>
3 <script src=../../resources/testharness.js
></script>
4 <script src=../../resources/testharnessreport.js
></script>
5 <div id=
"testcontainer">
6 <svg width=
"1" height=
"1" visibility=
"hidden">
11 var svg
= document
.querySelector("svg");
12 var EPSILON
= Math
.pow(2, -8);
13 var lengths
= [ 10, 0, 360, 500, 90, 180, 45, 25.9];
29 var highestExposedUnit
= 10; // SVG_LENGTHTYPE_PC
43 var nonexposedunitconstants
= {
48 function convertTo(value
, unit
, outunit
) {
50 var cssPixelsPerInch
= 96;
51 var cssPixelsPerCentimeter
= cssPixelsPerInch
/ 2.54; //2.54 cm/in
52 var cssPixelsPerMillimeter
= cssPixelsPerCentimeter
/ 10;
53 var cssPixelsPerPoint
= cssPixelsPerInch
/ 72;
54 var cssPixelsPerPica
= cssPixelsPerInch
/ 6;
68 userUnits
= value
* cssPixelsPerCentimeter
;
71 userUnits
= value
* cssPixelsPerMillimeter
;
74 userUnits
= value
* cssPixelsPerInch
;
77 userUnits
= value
* cssPixelsPerPoint
;
80 userUnits
= value
* cssPixelsPerPica
;
95 return userUnits
/ cssPixelsPerCentimeter
;
97 return userUnits
/ cssPixelsPerMillimeter
;
99 return userUnits
/ cssPixelsPerInch
;
101 return userUnits
/ cssPixelsPerPoint
;
103 return userUnits
/ cssPixelsPerPica
;
107 function createLength(valuestr
) {
108 var length
= svg
.createSVGLength();
109 length
.valueAsString
= valuestr
;
113 for(var unit
in units
) {
115 var result
= undefined;
117 var a
= createLength(10 + unit
);
121 if (units
[unit
] > highestExposedUnit
)
122 assert_equals(result
, undefined);
124 assert_equals(result
, units
[unit
]);
125 }, "SVGLength(10" + unit
+ ").unitType");
128 for(var constant
in unitconstants
) {
129 var str
= "SVG_LENGTHTYPE_" + constant
;
131 assert_exists(SVGLength
, str
, "");
132 }, "SVGLength." + str
);
134 for(var constant
in nonexposedunitconstants
) {
135 var str
= "SVG_LENGTHTYPE_" + constant
;
137 assert_not_exists(SVGLength
, str
, "");
138 }, "SVGLength." + str
);
141 lengths
.forEach(function(length
) {
142 for(var unit
in units
) {
143 var lengthstr
= length
+ unit
;
146 ref
= createLength(lengthstr
);
153 assert_approx_equals(length
, ref
.valueInSpecifiedUnits
, EPSILON
);
154 }, "SVGLength(" + lengthstr
+ ").valueInSpecifiedUnits");
156 for (var otherunit
in units
) {
158 var a
= createLength(lengthstr
);
160 a
.convertToSpecifiedUnits(units
[otherunit
]);
165 if (units
[otherunit
] > highestExposedUnit
)
166 assert_approx_equals(a
.valueInSpecifiedUnits
, length
, EPSILON
);
168 assert_approx_equals(a
.valueInSpecifiedUnits
, convertTo(length
, unit
, otherunit
), EPSILON
);
169 }, "SVGLength(" + lengthstr
+ ").convertToSpecifiedUnits(" + units
[otherunit
] + " /*" + (otherunit
? otherunit
: "unspecified") + "*/)");
174 var a
= createLength(47 + otherunit
);
175 a
.newValueSpecifiedUnits(units
[unit
], length
);
176 result
= a
.valueAsString
;
182 if (units
[unit
] > highestExposedUnit
|| units
[otherunit
] > highestExposedUnit
)
183 assert_equals(result
, "");
185 assert_equals(result
, ref
.valueAsString
);
186 }, "newValueSpecifiedUnits(" + units
[unit
] + ", " + length
+ ")" );