1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test for SMIL sync behaviour </title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content">
<svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px">
<circle cx="20" cy="20" r="15" fill="blue">
<animate attributeName="cx" attributeType="XML" from="20" to="100"
begin="indefinite" dur="4s" restart="always" id="anim1"/>
</circle>
<circle cx="20" cy="20" r="15" fill="blue">
<animate attributeName="cx" attributeType="XML" from="0" to="50"
begin="0" dur="1s" additive="sum" fill="freeze" id="anim2"/>
</circle>
<circle cx="20" cy="20" r="15" fill="blue">
<animate attributeName="cx" attributeType="XML" from="0" to="50"
begin="0" dur="10s" additive="sum" fill="freeze" id="anim3"/>
</circle>
<circle cx="20" cy="20" r="15" fill="blue">
<animate attributeName="cx" attributeType="XML" from="0" to="50"
begin="0" dur="10s" additive="sum" fill="freeze" id="anim4"/>
</circle>
<circle cx="20" cy="20" r="15" fill="blue">
<animate attributeName="cx" attributeType="XML" from="0" to="50"
begin="0" dur="40s" additive="sum" fill="freeze" id="anim5"/>
</circle>
<circle cx="20" cy="20" r="15" fill="blue">
<animate attributeName="cx" attributeType="XML" from="20" to="100"
begin="100s" dur="4s" restart="always" id="anim6"/>
</circle>
</svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[
/** Test for SMIL sync behavior **/
/* Global Variables */
var svg = document.getElementById("svg");
SimpleTest.waitForExplicitFinish();
function main() {
testBeginAt(document.getElementById("anim1"));
testChangeBaseVal(document.getElementById("anim2"));
testChangeWhilePaused(document.getElementById("anim3"));
testChangeAnimAttribute(document.getElementById("anim4"));
testChangeTimingAttribute(document.getElementById("anim5"));
testSetCurrentTime(document.getElementById("anim6"));
SimpleTest.finish();
}
function testBeginAt(anim) {
// This (hugely important) test checks that a call to beginElement updates to
// the new interval
// Check some pre-conditions
is(anim.getAttribute("restart"), "always");
ok(anim.getSimpleDuration() >= 4);
// First start the animation
svg.setCurrentTime(2);
anim.beginElement();
// Then restart it--twice
svg.setCurrentTime(4);
anim.beginElement();
anim.beginElementAt(-1);
// The first restart should win if the state machine has been successfully
// updated. If we get '3' back instead we haven't updated properly.
is(anim.getStartTime(), 4);
}
function testChangeBaseVal(anim) {
// Check that a change to the base value is updated even after animation is
// frozen
// preconditions -- element should have ended
try {
anim.getStartTime();
ok(false, "Element has not ended yet.");
} catch (e) { }
// check frozen value is applied
var target = anim.targetElement;
is(target.cx.animVal.value, 70);
is(target.cx.baseVal.value, 20);
// change base val and re-check
target.cx.baseVal.value = 30;
is(target.cx.animVal.value, 80);
is(target.cx.baseVal.value, 30);
}
function testChangeWhilePaused(anim) {
// Check that a change to the base value is updated even when the animation is
// paused
svg.pauseAnimations();
svg.setCurrentTime(anim.getSimpleDuration() / 2);
// check paused value is applied
var target = anim.targetElement;
is(target.cx.animVal.value, 45);
is(target.cx.baseVal.value, 20);
// change base val and re-check
target.cx.baseVal.value = 30;
is(target.cx.animVal.value, 55);
is(target.cx.baseVal.value, 30);
}
function testChangeAnimAttribute(anim) {
// Check that a change to an animation attribute causes an update even when
// the animation is frozen and paused
// Make sure animation is paused and frozen
svg.pauseAnimations();
svg.setCurrentTime(anim.getStartTime() + anim.getSimpleDuration() + 1);
// Check frozen value is applied
var target = anim.targetElement;
is(target.cx.animVal.value, 70);
is(target.cx.baseVal.value, 20);
// Make the animation no longer additive
anim.removeAttribute("additive");
is(target.cx.animVal.value, 50);
is(target.cx.baseVal.value, 20);
}
function testChangeTimingAttribute(anim) {
// Check that a change to a timing attribute causes an update even when
// the animation is paused
svg.pauseAnimations();
svg.setCurrentTime(anim.getSimpleDuration() / 2);
// Check part-way value is applied
var target = anim.targetElement;
is(target.cx.animVal.value, 45);
is(target.cx.baseVal.value, 20);
// Make the animation no longer additive
anim.setAttribute("dur", String(anim.getSimpleDuration() / 2) + "s");
is(target.cx.animVal.value, 70);
is(target.cx.baseVal.value, 20);
// Remove fill
anim.removeAttribute("fill");
is(target.cx.animVal.value, 20);
is(target.cx.baseVal.value, 20);
}
function testSetCurrentTime(anim) {
// This test checks that a call to setCurrentTime flushes restarts
//
// Actually, this same scenario arises in test_smilRestart.xhtml but we
// isolate this particular situation here for easier diagnosis if this ever
// fails.
//
// At first we have:
// currentTime begin="100s"
// v v
// Doc time: 0---\/\/\/-------99----------100-------
//
svg.setCurrentTime(99);
is(anim.getStartTime(), 100);
// Then we restart giving us:
//
// beginElement begin="100s"
// v v
// Doc time: 0---\/\/\/-------99----------100-------
//
// So our current interval is
//
// begin="100s"
// v
// +---------------|
// Doc time: 0---\/\/\/-------99-100-101-102-103-----
//
anim.beginElement();
is(anim.getStartTime(), svg.getCurrentTime());
// Then we skip to half-way, i.e.
//
// currentTime
// v
// begin="100s"
// v
// +---------------|
// Doc time: 0---\/\/\/-------99-100-101-102-103-----
//
// At this point we should flush our restarts and early end the first interval
// and start the second interval, giving us
//
// So our timegraph looks like:
//
// currentTime
// v
// +---------------|
// +---|
// Doc time: 0---\/\/\/-------99-100-101-102-103-104-
//
var newTime = anim.getStartTime() + 0.5 * anim.getSimpleDuration();
svg.setCurrentTime(newTime);
// Finally we call beginElement again giving us
//
// currentTime
// v
// +---------------|
// +---|
// +---|
// Doc time: 0---\/\/\/-------99-100-101-102-103-104-105-
//
// If, however, setCurrentTime failed to flush restarts out starting point
// we do come to update the timegraph would be:
//
// beginElementAt
// v
// begin="100s"
// v
// +---------------|
// Doc time: 0---\/\/\/-------99-100-101-102-103-----
//
// And as soon as we encountered the begin="100s" spec we'd do a restart
// according to the SMIL algorithms and a restart involves a reset which
// clears the instance times created by DOM calls and so we'd end up with
// just:
//
// currentTime
// v
// +---------------|
// +---|
// Doc time: 0---\/\/\/-------99-100-101-102-103-104-
//
// Which is probably not what the author intended.
//
anim.beginElement();
is(anim.getStartTime(), svg.getCurrentTime());
}
window.addEventListener("load", main, false);
]]>
</script>
</pre>
</body>
</html>
|