Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: cc/input/scrollbar_animation_controller_unittest.cc

Issue 2816923002: change overlay scrollbar hover show to hover fade in (Closed)
Patch Set: combine fade_in_delay and fade_out_delay to fade_delay Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/input/scrollbar_animation_controller.cc ('k') | cc/layers/scrollbar_layer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 = 29 const float kMouseMoveDistanceToTriggerFadeIn =
30 ScrollbarAnimationController::kMouseMoveDistanceToTriggerShow; 30 ScrollbarAnimationController::kMouseMoveDistanceToTriggerFadeIn;
31 const int kThumbThickness = 10; 31 const int kThumbThickness = 10;
32 32
33 class MockScrollbarAnimationControllerClient 33 class MockScrollbarAnimationControllerClient
34 : public ScrollbarAnimationControllerClient { 34 : public ScrollbarAnimationControllerClient {
35 public: 35 public:
36 explicit MockScrollbarAnimationControllerClient(LayerTreeHostImpl* host_impl) 36 explicit MockScrollbarAnimationControllerClient(LayerTreeHostImpl* host_impl)
37 : host_impl_(host_impl) {} 37 : host_impl_(host_impl) {}
38 virtual ~MockScrollbarAnimationControllerClient() {} 38 virtual ~MockScrollbarAnimationControllerClient() {}
39 39
40 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade, 40 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade,
(...skipping 22 matching lines...) Expand all
63 ScrollbarAnimationControllerAuraOverlayTest() 63 ScrollbarAnimationControllerAuraOverlayTest()
64 : host_impl_(&task_runner_provider_, &task_graph_runner_), 64 : host_impl_(&task_runner_provider_, &task_graph_runner_),
65 client_(&host_impl_) {} 65 client_(&host_impl_) {}
66 66
67 void ExpectScrollbarsOpacity(float opacity) { 67 void ExpectScrollbarsOpacity(float opacity) {
68 EXPECT_FLOAT_EQ(opacity, v_scrollbar_layer_->Opacity()); 68 EXPECT_FLOAT_EQ(opacity, v_scrollbar_layer_->Opacity());
69 EXPECT_FLOAT_EQ(opacity, h_scrollbar_layer_->Opacity()); 69 EXPECT_FLOAT_EQ(opacity, h_scrollbar_layer_->Opacity());
70 } 70 }
71 71
72 protected: 72 protected:
73 const base::TimeDelta kShowDelay = base::TimeDelta::FromSeconds(4); 73 const base::TimeDelta kFadeDelay = base::TimeDelta::FromSeconds(4);
74 const base::TimeDelta kFadeOutDelay = base::TimeDelta::FromSeconds(2);
75 const base::TimeDelta kResizeFadeOutDelay = base::TimeDelta::FromSeconds(5); 74 const base::TimeDelta kResizeFadeOutDelay = base::TimeDelta::FromSeconds(5);
76 const base::TimeDelta kFadeOutDuration = base::TimeDelta::FromSeconds(3); 75 const base::TimeDelta kFadeDuration = base::TimeDelta::FromSeconds(3);
77 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2); 76 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2);
78 77
79 void SetUp() override { 78 void SetUp() override {
80 std::unique_ptr<LayerImpl> scroll_layer = 79 std::unique_ptr<LayerImpl> scroll_layer =
81 LayerImpl::Create(host_impl_.active_tree(), 1); 80 LayerImpl::Create(host_impl_.active_tree(), 1);
82 std::unique_ptr<LayerImpl> clip = 81 std::unique_ptr<LayerImpl> clip =
83 LayerImpl::Create(host_impl_.active_tree(), 2); 82 LayerImpl::Create(host_impl_.active_tree(), 2);
84 clip_layer_ = clip.get(); 83 clip_layer_ = clip.get();
85 scroll_layer->SetElementId( 84 scroll_layer->SetElementId(
86 LayerIdToElementIdForTesting(scroll_layer->id())); 85 LayerIdToElementIdForTesting(scroll_layer->id()));
(...skipping 25 matching lines...) Expand all
112 h_scrollbar_layer_->SetScrollInfo(scroll_layer_ptr->id(), 111 h_scrollbar_layer_->SetScrollInfo(scroll_layer_ptr->id(),
113 scroll_layer_ptr->element_id()); 112 scroll_layer_ptr->element_id());
114 v_scrollbar_layer_->test_properties()->opacity_can_animate = true; 113 v_scrollbar_layer_->test_properties()->opacity_can_animate = true;
115 h_scrollbar_layer_->test_properties()->opacity_can_animate = true; 114 h_scrollbar_layer_->test_properties()->opacity_can_animate = true;
116 clip_layer_->SetBounds(gfx::Size(100, 100)); 115 clip_layer_->SetBounds(gfx::Size(100, 100));
117 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); 116 scroll_layer_ptr->SetBounds(gfx::Size(200, 200));
118 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); 117 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting();
119 118
120 scrollbar_controller_ = ScrollbarAnimationController:: 119 scrollbar_controller_ = ScrollbarAnimationController::
121 CreateScrollbarAnimationControllerAuraOverlay( 120 CreateScrollbarAnimationControllerAuraOverlay(
122 scroll_layer_ptr->element_id(), &client_, kShowDelay, kFadeOutDelay, 121 scroll_layer_ptr->element_id(), &client_, kFadeDelay,
123 kResizeFadeOutDelay, kFadeOutDuration, kThinningDuration); 122 kResizeFadeOutDelay, kFadeDuration, kThinningDuration);
124 } 123 }
125 124
126 FakeImplTaskRunnerProvider task_runner_provider_; 125 FakeImplTaskRunnerProvider task_runner_provider_;
127 TestTaskGraphRunner task_graph_runner_; 126 TestTaskGraphRunner task_graph_runner_;
128 FakeLayerTreeHostImpl host_impl_; 127 FakeLayerTreeHostImpl host_impl_;
129 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; 128 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_;
130 LayerImpl* clip_layer_; 129 LayerImpl* clip_layer_;
131 SolidColorScrollbarLayerImpl* v_scrollbar_layer_; 130 SolidColorScrollbarLayerImpl* v_scrollbar_layer_;
132 SolidColorScrollbarLayerImpl* h_scrollbar_layer_; 131 SolidColorScrollbarLayerImpl* h_scrollbar_layer_;
133 NiceMock<MockScrollbarAnimationControllerClient> client_; 132 NiceMock<MockScrollbarAnimationControllerClient> client_;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 212
214 scrollbar_controller_->DidScrollUpdate(); 213 scrollbar_controller_->DidScrollUpdate();
215 ExpectScrollbarsOpacity(1); 214 ExpectScrollbarsOpacity(1);
216 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 215 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
217 216
218 scrollbar_controller_->DidScrollEnd(); 217 scrollbar_controller_->DidScrollEnd();
219 ExpectScrollbarsOpacity(1); 218 ExpectScrollbarsOpacity(1);
220 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 219 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
221 220
222 // An fade out animation should have been enqueued. 221 // An fade out animation should have been enqueued.
223 EXPECT_EQ(kFadeOutDelay, client_.delay()); 222 EXPECT_EQ(kFadeDelay, client_.delay());
224 EXPECT_FALSE(client_.start_fade().is_null()); 223 EXPECT_FALSE(client_.start_fade().is_null());
225 client_.start_fade().Run(); 224 client_.start_fade().Run();
226 225
227 // Scrollbar should fade out over kFadeOutDuration. 226 // Scrollbar should fade out over kFadeDuration.
228 scrollbar_controller_->Animate(time); 227 scrollbar_controller_->Animate(time);
229 time += kFadeOutDuration; 228 time += kFadeDuration;
230 scrollbar_controller_->Animate(time); 229 scrollbar_controller_->Animate(time);
231 230
232 ExpectScrollbarsOpacity(0); 231 ExpectScrollbarsOpacity(0);
233 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); 232 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
234 } 233 }
235 234
236 // Confirm the scrollbar appears by WillUpdateScroll and fade out. 235 // Confirm the scrollbar appears by WillUpdateScroll and fade out.
237 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 236 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
238 BasicAppearByWillUpdateScrollThenFadeOut) { 237 BasicAppearByWillUpdateScrollThenFadeOut) {
239 base::TimeTicks time; 238 base::TimeTicks time;
240 time += base::TimeDelta::FromSeconds(1); 239 time += base::TimeDelta::FromSeconds(1);
241 240
242 // Scrollbar should be invisible. 241 // Scrollbar should be invisible.
243 ExpectScrollbarsOpacity(0); 242 ExpectScrollbarsOpacity(0);
244 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); 243 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
245 244
246 // Scrollbar should appear when scroll will update. 245 // Scrollbar should appear when scroll will update.
247 scrollbar_controller_->WillUpdateScroll(); 246 scrollbar_controller_->WillUpdateScroll();
248 ExpectScrollbarsOpacity(1); 247 ExpectScrollbarsOpacity(1);
249 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 248 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
250 249
251 // An fade out animation should have been enqueued. 250 // An fade out animation should have been enqueued.
252 EXPECT_EQ(kFadeOutDelay, client_.delay()); 251 EXPECT_EQ(kFadeDelay, client_.delay());
253 EXPECT_FALSE(client_.start_fade().is_null()); 252 EXPECT_FALSE(client_.start_fade().is_null());
254 client_.start_fade().Run(); 253 client_.start_fade().Run();
255 254
256 // Scrollbar should fade out over kFadeOutDuration. 255 // Scrollbar should fade out over kFadeDuration.
257 scrollbar_controller_->Animate(time); 256 scrollbar_controller_->Animate(time);
258 time += kFadeOutDuration; 257 time += kFadeDuration;
259 scrollbar_controller_->Animate(time); 258 scrollbar_controller_->Animate(time);
260 259
261 ExpectScrollbarsOpacity(0); 260 ExpectScrollbarsOpacity(0);
262 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); 261 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
263 } 262 }
264 263
265 // Scroll content. Move the mouse near the scrollbar and confirm it becomes 264 // Scroll content. Move the mouse near the scrollbar and confirm it becomes
266 // thick. Ensure it remains visible as long as the mouse is near the scrollbar. 265 // thick. Ensure it remains visible as long as the mouse is near the scrollbar.
267 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveNearAndDontFadeOut) { 266 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveNearAndDontFadeOut) {
268 base::TimeTicks time; 267 base::TimeTicks time;
269 time += base::TimeDelta::FromSeconds(1); 268 time += base::TimeDelta::FromSeconds(1);
270 269
271 scrollbar_controller_->DidScrollBegin(); 270 scrollbar_controller_->DidScrollBegin();
272 scrollbar_controller_->DidScrollUpdate(); 271 scrollbar_controller_->DidScrollUpdate();
273 scrollbar_controller_->DidScrollEnd(); 272 scrollbar_controller_->DidScrollEnd();
274 273
275 // An fade out animation should have been enqueued. 274 // An fade out animation should have been enqueued.
276 EXPECT_EQ(kFadeOutDelay, client_.delay()); 275 EXPECT_EQ(kFadeDelay, client_.delay());
277 EXPECT_FALSE(client_.start_fade().is_null()); 276 EXPECT_FALSE(client_.start_fade().is_null());
278 EXPECT_FALSE(client_.start_fade().IsCancelled()); 277 EXPECT_FALSE(client_.start_fade().IsCancelled());
279 278
280 // Now move the mouse near the scrollbar. This should cancel the currently 279 // Now move the mouse near the scrollbar. This should cancel the currently
281 // queued fading animation and start animating thickness. 280 // queued fading animation and start animating thickness.
282 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); 281 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1);
283 ExpectScrollbarsOpacity(1); 282 ExpectScrollbarsOpacity(1);
284 EXPECT_FLOAT_EQ(kIdleThicknessScale, 283 EXPECT_FLOAT_EQ(kIdleThicknessScale,
285 v_scrollbar_layer_->thumb_thickness_scale_factor()); 284 v_scrollbar_layer_->thumb_thickness_scale_factor());
286 EXPECT_FLOAT_EQ(kIdleThicknessScale, 285 EXPECT_FLOAT_EQ(kIdleThicknessScale,
(...skipping 20 matching lines...) Expand all
307 // thick. Ensure it remains visible as long as the mouse is over the scrollbar. 306 // thick. Ensure it remains visible as long as the mouse is over the scrollbar.
308 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveOverAndDontFadeOut) { 307 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveOverAndDontFadeOut) {
309 base::TimeTicks time; 308 base::TimeTicks time;
310 time += base::TimeDelta::FromSeconds(1); 309 time += base::TimeDelta::FromSeconds(1);
311 310
312 scrollbar_controller_->DidScrollBegin(); 311 scrollbar_controller_->DidScrollBegin();
313 scrollbar_controller_->DidScrollUpdate(); 312 scrollbar_controller_->DidScrollUpdate();
314 scrollbar_controller_->DidScrollEnd(); 313 scrollbar_controller_->DidScrollEnd();
315 314
316 // An fade out animation should have been enqueued. 315 // An fade out animation should have been enqueued.
317 EXPECT_EQ(kFadeOutDelay, client_.delay()); 316 EXPECT_EQ(kFadeDelay, client_.delay());
318 EXPECT_FALSE(client_.start_fade().is_null()); 317 EXPECT_FALSE(client_.start_fade().is_null());
319 EXPECT_FALSE(client_.start_fade().IsCancelled()); 318 EXPECT_FALSE(client_.start_fade().IsCancelled());
320 319
321 // Now move the mouse over the scrollbar. This should cancel the currently 320 // Now move the mouse over the scrollbar. This should cancel the currently
322 // queued fading animation and start animating thickness. 321 // queued fading animation and start animating thickness.
323 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); 322 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0);
324 ExpectScrollbarsOpacity(1); 323 ExpectScrollbarsOpacity(1);
325 EXPECT_FLOAT_EQ(kIdleThicknessScale, 324 EXPECT_FLOAT_EQ(kIdleThicknessScale,
326 v_scrollbar_layer_->thumb_thickness_scale_factor()); 325 v_scrollbar_layer_->thumb_thickness_scale_factor());
327 EXPECT_FLOAT_EQ(kIdleThicknessScale, 326 EXPECT_FLOAT_EQ(kIdleThicknessScale,
(...skipping 21 matching lines...) Expand all
349 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 348 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
350 DontFadeWhileCapturedBeforeThick) { 349 DontFadeWhileCapturedBeforeThick) {
351 base::TimeTicks time; 350 base::TimeTicks time;
352 time += base::TimeDelta::FromSeconds(1); 351 time += base::TimeDelta::FromSeconds(1);
353 352
354 scrollbar_controller_->DidScrollBegin(); 353 scrollbar_controller_->DidScrollBegin();
355 scrollbar_controller_->DidScrollUpdate(); 354 scrollbar_controller_->DidScrollUpdate();
356 scrollbar_controller_->DidScrollEnd(); 355 scrollbar_controller_->DidScrollEnd();
357 356
358 // An fade out animation should have been enqueued. 357 // An fade out animation should have been enqueued.
359 EXPECT_EQ(kFadeOutDelay, client_.delay()); 358 EXPECT_EQ(kFadeDelay, client_.delay());
360 EXPECT_FALSE(client_.start_fade().is_null()); 359 EXPECT_FALSE(client_.start_fade().is_null());
361 360
362 // Now move the mouse over the scrollbar and capture it. It should become 361 // Now move the mouse over the scrollbar and capture it. It should become
363 // thick without need for an animation. 362 // thick without need for an animation.
364 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); 363 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0);
365 scrollbar_controller_->DidMouseDown(); 364 scrollbar_controller_->DidMouseDown();
366 ExpectScrollbarsOpacity(1); 365 ExpectScrollbarsOpacity(1);
367 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); 366 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
368 EXPECT_FLOAT_EQ(kIdleThicknessScale, 367 EXPECT_FLOAT_EQ(kIdleThicknessScale,
369 h_scrollbar_layer_->thumb_thickness_scale_factor()); 368 h_scrollbar_layer_->thumb_thickness_scale_factor());
370 369
371 // The fade out animation should have been cleared or cancelled. 370 // The fade out animation should have been cleared or cancelled.
372 EXPECT_TRUE(client_.start_fade().is_null() || 371 EXPECT_TRUE(client_.start_fade().is_null() ||
373 client_.start_fade().IsCancelled()); 372 client_.start_fade().IsCancelled());
374 } 373 }
375 374
376 // Make sure a scrollbar captured then move mouse away doesn't try to fade out. 375 // Make sure a scrollbar captured then move mouse away doesn't try to fade out.
377 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 376 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
378 DontFadeWhileCapturedThenAway) { 377 DontFadeWhileCapturedThenAway) {
379 base::TimeTicks time; 378 base::TimeTicks time;
380 time += base::TimeDelta::FromSeconds(1); 379 time += base::TimeDelta::FromSeconds(1);
381 380
382 scrollbar_controller_->DidScrollBegin(); 381 scrollbar_controller_->DidScrollBegin();
383 scrollbar_controller_->DidScrollUpdate(); 382 scrollbar_controller_->DidScrollUpdate();
384 scrollbar_controller_->DidScrollEnd(); 383 scrollbar_controller_->DidScrollEnd();
385 384
386 // An fade out animation should have been enqueued. 385 // An fade out animation should have been enqueued.
387 EXPECT_EQ(kFadeOutDelay, client_.delay()); 386 EXPECT_EQ(kFadeDelay, client_.delay());
388 EXPECT_FALSE(client_.start_fade().is_null()); 387 EXPECT_FALSE(client_.start_fade().is_null());
389 388
390 // Now move the mouse over the scrollbar and capture it. It should become 389 // Now move the mouse over the scrollbar and capture it. It should become
391 // thick without need for an animation. 390 // thick without need for an animation.
392 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); 391 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0);
393 scrollbar_controller_->DidMouseDown(); 392 scrollbar_controller_->DidMouseDown();
394 ExpectScrollbarsOpacity(1); 393 ExpectScrollbarsOpacity(1);
395 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); 394 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
396 EXPECT_FLOAT_EQ(kIdleThicknessScale, 395 EXPECT_FLOAT_EQ(kIdleThicknessScale,
397 h_scrollbar_layer_->thumb_thickness_scale_factor()); 396 h_scrollbar_layer_->thumb_thickness_scale_factor());
(...skipping 15 matching lines...) Expand all
413 // fade out. 412 // fade out.
414 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, DontFadeWhileCaptured) { 413 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, DontFadeWhileCaptured) {
415 base::TimeTicks time; 414 base::TimeTicks time;
416 time += base::TimeDelta::FromSeconds(1); 415 time += base::TimeDelta::FromSeconds(1);
417 416
418 scrollbar_controller_->DidScrollBegin(); 417 scrollbar_controller_->DidScrollBegin();
419 scrollbar_controller_->DidScrollUpdate(); 418 scrollbar_controller_->DidScrollUpdate();
420 scrollbar_controller_->DidScrollEnd(); 419 scrollbar_controller_->DidScrollEnd();
421 420
422 // An fade out animation should have been enqueued. 421 // An fade out animation should have been enqueued.
423 EXPECT_EQ(kFadeOutDelay, client_.delay()); 422 EXPECT_EQ(kFadeDelay, client_.delay());
424 EXPECT_FALSE(client_.start_fade().is_null()); 423 EXPECT_FALSE(client_.start_fade().is_null());
425 EXPECT_FALSE(client_.start_fade().IsCancelled()); 424 EXPECT_FALSE(client_.start_fade().IsCancelled());
426 425
427 // Now move the mouse over the scrollbar and animate it until it's thick. 426 // Now move the mouse over the scrollbar and animate it until it's thick.
428 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); 427 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0);
429 scrollbar_controller_->Animate(time); 428 scrollbar_controller_->Animate(time);
430 time += kThinningDuration; 429 time += kThinningDuration;
431 scrollbar_controller_->Animate(time); 430 scrollbar_controller_->Animate(time);
432 ExpectScrollbarsOpacity(1); 431 ExpectScrollbarsOpacity(1);
433 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); 432 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
(...skipping 16 matching lines...) Expand all
450 // the scrollbar to fade out. 449 // the scrollbar to fade out.
451 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAfterReleasedFar) { 450 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAfterReleasedFar) {
452 base::TimeTicks time; 451 base::TimeTicks time;
453 time += base::TimeDelta::FromSeconds(1); 452 time += base::TimeDelta::FromSeconds(1);
454 453
455 scrollbar_controller_->DidScrollBegin(); 454 scrollbar_controller_->DidScrollBegin();
456 scrollbar_controller_->DidScrollUpdate(); 455 scrollbar_controller_->DidScrollUpdate();
457 scrollbar_controller_->DidScrollEnd(); 456 scrollbar_controller_->DidScrollEnd();
458 457
459 // An fade out animation should have been enqueued. 458 // An fade out animation should have been enqueued.
460 EXPECT_EQ(kFadeOutDelay, client_.delay()); 459 EXPECT_EQ(kFadeDelay, client_.delay());
461 EXPECT_FALSE(client_.start_fade().is_null()); 460 EXPECT_FALSE(client_.start_fade().is_null());
462 EXPECT_FALSE(client_.start_fade().IsCancelled()); 461 EXPECT_FALSE(client_.start_fade().IsCancelled());
463 462
464 // Now move the mouse over the scrollbar and capture it. 463 // Now move the mouse over the scrollbar and capture it.
465 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); 464 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0);
466 scrollbar_controller_->DidMouseDown(); 465 scrollbar_controller_->DidMouseDown();
467 ExpectScrollbarsOpacity(1); 466 ExpectScrollbarsOpacity(1);
468 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); 467 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
469 EXPECT_FLOAT_EQ(kIdleThicknessScale, 468 EXPECT_FLOAT_EQ(kIdleThicknessScale,
470 h_scrollbar_layer_->thumb_thickness_scale_factor()); 469 h_scrollbar_layer_->thumb_thickness_scale_factor());
(...skipping 30 matching lines...) Expand all
501 // doesn't cause the scrollbar to fade out. 500 // doesn't cause the scrollbar to fade out.
502 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, DontFadeAfterReleasedNear) { 501 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, DontFadeAfterReleasedNear) {
503 base::TimeTicks time; 502 base::TimeTicks time;
504 time += base::TimeDelta::FromSeconds(1); 503 time += base::TimeDelta::FromSeconds(1);
505 504
506 scrollbar_controller_->DidScrollBegin(); 505 scrollbar_controller_->DidScrollBegin();
507 scrollbar_controller_->DidScrollUpdate(); 506 scrollbar_controller_->DidScrollUpdate();
508 scrollbar_controller_->DidScrollEnd(); 507 scrollbar_controller_->DidScrollEnd();
509 508
510 // An fade out animation should have been enqueued. 509 // An fade out animation should have been enqueued.
511 EXPECT_EQ(kFadeOutDelay, client_.delay()); 510 EXPECT_EQ(kFadeDelay, client_.delay());
512 EXPECT_FALSE(client_.start_fade().is_null()); 511 EXPECT_FALSE(client_.start_fade().is_null());
513 EXPECT_FALSE(client_.start_fade().IsCancelled()); 512 EXPECT_FALSE(client_.start_fade().IsCancelled());
514 513
515 // Now move the mouse over the scrollbar and capture it. 514 // Now move the mouse over the scrollbar and capture it.
516 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); 515 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0);
517 scrollbar_controller_->DidMouseDown(); 516 scrollbar_controller_->DidMouseDown();
518 ExpectScrollbarsOpacity(1); 517 ExpectScrollbarsOpacity(1);
519 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); 518 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
520 EXPECT_FLOAT_EQ(kIdleThicknessScale, 519 EXPECT_FLOAT_EQ(kIdleThicknessScale,
521 h_scrollbar_layer_->thumb_thickness_scale_factor()); 520 h_scrollbar_layer_->thumb_thickness_scale_factor());
(...skipping 18 matching lines...) Expand all
540 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 539 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
541 MoveNearScrollbarWhileFading) { 540 MoveNearScrollbarWhileFading) {
542 base::TimeTicks time; 541 base::TimeTicks time;
543 time += base::TimeDelta::FromSeconds(1); 542 time += base::TimeDelta::FromSeconds(1);
544 543
545 scrollbar_controller_->DidScrollBegin(); 544 scrollbar_controller_->DidScrollBegin();
546 scrollbar_controller_->DidScrollUpdate(); 545 scrollbar_controller_->DidScrollUpdate();
547 scrollbar_controller_->DidScrollEnd(); 546 scrollbar_controller_->DidScrollEnd();
548 547
549 // A fade out animation should have been enqueued. Start it. 548 // A fade out animation should have been enqueued. Start it.
550 EXPECT_EQ(kFadeOutDelay, client_.delay()); 549 EXPECT_EQ(kFadeDelay, client_.delay());
551 EXPECT_FALSE(client_.start_fade().is_null()); 550 EXPECT_FALSE(client_.start_fade().is_null());
552 client_.start_fade().Run(); 551 client_.start_fade().Run();
553 552
554 scrollbar_controller_->Animate(time); 553 scrollbar_controller_->Animate(time);
555 ExpectScrollbarsOpacity(1); 554 ExpectScrollbarsOpacity(1);
556 555
557 // Proceed half way through the fade out animation. 556 // Proceed half way through the fade out animation.
558 time += kFadeOutDuration / 2; 557 time += kFadeDuration / 2;
559 scrollbar_controller_->Animate(time); 558 scrollbar_controller_->Animate(time);
560 ExpectScrollbarsOpacity(.5f); 559 ExpectScrollbarsOpacity(.5f);
561 560
562 // Now move the mouse near the scrollbar. It should reset opacity to 1 561 // Now move the mouse near the scrollbar. It should reset opacity to 1
563 // instantly and start animating to thick. 562 // instantly and start animating to thick.
564 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); 563 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1);
565 ExpectScrollbarsOpacity(1); 564 ExpectScrollbarsOpacity(1);
566 EXPECT_FLOAT_EQ(kIdleThicknessScale, 565 EXPECT_FLOAT_EQ(kIdleThicknessScale,
567 v_scrollbar_layer_->thumb_thickness_scale_factor()); 566 v_scrollbar_layer_->thumb_thickness_scale_factor());
568 EXPECT_FLOAT_EQ(kIdleThicknessScale, 567 EXPECT_FLOAT_EQ(kIdleThicknessScale,
(...skipping 10 matching lines...) Expand all
579 578
580 // Make sure we can't capture scrollbar that's completely faded out. 579 // Make sure we can't capture scrollbar that's completely faded out.
581 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, TestCantCaptureWhenFaded) { 580 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, TestCantCaptureWhenFaded) {
582 base::TimeTicks time; 581 base::TimeTicks time;
583 time += base::TimeDelta::FromSeconds(1); 582 time += base::TimeDelta::FromSeconds(1);
584 583
585 scrollbar_controller_->DidScrollBegin(); 584 scrollbar_controller_->DidScrollBegin();
586 scrollbar_controller_->DidScrollUpdate(); 585 scrollbar_controller_->DidScrollUpdate();
587 scrollbar_controller_->DidScrollEnd(); 586 scrollbar_controller_->DidScrollEnd();
588 587
589 EXPECT_EQ(kFadeOutDelay, client_.delay()); 588 EXPECT_EQ(kFadeDelay, client_.delay());
590 EXPECT_FALSE(client_.start_fade().is_null()); 589 EXPECT_FALSE(client_.start_fade().is_null());
591 EXPECT_FALSE(client_.start_fade().IsCancelled()); 590 EXPECT_FALSE(client_.start_fade().IsCancelled());
592 client_.start_fade().Run(); 591 client_.start_fade().Run();
593 scrollbar_controller_->Animate(time); 592 scrollbar_controller_->Animate(time);
594 ExpectScrollbarsOpacity(1); 593 ExpectScrollbarsOpacity(1);
595 594
596 // Fade the scrollbar out completely. 595 // Fade the scrollbar out completely.
597 time += kFadeOutDuration; 596 time += kFadeDuration;
598 scrollbar_controller_->Animate(time); 597 scrollbar_controller_->Animate(time);
599 ExpectScrollbarsOpacity(0); 598 ExpectScrollbarsOpacity(0);
600 599
601 // Move mouse over the scrollbar. It shouldn't thicken the scrollbar since 600 // Move mouse over the scrollbar. It shouldn't thicken the scrollbar since
602 // it's completely faded out. 601 // it's completely faded out.
603 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); 602 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0);
604 scrollbar_controller_->Animate(time); 603 scrollbar_controller_->Animate(time);
605 time += kThinningDuration; 604 time += kThinningDuration;
606 scrollbar_controller_->Animate(time); 605 scrollbar_controller_->Animate(time);
607 ExpectScrollbarsOpacity(0); 606 ExpectScrollbarsOpacity(0);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 EXPECT_TRUE(client_.start_fade().is_null() || 657 EXPECT_TRUE(client_.start_fade().is_null() ||
659 client_.start_fade().IsCancelled()); 658 client_.start_fade().IsCancelled());
660 659
661 scrollbar_controller_->Animate(time); 660 scrollbar_controller_->Animate(time);
662 ExpectScrollbarsOpacity(1); 661 ExpectScrollbarsOpacity(1);
663 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); 662 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
664 EXPECT_FLOAT_EQ(kIdleThicknessScale, 663 EXPECT_FLOAT_EQ(kIdleThicknessScale,
665 h_scrollbar_layer_->thumb_thickness_scale_factor()); 664 h_scrollbar_layer_->thumb_thickness_scale_factor());
666 665
667 // Scrollbar should still be thick and visible. 666 // Scrollbar should still be thick and visible.
668 time += kFadeOutDuration; 667 time += kFadeDuration;
669 scrollbar_controller_->Animate(time); 668 scrollbar_controller_->Animate(time);
670 ExpectScrollbarsOpacity(1); 669 ExpectScrollbarsOpacity(1);
671 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); 670 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
672 EXPECT_FLOAT_EQ(kIdleThicknessScale, 671 EXPECT_FLOAT_EQ(kIdleThicknessScale,
673 h_scrollbar_layer_->thumb_thickness_scale_factor()); 672 h_scrollbar_layer_->thumb_thickness_scale_factor());
674 } 673 }
675 674
676 // Tests that main thread scroll updates immediatley queue a fade out animation 675 // Tests that main thread scroll updates immediatley queue a fade out animation
677 // without requiring a ScrollEnd. 676 // without requiring a ScrollEnd.
678 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 677 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
679 MainThreadScrollQueuesFade) { 678 MainThreadScrollQueuesFade) {
680 ASSERT_TRUE(client_.start_fade().is_null()); 679 ASSERT_TRUE(client_.start_fade().is_null());
681 680
682 // A ScrollUpdate without a ScrollBegin indicates a main thread scroll update 681 // A ScrollUpdate without a ScrollBegin indicates a main thread scroll update
683 // so we should schedule a fade out animation without waiting for a ScrollEnd 682 // so we should schedule a fade out animation without waiting for a ScrollEnd
684 // (which will never come). 683 // (which will never come).
685 scrollbar_controller_->DidScrollUpdate(); 684 scrollbar_controller_->DidScrollUpdate();
686 EXPECT_FALSE(client_.start_fade().is_null()); 685 EXPECT_FALSE(client_.start_fade().is_null());
687 EXPECT_EQ(kFadeOutDelay, client_.delay()); 686 EXPECT_EQ(kFadeDelay, client_.delay());
688 687
689 client_.start_fade().Reset(); 688 client_.start_fade().Reset();
690 689
691 // If we got a ScrollBegin, we shouldn't schedule the fade out animation until 690 // If we got a ScrollBegin, we shouldn't schedule the fade out animation until
692 // we get a corresponding ScrollEnd. 691 // we get a corresponding ScrollEnd.
693 scrollbar_controller_->DidScrollBegin(); 692 scrollbar_controller_->DidScrollBegin();
694 scrollbar_controller_->DidScrollUpdate(); 693 scrollbar_controller_->DidScrollUpdate();
695 EXPECT_TRUE(client_.start_fade().is_null()); 694 EXPECT_TRUE(client_.start_fade().is_null());
696 scrollbar_controller_->DidScrollEnd(); 695 scrollbar_controller_->DidScrollEnd();
697 EXPECT_FALSE(client_.start_fade().is_null()); 696 EXPECT_FALSE(client_.start_fade().is_null());
698 EXPECT_EQ(kFadeOutDelay, client_.delay()); 697 EXPECT_EQ(kFadeDelay, client_.delay());
699 } 698 }
700 699
701 // Make sure that if the scroll update is as a result of a resize, we use the 700 // Make sure that if the scroll update is as a result of a resize, we use the
702 // resize delay time instead of the default one. 701 // resize delay time instead of the default one.
703 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, ResizeFadeDuration) { 702 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, ResizeFadeDuration) {
704 ASSERT_TRUE(client_.delay().is_zero()); 703 ASSERT_TRUE(client_.delay().is_zero());
705 704
706 scrollbar_controller_->DidResize(); 705 scrollbar_controller_->DidResize();
707 EXPECT_FALSE(client_.start_fade().is_null()); 706 EXPECT_FALSE(client_.start_fade().is_null());
708 EXPECT_EQ(kResizeFadeOutDelay, client_.delay()); 707 EXPECT_EQ(kResizeFadeOutDelay, client_.delay());
709 708
710 client_.delay() = base::TimeDelta(); 709 client_.delay() = base::TimeDelta();
711 710
712 // We should use the gesture delay rather than the resize delay if we're in a 711 // We should use the gesture delay rather than the resize delay if we're in a
713 // gesture scroll, even if it is resizing. 712 // gesture scroll, even if it is resizing.
714 scrollbar_controller_->DidScrollBegin(); 713 scrollbar_controller_->DidScrollBegin();
715 scrollbar_controller_->DidResize(); 714 scrollbar_controller_->DidResize();
716 scrollbar_controller_->DidScrollEnd(); 715 scrollbar_controller_->DidScrollEnd();
717 716
718 EXPECT_FALSE(client_.start_fade().is_null()); 717 EXPECT_FALSE(client_.start_fade().is_null());
719 EXPECT_EQ(kFadeOutDelay, client_.delay()); 718 EXPECT_EQ(kFadeDelay, client_.delay());
720 } 719 }
721 720
722 // Tests that the fade effect is animated. 721 // Tests that the fade effect is animated.
723 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAnimated) { 722 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAnimated) {
724 base::TimeTicks time; 723 base::TimeTicks time;
725 time += base::TimeDelta::FromSeconds(1); 724 time += base::TimeDelta::FromSeconds(1);
726 725
727 // Scroll to make the scrollbars visible. 726 // Scroll to make the scrollbars visible.
728 scrollbar_controller_->DidScrollBegin(); 727 scrollbar_controller_->DidScrollBegin();
729 scrollbar_controller_->DidScrollUpdate(); 728 scrollbar_controller_->DidScrollUpdate();
730 scrollbar_controller_->DidScrollEnd(); 729 scrollbar_controller_->DidScrollEnd();
731 730
732 // Appearance is instant. 731 // Appearance is instant.
733 ExpectScrollbarsOpacity(1); 732 ExpectScrollbarsOpacity(1);
734 733
735 // An fade out animation should have been enqueued. 734 // An fade out animation should have been enqueued.
736 EXPECT_EQ(kFadeOutDelay, client_.delay()); 735 EXPECT_EQ(kFadeDelay, client_.delay());
737 EXPECT_FALSE(client_.start_fade().is_null()); 736 EXPECT_FALSE(client_.start_fade().is_null());
738 client_.start_fade().Run(); 737 client_.start_fade().Run();
739 738
740 // Test that at half the fade duration time, the opacity is at half. 739 // Test that at half the fade duration time, the opacity is at half.
741 scrollbar_controller_->Animate(time); 740 scrollbar_controller_->Animate(time);
742 ExpectScrollbarsOpacity(1); 741 ExpectScrollbarsOpacity(1);
743 742
744 time += kFadeOutDuration / 2; 743 time += kFadeDuration / 2;
745 scrollbar_controller_->Animate(time); 744 scrollbar_controller_->Animate(time);
746 ExpectScrollbarsOpacity(.5f); 745 ExpectScrollbarsOpacity(.5f);
747 746
748 time += kFadeOutDuration / 2; 747 time += kFadeDuration / 2;
749 scrollbar_controller_->Animate(time); 748 scrollbar_controller_->Animate(time);
750 ExpectScrollbarsOpacity(0); 749 ExpectScrollbarsOpacity(0);
751 } 750 }
752 751
753 // Tests that the controller tells the client when the scrollbars hide/show. 752 // Tests that the controller tells the client when the scrollbars hide/show.
754 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, NotifyChangedVisibility) { 753 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, NotifyChangedVisibility) {
755 base::TimeTicks time; 754 base::TimeTicks time;
756 time += base::TimeDelta::FromSeconds(1); 755 time += base::TimeDelta::FromSeconds(1);
757 756
758 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); 757 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1);
759 // Scroll to make the scrollbars visible. 758 // Scroll to make the scrollbars visible.
760 scrollbar_controller_->DidScrollBegin(); 759 scrollbar_controller_->DidScrollBegin();
761 scrollbar_controller_->DidScrollUpdate(); 760 scrollbar_controller_->DidScrollUpdate();
762 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 761 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
763 Mock::VerifyAndClearExpectations(&client_); 762 Mock::VerifyAndClearExpectations(&client_);
764 763
765 scrollbar_controller_->DidScrollEnd(); 764 scrollbar_controller_->DidScrollEnd();
766 765
767 // Play out the fade out animation. We shouldn't notify that the scrollbars 766 // Play out the fade out animation. We shouldn't notify that the scrollbars
768 // are hidden until the animation is completly over. We can (but don't have 767 // are hidden until the animation is completly over. We can (but don't have
769 // to) notify during the animation that the scrollbars are still visible. 768 // to) notify during the animation that the scrollbars are still visible.
770 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(0); 769 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(0);
771 ASSERT_FALSE(client_.start_fade().is_null()); 770 ASSERT_FALSE(client_.start_fade().is_null());
772 client_.start_fade().Run(); 771 client_.start_fade().Run();
773 scrollbar_controller_->Animate(time); 772 scrollbar_controller_->Animate(time);
774 time += kFadeOutDuration / 4; 773 time += kFadeDuration / 4;
775 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 774 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
776 scrollbar_controller_->Animate(time); 775 scrollbar_controller_->Animate(time);
777 time += kFadeOutDuration / 4; 776 time += kFadeDuration / 4;
778 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 777 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
779 scrollbar_controller_->Animate(time); 778 scrollbar_controller_->Animate(time);
780 time += kFadeOutDuration / 4; 779 time += kFadeDuration / 4;
781 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 780 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
782 scrollbar_controller_->Animate(time); 781 scrollbar_controller_->Animate(time);
783 ExpectScrollbarsOpacity(.25f); 782 ExpectScrollbarsOpacity(.25f);
784 Mock::VerifyAndClearExpectations(&client_); 783 Mock::VerifyAndClearExpectations(&client_);
785 784
786 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); 785 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1);
787 time += kFadeOutDuration / 4; 786 time += kFadeDuration / 4;
788 scrollbar_controller_->Animate(time); 787 scrollbar_controller_->Animate(time);
789 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); 788 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
790 ExpectScrollbarsOpacity(0); 789 ExpectScrollbarsOpacity(0);
791 Mock::VerifyAndClearExpectations(&client_); 790 Mock::VerifyAndClearExpectations(&client_);
792 791
793 // Calling DidScrollUpdate without a begin (i.e. update from commit) should 792 // Calling DidScrollUpdate without a begin (i.e. update from commit) should
794 // also notify. 793 // also notify.
795 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); 794 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1);
796 scrollbar_controller_->DidScrollUpdate(); 795 scrollbar_controller_->DidScrollUpdate();
797 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 796 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 time += kThinningDuration; 881 time += kThinningDuration;
883 scrollbar_controller_->Animate(time); 882 scrollbar_controller_->Animate(time);
884 ExpectScrollbarsOpacity(1); 883 ExpectScrollbarsOpacity(1);
885 EXPECT_FLOAT_EQ(kIdleThicknessScale, 884 EXPECT_FLOAT_EQ(kIdleThicknessScale,
886 v_scrollbar_layer_->thumb_thickness_scale_factor()); 885 v_scrollbar_layer_->thumb_thickness_scale_factor());
887 EXPECT_FLOAT_EQ(kIdleThicknessScale, 886 EXPECT_FLOAT_EQ(kIdleThicknessScale,
888 h_scrollbar_layer_->thumb_thickness_scale_factor()); 887 h_scrollbar_layer_->thumb_thickness_scale_factor());
889 888
890 // An fade out animation should have been enqueued. 889 // An fade out animation should have been enqueued.
891 EXPECT_FALSE(client_.start_fade().is_null()); 890 EXPECT_FALSE(client_.start_fade().is_null());
892 EXPECT_EQ(kFadeOutDelay, client_.delay()); 891 EXPECT_EQ(kFadeDelay, client_.delay());
893 } 892 }
894 893
895 // Move mouse near both scrollbars at the same time. 894 // Move mouse near both scrollbars at the same time.
896 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearBoth) { 895 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearBoth) {
897 base::TimeTicks time; 896 base::TimeTicks time;
898 time += base::TimeDelta::FromSeconds(1); 897 time += base::TimeDelta::FromSeconds(1);
899 898
900 // Scroll to make the scrollbars visible. 899 // Scroll to make the scrollbars visible.
901 scrollbar_controller_->DidScrollBegin(); 900 scrollbar_controller_->DidScrollBegin();
902 scrollbar_controller_->DidScrollUpdate(); 901 scrollbar_controller_->DidScrollUpdate();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 time += kThinningDuration; 973 time += kThinningDuration;
975 scrollbar_controller_->Animate(time); 974 scrollbar_controller_->Animate(time);
976 ExpectScrollbarsOpacity(1); 975 ExpectScrollbarsOpacity(1);
977 EXPECT_FLOAT_EQ(kIdleThicknessScale, 976 EXPECT_FLOAT_EQ(kIdleThicknessScale,
978 v_scrollbar_layer_->thumb_thickness_scale_factor()); 977 v_scrollbar_layer_->thumb_thickness_scale_factor());
979 EXPECT_FLOAT_EQ(kIdleThicknessScale, 978 EXPECT_FLOAT_EQ(kIdleThicknessScale,
980 h_scrollbar_layer_->thumb_thickness_scale_factor()); 979 h_scrollbar_layer_->thumb_thickness_scale_factor());
981 980
982 // An fade out animation should have been enqueued. 981 // An fade out animation should have been enqueued.
983 EXPECT_FALSE(client_.start_fade().is_null()); 982 EXPECT_FALSE(client_.start_fade().is_null());
984 EXPECT_EQ(kFadeOutDelay, client_.delay()); 983 EXPECT_EQ(kFadeDelay, client_.delay());
985 } 984 }
986 985
987 // Ensure we have a delay fadeout animation after mouse leave without a mouse 986 // Ensure we have a delay fadeout animation after mouse leave without a mouse
988 // move. 987 // move.
989 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseLeaveFadeOut) { 988 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseLeaveFadeOut) {
990 base::TimeTicks time; 989 base::TimeTicks time;
991 time += base::TimeDelta::FromSeconds(1); 990 time += base::TimeDelta::FromSeconds(1);
992 991
993 // Move mouse near scrollbar. 992 // Move mouse near scrollbar.
994 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); 993 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1);
995 994
996 // Scroll to make the scrollbars visible. 995 // Scroll to make the scrollbars visible.
997 scrollbar_controller_->DidScrollBegin(); 996 scrollbar_controller_->DidScrollBegin();
998 scrollbar_controller_->DidScrollUpdate(); 997 scrollbar_controller_->DidScrollUpdate();
999 scrollbar_controller_->DidScrollEnd(); 998 scrollbar_controller_->DidScrollEnd();
1000 999
1001 // Should not have delay fadeout animation. 1000 // Should not have delay fadeout animation.
1002 EXPECT_TRUE(client_.start_fade().is_null() || 1001 EXPECT_TRUE(client_.start_fade().is_null() ||
1003 client_.start_fade().IsCancelled()); 1002 client_.start_fade().IsCancelled());
1004 1003
1005 // Mouse leave. 1004 // Mouse leave.
1006 scrollbar_controller_->DidMouseLeave(); 1005 scrollbar_controller_->DidMouseLeave();
1007 1006
1008 // An fade out animation should have been enqueued. 1007 // An fade out animation should have been enqueued.
1009 EXPECT_FALSE(client_.start_fade().is_null()); 1008 EXPECT_FALSE(client_.start_fade().is_null());
1010 EXPECT_EQ(kFadeOutDelay, client_.delay()); 1009 EXPECT_EQ(kFadeDelay, client_.delay());
1011 } 1010 }
1012 1011
1013 // Scrollbars should schedule a delay show when mouse hover the show scrollbar 1012 // Scrollbars should schedule a delay fade in when mouse hover the show
1014 // region of a hidden scrollbar. 1013 // scrollbar region of a hidden scrollbar.
1015 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, BasicMouseHoverShow) { 1014 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, BasicMouseHoverFadeIn) {
1016 base::TimeTicks time; 1015 base::TimeTicks time;
1017 time += base::TimeDelta::FromSeconds(1); 1016 time += base::TimeDelta::FromSeconds(1);
1018 1017
1019 // Move mouse hover the show scrollbar region of scrollbar. 1018 // Move mouse hover the fade in scrollbar region of scrollbar.
1020 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1019 scrollbar_controller_->DidMouseMoveNear(
1021 kMouseMoveDistanceToTriggerShow - 1); 1020 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 1);
1022 1021
1023 // An show animation should have been enqueued. 1022 // An fade in animation should have been enqueued.
1024 EXPECT_FALSE(client_.start_fade().is_null()); 1023 EXPECT_FALSE(client_.start_fade().is_null());
1025 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1024 EXPECT_FALSE(client_.start_fade().IsCancelled());
1026 EXPECT_EQ(kShowDelay, client_.delay()); 1025 EXPECT_EQ(kFadeDelay, client_.delay());
1027 1026
1028 // Play the delay animation. 1027 // Play the delay animation.
1029 client_.start_fade().Run(); 1028 client_.start_fade().Run();
1030 EXPECT_TRUE(client_.start_fade().IsCancelled()); 1029 EXPECT_TRUE(client_.start_fade().IsCancelled());
1030
1031 scrollbar_controller_->Animate(time);
1032 time += kFadeDuration / 2;
1033 scrollbar_controller_->Animate(time);
1034
1035 ExpectScrollbarsOpacity(0.5);
1036 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
1037
1038 time += kFadeDuration / 2;
1039 scrollbar_controller_->Animate(time);
1040
1041 ExpectScrollbarsOpacity(1);
1031 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 1042 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
1032 } 1043 }
1033 1044
1034 // Scrollbars should not schedule a new delay show when the mouse hovers inside 1045 // Scrollbars should not schedule a new delay fade in when the mouse hovers
1035 // a scrollbar already scheduled a delay show. 1046 // inside a scrollbar already scheduled a delay fade in.
1036 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 1047 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
1037 MouseHoverScrollbarAndMoveInside) { 1048 MouseHoverScrollbarAndMoveInside) {
1038 base::TimeTicks time; 1049 base::TimeTicks time;
1039 time += base::TimeDelta::FromSeconds(1); 1050 time += base::TimeDelta::FromSeconds(1);
1040 1051
1041 // Move mouse hover the show scrollbar region of scrollbar. 1052 // Move mouse hover the fade in scrollbar region of scrollbar.
1042 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1053 scrollbar_controller_->DidMouseMoveNear(
1043 kMouseMoveDistanceToTriggerShow - 1); 1054 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 1);
1044 1055
1045 // An show animation should have been enqueued. 1056 // An fade in animation should have been enqueued.
1046 EXPECT_FALSE(client_.start_fade().is_null()); 1057 EXPECT_FALSE(client_.start_fade().is_null());
1047 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1058 EXPECT_FALSE(client_.start_fade().IsCancelled());
1048 EXPECT_EQ(kShowDelay, client_.delay()); 1059 EXPECT_EQ(kFadeDelay, client_.delay());
1049 1060
1050 base::Closure& fade = client_.start_fade(); 1061 base::Closure& fade = client_.start_fade();
1051 // Move mouse still hover the show scrollbar region of scrollbar should not 1062 // Move mouse still hover the fade in scrollbar region of scrollbar should not
1052 // post a new show. 1063 // post a new fade in.
1053 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1064 scrollbar_controller_->DidMouseMoveNear(
1054 kMouseMoveDistanceToTriggerShow - 2); 1065 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 2);
1055 1066
1056 EXPECT_TRUE(fade.Equals(client_.start_fade())); 1067 EXPECT_TRUE(fade.Equals(client_.start_fade()));
1057 } 1068 }
1058 1069
1059 // Scrollbars should cancel delay show when mouse hover hidden scrollbar then 1070 // Scrollbars should cancel delay fade in when mouse hover hidden scrollbar then
1060 // move far away. 1071 // move far away.
1061 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 1072 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
1062 MouseHoverThenOutShouldCancelShow) { 1073 MouseHoverThenOutShouldCancelFadeIn) {
1063 base::TimeTicks time; 1074 base::TimeTicks time;
1064 time += base::TimeDelta::FromSeconds(1); 1075 time += base::TimeDelta::FromSeconds(1);
1065 1076
1066 // Move mouse hover the show scrollbar region of scrollbar. 1077 // Move mouse hover the fade in scrollbar region of scrollbar.
1067 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1078 scrollbar_controller_->DidMouseMoveNear(
1068 kMouseMoveDistanceToTriggerShow - 1); 1079 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 1);
1069 1080
1070 // An show animation should have been enqueued. 1081 // An fade in animation should have been enqueued.
1071 EXPECT_FALSE(client_.start_fade().is_null()); 1082 EXPECT_FALSE(client_.start_fade().is_null());
1072 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1083 EXPECT_FALSE(client_.start_fade().IsCancelled());
1073 EXPECT_EQ(kShowDelay, client_.delay()); 1084 EXPECT_EQ(kFadeDelay, client_.delay());
1074 1085
1075 // Move mouse far away,delay show should be canceled. 1086 // Move mouse far away,delay fade in should be canceled.
1076 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1087 scrollbar_controller_->DidMouseMoveNear(VERTICAL,
1077 kMouseMoveDistanceToTriggerShow); 1088 kMouseMoveDistanceToTriggerFadeIn);
1078 EXPECT_TRUE(client_.start_fade().is_null() || 1089 EXPECT_TRUE(client_.start_fade().is_null() ||
1079 client_.start_fade().IsCancelled()); 1090 client_.start_fade().IsCancelled());
1080 } 1091 }
1081 1092
1082 // Scrollbars should cancel delay show when mouse hover hidden scrollbar then 1093 // Scrollbars should cancel delay fade in when mouse hover hidden scrollbar then
1083 // move out of window. 1094 // move out of window.
1084 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 1095 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
1085 MouseHoverThenLeaveShouldCancelShowThenEnterShouldShow) { 1096 MouseHoverThenLeaveShouldCancelShowThenEnterShouldFadeIn) {
1086 base::TimeTicks time; 1097 base::TimeTicks time;
1087 time += base::TimeDelta::FromSeconds(1); 1098 time += base::TimeDelta::FromSeconds(1);
1088 1099
1089 // Move mouse hover the show scrollbar region of scrollbar. 1100 // Move mouse hover the fade in scrollbar region of scrollbar.
1090 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1101 scrollbar_controller_->DidMouseMoveNear(
1091 kMouseMoveDistanceToTriggerShow - 1); 1102 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 1);
1092 1103
1093 // An show animation should have been enqueued. 1104 // An fade in animation should have been enqueued.
1094 EXPECT_FALSE(client_.start_fade().is_null()); 1105 EXPECT_FALSE(client_.start_fade().is_null());
1095 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1106 EXPECT_FALSE(client_.start_fade().IsCancelled());
1096 EXPECT_EQ(kShowDelay, client_.delay()); 1107 EXPECT_EQ(kFadeDelay, client_.delay());
1097 1108
1098 // Move mouse out of window,delay show should be canceled. 1109 // Move mouse out of window,delay fade in should be canceled.
1099 scrollbar_controller_->DidMouseLeave(); 1110 scrollbar_controller_->DidMouseLeave();
1100 EXPECT_TRUE(client_.start_fade().is_null() || 1111 EXPECT_TRUE(client_.start_fade().is_null() ||
1101 client_.start_fade().IsCancelled()); 1112 client_.start_fade().IsCancelled());
1102 1113
1103 // Move mouse hover the show scrollbar region of scrollbar. 1114 // Move mouse hover the fade in scrollbar region of scrollbar.
1104 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1115 scrollbar_controller_->DidMouseMoveNear(
1105 kMouseMoveDistanceToTriggerShow - 1); 1116 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 1);
1106 1117
1107 // An show animation should have been enqueued. 1118 // An fade in animation should have been enqueued.
1108 EXPECT_FALSE(client_.start_fade().is_null()); 1119 EXPECT_FALSE(client_.start_fade().is_null());
1109 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1120 EXPECT_FALSE(client_.start_fade().IsCancelled());
1110 EXPECT_EQ(kShowDelay, client_.delay()); 1121 EXPECT_EQ(kFadeDelay, client_.delay());
1111 1122
1112 // Play the delay animation. 1123 // Play the delay animation.
1113 client_.start_fade().Run(); 1124 client_.start_fade().Run();
1114 EXPECT_TRUE(client_.start_fade().IsCancelled()); 1125 EXPECT_TRUE(client_.start_fade().IsCancelled());
1126
1127 scrollbar_controller_->Animate(time);
1128 time += kFadeDuration;
1129 scrollbar_controller_->Animate(time);
1130
1115 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 1131 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
1116 } 1132 }
1117 1133
1118 class ScrollbarAnimationControllerAndroidTest 1134 class ScrollbarAnimationControllerAndroidTest
1119 : public testing::Test, 1135 : public testing::Test,
1120 public ScrollbarAnimationControllerClient { 1136 public ScrollbarAnimationControllerClient {
1121 public: 1137 public:
1122 ScrollbarAnimationControllerAndroidTest() 1138 ScrollbarAnimationControllerAndroidTest()
1123 : host_impl_(&task_runner_provider_, &task_graph_runner_), 1139 : host_impl_(&task_runner_provider_, &task_graph_runner_),
1124 did_request_redraw_(false), 1140 did_request_redraw_(false),
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); 1618 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity());
1603 1619
1604 time += base::TimeDelta::FromSeconds(1); 1620 time += base::TimeDelta::FromSeconds(1);
1605 scrollbar_controller_->DidScrollEnd(); 1621 scrollbar_controller_->DidScrollEnd();
1606 EXPECT_FALSE(did_request_animate_); 1622 EXPECT_FALSE(did_request_animate_);
1607 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); 1623 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity());
1608 } 1624 }
1609 1625
1610 } // namespace 1626 } // namespace
1611 } // namespace cc 1627 } // namespace cc
OLDNEW
« no previous file with comments | « cc/input/scrollbar_animation_controller.cc ('k') | cc/layers/scrollbar_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698