|
1 <html xmlns="http://www.w3.org/1999/xhtml"> |
|
2 <head> |
|
3 <title>Test for SMIL timing with zero-duration intervals</title> |
|
4 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
5 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
6 </head> |
|
7 <body> |
|
8 <p id="display"></p> |
|
9 <div id="content" style="display: none"> |
|
10 <svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px" |
|
11 onload="this.pauseAnimations()"> |
|
12 <circle cx="-100" cy="20" r="15" fill="blue" id="circle"/> |
|
13 </svg> |
|
14 </div> |
|
15 <pre id="test"> |
|
16 <script class="testbody" type="text/javascript"> |
|
17 <![CDATA[ |
|
18 /** Test for SMIL timing with zero-duration intervals **/ |
|
19 |
|
20 /* Global Variables */ |
|
21 const svgns="http://www.w3.org/2000/svg"; |
|
22 var svg = document.getElementById("svg"); |
|
23 var circle = document.getElementById('circle'); |
|
24 |
|
25 SimpleTest.waitForExplicitFinish(); |
|
26 |
|
27 function createAnim() { |
|
28 var anim = document.createElementNS(svgns,'animate'); |
|
29 anim.setAttribute('attributeName','cx'); |
|
30 anim.setAttribute('from','0'); |
|
31 anim.setAttribute('to','100'); |
|
32 anim.setAttribute('dur','10s'); |
|
33 anim.setAttribute('begin','indefinite'); |
|
34 return circle.appendChild(anim); |
|
35 } |
|
36 |
|
37 function removeAnim(anim) { |
|
38 anim.parentNode.removeChild(anim); |
|
39 } |
|
40 |
|
41 function main() { |
|
42 ok(svg.animationsPaused(), "should be paused by <svg> load handler"); |
|
43 is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler"); |
|
44 |
|
45 var tests = |
|
46 [ testZeroDurationIntervalsA, |
|
47 testZeroDurationIntervalsB, |
|
48 testZeroDurationIntervalsC, |
|
49 testZeroDurationIntervalsD, |
|
50 testZeroDurationIntervalsE, |
|
51 testZeroDurationIntervalsF, |
|
52 testZeroDurationIntervalsG, |
|
53 testZeroDurationIntervalsH, |
|
54 testZeroDurationIntervalsI, |
|
55 testZeroDurationIntervalsJ, |
|
56 testZeroDurationIntervalsK, |
|
57 testZeroDurationIntervalsL, |
|
58 testZeroDurationIntervalsM, |
|
59 testZeroDurationIntervalsN, |
|
60 testZeroDurationIntervalsO |
|
61 ]; |
|
62 for (var i = 0; i < tests.length; i++) { |
|
63 var anim = createAnim(); |
|
64 svg.setCurrentTime(0); |
|
65 tests[i](anim); |
|
66 removeAnim(anim); |
|
67 } |
|
68 SimpleTest.finish(); |
|
69 } |
|
70 |
|
71 function checkSample(time, expectedValue) { |
|
72 svg.setCurrentTime(time); |
|
73 is(circle.cx.animVal.value, expectedValue); |
|
74 } |
|
75 |
|
76 function testZeroDurationIntervalsA(anim) { |
|
77 // The zero-duration interval should play, followed by a second interval |
|
78 // starting at the same point. There is no end for the interval |
|
79 // at 4s so it should not play. |
|
80 anim.setAttribute('begin', '1s ;4s'); |
|
81 anim.setAttribute('end', '1s; 2s'); |
|
82 anim.setAttribute('dur', '2s '); |
|
83 anim.setAttribute('fill', 'freeze'); |
|
84 checkSample(0,-100); |
|
85 checkSample(1,0); |
|
86 checkSample(1.1,5); |
|
87 checkSample(2,50); |
|
88 checkSample(3,50); |
|
89 checkSample(4,50); |
|
90 checkSample(5,50); |
|
91 checkSample(6,50); |
|
92 } |
|
93 |
|
94 function testZeroDurationIntervalsB(anim) { |
|
95 // This interval should however actually restart as there is a valid end-point |
|
96 anim.setAttribute('begin', '1s ;4s'); |
|
97 anim.setAttribute('end', '1.1s; indefinite'); |
|
98 anim.setAttribute('dur', '2s '); |
|
99 anim.setAttribute('fill', 'freeze'); |
|
100 checkSample(0,-100); |
|
101 checkSample(1,0); |
|
102 checkSample(1.1,5); |
|
103 checkSample(2,5); |
|
104 checkSample(4,0); |
|
105 checkSample(5,50); |
|
106 } |
|
107 |
|
108 function testZeroDurationIntervalsC(anim) { |
|
109 // -0.5s has already been used as the endpoint of one interval so don't use it |
|
110 // a second time |
|
111 anim.setAttribute('begin', '-2s; -0.5s'); |
|
112 anim.setAttribute('end', '-0.5s; 1s'); |
|
113 anim.setAttribute('dur', '2s'); |
|
114 anim.setAttribute('fill', 'freeze'); |
|
115 checkSample(0,25); |
|
116 checkSample(1.5,75); |
|
117 } |
|
118 |
|
119 function testZeroDurationIntervalsD(anim) { |
|
120 // Two end points that could make a zero-length interval |
|
121 anim.setAttribute('begin', '-2s; -0.5s'); |
|
122 anim.setAttribute('end', '-0.5s; -0.5s; 1s'); |
|
123 anim.setAttribute('dur', '2s'); |
|
124 anim.setAttribute('fill', 'freeze'); |
|
125 checkSample(0,25); |
|
126 checkSample(1.5,75); |
|
127 } |
|
128 |
|
129 function testZeroDurationIntervalsE(anim) { |
|
130 // Should give us 1s-1s, 1s-5s |
|
131 anim.setAttribute('begin', '1s'); |
|
132 anim.setAttribute('end', '1s; 5s'); |
|
133 anim.setAttribute('fill', 'freeze'); |
|
134 is(anim.getStartTime(),1); |
|
135 checkSample(0,-100); |
|
136 checkSample(1,0); |
|
137 checkSample(6,40); |
|
138 } |
|
139 |
|
140 function testZeroDurationIntervalsF(anim) { |
|
141 // Should give us 1s-1s |
|
142 anim.setAttribute('begin', '1s'); |
|
143 anim.setAttribute('end', '1s'); |
|
144 anim.setAttribute('fill', 'freeze'); |
|
145 is(anim.getStartTime(),1); |
|
146 checkSample(0,-100); |
|
147 checkSample(1,0); |
|
148 checkSample(2,0); |
|
149 try { |
|
150 anim.getStartTime(); |
|
151 ok(false, "Failed to throw exception when there's no current interval."); |
|
152 } catch (e) { } |
|
153 } |
|
154 |
|
155 function testZeroDurationIntervalsG(anim) { |
|
156 // Test a non-zero interval after a zero interval |
|
157 // Should give us 1-2s, 3-3s, 3-4s |
|
158 anim.setAttribute('begin', '1s; 3s'); |
|
159 anim.setAttribute('end', '3s; 5s'); |
|
160 anim.setAttribute('dur', '1s'); |
|
161 anim.setAttribute('fill', 'freeze'); |
|
162 checkSample(0,-100); |
|
163 checkSample(1,0); |
|
164 checkSample(2,100); |
|
165 checkSample(3,0); |
|
166 checkSample(5,100); |
|
167 } |
|
168 |
|
169 function testZeroDurationIntervalsH(anim) { |
|
170 // Test multiple non-adjacent zero-intervals |
|
171 // Should give us 1-1s, 1-2s, 3-3s, 3-4s |
|
172 anim.setAttribute('begin', '1s; 3s'); |
|
173 anim.setAttribute('end', '1s; 3s; 5s'); |
|
174 anim.setAttribute('dur', '1s'); |
|
175 anim.setAttribute('fill', 'freeze'); |
|
176 checkSample(0,-100); |
|
177 checkSample(1,0); |
|
178 checkSample(2,100); |
|
179 checkSample(3,0); |
|
180 checkSample(5,100); |
|
181 } |
|
182 |
|
183 function testZeroDurationIntervalsI(anim) { |
|
184 // Test skipping values that are the same |
|
185 // Should give us 1-1s, 1-2s |
|
186 anim.setAttribute('begin', '1s; 1s'); |
|
187 anim.setAttribute('end', '1s; 1s; 2s'); |
|
188 anim.setAttribute('fill', 'freeze'); |
|
189 is(anim.getStartTime(),1); |
|
190 checkSample(0,-100); |
|
191 checkSample(1,0); |
|
192 checkSample(2,10); |
|
193 checkSample(3,10); |
|
194 } |
|
195 |
|
196 function testZeroDurationIntervalsJ(anim) { |
|
197 // Should give us 0-0.5s, 1-1s, 1-3s |
|
198 anim.setAttribute('begin', '0s; 1s; 1s'); |
|
199 anim.setAttribute('end', '1s; 3s'); |
|
200 anim.setAttribute('dur', '0.5s'); |
|
201 anim.setAttribute('fill', 'freeze'); |
|
202 is(anim.getStartTime(),0); |
|
203 checkSample(0,0); |
|
204 checkSample(0.6,100); |
|
205 checkSample(1,0); |
|
206 checkSample(2,100); |
|
207 } |
|
208 |
|
209 function testZeroDurationIntervalsK(anim) { |
|
210 // Should give us -0.5-1s |
|
211 anim.setAttribute('begin', '-0.5s'); |
|
212 anim.setAttribute('end', '-0.5s; 1s'); |
|
213 anim.setAttribute('fill', 'freeze'); |
|
214 is(anim.getStartTime(),-0.5); |
|
215 checkSample(0,5); |
|
216 checkSample(1,15); |
|
217 checkSample(2,15); |
|
218 } |
|
219 |
|
220 function testZeroDurationIntervalsL(anim) { |
|
221 // Test that multiple end values are ignored |
|
222 // Should give us 1-1s, 1-3s |
|
223 anim.setAttribute('begin', '1s'); |
|
224 anim.setAttribute('end', '1s; 1s; 1s; 3s'); |
|
225 anim.setAttribute('fill', 'freeze'); |
|
226 is(anim.getStartTime(),1); |
|
227 checkSample(0,-100); |
|
228 checkSample(1,0); |
|
229 checkSample(2,10); |
|
230 checkSample(4,20); |
|
231 } |
|
232 |
|
233 function testZeroDurationIntervalsM(anim) { |
|
234 // Test 0-duration interval at start |
|
235 anim.setAttribute('begin', '0s'); |
|
236 anim.setAttribute('end', '0s'); |
|
237 anim.setAttribute('fill', 'freeze'); |
|
238 try { |
|
239 anim.getStartTime(); |
|
240 ok(false, "Failed to throw exception when there's no current interval."); |
|
241 } catch (e) { } |
|
242 checkSample(0,0); |
|
243 checkSample(1,0); |
|
244 } |
|
245 |
|
246 function testZeroDurationIntervalsN(anim) { |
|
247 // Test 0-active-duration interval at start (different code path to above) |
|
248 anim.setAttribute('begin', '0s'); |
|
249 anim.setAttribute('repeatDur', '0s'); |
|
250 anim.setAttribute('fill', 'freeze'); |
|
251 try { |
|
252 anim.getStartTime(); |
|
253 ok(false, "Failed to throw exception when there's no current interval."); |
|
254 } catch (e) { } |
|
255 checkSample(0,0); |
|
256 checkSample(1,0); |
|
257 } |
|
258 |
|
259 function testZeroDurationIntervalsO(anim) { |
|
260 // Make a zero-duration interval by constraining the active duration |
|
261 // We should not loop infinitely but should look for the next begin time after |
|
262 // that (in this case that is 2s, which would otherwise have been skipped |
|
263 // because restart=whenNotActive) |
|
264 // Should give us 1-1s, 2-2s |
|
265 anim.setAttribute('begin', '1s; 2s'); |
|
266 anim.setAttribute('repeatDur', '0s'); |
|
267 anim.setAttribute('restart', 'whenNotActive'); |
|
268 anim.setAttribute('fill', 'freeze'); |
|
269 is(anim.getStartTime(),1); |
|
270 checkSample(0,-100); |
|
271 checkSample(1,0); |
|
272 checkSample(1.5,0); |
|
273 checkSample(3,0); |
|
274 try { |
|
275 anim.getStartTime(); |
|
276 ok(false, "Failed to throw exception when there's no current interval."); |
|
277 } catch (e) { } |
|
278 } |
|
279 |
|
280 window.addEventListener("load", main, false); |
|
281 ]]> |
|
282 </script> |
|
283 </pre> |
|
284 </body> |
|
285 </html> |