OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/compositor/layer_animation_sequence.h" | 5 #include "ui/compositor/layer_animation_sequence.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 // Check that the sequence behaves sanely when it contains no elements. | 24 // Check that the sequence behaves sanely when it contains no elements. |
25 TEST(LayerAnimationSequenceTest, NoElement) { | 25 TEST(LayerAnimationSequenceTest, NoElement) { |
26 LayerAnimationSequence sequence; | 26 LayerAnimationSequence sequence; |
27 base::TimeTicks start_time; | 27 base::TimeTicks start_time; |
28 start_time += base::TimeDelta::FromSeconds(1); | 28 start_time += base::TimeDelta::FromSeconds(1); |
29 sequence.set_start_time(start_time); | 29 sequence.set_start_time(start_time); |
30 EXPECT_TRUE(sequence.IsFinished(start_time)); | 30 EXPECT_TRUE(sequence.IsFinished(start_time)); |
31 EXPECT_TRUE(sequence.properties().size() == 0); | 31 EXPECT_TRUE(sequence.properties().size() == 0); |
32 LayerAnimationElement::AnimatableProperties properties; | 32 LayerAnimationElement::AnimatableProperties properties; |
33 EXPECT_FALSE(sequence.HasCommonProperty(properties)); | 33 EXPECT_FALSE(sequence.HasConflictingProperty(properties)); |
34 } | 34 } |
35 | 35 |
36 // Check that the sequences progresses the delegate as expected when it contains | 36 // Check that the sequences progresses the delegate as expected when it contains |
37 // a single non-threaded element. | 37 // a single non-threaded element. |
38 TEST(LayerAnimationSequenceTest, SingleElement) { | 38 TEST(LayerAnimationSequenceTest, SingleElement) { |
39 LayerAnimationSequence sequence; | 39 LayerAnimationSequence sequence; |
40 TestLayerAnimationDelegate delegate; | 40 TestLayerAnimationDelegate delegate; |
41 float start = 0.0f; | 41 float start = 0.0f; |
42 float middle = 0.5f; | 42 float middle = 0.5f; |
43 float target = 1.0f; | 43 float target = 1.0f; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 109 } |
110 | 110 |
111 // Check that the sequences progresses the delegate as expected when it contains | 111 // Check that the sequences progresses the delegate as expected when it contains |
112 // multiple elements. Note, see the layer animator tests for cyclic sequences. | 112 // multiple elements. Note, see the layer animator tests for cyclic sequences. |
113 TEST(LayerAnimationSequenceTest, MultipleElement) { | 113 TEST(LayerAnimationSequenceTest, MultipleElement) { |
114 LayerAnimationSequence sequence; | 114 LayerAnimationSequence sequence; |
115 TestLayerAnimationDelegate delegate; | 115 TestLayerAnimationDelegate delegate; |
116 float start_opacity = 0.0f; | 116 float start_opacity = 0.0f; |
117 float target_opacity = 1.0f; | 117 float target_opacity = 1.0f; |
118 base::TimeTicks start_time; | 118 base::TimeTicks start_time; |
119 base::TimeTicks effective_start; | 119 base::TimeTicks opacity_effective_start; |
| 120 base::TimeTicks transform_effective_start; |
120 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 121 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
121 sequence.AddElement( | 122 sequence.AddElement( |
122 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)); | 123 LayerAnimationElement::CreateOpacityElement(target_opacity, delta)); |
123 | 124 |
124 // Pause bounds for a second. | 125 // Pause bounds for a second. |
125 LayerAnimationElement::AnimatableProperties properties; | 126 LayerAnimationElement::AnimatableProperties properties; |
126 properties.insert(LayerAnimationElement::BOUNDS); | 127 properties.insert(LayerAnimationElement::BOUNDS); |
127 | 128 |
128 sequence.AddElement( | 129 sequence.AddElement( |
129 LayerAnimationElement::CreatePauseElement(properties, delta)); | 130 LayerAnimationElement::CreatePauseElement(properties, delta)); |
130 | 131 |
131 gfx::Transform start_transform, target_transform, middle_transform; | 132 gfx::Transform start_transform, target_transform, middle_transform; |
132 start_transform.Rotate(-30.0); | 133 start_transform.Rotate(-30.0); |
133 target_transform.Rotate(30.0); | 134 target_transform.Rotate(30.0); |
134 | 135 |
135 sequence.AddElement( | 136 sequence.AddElement( |
136 LayerAnimationElement::CreateTransformElement(target_transform, delta)); | 137 LayerAnimationElement::CreateTransformElement(target_transform, delta)); |
137 | 138 |
138 for (int i = 0; i < 2; ++i) { | 139 for (int i = 0; i < 2; ++i) { |
139 int group_id = 1; | 140 int group_id = 1; |
140 sequence.set_animation_group_id(group_id); | 141 sequence.set_animation_group_id(group_id); |
141 start_time = effective_start + 3 * delta; | 142 start_time = opacity_effective_start + 4 * delta; |
142 sequence.set_start_time(start_time); | 143 sequence.set_start_time(start_time); |
143 delegate.SetOpacityFromAnimation(start_opacity); | 144 delegate.SetOpacityFromAnimation(start_opacity); |
144 delegate.SetTransformFromAnimation(start_transform); | 145 delegate.SetTransformFromAnimation(start_transform); |
145 | 146 |
146 sequence.Progress(start_time, &delegate); | 147 sequence.Progress(start_time, &delegate); |
147 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); | 148 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); |
148 effective_start = start_time + delta; | 149 opacity_effective_start = start_time + delta; |
149 sequence.OnThreadedAnimationStarted(cc::AnimationEvent( | 150 sequence.OnThreadedAnimationStarted(cc::AnimationEvent( |
150 cc::AnimationEvent::Started, | 151 cc::AnimationEvent::Started, |
151 0, | 152 0, |
152 group_id, | 153 group_id, |
153 cc::Animation::Opacity, | 154 cc::Animation::Opacity, |
154 (effective_start - base::TimeTicks()).InSecondsF())); | 155 (opacity_effective_start - base::TimeTicks()).InSecondsF())); |
155 sequence.Progress(effective_start + delta/2, &delegate); | 156 sequence.Progress(opacity_effective_start + delta/2, &delegate); |
156 EXPECT_FLOAT_EQ(0.5, sequence.last_progressed_fraction()); | 157 EXPECT_FLOAT_EQ(0.5, sequence.last_progressed_fraction()); |
157 sequence.Progress(effective_start + delta, &delegate); | 158 sequence.Progress(opacity_effective_start + delta, &delegate); |
158 EXPECT_FLOAT_EQ(target_opacity, delegate.GetOpacityForAnimation()); | 159 EXPECT_FLOAT_EQ(target_opacity, delegate.GetOpacityForAnimation()); |
159 | 160 |
160 // Now at the start of the pause. | 161 // Now at the start of the pause. |
161 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); | 162 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); |
162 TestLayerAnimationDelegate copy = delegate; | 163 TestLayerAnimationDelegate copy = delegate; |
163 | 164 |
164 // In the middle of the pause -- nothing should have changed. | 165 // In the middle of the pause -- nothing should have changed. |
165 sequence.Progress(effective_start + delta + delta/2, | 166 sequence.Progress(opacity_effective_start + delta + delta/2, |
166 &delegate); | 167 &delegate); |
167 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), | 168 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), |
168 copy.GetBoundsForAnimation()); | 169 copy.GetBoundsForAnimation()); |
169 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), | 170 CheckApproximatelyEqual(delegate.GetTransformForAnimation(), |
170 copy.GetTransformForAnimation()); | 171 copy.GetTransformForAnimation()); |
171 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), | 172 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), |
172 copy.GetOpacityForAnimation()); | 173 copy.GetOpacityForAnimation()); |
173 | 174 |
174 | 175 sequence.Progress(opacity_effective_start + 2 * delta, &delegate); |
175 sequence.Progress(effective_start + 2 * delta, &delegate); | |
176 CheckApproximatelyEqual(start_transform, | 176 CheckApproximatelyEqual(start_transform, |
177 delegate.GetTransformForAnimation()); | 177 delegate.GetTransformForAnimation()); |
178 sequence.Progress(effective_start + 2 * delta + delta/2, &delegate); | 178 EXPECT_FLOAT_EQ(0.0, sequence.last_progressed_fraction()); |
179 CheckApproximatelyEqual(middle_transform, | 179 transform_effective_start = opacity_effective_start + 3 * delta; |
180 delegate.GetTransformForAnimation()); | 180 sequence.OnThreadedAnimationStarted(cc::AnimationEvent( |
181 EXPECT_TRUE(sequence.IsFinished(effective_start + 3 * delta)); | 181 cc::AnimationEvent::Started, |
182 sequence.Progress(effective_start + 3 * delta, &delegate); | 182 0, |
| 183 group_id, |
| 184 cc::Animation::Transform, |
| 185 (transform_effective_start - base::TimeTicks()).InSecondsF())); |
| 186 sequence.Progress(transform_effective_start + delta/2, &delegate); |
| 187 EXPECT_FLOAT_EQ(0.5, sequence.last_progressed_fraction()); |
| 188 EXPECT_TRUE(sequence.IsFinished(transform_effective_start + delta)); |
| 189 sequence.Progress(transform_effective_start + delta, &delegate); |
183 CheckApproximatelyEqual(target_transform, | 190 CheckApproximatelyEqual(target_transform, |
184 delegate.GetTransformForAnimation()); | 191 delegate.GetTransformForAnimation()); |
185 } | 192 } |
186 | 193 |
187 EXPECT_TRUE(sequence.properties().size() == 3); | 194 EXPECT_TRUE(sequence.properties().size() == 3); |
188 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::OPACITY) != | 195 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::OPACITY) != |
189 sequence.properties().end()); | 196 sequence.properties().end()); |
190 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::TRANSFORM) != | 197 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::TRANSFORM) != |
191 sequence.properties().end()); | 198 sequence.properties().end()); |
192 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::BOUNDS) != | 199 EXPECT_TRUE(sequence.properties().find(LayerAnimationElement::BOUNDS) != |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 EXPECT_TRUE(!observer.last_ended_sequence()); | 271 EXPECT_TRUE(!observer.last_ended_sequence()); |
265 sequence.Progress(start_time + delta, &delegate); | 272 sequence.Progress(start_time + delta, &delegate); |
266 EXPECT_EQ(observer.last_ended_sequence(), &sequence); | 273 EXPECT_EQ(observer.last_ended_sequence(), &sequence); |
267 sequence.RemoveObserver(&observer); | 274 sequence.RemoveObserver(&observer); |
268 } | 275 } |
269 } | 276 } |
270 | 277 |
271 } // namespace | 278 } // namespace |
272 | 279 |
273 } // namespace ui | 280 } // namespace ui |
OLD | NEW |