OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <meta charset=utf-8> | |
3 <title>AnimationNode replace() method tests</title> | |
4 <meta name="assert" content="Replaces this AnimationNode with the passed in node
s parameter"> | |
5 <link rel="help" href="http://w3c.github.io/web-animations/#dom-animationnode-re
place"> | |
6 <link rel="help" href="http://w3c.github.io/web-animations/#remove-an-animation-
node"> | |
7 <link rel="help" href="http://w3c.github.io/web-animations/#insert-children"> | |
8 <link rel="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru"> | |
9 <link rel="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru"
> | |
10 <script src="../../../../resources/testharness.js"></script> | |
11 <script src="../../../../resources/testharnessreport.js"></script> | |
12 <script src="../testcommon.js"></script> | |
13 <body> | |
14 <div id="log"></div> | |
15 <script> | |
16 // Step 1. If there is no parent animation group, terminate these steps. | |
17 test(function() { | |
18 var nodes = [newAnimation(createDiv(this)), new AnimationGroup([]), new Anim
ationSequence([])]; | |
19 nodes.forEach(function(node) { | |
20 try { | |
21 node.replace(null); | |
22 } catch(e) { | |
23 assert_unreached(type(node) + '.replace(null) throws unexpected exce
ption: ' + e); | |
24 } | |
25 }); | |
26 }, 'AnimationNode.replace(null) does nothing if node has no parent animation gro
up'); | |
27 | |
28 test(function() { | |
29 var nodes = [newAnimation(createDiv(this)), new AnimationGroup([]), new Anim
ationSequence([])]; | |
30 nodes.forEach(function(node) { | |
31 try { | |
32 node.replace(node); | |
33 } catch(e) { | |
34 assert_unreached(type(node) + '.replace(node) throws unexpected exce
ption: ' + e); | |
35 } | |
36 }); | |
37 }, 'AnimationNode.replace() does nothing if node has no parent animation group.
' + | |
38 'HierarchyRequestError is not thrown if the node is replacing itself'); | |
39 | |
40 test(function() { | |
41 var test = this; | |
42 var nodes = [newAnimation(createDiv(this)), new AnimationGroup([]), new Anim
ationSequence([])]; | |
43 nodes.forEach(function(node1) { | |
44 var node2 = newAnimation(createDiv(test)); | |
45 | |
46 try { | |
47 node1.replace(node2); | |
48 } catch(e) { | |
49 assert_unreached(type(node1) + '.replace() throws unexpected excepti
on: ' + e); | |
50 } | |
51 }); | |
52 }, 'AnimationNode.replace() does nothing if node has no parent animation group')
; | |
53 | |
54 // Step 2. If any of the animation nodes in nodes is an inclusive ancestor | |
55 // of the parent animation group throw a HierarchyRequestError exception and ter
minate these steps. | |
56 test(function() { | |
57 var test = this; | |
58 var parents = [AnimationGroup, AnimationSequence]; | |
59 parents.forEach(function(parentCtor) { | |
60 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; | |
61 nodes.forEach(function(node) { | |
62 var parent = new parentCtor([node]); | |
63 | |
64 assert_throws('HierarchyRequestError', function() { | |
65 node.replace(node); | |
66 }, 'HierarchyRequestError should be thrown if ' + type(node) + | |
67 ' replaces itself'); | |
68 assert_equals(node.parent, parent, type(node) + '.replace() should n
ot change ' + | |
69 'parent attribute before throwing HierarchyRequestError'); | |
70 assert_array_equals(parent.children, [node], type(node) + '.replace(
) ' + | |
71 'should not change parent children before throwing HierarchyRequ
estError'); | |
72 }); | |
73 }); | |
74 }, 'HierarchyRequestError is thrown if the node replaces itself'); | |
75 | |
76 test(function() { | |
77 var test = this; | |
78 var parents = [AnimationGroup, AnimationSequence]; | |
79 parents.forEach(function(parentCtor) { | |
80 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; | |
81 nodes.forEach(function(node) { | |
82 var parent = new parentCtor([node]); | |
83 | |
84 assert_throws('HierarchyRequestError', function() { | |
85 node.replace(parent); | |
86 }, 'HierarchyRequestError should be thrown if ' + type(node) + | |
87 ' is replaced by its parent ' + parentCtor.name); | |
88 assert_equals(node.parent, parent, type(node) + '.replace() should n
ot change ' + | |
89 'parent attribute before throwing HierarchyRequestError'); | |
90 assert_array_equals(parent.children, [node], type(node) + '.replace(
) ' + | |
91 'should not change parent children before throwing HierarchyRequ
estError'); | |
92 }); | |
93 }); | |
94 }, 'HierarchyRequestError is thrown if the node is replaced by its parent'); | |
95 | |
96 test(function() { | |
97 var test = this; | |
98 var parents = [AnimationGroup, AnimationSequence]; | |
99 parents.forEach(function(parentCtor) { | |
100 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; | |
101 nodes.forEach(function(node) { | |
102 var parent1 = new parentCtor([node]); | |
103 var parent2 = new parentCtor([parent1]); | |
104 var parent3 = new parentCtor([parent2]); | |
105 var parent4 = new parentCtor([parent3]); | |
106 | |
107 assert_throws('HierarchyRequestError', function() { | |
108 node.replace(parent3); | |
109 }, 'HierarchyRequestError should be thrown if ' + type(node) + | |
110 ' is replaced by its inclusive ancestor' + parentCtor.name); | |
111 assert_equals(node.parent, parent1, type(node) + '.replace() should
not change ' + | |
112 'parent attribute before throwing HierarchyRequestError'); | |
113 assert_array_equals(parent1.children, [node], type(node) + '.replace
() ' + | |
114 'should not change parent children before throwing HierarchyRequ
estError'); | |
115 assert_equals(parent3.parent, parent4, type(node) + '.replace() shou
ld not change ' + | |
116 'parent attribute of replacement node before throwing HierarchyR
equestError'); | |
117 assert_array_equals(parent4.children, [parent3], type(node) + '.repl
ace() ' + | |
118 'should not change replacement node parent children before throw
ing HierarchyRequestError'); | |
119 }); | |
120 }); | |
121 }, 'HierarchyRequestError is thrown if the node is replaced by its inclusive anc
estor'); | |
122 | |
123 test(function() { | |
124 var test = this; | |
125 var parents = [AnimationGroup, AnimationSequence]; | |
126 parents.forEach(function(parentCtor) { | |
127 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; | |
128 nodes.forEach(function(node1) { | |
129 var parent1 = new parentCtor([node1]); | |
130 var parent2 = new parentCtor([parent1]); | |
131 var parent3 = new parentCtor([parent2]); | |
132 var parent4 = new parentCtor([parent3]); | |
133 var node2 = newAnimation(createDiv(test)); | |
134 var parent5 = new parentCtor([node2]); | |
135 | |
136 assert_throws('HierarchyRequestError', function() { | |
137 node1.replace(node2, parent3); | |
138 }, 'HierarchyRequestError should be thrown if ' + type(node1) + | |
139 ' is replaced by its inclusive ancestor' + parentCtor.name); | |
140 assert_equals(node1.parent, parent1, type(node1) + '.replace() shoul
d not change ' + | |
141 'parent attribute before throwing HierarchyRequestError'); | |
142 assert_array_equals(parent1.children, [node1], type(node1) + '.repla
ce() ' + | |
143 'should not change parent children before throwing HierarchyRequ
estError'); | |
144 assert_equals(parent3.parent, parent4, type(node1) + '.replace() sho
uld not change ' + | |
145 'parent attribute of replacement node before throwing HierarchyR
equestError'); | |
146 assert_array_equals(parent4.children, [parent3], type(node1) + '.rep
lace() ' + | |
147 'should not change replacement node parent children before throw
ing HierarchyRequestError'); | |
148 assert_equals(node2.parent, parent5, type(node1) + '.replace() shoul
d not change ' + | |
149 'parent attribute of replacement node before throwing HierarchyR
equestError'); | |
150 assert_array_equals(parent5.children, [node2], type(node1) + '.repla
ce() ' + | |
151 'should not change replacement node parent children before throw
ing HierarchyRequestError'); | |
152 }); | |
153 }); | |
154 }, 'HierarchyRequestError is thrown if node is replaced by its inclusive ancesto
r. ' + | |
155 'Test several arguments in replace() call'); | |
156 | |
157 // Step 3. Let reference child be the next sibling of this animation node not in
nodes. | |
158 // Step 4. Remove this animation node from its parent animation group. | |
159 test(function() { | |
160 var test = this; | |
161 var parents = [AnimationGroup, AnimationSequence]; | |
162 parents.forEach(function(parentCtor) { | |
163 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; | |
164 nodes.forEach(function(node) { | |
165 var parent = new parentCtor([node]); | |
166 | |
167 node.replace(); | |
168 | |
169 assert_array_equals(parent.children, [], type(node) + | |
170 ' node should be removed from parent ' + parentCtor.name); | |
171 assert_equals(node.parent, null, type(node) + | |
172 ' node parent attribute should be updated'); | |
173 }); | |
174 }); | |
175 }, 'AnimationNode.replace() without arguments removes the node from the parent '
+ | |
176 'animation group'); | |
177 | |
178 test(function() { | |
179 var test = this; | |
180 var parents = [AnimationGroup, AnimationSequence]; | |
181 parents.forEach(function(parentCtor) { | |
182 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; | |
183 nodes.forEach(function(node1) { | |
184 var node2 = newAnimation(createDiv(test)); | |
185 var parent = new parentCtor([node1]); | |
186 | |
187 node1.replace(node2); | |
188 | |
189 assert_array_equals(parent.children, [node2], type(node1) + | |
190 ' node should be removed its parent group'); | |
191 assert_equals(node1.parent, null, type(node1) + | |
192 ' node should be removed from its parent group'); | |
193 assert_equals(node1.previousSibling, null, type(node1) + | |
194 ' node previousSibling attribute should be updated'); | |
195 assert_equals(node1.nextSibling, null, type(node1) + | |
196 ' node nextSibling attribute should be updated'); | |
197 }); | |
198 }); | |
199 }, 'AnimationNode.replace() removes the node from its parent animation group'); | |
200 | |
201 test(function() { | |
202 var test = this; | |
203 var parents = [AnimationGroup, AnimationSequence]; | |
204 parents.forEach(function(parentCtor) { | |
205 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; | |
206 nodes.forEach(function(node2) { | |
207 var node1 = newAnimation(createDiv(test)); | |
208 var node3 = newAnimation(createDiv(test)); | |
209 var parent = new parentCtor([node1, node2, node3]); | |
210 | |
211 node2.replace(node3); | |
212 | |
213 assert_array_equals(parent.children, [node1,node3], type(node2) + | |
214 ' node should be removed from parent ' + parentCtor.name); | |
215 assert_equals(node2.parent, null, type(node2) + | |
216 ' node parent attribute should be updated'); | |
217 assert_equals(node2.nextSibling, null, type(node2) + | |
218 ' node nextSibling attribute should be updated'); | |
219 assert_equals(node2.previousSibling, null, type(node2) + | |
220 ' node previousSibling attribute should be updated'); | |
221 assert_equals(node1.nextSibling, node3, | |
222 'Sibling node nextSibling attribute should be updated'); | |
223 assert_equals(node3.previousSibling, node1, | |
224 'Sibling node previousSibling attribute should be updated'); | |
225 }); | |
226 }); | |
227 }, 'AnimationNode.replace(next sibling) removes the node from its parent ' + | |
228 'animation group'); | |
229 | |
230 // Step 5. Insert nodes before reference child. | |
231 test(function() { | |
232 var test = this; | |
233 var parents = [AnimationGroup, AnimationSequence]; | |
234 parents.forEach(function(parentCtor) { | |
235 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; | |
236 nodes.forEach(function(node1) { | |
237 var node2 = newAnimation(createDiv(test)); | |
238 var parent = new parentCtor([node1]); | |
239 | |
240 node1.replace(node2); | |
241 | |
242 assert_array_equals(parent.children, [node2], type(node1) + | |
243 ' node should be replaced'); | |
244 assert_equals(node2.parent, parent, | |
245 'Replacement node should be assigned to a parent group'); | |
246 }); | |
247 }); | |
248 }, 'AnimationNode.replace() replaces node in the parent animation group'); | |
249 | |
250 test(function() { | |
251 var test = this; | |
252 var parents = [AnimationGroup, AnimationSequence]; | |
253 parents.forEach(function(parentCtor) { | |
254 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; | |
255 nodes.forEach(function(node4) { | |
256 var node1 = newAnimation(createDiv(test)); | |
257 var node2 = newAnimation(createDiv(test)); | |
258 var node3 = newAnimation(createDiv(test)); | |
259 var parent1 = new parentCtor([node1, node2]); | |
260 var parent2 = new parentCtor([node3, parent1, node4]); | |
261 | |
262 node4.replace(node1); | |
263 | |
264 assert_array_equals(parent1.children, [node2], | |
265 'Replacement node should be removed from its previous position i
n the tree'); | |
266 assert_array_equals(parent2.children, [node3, parent1, node1], | |
267 'Replacement node should be inserted into the new position'); | |
268 assert_equals(node1.parent, parent2, 'Inserted node parent group sho
uld be assigned'); | |
269 assert_equals(node1.previousSibling, parent1, | |
270 'Inserted node previousSibling attribute should be updated'); | |
271 assert_equals(node1.nextSibling, null, | |
272 'Inserted node nextSibling attribute should be updated'); | |
273 | |
274 assert_equals(node4.parent, null, 'Node should be removed from its p
arent group'); | |
275 assert_equals(node4.previousSibling, null, | |
276 'Replaced node previousSibling attribute should be updated'); | |
277 assert_equals(node4.nextSibling, null, | |
278 'Replaced node nextSibling attribute should be updated'); | |
279 }); | |
280 }); | |
281 }, 'Test AnimationNode.replace() replaces given node. The previous position ' + | |
282 'of the replacement node is deeper in the tree than the current node'); | |
283 | |
284 test(function() { | |
285 var test = this; | |
286 var parents = [AnimationGroup, AnimationSequence]; | |
287 parents.forEach(function(parentCtor) { | |
288 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; | |
289 nodes.forEach(function(node2) { | |
290 var node1 = newAnimation(createDiv(test)); | |
291 var node3 = newAnimation(createDiv(test)); | |
292 var node4 = newAnimation(createDiv(test)); | |
293 var parent1 = new parentCtor([node1, node2]); | |
294 var parent2 = new parentCtor([node3, parent1, node4]); | |
295 | |
296 node2.replace(node4); | |
297 | |
298 assert_array_equals(parent1.children, [node1, node4], | |
299 'Replacement node should be inserted to the new position'); | |
300 assert_array_equals(parent2.children, [node3, parent1], | |
301 'Replacement node should be removed from its previous position i
n the tree'); | |
302 assert_equals(node4.parent, parent1, 'Inserted node parent group sho
uld be changed'); | |
303 assert_equals(node4.previousSibling, node1, | |
304 'Inserted node previousSibling attribute should be updated'); | |
305 assert_equals(node1.nextSibling, node4, | |
306 'Inserted node sibling nextSibling attribute should be updated')
; | |
307 | |
308 assert_equals(node2.parent, null, 'Replaced node parent group should
be changed'); | |
309 assert_equals(node2.previousSibling, null, | |
310 'Replaced node previousSibling attribute should be updated'); | |
311 assert_equals(node2.nextSibling, null, 'Replaced node nextSibling at
tribute ' + | |
312 'should be updated'); | |
313 }); | |
314 }); | |
315 }, 'Test AnimationNode.replace() replaces given node. The previous position ' + | |
316 'of the replacement node is shallower in the tree than current node, but is
not an ancestor'); | |
317 | |
318 test(function() { | |
319 var test = this; | |
320 var parents = [AnimationGroup, AnimationSequence]; | |
321 parents.forEach(function(parentCtor) { | |
322 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; | |
323 nodes.forEach(function(node2) { | |
324 var node1 = newAnimation(createDiv(test)); | |
325 var node3 = newAnimation(createDiv(test)); | |
326 var node4 = newAnimation(createDiv(test)); | |
327 var parent = new parentCtor([node1, node2]); | |
328 | |
329 node2.replace(node3, node4); | |
330 | |
331 assert_array_equals(parent.children, [node1, node3, node4], type(nod
e2) + '.replace() ' + | |
332 'should replace the current node by ones passed in arguments'); | |
333 assert_equals(node1.nextSibling, node3, 'nextSibling attribute shoul
d be updated'); | |
334 assert_equals(node3.previousSibling, node1, 'Inserted node previousS
ibling attribute ' + | |
335 'should be updated'); | |
336 assert_equals(node3.nextSibling, node4, 'Inserted node nextSibling a
ttribute ' + | |
337 'should be updated'); | |
338 assert_equals(node3.parent, parent, 'Parent group of the inserted no
de should be changed'); | |
339 assert_equals(node4.previousSibling, node3, 'Inserted node previousS
ibling attribute ' + | |
340 'should be updated'); | |
341 assert_equals(node4.nextSibling, null, 'Inserted node nextSibling at
tribute ' + | |
342 'should be updated'); | |
343 assert_equals(node4.parent, parent, 'Parent group of the second inse
rted node ' + | |
344 'should be changed'); | |
345 assert_equals(node2.parent, null, 'Replaced node parent group should
be changed'); | |
346 assert_equals(node2.previousSibling, null, | |
347 'Replaced node previousSibling attribute should be updated'); | |
348 assert_equals(node2.nextSibling, null, 'Replaced node nextSibling at
tribute ' + | |
349 'should be updated'); | |
350 }); | |
351 }); | |
352 }, 'Test AnimationNode.replace() replaces given node. Test several arguments'); | |
353 | |
354 test(function() { | |
355 var test = this; | |
356 var parents = [AnimationGroup, AnimationSequence]; | |
357 parents.forEach(function(parentCtor) { | |
358 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; | |
359 nodes.forEach(function(node2) { | |
360 var node1 = newAnimation(createDiv(test)); | |
361 var node3 = newAnimation(createDiv(test)); | |
362 var node4 = newAnimation(createDiv(test)); | |
363 var parent = new parentCtor([node1, node2]); | |
364 | |
365 node2.replace(node3, node4, node3, node4); | |
366 | |
367 assert_array_equals(parent.children, [node1, node3, node4], type(nod
e2) + '.replace() ' + | |
368 'should replace the current node by ones passed in arguments'); | |
369 assert_equals(node1.nextSibling, node3, 'nextSibling attribute shoul
d be updated'); | |
370 assert_equals(node3.previousSibling, node1, 'Inserted node previousS
ibling attribute ' + | |
371 'should be updated'); | |
372 assert_equals(node3.nextSibling, node4, 'Inserted node nextSibling a
ttribute ' + | |
373 'should be updated'); | |
374 assert_equals(node3.parent, parent, 'Parent group of the inserted no
de should be changed'); | |
375 assert_equals(node4.previousSibling, node3, 'Inserted node previousS
ibling attribute ' + | |
376 'should be updated'); | |
377 assert_equals(node4.nextSibling, null, 'Inserted node nextSibling at
tribute ' + | |
378 'should be updated'); | |
379 assert_equals(node4.parent, parent, 'Parent group of the second inse
rted node ' + | |
380 'should be changed'); | |
381 assert_equals(node2.parent, null, 'Replaced node parent group should
be changed'); | |
382 assert_equals(node2.previousSibling, null, | |
383 'Replaced node previousSibling attribute should be updated'); | |
384 assert_equals(node2.nextSibling, null, 'Replaced node nextSibling at
tribute ' + | |
385 'should be updated'); | |
386 }); | |
387 }); | |
388 }, 'Test AnimationNode.replace() replaces given node by several nodes, duplicate
nodes are ignored'); | |
389 | |
390 test(function() { | |
391 var test = this; | |
392 var parents = [AnimationGroup, AnimationSequence]; | |
393 parents.forEach(function(parentCtor) { | |
394 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; | |
395 nodes.forEach(function(node2) { | |
396 var node1 = newAnimation(createDiv(test)); | |
397 var node3 = newAnimation(createDiv(test)); | |
398 var node4 = newAnimation(createDiv(test)); | |
399 var parent = new parentCtor([node1, node2]); | |
400 | |
401 node2.replace(node3, node4, node3); | |
402 | |
403 assert_array_equals(parent.children, [node1, node4, node3], type(nod
e2) + '.replace() ' + | |
404 'should replace the current node by ones passed in arguments'); | |
405 assert_equals(node1.nextSibling, node4, 'nextSibling attribute shoul
d be updated'); | |
406 assert_equals(node4.previousSibling, node1, 'Inserted node previousS
ibling attribute ' + | |
407 'should be updated'); | |
408 assert_equals(node4.nextSibling, node3, 'Inserted node nextSibling a
ttribute ' + | |
409 'should be updated'); | |
410 assert_equals(node4.parent, parent, 'Parent group of the inserted no
de should be changed'); | |
411 assert_equals(node3.previousSibling, node4, 'Inserted node previousS
ibling attribute ' + | |
412 'should be updated'); | |
413 assert_equals(node3.nextSibling, null, 'Inserted node nextSibling at
tribute ' + | |
414 'should be updated'); | |
415 assert_equals(node3.parent, parent, 'Parent group of the second inse
rted node ' + | |
416 'should be changed'); | |
417 assert_equals(node2.parent, null, 'Replaced node parent group should
be changed'); | |
418 assert_equals(node2.previousSibling, null, | |
419 'Replaced node previousSibling attribute should be updated'); | |
420 assert_equals(node2.nextSibling, null, 'Replaced node nextSibling at
tribute ' + | |
421 'should be updated'); | |
422 }); | |
423 }); | |
424 }, 'Test AnimationNode.replace() replaces given node by several nodes, check rep
lacement order'); | |
425 | |
426 test(function() { | |
427 var test = this; | |
428 var parents = [AnimationGroup, AnimationSequence]; | |
429 parents.forEach(function(parentCtor) { | |
430 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; | |
431 nodes.forEach(function(node1) { | |
432 var node2 = newAnimation(createDiv(test)); | |
433 var parent = new parentCtor([node1]); | |
434 var player = document.timeline.play(node2); | |
435 | |
436 assert_equals(player.source, node2, 'The node should be associated w
ith its player'); | |
437 node1.replace(node2); | |
438 assert_equals(player.source, null, 'The node should be disassociated
from its player'); | |
439 }); | |
440 }); | |
441 }, 'Test AnimationNode.replace() disassociates the inserted node from the player
, ' + | |
442 'if node is directly associated with a player'); | |
443 </script> | |
444 </body> | |
OLD | NEW |