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/solid_color_scrollbar_layer_impl.h" | 7 #include "cc/layers/solid_color_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 "cc/test/geometry_test_utils.h" | |
10 #include "cc/test/test_shared_bitmap_manager.h" | 11 #include "cc/test/test_shared_bitmap_manager.h" |
12 #include "cc/trees/layer_tree_impl.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 namespace cc { | 15 namespace cc { |
14 namespace { | 16 namespace { |
15 | 17 |
16 class ScrollbarAnimationControllerLinearFadeTest | 18 class ScrollbarAnimationControllerLinearFadeTest |
17 : public testing::Test, | 19 : public testing::Test, |
18 public ScrollbarAnimationControllerClient { | 20 public ScrollbarAnimationControllerClient { |
19 public: | 21 public: |
20 ScrollbarAnimationControllerLinearFadeTest() | 22 ScrollbarAnimationControllerLinearFadeTest() |
(...skipping 13 matching lines...) Expand all Loading... | |
34 const int kThumbThickness = 10; | 36 const int kThumbThickness = 10; |
35 const int kTrackStart = 0; | 37 const int kTrackStart = 0; |
36 const bool kIsLeftSideVerticalScrollbar = false; | 38 const bool kIsLeftSideVerticalScrollbar = false; |
37 const bool kIsOverlayScrollbar = true; // Allow opacity animations. | 39 const bool kIsOverlayScrollbar = true; // Allow opacity animations. |
38 | 40 |
39 scoped_ptr<LayerImpl> scroll_layer = | 41 scoped_ptr<LayerImpl> scroll_layer = |
40 LayerImpl::Create(host_impl_.active_tree(), 1); | 42 LayerImpl::Create(host_impl_.active_tree(), 1); |
41 scrollbar_layer_ = | 43 scrollbar_layer_ = |
42 SolidColorScrollbarLayerImpl::Create(host_impl_.active_tree(), | 44 SolidColorScrollbarLayerImpl::Create(host_impl_.active_tree(), |
43 2, | 45 2, |
44 HORIZONTAL, | 46 orientation(), |
45 kThumbThickness, | 47 kThumbThickness, |
46 kTrackStart, | 48 kTrackStart, |
47 kIsLeftSideVerticalScrollbar, | 49 kIsLeftSideVerticalScrollbar, |
48 kIsOverlayScrollbar); | 50 kIsOverlayScrollbar); |
49 clip_layer_ = LayerImpl::Create(host_impl_.active_tree(), 3); | 51 clip_layer_ = LayerImpl::Create(host_impl_.active_tree(), 3); |
50 scroll_layer->SetScrollClipLayer(clip_layer_->id()); | 52 scroll_layer->SetScrollClipLayer(clip_layer_->id()); |
51 LayerImpl* scroll_layer_ptr = scroll_layer.get(); | 53 LayerImpl* scroll_layer_ptr = scroll_layer.get(); |
52 clip_layer_->AddChild(scroll_layer.Pass()); | 54 clip_layer_->AddChild(scroll_layer.Pass()); |
53 | 55 |
54 scrollbar_layer_->SetScrollLayerAndClipLayerByIds(scroll_layer_ptr->id(), | 56 scrollbar_layer_->SetScrollLayerAndClipLayerByIds(scroll_layer_ptr->id(), |
55 clip_layer_->id()); | 57 clip_layer_->id()); |
56 clip_layer_->SetBounds(gfx::Size(100, 100)); | 58 clip_layer_->SetBounds(gfx::Size(100, 100)); |
57 scroll_layer_ptr->SetBounds(gfx::Size(50, 50)); | 59 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
58 | 60 |
59 scrollbar_controller_ = ScrollbarAnimationControllerLinearFade::Create( | 61 scrollbar_controller_ = ScrollbarAnimationControllerLinearFade::Create( |
60 scroll_layer_ptr, | 62 scroll_layer_ptr, |
61 this, | 63 this, |
62 base::TimeDelta::FromSeconds(2), | 64 base::TimeDelta::FromSeconds(2), |
63 base::TimeDelta::FromSeconds(5), | 65 base::TimeDelta::FromSeconds(5), |
64 base::TimeDelta::FromSeconds(3)); | 66 base::TimeDelta::FromSeconds(3)); |
65 } | 67 } |
66 | 68 |
69 virtual ScrollbarOrientation orientation() const { return HORIZONTAL; } | |
70 | |
67 FakeImplProxy proxy_; | 71 FakeImplProxy proxy_; |
68 TestSharedBitmapManager shared_bitmap_manager_; | 72 TestSharedBitmapManager shared_bitmap_manager_; |
69 FakeLayerTreeHostImpl host_impl_; | 73 FakeLayerTreeHostImpl host_impl_; |
70 scoped_ptr<ScrollbarAnimationControllerLinearFade> scrollbar_controller_; | 74 scoped_ptr<ScrollbarAnimationControllerLinearFade> scrollbar_controller_; |
71 scoped_ptr<LayerImpl> clip_layer_; | 75 scoped_ptr<LayerImpl> clip_layer_; |
72 scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_; | 76 scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_; |
73 | 77 |
74 base::Closure start_fade_; | 78 base::Closure start_fade_; |
75 base::TimeDelta delay_; | 79 base::TimeDelta delay_; |
76 int needs_frame_count_; | 80 int needs_frame_count_; |
77 }; | 81 }; |
78 | 82 |
83 class VerticalScrollbarAnimationControllerLinearFadeTest | |
84 : public ScrollbarAnimationControllerLinearFadeTest { | |
85 protected: | |
86 virtual ScrollbarOrientation orientation() const override { return VERTICAL; } | |
87 }; | |
88 | |
79 TEST_F(ScrollbarAnimationControllerLinearFadeTest, DelayAnimationOnResize) { | 89 TEST_F(ScrollbarAnimationControllerLinearFadeTest, DelayAnimationOnResize) { |
80 scrollbar_layer_->SetOpacity(0.0f); | 90 scrollbar_layer_->SetOpacity(0.0f); |
81 scrollbar_controller_->DidScrollBegin(); | 91 scrollbar_controller_->DidScrollBegin(); |
82 scrollbar_controller_->DidScrollUpdate(true); | 92 scrollbar_controller_->DidScrollUpdate(true); |
83 scrollbar_controller_->DidScrollEnd(); | 93 scrollbar_controller_->DidScrollEnd(); |
84 // Normal Animation delay of 2 seconds. | 94 // Normal Animation delay of 2 seconds. |
85 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 95 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
86 EXPECT_EQ(delay_, base::TimeDelta::FromSeconds(2)); | 96 EXPECT_EQ(delay_, base::TimeDelta::FromSeconds(2)); |
87 | 97 |
88 scrollbar_layer_->SetOpacity(0.0f); | 98 scrollbar_layer_->SetOpacity(0.0f); |
(...skipping 23 matching lines...) Expand all Loading... | |
112 | 122 |
113 EXPECT_TRUE(start_fade_.Equals(base::Closure())); | 123 EXPECT_TRUE(start_fade_.Equals(base::Closure())); |
114 | 124 |
115 time += base::TimeDelta::FromSeconds(100); | 125 time += base::TimeDelta::FromSeconds(100); |
116 scrollbar_controller_->Animate(time); | 126 scrollbar_controller_->Animate(time); |
117 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | 127 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); |
118 | 128 |
119 EXPECT_EQ(0, needs_frame_count_); | 129 EXPECT_EQ(0, needs_frame_count_); |
120 } | 130 } |
121 | 131 |
132 TEST_F(ScrollbarAnimationControllerLinearFadeTest, HideOnResize) { | |
133 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); | |
134 ASSERT_TRUE(scroll_layer); | |
135 EXPECT_SIZE_EQ(gfx::Size(200, 200), scroll_layer->bounds()); | |
136 | |
137 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); | |
138 | |
139 clip_layer_->SetBounds(gfx::Size(100, 200)); | |
140 EXPECT_SIZE_EQ(gfx::Size(100, 200), clip_layer_->bounds()); | |
141 | |
142 base::TimeTicks time; | |
aelias_OOO_until_Jul13
2014/10/14 23:23:41
You're not doing anything with this time variable?
| |
143 time += base::TimeDelta::FromSeconds(1); | |
144 scrollbar_controller_->DidScrollBegin(); | |
145 | |
146 scrollbar_controller_->DidScrollUpdate(false); | |
147 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | |
148 | |
149 scrollbar_controller_->DidScrollEnd(); | |
150 | |
151 clip_layer_->SetBounds(gfx::Size(200, 100)); | |
152 EXPECT_SIZE_EQ(gfx::Size(200, 100), clip_layer_->bounds()); | |
153 | |
154 time = base::TimeTicks(); | |
155 | |
156 time += base::TimeDelta::FromSeconds(1); | |
157 scrollbar_controller_->DidScrollBegin(); | |
158 | |
159 scrollbar_controller_->DidScrollUpdate(false); | |
160 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | |
161 | |
162 scrollbar_controller_->DidScrollEnd(); | |
163 } | |
164 | |
165 TEST_F(VerticalScrollbarAnimationControllerLinearFadeTest, HideOnResize) { | |
166 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); | |
167 ASSERT_TRUE(scroll_layer); | |
168 EXPECT_SIZE_EQ(gfx::Size(200, 200), scroll_layer->bounds()); | |
169 | |
170 EXPECT_EQ(VERTICAL, scrollbar_layer_->orientation()); | |
171 | |
172 clip_layer_->SetBounds(gfx::Size(100, 200)); | |
173 EXPECT_SIZE_EQ(gfx::Size(100, 200), clip_layer_->bounds()); | |
174 | |
175 base::TimeTicks time; | |
176 time += base::TimeDelta::FromSeconds(1); | |
177 scrollbar_controller_->DidScrollBegin(); | |
178 | |
179 scrollbar_controller_->DidScrollUpdate(false); | |
180 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | |
181 | |
182 scrollbar_controller_->DidScrollEnd(); | |
183 | |
184 clip_layer_->SetBounds(gfx::Size(200, 100)); | |
185 EXPECT_SIZE_EQ(gfx::Size(200, 100), clip_layer_->bounds()); | |
186 | |
187 time = base::TimeTicks(); | |
188 | |
189 time += base::TimeDelta::FromSeconds(1); | |
190 scrollbar_controller_->DidScrollBegin(); | |
191 | |
192 scrollbar_controller_->DidScrollUpdate(false); | |
193 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | |
194 | |
195 scrollbar_controller_->DidScrollEnd(); | |
196 } | |
197 | |
198 TEST_F(ScrollbarAnimationControllerLinearFadeTest, | |
199 HideOnUserNonScrollableHorz) { | |
200 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); | |
201 | |
202 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); | |
203 ASSERT_TRUE(scroll_layer); | |
204 scroll_layer->set_user_scrollable_horizontal(false); | |
205 | |
206 base::TimeTicks time; | |
207 time += base::TimeDelta::FromSeconds(1); | |
208 scrollbar_controller_->DidScrollBegin(); | |
209 | |
210 scrollbar_controller_->DidScrollUpdate(false); | |
211 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | |
212 | |
213 scrollbar_controller_->DidScrollEnd(); | |
214 } | |
215 | |
216 TEST_F(ScrollbarAnimationControllerLinearFadeTest, | |
217 ShowOnUserNonScrollableVert) { | |
218 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); | |
219 | |
220 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); | |
221 ASSERT_TRUE(scroll_layer); | |
222 scroll_layer->set_user_scrollable_vertical(false); | |
223 | |
224 base::TimeTicks time; | |
225 time += base::TimeDelta::FromSeconds(1); | |
226 scrollbar_controller_->DidScrollBegin(); | |
227 | |
228 scrollbar_controller_->DidScrollUpdate(false); | |
229 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | |
230 | |
231 scrollbar_controller_->DidScrollEnd(); | |
232 } | |
233 | |
234 TEST_F(VerticalScrollbarAnimationControllerLinearFadeTest, | |
235 HideOnUserNonScrollableVert) { | |
236 EXPECT_EQ(VERTICAL, scrollbar_layer_->orientation()); | |
237 | |
238 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); | |
239 ASSERT_TRUE(scroll_layer); | |
240 scroll_layer->set_user_scrollable_vertical(false); | |
241 | |
242 base::TimeTicks time; | |
243 time += base::TimeDelta::FromSeconds(1); | |
244 scrollbar_controller_->DidScrollBegin(); | |
245 | |
246 scrollbar_controller_->DidScrollUpdate(false); | |
247 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | |
248 | |
249 scrollbar_controller_->DidScrollEnd(); | |
250 } | |
251 | |
252 TEST_F(VerticalScrollbarAnimationControllerLinearFadeTest, | |
253 ShowOnUserNonScrollableHorz) { | |
254 EXPECT_EQ(VERTICAL, scrollbar_layer_->orientation()); | |
255 | |
256 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); | |
257 ASSERT_TRUE(scroll_layer); | |
258 scroll_layer->set_user_scrollable_horizontal(false); | |
259 | |
260 base::TimeTicks time; | |
261 time += base::TimeDelta::FromSeconds(1); | |
262 scrollbar_controller_->DidScrollBegin(); | |
263 | |
264 scrollbar_controller_->DidScrollUpdate(false); | |
265 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | |
266 | |
267 scrollbar_controller_->DidScrollEnd(); | |
268 } | |
269 | |
122 TEST_F(ScrollbarAnimationControllerLinearFadeTest, AwakenByScrollingGesture) { | 270 TEST_F(ScrollbarAnimationControllerLinearFadeTest, AwakenByScrollingGesture) { |
123 base::TimeTicks time; | 271 base::TimeTicks time; |
124 time += base::TimeDelta::FromSeconds(1); | 272 time += base::TimeDelta::FromSeconds(1); |
125 scrollbar_controller_->DidScrollBegin(); | 273 scrollbar_controller_->DidScrollBegin(); |
126 | 274 |
127 scrollbar_controller_->DidScrollUpdate(false); | 275 scrollbar_controller_->DidScrollUpdate(false); |
128 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 276 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
129 | 277 |
130 EXPECT_TRUE(start_fade_.Equals(base::Closure())); | 278 EXPECT_TRUE(start_fade_.Equals(base::Closure())); |
131 | 279 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 scrollbar_controller_->DidScrollUpdate(false); | 425 scrollbar_controller_->DidScrollUpdate(false); |
278 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity()); | 426 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity()); |
279 | 427 |
280 time += base::TimeDelta::FromSeconds(1); | 428 time += base::TimeDelta::FromSeconds(1); |
281 scrollbar_controller_->DidScrollEnd(); | 429 scrollbar_controller_->DidScrollEnd(); |
282 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity()); | 430 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity()); |
283 } | 431 } |
284 | 432 |
285 } // namespace | 433 } // namespace |
286 } // namespace cc | 434 } // namespace cc |
OLD | NEW |