test_getTotalLength.xhtml (1980B)
1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1474284 5 --> 6 <head> 7 <title>Test for Bug 1474284</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1474284">Mozilla Bug 1474284</a> 13 <p id="display"></p> 14 15 <svg xmlns="http://www.w3.org/2000/svg"> 16 <path id="path1" stroke="#000" fill="none" 17 d="M 50,40 18 C 50,40 0,60 30,20"/> 19 <symbol font-size="10" width="20em" height="20em"> 20 <rect id="r1" x="5em" y="6em" width="20%" height="30%" /> 21 </symbol> 22 </svg> 23 24 <pre id="test"> 25 <script class="testbody" type="application/javascript"> 26 SimpleTest.waitForExplicitFinish(); 27 28 function run() { 29 isfuzzy(document.getElementById("path1").getTotalLength(), 30 55.19, 0.02, 31 'getTotalLength() on element id="path1" returned the wrong value'); 32 33 let r1 = document.getElementById("r1"); 34 is(r1.getTotalLength(), 210, "getTotalLength() should work for non-rendered element"); 35 36 let r2 = document.createElementNS("http://www.w3.org/2000/svg", "rect"); 37 r2.setAttribute("width", 200); 38 r2.setAttribute("height", 300); 39 is(r2.getTotalLength(), 1000, "getTotalLength() should work for a rect element not in the document"); 40 41 let c = document.createElementNS("http://www.w3.org/2000/svg", "circle"); 42 c.setAttribute("r", 200); 43 isfuzzy(c.getTotalLength(), 2 * Math.PI * 200, 0.2, "getTotalLength() should work for a circle element not in the document"); 44 45 let e = document.createElementNS("http://www.w3.org/2000/svg", "ellipse"); 46 e.setAttribute("rx", 200); 47 e.setAttribute("ry", 200); 48 isfuzzy(e.getTotalLength(), 2 * Math.PI * 200, 0.2, "getTotalLength() should work for an ellipse element not in the document"); 49 50 SimpleTest.finish(); 51 } 52 53 window.addEventListener("load", run); 54 </script> 55 </pre> 56 </body> 57 </html>