1 <html xmlns=
"http://www.w3.org/1999/xhtml">
3 https://bugzilla.mozilla.org/show_bug.cgi?id=342513
6 <title>Test SVG Length conversions
</title>
7 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
8 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
11 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=342513">Mozilla Bug
342513</a>
15 <div width=
"100%" height=
"1" id=
"div">
17 <svg xmlns=
"http://www.w3.org/2000/svg" width=
"100%" height=
"1" id=
"svg">
19 <svg xmlns=
"http://www.w3.org/2000/svg" width=
"600" height=
"400" font-size=
"5">
20 <svg font-size=
"10" width=
"20em" height=
"20em">
21 <rect id=
"r1" x=
"5em" y=
"6em" width=
"20%" height=
"30%" />
23 <div style=
"zoom: 2;">
24 <svg width=
"40" height=
"40">
25 <rect id=
"r2" width=
"25" height=
"20" />
32 <script class=
"testbody" type=
"text/javascript">
35 SimpleTest.waitForExplicitFinish();
38 var svgDoc = document.getElementById(
"svg");
39 var divElem = document.getElementById(
"div");
40 var expectedWidth = divElem.clientWidth;
41 // test for the pixel width of the svg
42 isfuzzy(svgDoc.width.baseVal.value, expectedWidth,
0.01,
"svgDoc.width.baseVal.value");
44 // set the SVG width to ~
50% in pixels
45 svgDoc.width.baseVal.newValueSpecifiedUnits(svgDoc.width.baseVal.SVG_LENGTHTYPE_PX, Math.floor(expectedWidth /
2));
46 svgDoc.width.baseVal.convertToSpecifiedUnits(svgDoc.width.baseVal.SVG_LENGTHTYPE_PERCENTAGE);
47 // the valueInSpecifiedUnits should now be
50%
48 is(Math.round(svgDoc.width.baseVal.valueInSpecifiedUnits),
50,
"valueInSpecifiedUnits after convertToSpecifiedUnits");
50 let r1 = document.getElementById(
"r1");
51 is(r1.width.baseVal.value,
40,
"width in em for elements inside inner <svg> should be resolved against the inner <svg>");
52 is(r1.height.baseVal.value,
60,
"height in em for elements inside inner <svg> should be resolved against the inner <svg>");
54 let r2 = document.getElementById(
"r2");
55 is(r2.width.baseVal.value,
25,
"width in px for elements in zoomed div should be the same as unzoomed");
56 is(r2.height.baseVal.value,
20,
"height in px for elements inside zoomed div should be the same as unzoomed");
61 window.addEventListener(
"load", run);