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 #ifndef CC_TEST_ANIMATION_TIMELINES_TEST_COMMON_H_
6 #define CC_TEST_ANIMATION_TIMELINES_TEST_COMMON_H_
8 #include "base/containers/scoped_ptr_hash_map.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "cc/animation/animation.h"
11 #include "cc/animation/animation_delegate.h"
12 #include "cc/animation/animation_host.h"
13 #include "cc/trees/mutator_host_client.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gfx/geometry/scroll_offset.h"
21 static scoped_ptr
<TestLayer
> Create();
23 void ClearMutatedProperties();
25 int transform_x() const { return transform_x_
; }
26 int transform_y() const { return transform_y_
; }
28 void set_transform(int transform_x
, int transform_y
) {
29 transform_x_
= transform_x
;
30 transform_y_
= transform_y
;
31 mutated_properties_
[Animation::TRANSFORM
] = true;
34 float opacity() const { return opacity_
; }
35 void set_opacity(float opacity
) {
37 mutated_properties_
[Animation::OPACITY
] = true;
40 float brightness() const { return brightness_
; }
41 void set_brightness(float brightness
) {
42 brightness_
= brightness
;
43 mutated_properties_
[Animation::FILTER
] = true;
46 gfx::ScrollOffset
scroll_offset() const { return scroll_offset_
; }
47 void set_scroll_offset(const gfx::ScrollOffset
& scroll_offset
) {
48 scroll_offset_
= scroll_offset
;
49 mutated_properties_
[Animation::SCROLL_OFFSET
] = true;
52 bool is_property_mutated(Animation::TargetProperty property
) const {
53 return mutated_properties_
[property
];
64 gfx::ScrollOffset scroll_offset_
;
66 bool mutated_properties_
[Animation::LAST_TARGET_PROPERTY
+ 1];
69 class TestHostClient
: public MutatorHostClient
{
71 explicit TestHostClient(ThreadInstance thread_instance
);
74 void ClearMutatedProperties();
76 bool IsLayerInTree(int layer_id
, LayerTreeType tree_type
) const override
;
78 void SetMutatorsNeedCommit() override
;
80 void SetLayerFilterMutated(int layer_id
,
81 LayerTreeType tree_type
,
82 const FilterOperations
& filters
) override
;
84 void SetLayerOpacityMutated(int layer_id
,
85 LayerTreeType tree_type
,
86 float opacity
) override
;
88 void SetLayerTransformMutated(int layer_id
,
89 LayerTreeType tree_type
,
90 const gfx::Transform
& transform
) override
;
92 void SetLayerScrollOffsetMutated(
94 LayerTreeType tree_type
,
95 const gfx::ScrollOffset
& scroll_offset
) override
;
97 void LayerTransformIsPotentiallyAnimatingChanged(int layer_id
,
98 LayerTreeType tree_type
,
99 bool is_animating
) override
{
102 void ScrollOffsetAnimationFinished() override
{}
103 gfx::ScrollOffset
GetScrollOffsetForAnimation(int layer_id
) const override
;
105 bool mutators_need_commit() const { return mutators_need_commit_
; }
106 void set_mutators_need_commit(bool need
) { mutators_need_commit_
= need
; }
108 void RegisterLayer(int layer_id
, LayerTreeType tree_type
);
109 void UnregisterLayer(int layer_id
, LayerTreeType tree_type
);
111 AnimationHost
* host() {
116 bool IsPropertyMutated(int layer_id
,
117 LayerTreeType tree_type
,
118 Animation::TargetProperty property
) const;
120 void ExpectFilterPropertyMutated(int layer_id
,
121 LayerTreeType tree_type
,
122 float brightness
) const;
123 void ExpectOpacityPropertyMutated(int layer_id
,
124 LayerTreeType tree_type
,
125 float opacity
) const;
126 void ExpectTransformPropertyMutated(int layer_id
,
127 LayerTreeType tree_type
,
129 int transform_y
) const;
130 void ExpectScrollOffsetPropertyMutated(
132 LayerTreeType tree_type
,
133 const gfx::ScrollOffset
& scroll_offset
) const;
135 TestLayer
* FindTestLayer(int layer_id
, LayerTreeType tree_type
) const;
138 scoped_ptr
<AnimationHost
> host_
;
140 typedef base::ScopedPtrHashMap
<int, scoped_ptr
<TestLayer
>> LayerIdToTestLayer
;
141 LayerIdToTestLayer layers_in_active_tree_
;
142 LayerIdToTestLayer layers_in_pending_tree_
;
144 bool mutators_need_commit_
;
147 class TestAnimationDelegate
: public AnimationDelegate
{
149 TestAnimationDelegate();
151 void NotifyAnimationStarted(base::TimeTicks monotonic_time
,
152 Animation::TargetProperty target_property
,
154 void NotifyAnimationFinished(base::TimeTicks monotonic_time
,
155 Animation::TargetProperty target_property
,
161 class AnimationTimelinesTest
: public testing::Test
{
163 AnimationTimelinesTest();
164 ~AnimationTimelinesTest() override
;
167 void SetUp() override
;
169 void GetImplTimelineAndPlayerByID();
171 void ReleaseRefPtrs();
173 void AnimateLayersTransferEvents(base::TimeTicks time
,
174 unsigned expect_events
);
176 AnimationPlayer
* GetPlayerForLayerId(int layer_id
);
177 AnimationPlayer
* GetImplPlayerForLayerId(int layer_id
);
179 TestHostClient client_
;
180 TestHostClient client_impl_
;
182 AnimationHost
* host_
;
183 AnimationHost
* host_impl_
;
185 const int timeline_id_
;
186 const int player_id_
;
189 scoped_refptr
<AnimationTimeline
> timeline_
;
190 scoped_refptr
<AnimationPlayer
> player_
;
192 scoped_refptr
<AnimationTimeline
> timeline_impl_
;
193 scoped_refptr
<AnimationPlayer
> player_impl_
;
198 #endif // CC_TEST_ANIMATION_TIMELINES_TEST_COMMON_H_