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

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

Issue 1810833002: Blink Compositor Animations: Add tests for resetting delegate in CC on Blink player deletion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "platform/animation/CompositorAnimationDelegate.h" 9 #include "platform/animation/CompositorAnimationDelegate.h"
10 #include "platform/animation/CompositorAnimationPlayerClient.h"
11 #include "platform/animation/CompositorAnimationTimeline.h"
10 #include "platform/animation/CompositorTargetProperty.h" 12 #include "platform/animation/CompositorTargetProperty.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 using base::TimeTicks;
15 using blink::CompositorAnimationDelegate;
16 using cc::Animation;
17 using testing::_;
18
19 namespace blink { 15 namespace blink {
20 16
21 class MockCompositorAnimationDelegate : public CompositorAnimationDelegate { 17 class CompositorAnimationDelegateForTesting : public CompositorAnimationDelegate {
22 public: 18 public:
23 MockCompositorAnimationDelegate() {} 19 CompositorAnimationDelegateForTesting() { resetFlags(); }
24 20
25 MOCK_METHOD2(notifyAnimationStarted, void(double, int)); 21 void resetFlags()
26 MOCK_METHOD2(notifyAnimationFinished, void(double, int)); 22 {
27 MOCK_METHOD2(notifyAnimationAborted, void(double, int)); 23 m_started = false;
24 m_finished = false;
25 m_aborted = false;
26 }
27
28 void notifyAnimationStarted(double, int) override { m_started = true; }
29 void notifyAnimationFinished(double, int) override { m_finished = true; }
30 void notifyAnimationAborted(double, int) override { m_aborted = true; }
31
32 bool m_started;
33 bool m_finished;
34 bool m_aborted;
28 }; 35 };
29 36
37 class CompositorAnimationPlayerTestClient : public CompositorAnimationPlayerClie nt {
38 public:
39 CompositorAnimationPlayerTestClient() : m_player(new CompositorAnimationPlay er) {}
40
41 CompositorAnimationPlayer* compositorPlayer() const override
42 {
43 return m_player.get();
44 }
45
46 scoped_ptr<CompositorAnimationPlayer> m_player;
47 };
48
49
30 // Test that when the animation delegate is null, the animation player 50 // Test that when the animation delegate is null, the animation player
31 // doesn't forward the finish notification. 51 // doesn't forward the finish notification.
32 TEST(CompositorAnimationPlayerTest, NullDelegate) 52 TEST(CompositorAnimationPlayerTest, NullDelegate)
33 { 53 {
34 scoped_ptr<CompositorAnimationDelegate> delegate( 54 scoped_ptr<CompositorAnimationDelegateForTesting> delegate(new CompositorAni mationDelegateForTesting);
35 new MockCompositorAnimationDelegate);
36 EXPECT_CALL(*static_cast<MockCompositorAnimationDelegate*>(delegate.get()),
37 notifyAnimationFinished(_, _))
38 .Times(1);
39 55
40 scoped_ptr<CompositorAnimationPlayer> webPlayer(new CompositorAnimationPlaye r); 56 scoped_ptr<CompositorAnimationPlayer> player(new CompositorAnimationPlayer);
41 cc::AnimationPlayer* player = webPlayer->animationPlayer(); 57 cc::AnimationPlayer* ccPlayer = player->animationPlayer();
42 58
43 webPlayer->setAnimationDelegate(delegate.get()); 59 player->setAnimationDelegate(delegate.get());
44 player->NotifyAnimationFinished(TimeTicks(), CompositorTargetProperty::SCROL L_OFFSET, 0); 60 EXPECT_FALSE(delegate->m_finished);
45 61
46 webPlayer->setAnimationDelegate(nullptr); 62 ccPlayer->NotifyAnimationFinished(base::TimeTicks(), CompositorTargetPropert y::SCROLL_OFFSET, 0);
47 player->NotifyAnimationFinished(TimeTicks(), CompositorTargetProperty::SCROL L_OFFSET, 0); 63 EXPECT_TRUE(delegate->m_finished);
64
65 delegate->resetFlags();
66
67 player->setAnimationDelegate(nullptr);
68 ccPlayer->NotifyAnimationFinished(base::TimeTicks(), CompositorTargetPropert y::SCROLL_OFFSET, 0);
69 EXPECT_FALSE(delegate->m_finished);
70 }
71
72 TEST(CompositorAnimationPlayerTest, NotifyFromCCAfterCompositorPlayerDeletion)
73 {
74 scoped_ptr<CompositorAnimationDelegateForTesting> delegate(new CompositorAni mationDelegateForTesting);
75
76 scoped_ptr<CompositorAnimationPlayer> player(new CompositorAnimationPlayer);
77 scoped_refptr<cc::AnimationPlayer> ccPlayer = player->animationPlayer();
78
79 player->setAnimationDelegate(delegate.get());
80 EXPECT_FALSE(delegate->m_finished);
81
82 // Delete CompositorAnimationPlayer. ccPlayer stays alive.
83 player = nullptr;
84
85 // No notifications. Doesn't crash.
86 ccPlayer->NotifyAnimationFinished(base::TimeTicks(), CompositorTargetPropert y::OPACITY, 0);
87 EXPECT_FALSE(delegate->m_finished);
88 }
89
90 TEST(CompositorAnimationPlayerTest, CompositorPlayerDeletionDetachesFromCCTimeli ne)
91 {
92 scoped_ptr<CompositorAnimationTimeline> timeline(new CompositorAnimationTime line);
93 scoped_ptr<CompositorAnimationPlayerTestClient> client(new CompositorAnimati onPlayerTestClient);
94
95 scoped_refptr<cc::AnimationTimeline> ccTimeline = timeline->animationTimelin e();
96 scoped_refptr<cc::AnimationPlayer> ccPlayer = client->m_player->animationPla yer();
97 EXPECT_FALSE(ccPlayer->animation_timeline());
98
99 timeline->playerAttached(*client);
100 EXPECT_TRUE(ccPlayer->animation_timeline());
101 EXPECT_TRUE(ccTimeline->GetPlayerById(ccPlayer->id()));
102
103 // Delete client and CompositorAnimationPlayer while attached to timeline.
104 client = nullptr;
105
106 EXPECT_FALSE(ccPlayer->animation_timeline());
107 EXPECT_FALSE(ccTimeline->GetPlayerById(ccPlayer->id()));
48 } 108 }
49 109
50 } // namespace blink 110 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698