Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: third_party/WebKit/Source/platform/animation/CompositorAnimationPlayerTest.cpp

Issue 2335043002: CC Animation: Move animations_ from ElementAnimations to AnimationPlayer. (Closed)
Patch Set: Clean it up harder. Rework UpdateClientAnimationState. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "platform/animation/CompositorAnimationPlayer.h" 5 #include "platform/animation/CompositorAnimationPlayer.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "platform/animation/CompositorAnimation.h"
8 #include "platform/animation/CompositorAnimationDelegate.h" 9 #include "platform/animation/CompositorAnimationDelegate.h"
9 #include "platform/animation/CompositorAnimationPlayerClient.h" 10 #include "platform/animation/CompositorAnimationPlayerClient.h"
10 #include "platform/animation/CompositorAnimationTimeline.h" 11 #include "platform/animation/CompositorAnimationTimeline.h"
12 #include "platform/animation/CompositorFloatAnimationCurve.h"
11 #include "platform/animation/CompositorTargetProperty.h" 13 #include "platform/animation/CompositorTargetProperty.h"
12 #include "platform/testing/CompositorTest.h" 14 #include "platform/testing/CompositorTest.h"
13 15
14 #include <memory> 16 #include <memory>
15 17
16 namespace blink { 18 namespace blink {
17 19
18 class CompositorAnimationDelegateForTesting : public CompositorAnimationDelegate { 20 class CompositorAnimationDelegateForTesting : public CompositorAnimationDelegate {
19 public: 21 public:
20 CompositorAnimationDelegateForTesting() { resetFlags(); } 22 CompositorAnimationDelegateForTesting() { resetFlags(); }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 54
53 // Test that when the animation delegate is null, the animation player 55 // Test that when the animation delegate is null, the animation player
54 // doesn't forward the finish notification. 56 // doesn't forward the finish notification.
55 TEST_F(CompositorAnimationPlayerTest, NullDelegate) 57 TEST_F(CompositorAnimationPlayerTest, NullDelegate)
56 { 58 {
57 std::unique_ptr<CompositorAnimationDelegateForTesting> delegate(new Composit orAnimationDelegateForTesting); 59 std::unique_ptr<CompositorAnimationDelegateForTesting> delegate(new Composit orAnimationDelegateForTesting);
58 60
59 std::unique_ptr<CompositorAnimationPlayer> player = CompositorAnimationPlaye r::create(); 61 std::unique_ptr<CompositorAnimationPlayer> player = CompositorAnimationPlaye r::create();
60 cc::AnimationPlayer* ccPlayer = player->animationPlayer(); 62 cc::AnimationPlayer* ccPlayer = player->animationPlayer();
61 63
64 std::unique_ptr<CompositorAnimationCurve> curve = CompositorFloatAnimationCu rve::create();
65 std::unique_ptr<CompositorAnimation> animation = CompositorAnimation::create (
66 *curve, CompositorTargetProperty::TRANSFORM, 1, 0);
67 // TODO(loyso): CompositorPlayer::addAnimation should consume unique_ptr.
68 player->addAnimation(animation.release());
69
62 player->setAnimationDelegate(delegate.get()); 70 player->setAnimationDelegate(delegate.get());
63 EXPECT_FALSE(delegate->m_finished); 71 EXPECT_FALSE(delegate->m_finished);
64 72
65 ccPlayer->NotifyAnimationFinished(base::TimeTicks(), CompositorTargetPropert y::SCROLL_OFFSET, 0); 73 ccPlayer->NotifyAnimationFinishedForTesting(CompositorTargetProperty::TRANSF ORM, 1);
66 EXPECT_TRUE(delegate->m_finished); 74 EXPECT_TRUE(delegate->m_finished);
67 75
68 delegate->resetFlags(); 76 delegate->resetFlags();
69 77
70 player->setAnimationDelegate(nullptr); 78 player->setAnimationDelegate(nullptr);
71 ccPlayer->NotifyAnimationFinished(base::TimeTicks(), CompositorTargetPropert y::SCROLL_OFFSET, 0); 79 ccPlayer->NotifyAnimationFinishedForTesting(CompositorTargetProperty::TRANSF ORM, 1);
72 EXPECT_FALSE(delegate->m_finished); 80 EXPECT_FALSE(delegate->m_finished);
73 } 81 }
74 82
75 TEST_F(CompositorAnimationPlayerTest, NotifyFromCCAfterCompositorPlayerDeletion) 83 TEST_F(CompositorAnimationPlayerTest, NotifyFromCCAfterCompositorPlayerDeletion)
76 { 84 {
77 std::unique_ptr<CompositorAnimationDelegateForTesting> delegate(new Composit orAnimationDelegateForTesting); 85 std::unique_ptr<CompositorAnimationDelegateForTesting> delegate(new Composit orAnimationDelegateForTesting);
78 86
79 std::unique_ptr<CompositorAnimationPlayer> player = CompositorAnimationPlaye r::create(); 87 std::unique_ptr<CompositorAnimationPlayer> player = CompositorAnimationPlaye r::create();
80 scoped_refptr<cc::AnimationPlayer> ccPlayer = player->animationPlayer(); 88 scoped_refptr<cc::AnimationPlayer> ccPlayer = player->animationPlayer();
81 89
90 std::unique_ptr<CompositorAnimationCurve> curve = CompositorFloatAnimationCu rve::create();
91 std::unique_ptr<CompositorAnimation> animation = CompositorAnimation::create (
92 *curve, CompositorTargetProperty::OPACITY, 1, 0);
93 // TODO(loyso): CompositorPlayer::addAnimation should consume unique_ptr.
94 player->addAnimation(animation.release());
95
82 player->setAnimationDelegate(delegate.get()); 96 player->setAnimationDelegate(delegate.get());
83 EXPECT_FALSE(delegate->m_finished); 97 EXPECT_FALSE(delegate->m_finished);
84 98
99 ccPlayer->NotifyAnimationFinishedForTesting(CompositorTargetProperty::OPACIT Y, 1);
100 EXPECT_TRUE(delegate->m_finished);
101 delegate->m_finished = false;
102
85 // Delete CompositorAnimationPlayer. ccPlayer stays alive. 103 // Delete CompositorAnimationPlayer. ccPlayer stays alive.
86 player = nullptr; 104 player = nullptr;
87 105
88 // No notifications. Doesn't crash. 106 // No notifications. Doesn't crash.
89 ccPlayer->NotifyAnimationFinished(base::TimeTicks(), CompositorTargetPropert y::OPACITY, 0); 107 ccPlayer->NotifyAnimationFinishedForTesting(CompositorTargetProperty::OPACIT Y, 1);
90 EXPECT_FALSE(delegate->m_finished); 108 EXPECT_FALSE(delegate->m_finished);
91 } 109 }
92 110
93 TEST_F(CompositorAnimationPlayerTest, CompositorPlayerDeletionDetachesFromCCTime line) 111 TEST_F(CompositorAnimationPlayerTest, CompositorPlayerDeletionDetachesFromCCTime line)
94 { 112 {
95 std::unique_ptr<CompositorAnimationTimeline> timeline = CompositorAnimationT imeline::create(); 113 std::unique_ptr<CompositorAnimationTimeline> timeline = CompositorAnimationT imeline::create();
96 std::unique_ptr<CompositorAnimationPlayerTestClient> client(new CompositorAn imationPlayerTestClient); 114 std::unique_ptr<CompositorAnimationPlayerTestClient> client(new CompositorAn imationPlayerTestClient);
97 115
98 scoped_refptr<cc::AnimationTimeline> ccTimeline = timeline->animationTimelin e(); 116 scoped_refptr<cc::AnimationTimeline> ccTimeline = timeline->animationTimelin e();
99 scoped_refptr<cc::AnimationPlayer> ccPlayer = client->m_player->animationPla yer(); 117 scoped_refptr<cc::AnimationPlayer> ccPlayer = client->m_player->animationPla yer();
100 EXPECT_FALSE(ccPlayer->animation_timeline()); 118 EXPECT_FALSE(ccPlayer->animation_timeline());
101 119
102 timeline->playerAttached(*client); 120 timeline->playerAttached(*client);
103 EXPECT_TRUE(ccPlayer->animation_timeline()); 121 EXPECT_TRUE(ccPlayer->animation_timeline());
104 EXPECT_TRUE(ccTimeline->GetPlayerById(ccPlayer->id())); 122 EXPECT_TRUE(ccTimeline->GetPlayerById(ccPlayer->id()));
105 123
106 // Delete client and CompositorAnimationPlayer while attached to timeline. 124 // Delete client and CompositorAnimationPlayer while attached to timeline.
107 client = nullptr; 125 client = nullptr;
108 126
109 EXPECT_FALSE(ccPlayer->animation_timeline()); 127 EXPECT_FALSE(ccPlayer->animation_timeline());
110 EXPECT_FALSE(ccTimeline->GetPlayerById(ccPlayer->id())); 128 EXPECT_FALSE(ccTimeline->GetPlayerById(ccPlayer->id()));
111 } 129 }
112 130
113 } // namespace blink 131 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698