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
{
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 bool mutators_need_commit() const { return mutators_need_commit_
; }
98 void set_mutators_need_commit(bool need
) { mutators_need_commit_
= need
; }
100 void RegisterLayer(int layer_id
, LayerTreeType tree_type
);
101 void UnregisterLayer(int layer_id
, LayerTreeType tree_type
);
103 AnimationHost
* host() {
108 bool IsPropertyMutated(int layer_id
,
109 LayerTreeType tree_type
,
110 Animation::TargetProperty property
) const;
112 void ExpectFilterPropertyMutated(int layer_id
,
113 LayerTreeType tree_type
,
114 float brightness
) const;
115 void ExpectOpacityPropertyMutated(int layer_id
,
116 LayerTreeType tree_type
,
117 float opacity
) const;
118 void ExpectTransformPropertyMutated(int layer_id
,
119 LayerTreeType tree_type
,
121 int transform_y
) const;
122 void ExpectScrollOffsetPropertyMutated(
124 LayerTreeType tree_type
,
125 const gfx::ScrollOffset
& scroll_offset
) const;
127 TestLayer
* FindTestLayer(int layer_id
, LayerTreeType tree_type
) const;
130 scoped_ptr
<AnimationHost
> host_
;
132 typedef base::ScopedPtrHashMap
<int, scoped_ptr
<TestLayer
>> LayerIdToTestLayer
;
133 LayerIdToTestLayer layers_in_active_tree_
;
134 LayerIdToTestLayer layers_in_pending_tree_
;
136 bool mutators_need_commit_
;
139 class TestAnimationDelegate
: public AnimationDelegate
{
141 TestAnimationDelegate();
143 void NotifyAnimationStarted(base::TimeTicks monotonic_time
,
144 Animation::TargetProperty target_property
,
146 void NotifyAnimationFinished(base::TimeTicks monotonic_time
,
147 Animation::TargetProperty target_property
,
153 class AnimationTimelinesTest
: public testing::Test
{
155 AnimationTimelinesTest();
156 ~AnimationTimelinesTest() override
;
159 void SetUp() override
;
161 void GetImplTimelineAndPlayerByID();
163 void ReleaseRefPtrs();
165 void AnimateLayersTransferEvents(base::TimeTicks time
,
166 unsigned expect_events
);
168 AnimationPlayer
* GetPlayerForLayerId(int layer_id
);
169 AnimationPlayer
* GetImplPlayerForLayerId(int layer_id
);
171 TestHostClient client_
;
172 TestHostClient client_impl_
;
174 AnimationHost
* host_
;
175 AnimationHost
* host_impl_
;
177 const int timeline_id_
;
178 const int player_id_
;
181 scoped_refptr
<AnimationTimeline
> timeline_
;
182 scoped_refptr
<AnimationPlayer
> player_
;
184 scoped_refptr
<AnimationTimeline
> timeline_impl_
;
185 scoped_refptr
<AnimationPlayer
> player_impl_
;
190 #endif // CC_TEST_ANIMATION_TIMELINES_TEST_COMMON_H_