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

Side by Side Diff: third_party/WebKit/LayoutTests/svg/dom/SVGAngle.html

Issue 2741153003: Convert LayoutTests/svg/dom/*.html js-tests.js to testharness.js based tests. (Closed)
Patch Set: Align with review comments Created 3 years, 9 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 | third_party/WebKit/LayoutTests/svg/dom/SVGAngle-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 1 <!DOCTYPE HTML>
2 <html> 2 <title>SVGAngle interface</title>
3 <head> 3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/js-test.js"></script> 4 <script src="../../resources/testharnessreport.js"></script>
5 </head> 5 <script>
6 <body> 6 test(function() {
7 <p id="description"></p> 7 // This test checks the SVGAngle API.
8 <div id="console"></div> 8
9 <script src="script-tests/SVGAngle.js"></script> 9 var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg") ;
10 </body> 10 var angle = svgElement.createSVGAngle();
11 </html> 11
12 // Check initial angle values.
13 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
14 assert_equals(angle.valueAsString, "0");
15 assert_equals(angle.value, 0);
16 assert_equals(angle.valueInSpecifiedUnits, 0);
17
18 // Spec: Raised if unitType is SVG_ANGLETYPE_UNKNOWN or not a valid unit type constant (one of the other SVG_ANGLETYPE_* constants defined on this interface).
19 // Check invalid arguments for 'convertToSpecifiedUnits'.
20 assert_throws("NotSupportedError", function() { angle.convertToSpecifiedUnits( SVGAngle.SVG_ANGLETYPE_UNKNOWN); });
21 assert_throws("NotSupportedError", function() { angle.convertToSpecifiedUnits( -1); });
22 assert_throws("NotSupportedError", function() { angle.convertToSpecifiedUnits( 5); });
23 // 'aString' converts to short 0 (through NaN) according to ECMA-262, ToUint16 .
24 // Therefore this throws NOT_SUPPORTED_ERR.
25 assert_throws("NotSupportedError", function() { angle.convertToSpecifiedUnits( 'aString'); });
26 // Same here, via ToString conversion of object.
27 assert_throws("NotSupportedError", function() { angle.convertToSpecifiedUnits( angle); });
28 // Same here, via ToString conversion of object.
29 assert_throws("NotSupportedError", function() { angle.convertToSpecifiedUnits( svgElement); });
30 assert_throws(new TypeError(), function() { angle.convertToSpecifiedUnits(); } );
31 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
32
33 // Check valid arguments for 'convertToSpecifiedUnits', that should only modif y the 'valueAsString'");
34 angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_RAD);
35 assert_equals(angle.valueAsString, "0rad");
36 assert_equals(angle.value, 0);
37 assert_equals(angle.valueInSpecifiedUnits, 0);
38 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_RAD);
39
40 angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_GRAD);
41 assert_equals(angle.valueAsString, "0grad");
42 assert_equals(angle.value, 0);
43 assert_equals(angle.valueInSpecifiedUnits, 0);
44 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_GRAD);
45
46 angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG);
47 assert_equals(angle.valueAsString, "0deg");
48 assert_equals(angle.value, 0);
49 assert_equals(angle.valueInSpecifiedUnits, 0);
50 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_DEG);
51
52 angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
53 assert_equals(angle.valueAsString, "0");
54 assert_equals(angle.value, 0);
55 assert_equals(angle.valueInSpecifiedUnits, 0);
56 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
57
58 // Spec: Raised if unitType is SVG_ANGLETYPE_UNKNOWN or not a valid unit type constant (one of the other SVG_ANGLETYPE_* constants defined on this interface).
59 // Check invalid arguments for 'newValueSpecifiedUnits'.
60 assert_throws("NotSupportedError", function() { angle.newValueSpecifiedUnits(S VGAngle.SVG_ANGLETYPE_UNKNOWN, 50); });
61 assert_throws("NotSupportedError", function() { angle.newValueSpecifiedUnits(- 1, 50); });
62 assert_throws("NotSupportedError", function() { angle.newValueSpecifiedUnits(5 , 50); });
63 assert_throws(new TypeError(), function() { angle.newValueSpecifiedUnits(SVGAn gle.SVG_ANGLETYPE_DEG); });
64 assert_throws(new TypeError(), function() { angle.newValueSpecifiedUnits(SVGAn gle.SVG_ANGLETYPE_DEG, 'aString'); });
65 assert_equals(angle.value, 0);
66
67 angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, 0);
68 assert_throws(new TypeError(), function() { angle.newValueSpecifiedUnits(SVGAn gle.SVG_ANGLETYPE_DEG, angle); });
69 assert_equals(angle.value, 0);
70 assert_throws(new TypeError(), function() { angle.newValueSpecifiedUnits(SVGAn gle.SVG_ANGLETYPE_DEG, svgElement); });
71 assert_equals(angle.value, 0);
72 assert_throws(new TypeError(), function() { angle.newValueSpecifiedUnits(SVGAn gle.SVG_ANGLETYPE_DEG, NaN); });
73 assert_equals(angle.value, 0);
74 assert_throws(new TypeError(), function() { angle.newValueSpecifiedUnits(SVGAn gle.SVG_ANGLETYPE_DEG, Infinity); });
75 assert_equals(angle.value, 0);
76 assert_throws(new TypeError(), function() { angle.newValueSpecifiedUnits(SVGAn gle.SVG_ANGLETYPE_DEG); });
77
78 // All of the following unitType arguments convert to 0 (SVG_ANGLETYPE_UNKNOWN ).
79 assert_throws("NotSupportedError", function() { angle.newValueSpecifiedUnits(' aString', 4); });
80 assert_throws("NotSupportedError", function() { angle.newValueSpecifiedUnits(a ngle, 4); });
81 assert_throws("NotSupportedError", function() { angle.newValueSpecifiedUnits(s vgElement, 4); });
82 assert_throws(new TypeError(), function() { angle.newValueSpecifiedUnits('aStr ing', 'aString'); });
83 assert_throws(new TypeError(), function() { angle.newValueSpecifiedUnits(angle , angle); });
84 assert_throws(new TypeError(), function() { angle.newValueSpecifiedUnits(svgEl ement, svgElement); });
85 assert_throws(new TypeError(), function() { angle.newValueSpecifiedUnits(); }) ;
86 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_DEG);
87
88 // Check valid arguments for 'newValueSpecifiedUnits', that should only modify the 'valueAsString'.
89 angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_RAD, parseFloat(Math.PI.to Fixed(5)));
90 assert_equals(angle.valueAsString, Math.PI.toFixed(5) + "rad");
91 assert_equals(angle.value.toFixed(1), "180.0");
92 assert_equals(angle.valueInSpecifiedUnits.toFixed(5), Math.PI.toFixed(5));
93 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_RAD);
94
95 angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_GRAD, 400);
96 assert_equals(angle.valueAsString, "400grad");
97 assert_equals(angle.value.toFixed(1), "360.0");
98 assert_equals(angle.valueInSpecifiedUnits, 400);
99 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_GRAD);
100
101 angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, 360);
102 assert_equals(angle.valueAsString, "360deg");
103 assert_equals(angle.value, 360);
104 assert_equals(angle.valueInSpecifiedUnits, 360);
105 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_DEG);
106
107 angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_UNSPECIFIED, 180);
108 assert_equals(angle.valueAsString, "180");
109 assert_equals(angle.value, 180);
110 assert_equals(angle.valueInSpecifiedUnits, 180);
111 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
112
113 // Reset to initial angle state.
114 angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_UNSPECIFIED, 0);
115 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
116
117 // Spec: Raised if the assigned string cannot be parsed as a valid <angle>.
118 // Check setting invalid 'valueAsString' arguments.
119 assert_throws("SyntaxError", function() { angle.valueAsString = '10px'; });
120 assert_equals(angle.valueAsString, "0");
121 assert_equals(angle.value, 0);
122 assert_equals(angle.valueInSpecifiedUnits, 0);
123 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
124
125 assert_throws("SyntaxError", function() { angle.valueAsString = '10x'; });
126 assert_equals(angle.valueAsString, "0");
127 assert_equals(angle.value, 0);
128 assert_equals(angle.valueInSpecifiedUnits, 0);
129 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
130
131 assert_throws("SyntaxError", function() { angle.valueAsString = '5graD'; });
132 assert_equals(angle.valueAsString, "0");
133 assert_equals(angle.value, 0);
134 assert_equals(angle.valueInSpecifiedUnits, 0);
135 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
136
137 assert_throws("SyntaxError", function() { angle.valueAsString = '5Rad'; });
138 assert_equals(angle.valueAsString, "0");
139 assert_equals(angle.value, 0);
140 assert_equals(angle.valueInSpecifiedUnits, 0);
141 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
142
143 assert_throws("SyntaxError", function() { angle.valueAsString = ',5 rad'; });
144 assert_equals(angle.valueAsString, "0");
145 assert_equals(angle.value, 0);
146 assert_equals(angle.valueInSpecifiedUnits, 0);
147 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
148
149 assert_throws("SyntaxError", function() { angle.valueAsString = null; });
150 assert_equals(angle.valueAsString, "0");
151 assert_equals(angle.value, 0);
152 assert_equals(angle.valueInSpecifiedUnits, 0);
153 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
154
155 // Check setting invalid 'valueInSpecifiedUnits' arguments
156 assert_throws(new TypeError(), function() { angle.valueInSpecifiedUnits = 'tes t'; });
157 assert_equals(angle.value, 0);
158 assert_equals(angle.valueInSpecifiedUnits, 0);
159 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
160 angle.valueInSpecifiedUnits = 0;
161 assert_equals(angle.valueInSpecifiedUnits, 0);
162
163 assert_throws(new TypeError(), function() { angle.valueInSpecifiedUnits = angl e; });
164 assert_equals(angle.value, 0);
165 assert_throws(new TypeError(), function() { angle.valueInSpecifiedUnits = NaN; });
166 assert_equals(angle.value, 0);
167 assert_throws(new TypeError(), function() { angle.valueInSpecifiedUnits = Infi nity; });
168 assert_equals(angle.value, 0);
169 assert_equals(angle.valueInSpecifiedUnits, 0);
170 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
171
172 // Check setting invalid 'value' arguments.
173 angle.value = 0;
174 assert_equals(angle.value, 0);
175 assert_throws(new TypeError(), function() { angle.value = 'test'; });
176 assert_equals(angle.value, 0);
177 assert_equals(angle.valueInSpecifiedUnits, 0);
178 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
179
180 angle.value = 0;
181 assert_equals(angle.value, 0);
182 assert_throws(new TypeError(), function() { angle.value = angle; });
183 assert_equals(angle.value, 0);
184 assert_throws(new TypeError(), function() { angle.value = NaN; });
185 assert_equals(angle.value, 0);
186 assert_throws(new TypeError(), function() { angle.value = Infinity; });
187 assert_equals(angle.value, 0);
188 assert_equals(angle.valueInSpecifiedUnits, 0);
189 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
190
191 // Reset to angle in degree units.
192 angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG, 0);
193 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_DEG);
194
195 // Check setting valid 'value' arguments, assure that 'valueInSpecifiedUnits' and 'valueAsString' are synchronized.
196 angle.value = 50;
197 assert_equals(angle.value, 50);
198 assert_equals(angle.valueInSpecifiedUnits, 50);
199 assert_equals(angle.valueAsString, "50deg");
200 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_DEG);
201
202 // Try modifiying the readonly 'unitType', needs to fail.
203 angle.unitType = SVGAngle.SVG_ANGLETYPE_RAD;
204 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_DEG);
205
206 // Check setting valid 'valueInSpecifiedUnits' arguments, assure that 'value' and 'valueAsString' are synchronized.
207 angle.valueInSpecifiedUnits = 100;
208 assert_equals(angle.valueInSpecifiedUnits, 100);
209 assert_equals(angle.value, 100);
210 assert_equals(angle.valueAsString, "100deg");
211 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_DEG);
212
213 // Check setting valid 'valueAsString' arguments, assure that 'value' and 'val ueInSpecifiedUnits' are synchronized.
214 angle.valueAsString = '200grad';
215 assert_equals(angle.valueAsString, "200grad");
216 assert_equals(angle.valueInSpecifiedUnits, 200);
217 assert_equals(angle.value.toFixed(1), "180.0");
218 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_GRAD);
219
220 // Now convert the GRAD value into a RAD value, and assure that all properties have been synchronized.
221 angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_RAD);
222 assert_equals(angle.value.toFixed(1), "180.0");
223 assert_equals(angle.valueInSpecifiedUnits.toFixed(5), Math.PI.toFixed(5));
224 assert_equals(angle.valueAsString, Math.PI.toFixed(5) + "rad");
225 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_RAD);
226
227 // Now try converting the RAD value into an unknown value, that should fail an d throw;
228 assert_throws("NotSupportedError", function() { angle.convertToSpecifiedUnits( SVGAngle.SVG_ANGLETYPE_UNKNOWN); });
229 assert_equals(angle.value.toFixed(1), "180.0");
230 assert_equals(angle.valueInSpecifiedUnits.toFixed(5), Math.PI.toFixed(5));
231 assert_equals(angle.valueAsString, Math.PI.toFixed(5) + "rad");
232 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_RAD);
233
234 // Now convert the RAD value into a DEG value, and assure that all properties have been synchronized.
235 angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG);
236 assert_equals(angle.value.toFixed(1), "180.0");
237 assert_equals(angle.valueInSpecifiedUnits.toFixed(1), "180.0");
238 assert_equals(angle.valueAsString, "180deg");
239 assert_equals(angle.unitType, SVGAngle.SVG_ANGLETYPE_DEG);
240 });
241 </script>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/svg/dom/SVGAngle-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698