Bug 1941128 - Turn off network.dns.native_https_query on Mac again
[gecko.git] / dom / svg / test / test_lengthParsing.html
blob8471b198553df455a8469b2dc6a03ac0242d439c
1 <!doctype html>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=946529
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test transform parsing</title>
9 <script src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=946529">Mozilla Bug 946529</a>
14 <p id="display"></p>
15 <div id="content" style="display: none">
16 <svg width="100%" height="1" id="svg">
17 <rect id="rect"/>
18 </svg>
19 </div>
20 <pre id="test">
21 <script class="testbody" type="text/javascript">
22 // Test cases
23 checkParseOk("", 0);
24 checkParseOk("-.1", -0.1);
25 checkParseOk("1e1", 10);
26 checkParseOk("1em", 1, "em");
27 checkParseOk("1ex", 1, "ex");
28 checkParseOk("1e1em", 10, "em");
29 checkParseOk("1E+2", 100);
30 checkParseOk(".1e-2", 0.001);
31 checkParseOk(" 10", 10);
32 checkParseOk("10 ", 10);
33 checkParseOk(" 10 ", 10);
34 checkParseOk(" 10em ", 10, "em");
36 // Fail cases
37 checkParseFail("1e");
38 checkParseFail("1 e");
39 checkParseFail("1 em");
40 checkParseFail("1ee");
41 checkParseFail(" 10 20");
43 function checkParseOk(spec, valueInUnits, units) {
44 var rect = document.getElementById("rect");
46 // Clear previous value
47 rect.removeAttribute("x");
48 rect.setAttribute("x", spec);
50 // Check number part
51 const tolerance = 1 / 65535;
52 var actual = rect.x.baseVal.valueInSpecifiedUnits;
53 ok(Math.abs(actual - valueInUnits) < tolerance,
54 spec + " (value) - got " + actual + ", expected " + valueInUnits);
56 // Check unit part
57 var unitMapping = {
58 "unknown": SVGLength.SVG_LENGTHTYPE_UNKNOWN,
59 "": SVGLength.SVG_LENGTHTYPE_NUMBER,
60 "%": SVGLength.SVG_LENGTHTYPE_PERCENTAGE,
61 "em": SVGLength.SVG_LENGTHTYPE_EMS,
62 "ex": SVGLength.SVG_LENGTHTYPE_EXS,
63 "px": SVGLength.SVG_LENGTHTYPE_PX,
64 "cm": SVGLength.SVG_LENGTHTYPE_CM,
65 "mm": SVGLength.SVG_LENGTHTYPE_MM,
66 "in": SVGLength.SVG_LENGTHTYPE_IN,
67 "pt": SVGLength.SVG_LENGTHTYPE_PT,
68 "pc": SVGLength.SVG_LENGTHTYPE_PC,
70 if (typeof units == "undefined") {
71 units = "";
73 is(rect.x.baseVal.unitType, unitMapping[units], spec + " (unit)");
76 function checkParseFail(spec) {
77 checkParseOk(spec, 0);
79 </script>
80 </pre>
81 </body>
82 </html>