OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gfx/compositor/layer_animator.h" | 5 #include "ui/gfx/compositor/layer_animator.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" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
13 #include "ui/gfx/transform.h" | 13 #include "ui/gfx/transform.h" |
| 14 #include "ui/gfx/compositor/dummy_layer_animation_delegate.h" |
14 #include "ui/gfx/compositor/layer_animation_delegate.h" | 15 #include "ui/gfx/compositor/layer_animation_delegate.h" |
15 #include "ui/gfx/compositor/layer_animation_element.h" | 16 #include "ui/gfx/compositor/layer_animation_element.h" |
16 #include "ui/gfx/compositor/layer_animation_sequence.h" | 17 #include "ui/gfx/compositor/layer_animation_sequence.h" |
17 #include "ui/gfx/compositor/test_utils.h" | 18 #include "ui/gfx/compositor/test_utils.h" |
18 #include "ui/gfx/compositor/test_layer_animation_delegate.h" | |
19 | 19 |
20 namespace ui { | 20 namespace ui { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Checks that setting a property on an implicit animator causes an animation to | 24 // Checks that setting a property on an implicit animator causes an animation to |
25 // happen. | 25 // happen. |
26 TEST(LayerAnimatorTest, ImplicitAnimation) { | 26 TEST(LayerAnimatorTest, ImplicitAnimation) { |
27 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); | 27 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); |
28 AnimationContainerElement* element = animator.get(); | 28 AnimationContainerElement* element = animator.get(); |
29 animator->set_disable_timer_for_test(true); | 29 animator->set_disable_timer_for_test(true); |
30 TestLayerAnimationDelegate delegate; | 30 DummyLayerAnimationDelegate delegate; |
31 animator->SetDelegate(&delegate); | 31 animator->SetDelegate(&delegate); |
32 base::TimeTicks now = base::TimeTicks::Now(); | 32 base::TimeTicks now = base::TimeTicks::Now(); |
33 animator->SetOpacity(0.5); | 33 animator->SetOpacity(0.5); |
34 EXPECT_TRUE(animator->is_animating()); | 34 EXPECT_TRUE(animator->is_animating()); |
35 element->Step(now + base::TimeDelta::FromSeconds(1)); | 35 element->Step(now + base::TimeDelta::FromSeconds(1)); |
36 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); | 36 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); |
37 } | 37 } |
38 | 38 |
39 // Checks that if the animator is a default animator, that implicit animations | 39 // Checks that if the animator is a default animator, that implicit animations |
40 // are not started. | 40 // are not started. |
41 TEST(LayerAnimatorTest, NoImplicitAnimation) { | 41 TEST(LayerAnimatorTest, NoImplicitAnimation) { |
42 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 42 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
43 animator->set_disable_timer_for_test(true); | 43 animator->set_disable_timer_for_test(true); |
44 TestLayerAnimationDelegate delegate; | 44 DummyLayerAnimationDelegate delegate; |
45 animator->SetDelegate(&delegate); | 45 animator->SetDelegate(&delegate); |
46 base::TimeTicks now = base::TimeTicks::Now(); | 46 base::TimeTicks now = base::TimeTicks::Now(); |
47 animator->SetOpacity(0.5); | 47 animator->SetOpacity(0.5); |
48 EXPECT_FALSE(animator->is_animating()); | 48 EXPECT_FALSE(animator->is_animating()); |
49 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); | 49 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); |
50 } | 50 } |
51 | 51 |
52 // Checks that StopAnimatingProperty stops animation for that property, and also | 52 // Checks that StopAnimatingProperty stops animation for that property, and also |
53 // skips the stopped animation to the end. | 53 // skips the stopped animation to the end. |
54 TEST(LayerAnimatorTest, StopAnimatingProperty) { | 54 TEST(LayerAnimatorTest, StopAnimatingProperty) { |
55 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); | 55 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); |
56 animator->set_disable_timer_for_test(true); | 56 animator->set_disable_timer_for_test(true); |
57 TestLayerAnimationDelegate delegate; | 57 DummyLayerAnimationDelegate delegate; |
58 animator->SetDelegate(&delegate); | 58 animator->SetDelegate(&delegate); |
59 base::TimeTicks now = base::TimeTicks::Now(); | 59 base::TimeTicks now = base::TimeTicks::Now(); |
60 double target_opacity(0.5); | 60 double target_opacity(0.5); |
61 gfx::Rect target_bounds(0, 0, 50, 50); | 61 gfx::Rect target_bounds(0, 0, 50, 50); |
62 animator->SetOpacity(target_opacity); | 62 animator->SetOpacity(target_opacity); |
63 animator->SetBounds(target_bounds); | 63 animator->SetBounds(target_bounds); |
64 animator->StopAnimatingProperty(LayerAnimationElement::OPACITY); | 64 animator->StopAnimatingProperty(LayerAnimationElement::OPACITY); |
65 EXPECT_TRUE(animator->is_animating()); | 65 EXPECT_TRUE(animator->is_animating()); |
66 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); | 66 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); |
67 animator->StopAnimatingProperty(LayerAnimationElement::BOUNDS); | 67 animator->StopAnimatingProperty(LayerAnimationElement::BOUNDS); |
68 EXPECT_FALSE(animator->is_animating()); | 68 EXPECT_FALSE(animator->is_animating()); |
69 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 69 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
70 } | 70 } |
71 | 71 |
72 // Checks that multiple running animation for separate properties can be stopped | 72 // Checks that multiple running animation for separate properties can be stopped |
73 // simultaneously and that all animations are advanced to their target values. | 73 // simultaneously and that all animations are advanced to their target values. |
74 TEST(LayerAnimatorTest, StopAnimating) { | 74 TEST(LayerAnimatorTest, StopAnimating) { |
75 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); | 75 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator()); |
76 animator->set_disable_timer_for_test(true); | 76 animator->set_disable_timer_for_test(true); |
77 TestLayerAnimationDelegate delegate; | 77 DummyLayerAnimationDelegate delegate; |
78 animator->SetDelegate(&delegate); | 78 animator->SetDelegate(&delegate); |
79 base::TimeTicks now = base::TimeTicks::Now(); | 79 base::TimeTicks now = base::TimeTicks::Now(); |
80 double target_opacity(0.5); | 80 double target_opacity(0.5); |
81 gfx::Rect target_bounds(0, 0, 50, 50); | 81 gfx::Rect target_bounds(0, 0, 50, 50); |
82 animator->SetOpacity(target_opacity); | 82 animator->SetOpacity(target_opacity); |
83 animator->SetBounds(target_bounds); | 83 animator->SetBounds(target_bounds); |
84 EXPECT_TRUE(animator->is_animating()); | 84 EXPECT_TRUE(animator->is_animating()); |
85 animator->StopAnimating(); | 85 animator->StopAnimating(); |
86 EXPECT_FALSE(animator->is_animating()); | 86 EXPECT_FALSE(animator->is_animating()); |
87 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); | 87 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), 0.5); |
88 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 88 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
89 } | 89 } |
90 | 90 |
91 // Schedule an animation that can run immediately. This is the trivial case and | 91 // Schedule an animation that can run immediately. This is the trivial case and |
92 // should result in the animation being started immediately. | 92 // should result in the animation being started immediately. |
93 TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) { | 93 TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) { |
94 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 94 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
95 AnimationContainerElement* element = animator.get(); | 95 AnimationContainerElement* element = animator.get(); |
96 animator->set_disable_timer_for_test(true); | 96 animator->set_disable_timer_for_test(true); |
97 TestLayerAnimationDelegate delegate; | 97 DummyLayerAnimationDelegate delegate; |
98 animator->SetDelegate(&delegate); | 98 animator->SetDelegate(&delegate); |
99 | 99 |
100 double start_opacity(0.0); | 100 double start_opacity(0.0); |
101 double middle_opacity(0.5); | 101 double middle_opacity(0.5); |
102 double target_opacity(1.0); | 102 double target_opacity(1.0); |
103 | 103 |
104 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 104 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
105 | 105 |
106 delegate.SetOpacityFromAnimation(start_opacity); | 106 delegate.SetOpacityFromAnimation(start_opacity); |
107 | 107 |
(...skipping 16 matching lines...) Expand all Loading... |
124 EXPECT_FALSE(animator->is_animating()); | 124 EXPECT_FALSE(animator->is_animating()); |
125 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 125 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
126 } | 126 } |
127 | 127 |
128 // Schedule two animations on separate properties. Both animations should | 128 // Schedule two animations on separate properties. Both animations should |
129 // start immediately and should progress in lock step. | 129 // start immediately and should progress in lock step. |
130 TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) { | 130 TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) { |
131 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 131 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
132 AnimationContainerElement* element = animator.get(); | 132 AnimationContainerElement* element = animator.get(); |
133 animator->set_disable_timer_for_test(true); | 133 animator->set_disable_timer_for_test(true); |
134 TestLayerAnimationDelegate delegate; | 134 DummyLayerAnimationDelegate delegate; |
135 animator->SetDelegate(&delegate); | 135 animator->SetDelegate(&delegate); |
136 | 136 |
137 double start_opacity(0.0); | 137 double start_opacity(0.0); |
138 double middle_opacity(0.5); | 138 double middle_opacity(0.5); |
139 double target_opacity(1.0); | 139 double target_opacity(1.0); |
140 | 140 |
141 gfx::Rect start_bounds, target_bounds, middle_bounds; | 141 gfx::Rect start_bounds, target_bounds, middle_bounds; |
142 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); | 142 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); |
143 start_bounds.set_x(-90); | 143 start_bounds.set_x(-90); |
144 target_bounds.set_x(90); | 144 target_bounds.set_x(90); |
(...skipping 29 matching lines...) Expand all Loading... |
174 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 174 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
175 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 175 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
176 } | 176 } |
177 | 177 |
178 // Schedule two animations on the same property. In this case, the two | 178 // Schedule two animations on the same property. In this case, the two |
179 // animations should run one after another. | 179 // animations should run one after another. |
180 TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) { | 180 TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) { |
181 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 181 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
182 AnimationContainerElement* element = animator.get(); | 182 AnimationContainerElement* element = animator.get(); |
183 animator->set_disable_timer_for_test(true); | 183 animator->set_disable_timer_for_test(true); |
184 TestLayerAnimationDelegate delegate; | 184 DummyLayerAnimationDelegate delegate; |
185 animator->SetDelegate(&delegate); | 185 animator->SetDelegate(&delegate); |
186 | 186 |
187 double start_opacity(0.0); | 187 double start_opacity(0.0); |
188 double middle_opacity(0.5); | 188 double middle_opacity(0.5); |
189 double target_opacity(1.0); | 189 double target_opacity(1.0); |
190 | 190 |
191 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 191 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
192 | 192 |
193 delegate.SetOpacityFromAnimation(start_opacity); | 193 delegate.SetOpacityFromAnimation(start_opacity); |
194 | 194 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 226 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
227 } | 227 } |
228 | 228 |
229 // Schedule [{o}, {o,b}, {b}] and ensure that {b} doesn't run right away. That | 229 // Schedule [{o}, {o,b}, {b}] and ensure that {b} doesn't run right away. That |
230 // is, ensure that all animations targetting a particular property are run in | 230 // is, ensure that all animations targetting a particular property are run in |
231 // order. | 231 // order. |
232 TEST(LayerAnimatorTest, ScheduleBlockedAnimation) { | 232 TEST(LayerAnimatorTest, ScheduleBlockedAnimation) { |
233 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 233 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
234 AnimationContainerElement* element = animator.get(); | 234 AnimationContainerElement* element = animator.get(); |
235 animator->set_disable_timer_for_test(true); | 235 animator->set_disable_timer_for_test(true); |
236 TestLayerAnimationDelegate delegate; | 236 DummyLayerAnimationDelegate delegate; |
237 animator->SetDelegate(&delegate); | 237 animator->SetDelegate(&delegate); |
238 | 238 |
239 double start_opacity(0.0); | 239 double start_opacity(0.0); |
240 double middle_opacity(0.5); | 240 double middle_opacity(0.5); |
241 double target_opacity(1.0); | 241 double target_opacity(1.0); |
242 | 242 |
243 gfx::Rect start_bounds, target_bounds, middle_bounds; | 243 gfx::Rect start_bounds, target_bounds, middle_bounds; |
244 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); | 244 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); |
245 start_bounds.set_x(-90); | 245 start_bounds.set_x(-90); |
246 target_bounds.set_x(90); | 246 target_bounds.set_x(90); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 304 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
305 } | 305 } |
306 | 306 |
307 // Schedule {o} and then schedule {o} and {b} together. In this case, since | 307 // Schedule {o} and then schedule {o} and {b} together. In this case, since |
308 // ScheduleTogether is being used, the bounds animation should not start until | 308 // ScheduleTogether is being used, the bounds animation should not start until |
309 // the second opacity animation starts. | 309 // the second opacity animation starts. |
310 TEST(LayerAnimatorTest, ScheduleTogether) { | 310 TEST(LayerAnimatorTest, ScheduleTogether) { |
311 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 311 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
312 AnimationContainerElement* element = animator.get(); | 312 AnimationContainerElement* element = animator.get(); |
313 animator->set_disable_timer_for_test(true); | 313 animator->set_disable_timer_for_test(true); |
314 TestLayerAnimationDelegate delegate; | 314 DummyLayerAnimationDelegate delegate; |
315 animator->SetDelegate(&delegate); | 315 animator->SetDelegate(&delegate); |
316 | 316 |
317 double start_opacity(0.0); | 317 double start_opacity(0.0); |
318 double target_opacity(1.0); | 318 double target_opacity(1.0); |
319 | 319 |
320 gfx::Rect start_bounds, target_bounds, middle_bounds; | 320 gfx::Rect start_bounds, target_bounds, middle_bounds; |
321 start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50); | 321 start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50); |
322 start_bounds.set_x(-90); | 322 start_bounds.set_x(-90); |
323 target_bounds.set_x(90); | 323 target_bounds.set_x(90); |
324 | 324 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 357 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
358 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 358 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
359 } | 359 } |
360 | 360 |
361 // Start animation (that can run immediately). This is the trivial case (see | 361 // Start animation (that can run immediately). This is the trivial case (see |
362 // the trival case for ScheduleAnimation). | 362 // the trival case for ScheduleAnimation). |
363 TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) { | 363 TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) { |
364 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 364 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
365 AnimationContainerElement* element = animator.get(); | 365 AnimationContainerElement* element = animator.get(); |
366 animator->set_disable_timer_for_test(true); | 366 animator->set_disable_timer_for_test(true); |
367 TestLayerAnimationDelegate delegate; | 367 DummyLayerAnimationDelegate delegate; |
368 animator->SetDelegate(&delegate); | 368 animator->SetDelegate(&delegate); |
369 | 369 |
370 double start_opacity(0.0); | 370 double start_opacity(0.0); |
371 double middle_opacity(0.5); | 371 double middle_opacity(0.5); |
372 double target_opacity(1.0); | 372 double target_opacity(1.0); |
373 | 373 |
374 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 374 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
375 | 375 |
376 delegate.SetOpacityFromAnimation(start_opacity); | 376 delegate.SetOpacityFromAnimation(start_opacity); |
377 | 377 |
(...skipping 14 matching lines...) Expand all Loading... |
392 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 392 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
393 | 393 |
394 EXPECT_FALSE(animator->is_animating()); | 394 EXPECT_FALSE(animator->is_animating()); |
395 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 395 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
396 } | 396 } |
397 | 397 |
398 // Preempt by immediately setting new target. | 398 // Preempt by immediately setting new target. |
399 TEST(LayerAnimatorTest, PreemptBySettingNewTarget) { | 399 TEST(LayerAnimatorTest, PreemptBySettingNewTarget) { |
400 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 400 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
401 animator->set_disable_timer_for_test(true); | 401 animator->set_disable_timer_for_test(true); |
402 TestLayerAnimationDelegate delegate; | 402 DummyLayerAnimationDelegate delegate; |
403 animator->SetDelegate(&delegate); | 403 animator->SetDelegate(&delegate); |
404 | 404 |
405 double start_opacity(0.0); | 405 double start_opacity(0.0); |
406 double target_opacity(1.0); | 406 double target_opacity(1.0); |
407 | 407 |
408 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 408 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
409 | 409 |
410 delegate.SetOpacityFromAnimation(start_opacity); | 410 delegate.SetOpacityFromAnimation(start_opacity); |
411 | 411 |
412 animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); | 412 animator->set_preemption_strategy(LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); |
413 | 413 |
414 animator->StartAnimation( | 414 animator->StartAnimation( |
415 new LayerAnimationSequence( | 415 new LayerAnimationSequence( |
416 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); | 416 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); |
417 | 417 |
418 animator->StartAnimation( | 418 animator->StartAnimation( |
419 new LayerAnimationSequence( | 419 new LayerAnimationSequence( |
420 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); | 420 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); |
421 | 421 |
422 EXPECT_FALSE(animator->is_animating()); | 422 EXPECT_FALSE(animator->is_animating()); |
423 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 423 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
424 } | 424 } |
425 | 425 |
426 // Preempt by animating to new target. | 426 // Preempt by animating to new target. |
427 TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) { | 427 TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) { |
428 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 428 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
429 AnimationContainerElement* element = animator.get(); | 429 AnimationContainerElement* element = animator.get(); |
430 animator->set_disable_timer_for_test(true); | 430 animator->set_disable_timer_for_test(true); |
431 TestLayerAnimationDelegate delegate; | 431 DummyLayerAnimationDelegate delegate; |
432 animator->SetDelegate(&delegate); | 432 animator->SetDelegate(&delegate); |
433 | 433 |
434 double start_opacity(0.0); | 434 double start_opacity(0.0); |
435 double middle_opacity(0.5); | 435 double middle_opacity(0.5); |
436 double target_opacity(1.0); | 436 double target_opacity(1.0); |
437 | 437 |
438 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 438 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
439 | 439 |
440 delegate.SetOpacityFromAnimation(start_opacity); | 440 delegate.SetOpacityFromAnimation(start_opacity); |
441 | 441 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 473 |
474 EXPECT_FALSE(animator->is_animating()); | 474 EXPECT_FALSE(animator->is_animating()); |
475 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 475 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
476 } | 476 } |
477 | 477 |
478 // Preempt by enqueuing the new animation. | 478 // Preempt by enqueuing the new animation. |
479 TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { | 479 TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { |
480 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 480 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
481 AnimationContainerElement* element = animator.get(); | 481 AnimationContainerElement* element = animator.get(); |
482 animator->set_disable_timer_for_test(true); | 482 animator->set_disable_timer_for_test(true); |
483 TestLayerAnimationDelegate delegate; | 483 DummyLayerAnimationDelegate delegate; |
484 animator->SetDelegate(&delegate); | 484 animator->SetDelegate(&delegate); |
485 | 485 |
486 double start_opacity(0.0); | 486 double start_opacity(0.0); |
487 double middle_opacity(0.5); | 487 double middle_opacity(0.5); |
488 double target_opacity(1.0); | 488 double target_opacity(1.0); |
489 | 489 |
490 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 490 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
491 | 491 |
492 delegate.SetOpacityFromAnimation(start_opacity); | 492 delegate.SetOpacityFromAnimation(start_opacity); |
493 | 493 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 526 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
527 } | 527 } |
528 | 528 |
529 // Start an animation when there are sequences waiting in the queue. In this | 529 // Start an animation when there are sequences waiting in the queue. In this |
530 // case, all pending and running animations should be finished, and the new | 530 // case, all pending and running animations should be finished, and the new |
531 // animation started. | 531 // animation started. |
532 TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) { | 532 TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) { |
533 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 533 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
534 AnimationContainerElement* element = animator.get(); | 534 AnimationContainerElement* element = animator.get(); |
535 animator->set_disable_timer_for_test(true); | 535 animator->set_disable_timer_for_test(true); |
536 TestLayerAnimationDelegate delegate; | 536 DummyLayerAnimationDelegate delegate; |
537 animator->SetDelegate(&delegate); | 537 animator->SetDelegate(&delegate); |
538 | 538 |
539 double start_opacity(0.0); | 539 double start_opacity(0.0); |
540 double middle_opacity(0.5); | 540 double middle_opacity(0.5); |
541 double target_opacity(1.0); | 541 double target_opacity(1.0); |
542 | 542 |
543 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 543 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
544 | 544 |
545 delegate.SetOpacityFromAnimation(start_opacity); | 545 delegate.SetOpacityFromAnimation(start_opacity); |
546 | 546 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 | 581 |
582 EXPECT_FALSE(animator->is_animating()); | 582 EXPECT_FALSE(animator->is_animating()); |
583 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 583 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
584 } | 584 } |
585 | 585 |
586 // Test that cyclic sequences continue to animate. | 586 // Test that cyclic sequences continue to animate. |
587 TEST(LayerAnimatorTest, CyclicSequences) { | 587 TEST(LayerAnimatorTest, CyclicSequences) { |
588 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 588 scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
589 AnimationContainerElement* element = animator.get(); | 589 AnimationContainerElement* element = animator.get(); |
590 animator->set_disable_timer_for_test(true); | 590 animator->set_disable_timer_for_test(true); |
591 TestLayerAnimationDelegate delegate; | 591 DummyLayerAnimationDelegate delegate; |
592 animator->SetDelegate(&delegate); | 592 animator->SetDelegate(&delegate); |
593 | 593 |
594 double start_opacity(0.0); | 594 double start_opacity(0.0); |
595 double target_opacity(1.0); | 595 double target_opacity(1.0); |
596 | 596 |
597 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 597 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
598 | 598 |
599 delegate.SetOpacityFromAnimation(start_opacity); | 599 delegate.SetOpacityFromAnimation(start_opacity); |
600 | 600 |
601 scoped_ptr<LayerAnimationSequence> sequence( | 601 scoped_ptr<LayerAnimationSequence> sequence( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 639 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
640 | 640 |
641 animator->StopAnimatingProperty(LayerAnimationElement::OPACITY); | 641 animator->StopAnimatingProperty(LayerAnimationElement::OPACITY); |
642 | 642 |
643 EXPECT_FALSE(animator->is_animating()); | 643 EXPECT_FALSE(animator->is_animating()); |
644 } | 644 } |
645 | 645 |
646 } // namespace | 646 } // namespace |
647 | 647 |
648 } // namespace ui | 648 } // namespace ui |
OLD | NEW |