Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: LayoutTests/fast/svg/svgangle.html

Issue 303263008: [SVG2] Add support for the 'turn' unit in <angle>. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fixups for MathExtras Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | LayoutTests/svg/css/svg-angle-turn.svg » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.1 4159 /* Math.PI */, 0.523599 /* Math.PI/6 */ ];
16 var units = {
17 "" : 1,
18 "deg": 2,
19 "rad": 3,
20 "grad": 4,
21 "turn": 5
22 };
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,
30 };
31 var nonexposedunitconstants = {
32 "TURN": 5
33 };
34
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;
49 }
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);
61 }
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;
73 }
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;
85 }
86 }
87 }
88
89 function createAngle(valuestr) {
90 var angle = svg.createSVGAngle();
91 angle.valueAsString = valuestr;
92 return angle;
93 }
94
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;
101 }
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");
108 }
109
110 for(var constant in unitconstants) {
111 var str = "SVG_ANGLETYPE_" + constant;
112 test(function() {
113 assert_exists(SVGAngle, str, "");
114 }, "SVGAngle." + str);
115 }
116 for(var constant in nonexposedunitconstants) {
117 var str = "SVG_ANGLETYPE_" + constant;
118 test(function() {
119 assert_not_exists(SVGAngle, str, "");
120 }, "SVGAngle." + str);
121 }
122
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);
129 }
130 catch(e) {
131 continue;
132 }
133
134 test(function() {
135 assert_approx_equals(angle, ref.valueInSpecifiedUnits, E PSILON);
136 }, "SVGAngle(" + anglestr + ").valueInSpecifiedUnits");
137
138 try {
139 marker.setAttribute("orient", anglestr);
140
141 test(function() {
142 assert_equals(marker.orientAngle.baseVal.valueAs String, anglestr);
143 }, "orient=\"" + anglestr + "\".valueAsString");
144
145 test(function() {
146 assert_approx_equals(marker.orientAngle.baseVal. value, convertTo(angle, unit, "deg"), EPSILON);
147 }, "orient=\"" + anglestr + "\".value");
148 }
149 finally {
150 marker.removeAttribute("orient");
151 }
152
153 for (var otherunit in units) {
154 test(function() {
155 var a = createAngle(anglestr);
156 try {
157 a.convertToSpecifiedUnits(units[otheruni t]);
158 }
159 catch(e) {}
160
161 // unknown unit
162 if (units[otherunit] > highestExposedUnit)
163 assert_approx_equals(a.valueInSpecifiedU nits, angle, EPSILON);
164 else
165 assert_approx_equals(a.valueInSpecifiedU nits, convertTo(angle, unit, otherunit), EPSILON);
166 }, "SVGAngle(" + anglestr + ").convertToSpecifiedUnits(" + units[otherunit] + " /*" + (otherunit ? otherunit : "unspecified") + "*/)");
167
168 test(function() {
169 var result = "";
170 try {
171 var a = createAngle(47 + otherunit);
172 a.newValueSpecifiedUnits(units[unit], an gle);
173 result = a.valueAsString;
174 }
175 catch(e) {
176 }
177
178 // unknown unit
179 if (units[unit] > highestExposedUnit || units[ot herunit] > highestExposedUnit)
180 assert_equals(result, "");
181 else
182 assert_equals(result, ref.valueAsString) ;
183 }, "newValueSpecifiedUnits(" + units[unit] + ", " + angl e + ")" );
184 };
185 }
186 });
187
188 </script>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/svg/css/svg-angle-turn.svg » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698