OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/animation/layer_animation_controller.h" | 5 #include "cc/animation/layer_animation_controller.h" |
6 | 6 |
7 #include "cc/animation/animation.h" | 7 #include "cc/animation/animation.h" |
8 #include "cc/animation/animation_curve.h" | 8 #include "cc/animation/animation_curve.h" |
9 #include "cc/animation/animation_delegate.h" | 9 #include "cc/animation/animation_delegate.h" |
10 #include "cc/animation/animation_registrar.h" | 10 #include "cc/animation/animation_registrar.h" |
11 #include "cc/animation/keyframed_animation_curve.h" | 11 #include "cc/animation/keyframed_animation_curve.h" |
12 #include "cc/animation/scroll_offset_animation_curve.h" | |
12 #include "cc/animation/transform_operations.h" | 13 #include "cc/animation/transform_operations.h" |
13 #include "cc/test/animation_test_common.h" | 14 #include "cc/test/animation_test_common.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "ui/gfx/box_f.h" | 17 #include "ui/gfx/box_f.h" |
17 #include "ui/gfx/transform.h" | 18 #include "ui/gfx/transform.h" |
18 | 19 |
19 namespace cc { | 20 namespace cc { |
20 namespace { | 21 namespace { |
21 | 22 |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 EXPECT_EQ(end_filters, dummy_impl.filters()); | 545 EXPECT_EQ(end_filters, dummy_impl.filters()); |
545 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | 546 EXPECT_FALSE(controller_impl->HasActiveAnimation()); |
546 EXPECT_EQ(4u, events->size()); | 547 EXPECT_EQ(4u, events->size()); |
547 const AnimationEvent* end_filter_event = | 548 const AnimationEvent* end_filter_event = |
548 GetMostRecentPropertyUpdateEvent(events.get()); | 549 GetMostRecentPropertyUpdateEvent(events.get()); |
549 EXPECT_TRUE(end_filter_event); | 550 EXPECT_TRUE(end_filter_event); |
550 EXPECT_EQ(end_filters, end_filter_event->filters); | 551 EXPECT_EQ(end_filters, end_filter_event->filters); |
551 EXPECT_TRUE(end_filter_event->is_impl_only); | 552 EXPECT_TRUE(end_filter_event->is_impl_only); |
552 } | 553 } |
553 | 554 |
555 TEST(LayerAnimationControllerTest, ScrollOffsetTransition) { | |
556 FakeLayerAnimationValueObserver dummy_impl; | |
557 FakeLayerAnimationValueProvider dummy_provider_impl; | |
558 scoped_refptr<LayerAnimationController> controller_impl( | |
559 LayerAnimationController::Create(0)); | |
560 controller_impl->AddValueObserver(&dummy_impl); | |
561 controller_impl->set_value_provider(&dummy_provider_impl); | |
562 scoped_ptr<AnimationEventsVector> events( | |
563 make_scoped_ptr(new AnimationEventsVector)); | |
564 FakeLayerAnimationValueObserver dummy; | |
565 FakeLayerAnimationValueProvider dummy_provider; | |
566 scoped_refptr<LayerAnimationController> controller( | |
567 LayerAnimationController::Create(0)); | |
568 controller->AddValueObserver(&dummy); | |
569 controller->set_value_provider(&dummy_provider); | |
570 | |
571 gfx::Vector2dF initial_value(100.f, 300.f); | |
572 gfx::Vector2dF target_value(300.f, 200.f); | |
573 scoped_ptr<ScrollOffsetAnimationCurve> curve( | |
574 ScrollOffsetAnimationCurve::Create( | |
575 target_value, | |
576 EaseInOutTimingFunction::Create().Pass())); | |
577 | |
578 scoped_ptr<Animation> animation(Animation::Create( | |
579 curve.PassAs<AnimationCurve>(), 1, 0, Animation::ScrollOffset)); | |
580 animation->set_needs_synchronized_start_time(true); | |
581 controller->AddAnimation(animation.Pass()); | |
582 | |
583 dummy_provider_impl.set_scroll_offset(initial_value); | |
584 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
585 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset)); | |
586 double duration = controller_impl->GetAnimation( | |
587 Animation::ScrollOffset)->curve()->Duration(); | |
588 | |
589 EXPECT_EQ( | |
590 duration, | |
591 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration()); | |
592 | |
593 controller->Animate(0.0); | |
594 controller->UpdateState(true, NULL); | |
Ian Vollick
2013/11/29 15:29:29
Should we check that we get no events here?
ajuma
2013/11/29 21:18:41
Note that we're passing NULL as the events argumen
Ian Vollick
2013/12/02 21:23:32
Ah, right -- main thread! Sorry.
| |
595 EXPECT_TRUE(controller->HasActiveAnimation()); | |
596 EXPECT_EQ(initial_value, dummy.scroll_offset()); | |
597 | |
598 controller_impl->Animate(1.0); | |
599 controller_impl->UpdateState(true, events.get()); | |
600 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | |
601 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | |
602 // Scroll offset animations should not generate property updates. | |
603 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | |
604 EXPECT_FALSE(event); | |
605 | |
606 controller->NotifyAnimationStarted((*events)[0], 0.0); | |
607 controller->Animate(1.0 + duration/2.0); | |
Ian Vollick
2013/11/29 15:29:29
This (1.0 + duration/2.0) and (1.0 + duration) stu
ajuma
2013/11/29 21:18:41
The issue is that LayerAnimationController::Promot
Ian Vollick
2013/12/02 21:23:32
I think this is fine for this CL, but yes, it woul
ajuma
2013/12/02 21:48:57
Sgtm. For this CL, I've replaced the "1.0+" with "
| |
608 controller->UpdateState(true, NULL); | |
609 EXPECT_TRUE(controller->HasActiveAnimation()); | |
610 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), dummy.scroll_offset()); | |
611 | |
612 controller_impl->Animate(1.0 + duration/2.0); | |
613 controller_impl->UpdateState(true, events.get()); | |
614 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), | |
615 dummy_impl.scroll_offset()); | |
616 event = GetMostRecentPropertyUpdateEvent(events.get()); | |
617 EXPECT_FALSE(event); | |
618 | |
619 controller_impl->Animate(1.0 + duration); | |
620 controller_impl->UpdateState(true, events.get()); | |
621 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); | |
622 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | |
623 event = GetMostRecentPropertyUpdateEvent(events.get()); | |
624 EXPECT_FALSE(event); | |
625 | |
626 controller->Animate(1.0 + duration); | |
627 controller->UpdateState(true, NULL); | |
628 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); | |
629 EXPECT_FALSE(controller->HasActiveAnimation()); | |
630 } | |
631 | |
632 // Ensure that when the impl controller doesn't have a value provider, | |
633 // the main-thread controller's value provider is used to obtain the intial | |
634 // scroll offset. | |
635 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionNoImplProvider) { | |
636 FakeLayerAnimationValueObserver dummy_impl; | |
637 scoped_refptr<LayerAnimationController> controller_impl( | |
638 LayerAnimationController::Create(0)); | |
639 controller_impl->AddValueObserver(&dummy_impl); | |
640 scoped_ptr<AnimationEventsVector> events( | |
641 make_scoped_ptr(new AnimationEventsVector)); | |
642 FakeLayerAnimationValueObserver dummy; | |
643 FakeLayerAnimationValueProvider dummy_provider; | |
644 scoped_refptr<LayerAnimationController> controller( | |
645 LayerAnimationController::Create(0)); | |
646 controller->AddValueObserver(&dummy); | |
647 controller->set_value_provider(&dummy_provider); | |
648 | |
649 gfx::Vector2dF initial_value(500.f, 100.f); | |
650 gfx::Vector2dF target_value(300.f, 200.f); | |
651 scoped_ptr<ScrollOffsetAnimationCurve> curve( | |
652 ScrollOffsetAnimationCurve::Create( | |
653 target_value, | |
654 EaseInOutTimingFunction::Create().Pass())); | |
655 | |
656 scoped_ptr<Animation> animation(Animation::Create( | |
657 curve.PassAs<AnimationCurve>(), 1, 0, Animation::ScrollOffset)); | |
658 animation->set_needs_synchronized_start_time(true); | |
659 controller->AddAnimation(animation.Pass()); | |
660 | |
661 dummy_provider.set_scroll_offset(initial_value); | |
662 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
663 EXPECT_TRUE(controller_impl->GetAnimation(Animation::ScrollOffset)); | |
664 double duration = controller_impl->GetAnimation( | |
665 Animation::ScrollOffset)->curve()->Duration(); | |
666 | |
667 EXPECT_EQ( | |
668 duration, | |
669 controller->GetAnimation(Animation::ScrollOffset)->curve()->Duration()); | |
670 | |
671 controller->Animate(0.0); | |
672 controller->UpdateState(true, NULL); | |
673 EXPECT_TRUE(controller->HasActiveAnimation()); | |
674 EXPECT_EQ(initial_value, dummy.scroll_offset()); | |
675 | |
676 controller_impl->Animate(1.0); | |
677 controller_impl->UpdateState(true, events.get()); | |
678 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | |
679 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | |
680 // Scroll offset animations should not generate property updates. | |
681 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | |
682 EXPECT_FALSE(event); | |
683 | |
684 controller->NotifyAnimationStarted((*events)[0], 0.0); | |
685 controller->Animate(1.0 + duration/2.0); | |
686 controller->UpdateState(true, NULL); | |
687 EXPECT_TRUE(controller->HasActiveAnimation()); | |
688 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), dummy.scroll_offset()); | |
689 | |
690 controller_impl->Animate(1.0 + duration/2.0); | |
691 controller_impl->UpdateState(true, events.get()); | |
692 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(400.f, 150.f), | |
693 dummy_impl.scroll_offset()); | |
694 event = GetMostRecentPropertyUpdateEvent(events.get()); | |
695 EXPECT_FALSE(event); | |
696 | |
697 controller_impl->Animate(1.0 + duration); | |
698 controller_impl->UpdateState(true, events.get()); | |
699 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); | |
700 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | |
701 event = GetMostRecentPropertyUpdateEvent(events.get()); | |
702 EXPECT_FALSE(event); | |
703 | |
704 controller->Animate(1.0 + duration); | |
705 controller->UpdateState(true, NULL); | |
706 EXPECT_VECTOR2DF_EQ(target_value, dummy.scroll_offset()); | |
707 EXPECT_FALSE(controller->HasActiveAnimation()); | |
708 } | |
709 | |
710 TEST(LayerAnimationControllerTest, ScrollOffsetTransitionOnImplOnly) { | |
711 FakeLayerAnimationValueObserver dummy_impl; | |
712 scoped_refptr<LayerAnimationController> controller_impl( | |
713 LayerAnimationController::Create(0)); | |
714 controller_impl->AddValueObserver(&dummy_impl); | |
715 scoped_ptr<AnimationEventsVector> events( | |
716 make_scoped_ptr(new AnimationEventsVector)); | |
717 | |
718 gfx::Vector2dF initial_value(100.f, 300.f); | |
719 gfx::Vector2dF target_value(300.f, 200.f); | |
720 scoped_ptr<ScrollOffsetAnimationCurve> curve( | |
721 ScrollOffsetAnimationCurve::Create( | |
722 target_value, | |
723 EaseInOutTimingFunction::Create().Pass())); | |
724 curve->SetInitialValue(initial_value); | |
725 double duration = curve->Duration(); | |
726 | |
727 scoped_ptr<Animation> animation(Animation::Create( | |
728 curve.PassAs<AnimationCurve>(), 1, 0, Animation::ScrollOffset)); | |
729 animation->set_is_impl_only(true); | |
730 controller_impl->AddAnimation(animation.Pass()); | |
731 | |
732 controller_impl->Animate(0.0); | |
733 controller_impl->UpdateState(true, events.get()); | |
734 EXPECT_TRUE(controller_impl->HasActiveAnimation()); | |
735 EXPECT_EQ(initial_value, dummy_impl.scroll_offset()); | |
736 // Scroll offset animations should not generate property updates. | |
737 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | |
738 EXPECT_FALSE(event); | |
739 | |
740 controller_impl->Animate(duration/2.0); | |
741 controller_impl->UpdateState(true, events.get()); | |
742 EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(200.f, 250.f), | |
743 dummy_impl.scroll_offset()); | |
744 event = GetMostRecentPropertyUpdateEvent(events.get()); | |
745 EXPECT_FALSE(event); | |
746 | |
747 controller_impl->Animate(duration); | |
748 controller_impl->UpdateState(true, events.get()); | |
749 EXPECT_VECTOR2DF_EQ(target_value, dummy_impl.scroll_offset()); | |
750 EXPECT_FALSE(controller_impl->HasActiveAnimation()); | |
751 event = GetMostRecentPropertyUpdateEvent(events.get()); | |
752 EXPECT_FALSE(event); | |
753 } | |
754 | |
554 class FakeAnimationDelegate : public AnimationDelegate { | 755 class FakeAnimationDelegate : public AnimationDelegate { |
555 public: | 756 public: |
556 FakeAnimationDelegate() | 757 FakeAnimationDelegate() |
557 : started_(false), | 758 : started_(false), |
558 finished_(false) {} | 759 finished_(false) {} |
559 | 760 |
560 virtual void NotifyAnimationStarted(double time) OVERRIDE { | 761 virtual void NotifyAnimationStarted(double time) OVERRIDE { |
561 started_ = true; | 762 started_ = true; |
562 } | 763 } |
563 | 764 |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1461 // animation, and an Aborted event for the opacity animation. | 1662 // animation, and an Aborted event for the opacity animation. |
1462 EXPECT_EQ(2u, events->size()); | 1663 EXPECT_EQ(2u, events->size()); |
1463 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); | 1664 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type); |
1464 EXPECT_EQ(Animation::Transform, (*events)[0].target_property); | 1665 EXPECT_EQ(Animation::Transform, (*events)[0].target_property); |
1465 EXPECT_EQ(AnimationEvent::Aborted, (*events)[1].type); | 1666 EXPECT_EQ(AnimationEvent::Aborted, (*events)[1].type); |
1466 EXPECT_EQ(Animation::Opacity, (*events)[1].target_property); | 1667 EXPECT_EQ(Animation::Opacity, (*events)[1].target_property); |
1467 } | 1668 } |
1468 | 1669 |
1469 } // namespace | 1670 } // namespace |
1470 } // namespace cc | 1671 } // namespace cc |
OLD | NEW |