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