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

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: compilefix :P 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') | Source/core/svg/SVGAngle.cpp » ('J')
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 unitconstants = {
24 "UNKNOWN" : 0,
25 "UNSPECIFIED": 1,
26 "DEG": 2,
27 "RAD": 3,
28 "GRAD": 4,
29 "TURN": 5
30 };
31
32 function convertTo(value, unit, outunit) {
33 switch(unit) {
34 case "":
35 case "deg":
36 switch(outunit) {
37 case "":
38 case "deg":
39 return value;
40 case "rad":
41 return value*(Math.PI/180);
42 case "grad":
43 return value*(400/360);
44 case "turn":
45 return value/360;
46 }
47 case "rad":
48 switch(outunit) {
49 case "":
50 case "deg":
51 return value * 180 / Math.PI;
52 case "rad":
53 return value;
54 case "grad":
55 return value * 180 / Math.PI * 400 / 360 ;
56 case "turn":
57 return value / (2 * Math.PI);
58 }
59 case "grad":
60 switch(outunit) {
61 case "":
62 case "deg":
63 return value * 360 / 400;
64 case "rad":
65 return value * Math.PI * 2 / 400;
66 case "grad":
67 return value;
68 case "turn":
69 return value / 400;
70 }
71 case "turn":
72 switch(outunit) {
73 case "":
74 case "deg":
75 return value * 360;
76 case "rad":
77 return value * Math.PI * 2;
78 case "grad":
79 return value * 400;
80 case "turn":
81 return value;
82 }
83 }
84 }
85
86 function createAngle(valuestr) {
87 var angle = svg.createSVGAngle();
88 try {
89 angle.valueAsString = valuestr;
90 }
91 catch(e) {
92 throw e;
fs 2014/06/03 15:52:48 Nit: Looks having no try-catch block would give th
93 }
94 return angle;
95 }
96
97 for(var unit in units) {
98 test(function() {
99 var result = undefined;
100 try {
101 var a = createAngle(47 + unit);
102 result = a.unitType;
103 }
104 catch(e) {}
fs 2014/06/03 15:52:48 Nit: AFAIK, the harness will catch exceptions (and
Erik Dahlström (inactive) 2014/06/04 09:28:21 Yes, the output from failures looked (much) cleane
fs 2014/06/04 11:21:14 Yepp, I can see that. Ok.
105 assert_equals(result, units[unit]);
106 }, "SVGAngle(47" + unit + ").unitType");
107 }
108
109 for(var constant in unitconstants) {
110 var str = "SVG_ANGLETYPE_" + constant;
111 test(function() {
112 assert_exists(SVGAngle, str, "");
113 }, "SVGAngle." + str);
114 }
115
116 angles.forEach(function(angle) {
117 for(var unit in units) {
118 var anglestr = angle + unit;
119 var ref;
120 try {
121 ref = createAngle(anglestr);
122 }
123 catch(e) {
124 continue;
125 }
126
127 test(function() {
128 assert_approx_equals(angle, ref.valueInSpecifiedUnits, E PSILON);
129 }, "SVGAngle(" + anglestr + ").valueInSpecifiedUnits");
130
131 try {
132 marker.setAttribute("orient", anglestr);
133
134 test(function() {
135 assert_equals(marker.orientAngle.baseVal.valueAs String, anglestr);
136 }, "orient=\"" + anglestr + "\".valueAsString");
137
138 test(function() {
139 assert_approx_equals(marker.orientAngle.baseVal. value, convertTo(angle, unit, "deg"), EPSILON);
140 }, "orient=\"" + anglestr + "\".value");
141 }
142 finally {
143 marker.removeAttribute("orient");
144 }
145
146 for (var otherunit in units) {
147 test(function() {
148 var a = createAngle(anglestr);
149 try {
150 a.convertToSpecifiedUnits(units[otheruni t]);
151 }
152 catch(e) {}
153 assert_approx_equals(a.valueInSpecifiedUnits, co nvertTo(angle, unit, otherunit), EPSILON);
154 }, "SVGAngle(" + anglestr + ").convertToSpecifiedUnits(" + units[otherunit] + " /*" + (otherunit ? otherunit : "unspecified") + "*/)");
155
156 test(function() {
157 var result = "";
158 try {
159 var a = createAngle(47 + otherunit);
160 a.newValueSpecifiedUnits(units[unit], an gle);
161 result = a.valueAsString;
162 }
163 catch(e) {
164 }
165 assert_equals(result, ref.valueAsString);
166 }, "newValueSpecifiedUnits(" + units[unit] + ", " + angl e + ")" );
167 };
168 }
169 });
170 </script>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/svg/css/svg-angle-turn.svg » ('j') | Source/core/svg/SVGAngle.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698