MacViews: Round corners for the Yosemite menu background paint for blur
[chromium-blink-merge.git] / cc / test / animation_timelines_test_common.cc
blob54056080e4efb65d0d01566daf61da462d2c2d8e
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/test/animation_timelines_test_common.h"
7 #include "cc/animation/animation_events.h"
8 #include "cc/animation/animation_id_provider.h"
9 #include "cc/animation/animation_player.h"
10 #include "cc/animation/animation_registrar.h"
11 #include "cc/animation/animation_timeline.h"
12 #include "cc/animation/element_animations.h"
13 #include "cc/output/filter_operation.h"
14 #include "cc/output/filter_operations.h"
15 #include "ui/gfx/transform.h"
17 namespace cc {
19 scoped_ptr<TestLayer> TestLayer::Create() {
20 return make_scoped_ptr(new TestLayer());
23 TestLayer::TestLayer() {
24 ClearMutatedProperties();
27 void TestLayer::ClearMutatedProperties() {
28 transform_x_ = 0;
29 transform_y_ = 0;
31 opacity_ = 0;
32 brightness_ = 0;
34 for (int i = 0; i <= Animation::LAST_TARGET_PROPERTY; ++i)
35 mutated_properties_[i] = false;
38 TestHostClient::TestHostClient(ThreadInstance thread_instance)
39 : host_(AnimationHost::Create(thread_instance)),
40 mutators_need_commit_(false) {
41 host_->SetMutatorHostClient(this);
44 TestHostClient::~TestHostClient() {
45 host_->SetMutatorHostClient(nullptr);
48 void TestHostClient::ClearMutatedProperties() {
49 for (auto& kv : layers_in_pending_tree_)
50 kv.second->ClearMutatedProperties();
51 for (auto& kv : layers_in_active_tree_)
52 kv.second->ClearMutatedProperties();
55 bool TestHostClient::IsLayerInTree(int layer_id,
56 LayerTreeType tree_type) const {
57 return tree_type == LayerTreeType::ACTIVE
58 ? layers_in_active_tree_.count(layer_id)
59 : layers_in_pending_tree_.count(layer_id);
62 void TestHostClient::SetMutatorsNeedCommit() {
63 mutators_need_commit_ = true;
66 void TestHostClient::SetLayerFilterMutated(int layer_id,
67 LayerTreeType tree_type,
68 const FilterOperations& filters) {
69 for (unsigned i = 0; i < filters.size(); ++i) {
70 const FilterOperation& filter = filters.at(i);
71 if (filter.type() == FilterOperation::BRIGHTNESS) {
72 TestLayer* layer = FindTestLayer(layer_id, tree_type);
73 layer->set_brightness(filter.amount());
78 void TestHostClient::SetLayerOpacityMutated(int layer_id,
79 LayerTreeType tree_type,
80 float opacity) {
81 TestLayer* layer = FindTestLayer(layer_id, tree_type);
82 layer->set_opacity(opacity);
85 void TestHostClient::SetLayerTransformMutated(int layer_id,
86 LayerTreeType tree_type,
87 const gfx::Transform& transform) {
88 TestLayer* layer = FindTestLayer(layer_id, tree_type);
89 gfx::Vector2dF vec = transform.To2dTranslation();
90 layer->set_transform(static_cast<int>(vec.x()), static_cast<int>(vec.y()));
93 void TestHostClient::SetLayerScrollOffsetMutated(
94 int layer_id,
95 LayerTreeType tree_type,
96 const gfx::ScrollOffset& scroll_offset) {
97 TestLayer* layer = FindTestLayer(layer_id, tree_type);
98 layer->set_scroll_offset(scroll_offset);
101 gfx::ScrollOffset TestHostClient::GetScrollOffsetForAnimation(
102 int layer_id) const {
103 return gfx::ScrollOffset();
106 void TestHostClient::RegisterLayer(int layer_id, LayerTreeType tree_type) {
107 LayerIdToTestLayer& layers_in_tree = tree_type == LayerTreeType::ACTIVE
108 ? layers_in_active_tree_
109 : layers_in_pending_tree_;
110 DCHECK(layers_in_tree.find(layer_id) == layers_in_tree.end());
111 layers_in_tree.add(layer_id, TestLayer::Create());
113 DCHECK(host_);
114 host_->RegisterLayer(layer_id, tree_type);
117 void TestHostClient::UnregisterLayer(int layer_id, LayerTreeType tree_type) {
118 DCHECK(host_);
119 host_->UnregisterLayer(layer_id, tree_type);
121 LayerIdToTestLayer& layers_in_tree = tree_type == LayerTreeType::ACTIVE
122 ? layers_in_active_tree_
123 : layers_in_pending_tree_;
124 auto kv = layers_in_tree.find(layer_id);
125 DCHECK(kv != layers_in_tree.end());
126 layers_in_tree.erase(kv);
129 bool TestHostClient::IsPropertyMutated(
130 int layer_id,
131 LayerTreeType tree_type,
132 Animation::TargetProperty property) const {
133 TestLayer* layer = FindTestLayer(layer_id, tree_type);
134 return layer->is_property_mutated(property);
137 void TestHostClient::ExpectFilterPropertyMutated(int layer_id,
138 LayerTreeType tree_type,
139 float brightness) const {
140 TestLayer* layer = FindTestLayer(layer_id, tree_type);
141 EXPECT_TRUE(layer->is_property_mutated(Animation::OPACITY));
142 EXPECT_EQ(brightness, layer->brightness());
145 void TestHostClient::ExpectOpacityPropertyMutated(int layer_id,
146 LayerTreeType tree_type,
147 float opacity) const {
148 TestLayer* layer = FindTestLayer(layer_id, tree_type);
149 EXPECT_TRUE(layer->is_property_mutated(Animation::OPACITY));
150 EXPECT_EQ(opacity, layer->opacity());
153 void TestHostClient::ExpectTransformPropertyMutated(int layer_id,
154 LayerTreeType tree_type,
155 int transform_x,
156 int transform_y) const {
157 TestLayer* layer = FindTestLayer(layer_id, tree_type);
158 EXPECT_TRUE(layer->is_property_mutated(Animation::OPACITY));
159 EXPECT_EQ(transform_x, layer->transform_x());
160 EXPECT_EQ(transform_y, layer->transform_y());
163 void TestHostClient::ExpectScrollOffsetPropertyMutated(
164 int layer_id,
165 LayerTreeType tree_type,
166 const gfx::ScrollOffset& scroll_offset) const {
167 TestLayer* layer = FindTestLayer(layer_id, tree_type);
168 EXPECT_TRUE(layer->is_property_mutated(Animation::OPACITY));
169 EXPECT_EQ(scroll_offset, layer->scroll_offset());
172 TestLayer* TestHostClient::FindTestLayer(int layer_id,
173 LayerTreeType tree_type) const {
174 const LayerIdToTestLayer& layers_in_tree = tree_type == LayerTreeType::ACTIVE
175 ? layers_in_active_tree_
176 : layers_in_pending_tree_;
177 auto kv = layers_in_tree.find(layer_id);
178 DCHECK(kv != layers_in_tree.end());
179 DCHECK(kv->second);
180 return kv->second;
183 TestAnimationDelegate::TestAnimationDelegate()
184 : started_(false), finished_(false) {
187 void TestAnimationDelegate::NotifyAnimationStarted(
188 base::TimeTicks monotonic_time,
189 Animation::TargetProperty target_property,
190 int group) {
191 started_ = true;
193 void TestAnimationDelegate::NotifyAnimationFinished(
194 base::TimeTicks monotonic_time,
195 Animation::TargetProperty target_property,
196 int group) {
197 finished_ = true;
200 AnimationTimelinesTest::AnimationTimelinesTest()
201 : client_(ThreadInstance::MAIN),
202 client_impl_(ThreadInstance::IMPL),
203 host_(nullptr),
204 host_impl_(nullptr),
205 timeline_id_(AnimationIdProvider::NextTimelineId()),
206 player_id_(AnimationIdProvider::NextPlayerId()),
207 layer_id_(1) {
208 host_ = client_.host();
209 host_impl_ = client_impl_.host();
212 AnimationTimelinesTest::~AnimationTimelinesTest() {
215 void AnimationTimelinesTest::SetUp() {
216 timeline_ = AnimationTimeline::Create(timeline_id_);
217 player_ = AnimationPlayer::Create(player_id_);
220 void AnimationTimelinesTest::GetImplTimelineAndPlayerByID() {
221 timeline_impl_ = host_impl_->GetTimelineById(timeline_id_);
222 EXPECT_TRUE(timeline_impl_);
223 player_impl_ = timeline_impl_->GetPlayerById(player_id_);
224 EXPECT_TRUE(player_impl_);
227 void AnimationTimelinesTest::ReleaseRefPtrs() {
228 player_ = nullptr;
229 timeline_ = nullptr;
230 player_impl_ = nullptr;
231 timeline_impl_ = nullptr;
234 void AnimationTimelinesTest::AnimateLayersTransferEvents(
235 base::TimeTicks time,
236 unsigned expect_events) {
237 scoped_ptr<AnimationEventsVector> events =
238 host_->animation_registrar()->CreateEvents();
240 host_impl_->animation_registrar()->AnimateLayers(time);
241 host_impl_->animation_registrar()->UpdateAnimationState(true, events.get());
242 EXPECT_EQ(expect_events, events->size());
244 host_->animation_registrar()->AnimateLayers(time);
245 host_->animation_registrar()->UpdateAnimationState(true, nullptr);
246 host_->animation_registrar()->SetAnimationEvents(events.Pass());
249 AnimationPlayer* AnimationTimelinesTest::GetPlayerForLayerId(int layer_id) {
250 const ElementAnimations* element_animations =
251 host_->GetElementAnimationsForLayerId(layer_id);
252 return element_animations ? element_animations->players_list().head()->value()
253 : nullptr;
256 AnimationPlayer* AnimationTimelinesTest::GetImplPlayerForLayerId(int layer_id) {
257 const ElementAnimations* element_animations =
258 host_impl_->GetElementAnimationsForLayerId(layer_id);
259 return element_animations ? element_animations->players_list().head()->value()
260 : nullptr;
263 } // namespace cc