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

Unified Diff: cc/animation/animation_player_unittest.cc

Issue 947033002: CC Animations: Establish AnimationHost, AnimationTimeline and AnimationPlayer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix code review issues. Rebase. Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: cc/animation/animation_player_unittest.cc
diff --git a/cc/animation/animation_player_unittest.cc b/cc/animation/animation_player_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7d2a8d9b244b6748539f46fb18d2cfaadae9c745
--- /dev/null
+++ b/cc/animation/animation_player_unittest.cc
@@ -0,0 +1,609 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/animation/animation_player.h"
+
+#include "base/containers/hash_tables.h"
+#include "cc/animation/animation_delegate.h"
+#include "cc/animation/animation_host.h"
+#include "cc/animation/animation_id_provider.h"
+#include "cc/animation/animation_registrar.h"
+#include "cc/animation/animation_timeline.h"
+#include "cc/test/animation_test_common.h"
+#include "cc/trees/layer_tree_mutators_client.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace cc {
+namespace {
+
+struct TestLayer {
+ TestLayer() { ClearMutatedProperties(); }
+
+ void ClearMutatedProperties() {
+ transform_x_ = 0;
+ transform_y_ = 0;
+
+ opacity_ = 0;
+ brightness_ = 0;
+
+ for (int i = 0; i <= Animation::LAST_TARGET_PROPERTY; ++i)
+ mutated_properties_[i] = false;
+ }
+
+ int transform_x_;
+ int transform_y_;
+
+ float opacity_;
+ float brightness_;
+ gfx::ScrollOffset scroll_offset_;
+
+ bool mutated_properties_[Animation::LAST_TARGET_PROPERTY + 1];
+};
+
+class TestLayerTreeMutatorsClient : public LayerTreeMutatorsClient {
+ public:
+ explicit TestLayerTreeMutatorsClient(ThreadInstance thread_instance)
+ : host_(AnimationHost::Create(thread_instance)),
+ mutators_need_commit_(false) {
+ host_->SetLayerTreeMutatorsClient(this);
+ }
+
+ ~TestLayerTreeMutatorsClient() {
+ for (auto& kv : layers_in_pending_tree_)
+ delete kv.second;
+ for (auto& kv : layers_in_active_tree_)
+ delete kv.second;
+ host_->SetLayerTreeMutatorsClient(nullptr);
+ }
+
+ void ClearMutatedProperties() {
+ for (auto& kv : layers_in_pending_tree_)
+ kv.second->ClearMutatedProperties();
+ for (auto& kv : layers_in_active_tree_)
+ kv.second->ClearMutatedProperties();
+ }
+
+ bool IsLayerInTree(int layer_id, LayerTreeType tree_type) const override {
+ return tree_type == LayerTreeType::ACTIVE
+ ? layers_in_active_tree_.count(layer_id)
+ : layers_in_pending_tree_.count(layer_id);
+ }
+
+ void SetMutatorsNeedCommit() override { mutators_need_commit_ = true; }
+
+ void SetLayerFilterMutated(int layer_id,
+ LayerTreeType tree_type,
+ const FilterOperations& filters) override {
+ for (unsigned i = 0; i < filters.size(); ++i) {
+ const FilterOperation& filter = filters.at(i);
+ if (filter.type() == FilterOperation::BRIGHTNESS) {
+ TestLayer* layer = FindTestLayer(layer_id, tree_type);
+ layer->mutated_properties_[Animation::FILTER] = true;
+ layer->brightness_ = filter.amount();
+ }
+ }
+ }
+
+ void SetLayerOpacityMutated(int layer_id,
+ LayerTreeType tree_type,
+ float opacity) override {
+ TestLayer* layer = FindTestLayer(layer_id, tree_type);
+ layer->mutated_properties_[Animation::OPACITY] = true;
+ layer->opacity_ = opacity;
+ }
+
+ void SetLayerTransformMutated(int layer_id,
+ LayerTreeType tree_type,
+ const gfx::Transform& transform) override {
+ TestLayer* layer = FindTestLayer(layer_id, tree_type);
+ layer->mutated_properties_[Animation::TRANSFORM] = true;
+ gfx::Vector2dF vec = transform.To2dTranslation();
+ layer->transform_x_ = static_cast<int>(vec.x());
+ layer->transform_y_ = static_cast<int>(vec.y());
+ }
+
+ void SetLayerScrollOffsetMutated(
+ int layer_id,
+ LayerTreeType tree_type,
+ const gfx::ScrollOffset& scroll_offset) override {
+ TestLayer* layer = FindTestLayer(layer_id, tree_type);
+ layer->mutated_properties_[Animation::SCROLL_OFFSET] = true;
+ layer->scroll_offset_ = scroll_offset;
+ }
+
+ bool mutators_need_commit() const { return mutators_need_commit_; }
+ void set_mutators_need_commit(bool need) { mutators_need_commit_ = need; }
+
+ void RegisterLayer(int layer_id, LayerTreeType tree_type) {
+ LayerIdToTestLayer& layers_in_tree = tree_type == LayerTreeType::ACTIVE
+ ? layers_in_active_tree_
+ : layers_in_pending_tree_;
+ DCHECK(layers_in_tree.find(layer_id) == layers_in_tree.end());
+ layers_in_tree.insert(std::make_pair(layer_id, new TestLayer()));
+
+ DCHECK(host_);
+ host_->RegisterLayer(layer_id, tree_type);
+ }
+
+ void UnregisterLayer(int layer_id, LayerTreeType tree_type) {
+ DCHECK(host_);
+ host_->UnregisterLayer(layer_id, tree_type);
+
+ LayerIdToTestLayer& layers_in_tree = tree_type == LayerTreeType::ACTIVE
+ ? layers_in_active_tree_
+ : layers_in_pending_tree_;
+ auto kv = layers_in_tree.find(layer_id);
+ DCHECK(kv != layers_in_tree.end());
+ delete kv->second;
+ layers_in_tree.erase(kv);
+ }
+
+ AnimationHost* host() {
+ DCHECK(host_);
+ return host_.get();
+ }
+
+ bool IsPropertyMutated(int layer_id,
+ LayerTreeType tree_type,
+ Animation::TargetProperty property) const {
+ TestLayer* layer = FindTestLayer(layer_id, tree_type);
+ return layer->mutated_properties_[property];
+ }
+
+ void ExpectFilterPropertyMutated(int layer_id,
+ LayerTreeType tree_type,
+ float brightness) const {
+ TestLayer* layer = FindTestLayer(layer_id, tree_type);
+ EXPECT_TRUE(layer->mutated_properties_[Animation::OPACITY]);
+ EXPECT_EQ(brightness, layer->brightness_);
+ }
+
+ void ExpectOpacityPropertyMutated(int layer_id,
+ LayerTreeType tree_type,
+ float opacity) const {
+ TestLayer* layer = FindTestLayer(layer_id, tree_type);
+ EXPECT_TRUE(layer->mutated_properties_[Animation::OPACITY]);
+ EXPECT_EQ(opacity, layer->opacity_);
+ }
+
+ void ExpectTransformPropertyMutated(int layer_id,
+ LayerTreeType tree_type,
+ int transform_x,
+ int transform_y) const {
+ TestLayer* layer = FindTestLayer(layer_id, tree_type);
+ EXPECT_TRUE(layer->mutated_properties_[Animation::OPACITY]);
+ EXPECT_EQ(transform_x, layer->transform_x_);
+ EXPECT_EQ(transform_y, layer->transform_y_);
+ }
+
+ void ExpectScrollOffsetPropertyMutated(
+ int layer_id,
+ LayerTreeType tree_type,
+ const gfx::ScrollOffset& scroll_offset) const {
+ TestLayer* layer = FindTestLayer(layer_id, tree_type);
+ EXPECT_TRUE(layer->mutated_properties_[Animation::OPACITY]);
+ EXPECT_EQ(scroll_offset, layer->scroll_offset_);
+ }
+
+ TestLayer* FindTestLayer(int layer_id, LayerTreeType tree_type) const {
+ const LayerIdToTestLayer& layers_in_tree =
+ tree_type == LayerTreeType::ACTIVE ? layers_in_active_tree_
+ : layers_in_pending_tree_;
+ auto kv = layers_in_tree.find(layer_id);
+ DCHECK(kv != layers_in_tree.end());
+ DCHECK(kv->second);
+ return kv->second;
+ }
+
+ private:
+ scoped_ptr<AnimationHost> host_;
+
+ typedef base::hash_map<int, TestLayer*> LayerIdToTestLayer;
+ LayerIdToTestLayer layers_in_active_tree_;
+ LayerIdToTestLayer layers_in_pending_tree_;
+
+ bool mutators_need_commit_;
+};
+
+class TestAnimationDelegate : public AnimationDelegate {
+ public:
+ TestAnimationDelegate() : started_(false), finished_(false) {}
+
+ void NotifyAnimationStarted(base::TimeTicks monotonic_time,
+ Animation::TargetProperty target_property,
+ int group) override {
+ started_ = true;
+ }
+ void NotifyAnimationFinished(base::TimeTicks monotonic_time,
+ Animation::TargetProperty target_property,
+ int group) override {
+ finished_ = true;
+ }
+
+ bool started_;
+ bool finished_;
+};
+
+class AnimationPlayerTest : public testing::Test {
+ public:
+ AnimationPlayerTest()
+ : client_(ThreadInstance::MAIN),
+ client_impl_(ThreadInstance::IMPL),
+ timeline_id_(AnimationIdProvider::NextTimelineId()),
+ player_id_(AnimationIdProvider::NextPlayerId()),
+ layer_id_(1) {
+ host_ = client_.host();
+ host_impl_ = client_impl_.host();
+ }
+
+ protected:
+ void SetUp() override {
+ timeline_ = AnimationTimeline::Create(timeline_id_);
+ player_ = AnimationPlayer::Create(player_id_);
+ }
+
+ void GetImplTimelineAndPlayerByID() {
+ timeline_impl_ = host_impl_->GetTimelineById(timeline_id_);
+ EXPECT_TRUE(timeline_impl_);
+ player_impl_ = timeline_impl_->GetPlayerById(player_id_);
+ EXPECT_TRUE(player_impl_);
+ }
+
+ void ReleaseRefPtrs() {
+ player_ = nullptr;
+ timeline_ = nullptr;
+ player_impl_ = nullptr;
+ timeline_impl_ = nullptr;
+ }
+
+ void AnimateLayersTransferEvents(base::TimeTicks time,
+ unsigned expect_events) {
+ scoped_ptr<AnimationEventsVector> events =
+ host_->animation_registrar()->CreateEvents();
+
+ host_impl_->animation_registrar()->AnimateLayers(time);
+ host_impl_->animation_registrar()->UpdateAnimationState(true, events.get());
+ EXPECT_EQ(expect_events, events->size());
+
+ host_->animation_registrar()->AnimateLayers(time);
+ host_->animation_registrar()->UpdateAnimationState(true, nullptr);
+ host_->animation_registrar()->SetAnimationEvents(events.Pass());
+ }
+
+ AnimationPlayer* GetPlayerForLayerId(int layer_id) {
+ const AnimationHost::PlayersList* list =
+ host_->GetPlayersForLayerId(layer_id);
+ return list ? list->head()->value() : nullptr;
+ }
+
+ AnimationPlayer* GetImplPlayerForLayerId(int layer_id) {
+ const AnimationHost::PlayersList* list =
+ host_impl_->GetPlayersForLayerId(layer_id);
+ return list ? list->head()->value() : nullptr;
+ }
+
+ TestLayerTreeMutatorsClient client_;
+ TestLayerTreeMutatorsClient client_impl_;
+
+ AnimationHost* host_;
+ AnimationHost* host_impl_;
+
+ const int timeline_id_;
+ const int player_id_;
+ const int layer_id_;
+
+ scoped_refptr<AnimationTimeline> timeline_;
+ scoped_refptr<AnimationPlayer> player_;
+
+ scoped_refptr<AnimationTimeline> timeline_impl_;
+ scoped_refptr<AnimationPlayer> player_impl_;
+};
+
+TEST_F(AnimationPlayerTest, AttachDetachLayerIfTimelineAttached) {
+ host_->AddAnimationTimeline(timeline_.get());
+ timeline_->AttachPlayer(player_.get());
+ EXPECT_FALSE(player_->layer_animation_controller());
+ EXPECT_FALSE(player_->layer_id());
+
+ host_->PushPropertiesTo(host_impl_);
+
+ EXPECT_FALSE(GetImplPlayerForLayerId(layer_id_));
+
+ GetImplTimelineAndPlayerByID();
+
+ EXPECT_FALSE(player_impl_->layer_animation_controller());
+ EXPECT_FALSE(player_impl_->layer_id());
+
+ player_->AttachLayer(layer_id_);
+ EXPECT_EQ(player_, GetPlayerForLayerId(layer_id_));
+ EXPECT_TRUE(player_->layer_animation_controller());
+ EXPECT_EQ(player_->layer_id(), layer_id_);
+
+ host_->PushPropertiesTo(host_impl_);
+
+ EXPECT_EQ(player_impl_, GetImplPlayerForLayerId(layer_id_));
+ EXPECT_TRUE(player_impl_->layer_animation_controller());
+ EXPECT_EQ(player_impl_->layer_id(), layer_id_);
+
+ player_->DetachLayer();
+ EXPECT_FALSE(GetPlayerForLayerId(layer_id_));
+ EXPECT_FALSE(player_->layer_animation_controller());
+ EXPECT_FALSE(player_->layer_id());
+
+ host_->PushPropertiesTo(host_impl_);
+
+ EXPECT_FALSE(GetImplPlayerForLayerId(layer_id_));
+ EXPECT_FALSE(player_impl_->layer_animation_controller());
+ EXPECT_FALSE(player_impl_->layer_id());
+
+ timeline_->DetachPlayer(player_.get());
+ EXPECT_FALSE(player_->animation_timeline());
+ EXPECT_FALSE(player_->layer_animation_controller());
+ EXPECT_FALSE(player_->layer_id());
+}
+
+TEST_F(AnimationPlayerTest, AttachDetachTimelineIfLayerAttached) {
+ host_->AddAnimationTimeline(timeline_.get());
+
+ EXPECT_FALSE(player_->layer_animation_controller());
+ EXPECT_FALSE(player_->layer_id());
+
+ player_->AttachLayer(layer_id_);
+ EXPECT_FALSE(player_->animation_timeline());
+ EXPECT_FALSE(GetPlayerForLayerId(layer_id_));
+ EXPECT_FALSE(player_->layer_animation_controller());
+ EXPECT_EQ(player_->layer_id(), layer_id_);
+
+ timeline_->AttachPlayer(player_.get());
+ EXPECT_EQ(timeline_, player_->animation_timeline());
+ EXPECT_EQ(player_, GetPlayerForLayerId(layer_id_));
+ EXPECT_TRUE(player_->layer_animation_controller());
+ EXPECT_EQ(player_->layer_id(), layer_id_);
+
+ // Removing player from timeline detaches layer.
+ timeline_->DetachPlayer(player_.get());
+ EXPECT_FALSE(player_->animation_timeline());
+ EXPECT_FALSE(GetPlayerForLayerId(layer_id_));
+ EXPECT_FALSE(player_->layer_animation_controller());
+ EXPECT_FALSE(player_->layer_id());
+}
+
+TEST_F(AnimationPlayerTest, AttachToLayerInActiveTree) {
+ // Set up the layer which is in active tree for main thread and not
+ // yet passed onto the impl thread.
+ client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
+ client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING);
+
+ EXPECT_TRUE(client_.IsLayerInTree(layer_id_, LayerTreeType::ACTIVE));
+ EXPECT_FALSE(client_.IsLayerInTree(layer_id_, LayerTreeType::PENDING));
+
+ host_->AddAnimationTimeline(timeline_.get());
+
+ timeline_->AttachPlayer(player_.get());
+ player_->AttachLayer(layer_id_);
+ EXPECT_TRUE(player_->has_active_value_observer_for_testing());
+ EXPECT_FALSE(player_->has_pending_value_observer_for_testing());
+ EXPECT_TRUE(player_->layer_animation_controller());
+
+ host_->PushPropertiesTo(host_impl_);
+
+ GetImplTimelineAndPlayerByID();
+
+ EXPECT_FALSE(player_impl_->has_active_value_observer_for_testing());
+ EXPECT_TRUE(player_impl_->has_pending_value_observer_for_testing());
+
+ // Create the layer in the impl active tree.
+ client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
+ EXPECT_TRUE(player_impl_->has_active_value_observer_for_testing());
+ EXPECT_TRUE(player_impl_->has_pending_value_observer_for_testing());
+
+ EXPECT_TRUE(client_impl_.IsLayerInTree(layer_id_, LayerTreeType::ACTIVE));
+ EXPECT_TRUE(client_impl_.IsLayerInTree(layer_id_, LayerTreeType::PENDING));
+
+ // kill layer on main thread.
+ client_.UnregisterLayer(layer_id_, LayerTreeType::ACTIVE);
+ EXPECT_FALSE(player_->has_active_value_observer_for_testing());
+ EXPECT_FALSE(player_->has_pending_value_observer_for_testing());
+ EXPECT_TRUE(player_->layer_animation_controller());
+
+ // Sync doesn't detach LayerImpl.
+ host_->PushPropertiesTo(host_impl_);
+ EXPECT_TRUE(player_impl_->has_active_value_observer_for_testing());
+ EXPECT_TRUE(player_impl_->has_pending_value_observer_for_testing());
+ EXPECT_TRUE(player_impl_->layer_animation_controller());
+
+ // Kill layer on impl thread in pending tree.
+ client_impl_.UnregisterLayer(layer_id_, LayerTreeType::PENDING);
+ EXPECT_TRUE(player_impl_->has_active_value_observer_for_testing());
+ EXPECT_FALSE(player_impl_->has_pending_value_observer_for_testing());
+ EXPECT_TRUE(player_impl_->layer_animation_controller());
+
+ // Kill layer on impl thread in active tree.
+ client_impl_.UnregisterLayer(layer_id_, LayerTreeType::ACTIVE);
+ EXPECT_FALSE(player_impl_->has_active_value_observer_for_testing());
+ EXPECT_FALSE(player_impl_->has_pending_value_observer_for_testing());
+ EXPECT_TRUE(player_impl_->layer_animation_controller());
+
+ // Sync doesn't change anything.
+ host_->PushPropertiesTo(host_impl_);
+ EXPECT_FALSE(player_impl_->has_active_value_observer_for_testing());
+ EXPECT_FALSE(player_impl_->has_pending_value_observer_for_testing());
+ EXPECT_TRUE(player_impl_->layer_animation_controller());
+
+ player_->DetachLayer();
+ EXPECT_FALSE(player_->layer_animation_controller());
+
+ // Release ptrs now to test the order of destruction.
+ ReleaseRefPtrs();
+}
+
+TEST_F(AnimationPlayerTest, AttachToNotYetCreatedLayer) {
+ host_->AddAnimationTimeline(timeline_.get());
+ timeline_->AttachPlayer(player_.get());
+
+ host_->PushPropertiesTo(host_impl_);
+
+ GetImplTimelineAndPlayerByID();
+
+ player_->AttachLayer(layer_id_);
+ EXPECT_FALSE(player_->has_active_value_observer_for_testing());
+ EXPECT_FALSE(player_->has_pending_value_observer_for_testing());
+ EXPECT_TRUE(player_->layer_animation_controller());
+
+ host_->PushPropertiesTo(host_impl_);
+ EXPECT_FALSE(player_impl_->has_active_value_observer_for_testing());
+ EXPECT_FALSE(player_impl_->has_pending_value_observer_for_testing());
+ EXPECT_TRUE(player_impl_->layer_animation_controller());
+
+ // Create layer.
+ client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
+ EXPECT_TRUE(player_->has_active_value_observer_for_testing());
+ EXPECT_FALSE(player_->has_pending_value_observer_for_testing());
+
+ client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING);
+ EXPECT_FALSE(player_impl_->has_active_value_observer_for_testing());
+ EXPECT_TRUE(player_impl_->has_pending_value_observer_for_testing());
+
+ client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
+ EXPECT_TRUE(player_impl_->has_active_value_observer_for_testing());
+ EXPECT_TRUE(player_impl_->has_pending_value_observer_for_testing());
+}
+
+TEST_F(AnimationPlayerTest, PropertiesMutate) {
+ client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
+ client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING);
+ client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
+
+ host_->AddAnimationTimeline(timeline_.get());
+ timeline_->AttachPlayer(player_.get());
+ player_->AttachLayer(layer_id_);
+
+ const float start_opacity = .7f;
+ const float end_opacity = .3f;
+
+ const float start_brightness = .6f;
+ const float end_brightness = .4f;
+
+ const int transform_x = 10;
+ const int transform_y = 20;
+
+ const double duration = 1.;
+
+ AddOpacityTransitionToPlayer(player_.get(), duration, start_opacity,
+ end_opacity, false);
+ AddAnimatedTransformToPlayer(player_.get(), duration, transform_x,
+ transform_y);
+ AddAnimatedFilterToPlayer(player_.get(), duration, start_brightness,
+ end_brightness);
+
+ host_->PushPropertiesTo(host_impl_);
+
+ EXPECT_FALSE(client_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
+ Animation::OPACITY));
+ EXPECT_FALSE(client_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
+ Animation::TRANSFORM));
+ EXPECT_FALSE(client_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
+ Animation::FILTER));
+
+ EXPECT_FALSE(client_impl_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
+ Animation::OPACITY));
+ EXPECT_FALSE(client_impl_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
+ Animation::TRANSFORM));
+ EXPECT_FALSE(client_impl_.IsPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
+ Animation::FILTER));
+
+ host_impl_->animation_registrar()->ActivateAnimations();
+
+ base::TimeTicks time;
+ time += base::TimeDelta::FromSecondsD(0.1);
+ AnimateLayersTransferEvents(time, 3u);
+
+ time += base::TimeDelta::FromSecondsD(duration);
+ AnimateLayersTransferEvents(time, 3u);
+
+ client_.ExpectOpacityPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
+ end_opacity);
+ client_.ExpectTransformPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
+ transform_x, transform_y);
+ client_.ExpectFilterPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
+ end_brightness);
+
+ client_impl_.ExpectOpacityPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
+ end_opacity);
+ client_impl_.ExpectTransformPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
+ transform_x, transform_y);
+ client_impl_.ExpectFilterPropertyMutated(layer_id_, LayerTreeType::ACTIVE,
+ end_brightness);
+
+ client_impl_.ExpectOpacityPropertyMutated(layer_id_, LayerTreeType::PENDING,
+ end_opacity);
+ client_impl_.ExpectTransformPropertyMutated(layer_id_, LayerTreeType::PENDING,
+ transform_x, transform_y);
+ client_impl_.ExpectFilterPropertyMutated(layer_id_, LayerTreeType::PENDING,
+ end_brightness);
+}
+
+TEST_F(AnimationPlayerTest, LayerAnimationDelegate) {
+ TestAnimationDelegate delegate;
+
+ client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
+ client_impl_.RegisterLayer(layer_id_, LayerTreeType::PENDING);
+ client_impl_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
+
+ host_->AddAnimationTimeline(timeline_.get());
+ timeline_->AttachPlayer(player_.get());
+
+ // Set delegate before controller created.
+ player_->set_layer_animation_delegate(&delegate);
+ player_->AttachLayer(layer_id_);
+
+ const double duration = 1.;
+
+ AddOpacityTransitionToPlayer(player_.get(), duration, .7f, .3f, false);
+
+ host_->PushPropertiesTo(host_impl_);
+ host_impl_->animation_registrar()->ActivateAnimations();
+
+ EXPECT_FALSE(delegate.started_);
+ EXPECT_FALSE(delegate.finished_);
+
+ base::TimeTicks time;
+ time += base::TimeDelta::FromSecondsD(0.1);
+ AnimateLayersTransferEvents(time, 1u);
+
+ EXPECT_TRUE(delegate.started_);
+ EXPECT_FALSE(delegate.finished_);
+
+ time += base::TimeDelta::FromSecondsD(duration);
+ AnimateLayersTransferEvents(time, 1u);
+
+ EXPECT_TRUE(delegate.finished_);
+}
+
+TEST_F(AnimationPlayerTest, AddRemoveAnimationCausesSetNeedsCommit) {
+ client_.RegisterLayer(layer_id_, LayerTreeType::ACTIVE);
+ host_->AddAnimationTimeline(timeline_.get());
+ timeline_->AttachPlayer(player_.get());
+ player_->AttachLayer(layer_id_);
+
+ EXPECT_FALSE(client_.mutators_need_commit());
+
+ const int animation_id =
+ AddOpacityTransitionToPlayer(player_.get(), 1., .7f, .3f, false);
+
+ EXPECT_TRUE(client_.mutators_need_commit());
+ client_.set_mutators_need_commit(false);
+
+ player_->PauseAnimation(animation_id, 1.);
+ EXPECT_TRUE(client_.mutators_need_commit());
+ client_.set_mutators_need_commit(false);
+
+ player_->RemoveAnimation(animation_id);
+ EXPECT_TRUE(client_.mutators_need_commit());
+ client_.set_mutators_need_commit(false);
+}
+
+} // namespace
+} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698