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_animator.h" | 5 #include "ui/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/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/compositor/layer.h" | 13 #include "ui/compositor/layer.h" |
14 #include "ui/compositor/layer_animation_delegate.h" | 14 #include "ui/compositor/layer_animation_delegate.h" |
15 #include "ui/compositor/layer_animation_element.h" | 15 #include "ui/compositor/layer_animation_element.h" |
16 #include "ui/compositor/layer_animation_sequence.h" | 16 #include "ui/compositor/layer_animation_sequence.h" |
| 17 #include "ui/compositor/layer_animator_collection.h" |
17 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 18 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
18 #include "ui/compositor/scoped_layer_animation_settings.h" | 19 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 20 #include "ui/compositor/test/context_factories_for_test.h" |
19 #include "ui/compositor/test/layer_animator_test_controller.h" | 21 #include "ui/compositor/test/layer_animator_test_controller.h" |
| 22 #include "ui/compositor/test/test_compositor_host.h" |
20 #include "ui/compositor/test/test_layer_animation_delegate.h" | 23 #include "ui/compositor/test/test_layer_animation_delegate.h" |
21 #include "ui/compositor/test/test_layer_animation_observer.h" | 24 #include "ui/compositor/test/test_layer_animation_observer.h" |
22 #include "ui/compositor/test/test_utils.h" | 25 #include "ui/compositor/test/test_utils.h" |
23 #include "ui/gfx/frame_time.h" | 26 #include "ui/gfx/frame_time.h" |
24 #include "ui/gfx/rect.h" | 27 #include "ui/gfx/rect.h" |
25 #include "ui/gfx/transform.h" | 28 #include "ui/gfx/transform.h" |
26 | 29 |
27 using gfx::AnimationContainerElement; | |
28 | |
29 namespace ui { | 30 namespace ui { |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 // Converts |color| to a string. Each component of the color is separated by a | 34 // Converts |color| to a string. Each component of the color is separated by a |
34 // space and the order if A R G B. | 35 // space and the order if A R G B. |
35 std::string ColorToString(SkColor color) { | 36 std::string ColorToString(SkColor color) { |
36 return base::StringPrintf("%d %d %d %d", SkColorGetA(color), | 37 return base::StringPrintf("%d %d %d %d", SkColorGetA(color), |
37 SkColorGetR(color), SkColorGetG(color), | 38 SkColorGetR(color), SkColorGetG(color), |
38 SkColorGetB(color)); | 39 SkColorGetB(color)); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationSequence); | 190 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationSequence); |
190 }; | 191 }; |
191 | 192 |
192 } // namespace | 193 } // namespace |
193 | 194 |
194 // Checks that setting a property on an implicit animator causes an animation to | 195 // Checks that setting a property on an implicit animator causes an animation to |
195 // happen. | 196 // happen. |
196 TEST(LayerAnimatorTest, ImplicitAnimation) { | 197 TEST(LayerAnimatorTest, ImplicitAnimation) { |
197 scoped_refptr<LayerAnimator> animator( | 198 scoped_refptr<LayerAnimator> animator( |
198 LayerAnimator::CreateImplicitAnimator()); | 199 LayerAnimator::CreateImplicitAnimator()); |
199 AnimationContainerElement* element = animator.get(); | |
200 animator->set_disable_timer_for_test(true); | 200 animator->set_disable_timer_for_test(true); |
201 TestLayerAnimationDelegate delegate; | 201 TestLayerAnimationDelegate delegate; |
202 animator->SetDelegate(&delegate); | 202 animator->SetDelegate(&delegate); |
203 base::TimeTicks now = gfx::FrameTime::Now(); | 203 base::TimeTicks now = gfx::FrameTime::Now(); |
204 animator->SetBrightness(0.5); | 204 animator->SetBrightness(0.5); |
205 EXPECT_TRUE(animator->is_animating()); | 205 EXPECT_TRUE(animator->is_animating()); |
206 element->Step(now + base::TimeDelta::FromSeconds(1)); | 206 animator->Step(now + base::TimeDelta::FromSeconds(1)); |
207 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5); | 207 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), 0.5); |
208 } | 208 } |
209 | 209 |
210 // Checks that if the animator is a default animator, that implicit animations | 210 // Checks that if the animator is a default animator, that implicit animations |
211 // are not started. | 211 // are not started. |
212 TEST(LayerAnimatorTest, NoImplicitAnimation) { | 212 TEST(LayerAnimatorTest, NoImplicitAnimation) { |
213 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 213 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
214 animator->set_disable_timer_for_test(true); | 214 animator->set_disable_timer_for_test(true); |
215 TestLayerAnimationDelegate delegate; | 215 TestLayerAnimationDelegate delegate; |
216 animator->SetDelegate(&delegate); | 216 animator->SetDelegate(&delegate); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 animator->AbortAllAnimations(); | 278 animator->AbortAllAnimations(); |
279 EXPECT_FALSE(animator->is_animating()); | 279 EXPECT_FALSE(animator->is_animating()); |
280 EXPECT_FLOAT_EQ(initial_opacity, delegate.GetOpacityForAnimation()); | 280 EXPECT_FLOAT_EQ(initial_opacity, delegate.GetOpacityForAnimation()); |
281 CheckApproximatelyEqual(initial_bounds, delegate.GetBoundsForAnimation()); | 281 CheckApproximatelyEqual(initial_bounds, delegate.GetBoundsForAnimation()); |
282 } | 282 } |
283 | 283 |
284 // Schedule a non-threaded animation that can run immediately. This is the | 284 // Schedule a non-threaded animation that can run immediately. This is the |
285 // trivial case and should result in the animation being started immediately. | 285 // trivial case and should result in the animation being started immediately. |
286 TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) { | 286 TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) { |
287 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 287 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
288 AnimationContainerElement* element = animator.get(); | |
289 animator->set_disable_timer_for_test(true); | 288 animator->set_disable_timer_for_test(true); |
290 TestLayerAnimationDelegate delegate; | 289 TestLayerAnimationDelegate delegate; |
291 animator->SetDelegate(&delegate); | 290 animator->SetDelegate(&delegate); |
292 | 291 |
293 double start_brightness(0.0); | 292 double start_brightness(0.0); |
294 double middle_brightness(0.5); | 293 double middle_brightness(0.5); |
295 double target_brightness(1.0); | 294 double target_brightness(1.0); |
296 | 295 |
297 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 296 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
298 | 297 |
299 delegate.SetBrightnessFromAnimation(start_brightness); | 298 delegate.SetBrightnessFromAnimation(start_brightness); |
300 | 299 |
301 animator->ScheduleAnimation( | 300 animator->ScheduleAnimation( |
302 new LayerAnimationSequence( | 301 new LayerAnimationSequence( |
303 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 302 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
304 delta))); | 303 delta))); |
305 | 304 |
306 EXPECT_TRUE(animator->is_animating()); | 305 EXPECT_TRUE(animator->is_animating()); |
307 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 306 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
308 | 307 |
309 base::TimeTicks start_time = animator->last_step_time(); | 308 base::TimeTicks start_time = animator->last_step_time(); |
310 | 309 |
311 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 310 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
312 | 311 |
313 EXPECT_TRUE(animator->is_animating()); | 312 EXPECT_TRUE(animator->is_animating()); |
314 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 313 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
315 | 314 |
316 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 315 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
317 | 316 |
318 EXPECT_FALSE(animator->is_animating()); | 317 EXPECT_FALSE(animator->is_animating()); |
319 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 318 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
320 } | 319 } |
321 | 320 |
322 // Schedule a threaded animation that can run immediately. | 321 // Schedule a threaded animation that can run immediately. |
323 TEST(LayerAnimatorTest, ScheduleThreadedAnimationThatCanRunImmediately) { | 322 TEST(LayerAnimatorTest, ScheduleThreadedAnimationThatCanRunImmediately) { |
324 double epsilon = 0.00001; | 323 double epsilon = 0.00001; |
325 LayerAnimatorTestController test_controller( | 324 LayerAnimatorTestController test_controller( |
326 LayerAnimator::CreateDefaultAnimator()); | 325 LayerAnimator::CreateDefaultAnimator()); |
327 AnimationContainerElement* element = test_controller.animator(); | 326 LayerAnimator* animator = test_controller.animator(); |
328 test_controller.animator()->set_disable_timer_for_test(true); | 327 test_controller.animator()->set_disable_timer_for_test(true); |
329 TestLayerAnimationDelegate delegate; | 328 TestLayerAnimationDelegate delegate; |
330 test_controller.animator()->SetDelegate(&delegate); | 329 test_controller.animator()->SetDelegate(&delegate); |
331 | 330 |
332 double start_opacity(0.0); | 331 double start_opacity(0.0); |
333 double target_opacity(1.0); | 332 double target_opacity(1.0); |
334 | 333 |
335 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 334 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
336 | 335 |
337 delegate.SetOpacityFromAnimation(start_opacity); | 336 delegate.SetOpacityFromAnimation(start_opacity); |
338 | 337 |
339 test_controller.animator()->ScheduleAnimation( | 338 test_controller.animator()->ScheduleAnimation( |
340 new LayerAnimationSequence( | 339 new LayerAnimationSequence( |
341 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); | 340 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); |
342 | 341 |
343 EXPECT_TRUE(test_controller.animator()->is_animating()); | 342 EXPECT_TRUE(test_controller.animator()->is_animating()); |
344 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 343 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
345 | 344 |
346 base::TimeTicks start_time = test_controller.animator()->last_step_time(); | 345 base::TimeTicks start_time = test_controller.animator()->last_step_time(); |
347 base::TimeTicks effective_start = start_time + delta; | 346 base::TimeTicks effective_start = start_time + delta; |
348 | 347 |
349 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 348 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
350 cc::AnimationEvent::Started, | 349 cc::AnimationEvent::Started, |
351 0, | 350 0, |
352 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 351 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
353 ->animation_group_id(), | 352 ->animation_group_id(), |
354 cc::Animation::Opacity, | 353 cc::Animation::Opacity, |
355 effective_start)); | 354 effective_start)); |
356 | 355 |
357 element->Step(effective_start + delta/2); | 356 animator->Step(effective_start + delta / 2); |
358 | 357 |
359 EXPECT_TRUE(test_controller.animator()->is_animating()); | 358 EXPECT_TRUE(test_controller.animator()->is_animating()); |
360 EXPECT_NEAR( | 359 EXPECT_NEAR( |
361 0.5, | 360 0.5, |
362 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> | 361 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> |
363 last_progressed_fraction(), | 362 last_progressed_fraction(), |
364 epsilon); | 363 epsilon); |
365 | 364 |
366 element->Step(effective_start + delta); | 365 animator->Step(effective_start + delta); |
367 | 366 |
368 EXPECT_FALSE(test_controller.animator()->is_animating()); | 367 EXPECT_FALSE(test_controller.animator()->is_animating()); |
369 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 368 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
370 } | 369 } |
371 | 370 |
372 // Schedule two non-threaded animations on separate properties. Both animations | 371 // Schedule two non-threaded animations on separate properties. Both animations |
373 // should start immediately and should progress in lock step. | 372 // should start immediately and should progress in lock step. |
374 TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) { | 373 TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) { |
375 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 374 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
376 AnimationContainerElement* element = animator.get(); | |
377 animator->set_disable_timer_for_test(true); | 375 animator->set_disable_timer_for_test(true); |
378 TestLayerAnimationDelegate delegate; | 376 TestLayerAnimationDelegate delegate; |
379 animator->SetDelegate(&delegate); | 377 animator->SetDelegate(&delegate); |
380 | 378 |
381 double start_brightness(0.0); | 379 double start_brightness(0.0); |
382 double middle_brightness(0.5); | 380 double middle_brightness(0.5); |
383 double target_brightness(1.0); | 381 double target_brightness(1.0); |
384 | 382 |
385 gfx::Rect start_bounds, target_bounds, middle_bounds; | 383 gfx::Rect start_bounds, target_bounds, middle_bounds; |
386 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); | 384 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); |
(...skipping 13 matching lines...) Expand all Loading... |
400 animator->ScheduleAnimation( | 398 animator->ScheduleAnimation( |
401 new LayerAnimationSequence( | 399 new LayerAnimationSequence( |
402 LayerAnimationElement::CreateBoundsElement(target_bounds, delta))); | 400 LayerAnimationElement::CreateBoundsElement(target_bounds, delta))); |
403 | 401 |
404 EXPECT_TRUE(animator->is_animating()); | 402 EXPECT_TRUE(animator->is_animating()); |
405 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 403 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
406 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 404 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
407 | 405 |
408 base::TimeTicks start_time = animator->last_step_time(); | 406 base::TimeTicks start_time = animator->last_step_time(); |
409 | 407 |
410 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 408 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
411 | 409 |
412 EXPECT_TRUE(animator->is_animating()); | 410 EXPECT_TRUE(animator->is_animating()); |
413 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 411 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
414 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds); | 412 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds); |
415 | 413 |
416 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 414 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
417 | 415 |
418 EXPECT_FALSE(animator->is_animating()); | 416 EXPECT_FALSE(animator->is_animating()); |
419 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 417 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
420 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 418 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
421 } | 419 } |
422 | 420 |
423 // Schedule a threaded and a non-threaded animation on separate properties. Both | 421 // Schedule a threaded and a non-threaded animation on separate properties. Both |
424 // animations should progress in lock step. | 422 // animations should progress in lock step. |
425 TEST(LayerAnimatorTest, ScheduleThreadedAndNonThreadedAnimations) { | 423 TEST(LayerAnimatorTest, ScheduleThreadedAndNonThreadedAnimations) { |
426 double epsilon = 0.00001; | 424 double epsilon = 0.00001; |
427 LayerAnimatorTestController test_controller( | 425 LayerAnimatorTestController test_controller( |
428 LayerAnimator::CreateDefaultAnimator()); | 426 LayerAnimator::CreateDefaultAnimator()); |
429 AnimationContainerElement* element = test_controller.animator(); | 427 LayerAnimator* animator = test_controller.animator(); |
430 test_controller.animator()->set_disable_timer_for_test(true); | 428 test_controller.animator()->set_disable_timer_for_test(true); |
431 TestLayerAnimationDelegate delegate; | 429 TestLayerAnimationDelegate delegate; |
432 test_controller.animator()->SetDelegate(&delegate); | 430 test_controller.animator()->SetDelegate(&delegate); |
433 | 431 |
434 double start_opacity(0.0); | 432 double start_opacity(0.0); |
435 double target_opacity(1.0); | 433 double target_opacity(1.0); |
436 | 434 |
437 gfx::Rect start_bounds, target_bounds, middle_bounds; | 435 gfx::Rect start_bounds, target_bounds, middle_bounds; |
438 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); | 436 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); |
439 start_bounds.set_x(-90); | 437 start_bounds.set_x(-90); |
(...skipping 23 matching lines...) Expand all Loading... |
463 base::TimeTicks effective_start = start_time + delta; | 461 base::TimeTicks effective_start = start_time + delta; |
464 | 462 |
465 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 463 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
466 cc::AnimationEvent::Started, | 464 cc::AnimationEvent::Started, |
467 0, | 465 0, |
468 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 466 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
469 ->animation_group_id(), | 467 ->animation_group_id(), |
470 cc::Animation::Opacity, | 468 cc::Animation::Opacity, |
471 effective_start)); | 469 effective_start)); |
472 | 470 |
473 element->Step(effective_start + delta/2); | 471 animator->Step(effective_start + delta / 2); |
474 | 472 |
475 EXPECT_TRUE(test_controller.animator()->is_animating()); | 473 EXPECT_TRUE(test_controller.animator()->is_animating()); |
476 EXPECT_NEAR( | 474 EXPECT_NEAR( |
477 0.5, | 475 0.5, |
478 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> | 476 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> |
479 last_progressed_fraction(), | 477 last_progressed_fraction(), |
480 epsilon); | 478 epsilon); |
481 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds); | 479 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), middle_bounds); |
482 | 480 |
483 element->Step(effective_start + delta); | 481 animator->Step(effective_start + delta); |
484 | 482 |
485 EXPECT_FALSE(test_controller.animator()->is_animating()); | 483 EXPECT_FALSE(test_controller.animator()->is_animating()); |
486 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 484 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
487 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 485 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
488 } | 486 } |
489 | 487 |
490 // Schedule two animations on the same property. In this case, the two | 488 // Schedule two animations on the same property. In this case, the two |
491 // animations should run one after another. | 489 // animations should run one after another. |
492 TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) { | 490 TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) { |
493 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 491 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
494 AnimationContainerElement* element = animator.get(); | |
495 animator->set_disable_timer_for_test(true); | 492 animator->set_disable_timer_for_test(true); |
496 TestLayerAnimationDelegate delegate; | 493 TestLayerAnimationDelegate delegate; |
497 animator->SetDelegate(&delegate); | 494 animator->SetDelegate(&delegate); |
498 | 495 |
499 double start_brightness(0.0); | 496 double start_brightness(0.0); |
500 double middle_brightness(0.5); | 497 double middle_brightness(0.5); |
501 double target_brightness(1.0); | 498 double target_brightness(1.0); |
502 | 499 |
503 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 500 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
504 | 501 |
505 delegate.SetBrightnessFromAnimation(start_brightness); | 502 delegate.SetBrightnessFromAnimation(start_brightness); |
506 | 503 |
507 animator->ScheduleAnimation( | 504 animator->ScheduleAnimation( |
508 new LayerAnimationSequence( | 505 new LayerAnimationSequence( |
509 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 506 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
510 delta))); | 507 delta))); |
511 | 508 |
512 animator->ScheduleAnimation( | 509 animator->ScheduleAnimation( |
513 new LayerAnimationSequence( | 510 new LayerAnimationSequence( |
514 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 511 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
515 delta))); | 512 delta))); |
516 | 513 |
517 EXPECT_TRUE(animator->is_animating()); | 514 EXPECT_TRUE(animator->is_animating()); |
518 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 515 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
519 | 516 |
520 base::TimeTicks start_time = animator->last_step_time(); | 517 base::TimeTicks start_time = animator->last_step_time(); |
521 | 518 |
522 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 519 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
523 | 520 |
524 EXPECT_TRUE(animator->is_animating()); | 521 EXPECT_TRUE(animator->is_animating()); |
525 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 522 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
526 | 523 |
527 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 524 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
528 | 525 |
529 EXPECT_TRUE(animator->is_animating()); | 526 EXPECT_TRUE(animator->is_animating()); |
530 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 527 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
531 | 528 |
532 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 529 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
533 | 530 |
534 EXPECT_TRUE(animator->is_animating()); | 531 EXPECT_TRUE(animator->is_animating()); |
535 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 532 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
536 | 533 |
537 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 534 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
538 | 535 |
539 EXPECT_FALSE(animator->is_animating()); | 536 EXPECT_FALSE(animator->is_animating()); |
540 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 537 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
541 } | 538 } |
542 | 539 |
543 // Schedule [{g}, {g,b}, {b}] and ensure that {b} doesn't run right away. That | 540 // Schedule [{g}, {g,b}, {b}] and ensure that {b} doesn't run right away. That |
544 // is, ensure that all animations targetting a particular property are run in | 541 // is, ensure that all animations targetting a particular property are run in |
545 // order. | 542 // order. |
546 TEST(LayerAnimatorTest, ScheduleBlockedAnimation) { | 543 TEST(LayerAnimatorTest, ScheduleBlockedAnimation) { |
547 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 544 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
548 AnimationContainerElement* element = animator.get(); | |
549 animator->set_disable_timer_for_test(true); | 545 animator->set_disable_timer_for_test(true); |
550 TestLayerAnimationDelegate delegate; | 546 TestLayerAnimationDelegate delegate; |
551 animator->SetDelegate(&delegate); | 547 animator->SetDelegate(&delegate); |
552 | 548 |
553 double start_grayscale(0.0); | 549 double start_grayscale(0.0); |
554 double middle_grayscale(0.5); | 550 double middle_grayscale(0.5); |
555 double target_grayscale(1.0); | 551 double target_grayscale(1.0); |
556 | 552 |
557 gfx::Rect start_bounds, target_bounds, middle_bounds; | 553 gfx::Rect start_bounds, target_bounds, middle_bounds; |
558 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); | 554 start_bounds = target_bounds = middle_bounds = gfx::Rect(0, 0, 50, 50); |
(...skipping 23 matching lines...) Expand all Loading... |
582 animator->ScheduleAnimation( | 578 animator->ScheduleAnimation( |
583 new LayerAnimationSequence( | 579 new LayerAnimationSequence( |
584 LayerAnimationElement::CreateBoundsElement(start_bounds, delta))); | 580 LayerAnimationElement::CreateBoundsElement(start_bounds, delta))); |
585 | 581 |
586 EXPECT_TRUE(animator->is_animating()); | 582 EXPECT_TRUE(animator->is_animating()); |
587 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 583 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
588 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 584 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
589 | 585 |
590 base::TimeTicks start_time = animator->last_step_time(); | 586 base::TimeTicks start_time = animator->last_step_time(); |
591 | 587 |
592 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 588 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
593 | 589 |
594 EXPECT_TRUE(animator->is_animating()); | 590 EXPECT_TRUE(animator->is_animating()); |
595 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); | 591 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); |
596 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 592 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
597 | 593 |
598 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 594 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
599 | 595 |
600 EXPECT_TRUE(animator->is_animating()); | 596 EXPECT_TRUE(animator->is_animating()); |
601 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); | 597 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); |
602 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 598 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
603 | 599 |
604 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 600 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
605 | 601 |
606 EXPECT_TRUE(animator->is_animating()); | 602 EXPECT_TRUE(animator->is_animating()); |
607 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 603 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
608 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 604 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
609 | 605 |
610 element->Step(start_time + base::TimeDelta::FromMilliseconds(3000)); | 606 animator->Step(start_time + base::TimeDelta::FromMilliseconds(3000)); |
611 | 607 |
612 EXPECT_TRUE(animator->is_animating()); | 608 EXPECT_TRUE(animator->is_animating()); |
613 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 609 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
614 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 610 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
615 | 611 |
616 element->Step(start_time + base::TimeDelta::FromMilliseconds(4000)); | 612 animator->Step(start_time + base::TimeDelta::FromMilliseconds(4000)); |
617 | 613 |
618 EXPECT_FALSE(animator->is_animating()); | 614 EXPECT_FALSE(animator->is_animating()); |
619 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 615 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
620 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 616 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
621 } | 617 } |
622 | 618 |
623 // Schedule {g} and then schedule {g} and {b} together. In this case, since | 619 // Schedule {g} and then schedule {g} and {b} together. In this case, since |
624 // ScheduleTogether is being used, the bounds animation should not start until | 620 // ScheduleTogether is being used, the bounds animation should not start until |
625 // the second grayscale animation starts. | 621 // the second grayscale animation starts. |
626 TEST(LayerAnimatorTest, ScheduleTogether) { | 622 TEST(LayerAnimatorTest, ScheduleTogether) { |
627 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 623 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
628 AnimationContainerElement* element = animator.get(); | |
629 animator->set_disable_timer_for_test(true); | 624 animator->set_disable_timer_for_test(true); |
630 TestLayerAnimationDelegate delegate; | 625 TestLayerAnimationDelegate delegate; |
631 animator->SetDelegate(&delegate); | 626 animator->SetDelegate(&delegate); |
632 | 627 |
633 double start_grayscale(0.0); | 628 double start_grayscale(0.0); |
634 double target_grayscale(1.0); | 629 double target_grayscale(1.0); |
635 | 630 |
636 gfx::Rect start_bounds, target_bounds, middle_bounds; | 631 gfx::Rect start_bounds, target_bounds, middle_bounds; |
637 start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50); | 632 start_bounds = target_bounds = gfx::Rect(0, 0, 50, 50); |
638 start_bounds.set_x(-90); | 633 start_bounds.set_x(-90); |
(...skipping 16 matching lines...) Expand all Loading... |
655 LayerAnimationElement::CreateBoundsElement(target_bounds, delta))); | 650 LayerAnimationElement::CreateBoundsElement(target_bounds, delta))); |
656 | 651 |
657 animator->ScheduleTogether(sequences); | 652 animator->ScheduleTogether(sequences); |
658 | 653 |
659 EXPECT_TRUE(animator->is_animating()); | 654 EXPECT_TRUE(animator->is_animating()); |
660 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 655 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
661 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 656 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
662 | 657 |
663 base::TimeTicks start_time = animator->last_step_time(); | 658 base::TimeTicks start_time = animator->last_step_time(); |
664 | 659 |
665 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 660 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
666 | 661 |
667 EXPECT_TRUE(animator->is_animating()); | 662 EXPECT_TRUE(animator->is_animating()); |
668 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); | 663 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); |
669 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); | 664 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), start_bounds); |
670 | 665 |
671 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 666 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
672 | 667 |
673 EXPECT_FALSE(animator->is_animating()); | 668 EXPECT_FALSE(animator->is_animating()); |
674 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 669 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
675 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); | 670 CheckApproximatelyEqual(delegate.GetBoundsForAnimation(), target_bounds); |
676 } | 671 } |
677 | 672 |
678 // Start non-threaded animation (that can run immediately). This is the trivial | 673 // Start non-threaded animation (that can run immediately). This is the trivial |
679 // case (see the trival case for ScheduleAnimation). | 674 // case (see the trival case for ScheduleAnimation). |
680 TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) { | 675 TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) { |
681 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 676 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
682 AnimationContainerElement* element = animator.get(); | |
683 animator->set_disable_timer_for_test(true); | 677 animator->set_disable_timer_for_test(true); |
684 TestLayerAnimationDelegate delegate; | 678 TestLayerAnimationDelegate delegate; |
685 animator->SetDelegate(&delegate); | 679 animator->SetDelegate(&delegate); |
686 | 680 |
687 double start_brightness(0.0); | 681 double start_brightness(0.0); |
688 double middle_brightness(0.5); | 682 double middle_brightness(0.5); |
689 double target_brightness(1.0); | 683 double target_brightness(1.0); |
690 | 684 |
691 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 685 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
692 | 686 |
693 delegate.SetBrightnessFromAnimation(start_brightness); | 687 delegate.SetBrightnessFromAnimation(start_brightness); |
694 | 688 |
695 animator->StartAnimation( | 689 animator->StartAnimation( |
696 new LayerAnimationSequence( | 690 new LayerAnimationSequence( |
697 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 691 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
698 delta))); | 692 delta))); |
699 | 693 |
700 EXPECT_TRUE(animator->is_animating()); | 694 EXPECT_TRUE(animator->is_animating()); |
701 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 695 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
702 | 696 |
703 base::TimeTicks start_time = animator->last_step_time(); | 697 base::TimeTicks start_time = animator->last_step_time(); |
704 | 698 |
705 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 699 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
706 | 700 |
707 EXPECT_TRUE(animator->is_animating()); | 701 EXPECT_TRUE(animator->is_animating()); |
708 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 702 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
709 | 703 |
710 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 704 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
711 | 705 |
712 EXPECT_FALSE(animator->is_animating()); | 706 EXPECT_FALSE(animator->is_animating()); |
713 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 707 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
714 } | 708 } |
715 | 709 |
716 // Start threaded animation (that can run immediately). | 710 // Start threaded animation (that can run immediately). |
717 TEST(LayerAnimatorTest, StartThreadedAnimationThatCanRunImmediately) { | 711 TEST(LayerAnimatorTest, StartThreadedAnimationThatCanRunImmediately) { |
718 double epsilon = 0.00001; | 712 double epsilon = 0.00001; |
719 LayerAnimatorTestController test_controller( | 713 LayerAnimatorTestController test_controller( |
720 LayerAnimator::CreateDefaultAnimator()); | 714 LayerAnimator::CreateDefaultAnimator()); |
721 AnimationContainerElement* element = test_controller.animator(); | 715 LayerAnimator* animator = test_controller.animator(); |
722 test_controller.animator()->set_disable_timer_for_test(true); | 716 test_controller.animator()->set_disable_timer_for_test(true); |
723 TestLayerAnimationDelegate delegate; | 717 TestLayerAnimationDelegate delegate; |
724 test_controller.animator()->SetDelegate(&delegate); | 718 test_controller.animator()->SetDelegate(&delegate); |
725 | 719 |
726 double start_opacity(0.0); | 720 double start_opacity(0.0); |
727 double target_opacity(1.0); | 721 double target_opacity(1.0); |
728 | 722 |
729 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 723 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
730 | 724 |
731 delegate.SetOpacityFromAnimation(start_opacity); | 725 delegate.SetOpacityFromAnimation(start_opacity); |
732 | 726 |
733 test_controller.animator()->StartAnimation( | 727 test_controller.animator()->StartAnimation( |
734 new LayerAnimationSequence( | 728 new LayerAnimationSequence( |
735 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); | 729 LayerAnimationElement::CreateOpacityElement(target_opacity, delta))); |
736 | 730 |
737 EXPECT_TRUE(test_controller.animator()->is_animating()); | 731 EXPECT_TRUE(test_controller.animator()->is_animating()); |
738 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 732 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
739 | 733 |
740 base::TimeTicks start_time = test_controller.animator()->last_step_time(); | 734 base::TimeTicks start_time = test_controller.animator()->last_step_time(); |
741 base::TimeTicks effective_start = start_time + delta; | 735 base::TimeTicks effective_start = start_time + delta; |
742 | 736 |
743 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 737 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
744 cc::AnimationEvent::Started, | 738 cc::AnimationEvent::Started, |
745 0, | 739 0, |
746 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 740 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
747 ->animation_group_id(), | 741 ->animation_group_id(), |
748 cc::Animation::Opacity, | 742 cc::Animation::Opacity, |
749 effective_start)); | 743 effective_start)); |
750 | 744 |
751 element->Step(effective_start + delta/2); | 745 animator->Step(effective_start + delta / 2); |
752 | 746 |
753 EXPECT_TRUE(test_controller.animator()->is_animating()); | 747 EXPECT_TRUE(test_controller.animator()->is_animating()); |
754 EXPECT_NEAR( | 748 EXPECT_NEAR( |
755 0.5, | 749 0.5, |
756 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> | 750 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> |
757 last_progressed_fraction(), | 751 last_progressed_fraction(), |
758 epsilon); | 752 epsilon); |
759 | 753 |
760 element->Step(effective_start + delta); | 754 animator->Step(effective_start + delta); |
761 EXPECT_FALSE(test_controller.animator()->is_animating()); | 755 EXPECT_FALSE(test_controller.animator()->is_animating()); |
762 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 756 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
763 } | 757 } |
764 | 758 |
765 // Preempt by immediately setting new target. | 759 // Preempt by immediately setting new target. |
766 TEST(LayerAnimatorTest, PreemptBySettingNewTarget) { | 760 TEST(LayerAnimatorTest, PreemptBySettingNewTarget) { |
767 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 761 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
768 animator->set_disable_timer_for_test(true); | 762 animator->set_disable_timer_for_test(true); |
769 TestLayerAnimationDelegate delegate; | 763 TestLayerAnimationDelegate delegate; |
770 animator->SetDelegate(&delegate); | 764 animator->SetDelegate(&delegate); |
(...skipping 15 matching lines...) Expand all Loading... |
786 new LayerAnimationSequence( | 780 new LayerAnimationSequence( |
787 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); | 781 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); |
788 | 782 |
789 EXPECT_FALSE(animator->is_animating()); | 783 EXPECT_FALSE(animator->is_animating()); |
790 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 784 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
791 } | 785 } |
792 | 786 |
793 // Preempt by animating to new target, with a non-threaded animation. | 787 // Preempt by animating to new target, with a non-threaded animation. |
794 TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) { | 788 TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) { |
795 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 789 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
796 AnimationContainerElement* element = animator.get(); | |
797 animator->set_disable_timer_for_test(true); | 790 animator->set_disable_timer_for_test(true); |
798 TestLayerAnimationDelegate delegate; | 791 TestLayerAnimationDelegate delegate; |
799 animator->SetDelegate(&delegate); | 792 animator->SetDelegate(&delegate); |
800 | 793 |
801 double start_brightness(0.0); | 794 double start_brightness(0.0); |
802 double middle_brightness(0.5); | 795 double middle_brightness(0.5); |
803 double target_brightness(1.0); | 796 double target_brightness(1.0); |
804 | 797 |
805 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 798 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
806 | 799 |
807 delegate.SetBrightnessFromAnimation(start_brightness); | 800 delegate.SetBrightnessFromAnimation(start_brightness); |
808 | 801 |
809 animator->set_preemption_strategy( | 802 animator->set_preemption_strategy( |
810 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 803 LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
811 | 804 |
812 animator->StartAnimation( | 805 animator->StartAnimation( |
813 new LayerAnimationSequence( | 806 new LayerAnimationSequence( |
814 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 807 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
815 delta))); | 808 delta))); |
816 | 809 |
817 base::TimeTicks start_time = animator->last_step_time(); | 810 base::TimeTicks start_time = animator->last_step_time(); |
818 | 811 |
819 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 812 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
820 | 813 |
821 animator->StartAnimation( | 814 animator->StartAnimation( |
822 new LayerAnimationSequence( | 815 new LayerAnimationSequence( |
823 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 816 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
824 delta))); | 817 delta))); |
825 | 818 |
826 EXPECT_TRUE(animator->is_animating()); | 819 EXPECT_TRUE(animator->is_animating()); |
827 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 820 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
828 | 821 |
829 animator->StartAnimation( | 822 animator->StartAnimation( |
830 new LayerAnimationSequence( | 823 new LayerAnimationSequence( |
831 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 824 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
832 delta))); | 825 delta))); |
833 | 826 |
834 EXPECT_TRUE(animator->is_animating()); | 827 EXPECT_TRUE(animator->is_animating()); |
835 | 828 |
836 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 829 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
837 | 830 |
838 EXPECT_TRUE(animator->is_animating()); | 831 EXPECT_TRUE(animator->is_animating()); |
839 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), | 832 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), |
840 0.5 * (start_brightness + middle_brightness)); | 833 0.5 * (start_brightness + middle_brightness)); |
841 | 834 |
842 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 835 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
843 | 836 |
844 EXPECT_FALSE(animator->is_animating()); | 837 EXPECT_FALSE(animator->is_animating()); |
845 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 838 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
846 } | 839 } |
847 | 840 |
848 // Preempt by animating to new target, with a threaded animation. | 841 // Preempt by animating to new target, with a threaded animation. |
849 TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) { | 842 TEST(LayerAnimatorTest, PreemptThreadedByImmediatelyAnimatingToNewTarget) { |
850 double epsilon = 0.00001; | 843 double epsilon = 0.00001; |
851 LayerAnimatorTestController test_controller( | 844 LayerAnimatorTestController test_controller( |
852 LayerAnimator::CreateDefaultAnimator()); | 845 LayerAnimator::CreateDefaultAnimator()); |
853 AnimationContainerElement* element = test_controller.animator(); | 846 LayerAnimator* animator = test_controller.animator(); |
854 test_controller.animator()->set_disable_timer_for_test(true); | 847 test_controller.animator()->set_disable_timer_for_test(true); |
855 TestLayerAnimationDelegate delegate; | 848 TestLayerAnimationDelegate delegate; |
856 test_controller.animator()->SetDelegate(&delegate); | 849 test_controller.animator()->SetDelegate(&delegate); |
857 | 850 |
858 double start_opacity(0.0); | 851 double start_opacity(0.0); |
859 double middle_opacity(0.5); | 852 double middle_opacity(0.5); |
860 double target_opacity(1.0); | 853 double target_opacity(1.0); |
861 | 854 |
862 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 855 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
863 | 856 |
(...skipping 10 matching lines...) Expand all Loading... |
874 base::TimeTicks effective_start = start_time + delta; | 867 base::TimeTicks effective_start = start_time + delta; |
875 | 868 |
876 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 869 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
877 cc::AnimationEvent::Started, | 870 cc::AnimationEvent::Started, |
878 0, | 871 0, |
879 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 872 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
880 ->animation_group_id(), | 873 ->animation_group_id(), |
881 cc::Animation::Opacity, | 874 cc::Animation::Opacity, |
882 effective_start)); | 875 effective_start)); |
883 | 876 |
884 element->Step(effective_start + delta/2); | 877 animator->Step(effective_start + delta / 2); |
885 | 878 |
886 test_controller.animator()->StartAnimation( | 879 test_controller.animator()->StartAnimation( |
887 new LayerAnimationSequence( | 880 new LayerAnimationSequence( |
888 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); | 881 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); |
889 | 882 |
890 EXPECT_TRUE(test_controller.animator()->is_animating()); | 883 EXPECT_TRUE(test_controller.animator()->is_animating()); |
891 EXPECT_NEAR(delegate.GetOpacityForAnimation(), middle_opacity, epsilon); | 884 EXPECT_NEAR(delegate.GetOpacityForAnimation(), middle_opacity, epsilon); |
892 | 885 |
893 test_controller.animator()->StartAnimation( | 886 test_controller.animator()->StartAnimation( |
894 new LayerAnimationSequence( | 887 new LayerAnimationSequence( |
895 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); | 888 LayerAnimationElement::CreateOpacityElement(start_opacity, delta))); |
896 | 889 |
897 EXPECT_TRUE(test_controller.animator()->is_animating()); | 890 EXPECT_TRUE(test_controller.animator()->is_animating()); |
898 | 891 |
899 base::TimeTicks second_effective_start = effective_start + delta; | 892 base::TimeTicks second_effective_start = effective_start + delta; |
900 | 893 |
901 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 894 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
902 cc::AnimationEvent::Started, | 895 cc::AnimationEvent::Started, |
903 0, | 896 0, |
904 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 897 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
905 ->animation_group_id(), | 898 ->animation_group_id(), |
906 cc::Animation::Opacity, | 899 cc::Animation::Opacity, |
907 second_effective_start)); | 900 second_effective_start)); |
908 | 901 |
909 element->Step(second_effective_start + delta/2); | 902 animator->Step(second_effective_start + delta / 2); |
910 | 903 |
911 EXPECT_TRUE(test_controller.animator()->is_animating()); | 904 EXPECT_TRUE(test_controller.animator()->is_animating()); |
912 EXPECT_NEAR( | 905 EXPECT_NEAR( |
913 0.5, | 906 0.5, |
914 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> | 907 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> |
915 last_progressed_fraction(), | 908 last_progressed_fraction(), |
916 epsilon); | 909 epsilon); |
917 | 910 |
918 element->Step(second_effective_start + delta); | 911 animator->Step(second_effective_start + delta); |
919 | 912 |
920 EXPECT_FALSE(test_controller.animator()->is_animating()); | 913 EXPECT_FALSE(test_controller.animator()->is_animating()); |
921 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 914 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
922 } | 915 } |
923 | 916 |
924 // Preempt by enqueuing the new animation. | 917 // Preempt by enqueuing the new animation. |
925 TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { | 918 TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) { |
926 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 919 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
927 AnimationContainerElement* element = animator.get(); | |
928 animator->set_disable_timer_for_test(true); | 920 animator->set_disable_timer_for_test(true); |
929 TestLayerAnimationDelegate delegate; | 921 TestLayerAnimationDelegate delegate; |
930 animator->SetDelegate(&delegate); | 922 animator->SetDelegate(&delegate); |
931 | 923 |
932 double start_brightness(0.0); | 924 double start_brightness(0.0); |
933 double middle_brightness(0.5); | 925 double middle_brightness(0.5); |
934 double target_brightness(1.0); | 926 double target_brightness(1.0); |
935 | 927 |
936 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 928 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
937 | 929 |
938 delegate.SetBrightnessFromAnimation(start_brightness); | 930 delegate.SetBrightnessFromAnimation(start_brightness); |
939 | 931 |
940 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); | 932 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); |
941 | 933 |
942 animator->StartAnimation( | 934 animator->StartAnimation( |
943 new LayerAnimationSequence( | 935 new LayerAnimationSequence( |
944 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 936 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
945 delta))); | 937 delta))); |
946 | 938 |
947 base::TimeTicks start_time = animator->last_step_time(); | 939 base::TimeTicks start_time = animator->last_step_time(); |
948 | 940 |
949 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 941 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
950 | 942 |
951 animator->StartAnimation( | 943 animator->StartAnimation( |
952 new LayerAnimationSequence( | 944 new LayerAnimationSequence( |
953 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 945 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
954 delta))); | 946 delta))); |
955 | 947 |
956 EXPECT_TRUE(animator->is_animating()); | 948 EXPECT_TRUE(animator->is_animating()); |
957 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 949 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
958 | 950 |
959 EXPECT_TRUE(animator->is_animating()); | 951 EXPECT_TRUE(animator->is_animating()); |
960 | 952 |
961 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 953 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
962 | 954 |
963 EXPECT_TRUE(animator->is_animating()); | 955 EXPECT_TRUE(animator->is_animating()); |
964 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 956 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
965 | 957 |
966 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 958 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
967 | 959 |
968 EXPECT_TRUE(animator->is_animating()); | 960 EXPECT_TRUE(animator->is_animating()); |
969 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 961 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
970 | 962 |
971 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 963 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
972 | 964 |
973 EXPECT_FALSE(animator->is_animating()); | 965 EXPECT_FALSE(animator->is_animating()); |
974 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 966 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
975 } | 967 } |
976 | 968 |
977 // Start an animation when there are sequences waiting in the queue. In this | 969 // Start an animation when there are sequences waiting in the queue. In this |
978 // case, all pending and running animations should be finished, and the new | 970 // case, all pending and running animations should be finished, and the new |
979 // animation started. | 971 // animation started. |
980 TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) { | 972 TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) { |
981 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 973 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
982 AnimationContainerElement* element = animator.get(); | |
983 animator->set_disable_timer_for_test(true); | 974 animator->set_disable_timer_for_test(true); |
984 TestLayerAnimationDelegate delegate; | 975 TestLayerAnimationDelegate delegate; |
985 animator->SetDelegate(&delegate); | 976 animator->SetDelegate(&delegate); |
986 | 977 |
987 double start_brightness(0.0); | 978 double start_brightness(0.0); |
988 double middle_brightness(0.5); | 979 double middle_brightness(0.5); |
989 double target_brightness(1.0); | 980 double target_brightness(1.0); |
990 | 981 |
991 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 982 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
992 | 983 |
993 delegate.SetBrightnessFromAnimation(start_brightness); | 984 delegate.SetBrightnessFromAnimation(start_brightness); |
994 | 985 |
995 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 986 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
996 | 987 |
997 animator->StartAnimation( | 988 animator->StartAnimation( |
998 new LayerAnimationSequence( | 989 new LayerAnimationSequence( |
999 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 990 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
1000 delta))); | 991 delta))); |
1001 | 992 |
1002 base::TimeTicks start_time = animator->last_step_time(); | 993 base::TimeTicks start_time = animator->last_step_time(); |
1003 | 994 |
1004 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 995 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
1005 | 996 |
1006 animator->StartAnimation( | 997 animator->StartAnimation( |
1007 new LayerAnimationSequence( | 998 new LayerAnimationSequence( |
1008 LayerAnimationElement::CreateBrightnessElement(middle_brightness, | 999 LayerAnimationElement::CreateBrightnessElement(middle_brightness, |
1009 delta))); | 1000 delta))); |
1010 | 1001 |
1011 // Queue should now have two animations. Starting a third should replace the | 1002 // Queue should now have two animations. Starting a third should replace the |
1012 // second. | 1003 // second. |
1013 animator->StartAnimation( | 1004 animator->StartAnimation( |
1014 new LayerAnimationSequence( | 1005 new LayerAnimationSequence( |
1015 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 1006 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
1016 delta))); | 1007 delta))); |
1017 | 1008 |
1018 EXPECT_TRUE(animator->is_animating()); | 1009 EXPECT_TRUE(animator->is_animating()); |
1019 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 1010 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
1020 | 1011 |
1021 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1012 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1022 | 1013 |
1023 EXPECT_TRUE(animator->is_animating()); | 1014 EXPECT_TRUE(animator->is_animating()); |
1024 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 1015 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
1025 | 1016 |
1026 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 1017 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
1027 | 1018 |
1028 EXPECT_TRUE(animator->is_animating()); | 1019 EXPECT_TRUE(animator->is_animating()); |
1029 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 1020 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
1030 | 1021 |
1031 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 1022 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
1032 | 1023 |
1033 EXPECT_FALSE(animator->is_animating()); | 1024 EXPECT_FALSE(animator->is_animating()); |
1034 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 1025 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
1035 } | 1026 } |
1036 | 1027 |
1037 TEST(LayerAnimatorTest, StartTogetherSetsLastStepTime) { | 1028 TEST(LayerAnimatorTest, StartTogetherSetsLastStepTime) { |
1038 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1029 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1039 animator->set_disable_timer_for_test(true); | 1030 animator->set_disable_timer_for_test(true); |
1040 TestLayerAnimationDelegate delegate; | 1031 TestLayerAnimationDelegate delegate; |
1041 animator->SetDelegate(&delegate); | 1032 animator->SetDelegate(&delegate); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 )); | 1097 )); |
1107 | 1098 |
1108 EXPECT_FALSE(animator->is_animating()); | 1099 EXPECT_FALSE(animator->is_animating()); |
1109 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 1100 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
1110 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 1101 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
1111 } | 1102 } |
1112 | 1103 |
1113 // Preempt by animating to new target. | 1104 // Preempt by animating to new target. |
1114 TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) { | 1105 TEST(LayerAnimatorTest, MultiPreemptByImmediatelyAnimatingToNewTarget) { |
1115 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1106 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1116 AnimationContainerElement* element = animator.get(); | |
1117 animator->set_disable_timer_for_test(true); | 1107 animator->set_disable_timer_for_test(true); |
1118 TestLayerAnimationDelegate delegate; | 1108 TestLayerAnimationDelegate delegate; |
1119 animator->SetDelegate(&delegate); | 1109 animator->SetDelegate(&delegate); |
1120 | 1110 |
1121 double start_grayscale(0.0); | 1111 double start_grayscale(0.0); |
1122 double middle_grayscale(0.5); | 1112 double middle_grayscale(0.5); |
1123 double target_grayscale(1.0); | 1113 double target_grayscale(1.0); |
1124 | 1114 |
1125 double start_brightness(0.1); | 1115 double start_brightness(0.1); |
1126 double middle_brightness(0.2); | 1116 double middle_brightness(0.2); |
(...skipping 10 matching lines...) Expand all Loading... |
1137 animator->StartTogether( | 1127 animator->StartTogether( |
1138 CreateMultiSequence( | 1128 CreateMultiSequence( |
1139 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, | 1129 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, |
1140 delta), | 1130 delta), |
1141 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 1131 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
1142 delta) | 1132 delta) |
1143 )); | 1133 )); |
1144 | 1134 |
1145 base::TimeTicks start_time = animator->last_step_time(); | 1135 base::TimeTicks start_time = animator->last_step_time(); |
1146 | 1136 |
1147 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 1137 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
1148 | 1138 |
1149 animator->StartTogether( | 1139 animator->StartTogether( |
1150 CreateMultiSequence( | 1140 CreateMultiSequence( |
1151 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), | 1141 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), |
1152 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 1142 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
1153 delta))); | 1143 delta))); |
1154 | 1144 |
1155 EXPECT_TRUE(animator->is_animating()); | 1145 EXPECT_TRUE(animator->is_animating()); |
1156 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); | 1146 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); |
1157 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 1147 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
1158 | 1148 |
1159 animator->StartTogether( | 1149 animator->StartTogether( |
1160 CreateMultiSequence( | 1150 CreateMultiSequence( |
1161 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), | 1151 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), |
1162 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 1152 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
1163 delta))); | 1153 delta))); |
1164 | 1154 |
1165 EXPECT_TRUE(animator->is_animating()); | 1155 EXPECT_TRUE(animator->is_animating()); |
1166 | 1156 |
1167 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1157 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1168 | 1158 |
1169 EXPECT_TRUE(animator->is_animating()); | 1159 EXPECT_TRUE(animator->is_animating()); |
1170 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), | 1160 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), |
1171 0.5 * (start_grayscale + middle_grayscale)); | 1161 0.5 * (start_grayscale + middle_grayscale)); |
1172 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), | 1162 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), |
1173 0.5 * (start_brightness + middle_brightness)); | 1163 0.5 * (start_brightness + middle_brightness)); |
1174 | 1164 |
1175 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 1165 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
1176 | 1166 |
1177 EXPECT_FALSE(animator->is_animating()); | 1167 EXPECT_FALSE(animator->is_animating()); |
1178 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 1168 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
1179 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 1169 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
1180 } | 1170 } |
1181 | 1171 |
1182 // Preempt a threaded animation by animating to new target. | 1172 // Preempt a threaded animation by animating to new target. |
1183 TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) { | 1173 TEST(LayerAnimatorTest, MultiPreemptThreadedByImmediatelyAnimatingToNewTarget) { |
1184 double epsilon = 0.00001; | 1174 double epsilon = 0.00001; |
1185 LayerAnimatorTestController test_controller( | 1175 LayerAnimatorTestController test_controller( |
1186 LayerAnimator::CreateDefaultAnimator()); | 1176 LayerAnimator::CreateDefaultAnimator()); |
1187 AnimationContainerElement* element = test_controller.animator(); | 1177 LayerAnimator* animator = test_controller.animator(); |
1188 test_controller.animator()->set_disable_timer_for_test(true); | 1178 test_controller.animator()->set_disable_timer_for_test(true); |
1189 TestLayerAnimationDelegate delegate; | 1179 TestLayerAnimationDelegate delegate; |
1190 test_controller.animator()->SetDelegate(&delegate); | 1180 test_controller.animator()->SetDelegate(&delegate); |
1191 | 1181 |
1192 double start_opacity(0.0); | 1182 double start_opacity(0.0); |
1193 double middle_opacity(0.5); | 1183 double middle_opacity(0.5); |
1194 double target_opacity(1.0); | 1184 double target_opacity(1.0); |
1195 | 1185 |
1196 double start_brightness(0.1); | 1186 double start_brightness(0.1); |
1197 double middle_brightness(0.2); | 1187 double middle_brightness(0.2); |
(...skipping 18 matching lines...) Expand all Loading... |
1216 base::TimeTicks effective_start = start_time + delta; | 1206 base::TimeTicks effective_start = start_time + delta; |
1217 | 1207 |
1218 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 1208 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
1219 cc::AnimationEvent::Started, | 1209 cc::AnimationEvent::Started, |
1220 0, | 1210 0, |
1221 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 1211 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
1222 ->animation_group_id(), | 1212 ->animation_group_id(), |
1223 cc::Animation::Opacity, | 1213 cc::Animation::Opacity, |
1224 effective_start)); | 1214 effective_start)); |
1225 | 1215 |
1226 element->Step(effective_start + delta/2); | 1216 animator->Step(effective_start + delta / 2); |
1227 | 1217 |
1228 test_controller.animator()->StartTogether( | 1218 test_controller.animator()->StartTogether( |
1229 CreateMultiSequence( | 1219 CreateMultiSequence( |
1230 LayerAnimationElement::CreateOpacityElement(start_opacity, delta), | 1220 LayerAnimationElement::CreateOpacityElement(start_opacity, delta), |
1231 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 1221 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
1232 delta))); | 1222 delta))); |
1233 | 1223 |
1234 EXPECT_TRUE(test_controller.animator()->is_animating()); | 1224 EXPECT_TRUE(test_controller.animator()->is_animating()); |
1235 EXPECT_NEAR(delegate.GetOpacityForAnimation(), middle_opacity, epsilon); | 1225 EXPECT_NEAR(delegate.GetOpacityForAnimation(), middle_opacity, epsilon); |
1236 EXPECT_NEAR(delegate.GetBrightnessForAnimation(), middle_brightness, epsilon); | 1226 EXPECT_NEAR(delegate.GetBrightnessForAnimation(), middle_brightness, epsilon); |
1237 | 1227 |
1238 test_controller.animator()->StartTogether( | 1228 test_controller.animator()->StartTogether( |
1239 CreateMultiSequence( | 1229 CreateMultiSequence( |
1240 LayerAnimationElement::CreateOpacityElement(start_opacity, delta), | 1230 LayerAnimationElement::CreateOpacityElement(start_opacity, delta), |
1241 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 1231 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
1242 delta))); | 1232 delta))); |
1243 | 1233 |
1244 EXPECT_TRUE(test_controller.animator()->is_animating()); | 1234 EXPECT_TRUE(test_controller.animator()->is_animating()); |
1245 | 1235 |
1246 base::TimeTicks second_effective_start = effective_start + delta; | 1236 base::TimeTicks second_effective_start = effective_start + delta; |
1247 | 1237 |
1248 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 1238 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
1249 cc::AnimationEvent::Started, | 1239 cc::AnimationEvent::Started, |
1250 0, | 1240 0, |
1251 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 1241 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
1252 ->animation_group_id(), | 1242 ->animation_group_id(), |
1253 cc::Animation::Opacity, | 1243 cc::Animation::Opacity, |
1254 second_effective_start)); | 1244 second_effective_start)); |
1255 | 1245 |
1256 element->Step(second_effective_start + delta/2); | 1246 animator->Step(second_effective_start + delta / 2); |
1257 | 1247 |
1258 EXPECT_TRUE(test_controller.animator()->is_animating()); | 1248 EXPECT_TRUE(test_controller.animator()->is_animating()); |
1259 EXPECT_NEAR( | 1249 EXPECT_NEAR( |
1260 0.5, | 1250 0.5, |
1261 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> | 1251 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY)-> |
1262 last_progressed_fraction(), | 1252 last_progressed_fraction(), |
1263 epsilon); | 1253 epsilon); |
1264 EXPECT_NEAR(delegate.GetBrightnessForAnimation(), | 1254 EXPECT_NEAR(delegate.GetBrightnessForAnimation(), |
1265 0.5 * (start_brightness + middle_brightness), | 1255 0.5 * (start_brightness + middle_brightness), |
1266 epsilon); | 1256 epsilon); |
1267 | 1257 |
1268 element->Step(second_effective_start + delta); | 1258 animator->Step(second_effective_start + delta); |
1269 | 1259 |
1270 EXPECT_FALSE(test_controller.animator()->is_animating()); | 1260 EXPECT_FALSE(test_controller.animator()->is_animating()); |
1271 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 1261 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
1272 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 1262 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
1273 } | 1263 } |
1274 | 1264 |
1275 // Preempt by enqueuing the new animation. | 1265 // Preempt by enqueuing the new animation. |
1276 TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) { | 1266 TEST(LayerAnimatorTest, MultiPreemptEnqueueNewAnimation) { |
1277 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1267 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1278 AnimationContainerElement* element = animator.get(); | |
1279 animator->set_disable_timer_for_test(true); | 1268 animator->set_disable_timer_for_test(true); |
1280 TestLayerAnimationDelegate delegate; | 1269 TestLayerAnimationDelegate delegate; |
1281 animator->SetDelegate(&delegate); | 1270 animator->SetDelegate(&delegate); |
1282 | 1271 |
1283 double start_grayscale(0.0); | 1272 double start_grayscale(0.0); |
1284 double middle_grayscale(0.5); | 1273 double middle_grayscale(0.5); |
1285 double target_grayscale(1.0); | 1274 double target_grayscale(1.0); |
1286 | 1275 |
1287 double start_brightness(0.1); | 1276 double start_brightness(0.1); |
1288 double middle_brightness(0.2); | 1277 double middle_brightness(0.2); |
1289 double target_brightness(0.3); | 1278 double target_brightness(0.3); |
1290 | 1279 |
1291 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1280 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
1292 | 1281 |
1293 delegate.SetGrayscaleFromAnimation(start_grayscale); | 1282 delegate.SetGrayscaleFromAnimation(start_grayscale); |
1294 delegate.SetBrightnessFromAnimation(start_brightness); | 1283 delegate.SetBrightnessFromAnimation(start_brightness); |
1295 | 1284 |
1296 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); | 1285 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); |
1297 | 1286 |
1298 animator->StartTogether( | 1287 animator->StartTogether( |
1299 CreateMultiSequence( | 1288 CreateMultiSequence( |
1300 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, | 1289 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, |
1301 delta), | 1290 delta), |
1302 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 1291 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
1303 delta))); | 1292 delta))); |
1304 | 1293 |
1305 base::TimeTicks start_time = animator->last_step_time(); | 1294 base::TimeTicks start_time = animator->last_step_time(); |
1306 | 1295 |
1307 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 1296 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
1308 | 1297 |
1309 animator->StartTogether( | 1298 animator->StartTogether( |
1310 CreateMultiSequence( | 1299 CreateMultiSequence( |
1311 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), | 1300 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), |
1312 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 1301 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
1313 delta))); | 1302 delta))); |
1314 | 1303 |
1315 EXPECT_TRUE(animator->is_animating()); | 1304 EXPECT_TRUE(animator->is_animating()); |
1316 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); | 1305 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); |
1317 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 1306 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
1318 | 1307 |
1319 EXPECT_TRUE(animator->is_animating()); | 1308 EXPECT_TRUE(animator->is_animating()); |
1320 | 1309 |
1321 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1310 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1322 | 1311 |
1323 EXPECT_TRUE(animator->is_animating()); | 1312 EXPECT_TRUE(animator->is_animating()); |
1324 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); | 1313 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); |
1325 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 1314 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
1326 | 1315 |
1327 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 1316 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
1328 | 1317 |
1329 EXPECT_TRUE(animator->is_animating()); | 1318 EXPECT_TRUE(animator->is_animating()); |
1330 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); | 1319 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); |
1331 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 1320 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
1332 | 1321 |
1333 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 1322 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
1334 | 1323 |
1335 EXPECT_FALSE(animator->is_animating()); | 1324 EXPECT_FALSE(animator->is_animating()); |
1336 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 1325 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
1337 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 1326 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
1338 } | 1327 } |
1339 | 1328 |
1340 // Start an animation when there are sequences waiting in the queue. In this | 1329 // Start an animation when there are sequences waiting in the queue. In this |
1341 // case, all pending and running animations should be finished, and the new | 1330 // case, all pending and running animations should be finished, and the new |
1342 // animation started. | 1331 // animation started. |
1343 TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) { | 1332 TEST(LayerAnimatorTest, MultiPreemptByReplacingQueuedAnimations) { |
1344 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1333 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1345 AnimationContainerElement* element = animator.get(); | |
1346 animator->set_disable_timer_for_test(true); | 1334 animator->set_disable_timer_for_test(true); |
1347 TestLayerAnimationDelegate delegate; | 1335 TestLayerAnimationDelegate delegate; |
1348 animator->SetDelegate(&delegate); | 1336 animator->SetDelegate(&delegate); |
1349 | 1337 |
1350 double start_grayscale(0.0); | 1338 double start_grayscale(0.0); |
1351 double middle_grayscale(0.5); | 1339 double middle_grayscale(0.5); |
1352 double target_grayscale(1.0); | 1340 double target_grayscale(1.0); |
1353 | 1341 |
1354 double start_brightness(0.1); | 1342 double start_brightness(0.1); |
1355 double middle_brightness(0.2); | 1343 double middle_brightness(0.2); |
1356 double target_brightness(0.3); | 1344 double target_brightness(0.3); |
1357 | 1345 |
1358 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1346 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
1359 | 1347 |
1360 delegate.SetGrayscaleFromAnimation(start_grayscale); | 1348 delegate.SetGrayscaleFromAnimation(start_grayscale); |
1361 delegate.SetBrightnessFromAnimation(start_brightness); | 1349 delegate.SetBrightnessFromAnimation(start_brightness); |
1362 | 1350 |
1363 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 1351 animator->set_preemption_strategy(LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
1364 | 1352 |
1365 animator->StartTogether( | 1353 animator->StartTogether( |
1366 CreateMultiSequence( | 1354 CreateMultiSequence( |
1367 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, | 1355 LayerAnimationElement::CreateGrayscaleElement(target_grayscale, |
1368 delta), | 1356 delta), |
1369 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 1357 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
1370 delta))); | 1358 delta))); |
1371 | 1359 |
1372 base::TimeTicks start_time = animator->last_step_time(); | 1360 base::TimeTicks start_time = animator->last_step_time(); |
1373 | 1361 |
1374 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 1362 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
1375 | 1363 |
1376 animator->StartTogether( | 1364 animator->StartTogether( |
1377 CreateMultiSequence( | 1365 CreateMultiSequence( |
1378 LayerAnimationElement::CreateGrayscaleElement(middle_grayscale, | 1366 LayerAnimationElement::CreateGrayscaleElement(middle_grayscale, |
1379 delta), | 1367 delta), |
1380 LayerAnimationElement::CreateBrightnessElement(middle_brightness, | 1368 LayerAnimationElement::CreateBrightnessElement(middle_brightness, |
1381 delta))); | 1369 delta))); |
1382 | 1370 |
1383 // Queue should now have two animations. Starting a third should replace the | 1371 // Queue should now have two animations. Starting a third should replace the |
1384 // second. | 1372 // second. |
1385 animator->StartTogether( | 1373 animator->StartTogether( |
1386 CreateMultiSequence( | 1374 CreateMultiSequence( |
1387 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), | 1375 LayerAnimationElement::CreateGrayscaleElement(start_grayscale, delta), |
1388 LayerAnimationElement::CreateBrightnessElement(start_brightness, | 1376 LayerAnimationElement::CreateBrightnessElement(start_brightness, |
1389 delta))); | 1377 delta))); |
1390 | 1378 |
1391 EXPECT_TRUE(animator->is_animating()); | 1379 EXPECT_TRUE(animator->is_animating()); |
1392 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); | 1380 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); |
1393 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 1381 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
1394 | 1382 |
1395 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1383 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1396 | 1384 |
1397 EXPECT_TRUE(animator->is_animating()); | 1385 EXPECT_TRUE(animator->is_animating()); |
1398 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); | 1386 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), target_grayscale); |
1399 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 1387 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
1400 | 1388 |
1401 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 1389 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
1402 | 1390 |
1403 EXPECT_TRUE(animator->is_animating()); | 1391 EXPECT_TRUE(animator->is_animating()); |
1404 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); | 1392 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), middle_grayscale); |
1405 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); | 1393 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), middle_brightness); |
1406 | 1394 |
1407 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 1395 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
1408 | 1396 |
1409 EXPECT_FALSE(animator->is_animating()); | 1397 EXPECT_FALSE(animator->is_animating()); |
1410 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); | 1398 EXPECT_FLOAT_EQ(delegate.GetGrayscaleForAnimation(), start_grayscale); |
1411 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 1399 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
1412 } | 1400 } |
1413 //------------------------------------------------------- | 1401 //------------------------------------------------------- |
1414 // Test that non-threaded cyclic sequences continue to animate. | 1402 // Test that non-threaded cyclic sequences continue to animate. |
1415 TEST(LayerAnimatorTest, CyclicSequences) { | 1403 TEST(LayerAnimatorTest, CyclicSequences) { |
1416 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1404 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1417 AnimationContainerElement* element = animator.get(); | |
1418 animator->set_disable_timer_for_test(true); | 1405 animator->set_disable_timer_for_test(true); |
1419 TestLayerAnimationDelegate delegate; | 1406 TestLayerAnimationDelegate delegate; |
1420 animator->SetDelegate(&delegate); | 1407 animator->SetDelegate(&delegate); |
1421 | 1408 |
1422 double start_brightness(0.0); | 1409 double start_brightness(0.0); |
1423 double target_brightness(1.0); | 1410 double target_brightness(1.0); |
1424 | 1411 |
1425 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1412 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
1426 | 1413 |
1427 delegate.SetBrightnessFromAnimation(start_brightness); | 1414 delegate.SetBrightnessFromAnimation(start_brightness); |
1428 | 1415 |
1429 scoped_ptr<LayerAnimationSequence> sequence( | 1416 scoped_ptr<LayerAnimationSequence> sequence( |
1430 new LayerAnimationSequence( | 1417 new LayerAnimationSequence( |
1431 LayerAnimationElement::CreateBrightnessElement(target_brightness, | 1418 LayerAnimationElement::CreateBrightnessElement(target_brightness, |
1432 delta))); | 1419 delta))); |
1433 | 1420 |
1434 sequence->AddElement( | 1421 sequence->AddElement( |
1435 LayerAnimationElement::CreateBrightnessElement(start_brightness, delta)); | 1422 LayerAnimationElement::CreateBrightnessElement(start_brightness, delta)); |
1436 | 1423 |
1437 sequence->set_is_cyclic(true); | 1424 sequence->set_is_cyclic(true); |
1438 | 1425 |
1439 animator->StartAnimation(sequence.release()); | 1426 animator->StartAnimation(sequence.release()); |
1440 | 1427 |
1441 base::TimeTicks start_time = animator->last_step_time(); | 1428 base::TimeTicks start_time = animator->last_step_time(); |
1442 | 1429 |
1443 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1430 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1444 | 1431 |
1445 EXPECT_TRUE(animator->is_animating()); | 1432 EXPECT_TRUE(animator->is_animating()); |
1446 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 1433 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
1447 | 1434 |
1448 element->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); | 1435 animator->Step(start_time + base::TimeDelta::FromMilliseconds(2000)); |
1449 | 1436 |
1450 EXPECT_TRUE(animator->is_animating()); | 1437 EXPECT_TRUE(animator->is_animating()); |
1451 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 1438 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
1452 | 1439 |
1453 element->Step(start_time + base::TimeDelta::FromMilliseconds(3000)); | 1440 animator->Step(start_time + base::TimeDelta::FromMilliseconds(3000)); |
1454 | 1441 |
1455 EXPECT_TRUE(animator->is_animating()); | 1442 EXPECT_TRUE(animator->is_animating()); |
1456 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 1443 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
1457 | 1444 |
1458 // Skip ahead by a lot. | 1445 // Skip ahead by a lot. |
1459 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000000000)); | 1446 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000000000)); |
1460 | 1447 |
1461 EXPECT_TRUE(animator->is_animating()); | 1448 EXPECT_TRUE(animator->is_animating()); |
1462 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); | 1449 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), start_brightness); |
1463 | 1450 |
1464 // Skip ahead by a lot. | 1451 // Skip ahead by a lot. |
1465 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000001000)); | 1452 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000001000)); |
1466 | 1453 |
1467 EXPECT_TRUE(animator->is_animating()); | 1454 EXPECT_TRUE(animator->is_animating()); |
1468 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); | 1455 EXPECT_FLOAT_EQ(delegate.GetBrightnessForAnimation(), target_brightness); |
1469 | 1456 |
1470 animator->StopAnimatingProperty(LayerAnimationElement::BRIGHTNESS); | 1457 animator->StopAnimatingProperty(LayerAnimationElement::BRIGHTNESS); |
1471 | 1458 |
1472 EXPECT_FALSE(animator->is_animating()); | 1459 EXPECT_FALSE(animator->is_animating()); |
1473 } | 1460 } |
1474 | 1461 |
1475 // Test that threaded cyclic sequences continue to animate. | 1462 // Test that threaded cyclic sequences continue to animate. |
1476 TEST(LayerAnimatorTest, ThreadedCyclicSequences) { | 1463 TEST(LayerAnimatorTest, ThreadedCyclicSequences) { |
1477 LayerAnimatorTestController test_controller( | 1464 LayerAnimatorTestController test_controller( |
1478 LayerAnimator::CreateDefaultAnimator()); | 1465 LayerAnimator::CreateDefaultAnimator()); |
1479 AnimationContainerElement* element = test_controller.animator(); | 1466 LayerAnimator* animator = test_controller.animator(); |
1480 test_controller.animator()->set_disable_timer_for_test(true); | 1467 test_controller.animator()->set_disable_timer_for_test(true); |
1481 TestLayerAnimationDelegate delegate; | 1468 TestLayerAnimationDelegate delegate; |
1482 test_controller.animator()->SetDelegate(&delegate); | 1469 test_controller.animator()->SetDelegate(&delegate); |
1483 | 1470 |
1484 double start_opacity(0.0); | 1471 double start_opacity(0.0); |
1485 double target_opacity(1.0); | 1472 double target_opacity(1.0); |
1486 | 1473 |
1487 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1474 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
1488 | 1475 |
1489 delegate.SetOpacityFromAnimation(start_opacity); | 1476 delegate.SetOpacityFromAnimation(start_opacity); |
(...skipping 13 matching lines...) Expand all Loading... |
1503 base::TimeTicks effective_start = start_time + delta; | 1490 base::TimeTicks effective_start = start_time + delta; |
1504 | 1491 |
1505 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 1492 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
1506 cc::AnimationEvent::Started, | 1493 cc::AnimationEvent::Started, |
1507 0, | 1494 0, |
1508 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 1495 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
1509 ->animation_group_id(), | 1496 ->animation_group_id(), |
1510 cc::Animation::Opacity, | 1497 cc::Animation::Opacity, |
1511 effective_start)); | 1498 effective_start)); |
1512 | 1499 |
1513 element->Step(effective_start + delta); | 1500 animator->Step(effective_start + delta); |
1514 EXPECT_TRUE(test_controller.animator()->is_animating()); | 1501 EXPECT_TRUE(test_controller.animator()->is_animating()); |
1515 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 1502 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
1516 | 1503 |
1517 base::TimeTicks second_effective_start = effective_start + 2 * delta; | 1504 base::TimeTicks second_effective_start = effective_start + 2 * delta; |
1518 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 1505 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
1519 cc::AnimationEvent::Started, | 1506 cc::AnimationEvent::Started, |
1520 0, | 1507 0, |
1521 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 1508 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
1522 ->animation_group_id(), | 1509 ->animation_group_id(), |
1523 cc::Animation::Opacity, | 1510 cc::Animation::Opacity, |
1524 second_effective_start)); | 1511 second_effective_start)); |
1525 | 1512 |
1526 element->Step(second_effective_start + delta); | 1513 animator->Step(second_effective_start + delta); |
1527 | 1514 |
1528 EXPECT_TRUE(test_controller.animator()->is_animating()); | 1515 EXPECT_TRUE(test_controller.animator()->is_animating()); |
1529 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 1516 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
1530 | 1517 |
1531 base::TimeTicks third_effective_start = second_effective_start + 2 * delta; | 1518 base::TimeTicks third_effective_start = second_effective_start + 2 * delta; |
1532 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 1519 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
1533 cc::AnimationEvent::Started, | 1520 cc::AnimationEvent::Started, |
1534 0, | 1521 0, |
1535 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 1522 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
1536 ->animation_group_id(), | 1523 ->animation_group_id(), |
1537 cc::Animation::Opacity, | 1524 cc::Animation::Opacity, |
1538 third_effective_start)); | 1525 third_effective_start)); |
1539 | 1526 |
1540 element->Step(third_effective_start + delta); | 1527 animator->Step(third_effective_start + delta); |
1541 EXPECT_TRUE(test_controller.animator()->is_animating()); | 1528 EXPECT_TRUE(test_controller.animator()->is_animating()); |
1542 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 1529 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
1543 | 1530 |
1544 base::TimeTicks fourth_effective_start = third_effective_start + 2 * delta; | 1531 base::TimeTicks fourth_effective_start = third_effective_start + 2 * delta; |
1545 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 1532 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
1546 cc::AnimationEvent::Started, | 1533 cc::AnimationEvent::Started, |
1547 0, | 1534 0, |
1548 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 1535 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
1549 ->animation_group_id(), | 1536 ->animation_group_id(), |
1550 cc::Animation::Opacity, | 1537 cc::Animation::Opacity, |
1551 fourth_effective_start)); | 1538 fourth_effective_start)); |
1552 | 1539 |
1553 // Skip ahead by a lot. | 1540 // Skip ahead by a lot. |
1554 element->Step(fourth_effective_start + 1000 * delta); | 1541 animator->Step(fourth_effective_start + 1000 * delta); |
1555 | 1542 |
1556 EXPECT_TRUE(test_controller.animator()->is_animating()); | 1543 EXPECT_TRUE(test_controller.animator()->is_animating()); |
1557 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); | 1544 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), target_opacity); |
1558 | 1545 |
1559 base::TimeTicks fifth_effective_start = fourth_effective_start + 1001 * delta; | 1546 base::TimeTicks fifth_effective_start = fourth_effective_start + 1001 * delta; |
1560 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( | 1547 test_controller.animator()->OnThreadedAnimationStarted(cc::AnimationEvent( |
1561 cc::AnimationEvent::Started, | 1548 cc::AnimationEvent::Started, |
1562 0, | 1549 0, |
1563 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) | 1550 test_controller.GetRunningSequence(LayerAnimationElement::OPACITY) |
1564 ->animation_group_id(), | 1551 ->animation_group_id(), |
1565 cc::Animation::Opacity, | 1552 cc::Animation::Opacity, |
1566 fifth_effective_start)); | 1553 fifth_effective_start)); |
1567 | 1554 |
1568 // Skip ahead by a lot. | 1555 // Skip ahead by a lot. |
1569 element->Step(fifth_effective_start + 999 * delta); | 1556 animator->Step(fifth_effective_start + 999 * delta); |
1570 | 1557 |
1571 EXPECT_TRUE(test_controller.animator()->is_animating()); | 1558 EXPECT_TRUE(test_controller.animator()->is_animating()); |
1572 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); | 1559 EXPECT_FLOAT_EQ(delegate.GetOpacityForAnimation(), start_opacity); |
1573 | 1560 |
1574 test_controller.animator()->StopAnimatingProperty( | 1561 test_controller.animator()->StopAnimatingProperty( |
1575 LayerAnimationElement::OPACITY); | 1562 LayerAnimationElement::OPACITY); |
1576 | 1563 |
1577 EXPECT_FALSE(test_controller.animator()->is_animating()); | 1564 EXPECT_FALSE(test_controller.animator()->is_animating()); |
1578 } | 1565 } |
1579 | 1566 |
1580 TEST(LayerAnimatorTest, AddObserverExplicit) { | 1567 TEST(LayerAnimatorTest, AddObserverExplicit) { |
1581 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1568 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1582 AnimationContainerElement* element = animator.get(); | |
1583 animator->set_disable_timer_for_test(true); | 1569 animator->set_disable_timer_for_test(true); |
1584 TestLayerAnimationObserver observer; | 1570 TestLayerAnimationObserver observer; |
1585 TestLayerAnimationDelegate delegate; | 1571 TestLayerAnimationDelegate delegate; |
1586 animator->SetDelegate(&delegate); | 1572 animator->SetDelegate(&delegate); |
1587 animator->AddObserver(&observer); | 1573 animator->AddObserver(&observer); |
1588 observer.set_requires_notification_when_animator_destroyed(true); | 1574 observer.set_requires_notification_when_animator_destroyed(true); |
1589 | 1575 |
1590 EXPECT_TRUE(!observer.last_ended_sequence()); | 1576 EXPECT_TRUE(!observer.last_ended_sequence()); |
1591 | 1577 |
1592 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1578 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
1593 | 1579 |
1594 delegate.SetBrightnessFromAnimation(0.0f); | 1580 delegate.SetBrightnessFromAnimation(0.0f); |
1595 | 1581 |
1596 LayerAnimationSequence* sequence = new LayerAnimationSequence( | 1582 LayerAnimationSequence* sequence = new LayerAnimationSequence( |
1597 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); | 1583 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); |
1598 | 1584 |
1599 animator->StartAnimation(sequence); | 1585 animator->StartAnimation(sequence); |
1600 | 1586 |
1601 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); | 1587 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); |
1602 | 1588 |
1603 base::TimeTicks start_time = animator->last_step_time(); | 1589 base::TimeTicks start_time = animator->last_step_time(); |
1604 | 1590 |
1605 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1591 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1606 | 1592 |
1607 EXPECT_EQ(observer.last_ended_sequence(), sequence); | 1593 EXPECT_EQ(observer.last_ended_sequence(), sequence); |
1608 | 1594 |
1609 // |sequence| has been destroyed. Recreate it to test abort. | 1595 // |sequence| has been destroyed. Recreate it to test abort. |
1610 sequence = new LayerAnimationSequence( | 1596 sequence = new LayerAnimationSequence( |
1611 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); | 1597 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); |
1612 | 1598 |
1613 animator->StartAnimation(sequence); | 1599 animator->StartAnimation(sequence); |
1614 | 1600 |
1615 animator = NULL; | 1601 animator = NULL; |
1616 | 1602 |
1617 EXPECT_EQ(observer.last_aborted_sequence(), sequence); | 1603 EXPECT_EQ(observer.last_aborted_sequence(), sequence); |
1618 } | 1604 } |
1619 | 1605 |
1620 // Tests that an observer added to a scoped settings object is still notified | 1606 // Tests that an observer added to a scoped settings object is still notified |
1621 // when the object goes out of scope. | 1607 // when the object goes out of scope. |
1622 TEST(LayerAnimatorTest, ImplicitAnimationObservers) { | 1608 TEST(LayerAnimatorTest, ImplicitAnimationObservers) { |
1623 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1609 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1624 AnimationContainerElement* element = animator.get(); | |
1625 animator->set_disable_timer_for_test(true); | 1610 animator->set_disable_timer_for_test(true); |
1626 TestImplicitAnimationObserver observer(false); | 1611 TestImplicitAnimationObserver observer(false); |
1627 TestLayerAnimationDelegate delegate; | 1612 TestLayerAnimationDelegate delegate; |
1628 animator->SetDelegate(&delegate); | 1613 animator->SetDelegate(&delegate); |
1629 | 1614 |
1630 EXPECT_FALSE(observer.animations_completed()); | 1615 EXPECT_FALSE(observer.animations_completed()); |
1631 animator->SetBrightness(1.0f); | 1616 animator->SetBrightness(1.0f); |
1632 | 1617 |
1633 { | 1618 { |
1634 ScopedLayerAnimationSettings settings(animator.get()); | 1619 ScopedLayerAnimationSettings settings(animator.get()); |
1635 settings.AddObserver(&observer); | 1620 settings.AddObserver(&observer); |
1636 animator->SetBrightness(0.0f); | 1621 animator->SetBrightness(0.0f); |
1637 } | 1622 } |
1638 | 1623 |
1639 EXPECT_FALSE(observer.animations_completed()); | 1624 EXPECT_FALSE(observer.animations_completed()); |
1640 base::TimeTicks start_time = animator->last_step_time(); | 1625 base::TimeTicks start_time = animator->last_step_time(); |
1641 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1626 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1642 EXPECT_TRUE(observer.animations_completed()); | 1627 EXPECT_TRUE(observer.animations_completed()); |
1643 EXPECT_TRUE(observer.WasAnimationCompletedForProperty( | 1628 EXPECT_TRUE(observer.WasAnimationCompletedForProperty( |
1644 LayerAnimationElement::BRIGHTNESS)); | 1629 LayerAnimationElement::BRIGHTNESS)); |
1645 EXPECT_FLOAT_EQ(0.0f, delegate.GetBrightnessForAnimation()); | 1630 EXPECT_FLOAT_EQ(0.0f, delegate.GetBrightnessForAnimation()); |
1646 } | 1631 } |
1647 | 1632 |
1648 // Tests that an observer added to a scoped settings object is still notified | 1633 // Tests that an observer added to a scoped settings object is still notified |
1649 // when the object goes out of scope due to the animation being interrupted. | 1634 // when the object goes out of scope due to the animation being interrupted. |
1650 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) { | 1635 TEST(LayerAnimatorTest, InterruptedImplicitAnimationObservers) { |
1651 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1636 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
(...skipping 21 matching lines...) Expand all Loading... |
1673 EXPECT_FLOAT_EQ(1.0f, delegate.GetBrightnessForAnimation()); | 1658 EXPECT_FLOAT_EQ(1.0f, delegate.GetBrightnessForAnimation()); |
1674 } | 1659 } |
1675 | 1660 |
1676 // Tests that LayerAnimator is not deleted after the animation completes as long | 1661 // Tests that LayerAnimator is not deleted after the animation completes as long |
1677 // as there is a live ScopedLayerAnimationSettings object wrapped around it. | 1662 // as there is a live ScopedLayerAnimationSettings object wrapped around it. |
1678 TEST(LayerAnimatorTest, AnimatorKeptAliveBySettings) { | 1663 TEST(LayerAnimatorTest, AnimatorKeptAliveBySettings) { |
1679 // Note we are using a raw pointer unlike in other tests. | 1664 // Note we are using a raw pointer unlike in other tests. |
1680 TestLayerAnimator* animator = new TestLayerAnimator(); | 1665 TestLayerAnimator* animator = new TestLayerAnimator(); |
1681 LayerAnimatorDestructionObserver destruction_observer; | 1666 LayerAnimatorDestructionObserver destruction_observer; |
1682 animator->SetDestructionObserver(&destruction_observer); | 1667 animator->SetDestructionObserver(&destruction_observer); |
1683 AnimationContainerElement* element = animator; | |
1684 animator->set_disable_timer_for_test(true); | 1668 animator->set_disable_timer_for_test(true); |
1685 TestLayerAnimationDelegate delegate; | 1669 TestLayerAnimationDelegate delegate; |
1686 animator->SetDelegate(&delegate); | 1670 animator->SetDelegate(&delegate); |
1687 { | 1671 { |
1688 // ScopedLayerAnimationSettings should keep the Animator alive as long as | 1672 // ScopedLayerAnimationSettings should keep the Animator alive as long as |
1689 // it is alive, even beyond the end of the animation. | 1673 // it is alive, even beyond the end of the animation. |
1690 ScopedLayerAnimationSettings settings(animator); | 1674 ScopedLayerAnimationSettings settings(animator); |
1691 base::TimeTicks now = gfx::FrameTime::Now(); | 1675 base::TimeTicks now = gfx::FrameTime::Now(); |
1692 animator->SetBrightness(0.5); | 1676 animator->SetBrightness(0.5); |
1693 element->Step(now + base::TimeDelta::FromSeconds(1)); | 1677 animator->Step(now + base::TimeDelta::FromSeconds(1)); |
1694 EXPECT_FALSE(destruction_observer.IsAnimatorDeleted()); | 1678 EXPECT_FALSE(destruction_observer.IsAnimatorDeleted()); |
1695 } | 1679 } |
1696 // ScopedLayerAnimationSettings was destroyed, so Animator should be deleted. | 1680 // ScopedLayerAnimationSettings was destroyed, so Animator should be deleted. |
1697 EXPECT_TRUE(destruction_observer.IsAnimatorDeleted()); | 1681 EXPECT_TRUE(destruction_observer.IsAnimatorDeleted()); |
1698 } | 1682 } |
1699 | 1683 |
1700 // Tests that an observer added to a scoped settings object is not notified | 1684 // Tests that an observer added to a scoped settings object is not notified |
1701 // when the animator is destroyed unless explicitly requested. | 1685 // when the animator is destroyed unless explicitly requested. |
1702 TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) { | 1686 TEST(LayerAnimatorTest, ImplicitObserversAtAnimatorDestruction) { |
1703 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1687 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1763 animator->AbortAllAnimations(); | 1747 animator->AbortAllAnimations(); |
1764 EXPECT_TRUE(observer.animations_completed()); | 1748 EXPECT_TRUE(observer.animations_completed()); |
1765 EXPECT_TRUE(observer.WasAnimationAbortedForProperty( | 1749 EXPECT_TRUE(observer.WasAnimationAbortedForProperty( |
1766 LayerAnimationElement::BRIGHTNESS)); | 1750 LayerAnimationElement::BRIGHTNESS)); |
1767 EXPECT_TRUE(observer.WasAnimationAbortedForProperty( | 1751 EXPECT_TRUE(observer.WasAnimationAbortedForProperty( |
1768 LayerAnimationElement::OPACITY)); | 1752 LayerAnimationElement::OPACITY)); |
1769 } | 1753 } |
1770 | 1754 |
1771 TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) { | 1755 TEST(LayerAnimatorTest, RemoveObserverShouldRemoveFromSequences) { |
1772 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1756 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1773 AnimationContainerElement* element = animator.get(); | |
1774 animator->set_disable_timer_for_test(true); | 1757 animator->set_disable_timer_for_test(true); |
1775 TestLayerAnimationObserver observer; | 1758 TestLayerAnimationObserver observer; |
1776 TestLayerAnimationObserver removed_observer; | 1759 TestLayerAnimationObserver removed_observer; |
1777 TestLayerAnimationDelegate delegate; | 1760 TestLayerAnimationDelegate delegate; |
1778 animator->SetDelegate(&delegate); | 1761 animator->SetDelegate(&delegate); |
1779 | 1762 |
1780 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1763 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
1781 | 1764 |
1782 LayerAnimationSequence* sequence = new LayerAnimationSequence( | 1765 LayerAnimationSequence* sequence = new LayerAnimationSequence( |
1783 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); | 1766 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); |
1784 | 1767 |
1785 sequence->AddObserver(&observer); | 1768 sequence->AddObserver(&observer); |
1786 sequence->AddObserver(&removed_observer); | 1769 sequence->AddObserver(&removed_observer); |
1787 | 1770 |
1788 animator->StartAnimation(sequence); | 1771 animator->StartAnimation(sequence); |
1789 | 1772 |
1790 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); | 1773 EXPECT_EQ(observer.last_scheduled_sequence(), sequence); |
1791 EXPECT_TRUE(!observer.last_ended_sequence()); | 1774 EXPECT_TRUE(!observer.last_ended_sequence()); |
1792 EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence); | 1775 EXPECT_EQ(removed_observer.last_scheduled_sequence(), sequence); |
1793 EXPECT_TRUE(!removed_observer.last_ended_sequence()); | 1776 EXPECT_TRUE(!removed_observer.last_ended_sequence()); |
1794 | 1777 |
1795 // This should stop the observer from observing sequence. | 1778 // This should stop the observer from observing sequence. |
1796 animator->RemoveObserver(&removed_observer); | 1779 animator->RemoveObserver(&removed_observer); |
1797 | 1780 |
1798 base::TimeTicks start_time = animator->last_step_time(); | 1781 base::TimeTicks start_time = animator->last_step_time(); |
1799 | 1782 |
1800 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1783 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1801 | 1784 |
1802 EXPECT_EQ(observer.last_ended_sequence(), sequence); | 1785 EXPECT_EQ(observer.last_ended_sequence(), sequence); |
1803 EXPECT_TRUE(!removed_observer.last_ended_sequence()); | 1786 EXPECT_TRUE(!removed_observer.last_ended_sequence()); |
1804 } | 1787 } |
1805 | 1788 |
1806 TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) { | 1789 TEST(LayerAnimatorTest, ObserverReleasedBeforeAnimationSequenceEnds) { |
1807 TestLayerAnimationDelegate delegate; | 1790 TestLayerAnimationDelegate delegate; |
1808 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1791 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1809 animator->set_disable_timer_for_test(true); | 1792 animator->set_disable_timer_for_test(true); |
1810 | 1793 |
(...skipping 15 matching lines...) Expand all Loading... |
1826 | 1809 |
1827 // Now, release |observer| | 1810 // Now, release |observer| |
1828 observer.reset(); | 1811 observer.reset(); |
1829 | 1812 |
1830 // And |sequence| should no longer be attached to |observer|. | 1813 // And |sequence| should no longer be attached to |observer|. |
1831 EXPECT_FALSE(sequence->observers_.might_have_observers()); | 1814 EXPECT_FALSE(sequence->observers_.might_have_observers()); |
1832 } | 1815 } |
1833 | 1816 |
1834 TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) { | 1817 TEST(LayerAnimatorTest, ObserverAttachedAfterAnimationStarted) { |
1835 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1818 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1836 AnimationContainerElement* element = animator.get(); | |
1837 animator->set_disable_timer_for_test(true); | 1819 animator->set_disable_timer_for_test(true); |
1838 | 1820 |
1839 TestImplicitAnimationObserver observer(false); | 1821 TestImplicitAnimationObserver observer(false); |
1840 TestLayerAnimationDelegate delegate; | 1822 TestLayerAnimationDelegate delegate; |
1841 animator->SetDelegate(&delegate); | 1823 animator->SetDelegate(&delegate); |
1842 | 1824 |
1843 delegate.SetBrightnessFromAnimation(0.0f); | 1825 delegate.SetBrightnessFromAnimation(0.0f); |
1844 | 1826 |
1845 { | 1827 { |
1846 ScopedLayerAnimationSettings setter(animator.get()); | 1828 ScopedLayerAnimationSettings setter(animator.get()); |
1847 | 1829 |
1848 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1830 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
1849 LayerAnimationSequence* sequence = new LayerAnimationSequence( | 1831 LayerAnimationSequence* sequence = new LayerAnimationSequence( |
1850 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); | 1832 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); |
1851 | 1833 |
1852 animator->StartAnimation(sequence); | 1834 animator->StartAnimation(sequence); |
1853 base::TimeTicks start_time = animator->last_step_time(); | 1835 base::TimeTicks start_time = animator->last_step_time(); |
1854 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 1836 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
1855 | 1837 |
1856 setter.AddObserver(&observer); | 1838 setter.AddObserver(&observer); |
1857 | 1839 |
1858 // Start observing an in-flight animation. | 1840 // Start observing an in-flight animation. |
1859 sequence->AddObserver(&observer); | 1841 sequence->AddObserver(&observer); |
1860 | 1842 |
1861 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 1843 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
1862 } | 1844 } |
1863 | 1845 |
1864 EXPECT_TRUE(observer.animations_completed()); | 1846 EXPECT_TRUE(observer.animations_completed()); |
1865 EXPECT_TRUE(observer.WasAnimationCompletedForProperty( | 1847 EXPECT_TRUE(observer.WasAnimationCompletedForProperty( |
1866 LayerAnimationElement::BRIGHTNESS)); | 1848 LayerAnimationElement::BRIGHTNESS)); |
1867 } | 1849 } |
1868 | 1850 |
1869 TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) { | 1851 TEST(LayerAnimatorTest, ObserverDetachedBeforeAnimationFinished) { |
1870 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 1852 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
1871 AnimationContainerElement* element = animator.get(); | |
1872 animator->set_disable_timer_for_test(true); | 1853 animator->set_disable_timer_for_test(true); |
1873 | 1854 |
1874 TestImplicitAnimationObserver observer(false); | 1855 TestImplicitAnimationObserver observer(false); |
1875 TestLayerAnimationDelegate delegate; | 1856 TestLayerAnimationDelegate delegate; |
1876 animator->SetDelegate(&delegate); | 1857 animator->SetDelegate(&delegate); |
1877 | 1858 |
1878 delegate.SetBrightnessFromAnimation(0.0f); | 1859 delegate.SetBrightnessFromAnimation(0.0f); |
1879 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 1860 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
1880 LayerAnimationSequence* sequence = new LayerAnimationSequence( | 1861 LayerAnimationSequence* sequence = new LayerAnimationSequence( |
1881 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); | 1862 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); |
1882 | 1863 |
1883 { | 1864 { |
1884 ScopedLayerAnimationSettings setter(animator.get()); | 1865 ScopedLayerAnimationSettings setter(animator.get()); |
1885 setter.AddObserver(&observer); | 1866 setter.AddObserver(&observer); |
1886 | 1867 |
1887 animator->StartAnimation(sequence); | 1868 animator->StartAnimation(sequence); |
1888 base::TimeTicks start_time = animator->last_step_time(); | 1869 base::TimeTicks start_time = animator->last_step_time(); |
1889 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 1870 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
1890 } | 1871 } |
1891 | 1872 |
1892 EXPECT_FALSE(observer.animations_completed()); | 1873 EXPECT_FALSE(observer.animations_completed()); |
1893 | 1874 |
1894 // Stop observing an in-flight animation. | 1875 // Stop observing an in-flight animation. |
1895 sequence->RemoveObserver(&observer); | 1876 sequence->RemoveObserver(&observer); |
1896 | 1877 |
1897 EXPECT_TRUE(observer.animations_completed()); | 1878 EXPECT_TRUE(observer.animations_completed()); |
1898 | 1879 |
1899 // The animation didn't complete, and neither was it aborted. | 1880 // The animation didn't complete, and neither was it aborted. |
1900 EXPECT_FALSE(observer.WasAnimationCompletedForProperty( | 1881 EXPECT_FALSE(observer.WasAnimationCompletedForProperty( |
1901 LayerAnimationElement::BRIGHTNESS)); | 1882 LayerAnimationElement::BRIGHTNESS)); |
1902 EXPECT_FALSE(observer.WasAnimationAbortedForProperty( | 1883 EXPECT_FALSE(observer.WasAnimationAbortedForProperty( |
1903 LayerAnimationElement::BRIGHTNESS)); | 1884 LayerAnimationElement::BRIGHTNESS)); |
1904 } | 1885 } |
1905 | 1886 |
1906 // This checks that if an animation is deleted due to a callback, that the | 1887 // This checks that if an animation is deleted due to a callback, that the |
1907 // animator does not try to use the deleted animation. For example, if we have | 1888 // animator does not try to use the deleted animation. For example, if we have |
1908 // two running animations, and the first finishes and the resulting callback | 1889 // two running animations, and the first finishes and the resulting callback |
1909 // causes the second to be deleted, we should not attempt to animate the second | 1890 // causes the second to be deleted, we should not attempt to animate the second |
1910 // animation. | 1891 // animation. |
1911 TEST(LayerAnimatorTest, ObserverDeletesAnimationsOnEnd) { | 1892 TEST(LayerAnimatorTest, ObserverDeletesAnimationsOnEnd) { |
1912 ScopedAnimationDurationScaleMode normal_duration_mode( | 1893 ScopedAnimationDurationScaleMode normal_duration_mode( |
1913 ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 1894 ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
1914 scoped_refptr<LayerAnimator> animator(new TestLayerAnimator()); | 1895 scoped_refptr<LayerAnimator> animator(new TestLayerAnimator()); |
1915 AnimationContainerElement* element = animator.get(); | |
1916 animator->set_disable_timer_for_test(true); | 1896 animator->set_disable_timer_for_test(true); |
1917 TestLayerAnimationDelegate delegate; | 1897 TestLayerAnimationDelegate delegate; |
1918 animator->SetDelegate(&delegate); | 1898 animator->SetDelegate(&delegate); |
1919 | 1899 |
1920 double start_brightness(0.0); | 1900 double start_brightness(0.0); |
1921 double target_brightness(1.0); | 1901 double target_brightness(1.0); |
1922 | 1902 |
1923 gfx::Rect start_bounds(0, 0, 50, 50); | 1903 gfx::Rect start_bounds(0, 0, 50, 50); |
1924 gfx::Rect target_bounds(5, 5, 5, 5); | 1904 gfx::Rect target_bounds(5, 5, 5, 5); |
1925 | 1905 |
(...skipping 13 matching lines...) Expand all Loading... |
1939 new LayerAnimationSequence( | 1919 new LayerAnimationSequence( |
1940 LayerAnimationElement::CreateBrightnessElement( | 1920 LayerAnimationElement::CreateBrightnessElement( |
1941 target_brightness, brightness_delta))); | 1921 target_brightness, brightness_delta))); |
1942 | 1922 |
1943 animator->StartAnimation(new LayerAnimationSequence( | 1923 animator->StartAnimation(new LayerAnimationSequence( |
1944 LayerAnimationElement::CreateBoundsElement( | 1924 LayerAnimationElement::CreateBoundsElement( |
1945 target_bounds, bounds_delta))); | 1925 target_bounds, bounds_delta))); |
1946 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | 1926 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); |
1947 | 1927 |
1948 base::TimeTicks start_time = animator->last_step_time(); | 1928 base::TimeTicks start_time = animator->last_step_time(); |
1949 element->Step(start_time + halfway_delta); | 1929 animator->Step(start_time + halfway_delta); |
1950 | 1930 |
1951 // Completing the brightness animation should have stopped the bounds | 1931 // Completing the brightness animation should have stopped the bounds |
1952 // animation. | 1932 // animation. |
1953 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | 1933 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); |
1954 | 1934 |
1955 animator->RemoveObserver(observer.get()); | 1935 animator->RemoveObserver(observer.get()); |
1956 } | 1936 } |
1957 | 1937 |
1958 // Ensure that stopping animation in a bounds change does not crash and that | 1938 // Ensure that stopping animation in a bounds change does not crash and that |
1959 // animation gets stopped correctly. | 1939 // animation gets stopped correctly. |
(...skipping 15 matching lines...) Expand all Loading... |
1975 } | 1955 } |
1976 private: | 1956 private: |
1977 LayerAnimator* animator_; | 1957 LayerAnimator* animator_; |
1978 int max_width_; | 1958 int max_width_; |
1979 // Allow copy and assign. | 1959 // Allow copy and assign. |
1980 }; | 1960 }; |
1981 | 1961 |
1982 ScopedAnimationDurationScaleMode normal_duration_mode( | 1962 ScopedAnimationDurationScaleMode normal_duration_mode( |
1983 ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 1963 ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
1984 scoped_refptr<LayerAnimator> animator(new TestLayerAnimator()); | 1964 scoped_refptr<LayerAnimator> animator(new TestLayerAnimator()); |
1985 AnimationContainerElement* element = animator.get(); | |
1986 animator->set_disable_timer_for_test(true); | 1965 animator->set_disable_timer_for_test(true); |
1987 TestLayerAnimationDeletingDelegate delegate(animator.get(), 30); | 1966 TestLayerAnimationDeletingDelegate delegate(animator.get(), 30); |
1988 animator->SetDelegate(&delegate); | 1967 animator->SetDelegate(&delegate); |
1989 | 1968 |
1990 gfx::Rect start_bounds(0, 0, 0, 0); | 1969 gfx::Rect start_bounds(0, 0, 0, 0); |
1991 gfx::Rect target_bounds(5, 5, 50, 50); | 1970 gfx::Rect target_bounds(5, 5, 50, 50); |
1992 | 1971 |
1993 delegate.SetBoundsFromAnimation(start_bounds); | 1972 delegate.SetBoundsFromAnimation(start_bounds); |
1994 | 1973 |
1995 base::TimeDelta bounds_delta1 = base::TimeDelta::FromMilliseconds(333); | 1974 base::TimeDelta bounds_delta1 = base::TimeDelta::FromMilliseconds(333); |
1996 base::TimeDelta bounds_delta2 = base::TimeDelta::FromMilliseconds(666); | 1975 base::TimeDelta bounds_delta2 = base::TimeDelta::FromMilliseconds(666); |
1997 base::TimeDelta bounds_delta = base::TimeDelta::FromMilliseconds(1000); | 1976 base::TimeDelta bounds_delta = base::TimeDelta::FromMilliseconds(1000); |
1998 base::TimeDelta final_delta = base::TimeDelta::FromMilliseconds(1500); | 1977 base::TimeDelta final_delta = base::TimeDelta::FromMilliseconds(1500); |
1999 | 1978 |
2000 animator->StartAnimation(new LayerAnimationSequence( | 1979 animator->StartAnimation(new LayerAnimationSequence( |
2001 LayerAnimationElement::CreateBoundsElement( | 1980 LayerAnimationElement::CreateBoundsElement( |
2002 target_bounds, bounds_delta))); | 1981 target_bounds, bounds_delta))); |
2003 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | 1982 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); |
2004 | 1983 |
2005 base::TimeTicks start_time = animator->last_step_time(); | 1984 base::TimeTicks start_time = animator->last_step_time(); |
2006 ASSERT_NO_FATAL_FAILURE(element->Step(start_time + bounds_delta1)); | 1985 ASSERT_NO_FATAL_FAILURE(animator->Step(start_time + bounds_delta1)); |
2007 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | 1986 ASSERT_TRUE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); |
2008 | 1987 |
2009 // The next step should change the animated bounds past the threshold and | 1988 // The next step should change the animated bounds past the threshold and |
2010 // cause the animaton to stop. | 1989 // cause the animaton to stop. |
2011 ASSERT_NO_FATAL_FAILURE(element->Step(start_time + bounds_delta2)); | 1990 ASSERT_NO_FATAL_FAILURE(animator->Step(start_time + bounds_delta2)); |
2012 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | 1991 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); |
2013 ASSERT_NO_FATAL_FAILURE(element->Step(start_time + final_delta)); | 1992 ASSERT_NO_FATAL_FAILURE(animator->Step(start_time + final_delta)); |
2014 | 1993 |
2015 // Completing the animation should have stopped the bounds | 1994 // Completing the animation should have stopped the bounds |
2016 // animation. | 1995 // animation. |
2017 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); | 1996 ASSERT_FALSE(animator->IsAnimatingProperty(LayerAnimationElement::BOUNDS)); |
2018 } | 1997 } |
2019 | 1998 |
2020 // Similar to the ObserverDeletesAnimationsOnEnd test above except that it | 1999 // Similar to the ObserverDeletesAnimationsOnEnd test above except that it |
2021 // tests the behavior when the OnLayerAnimationAborted() callback causes | 2000 // tests the behavior when the OnLayerAnimationAborted() callback causes |
2022 // all of the animator's other animations to be deleted. | 2001 // all of the animator's other animations to be deleted. |
2023 TEST(LayerAnimatorTest, ObserverDeletesAnimationsOnAbort) { | 2002 TEST(LayerAnimatorTest, ObserverDeletesAnimationsOnAbort) { |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2193 | 2172 |
2194 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1. | 2173 // Because the strategy is ENQUEUE_NEW_ANIMATION the target should now be 1. |
2195 animator->SetGrayscale(1.0); | 2174 animator->SetGrayscale(1.0); |
2196 EXPECT_EQ(1.0, animator->GetTargetGrayscale()); | 2175 EXPECT_EQ(1.0, animator->GetTargetGrayscale()); |
2197 } | 2176 } |
2198 } | 2177 } |
2199 | 2178 |
2200 // Verifies color property is modified appropriately. | 2179 // Verifies color property is modified appropriately. |
2201 TEST(LayerAnimatorTest, Color) { | 2180 TEST(LayerAnimatorTest, Color) { |
2202 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 2181 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
2203 AnimationContainerElement* element = animator.get(); | |
2204 animator->set_disable_timer_for_test(true); | 2182 animator->set_disable_timer_for_test(true); |
2205 TestLayerAnimationDelegate delegate; | 2183 TestLayerAnimationDelegate delegate; |
2206 animator->SetDelegate(&delegate); | 2184 animator->SetDelegate(&delegate); |
2207 | 2185 |
2208 SkColor start_color = SkColorSetARGB( 64, 20, 40, 60); | 2186 SkColor start_color = SkColorSetARGB( 64, 20, 40, 60); |
2209 SkColor middle_color = SkColorSetARGB(128, 35, 70, 120); | 2187 SkColor middle_color = SkColorSetARGB(128, 35, 70, 120); |
2210 SkColor target_color = SkColorSetARGB(192, 40, 80, 140); | 2188 SkColor target_color = SkColorSetARGB(192, 40, 80, 140); |
2211 | 2189 |
2212 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 2190 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
2213 | 2191 |
2214 delegate.SetColorFromAnimation(start_color); | 2192 delegate.SetColorFromAnimation(start_color); |
2215 | 2193 |
2216 animator->ScheduleAnimation( | 2194 animator->ScheduleAnimation( |
2217 new LayerAnimationSequence( | 2195 new LayerAnimationSequence( |
2218 LayerAnimationElement::CreateColorElement(target_color, delta))); | 2196 LayerAnimationElement::CreateColorElement(target_color, delta))); |
2219 | 2197 |
2220 EXPECT_TRUE(animator->is_animating()); | 2198 EXPECT_TRUE(animator->is_animating()); |
2221 EXPECT_EQ(ColorToString(start_color), | 2199 EXPECT_EQ(ColorToString(start_color), |
2222 ColorToString(delegate.GetColorForAnimation())); | 2200 ColorToString(delegate.GetColorForAnimation())); |
2223 | 2201 |
2224 base::TimeTicks start_time = animator->last_step_time(); | 2202 base::TimeTicks start_time = animator->last_step_time(); |
2225 | 2203 |
2226 element->Step(start_time + base::TimeDelta::FromMilliseconds(500)); | 2204 animator->Step(start_time + base::TimeDelta::FromMilliseconds(500)); |
2227 | 2205 |
2228 EXPECT_TRUE(animator->is_animating()); | 2206 EXPECT_TRUE(animator->is_animating()); |
2229 EXPECT_EQ(ColorToString(middle_color), | 2207 EXPECT_EQ(ColorToString(middle_color), |
2230 ColorToString(delegate.GetColorForAnimation())); | 2208 ColorToString(delegate.GetColorForAnimation())); |
2231 | 2209 |
2232 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 2210 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
2233 | 2211 |
2234 EXPECT_FALSE(animator->is_animating()); | 2212 EXPECT_FALSE(animator->is_animating()); |
2235 EXPECT_EQ(ColorToString(target_color), | 2213 EXPECT_EQ(ColorToString(target_color), |
2236 ColorToString(delegate.GetColorForAnimation())); | 2214 ColorToString(delegate.GetColorForAnimation())); |
2237 } | 2215 } |
2238 | 2216 |
2239 // Verifies SchedulePauseForProperties(). | 2217 // Verifies SchedulePauseForProperties(). |
2240 TEST(LayerAnimatorTest, SchedulePauseForProperties) { | 2218 TEST(LayerAnimatorTest, SchedulePauseForProperties) { |
2241 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); | 2219 scoped_refptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator()); |
2242 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); | 2220 animator->set_preemption_strategy(LayerAnimator::ENQUEUE_NEW_ANIMATION); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2330 | 2308 |
2331 DISALLOW_COPY_AND_ASSIGN(DeletingObserver); | 2309 DISALLOW_COPY_AND_ASSIGN(DeletingObserver); |
2332 }; | 2310 }; |
2333 | 2311 |
2334 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterFinishingAnimation) { | 2312 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterFinishingAnimation) { |
2335 bool observer_was_deleted = false; | 2313 bool observer_was_deleted = false; |
2336 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); | 2314 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); |
2337 observer->set_delete_on_animation_ended(true); | 2315 observer->set_delete_on_animation_ended(true); |
2338 observer->set_delete_on_animation_aborted(true); | 2316 observer->set_delete_on_animation_aborted(true); |
2339 LayerAnimator* animator = observer->animator(); | 2317 LayerAnimator* animator = observer->animator(); |
2340 AnimationContainerElement* element = observer->animator(); | |
2341 animator->set_disable_timer_for_test(true); | 2318 animator->set_disable_timer_for_test(true); |
2342 TestLayerAnimationDelegate delegate; | 2319 TestLayerAnimationDelegate delegate; |
2343 animator->SetDelegate(&delegate); | 2320 animator->SetDelegate(&delegate); |
2344 | 2321 |
2345 delegate.SetBrightnessFromAnimation(0.0f); | 2322 delegate.SetBrightnessFromAnimation(0.0f); |
2346 | 2323 |
2347 gfx::Rect start_bounds(0, 0, 50, 50); | 2324 gfx::Rect start_bounds(0, 0, 50, 50); |
2348 gfx::Rect target_bounds(10, 10, 100, 100); | 2325 gfx::Rect target_bounds(10, 10, 100, 100); |
2349 | 2326 |
2350 delegate.SetBoundsFromAnimation(start_bounds); | 2327 delegate.SetBoundsFromAnimation(start_bounds); |
2351 | 2328 |
2352 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); | 2329 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); |
2353 LayerAnimationSequence* brightness_sequence = new LayerAnimationSequence( | 2330 LayerAnimationSequence* brightness_sequence = new LayerAnimationSequence( |
2354 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); | 2331 LayerAnimationElement::CreateBrightnessElement(1.0f, delta)); |
2355 animator->StartAnimation(brightness_sequence); | 2332 animator->StartAnimation(brightness_sequence); |
2356 | 2333 |
2357 delta = base::TimeDelta::FromSeconds(2); | 2334 delta = base::TimeDelta::FromSeconds(2); |
2358 LayerAnimationSequence* bounds_sequence = new LayerAnimationSequence( | 2335 LayerAnimationSequence* bounds_sequence = new LayerAnimationSequence( |
2359 LayerAnimationElement::CreateBoundsElement(target_bounds, delta)); | 2336 LayerAnimationElement::CreateBoundsElement(target_bounds, delta)); |
2360 animator->StartAnimation(bounds_sequence); | 2337 animator->StartAnimation(bounds_sequence); |
2361 | 2338 |
2362 base::TimeTicks start_time = animator->last_step_time(); | 2339 base::TimeTicks start_time = animator->last_step_time(); |
2363 element->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); | 2340 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1500)); |
2364 | 2341 |
2365 EXPECT_TRUE(observer_was_deleted); | 2342 EXPECT_TRUE(observer_was_deleted); |
2366 } | 2343 } |
2367 | 2344 |
2368 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterStoppingAnimating) { | 2345 TEST(LayerAnimatorTest, ObserverDeletesAnimatorAfterStoppingAnimating) { |
2369 bool observer_was_deleted = false; | 2346 bool observer_was_deleted = false; |
2370 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); | 2347 DeletingObserver* observer = new DeletingObserver(&observer_was_deleted); |
2371 observer->set_delete_on_animation_ended(true); | 2348 observer->set_delete_on_animation_ended(true); |
2372 observer->set_delete_on_animation_aborted(true); | 2349 observer->set_delete_on_animation_aborted(true); |
2373 LayerAnimator* animator = observer->animator(); | 2350 LayerAnimator* animator = observer->animator(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2518 settings.AddInverselyAnimatedLayer(&child); | 2495 settings.AddInverselyAnimatedLayer(&child); |
2519 | 2496 |
2520 parent.SetTransform(parent_end); | 2497 parent.SetTransform(parent_end); |
2521 | 2498 |
2522 EXPECT_TRUE(child.GetAnimator()->is_animating()); | 2499 EXPECT_TRUE(child.GetAnimator()->is_animating()); |
2523 EXPECT_TRUE(child.GetTargetTransform().IsIdentity()) | 2500 EXPECT_TRUE(child.GetTargetTransform().IsIdentity()) |
2524 << child.GetTargetTransform().ToString(); | 2501 << child.GetTargetTransform().ToString(); |
2525 | 2502 |
2526 } | 2503 } |
2527 | 2504 |
| 2505 class CollectionLayerAnimationDelegate : public TestLayerAnimationDelegate { |
| 2506 public: |
| 2507 CollectionLayerAnimationDelegate() : collection(NULL) {} |
| 2508 virtual ~CollectionLayerAnimationDelegate() {} |
| 2509 |
| 2510 // LayerAnimationDelegate: |
| 2511 virtual LayerAnimatorCollection* GetLayerAnimatorCollection() OVERRIDE { |
| 2512 return &collection; |
| 2513 } |
| 2514 |
| 2515 private: |
| 2516 LayerAnimatorCollection collection; |
| 2517 }; |
| 2518 |
| 2519 TEST(LayerAnimatorTest, LayerAnimatorCollectionTickTime) { |
| 2520 Layer layer; |
| 2521 LayerAnimator* animator = layer.GetAnimator(); |
| 2522 CollectionLayerAnimationDelegate delegate; |
| 2523 animator->SetDelegate(&delegate); |
| 2524 |
| 2525 LayerAnimatorCollection* collection = delegate.GetLayerAnimatorCollection(); |
| 2526 base::TimeTicks null; |
| 2527 collection->Progress(null); |
| 2528 EXPECT_TRUE(collection->last_tick_time().is_null()); |
| 2529 |
| 2530 // Adding an animator to the collection should update the last tick time. |
| 2531 collection->StartAnimator(layer.GetAnimator()); |
| 2532 EXPECT_TRUE(collection->HasActiveAnimators()); |
| 2533 EXPECT_FALSE(collection->last_tick_time().is_null()); |
| 2534 |
| 2535 collection->StopAnimator(layer.GetAnimator()); |
| 2536 EXPECT_FALSE(collection->HasActiveAnimators()); |
| 2537 } |
| 2538 |
| 2539 TEST(LayerAnimatorTest, AnimatorStartedCorrectly) { |
| 2540 Layer layer; |
| 2541 LayerAnimatorTestController test_controller(layer.GetAnimator()); |
| 2542 LayerAnimator* animator = test_controller.animator(); |
| 2543 ASSERT_FALSE(animator->is_started_); |
| 2544 |
| 2545 TestLayerAnimationDelegate test_delegate; |
| 2546 animator->SetDelegate(&test_delegate); |
| 2547 double target_opacity = 1.0; |
| 2548 base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1); |
| 2549 animator->ScheduleAnimation(new LayerAnimationSequence( |
| 2550 LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta))); |
| 2551 EXPECT_FALSE(animator->is_started_); |
| 2552 |
| 2553 CollectionLayerAnimationDelegate collection_delegate; |
| 2554 animator->SetDelegate(&collection_delegate); |
| 2555 animator->UpdateAnimationState(); |
| 2556 EXPECT_TRUE(animator->is_started_); |
| 2557 animator->SetDelegate(NULL); |
| 2558 } |
| 2559 |
| 2560 TEST(LayerAnimatorTest, AnimatorRemovedFromCollectionWhenLayerIsDestroyed) { |
| 2561 scoped_ptr<Layer> layer(new Layer(LAYER_TEXTURED)); |
| 2562 LayerAnimatorTestController test_controller(layer->GetAnimator()); |
| 2563 scoped_refptr<LayerAnimator> animator = test_controller.animator(); |
| 2564 CollectionLayerAnimationDelegate collection_delegate; |
| 2565 animator->SetDelegate(&collection_delegate); |
| 2566 |
| 2567 double target_opacity = 1.0; |
| 2568 base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1); |
| 2569 animator->ScheduleAnimation(new LayerAnimationSequence( |
| 2570 LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta))); |
| 2571 |
| 2572 EXPECT_TRUE( |
| 2573 collection_delegate.GetLayerAnimatorCollection()->HasActiveAnimators()); |
| 2574 |
| 2575 layer.reset(); |
| 2576 EXPECT_EQ(NULL, animator->delegate()); |
| 2577 EXPECT_FALSE( |
| 2578 collection_delegate.GetLayerAnimatorCollection()->HasActiveAnimators()); |
| 2579 } |
| 2580 |
| 2581 TEST(LayerAnimatorTest, LayerMovedBetweenCompositorsDuringAnimation) { |
| 2582 bool enable_pixel_output = false; |
| 2583 ui::ContextFactory* context_factory = |
| 2584 InitializeContextFactoryForTests(enable_pixel_output); |
| 2585 const gfx::Rect bounds(10, 10, 100, 100); |
| 2586 scoped_ptr<TestCompositorHost> host_1( |
| 2587 TestCompositorHost::Create(bounds, context_factory)); |
| 2588 scoped_ptr<TestCompositorHost> host_2( |
| 2589 TestCompositorHost::Create(bounds, context_factory)); |
| 2590 host_1->Show(); |
| 2591 host_2->Show(); |
| 2592 |
| 2593 Compositor* compositor_1 = host_1->GetCompositor(); |
| 2594 Layer root_1; |
| 2595 compositor_1->SetRootLayer(&root_1); |
| 2596 |
| 2597 Compositor* compositor_2 = host_2->GetCompositor(); |
| 2598 Layer root_2; |
| 2599 compositor_2->SetRootLayer(&root_2); |
| 2600 |
| 2601 // Verify that neither compositor has active animators. |
| 2602 EXPECT_FALSE(compositor_1->layer_animator_collection()->HasActiveAnimators()); |
| 2603 EXPECT_FALSE(compositor_2->layer_animator_collection()->HasActiveAnimators()); |
| 2604 |
| 2605 Layer layer; |
| 2606 root_1.Add(&layer); |
| 2607 LayerAnimator* animator = layer.GetAnimator(); |
| 2608 double target_opacity = 1.0; |
| 2609 base::TimeDelta time_delta = base::TimeDelta::FromSeconds(1); |
| 2610 animator->ScheduleAnimation(new LayerAnimationSequence( |
| 2611 LayerAnimationElement::CreateOpacityElement(target_opacity, time_delta))); |
| 2612 EXPECT_TRUE(compositor_1->layer_animator_collection()->HasActiveAnimators()); |
| 2613 EXPECT_FALSE(compositor_2->layer_animator_collection()->HasActiveAnimators()); |
| 2614 |
| 2615 root_2.Add(&layer); |
| 2616 EXPECT_FALSE(compositor_1->layer_animator_collection()->HasActiveAnimators()); |
| 2617 EXPECT_TRUE(compositor_2->layer_animator_collection()->HasActiveAnimators()); |
| 2618 host_2.reset(); |
| 2619 host_1.reset(); |
| 2620 TerminateContextFactoryForTests(); |
| 2621 } |
| 2622 |
2528 } // namespace ui | 2623 } // namespace ui |
OLD | NEW |