| OLD | NEW |
| 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/CompositorAnimation.h" |
| 9 #include "platform/animation/CompositorAnimationDelegate.h" | 9 #include "platform/animation/CompositorAnimationDelegate.h" |
| 10 #include "platform/animation/CompositorAnimationPlayerClient.h" | 10 #include "platform/animation/CompositorAnimationPlayerClient.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 class CompositorAnimationPlayerTest : public CompositorTest { | 52 class CompositorAnimationPlayerTest : public CompositorTest { |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 // Test that when the animation delegate is null, the animation player | 55 // Test that when the animation delegate is null, the animation player |
| 56 // doesn't forward the finish notification. | 56 // doesn't forward the finish notification. |
| 57 TEST_F(CompositorAnimationPlayerTest, NullDelegate) | 57 TEST_F(CompositorAnimationPlayerTest, NullDelegate) |
| 58 { | 58 { |
| 59 std::unique_ptr<CompositorAnimationDelegateForTesting> delegate(new Composit
orAnimationDelegateForTesting); | 59 std::unique_ptr<CompositorAnimationDelegateForTesting> delegate(new Composit
orAnimationDelegateForTesting); |
| 60 | 60 |
| 61 std::unique_ptr<CompositorAnimationPlayer> player = CompositorAnimationPlaye
r::create(); | 61 std::unique_ptr<CompositorAnimationPlayer> player = CompositorAnimationPlaye
r::create(); |
| 62 cc::AnimationPlayer* ccPlayer = player->animationPlayer(); | 62 cc::AnimationPlayer* ccPlayer = player->ccAnimationPlayer(); |
| 63 | 63 |
| 64 std::unique_ptr<CompositorAnimationCurve> curve = CompositorFloatAnimationCu
rve::create(); | 64 std::unique_ptr<CompositorAnimationCurve> curve = CompositorFloatAnimationCu
rve::create(); |
| 65 std::unique_ptr<CompositorAnimation> animation = CompositorAnimation::create
( | 65 std::unique_ptr<CompositorAnimation> animation = CompositorAnimation::create
( |
| 66 *curve, CompositorTargetProperty::TRANSFORM, 1, 0); | 66 *curve, CompositorTargetProperty::TRANSFORM, 1, 0); |
| 67 // TODO(loyso): CompositorPlayer::addAnimation should consume unique_ptr. | 67 player->addAnimation(std::move(animation)); |
| 68 player->addAnimation(animation.release()); | |
| 69 | 68 |
| 70 player->setAnimationDelegate(delegate.get()); | 69 player->setAnimationDelegate(delegate.get()); |
| 71 EXPECT_FALSE(delegate->m_finished); | 70 EXPECT_FALSE(delegate->m_finished); |
| 72 | 71 |
| 73 ccPlayer->NotifyAnimationFinishedForTesting(CompositorTargetProperty::TRANSF
ORM, 1); | 72 ccPlayer->NotifyAnimationFinishedForTesting(CompositorTargetProperty::TRANSF
ORM, 1); |
| 74 EXPECT_TRUE(delegate->m_finished); | 73 EXPECT_TRUE(delegate->m_finished); |
| 75 | 74 |
| 76 delegate->resetFlags(); | 75 delegate->resetFlags(); |
| 77 | 76 |
| 78 player->setAnimationDelegate(nullptr); | 77 player->setAnimationDelegate(nullptr); |
| 79 ccPlayer->NotifyAnimationFinishedForTesting(CompositorTargetProperty::TRANSF
ORM, 1); | 78 ccPlayer->NotifyAnimationFinishedForTesting(CompositorTargetProperty::TRANSF
ORM, 1); |
| 80 EXPECT_FALSE(delegate->m_finished); | 79 EXPECT_FALSE(delegate->m_finished); |
| 81 } | 80 } |
| 82 | 81 |
| 83 TEST_F(CompositorAnimationPlayerTest, NotifyFromCCAfterCompositorPlayerDeletion) | 82 TEST_F(CompositorAnimationPlayerTest, NotifyFromCCAfterCompositorPlayerDeletion) |
| 84 { | 83 { |
| 85 std::unique_ptr<CompositorAnimationDelegateForTesting> delegate(new Composit
orAnimationDelegateForTesting); | 84 std::unique_ptr<CompositorAnimationDelegateForTesting> delegate(new Composit
orAnimationDelegateForTesting); |
| 86 | 85 |
| 87 std::unique_ptr<CompositorAnimationPlayer> player = CompositorAnimationPlaye
r::create(); | 86 std::unique_ptr<CompositorAnimationPlayer> player = CompositorAnimationPlaye
r::create(); |
| 88 scoped_refptr<cc::AnimationPlayer> ccPlayer = player->animationPlayer(); | 87 scoped_refptr<cc::AnimationPlayer> ccPlayer = player->ccAnimationPlayer(); |
| 89 | 88 |
| 90 std::unique_ptr<CompositorAnimationCurve> curve = CompositorFloatAnimationCu
rve::create(); | 89 std::unique_ptr<CompositorAnimationCurve> curve = CompositorFloatAnimationCu
rve::create(); |
| 91 std::unique_ptr<CompositorAnimation> animation = CompositorAnimation::create
( | 90 std::unique_ptr<CompositorAnimation> animation = CompositorAnimation::create
( |
| 92 *curve, CompositorTargetProperty::OPACITY, 1, 0); | 91 *curve, CompositorTargetProperty::OPACITY, 1, 0); |
| 93 // TODO(loyso): CompositorPlayer::addAnimation should consume unique_ptr. | 92 player->addAnimation(std::move(animation)); |
| 94 player->addAnimation(animation.release()); | |
| 95 | 93 |
| 96 player->setAnimationDelegate(delegate.get()); | 94 player->setAnimationDelegate(delegate.get()); |
| 97 EXPECT_FALSE(delegate->m_finished); | 95 EXPECT_FALSE(delegate->m_finished); |
| 98 | 96 |
| 99 ccPlayer->NotifyAnimationFinishedForTesting(CompositorTargetProperty::OPACIT
Y, 1); | 97 ccPlayer->NotifyAnimationFinishedForTesting(CompositorTargetProperty::OPACIT
Y, 1); |
| 100 EXPECT_TRUE(delegate->m_finished); | 98 EXPECT_TRUE(delegate->m_finished); |
| 101 delegate->m_finished = false; | 99 delegate->m_finished = false; |
| 102 | 100 |
| 103 // Delete CompositorAnimationPlayer. ccPlayer stays alive. | 101 // Delete CompositorAnimationPlayer. ccPlayer stays alive. |
| 104 player = nullptr; | 102 player = nullptr; |
| 105 | 103 |
| 106 // No notifications. Doesn't crash. | 104 // No notifications. Doesn't crash. |
| 107 ccPlayer->NotifyAnimationFinishedForTesting(CompositorTargetProperty::OPACIT
Y, 1); | 105 ccPlayer->NotifyAnimationFinishedForTesting(CompositorTargetProperty::OPACIT
Y, 1); |
| 108 EXPECT_FALSE(delegate->m_finished); | 106 EXPECT_FALSE(delegate->m_finished); |
| 109 } | 107 } |
| 110 | 108 |
| 111 TEST_F(CompositorAnimationPlayerTest, CompositorPlayerDeletionDetachesFromCCTime
line) | 109 TEST_F(CompositorAnimationPlayerTest, CompositorPlayerDeletionDetachesFromCCTime
line) |
| 112 { | 110 { |
| 113 std::unique_ptr<CompositorAnimationTimeline> timeline = CompositorAnimationT
imeline::create(); | 111 std::unique_ptr<CompositorAnimationTimeline> timeline = CompositorAnimationT
imeline::create(); |
| 114 std::unique_ptr<CompositorAnimationPlayerTestClient> client(new CompositorAn
imationPlayerTestClient); | 112 std::unique_ptr<CompositorAnimationPlayerTestClient> client(new CompositorAn
imationPlayerTestClient); |
| 115 | 113 |
| 116 scoped_refptr<cc::AnimationTimeline> ccTimeline = timeline->animationTimelin
e(); | 114 scoped_refptr<cc::AnimationTimeline> ccTimeline = timeline->animationTimelin
e(); |
| 117 scoped_refptr<cc::AnimationPlayer> ccPlayer = client->m_player->animationPla
yer(); | 115 scoped_refptr<cc::AnimationPlayer> ccPlayer = client->m_player->ccAnimationP
layer(); |
| 118 EXPECT_FALSE(ccPlayer->animation_timeline()); | 116 EXPECT_FALSE(ccPlayer->animation_timeline()); |
| 119 | 117 |
| 120 timeline->playerAttached(*client); | 118 timeline->playerAttached(*client); |
| 121 EXPECT_TRUE(ccPlayer->animation_timeline()); | 119 EXPECT_TRUE(ccPlayer->animation_timeline()); |
| 122 EXPECT_TRUE(ccTimeline->GetPlayerById(ccPlayer->id())); | 120 EXPECT_TRUE(ccTimeline->GetPlayerById(ccPlayer->id())); |
| 123 | 121 |
| 124 // Delete client and CompositorAnimationPlayer while attached to timeline. | 122 // Delete client and CompositorAnimationPlayer while attached to timeline. |
| 125 client = nullptr; | 123 client = nullptr; |
| 126 | 124 |
| 127 EXPECT_FALSE(ccPlayer->animation_timeline()); | 125 EXPECT_FALSE(ccPlayer->animation_timeline()); |
| 128 EXPECT_FALSE(ccTimeline->GetPlayerById(ccPlayer->id())); | 126 EXPECT_FALSE(ccTimeline->GetPlayerById(ccPlayer->id())); |
| 129 } | 127 } |
| 130 | 128 |
| 131 } // namespace blink | 129 } // namespace blink |
| OLD | NEW |