OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>SVGGeometryElement.getTotalLength method (element attached)</title> |
| 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <svg></svg> |
| 6 <script> |
| 7 setup(function() { |
| 8 window.svgElement = document.querySelector("svg"); |
| 9 }); |
| 10 |
| 11 test(function() { |
| 12 var pathElement = document.createElementNS("http://www.w3.org/2000/svg", "path
"); |
| 13 svgElement.appendChild(pathElement); |
| 14 |
| 15 function getTotalLength(string) { |
| 16 pathElement.setAttribute("d", string); |
| 17 return pathElement.getTotalLength(); |
| 18 } |
| 19 |
| 20 assert_equals(getTotalLength('M0,20 L400,20 L640,20'), 640); |
| 21 assert_equals(getTotalLength('M0,20 L400,20 L640,20 z'), 1280); |
| 22 assert_equals(getTotalLength('M0,20 L400,20 z M 320,20 L640,20'), 1120); |
| 23 }, document.title + " with SVGPathElement"); |
| 24 |
| 25 test(function() { |
| 26 var rectElement = document.createElementNS("http://www.w3.org/2000/svg", "rect
"); |
| 27 svgElement.appendChild(rectElement); |
| 28 |
| 29 function getTotalLength(rx, ry, width, height) { |
| 30 rectElement.setAttribute("rx", rx); |
| 31 rectElement.setAttribute("ry", ry); |
| 32 rectElement.setAttribute("width", width); |
| 33 rectElement.setAttribute("height", height); |
| 34 |
| 35 return rectElement.getTotalLength(); |
| 36 } |
| 37 |
| 38 assert_equals(getTotalLength(0, 0, 200, 300), 1000); |
| 39 assert_approx_equals(getTotalLength(50, 50, 200, 300), 913.65, 0.1); |
| 40 }, document.title + " with SVGRectElement"); |
| 41 |
| 42 test(function() { |
| 43 var circleElement = document.createElementNS("http://www.w3.org/2000/svg", "ci
rcle"); |
| 44 svgElement.appendChild(circleElement); |
| 45 |
| 46 circleElement.setAttribute("r", 10); |
| 47 assert_approx_equals(circleElement.getTotalLength(), 62.42, 0.1); |
| 48 circleElement.setAttribute("r", 20); |
| 49 assert_approx_equals(circleElement.getTotalLength(), 124.85, 0.1); |
| 50 }, document.title + " with SVGCircleElement"); |
| 51 </script> |
OLD | NEW |