OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> |
| 3 <title>AnimationNode before() method tests</title> |
| 4 <meta name="assert" content="Inserts nodes before this animation node."> |
| 5 <link rel="help" href="http://w3c.github.io/web-animations/#dom-animationnode-be
fore"> |
| 6 <link rel="help" href="http://w3c.github.io/web-animations/#insert-children"> |
| 7 <link rel="help" href="http://w3c.github.io/web-animations/#remove-an-animation-
node"> |
| 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 // Test 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.before(null); |
| 22 } catch(e) { |
| 23 assert_unreached(type(node) + '.before(null) throws unexpected excep
tion: ' + e); |
| 24 } |
| 25 }); |
| 26 }, 'AnimationNode.before() does nothing if the node has no parent animation grou
p. ' + |
| 27 'HierarchyRequestError is not thrown in call node.before(null)'); |
| 28 |
| 29 test(function() { |
| 30 var nodes = [newAnimation(createDiv(this)), new AnimationGroup([]), new Anim
ationSequence([])]; |
| 31 nodes.forEach(function(node) { |
| 32 try { |
| 33 node.before(node); |
| 34 } catch(e) { |
| 35 assert_unreached(type(node) + '.before() throws unexpected exception
: ' + e); |
| 36 } |
| 37 }); |
| 38 }, 'AnimationNode.before() does nothing if the node has no parent animation grou
p. ' + |
| 39 'No HierarchyRequestError is thrown if the node is inserted before itself'); |
| 40 |
| 41 test(function() { |
| 42 var nodes = [newAnimation(createDiv(this)), new AnimationGroup([]), new Anim
ationSequence([])]; |
| 43 var node2 = newAnimation(createDiv(this)); |
| 44 nodes.forEach(function(node1) { |
| 45 node1.before(node2); |
| 46 |
| 47 assert_equals(node1.nextSibling, null, type(node1) + '.before() should d
o nothing ' + |
| 48 'if the node has no parent animation group'); |
| 49 assert_equals(node2.previousSibling, null, type(node1) + '.before() shou
ld do nothing ' + |
| 50 'if the node has no parent animation group'); |
| 51 }); |
| 52 }, 'AnimationNode.before() does nothing if there is no parent animation group'); |
| 53 |
| 54 // Test step 2. If any of the animation nodes in nodes is an inclusive ancestor
of this animation node throw a HierarchyRequestError exception and terminate the
se steps. |
| 55 test(function() { |
| 56 var test = this; |
| 57 var parents = [AnimationGroup, AnimationSequence]; |
| 58 parents.forEach(function(parentCtor) { |
| 59 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; |
| 60 nodes.forEach(function(node) { |
| 61 var parent = new parentCtor([node]); |
| 62 |
| 63 assert_throws('HierarchyRequestError', function() { |
| 64 node.before(node); |
| 65 }, type(node) + '.before() should throw HierarchyRequestError ' + |
| 66 'if inserting node before itself'); |
| 67 assert_equals(node.parent, parent, type(node) + '.before() should no
t change ' + |
| 68 'parent attribute before throwing HierarchyRequestError'); |
| 69 assert_array_equals(parent.children, [node], type(node) + '.before()
' + |
| 70 'should not change parent children before throwing HierarchyRequ
estError'); |
| 71 |
| 72 }); |
| 73 }); |
| 74 }, 'HierarchyRequestError is thrown if node is inserted before 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.before(parent); |
| 86 }, type(node) + '.before() should throw HierarchyRequestError ' + |
| 87 'if inserting node\'s parent'); |
| 88 assert_equals(node.parent, parent, type(node) + '.before() should no
t change ' + |
| 89 'parent attribute before throwing HierarchyRequestError'); |
| 90 assert_array_equals(parent.children, [node], type(node) + '.before()
' + |
| 91 'should not change parent children before throwing HierarchyRequ
estError'); |
| 92 }); |
| 93 }); |
| 94 }, 'HierarchyRequestError is thrown if direct parent is inserted before the node
'); |
| 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.before(parent4); |
| 109 }, type(node) + '.before() should throw HierarchyRequestError ' + |
| 110 'if inserting node\'s ancestor'); |
| 111 assert_equals(node.parent, parent1, type(node) + '.before() should n
ot change ' + |
| 112 'parent attribute before throwing HierarchyRequestError'); |
| 113 assert_array_equals(parent1.children, [node], type(node) + '.before(
) ' + |
| 114 'should not change parent children before throwing HierarchyRequ
estError'); |
| 115 assert_equals(parent3.parent, parent4, type(node) + '.before() shoul
d not change ' + |
| 116 'parent attribute of inserted node before throwing HierarchyRequ
estError'); |
| 117 assert_array_equals(parent4.children, [parent3], type(node) + '.befo
re() ' + |
| 118 'should not change inserted node parent children before throwing
HierarchyRequestError'); |
| 119 }); |
| 120 }); |
| 121 }, 'HierarchyRequestError is thrown if an inclusive ancestor is inserted before
the node'); |
| 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 node2 = newAnimation(createDiv(test)); |
| 130 var node3 = newAnimation(createDiv(test)); |
| 131 var parent1 = new parentCtor([node1, node2]); |
| 132 var parent2 = new parentCtor([parent1]); |
| 133 var parent3 = new parentCtor([parent2]); |
| 134 var parent4 = new parentCtor([parent3]); |
| 135 var parent5 = new ParentCtor([node3]); |
| 136 |
| 137 assert_throws('HierarchyRequestError', function() { |
| 138 node1.before(node3, parent3); |
| 139 }, type(node1) + '.before() should throw HierarchyRequestError ' + |
| 140 'if inserting node\'s parent'); |
| 141 assert_equals(node1.parent, parent1, type(node1) + '.before() should
not change ' + |
| 142 'parent attribute before throwing HierarchyRequestError'); |
| 143 assert_array_equals(parent1.children, [node1, node2], type(node1) +
'.before() ' + |
| 144 'should not change parent children before throwing HierarchyRequ
estError'); |
| 145 assert_equals(parent3.parent, parent4, type(node1) + '.before() shou
ld not change ' + |
| 146 'parent attribute of inserted node before throwing HierarchyRequ
estError'); |
| 147 assert_array_equals(parent4.children, [parent3], type(node1) + '.bef
ore() ' + |
| 148 'should not change inserted node parent children before throwing
HierarchyRequestError'); |
| 149 assert_equals(node3.parent, parent5, type(node1) + '.before() should
not change ' + |
| 150 'parent attribute of inserted node before throwing HierarchyRequ
estError'); |
| 151 assert_array_equals(parent5.children, [node3], type(node1) + '.befor
e() ' + |
| 152 'should not change inserted node parent children before throwing
HierarchyRequestError'); |
| 153 }); |
| 154 }); |
| 155 }, 'HierarchyRequestError is thrown if an inclusive ancestor is inserted before
the node. ' + |
| 156 'Test several arguments in before() call'); |
| 157 |
| 158 // Test step 3. Insert nodes before this animation node. |
| 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(node1) { |
| 165 var node2 = newAnimation(createDiv(test)); |
| 166 var parent = new parentCtor([node1]); |
| 167 |
| 168 node1.before(node2); |
| 169 |
| 170 assert_equals(node1.previousSibling, node2, type(node1) + '.before()
should insert ' + |
| 171 'nodes before this node'); |
| 172 assert_equals(node2.parent, parent, 'Node should be inserted into th
e tree'); |
| 173 assert_equals(node2.nextSibling, node1, 'Node should be inserted int
o the tree ' + |
| 174 'before this node'); |
| 175 assert_equals(parent.children, [node2, node1], parentCtor.name + |
| 176 '.children should be updated'); |
| 177 }); |
| 178 }); |
| 179 }, 'AnimationNode.before() inserts nodes before this node'); |
| 180 |
| 181 test(function() { |
| 182 var test = this; |
| 183 var parents = [AnimationGroup, AnimationSequence]; |
| 184 parents.forEach(function(parentCtor) { |
| 185 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; |
| 186 nodes.forEach(function(node1) { |
| 187 var node2 = newAnimation(createDiv(test)); |
| 188 var parent = new parentCtor([node1, node2]); |
| 189 |
| 190 node1.before(node2); |
| 191 |
| 192 assert_equals(node2.previousSibling, null, type(node1) + '.before()
should insert ' + |
| 193 'nodes before this node'); |
| 194 assert_equals(node2.nextSibling, node1, 'Node should be inserted int
o the tree ' + |
| 195 'before this node'); |
| 196 assert_equals(node1.previousSibling, node2, type(node1) + '.before()
should insert ' + |
| 197 'nodes before this node'); |
| 198 assert_equals(node1.nextSibling, null, 'Node should be inserted into
the tree ' + |
| 199 'before this node'); |
| 200 assert_equals(parent.children, [node2, node1], parentCtor.name + |
| 201 '.children should be updated'); |
| 202 }); |
| 203 }); |
| 204 }, 'AnimationNode.before() inserts nodes before this node. Inserted node is on t
he same ' + |
| 205 'level in the tree'); |
| 206 |
| 207 test(function() { |
| 208 var test = this; |
| 209 var parents = [AnimationGroup, AnimationSequence]; |
| 210 parents.forEach(function(parentCtor) { |
| 211 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; |
| 212 nodes.forEach(function(node2) { |
| 213 var node1 = newAnimation(createDiv(test)); |
| 214 var parent = new parentCtor([node1, node2]); |
| 215 |
| 216 node2.before(node1); |
| 217 |
| 218 assert_equals(node1.nextSibling, node2, type(node2) + '.before() sho
uld insert ' + |
| 219 'nodes before this node'); |
| 220 assert_equals(node2.previousSibling, node1, 'Node should be inserted
into the tree ' + |
| 221 'before this node'); |
| 222 assert_equals(parent.children, [node1, node2], parentCtor.name + |
| 223 '.children should not be changed'); |
| 224 }); |
| 225 }); |
| 226 }, 'Test AnimationNode.before() inserts node before this node even if inserted '
+ |
| 227 'node is already before this one'); |
| 228 |
| 229 test(function() { |
| 230 var test = this; |
| 231 var parents = [AnimationGroup, AnimationSequence]; |
| 232 parents.forEach(function(parentCtor) { |
| 233 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; |
| 234 nodes.forEach(function(node4) { |
| 235 var node1 = newAnimation(createDiv(test)); |
| 236 var node2 = newAnimation(createDiv(test)); |
| 237 var node3 = newAnimation(createDiv(test)); |
| 238 var parent1 = new parentCtor([node1, node2]); |
| 239 var parent2 = new parentCtor([node3, parent1, node4]); |
| 240 |
| 241 node4.before(node1); |
| 242 |
| 243 assert_equals(node1.nextSibling, parent1, type(node4) + '.before() s
hould insert ' + |
| 244 'nodes before this node'); |
| 245 assert_equals(node1.parent, parent2, 'Parent group of the inserted n
ode should be changed'); |
| 246 assert_equals(node1.previousSibling, parent1, 'Node should be insert
ed into the tree ' + |
| 247 'before this node'); |
| 248 |
| 249 assert_equals(parent1.nextSibling, node1, type(node4) + '.before() s
hould insert ' + |
| 250 'nodes before this node'); |
| 251 assert_equals(node4.previousSibling, node1, type(node4) + '.before()
should insert ' + |
| 252 'nodes before this node'); |
| 253 |
| 254 assert_equals(node2.previousSibling, null, 'Inserted node should be
removed from its ' + |
| 255 'previous position in the tree'); |
| 256 assert_array_equals(parent1.children, [node2], 'Inserted node should
be removed from its ' + |
| 257 'previous position in the tree'); |
| 258 assert_array_equals(parent2.children, [node3, parent1, node1, node4]
, parentCtor.name + |
| 259 '.children should be updated'); |
| 260 }); |
| 261 }); |
| 262 }, 'Test AnimationNode.before() inserts node before this node. The previous posi
tion ' + |
| 263 'of the inserted node is deeper in the tree than current node'); |
| 264 |
| 265 test(function() { |
| 266 var test = this; |
| 267 var parents = [AnimationGroup, AnimationSequence]; |
| 268 parents.forEach(function(parentCtor) { |
| 269 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; |
| 270 nodes.forEach(function(node2) { |
| 271 var node1 = newAnimation(createDiv(test)); |
| 272 var node3 = newAnimation(createDiv(test)); |
| 273 var node4 = newAnimation(createDiv(test)); |
| 274 var parent1 = new parentCtor([node1, node2]); |
| 275 var parent2 = new parentCtor([node3, parent1, node4]); |
| 276 |
| 277 node2.before(node4); |
| 278 |
| 279 assert_equals(node4.nextSibling, node2, type(node2) + '.before() sho
uld insert ' + |
| 280 'nodes before this node'); |
| 281 assert_equals(node4.parent, parent1, 'Parent group of the inserted n
ode should be changed'); |
| 282 assert_equals(node4.previousSibling, node1, type(node2) + '.before()
should insert ' + |
| 283 'nodes before this node'); |
| 284 |
| 285 assert_equals(node1.nextSibling, node4, type(node2) + '.before() sho
uld insert ' + |
| 286 'nodes before this node'); |
| 287 assert_equals(node2.previousSibling, node4, 'Node should be inserted
into the tree ' + |
| 288 'before this node'); |
| 289 |
| 290 assert_equals(parent1.nextSibling, null, 'Inserted node should be re
moved from its ' + |
| 291 'previous position in the tree'); |
| 292 assert_array_equals(parent1.children, [node1, node4, node2], parentC
tor.name + |
| 293 '.children should be updated'); |
| 294 assert_array_equals(parent2.children, [node3, parent1], 'Inserted no
de should be ' + |
| 295 'removed from its previous position in the tree'); |
| 296 }); |
| 297 }); |
| 298 }, 'Test AnimationNode.before() inserts node before this node. The previous posi
tion ' + |
| 299 'of the inserted node is shallower in the tree than current node, but not an
cestor'); |
| 300 |
| 301 test(function() { |
| 302 var test = this; |
| 303 var parents = [AnimationGroup, AnimationSequence]; |
| 304 parents.forEach(function(parentCtor) { |
| 305 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; |
| 306 nodes.forEach(function(node2) { |
| 307 var node1 = newAnimation(createDiv(test)); |
| 308 var node3 = newAnimation(createDiv(test)); |
| 309 var node4 = newAnimation(createDiv(test)); |
| 310 var parent = new parentCtor([node1, node2]); |
| 311 |
| 312 node2.before(node3, node4); |
| 313 |
| 314 assert_equals(node1.nextSibling, node3, type(node1) + '.before() sho
uld insert ' + |
| 315 'nodes before this node'); |
| 316 assert_equals(node3.previousSibling, node1, type(node1) + '.before()
should insert ' + |
| 317 'nodes before this node'); |
| 318 assert_equals(node3.nextSibling, node4, type(node1) + '.before() sho
uld insert ' + |
| 319 'nodes before this node'); |
| 320 assert_equals(node3.parent, parent, 'Parent group of the inserted no
de should be changed'); |
| 321 assert_equals(node4.previousSibling, node3, type(node1) + '.before()
should insert ' + |
| 322 'nodes before this node'); |
| 323 assert_equals(node4.nextSibling, node2, type(node1) + '.before() sho
uld insert ' + |
| 324 'nodes before this node'); |
| 325 assert_equals(node4.parent, parent, 'Parent group of the inserted no
de should be changed'); |
| 326 assert_equals(node2.previousSibling, node4, type(node1) + '.before()
should insert ' + |
| 327 'nodes before this node'); |
| 328 assert_array_equals(parent.children, [node1, node3, node4, node2], p
arentCtor.name + |
| 329 '.children should be updated'); |
| 330 }); |
| 331 }); |
| 332 }, 'Test AnimationNode.before() inserts several nodes before this node'); |
| 333 |
| 334 test(function() { |
| 335 var test = this; |
| 336 var parents = [AnimationGroup, AnimationSequence]; |
| 337 parents.forEach(function(parentCtor) { |
| 338 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; |
| 339 nodes.forEach(function(node2) { |
| 340 var node1 = newAnimation(createDiv(test)); |
| 341 var node3 = newAnimation(createDiv(test)); |
| 342 var node4 = newAnimation(createDiv(test)); |
| 343 var parent = new parentCtor([node1, node2]); |
| 344 |
| 345 node2.before(node3, node4, node3, node4); |
| 346 |
| 347 assert_equals(node1.nextSibling, node3, type(node1) + '.before() sho
uld insert ' + |
| 348 'nodes before this node'); |
| 349 assert_equals(node3.previousSibling, node1, type(node1) + '.before()
should insert ' + |
| 350 'nodes before this node'); |
| 351 assert_equals(node3.nextSibling, node4, type(node1) + '.before() sho
uld insert ' + |
| 352 'nodes before this node'); |
| 353 assert_equals(node3.parent, parent, 'Parent group of the inserted no
de should be changed'); |
| 354 assert_equals(node4.previousSibling, node3, type(node1) + '.before()
should insert ' + |
| 355 'nodes before this node'); |
| 356 assert_equals(node4.nextSibling, node2, type(node1) + '.before() sho
uld insert ' + |
| 357 'nodes before this node'); |
| 358 assert_equals(node4.parent, parent, 'Parent group of the inserted no
de should be changed'); |
| 359 assert_equals(node2.previousSibling, node4, type(node1) + '.before()
should insert ' + |
| 360 'nodes before this node'); |
| 361 assert_array_equals(parent.children, [node1, node3, node4, node2], p
arentCtor.name + |
| 362 '.children should be updated'); |
| 363 }); |
| 364 }); |
| 365 }, 'Test AnimationNode.before() inserts several nodes before this node, duplicat
e nodes are ignored'); |
| 366 |
| 367 test(function() { |
| 368 var test = this; |
| 369 var parents = [AnimationGroup, AnimationSequence]; |
| 370 parents.forEach(function(parentCtor) { |
| 371 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; |
| 372 nodes.forEach(function(node2) { |
| 373 var node1 = newAnimation(createDiv(test)); |
| 374 var node3 = newAnimation(createDiv(test)); |
| 375 var node4 = newAnimation(createDiv(test)); |
| 376 var parent = new parentCtor([node1, node2]); |
| 377 |
| 378 node2.before(node3, node4, node3); |
| 379 |
| 380 assert_equals(node1.nextSibling, node4, type(node1) + '.before() sho
uld insert ' + |
| 381 'nodes before this node'); |
| 382 assert_equals(node4.previousSibling, node1, type(node1) + '.before()
should insert ' + |
| 383 'nodes before this node'); |
| 384 assert_equals(node4.nextSibling, node3, type(node1) + '.before() sho
uld insert ' + |
| 385 'nodes before this node'); |
| 386 assert_equals(node4.parent, parent, 'Parent group of the inserted no
de should be changed'); |
| 387 assert_equals(node3.previousSibling, node4, type(node1) + '.before()
should insert ' + |
| 388 'nodes before this node'); |
| 389 assert_equals(node3.nextSibling, node2, type(node1) + '.before() sho
uld insert ' + |
| 390 'nodes before this node'); |
| 391 assert_equals(node3.parent, parent, 'Parent group of the inserted no
de should be changed'); |
| 392 assert_equals(node2.previousSibling, node3, type(node1) + '.before()
should insert ' + |
| 393 'nodes before this node'); |
| 394 assert_array_equals(parent.children, [node1, node4, node3, node2], p
arentCtor.name + |
| 395 '.children should be updated'); |
| 396 }); |
| 397 }); |
| 398 }, 'Test AnimationNode.before() inserts several nodes before this node, check in
sertion order'); |
| 399 |
| 400 test(function() { |
| 401 var test = this; |
| 402 var parents = [AnimationGroup, AnimationSequence]; |
| 403 parents.forEach(function(parentCtor) { |
| 404 var nodes = [newAnimation(createDiv(test)), new AnimationGroup([]), new
AnimationSequence([])]; |
| 405 nodes.forEach(function(node2) { |
| 406 var node1 = newAnimation(createDiv(test)); |
| 407 var parent = new parentCtor([node1]); |
| 408 var player = document.timeline.play(node2); |
| 409 |
| 410 assert_equals(player.source, node2, 'The node should be associated w
ith its player'); |
| 411 node1.before(node2); |
| 412 assert_equals(player.source, null, 'The node should be disassociated
from its player'); |
| 413 }); |
| 414 }); |
| 415 }, 'Test AnimationNode.before() disassociates the inserted node from the player,
' + |
| 416 'if node is directly associated with a player'); |
| 417 </script> |
| 418 </body> |
OLD | NEW |