test_length.xhtml (2427B)
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <!-- 3 https://bugzilla.mozilla.org/show_bug.cgi?id=342513 4 --> 5 <head> 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" /> 9 </head> 10 <body> 11 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=342513">Mozilla Bug 342513</a> 12 <p id="display"></p> 13 <div id="content"> 14 15 <div width="100%" height="1" id="div"> 16 </div> 17 <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="1" id="svg"> 18 </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%" /> 22 </svg> 23 <div style="zoom: 2;"> 24 <svg width="40" height="40"> 25 <rect id="r2" width="25" height="20" /> 26 </svg> 27 </div> 28 </svg> 29 30 </div> 31 <pre id="test"> 32 <script class="testbody" type="text/javascript"> 33 <![CDATA[ 34 35 SimpleTest.waitForExplicitFinish(); 36 37 function run() { 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"); 43 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"); 49 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>"); 53 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"); 57 58 SimpleTest.finish(); 59 } 60 61 window.addEventListener("load", run); 62 63 ]]> 64 </script> 65 </pre> 66 </body> 67 </html>