[Android] Introduce new UMA action for when user copies Image URL from context menu
[chromium-blink-merge.git] / cc / test / animation_timelines_test_common.h
blobe17d9e5d95b1a897394665c5278c6a2b065f4eaf
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"
17 namespace cc {
19 class TestLayer {
20 public:
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) {
36 opacity_ = 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];
56 private:
57 TestLayer();
59 int transform_x_;
60 int transform_y_;
62 float opacity_;
63 float brightness_;
64 gfx::ScrollOffset scroll_offset_;
66 bool mutated_properties_[Animation::LAST_TARGET_PROPERTY + 1];
69 class TestHostClient : public MutatorHostClient {
70 public:
71 TestHostClient();
72 ~TestHostClient();
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(
93 int layer_id,
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() {
104 DCHECK(host_);
105 return host_.get();
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,
120 int transform_x,
121 int transform_y) const;
122 void ExpectScrollOffsetPropertyMutated(
123 int layer_id,
124 LayerTreeType tree_type,
125 const gfx::ScrollOffset& scroll_offset) const;
127 TestLayer* FindTestLayer(int layer_id, LayerTreeType tree_type) const;
129 private:
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 {
140 public:
141 TestAnimationDelegate();
143 void NotifyAnimationStarted(base::TimeTicks monotonic_time,
144 Animation::TargetProperty target_property,
145 int group) override;
146 void NotifyAnimationFinished(base::TimeTicks monotonic_time,
147 Animation::TargetProperty target_property,
148 int group) override;
149 bool started_;
150 bool finished_;
153 class AnimationTimelinesTest : public testing::Test {
154 public:
155 AnimationTimelinesTest();
156 ~AnimationTimelinesTest() override;
158 protected:
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_;
179 const int layer_id_;
181 scoped_refptr<AnimationTimeline> timeline_;
182 scoped_refptr<AnimationPlayer> player_;
184 scoped_refptr<AnimationTimeline> timeline_impl_;
185 scoped_refptr<AnimationPlayer> player_impl_;
188 } // namespace cc
190 #endif // CC_TEST_ANIMATION_TIMELINES_TEST_COMMON_H_