Rubber-stamped by Brady Eidson.
[webbrowser.git] / LayoutTests / svg / custom / path-getTotalLength.svg
blob46211a7578001ec7e8d0e5b2638170547e56c765
1 <svg xmlns="http://www.w3.org/2000/svg">
2 <g id='log' />
3 <script>
4 <![CDATA[
5 if (window.layoutTestController)
6 layoutTestController.dumpAsText();
8 var svgNS = "http://www.w3.org/2000/svg";
9 var pathElement = document.createElementNS(svgNS, 'path');
10 var errorTolerance = .1;
12 var logOffset = 20;
13 function result(didPass, string) {
14 var newText = document.createElementNS(svgNS, "text");
15 newText.setAttribute("x", 10);
16 newText.setAttribute("y", logOffset);
17 logOffset += 20;
18 newText.textContent = string;
19 var newTspan = document.createElementNS(svgNS, "tspan");
20 if (didPass) {
21 newTspan.textContent = "PASS: ";
22 newTspan.style.fill = "green";
23 } else {
24 newTspan.textContent = "FAIL: ";
25 newTspan.style.fill = "red";
27 newText.insertBefore(newTspan, newText.firstChild);
28 document.getElementById('log').appendChild(newText);
31 function expectLength(path, expectedLength) {
32 pathElement.setAttribute("d", path);
34 var actualLength;
35 try {
36 actualLength = pathElement.getTotalLength();
37 if (Math.abs(actualLength - expectedLength) < errorTolerance)
38 result(true, path + "\" = " + actualLength);
39 else
40 result(false, path + "\" expected: " + expectedLength + " actual: " + actualLength);
41 } catch(e) {
42 result(false, path + "\" expected: " + expectedLength + " got exception: " + e);
46 var errorCount = 0;
48 // Tests go here:
49 expectLength('M 0 0 L 100 0 L 100 100 L 0 100 Z', 400);
50 expectLength('M 0 0 l 100 0 l 0 100 l -100 0 Z', 400);
51 expectLength('M 0 0 t 0 100', 100);
52 expectLength('M 0 0 Q 55 50 100 100', 141.4); // I'm not sure if this is actually right
53 ]]>
54 </script>
55 </svg>