OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/animation/scrollbar_animation_controller_linear_fade.h" | 5 #include "cc/animation/scrollbar_animation_controller_linear_fade.h" |
6 | 6 |
7 #include "cc/layers/painted_scrollbar_layer_impl.h" | 7 #include "cc/layers/painted_scrollbar_layer_impl.h" |
8 #include "cc/test/fake_impl_proxy.h" | 8 #include "cc/test/fake_impl_proxy.h" |
9 #include "cc/test/fake_layer_tree_host_impl.h" | 9 #include "cc/test/fake_layer_tree_host_impl.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/gfx/frame_time.h" |
11 | 12 |
12 namespace cc { | 13 namespace cc { |
13 namespace { | 14 namespace { |
14 | 15 |
15 class ScrollbarAnimationControllerLinearFadeTest : public testing::Test { | 16 class ScrollbarAnimationControllerLinearFadeTest : public testing::Test { |
16 public: | 17 public: |
17 ScrollbarAnimationControllerLinearFadeTest() : host_impl_(&proxy_) {} | 18 ScrollbarAnimationControllerLinearFadeTest() : host_impl_(&proxy_) {} |
18 | 19 |
19 protected: | 20 protected: |
20 virtual void SetUp() { | 21 virtual void SetUp() { |
(...skipping 12 matching lines...) Expand all Loading... |
33 } | 34 } |
34 | 35 |
35 FakeImplProxy proxy_; | 36 FakeImplProxy proxy_; |
36 FakeLayerTreeHostImpl host_impl_; | 37 FakeLayerTreeHostImpl host_impl_; |
37 scoped_ptr<ScrollbarAnimationControllerLinearFade> scrollbar_controller_; | 38 scoped_ptr<ScrollbarAnimationControllerLinearFade> scrollbar_controller_; |
38 scoped_ptr<LayerImpl> scroll_layer_; | 39 scoped_ptr<LayerImpl> scroll_layer_; |
39 scoped_ptr<PaintedScrollbarLayerImpl> scrollbar_layer_; | 40 scoped_ptr<PaintedScrollbarLayerImpl> scrollbar_layer_; |
40 }; | 41 }; |
41 | 42 |
42 TEST_F(ScrollbarAnimationControllerLinearFadeTest, HiddenInBegin) { | 43 TEST_F(ScrollbarAnimationControllerLinearFadeTest, HiddenInBegin) { |
43 scrollbar_controller_->Animate(base::TimeTicks()); | 44 scrollbar_controller_->Animate(gfx::FrameTime()); |
44 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | 45 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); |
45 } | 46 } |
46 | 47 |
47 TEST_F(ScrollbarAnimationControllerLinearFadeTest, | 48 TEST_F(ScrollbarAnimationControllerLinearFadeTest, |
48 HiddenAfterNonScrollingGesture) { | 49 HiddenAfterNonScrollingGesture) { |
49 scrollbar_controller_->DidScrollGestureBegin(); | 50 scrollbar_controller_->DidScrollGestureBegin(); |
50 EXPECT_FALSE(scrollbar_controller_->IsAnimating()); | 51 EXPECT_FALSE(scrollbar_controller_->IsAnimating()); |
51 EXPECT_FALSE(scrollbar_controller_->Animate(base::TimeTicks())); | 52 EXPECT_FALSE(scrollbar_controller_->Animate(gfx::FrameTime())); |
52 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | 53 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); |
53 | 54 |
54 base::TimeTicks time; | 55 gfx::FrameTime time; |
55 time += base::TimeDelta::FromSeconds(100); | 56 time += base::TimeDelta::FromSeconds(100); |
56 EXPECT_FALSE(scrollbar_controller_->Animate(time)); | 57 EXPECT_FALSE(scrollbar_controller_->Animate(time)); |
57 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | 58 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); |
58 scrollbar_controller_->DidScrollGestureEnd(time); | 59 scrollbar_controller_->DidScrollGestureEnd(time); |
59 | 60 |
60 time += base::TimeDelta::FromSeconds(100); | 61 time += base::TimeDelta::FromSeconds(100); |
61 EXPECT_FALSE(scrollbar_controller_->IsAnimating()); | 62 EXPECT_FALSE(scrollbar_controller_->IsAnimating()); |
62 EXPECT_FALSE(scrollbar_controller_->Animate(time)); | 63 EXPECT_FALSE(scrollbar_controller_->Animate(time)); |
63 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | 64 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); |
64 } | 65 } |
65 | 66 |
66 TEST_F(ScrollbarAnimationControllerLinearFadeTest, AwakenByScrollingGesture) { | 67 TEST_F(ScrollbarAnimationControllerLinearFadeTest, AwakenByScrollingGesture) { |
67 base::TimeTicks time; | 68 gfx::FrameTime time; |
68 time += base::TimeDelta::FromSeconds(1); | 69 time += base::TimeDelta::FromSeconds(1); |
69 scrollbar_controller_->DidScrollGestureBegin(); | 70 scrollbar_controller_->DidScrollGestureBegin(); |
70 scrollbar_controller_->Animate(time); | 71 scrollbar_controller_->Animate(time); |
71 EXPECT_FALSE(scrollbar_controller_->IsAnimating()); | 72 EXPECT_FALSE(scrollbar_controller_->IsAnimating()); |
72 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | 73 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); |
73 | 74 |
74 EXPECT_FALSE(scrollbar_controller_->DidScrollUpdate(time)); | 75 EXPECT_FALSE(scrollbar_controller_->DidScrollUpdate(time)); |
75 EXPECT_FALSE(scrollbar_controller_->IsAnimating()); | 76 EXPECT_FALSE(scrollbar_controller_->IsAnimating()); |
76 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 77 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
77 | 78 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 time += base::TimeDelta::FromSeconds(1); | 122 time += base::TimeDelta::FromSeconds(1); |
122 scrollbar_controller_->Animate(time); | 123 scrollbar_controller_->Animate(time); |
123 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); | 124 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); |
124 | 125 |
125 time += base::TimeDelta::FromSeconds(1); | 126 time += base::TimeDelta::FromSeconds(1); |
126 scrollbar_controller_->Animate(time); | 127 scrollbar_controller_->Animate(time); |
127 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | 128 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); |
128 } | 129 } |
129 | 130 |
130 TEST_F(ScrollbarAnimationControllerLinearFadeTest, AwakenByProgrammaticScroll) { | 131 TEST_F(ScrollbarAnimationControllerLinearFadeTest, AwakenByProgrammaticScroll) { |
131 base::TimeTicks time; | 132 gfx::FrameTime time; |
132 time += base::TimeDelta::FromSeconds(1); | 133 time += base::TimeDelta::FromSeconds(1); |
133 EXPECT_TRUE(scrollbar_controller_->DidScrollUpdate(time)); | 134 EXPECT_TRUE(scrollbar_controller_->DidScrollUpdate(time)); |
134 EXPECT_TRUE(scrollbar_controller_->IsAnimating()); | 135 EXPECT_TRUE(scrollbar_controller_->IsAnimating()); |
135 EXPECT_EQ(2, scrollbar_controller_->DelayBeforeStart(time).InSeconds()); | 136 EXPECT_EQ(2, scrollbar_controller_->DelayBeforeStart(time).InSeconds()); |
136 scrollbar_controller_->Animate(time); | 137 scrollbar_controller_->Animate(time); |
137 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 138 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
138 | 139 |
139 time += base::TimeDelta::FromSeconds(1); | 140 time += base::TimeDelta::FromSeconds(1); |
140 scrollbar_controller_->Animate(time); | 141 scrollbar_controller_->Animate(time); |
141 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 142 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 scrollbar_controller_->Animate(time); | 176 scrollbar_controller_->Animate(time); |
176 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); | 177 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); |
177 | 178 |
178 time += base::TimeDelta::FromSeconds(1); | 179 time += base::TimeDelta::FromSeconds(1); |
179 scrollbar_controller_->Animate(time); | 180 scrollbar_controller_->Animate(time); |
180 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | 181 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); |
181 } | 182 } |
182 | 183 |
183 TEST_F(ScrollbarAnimationControllerLinearFadeTest, | 184 TEST_F(ScrollbarAnimationControllerLinearFadeTest, |
184 AnimationPreservedByNonScrollingGesture) { | 185 AnimationPreservedByNonScrollingGesture) { |
185 base::TimeTicks time; | 186 gfx::FrameTime time; |
186 time += base::TimeDelta::FromSeconds(1); | 187 time += base::TimeDelta::FromSeconds(1); |
187 EXPECT_TRUE(scrollbar_controller_->DidScrollUpdate(time)); | 188 EXPECT_TRUE(scrollbar_controller_->DidScrollUpdate(time)); |
188 EXPECT_TRUE(scrollbar_controller_->IsAnimating()); | 189 EXPECT_TRUE(scrollbar_controller_->IsAnimating()); |
189 scrollbar_controller_->Animate(time); | 190 scrollbar_controller_->Animate(time); |
190 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 191 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
191 | 192 |
192 time += base::TimeDelta::FromSeconds(3); | 193 time += base::TimeDelta::FromSeconds(3); |
193 scrollbar_controller_->Animate(time); | 194 scrollbar_controller_->Animate(time); |
194 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); | 195 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); |
195 | 196 |
196 scrollbar_controller_->DidScrollGestureBegin(); | 197 scrollbar_controller_->DidScrollGestureBegin(); |
197 EXPECT_TRUE(scrollbar_controller_->IsAnimating()); | 198 EXPECT_TRUE(scrollbar_controller_->IsAnimating()); |
198 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); | 199 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); |
199 | 200 |
200 time += base::TimeDelta::FromSeconds(1); | 201 time += base::TimeDelta::FromSeconds(1); |
201 scrollbar_controller_->Animate(time); | 202 scrollbar_controller_->Animate(time); |
202 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); | 203 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); |
203 | 204 |
204 scrollbar_controller_->DidScrollGestureEnd(time); | 205 scrollbar_controller_->DidScrollGestureEnd(time); |
205 EXPECT_TRUE(scrollbar_controller_->IsAnimating()); | 206 EXPECT_TRUE(scrollbar_controller_->IsAnimating()); |
206 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); | 207 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); |
207 | 208 |
208 time += base::TimeDelta::FromSeconds(1); | 209 time += base::TimeDelta::FromSeconds(1); |
209 EXPECT_FALSE(scrollbar_controller_->Animate(time)); | 210 EXPECT_FALSE(scrollbar_controller_->Animate(time)); |
210 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | 211 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); |
211 } | 212 } |
212 | 213 |
213 TEST_F(ScrollbarAnimationControllerLinearFadeTest, | 214 TEST_F(ScrollbarAnimationControllerLinearFadeTest, |
214 AnimationOverriddenByScrollingGesture) { | 215 AnimationOverriddenByScrollingGesture) { |
215 base::TimeTicks time; | 216 gfx::FrameTime time; |
216 time += base::TimeDelta::FromSeconds(1); | 217 time += base::TimeDelta::FromSeconds(1); |
217 EXPECT_TRUE(scrollbar_controller_->DidScrollUpdate(time)); | 218 EXPECT_TRUE(scrollbar_controller_->DidScrollUpdate(time)); |
218 EXPECT_TRUE(scrollbar_controller_->IsAnimating()); | 219 EXPECT_TRUE(scrollbar_controller_->IsAnimating()); |
219 scrollbar_controller_->Animate(time); | 220 scrollbar_controller_->Animate(time); |
220 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 221 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
221 | 222 |
222 time += base::TimeDelta::FromSeconds(3); | 223 time += base::TimeDelta::FromSeconds(3); |
223 scrollbar_controller_->Animate(time); | 224 scrollbar_controller_->Animate(time); |
224 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); | 225 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); |
225 | 226 |
(...skipping 11 matching lines...) Expand all Loading... |
237 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity()); | 238 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity()); |
238 | 239 |
239 time += base::TimeDelta::FromSeconds(1); | 240 time += base::TimeDelta::FromSeconds(1); |
240 scrollbar_controller_->DidScrollGestureEnd(time); | 241 scrollbar_controller_->DidScrollGestureEnd(time); |
241 EXPECT_TRUE(scrollbar_controller_->IsAnimating()); | 242 EXPECT_TRUE(scrollbar_controller_->IsAnimating()); |
242 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity()); | 243 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity()); |
243 } | 244 } |
244 | 245 |
245 } // namespace | 246 } // namespace |
246 } // namespace cc | 247 } // namespace cc |
OLD | NEW |