OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/input/scrollbar_animation_controller.h" | 5 #include "cc/input/scrollbar_animation_controller.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_task_runner_provider.h" | 8 #include "cc/test/fake_impl_task_runner_provider.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/geometry_test_utils.h" |
11 #include "cc/test/test_task_graph_runner.h" | 11 #include "cc/test/test_task_graph_runner.h" |
12 #include "cc/trees/layer_tree_impl.h" | 12 #include "cc/trees/layer_tree_impl.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 using testing::AtLeast; | 16 using testing::AtLeast; |
17 using testing::Mock; | 17 using testing::Mock; |
18 using testing::NiceMock; | 18 using testing::NiceMock; |
19 using testing::_; | 19 using testing::_; |
20 | 20 |
21 namespace cc { | 21 namespace cc { |
22 namespace { | 22 namespace { |
23 | 23 |
24 const float kIdleThicknessScale = | 24 const float kIdleThicknessScale = |
25 SingleScrollbarAnimationControllerThinning::kIdleThicknessScale; | 25 SingleScrollbarAnimationControllerThinning::kIdleThicknessScale; |
26 const float kDefaultMouseMoveDistanceToTriggerAnimation = | 26 const float kDefaultMouseMoveDistanceToTriggerAnimation = |
27 SingleScrollbarAnimationControllerThinning:: | 27 SingleScrollbarAnimationControllerThinning:: |
28 kDefaultMouseMoveDistanceToTriggerAnimation; | 28 kDefaultMouseMoveDistanceToTriggerAnimation; |
| 29 const float kMouseMoveDistanceToTriggerShow = |
| 30 ScrollbarAnimationController::kMouseMoveDistanceToTriggerShow; |
| 31 const int kThumbThickness = 10; |
29 | 32 |
30 class MockScrollbarAnimationControllerClient | 33 class MockScrollbarAnimationControllerClient |
31 : public ScrollbarAnimationControllerClient { | 34 : public ScrollbarAnimationControllerClient { |
32 public: | 35 public: |
33 explicit MockScrollbarAnimationControllerClient(LayerTreeHostImpl* host_impl) | 36 explicit MockScrollbarAnimationControllerClient(LayerTreeHostImpl* host_impl) |
34 : host_impl_(host_impl) {} | 37 : host_impl_(host_impl) {} |
35 virtual ~MockScrollbarAnimationControllerClient() {} | 38 virtual ~MockScrollbarAnimationControllerClient() {} |
36 | 39 |
37 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade, | 40 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade, |
38 base::TimeDelta delay) override { | 41 base::TimeDelta delay) override { |
(...skipping 21 matching lines...) Expand all Loading... |
60 ScrollbarAnimationControllerAuraOverlayTest() | 63 ScrollbarAnimationControllerAuraOverlayTest() |
61 : host_impl_(&task_runner_provider_, &task_graph_runner_), | 64 : host_impl_(&task_runner_provider_, &task_graph_runner_), |
62 client_(&host_impl_) {} | 65 client_(&host_impl_) {} |
63 | 66 |
64 void ExpectScrollbarsOpacity(float opacity) { | 67 void ExpectScrollbarsOpacity(float opacity) { |
65 EXPECT_FLOAT_EQ(opacity, v_scrollbar_layer_->Opacity()); | 68 EXPECT_FLOAT_EQ(opacity, v_scrollbar_layer_->Opacity()); |
66 EXPECT_FLOAT_EQ(opacity, h_scrollbar_layer_->Opacity()); | 69 EXPECT_FLOAT_EQ(opacity, h_scrollbar_layer_->Opacity()); |
67 } | 70 } |
68 | 71 |
69 protected: | 72 protected: |
70 const base::TimeDelta kDelayBeforeStarting = base::TimeDelta::FromSeconds(2); | 73 const base::TimeDelta kShowDelay = base::TimeDelta::FromSeconds(4); |
71 const base::TimeDelta kResizeDelayBeforeStarting = | 74 const base::TimeDelta kFadeOutDelay = base::TimeDelta::FromSeconds(2); |
72 base::TimeDelta::FromSeconds(5); | 75 const base::TimeDelta kResizeFadeOutDelay = base::TimeDelta::FromSeconds(5); |
73 const base::TimeDelta kFadeDuration = base::TimeDelta::FromSeconds(3); | 76 const base::TimeDelta kFadeOutDuration = base::TimeDelta::FromSeconds(3); |
74 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2); | 77 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2); |
75 | 78 |
76 void SetUp() override { | 79 void SetUp() override { |
77 std::unique_ptr<LayerImpl> scroll_layer = | 80 std::unique_ptr<LayerImpl> scroll_layer = |
78 LayerImpl::Create(host_impl_.active_tree(), 1); | 81 LayerImpl::Create(host_impl_.active_tree(), 1); |
79 std::unique_ptr<LayerImpl> clip = | 82 std::unique_ptr<LayerImpl> clip = |
80 LayerImpl::Create(host_impl_.active_tree(), 2); | 83 LayerImpl::Create(host_impl_.active_tree(), 2); |
81 clip_layer_ = clip.get(); | 84 clip_layer_ = clip.get(); |
82 scroll_layer->SetScrollClipLayer(clip_layer_->id()); | 85 scroll_layer->SetScrollClipLayer(clip_layer_->id()); |
83 LayerImpl* scroll_layer_ptr = scroll_layer.get(); | 86 LayerImpl* scroll_layer_ptr = scroll_layer.get(); |
84 | 87 |
85 const int kThumbThickness = 10; | |
86 const int kTrackStart = 0; | 88 const int kTrackStart = 0; |
87 const bool kIsLeftSideVerticalScrollbar = false; | 89 const bool kIsLeftSideVerticalScrollbar = false; |
88 const bool kIsOverlayScrollbar = true; | 90 const bool kIsOverlayScrollbar = true; |
89 | 91 |
90 std::unique_ptr<SolidColorScrollbarLayerImpl> h_scrollbar = | 92 std::unique_ptr<SolidColorScrollbarLayerImpl> h_scrollbar = |
91 SolidColorScrollbarLayerImpl::Create( | 93 SolidColorScrollbarLayerImpl::Create( |
92 host_impl_.active_tree(), 3, HORIZONTAL, kThumbThickness, | 94 host_impl_.active_tree(), 3, HORIZONTAL, kThumbThickness, |
93 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); | 95 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); |
94 std::unique_ptr<SolidColorScrollbarLayerImpl> v_scrollbar = | 96 std::unique_ptr<SolidColorScrollbarLayerImpl> v_scrollbar = |
95 SolidColorScrollbarLayerImpl::Create( | 97 SolidColorScrollbarLayerImpl::Create( |
(...skipping 10 matching lines...) Expand all Loading... |
106 v_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); | 108 v_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); |
107 h_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); | 109 h_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); |
108 v_scrollbar_layer_->test_properties()->opacity_can_animate = true; | 110 v_scrollbar_layer_->test_properties()->opacity_can_animate = true; |
109 h_scrollbar_layer_->test_properties()->opacity_can_animate = true; | 111 h_scrollbar_layer_->test_properties()->opacity_can_animate = true; |
110 clip_layer_->SetBounds(gfx::Size(100, 100)); | 112 clip_layer_->SetBounds(gfx::Size(100, 100)); |
111 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); | 113 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
112 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); | 114 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
113 | 115 |
114 scrollbar_controller_ = ScrollbarAnimationController:: | 116 scrollbar_controller_ = ScrollbarAnimationController:: |
115 CreateScrollbarAnimationControllerAuraOverlay( | 117 CreateScrollbarAnimationControllerAuraOverlay( |
116 scroll_layer_ptr->id(), &client_, kDelayBeforeStarting, | 118 scroll_layer_ptr->id(), &client_, kShowDelay, kFadeOutDelay, |
117 kResizeDelayBeforeStarting, kFadeDuration, kThinningDuration); | 119 kResizeFadeOutDelay, kFadeOutDuration, kThinningDuration); |
118 } | 120 } |
119 | 121 |
120 FakeImplTaskRunnerProvider task_runner_provider_; | 122 FakeImplTaskRunnerProvider task_runner_provider_; |
121 TestTaskGraphRunner task_graph_runner_; | 123 TestTaskGraphRunner task_graph_runner_; |
122 FakeLayerTreeHostImpl host_impl_; | 124 FakeLayerTreeHostImpl host_impl_; |
123 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; | 125 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; |
124 LayerImpl* clip_layer_; | 126 LayerImpl* clip_layer_; |
125 SolidColorScrollbarLayerImpl* v_scrollbar_layer_; | 127 SolidColorScrollbarLayerImpl* v_scrollbar_layer_; |
126 SolidColorScrollbarLayerImpl* h_scrollbar_layer_; | 128 SolidColorScrollbarLayerImpl* h_scrollbar_layer_; |
127 NiceMock<MockScrollbarAnimationControllerClient> client_; | 129 NiceMock<MockScrollbarAnimationControllerClient> client_; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); | 208 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); |
207 | 209 |
208 scrollbar_controller_->DidScrollUpdate(false); | 210 scrollbar_controller_->DidScrollUpdate(false); |
209 ExpectScrollbarsOpacity(1); | 211 ExpectScrollbarsOpacity(1); |
210 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); | 212 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); |
211 | 213 |
212 scrollbar_controller_->DidScrollEnd(); | 214 scrollbar_controller_->DidScrollEnd(); |
213 ExpectScrollbarsOpacity(1); | 215 ExpectScrollbarsOpacity(1); |
214 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); | 216 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); |
215 | 217 |
216 // An animation should have been enqueued. | 218 // An fade out animation should have been enqueued. |
217 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 219 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
218 EXPECT_FALSE(client_.start_fade().is_null()); | 220 EXPECT_FALSE(client_.start_fade().is_null()); |
219 client_.start_fade().Run(); | 221 client_.start_fade().Run(); |
220 | 222 |
221 // Scrollbar should fade out over kFadeDuration. | 223 // Scrollbar should fade out over kFadeOutDuration. |
222 scrollbar_controller_->Animate(time); | 224 scrollbar_controller_->Animate(time); |
223 time += kFadeDuration; | 225 time += kFadeOutDuration; |
224 scrollbar_controller_->Animate(time); | 226 scrollbar_controller_->Animate(time); |
225 | 227 |
226 ExpectScrollbarsOpacity(0); | 228 ExpectScrollbarsOpacity(0); |
227 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); | 229 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); |
228 } | 230 } |
229 | 231 |
230 // Scroll content. Move the mouse near the scrollbar and confirm it becomes | 232 // Scroll content. Move the mouse near the scrollbar and confirm it becomes |
231 // thick. Ensure it remains visible as long as the mouse is near the scrollbar. | 233 // thick. Ensure it remains visible as long as the mouse is near the scrollbar. |
232 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveNearAndDontFadeOut) { | 234 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveNearAndDontFadeOut) { |
233 base::TimeTicks time; | 235 base::TimeTicks time; |
234 time += base::TimeDelta::FromSeconds(1); | 236 time += base::TimeDelta::FromSeconds(1); |
235 | 237 |
236 scrollbar_controller_->DidScrollBegin(); | 238 scrollbar_controller_->DidScrollBegin(); |
237 scrollbar_controller_->DidScrollUpdate(false); | 239 scrollbar_controller_->DidScrollUpdate(false); |
238 scrollbar_controller_->DidScrollEnd(); | 240 scrollbar_controller_->DidScrollEnd(); |
239 | 241 |
240 // An animation should have been enqueued. | 242 // An fade out animation should have been enqueued. |
241 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 243 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
242 EXPECT_FALSE(client_.start_fade().is_null()); | 244 EXPECT_FALSE(client_.start_fade().is_null()); |
243 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 245 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
244 | 246 |
245 // Now move the mouse near the scrollbar. This should cancel the currently | 247 // Now move the mouse near the scrollbar. This should cancel the currently |
246 // queued fading animation and start animating thickness. | 248 // queued fading animation and start animating thickness. |
247 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); | 249 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); |
248 ExpectScrollbarsOpacity(1); | 250 ExpectScrollbarsOpacity(1); |
249 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 251 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
250 v_scrollbar_layer_->thumb_thickness_scale_factor()); | 252 v_scrollbar_layer_->thumb_thickness_scale_factor()); |
251 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 253 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
252 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 254 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
253 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 255 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
254 | 256 |
255 // Vertical scrollbar should become thick. | 257 // Vertical scrollbar should become thick. |
256 scrollbar_controller_->Animate(time); | 258 scrollbar_controller_->Animate(time); |
257 time += kThinningDuration; | 259 time += kThinningDuration; |
258 scrollbar_controller_->Animate(time); | 260 scrollbar_controller_->Animate(time); |
259 ExpectScrollbarsOpacity(1); | 261 ExpectScrollbarsOpacity(1); |
260 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 262 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
261 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 263 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
262 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 264 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
263 | 265 |
264 // Mouse is still near the Scrollbar. Once the thickness animation is | 266 // Mouse is still near the Scrollbar. Once the thickness animation is |
265 // complete, the queued delayed fade animation should be either cancelled or | 267 // complete, the queued delayed fade out animation should be either cancelled |
266 // null. | 268 // or null. |
267 EXPECT_TRUE(client_.start_fade().is_null() || | 269 EXPECT_TRUE(client_.start_fade().is_null() || |
268 client_.start_fade().IsCancelled()); | 270 client_.start_fade().IsCancelled()); |
269 } | 271 } |
270 | 272 |
271 // Scroll content. Move the mouse over the scrollbar and confirm it becomes | 273 // Scroll content. Move the mouse over the scrollbar and confirm it becomes |
272 // thick. Ensure it remains visible as long as the mouse is over the scrollbar. | 274 // thick. Ensure it remains visible as long as the mouse is over the scrollbar. |
273 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveOverAndDontFadeOut) { | 275 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveOverAndDontFadeOut) { |
274 base::TimeTicks time; | 276 base::TimeTicks time; |
275 time += base::TimeDelta::FromSeconds(1); | 277 time += base::TimeDelta::FromSeconds(1); |
276 | 278 |
277 scrollbar_controller_->DidScrollBegin(); | 279 scrollbar_controller_->DidScrollBegin(); |
278 scrollbar_controller_->DidScrollUpdate(false); | 280 scrollbar_controller_->DidScrollUpdate(false); |
279 scrollbar_controller_->DidScrollEnd(); | 281 scrollbar_controller_->DidScrollEnd(); |
280 | 282 |
281 // An animation should have been enqueued. | 283 // An fade out animation should have been enqueued. |
282 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 284 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
283 EXPECT_FALSE(client_.start_fade().is_null()); | 285 EXPECT_FALSE(client_.start_fade().is_null()); |
284 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 286 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
285 | 287 |
286 // Now move the mouse over the scrollbar. This should cancel the currently | 288 // Now move the mouse over the scrollbar. This should cancel the currently |
287 // queued fading animation and start animating thickness. | 289 // queued fading animation and start animating thickness. |
288 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); | 290 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); |
289 ExpectScrollbarsOpacity(1); | 291 ExpectScrollbarsOpacity(1); |
290 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 292 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
291 v_scrollbar_layer_->thumb_thickness_scale_factor()); | 293 v_scrollbar_layer_->thumb_thickness_scale_factor()); |
292 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 294 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
293 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 295 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
294 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 296 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
295 | 297 |
296 // Vertical scrollbar should become thick. | 298 // Vertical scrollbar should become thick. |
297 scrollbar_controller_->Animate(time); | 299 scrollbar_controller_->Animate(time); |
298 time += kThinningDuration; | 300 time += kThinningDuration; |
299 scrollbar_controller_->Animate(time); | 301 scrollbar_controller_->Animate(time); |
300 ExpectScrollbarsOpacity(1); | 302 ExpectScrollbarsOpacity(1); |
301 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 303 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
302 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 304 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
303 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 305 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
304 | 306 |
305 // Mouse is still over the Scrollbar. Once the thickness animation is | 307 // Mouse is still over the Scrollbar. Once the thickness animation is |
306 // complete, the queued delayed fade animation should be either cancelled or | 308 // complete, the queued delayed fade out animation should be either cancelled |
307 // null. | 309 // or null. |
308 EXPECT_TRUE(client_.start_fade().is_null() || | 310 EXPECT_TRUE(client_.start_fade().is_null() || |
309 client_.start_fade().IsCancelled()); | 311 client_.start_fade().IsCancelled()); |
310 } | 312 } |
311 | 313 |
312 // Make sure a scrollbar captured before the thickening animation doesn't try | 314 // Make sure a scrollbar captured before the thickening animation doesn't try |
313 // to fade out. | 315 // to fade out. |
314 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, | 316 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, |
315 DontFadeWhileCapturedBeforeThick) { | 317 DontFadeWhileCapturedBeforeThick) { |
316 base::TimeTicks time; | 318 base::TimeTicks time; |
317 time += base::TimeDelta::FromSeconds(1); | 319 time += base::TimeDelta::FromSeconds(1); |
318 | 320 |
319 scrollbar_controller_->DidScrollBegin(); | 321 scrollbar_controller_->DidScrollBegin(); |
320 scrollbar_controller_->DidScrollUpdate(false); | 322 scrollbar_controller_->DidScrollUpdate(false); |
321 scrollbar_controller_->DidScrollEnd(); | 323 scrollbar_controller_->DidScrollEnd(); |
322 | 324 |
323 // An animation should have been enqueued. | 325 // An fade out animation should have been enqueued. |
324 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 326 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
325 EXPECT_FALSE(client_.start_fade().is_null()); | 327 EXPECT_FALSE(client_.start_fade().is_null()); |
326 | 328 |
327 // Now move the mouse over the scrollbar and capture it. It should become | 329 // Now move the mouse over the scrollbar and capture it. It should become |
328 // thick without need for an animation. | 330 // thick without need for an animation. |
329 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); | 331 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); |
330 scrollbar_controller_->DidMouseDown(); | 332 scrollbar_controller_->DidMouseDown(); |
331 ExpectScrollbarsOpacity(1); | 333 ExpectScrollbarsOpacity(1); |
332 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 334 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
333 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 335 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
334 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 336 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
335 | 337 |
336 // The fade animation should have been cleared or cancelled. | 338 // The fade out animation should have been cleared or cancelled. |
337 EXPECT_TRUE(client_.start_fade().is_null() || | 339 EXPECT_TRUE(client_.start_fade().is_null() || |
338 client_.start_fade().IsCancelled()); | 340 client_.start_fade().IsCancelled()); |
339 } | 341 } |
340 | 342 |
341 // Make sure a scrollbar captured then move mouse away doesn't try to fade out. | 343 // Make sure a scrollbar captured then move mouse away doesn't try to fade out. |
342 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, | 344 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, |
343 DontFadeWhileCapturedThenAway) { | 345 DontFadeWhileCapturedThenAway) { |
344 base::TimeTicks time; | 346 base::TimeTicks time; |
345 time += base::TimeDelta::FromSeconds(1); | 347 time += base::TimeDelta::FromSeconds(1); |
346 | 348 |
347 scrollbar_controller_->DidScrollBegin(); | 349 scrollbar_controller_->DidScrollBegin(); |
348 scrollbar_controller_->DidScrollUpdate(false); | 350 scrollbar_controller_->DidScrollUpdate(false); |
349 scrollbar_controller_->DidScrollEnd(); | 351 scrollbar_controller_->DidScrollEnd(); |
350 | 352 |
351 // An animation should have been enqueued. | 353 // An fade out animation should have been enqueued. |
352 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 354 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
353 EXPECT_FALSE(client_.start_fade().is_null()); | 355 EXPECT_FALSE(client_.start_fade().is_null()); |
354 | 356 |
355 // Now move the mouse over the scrollbar and capture it. It should become | 357 // Now move the mouse over the scrollbar and capture it. It should become |
356 // thick without need for an animation. | 358 // thick without need for an animation. |
357 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); | 359 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); |
358 scrollbar_controller_->DidMouseDown(); | 360 scrollbar_controller_->DidMouseDown(); |
359 ExpectScrollbarsOpacity(1); | 361 ExpectScrollbarsOpacity(1); |
360 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 362 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
361 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 363 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
362 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 364 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
363 | 365 |
364 // The fade animation should have been cleared or cancelled. | 366 // The fade out animation should have been cleared or cancelled. |
365 EXPECT_TRUE(client_.start_fade().is_null() || | 367 EXPECT_TRUE(client_.start_fade().is_null() || |
366 client_.start_fade().IsCancelled()); | 368 client_.start_fade().IsCancelled()); |
367 | 369 |
368 // Then move mouse away, The fade animation should have been cleared or | 370 // Then move mouse away, The fade out animation should have been cleared or |
369 // cancelled. | 371 // cancelled. |
370 scrollbar_controller_->DidMouseMoveNear( | 372 scrollbar_controller_->DidMouseMoveNear( |
371 VERTICAL, kDefaultMouseMoveDistanceToTriggerAnimation); | 373 VERTICAL, kDefaultMouseMoveDistanceToTriggerAnimation); |
372 | 374 |
373 EXPECT_TRUE(client_.start_fade().is_null() || | 375 EXPECT_TRUE(client_.start_fade().is_null() || |
374 client_.start_fade().IsCancelled()); | 376 client_.start_fade().IsCancelled()); |
375 } | 377 } |
376 | 378 |
377 // Make sure a scrollbar captured after a thickening animation doesn't try to | 379 // Make sure a scrollbar captured after a thickening animation doesn't try to |
378 // fade out. | 380 // fade out. |
379 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, DontFadeWhileCaptured) { | 381 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, DontFadeWhileCaptured) { |
380 base::TimeTicks time; | 382 base::TimeTicks time; |
381 time += base::TimeDelta::FromSeconds(1); | 383 time += base::TimeDelta::FromSeconds(1); |
382 | 384 |
383 scrollbar_controller_->DidScrollBegin(); | 385 scrollbar_controller_->DidScrollBegin(); |
384 scrollbar_controller_->DidScrollUpdate(false); | 386 scrollbar_controller_->DidScrollUpdate(false); |
385 scrollbar_controller_->DidScrollEnd(); | 387 scrollbar_controller_->DidScrollEnd(); |
386 | 388 |
387 // An animation should have been enqueued. | 389 // An fade out animation should have been enqueued. |
388 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 390 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
389 EXPECT_FALSE(client_.start_fade().is_null()); | 391 EXPECT_FALSE(client_.start_fade().is_null()); |
390 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 392 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
391 | 393 |
392 // Now move the mouse over the scrollbar and animate it until it's thick. | 394 // Now move the mouse over the scrollbar and animate it until it's thick. |
393 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); | 395 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); |
394 scrollbar_controller_->Animate(time); | 396 scrollbar_controller_->Animate(time); |
395 time += kThinningDuration; | 397 time += kThinningDuration; |
396 scrollbar_controller_->Animate(time); | 398 scrollbar_controller_->Animate(time); |
397 ExpectScrollbarsOpacity(1); | 399 ExpectScrollbarsOpacity(1); |
398 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 400 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
399 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 401 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
400 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 402 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
401 | 403 |
402 // Since the mouse is over the scrollbar, it should either clear or cancel the | 404 // Since the mouse is over the scrollbar, it should either clear or cancel the |
403 // queued fade. | 405 // queued fade. |
404 EXPECT_TRUE(client_.start_fade().is_null() || | 406 EXPECT_TRUE(client_.start_fade().is_null() || |
405 client_.start_fade().IsCancelled()); | 407 client_.start_fade().IsCancelled()); |
406 | 408 |
407 // Make sure the queued fade animation is still null or cancelled after | 409 // Make sure the queued fade out animation is still null or cancelled after |
408 // capturing the scrollbar. | 410 // capturing the scrollbar. |
409 scrollbar_controller_->DidMouseDown(); | 411 scrollbar_controller_->DidMouseDown(); |
410 EXPECT_TRUE(client_.start_fade().is_null() || | 412 EXPECT_TRUE(client_.start_fade().is_null() || |
411 client_.start_fade().IsCancelled()); | 413 client_.start_fade().IsCancelled()); |
412 } | 414 } |
413 | 415 |
414 // Make sure releasing a captured scrollbar when the mouse isn't near it, causes | 416 // Make sure releasing a captured scrollbar when the mouse isn't near it, causes |
415 // the scrollbar to fade out. | 417 // the scrollbar to fade out. |
416 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAfterReleasedFar) { | 418 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAfterReleasedFar) { |
417 base::TimeTicks time; | 419 base::TimeTicks time; |
418 time += base::TimeDelta::FromSeconds(1); | 420 time += base::TimeDelta::FromSeconds(1); |
419 | 421 |
420 scrollbar_controller_->DidScrollBegin(); | 422 scrollbar_controller_->DidScrollBegin(); |
421 scrollbar_controller_->DidScrollUpdate(false); | 423 scrollbar_controller_->DidScrollUpdate(false); |
422 scrollbar_controller_->DidScrollEnd(); | 424 scrollbar_controller_->DidScrollEnd(); |
423 | 425 |
424 // An animation should have been enqueued. | 426 // An fade out animation should have been enqueued. |
425 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 427 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
426 EXPECT_FALSE(client_.start_fade().is_null()); | 428 EXPECT_FALSE(client_.start_fade().is_null()); |
427 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 429 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
428 | 430 |
429 // Now move the mouse over the scrollbar and capture it. | 431 // Now move the mouse over the scrollbar and capture it. |
430 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); | 432 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); |
431 scrollbar_controller_->DidMouseDown(); | 433 scrollbar_controller_->DidMouseDown(); |
432 ExpectScrollbarsOpacity(1); | 434 ExpectScrollbarsOpacity(1); |
433 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 435 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
434 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 436 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
435 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 437 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
(...skipping 29 matching lines...) Expand all Loading... |
465 // Make sure releasing a captured scrollbar when the mouse is near/over it, | 467 // Make sure releasing a captured scrollbar when the mouse is near/over it, |
466 // doesn't cause the scrollbar to fade out. | 468 // doesn't cause the scrollbar to fade out. |
467 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, DontFadeAfterReleasedNear) { | 469 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, DontFadeAfterReleasedNear) { |
468 base::TimeTicks time; | 470 base::TimeTicks time; |
469 time += base::TimeDelta::FromSeconds(1); | 471 time += base::TimeDelta::FromSeconds(1); |
470 | 472 |
471 scrollbar_controller_->DidScrollBegin(); | 473 scrollbar_controller_->DidScrollBegin(); |
472 scrollbar_controller_->DidScrollUpdate(false); | 474 scrollbar_controller_->DidScrollUpdate(false); |
473 scrollbar_controller_->DidScrollEnd(); | 475 scrollbar_controller_->DidScrollEnd(); |
474 | 476 |
475 // An animation should have been enqueued. | 477 // An fade out animation should have been enqueued. |
476 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 478 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
477 EXPECT_FALSE(client_.start_fade().is_null()); | 479 EXPECT_FALSE(client_.start_fade().is_null()); |
478 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 480 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
479 | 481 |
480 // Now move the mouse over the scrollbar and capture it. | 482 // Now move the mouse over the scrollbar and capture it. |
481 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); | 483 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); |
482 scrollbar_controller_->DidMouseDown(); | 484 scrollbar_controller_->DidMouseDown(); |
483 ExpectScrollbarsOpacity(1); | 485 ExpectScrollbarsOpacity(1); |
484 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 486 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
485 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 487 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
486 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 488 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
(...skipping 17 matching lines...) Expand all Loading... |
504 // the opacity and thicken. | 506 // the opacity and thicken. |
505 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, | 507 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, |
506 MoveNearScrollbarWhileFading) { | 508 MoveNearScrollbarWhileFading) { |
507 base::TimeTicks time; | 509 base::TimeTicks time; |
508 time += base::TimeDelta::FromSeconds(1); | 510 time += base::TimeDelta::FromSeconds(1); |
509 | 511 |
510 scrollbar_controller_->DidScrollBegin(); | 512 scrollbar_controller_->DidScrollBegin(); |
511 scrollbar_controller_->DidScrollUpdate(false); | 513 scrollbar_controller_->DidScrollUpdate(false); |
512 scrollbar_controller_->DidScrollEnd(); | 514 scrollbar_controller_->DidScrollEnd(); |
513 | 515 |
514 // A fade animation should have been enqueued. Start it. | 516 // A fade out animation should have been enqueued. Start it. |
515 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 517 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
516 EXPECT_FALSE(client_.start_fade().is_null()); | 518 EXPECT_FALSE(client_.start_fade().is_null()); |
517 client_.start_fade().Run(); | 519 client_.start_fade().Run(); |
518 | 520 |
519 scrollbar_controller_->Animate(time); | 521 scrollbar_controller_->Animate(time); |
520 ExpectScrollbarsOpacity(1); | 522 ExpectScrollbarsOpacity(1); |
521 | 523 |
522 // Proceed half way through the fade out animation. | 524 // Proceed half way through the fade out animation. |
523 time += kFadeDuration / 2; | 525 time += kFadeOutDuration / 2; |
524 scrollbar_controller_->Animate(time); | 526 scrollbar_controller_->Animate(time); |
525 ExpectScrollbarsOpacity(.5f); | 527 ExpectScrollbarsOpacity(.5f); |
526 | 528 |
527 // Now move the mouse near the scrollbar. It should reset opacity to 1 | 529 // Now move the mouse near the scrollbar. It should reset opacity to 1 |
528 // instantly and start animating to thick. | 530 // instantly and start animating to thick. |
529 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); | 531 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); |
530 ExpectScrollbarsOpacity(1); | 532 ExpectScrollbarsOpacity(1); |
531 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 533 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
532 v_scrollbar_layer_->thumb_thickness_scale_factor()); | 534 v_scrollbar_layer_->thumb_thickness_scale_factor()); |
533 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 535 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
(...skipping 10 matching lines...) Expand all Loading... |
544 | 546 |
545 // Make sure we can't capture scrollbar that's completely faded out. | 547 // Make sure we can't capture scrollbar that's completely faded out. |
546 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, TestCantCaptureWhenFaded) { | 548 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, TestCantCaptureWhenFaded) { |
547 base::TimeTicks time; | 549 base::TimeTicks time; |
548 time += base::TimeDelta::FromSeconds(1); | 550 time += base::TimeDelta::FromSeconds(1); |
549 | 551 |
550 scrollbar_controller_->DidScrollBegin(); | 552 scrollbar_controller_->DidScrollBegin(); |
551 scrollbar_controller_->DidScrollUpdate(false); | 553 scrollbar_controller_->DidScrollUpdate(false); |
552 scrollbar_controller_->DidScrollEnd(); | 554 scrollbar_controller_->DidScrollEnd(); |
553 | 555 |
554 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 556 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
555 EXPECT_FALSE(client_.start_fade().is_null()); | 557 EXPECT_FALSE(client_.start_fade().is_null()); |
556 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 558 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
557 client_.start_fade().Run(); | 559 client_.start_fade().Run(); |
558 scrollbar_controller_->Animate(time); | 560 scrollbar_controller_->Animate(time); |
559 ExpectScrollbarsOpacity(1); | 561 ExpectScrollbarsOpacity(1); |
560 | 562 |
561 // Fade the scrollbar out completely. | 563 // Fade the scrollbar out completely. |
562 time += kFadeDuration; | 564 time += kFadeOutDuration; |
563 scrollbar_controller_->Animate(time); | 565 scrollbar_controller_->Animate(time); |
564 ExpectScrollbarsOpacity(0); | 566 ExpectScrollbarsOpacity(0); |
565 | 567 |
566 // Move mouse over the scrollbar. It shouldn't thicken the scrollbar since | 568 // Move mouse over the scrollbar. It shouldn't thicken the scrollbar since |
567 // it's completely faded out. | 569 // it's completely faded out. |
568 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); | 570 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); |
569 scrollbar_controller_->Animate(time); | 571 scrollbar_controller_->Animate(time); |
570 time += kThinningDuration; | 572 time += kThinningDuration; |
571 scrollbar_controller_->Animate(time); | 573 scrollbar_controller_->Animate(time); |
572 ExpectScrollbarsOpacity(0); | 574 ExpectScrollbarsOpacity(0); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 EXPECT_TRUE(client_.start_fade().is_null() || | 625 EXPECT_TRUE(client_.start_fade().is_null() || |
624 client_.start_fade().IsCancelled()); | 626 client_.start_fade().IsCancelled()); |
625 | 627 |
626 scrollbar_controller_->Animate(time); | 628 scrollbar_controller_->Animate(time); |
627 ExpectScrollbarsOpacity(1); | 629 ExpectScrollbarsOpacity(1); |
628 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 630 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
629 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 631 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
630 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 632 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
631 | 633 |
632 // Scrollbar should still be thick and visible. | 634 // Scrollbar should still be thick and visible. |
633 time += kFadeDuration; | 635 time += kFadeOutDuration; |
634 scrollbar_controller_->Animate(time); | 636 scrollbar_controller_->Animate(time); |
635 ExpectScrollbarsOpacity(1); | 637 ExpectScrollbarsOpacity(1); |
636 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 638 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
637 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 639 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
638 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 640 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
639 } | 641 } |
640 | 642 |
641 // Tests that main thread scroll updates immediatley queue a fade animation | 643 // Tests that main thread scroll updates immediatley queue a fade out animation |
642 // without requiring a ScrollEnd. | 644 // without requiring a ScrollEnd. |
643 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, | 645 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, |
644 MainThreadScrollQueuesFade) { | 646 MainThreadScrollQueuesFade) { |
645 ASSERT_TRUE(client_.start_fade().is_null()); | 647 ASSERT_TRUE(client_.start_fade().is_null()); |
646 | 648 |
647 // A ScrollUpdate without a ScrollBegin indicates a main thread scroll update | 649 // A ScrollUpdate without a ScrollBegin indicates a main thread scroll update |
648 // so we should schedule a fade animation without waiting for a ScrollEnd | 650 // so we should schedule a fade out animation without waiting for a ScrollEnd |
649 // (which will never come). | 651 // (which will never come). |
650 scrollbar_controller_->DidScrollUpdate(false); | 652 scrollbar_controller_->DidScrollUpdate(false); |
651 EXPECT_FALSE(client_.start_fade().is_null()); | 653 EXPECT_FALSE(client_.start_fade().is_null()); |
652 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 654 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
653 | 655 |
654 client_.start_fade().Reset(); | 656 client_.start_fade().Reset(); |
655 | 657 |
656 // If we got a ScrollBegin, we shouldn't schedule the fade animation until we | 658 // If we got a ScrollBegin, we shouldn't schedule the fade out animation until |
657 // get a corresponding ScrollEnd. | 659 // we get a corresponding ScrollEnd. |
658 scrollbar_controller_->DidScrollBegin(); | 660 scrollbar_controller_->DidScrollBegin(); |
659 scrollbar_controller_->DidScrollUpdate(false); | 661 scrollbar_controller_->DidScrollUpdate(false); |
660 EXPECT_TRUE(client_.start_fade().is_null()); | 662 EXPECT_TRUE(client_.start_fade().is_null()); |
661 scrollbar_controller_->DidScrollEnd(); | 663 scrollbar_controller_->DidScrollEnd(); |
662 EXPECT_FALSE(client_.start_fade().is_null()); | 664 EXPECT_FALSE(client_.start_fade().is_null()); |
663 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 665 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
664 } | 666 } |
665 | 667 |
666 // Make sure that if the scroll update is as a result of a resize, we use the | 668 // Make sure that if the scroll update is as a result of a resize, we use the |
667 // resize delay time instead of the default one. | 669 // resize delay time instead of the default one. |
668 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, ResizeFadeDuration) { | 670 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, ResizeFadeDuration) { |
669 ASSERT_TRUE(client_.delay().is_zero()); | 671 ASSERT_TRUE(client_.delay().is_zero()); |
670 | 672 |
671 scrollbar_controller_->DidScrollUpdate(true); | 673 scrollbar_controller_->DidScrollUpdate(true); |
672 EXPECT_FALSE(client_.start_fade().is_null()); | 674 EXPECT_FALSE(client_.start_fade().is_null()); |
673 EXPECT_EQ(kResizeDelayBeforeStarting, client_.delay()); | 675 EXPECT_EQ(kResizeFadeOutDelay, client_.delay()); |
674 | 676 |
675 client_.delay() = base::TimeDelta(); | 677 client_.delay() = base::TimeDelta(); |
676 | 678 |
677 // We should use the gesture delay rather than the resize delay if we're in a | 679 // We should use the gesture delay rather than the resize delay if we're in a |
678 // gesture scroll, even if the resize param is set. | 680 // gesture scroll, even if the resize param is set. |
679 scrollbar_controller_->DidScrollBegin(); | 681 scrollbar_controller_->DidScrollBegin(); |
680 scrollbar_controller_->DidScrollUpdate(true); | 682 scrollbar_controller_->DidScrollUpdate(true); |
681 scrollbar_controller_->DidScrollEnd(); | 683 scrollbar_controller_->DidScrollEnd(); |
682 | 684 |
683 EXPECT_FALSE(client_.start_fade().is_null()); | 685 EXPECT_FALSE(client_.start_fade().is_null()); |
684 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 686 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
685 } | 687 } |
686 | 688 |
687 // Tests that the fade effect is animated. | 689 // Tests that the fade effect is animated. |
688 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAnimated) { | 690 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAnimated) { |
689 base::TimeTicks time; | 691 base::TimeTicks time; |
690 time += base::TimeDelta::FromSeconds(1); | 692 time += base::TimeDelta::FromSeconds(1); |
691 | 693 |
692 // Scroll to make the scrollbars visible. | 694 // Scroll to make the scrollbars visible. |
693 scrollbar_controller_->DidScrollBegin(); | 695 scrollbar_controller_->DidScrollBegin(); |
694 scrollbar_controller_->DidScrollUpdate(false); | 696 scrollbar_controller_->DidScrollUpdate(false); |
695 scrollbar_controller_->DidScrollEnd(); | 697 scrollbar_controller_->DidScrollEnd(); |
696 | 698 |
697 // Appearance is instant. | 699 // Appearance is instant. |
698 ExpectScrollbarsOpacity(1); | 700 ExpectScrollbarsOpacity(1); |
699 | 701 |
700 // An animation should have been enqueued. | 702 // An fade out animation should have been enqueued. |
701 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 703 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
702 EXPECT_FALSE(client_.start_fade().is_null()); | 704 EXPECT_FALSE(client_.start_fade().is_null()); |
703 client_.start_fade().Run(); | 705 client_.start_fade().Run(); |
704 | 706 |
705 // Test that at half the fade duration time, the opacity is at half. | 707 // Test that at half the fade duration time, the opacity is at half. |
706 scrollbar_controller_->Animate(time); | 708 scrollbar_controller_->Animate(time); |
707 ExpectScrollbarsOpacity(1); | 709 ExpectScrollbarsOpacity(1); |
708 | 710 |
709 time += kFadeDuration / 2; | 711 time += kFadeOutDuration / 2; |
710 scrollbar_controller_->Animate(time); | 712 scrollbar_controller_->Animate(time); |
711 ExpectScrollbarsOpacity(.5f); | 713 ExpectScrollbarsOpacity(.5f); |
712 | 714 |
713 time += kFadeDuration / 2; | 715 time += kFadeOutDuration / 2; |
714 scrollbar_controller_->Animate(time); | 716 scrollbar_controller_->Animate(time); |
715 ExpectScrollbarsOpacity(0); | 717 ExpectScrollbarsOpacity(0); |
716 } | 718 } |
717 | 719 |
718 // Tests that the controller tells the client when the scrollbars hide/show. | 720 // Tests that the controller tells the client when the scrollbars hide/show. |
719 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, NotifyChangedVisibility) { | 721 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, NotifyChangedVisibility) { |
720 base::TimeTicks time; | 722 base::TimeTicks time; |
721 time += base::TimeDelta::FromSeconds(1); | 723 time += base::TimeDelta::FromSeconds(1); |
722 | 724 |
723 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); | 725 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); |
724 // Scroll to make the scrollbars visible. | 726 // Scroll to make the scrollbars visible. |
725 scrollbar_controller_->DidScrollBegin(); | 727 scrollbar_controller_->DidScrollBegin(); |
726 scrollbar_controller_->DidScrollUpdate(false); | 728 scrollbar_controller_->DidScrollUpdate(false); |
727 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); | 729 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); |
728 Mock::VerifyAndClearExpectations(&client_); | 730 Mock::VerifyAndClearExpectations(&client_); |
729 | 731 |
730 scrollbar_controller_->DidScrollEnd(); | 732 scrollbar_controller_->DidScrollEnd(); |
731 | 733 |
732 // Play out the fade animation. We shouldn't notify that the scrollbars are | 734 // Play out the fade out animation. We shouldn't notify that the scrollbars |
733 // hidden until the animation is completly over. We can (but don't have to) | 735 // are hidden until the animation is completly over. We can (but don't have |
734 // notify during the animation that the scrollbars are still visible. | 736 // to) notify during the animation that the scrollbars are still visible. |
735 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(0); | 737 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(0); |
736 ASSERT_FALSE(client_.start_fade().is_null()); | 738 ASSERT_FALSE(client_.start_fade().is_null()); |
737 client_.start_fade().Run(); | 739 client_.start_fade().Run(); |
738 scrollbar_controller_->Animate(time); | 740 scrollbar_controller_->Animate(time); |
739 time += kFadeDuration / 4; | 741 time += kFadeOutDuration / 4; |
740 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); | 742 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); |
741 scrollbar_controller_->Animate(time); | 743 scrollbar_controller_->Animate(time); |
742 time += kFadeDuration / 4; | 744 time += kFadeOutDuration / 4; |
743 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); | 745 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); |
744 scrollbar_controller_->Animate(time); | 746 scrollbar_controller_->Animate(time); |
745 time += kFadeDuration / 4; | 747 time += kFadeOutDuration / 4; |
746 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); | 748 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); |
747 scrollbar_controller_->Animate(time); | 749 scrollbar_controller_->Animate(time); |
748 ExpectScrollbarsOpacity(.25f); | 750 ExpectScrollbarsOpacity(.25f); |
749 Mock::VerifyAndClearExpectations(&client_); | 751 Mock::VerifyAndClearExpectations(&client_); |
750 | 752 |
751 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); | 753 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); |
752 time += kFadeDuration / 4; | 754 time += kFadeOutDuration / 4; |
753 scrollbar_controller_->Animate(time); | 755 scrollbar_controller_->Animate(time); |
754 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); | 756 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); |
755 ExpectScrollbarsOpacity(0); | 757 ExpectScrollbarsOpacity(0); |
756 Mock::VerifyAndClearExpectations(&client_); | 758 Mock::VerifyAndClearExpectations(&client_); |
757 | 759 |
758 // Calling DidScrollUpdate without a begin (i.e. update from commit) should | 760 // Calling DidScrollUpdate without a begin (i.e. update from commit) should |
759 // also notify. | 761 // also notify. |
760 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); | 762 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); |
761 scrollbar_controller_->DidScrollUpdate(false); | 763 scrollbar_controller_->DidScrollUpdate(false); |
762 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); | 764 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation); | 847 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation); |
846 scrollbar_controller_->Animate(time); | 848 scrollbar_controller_->Animate(time); |
847 time += kThinningDuration; | 849 time += kThinningDuration; |
848 scrollbar_controller_->Animate(time); | 850 scrollbar_controller_->Animate(time); |
849 ExpectScrollbarsOpacity(1); | 851 ExpectScrollbarsOpacity(1); |
850 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 852 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
851 v_scrollbar_layer_->thumb_thickness_scale_factor()); | 853 v_scrollbar_layer_->thumb_thickness_scale_factor()); |
852 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 854 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
853 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 855 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
854 | 856 |
855 // An animation should have been enqueued. | 857 // An fade out animation should have been enqueued. |
856 EXPECT_FALSE(client_.start_fade().is_null()); | 858 EXPECT_FALSE(client_.start_fade().is_null()); |
857 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 859 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
858 } | 860 } |
859 | 861 |
860 // Move mouse near both scrollbars at the same time. | 862 // Move mouse near both scrollbars at the same time. |
861 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearBoth) { | 863 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearBoth) { |
862 base::TimeTicks time; | 864 base::TimeTicks time; |
863 time += base::TimeDelta::FromSeconds(1); | 865 time += base::TimeDelta::FromSeconds(1); |
864 | 866 |
865 // Scroll to make the scrollbars visible. | 867 // Scroll to make the scrollbars visible. |
866 scrollbar_controller_->DidScrollBegin(); | 868 scrollbar_controller_->DidScrollBegin(); |
867 scrollbar_controller_->DidScrollUpdate(false); | 869 scrollbar_controller_->DidScrollUpdate(false); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 | 939 |
938 // Horizontal scrollbar animate to thin. | 940 // Horizontal scrollbar animate to thin. |
939 time += kThinningDuration; | 941 time += kThinningDuration; |
940 scrollbar_controller_->Animate(time); | 942 scrollbar_controller_->Animate(time); |
941 ExpectScrollbarsOpacity(1); | 943 ExpectScrollbarsOpacity(1); |
942 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 944 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
943 v_scrollbar_layer_->thumb_thickness_scale_factor()); | 945 v_scrollbar_layer_->thumb_thickness_scale_factor()); |
944 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 946 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
945 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 947 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
946 | 948 |
947 // An animation should have been enqueued. | 949 // An fade out animation should have been enqueued. |
948 EXPECT_FALSE(client_.start_fade().is_null()); | 950 EXPECT_FALSE(client_.start_fade().is_null()); |
949 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 951 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
950 } | 952 } |
951 | 953 |
952 // Ensure we have a delay fadeout animation after mouse leave without a mouse | 954 // Ensure we have a delay fadeout animation after mouse leave without a mouse |
953 // move. | 955 // move. |
954 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseLeaveFadeOut) { | 956 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseLeaveFadeOut) { |
955 base::TimeTicks time; | 957 base::TimeTicks time; |
956 time += base::TimeDelta::FromSeconds(1); | 958 time += base::TimeDelta::FromSeconds(1); |
957 | 959 |
958 // Move mouse near scrollbar. | 960 // Move mouse near scrollbar. |
959 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); | 961 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); |
960 | 962 |
961 // Scroll to make the scrollbars visible. | 963 // Scroll to make the scrollbars visible. |
962 scrollbar_controller_->DidScrollBegin(); | 964 scrollbar_controller_->DidScrollBegin(); |
963 scrollbar_controller_->DidScrollUpdate(false); | 965 scrollbar_controller_->DidScrollUpdate(false); |
964 scrollbar_controller_->DidScrollEnd(); | 966 scrollbar_controller_->DidScrollEnd(); |
965 | 967 |
966 // Should not have delay fadeout animation. | 968 // Should not have delay fadeout animation. |
967 EXPECT_TRUE(client_.start_fade().is_null() || | 969 EXPECT_TRUE(client_.start_fade().is_null() || |
968 client_.start_fade().IsCancelled()); | 970 client_.start_fade().IsCancelled()); |
969 | 971 |
970 // Mouse leave. | 972 // Mouse leave. |
971 scrollbar_controller_->DidMouseLeave(); | 973 scrollbar_controller_->DidMouseLeave(); |
972 | 974 |
973 // An animation should have been enqueued. | 975 // An fade out animation should have been enqueued. |
974 EXPECT_FALSE(client_.start_fade().is_null()); | 976 EXPECT_FALSE(client_.start_fade().is_null()); |
975 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 977 EXPECT_EQ(kFadeOutDelay, client_.delay()); |
| 978 } |
| 979 |
| 980 // Scrollbars should schedule a delay show when mouse hover hidden scrollbar. |
| 981 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, BasicMouseHoverShow) { |
| 982 base::TimeTicks time; |
| 983 time += base::TimeDelta::FromSeconds(1); |
| 984 |
| 985 // Move mouse over scrollbar. |
| 986 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); |
| 987 |
| 988 // An show animation should have been enqueued. |
| 989 EXPECT_FALSE(client_.start_fade().is_null()); |
| 990 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 991 EXPECT_EQ(kShowDelay, client_.delay()); |
| 992 |
| 993 // Play the delay animation. |
| 994 client_.start_fade().Run(); |
| 995 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); |
| 996 } |
| 997 |
| 998 // Scrollbars should not schedule a new delay show when the mouse hovers inside |
| 999 // a scrollbar already scheduled a delay show. |
| 1000 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, |
| 1001 MouseHoverScrollbarAndMoveInside) { |
| 1002 base::TimeTicks time; |
| 1003 time += base::TimeDelta::FromSeconds(1); |
| 1004 |
| 1005 // Move mouse over scrollbar. |
| 1006 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); |
| 1007 |
| 1008 // An show animation should have been enqueued. |
| 1009 EXPECT_FALSE(client_.start_fade().is_null()); |
| 1010 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 1011 EXPECT_EQ(kShowDelay, client_.delay()); |
| 1012 |
| 1013 base::Closure& fade = client_.start_fade(); |
| 1014 // Move mouse inside scrollbar. should not post a new show. |
| 1015 scrollbar_controller_->DidMouseMoveNear( |
| 1016 VERTICAL, kMouseMoveDistanceToTriggerShow - kThumbThickness - 1); |
| 1017 |
| 1018 EXPECT_TRUE(fade.Equals(client_.start_fade())); |
| 1019 } |
| 1020 |
| 1021 // Scrollbars should cancel delay show when mouse hover hidden scrollbar then |
| 1022 // move out. |
| 1023 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, |
| 1024 MouseHoverThenOutShouldCancelShow) { |
| 1025 base::TimeTicks time; |
| 1026 time += base::TimeDelta::FromSeconds(1); |
| 1027 |
| 1028 // Move mouse over scrollbar. |
| 1029 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); |
| 1030 |
| 1031 // An show animation should have been enqueued. |
| 1032 EXPECT_FALSE(client_.start_fade().is_null()); |
| 1033 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 1034 EXPECT_EQ(kShowDelay, client_.delay()); |
| 1035 |
| 1036 // Move mouse out of scrollbar,delay show should be canceled. |
| 1037 scrollbar_controller_->DidMouseMoveNear( |
| 1038 VERTICAL, kMouseMoveDistanceToTriggerShow - kThumbThickness); |
| 1039 EXPECT_TRUE(client_.start_fade().is_null() || |
| 1040 client_.start_fade().IsCancelled()); |
976 } | 1041 } |
977 | 1042 |
978 class ScrollbarAnimationControllerAndroidTest | 1043 class ScrollbarAnimationControllerAndroidTest |
979 : public testing::Test, | 1044 : public testing::Test, |
980 public ScrollbarAnimationControllerClient { | 1045 public ScrollbarAnimationControllerClient { |
981 public: | 1046 public: |
982 ScrollbarAnimationControllerAndroidTest() | 1047 ScrollbarAnimationControllerAndroidTest() |
983 : host_impl_(&task_runner_provider_, &task_graph_runner_), | 1048 : host_impl_(&task_runner_provider_, &task_graph_runner_), |
984 did_request_redraw_(false), | 1049 did_request_redraw_(false), |
985 did_request_animate_(false) {} | 1050 did_request_animate_(false) {} |
986 | 1051 |
987 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade, | 1052 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade, |
988 base::TimeDelta delay) override { | 1053 base::TimeDelta delay) override { |
989 start_fade_ = start_fade; | 1054 start_fade_ = start_fade; |
990 delay_ = delay; | 1055 delay_ = delay; |
991 } | 1056 } |
992 void SetNeedsRedrawForScrollbarAnimation() override { | 1057 void SetNeedsRedrawForScrollbarAnimation() override { |
993 did_request_redraw_ = true; | 1058 did_request_redraw_ = true; |
994 } | 1059 } |
995 void SetNeedsAnimateForScrollbarAnimation() override { | 1060 void SetNeedsAnimateForScrollbarAnimation() override { |
996 did_request_animate_ = true; | 1061 did_request_animate_ = true; |
997 } | 1062 } |
998 ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override { | 1063 ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override { |
999 return host_impl_.ScrollbarsFor(scroll_layer_id); | 1064 return host_impl_.ScrollbarsFor(scroll_layer_id); |
1000 } | 1065 } |
1001 void DidChangeScrollbarVisibility() override {} | 1066 void DidChangeScrollbarVisibility() override {} |
1002 | 1067 |
1003 protected: | 1068 protected: |
1004 void SetUp() override { | 1069 void SetUp() override { |
1005 const int kThumbThickness = 10; | |
1006 const int kTrackStart = 0; | 1070 const int kTrackStart = 0; |
1007 const bool kIsLeftSideVerticalScrollbar = false; | 1071 const bool kIsLeftSideVerticalScrollbar = false; |
1008 const bool kIsOverlayScrollbar = true; // Allow opacity animations. | 1072 const bool kIsOverlayScrollbar = true; // Allow opacity animations. |
1009 | 1073 |
1010 std::unique_ptr<LayerImpl> scroll_layer = | 1074 std::unique_ptr<LayerImpl> scroll_layer = |
1011 LayerImpl::Create(host_impl_.active_tree(), 1); | 1075 LayerImpl::Create(host_impl_.active_tree(), 1); |
1012 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = | 1076 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
1013 SolidColorScrollbarLayerImpl::Create( | 1077 SolidColorScrollbarLayerImpl::Create( |
1014 host_impl_.active_tree(), 2, orientation(), kThumbThickness, | 1078 host_impl_.active_tree(), 2, orientation(), kThumbThickness, |
1015 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); | 1079 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); | 1518 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); |
1455 | 1519 |
1456 time += base::TimeDelta::FromSeconds(1); | 1520 time += base::TimeDelta::FromSeconds(1); |
1457 scrollbar_controller_->DidScrollEnd(); | 1521 scrollbar_controller_->DidScrollEnd(); |
1458 EXPECT_FALSE(did_request_animate_); | 1522 EXPECT_FALSE(did_request_animate_); |
1459 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); | 1523 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); |
1460 } | 1524 } |
1461 | 1525 |
1462 } // namespace | 1526 } // namespace |
1463 } // namespace cc | 1527 } // namespace cc |
OLD | NEW |