Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / svg / svgangle.html
blobe56cd696a9d4be7d424e930b90629149c6fd860c
1 <!doctype html>
2 <title>SVGAngle tests</title>
3 <script src=../../resources/testharness.js></script>
4 <script src=../../resources/testharnessreport.js></script>
5 <div id="testcontainer">
6 <svg width="1" height="1" visibility="hidden">
7 <defs><marker/></defs>
8 </svg>
9 </div>
10 <div id=log></div>
11 <script>
12 var svg = document.querySelector("svg");
13 var marker = document.querySelector("marker");
14 var EPSILON = Math.pow(2, -8);
15 var angles = [ 10, 0, 360, 500, 90, 180, 45, 25.9, 145, 270, 0.5, 0.2, 1.37, 3.14159 /* Math.PI */, 0.523599 /* Math.PI/6 */ ];
16 var units = {
17 "" : 1,
18 "deg": 2,
19 "rad": 3,
20 "grad": 4,
21 "turn": 5
23 var highestExposedUnit = 4; // SVG_ANGLETYPE_GRAD
24 var unitconstants = {
25 "UNKNOWN" : 0,
26 "UNSPECIFIED": 1,
27 "DEG": 2,
28 "RAD": 3,
29 "GRAD": 4,
31 var nonexposedunitconstants = {
32 "TURN": 5
35 function convertTo(value, unit, outunit) {
36 switch(unit) {
37 case "":
38 case "deg":
39 switch(outunit) {
40 case "":
41 case "deg":
42 return value;
43 case "rad":
44 return value*(Math.PI/180);
45 case "grad":
46 return value*(400/360);
47 case "turn":
48 return value/360;
50 case "rad":
51 switch(outunit) {
52 case "":
53 case "deg":
54 return value * 180 / Math.PI;
55 case "rad":
56 return value;
57 case "grad":
58 return value * 180 / Math.PI * 400 / 360;
59 case "turn":
60 return value / (2 * Math.PI);
62 case "grad":
63 switch(outunit) {
64 case "":
65 case "deg":
66 return value * 360 / 400;
67 case "rad":
68 return value * Math.PI * 2 / 400;
69 case "grad":
70 return value;
71 case "turn":
72 return value / 400;
74 case "turn":
75 switch(outunit) {
76 case "":
77 case "deg":
78 return value * 360;
79 case "rad":
80 return value * Math.PI * 2;
81 case "grad":
82 return value * 400;
83 case "turn":
84 return value;
89 function createAngle(valuestr) {
90 var angle = svg.createSVGAngle();
91 angle.valueAsString = valuestr;
92 return angle;
95 for(var unit in units) {
96 test(function() {
97 var result = undefined;
98 try {
99 var a = createAngle(47 + unit);
100 result = a.unitType;
102 catch(e) {}
103 if (units[unit] > highestExposedUnit)
104 assert_equals(result, undefined);
105 else
106 assert_equals(result, units[unit]);
107 }, "SVGAngle(47" + unit + ").unitType");
110 for(var constant in unitconstants) {
111 var str = "SVG_ANGLETYPE_" + constant;
112 test(function() {
113 assert_exists(SVGAngle, str, "");
114 }, "SVGAngle." + str);
116 for(var constant in nonexposedunitconstants) {
117 var str = "SVG_ANGLETYPE_" + constant;
118 test(function() {
119 assert_not_exists(SVGAngle, str, "");
120 }, "SVGAngle." + str);
123 angles.forEach(function(angle) {
124 for(var unit in units) {
125 var anglestr = angle + unit;
126 var ref;
127 try {
128 ref = createAngle(anglestr);
130 catch(e) {
131 continue;
134 test(function() {
135 assert_approx_equals(angle, ref.valueInSpecifiedUnits, EPSILON);
136 }, "SVGAngle(" + anglestr + ").valueInSpecifiedUnits");
138 try {
139 marker.setAttribute("orient", anglestr);
141 test(function() {
142 assert_equals(marker.orientAngle.baseVal.valueAsString, anglestr);
143 }, "orient=\"" + anglestr + "\".valueAsString");
145 test(function() {
146 assert_approx_equals(marker.orientAngle.baseVal.value, convertTo(angle, unit, "deg"), EPSILON);
147 }, "orient=\"" + anglestr + "\".value");
149 finally {
150 marker.removeAttribute("orient");
153 for (var otherunit in units) {
154 test(function() {
155 var a = createAngle(anglestr);
156 try {
157 a.convertToSpecifiedUnits(units[otherunit]);
159 catch(e) {}
161 // unknown unit
162 if (units[otherunit] > highestExposedUnit)
163 assert_approx_equals(a.valueInSpecifiedUnits, angle, EPSILON);
164 else
165 assert_approx_equals(a.valueInSpecifiedUnits, convertTo(angle, unit, otherunit), EPSILON);
166 }, "SVGAngle(" + anglestr + ").convertToSpecifiedUnits(" + units[otherunit] + " /*" + (otherunit ? otherunit : "unspecified") + "*/)");
168 test(function() {
169 var result = "";
170 try {
171 var a = createAngle(47 + otherunit);
172 a.newValueSpecifiedUnits(units[unit], angle);
173 result = a.valueAsString;
175 catch(e) {
178 // unknown unit
179 if (units[unit] > highestExposedUnit || units[otherunit] > highestExposedUnit)
180 assert_equals(result, "");
181 else
182 assert_equals(result, ref.valueAsString);
183 }, "newValueSpecifiedUnits(" + units[unit] + ", " + angle + ")" );
188 </script>