OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright 2013 Google Inc. All Rights Reserved. | |
3 | |
4 Licensed under the Apache License, Version 2.0 (the "License"); | |
5 you may not use this file except in compliance with the License. | |
6 You may obtain a copy of the License at | |
7 | |
8 http://www.apache.org/licenses/LICENSE-2.0 | |
9 | |
10 Unless required by applicable law or agreed to in writing, software | |
11 distributed under the License is distributed on an "AS IS" BASIS, | |
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 See the License for the specific language governing permissions and | |
14 limitations under the License. | |
15 --> | |
16 | |
17 <!DOCTYPE html><meta charset="UTF-8"> | |
18 <body></body> | |
19 <script src="../bootstrap.js"></script> | |
20 <script> | |
21 | |
22 var body = document.querySelector('body'); | |
23 var anims = [body, body, body, body, body, body, body, body, body, body].map(fun
ction(element, idx) { | |
24 return new Animation(element, { left: '100px' }, idx); | |
25 }); | |
26 | |
27 function initGroup() { | |
28 return new AnimationGroup(anims.slice(0, 5)); | |
29 } | |
30 | |
31 function toOrdering(list) { | |
32 return [].map.call(list, function(animation) { return animation.timing.duratio
n; }); | |
33 } | |
34 | |
35 function assert_child_order(group, list, message) { | |
36 assert_array_equals(toOrdering(group.children), list, message); | |
37 } | |
38 | |
39 test(function() { | |
40 var group = new AnimationGroup(); | |
41 group.append(anims[5]); | |
42 assert_child_order(group, [5], | |
43 'append on empty group should work'); | |
44 var group = initGroup(); | |
45 group.append(anims[5]); | |
46 assert_child_order(group, [0, 1, 2, 3, 4, 5], | |
47 'append should place element 5 at end of group'); | |
48 group.append(anims[6], anims[7], anims[8]); | |
49 assert_child_order(group, [0, 1, 2, 3, 4, 5, 6, 7, 8], | |
50 'append should place elements 6, 7, and 8 at end of group'); | |
51 }, 'append'); | |
52 | |
53 test(function() { | |
54 var group = new AnimationGroup(); | |
55 group.prepend(anims[5]); | |
56 assert_child_order(group, [5], | |
57 'prepend on empty group should work'); | |
58 var group = initGroup(); | |
59 group.prepend(anims[5]); | |
60 assert_child_order(group, [5, 0, 1, 2, 3, 4], | |
61 'prepend should place element 5 at beginning of group'); | |
62 group.prepend(anims[6], anims[7], anims[8]); | |
63 assert_child_order(group, [6, 7, 8, 5, 0, 1, 2, 3, 4], | |
64 'prepend should place elements 6, 7, and 8 at beginning of group'); | |
65 }, 'prepend'); | |
66 | |
67 test(function() { | |
68 var group = initGroup(); | |
69 assert_equals(group.firstChild, anims[0], | |
70 'first child should be element 0'); | |
71 group.prepend(anims[8]); | |
72 assert_equals(group.firstChild, anims[8], | |
73 'first child after prepend should be prepended element'); | |
74 }, 'firstChild'); | |
75 | |
76 test(function() { | |
77 var group = initGroup(); | |
78 assert_equals(group.lastChild, anims[4], | |
79 'last child should be element 4'); | |
80 group.append(anims[8]); | |
81 assert_equals(group.lastChild, anims[8], | |
82 'last child after append should be appended element'); | |
83 }, 'lastChild'); | |
84 | |
85 test(function() { | |
86 var group = initGroup(); | |
87 group.children[2].before(anims[5]); | |
88 assert_child_order(group, [0, 1, 5, 2, 3, 4], | |
89 'before should place element 5 before element 2'); | |
90 anims[3].before(anims[6], anims[7], anims[8]); | |
91 assert_child_order(group, [0, 1, 5, 2, 6, 7, 8, 3, 4], | |
92 'before should place elements 6, 7, and 8 before element 3'); | |
93 group.firstChild.before(anims[9]); | |
94 assert_child_order(group, [9, 0, 1, 5, 2, 6, 7, 8, 3, 4], | |
95 'before should place element 9 at beginning of list'); | |
96 }, 'before'); | |
97 | |
98 test(function() { | |
99 var group = initGroup(); | |
100 group.children[2].after(anims[5]); | |
101 assert_child_order(group, [0, 1, 2, 5, 3, 4], | |
102 'after should place element 5 after element 2'); | |
103 anims[3].after(anims[6], anims[7], anims[8]); | |
104 assert_child_order(group, [0, 1, 2, 5, 3, 6, 7, 8, 4], | |
105 'after should place elements 6, 7, and 8 after element 3'); | |
106 group.lastChild.after(anims[9]); | |
107 assert_child_order(group, [0, 1, 2, 5, 3, 6, 7, 8, 4, 9], | |
108 'after should place element 9 at end of list'); | |
109 }, 'after'); | |
110 | |
111 test(function() { | |
112 var group = initGroup(); | |
113 group.children[2].replace(anims[5]); | |
114 assert_child_order(group, [0, 1, 5, 3, 4], | |
115 'replace should replace element 2 with element 5'); | |
116 anims[3].replace(anims[6], anims[7], anims[8]); | |
117 assert_child_order(group, [0, 1, 5, 6, 7, 8, 4], | |
118 'replace should replace element 3 with elements 6, 7, and 8'); | |
119 group.firstChild.replace(anims[9]); | |
120 assert_child_order(group, [9, 1, 5, 6, 7, 8, 4], | |
121 'replace should replace element 0 with element 9'); | |
122 group.lastChild.replace(anims[0]); | |
123 assert_child_order(group, [9, 1, 5, 6, 7, 8, 0], | |
124 'replace should replace element 4 with element 0'); | |
125 }, 'replace'); | |
126 | |
127 test(function() { | |
128 var group = initGroup(); | |
129 group.children[2].remove(); | |
130 assert_child_order(group, [0, 1, 3, 4], | |
131 'element 2 should be removed'); | |
132 group.firstChild.remove(); | |
133 assert_child_order(group, [1, 3, 4], | |
134 'first child should be removed'); | |
135 group.lastChild.remove(); | |
136 assert_child_order(group, [1, 3], | |
137 'last child should be removed'); | |
138 }, 'remove'); | |
139 | |
140 test(function() { | |
141 var group = initGroup(); | |
142 var group2 = new AnimationGroup(); | |
143 group2.append(group); | |
144 var group3 = new AnimationSequence(); | |
145 group3.append(group); | |
146 assert_throws("HierarchyRequestError", | |
147 function() { | |
148 group.append(group3); | |
149 }, | |
150 'group3 should be in hierarchy of group'); | |
151 assert_throws("HierarchyRequestError", | |
152 function() { | |
153 group.append(group); | |
154 }, | |
155 'group should be in its own hierarchy'); | |
156 assert_throws("HierarchyRequestError", | |
157 function() { | |
158 anims[3].replace(group); | |
159 }, | |
160 'group should be in hierarchy of element 3'); | |
161 | |
162 }, 'inclusive ancestors fail'); | |
163 | |
164 </script> | |
OLD | NEW |