Chromium Code Reviews| 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_thinning.h" | 5 #include "cc/input/scrollbar_animation_controller_thinning.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" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 LayerImpl::Create(host_impl_.active_tree(), 3); | 48 LayerImpl::Create(host_impl_.active_tree(), 3); |
| 49 clip_layer_ = clip.get(); | 49 clip_layer_ = clip.get(); |
| 50 scroll_layer->SetScrollClipLayer(clip_layer_->id()); | 50 scroll_layer->SetScrollClipLayer(clip_layer_->id()); |
| 51 LayerImpl* scroll_layer_ptr = scroll_layer.get(); | 51 LayerImpl* scroll_layer_ptr = scroll_layer.get(); |
| 52 | 52 |
| 53 const int kId = 2; | 53 const int kId = 2; |
| 54 const int kThumbThickness = 10; | 54 const int kThumbThickness = 10; |
| 55 const int kTrackStart = 0; | 55 const int kTrackStart = 0; |
| 56 const bool kIsLeftSideVerticalScrollbar = false; | 56 const bool kIsLeftSideVerticalScrollbar = false; |
| 57 const bool kIsOverlayScrollbar = true; | 57 const bool kIsOverlayScrollbar = true; |
| 58 | |
| 59 const base::TimeDelta delay_before_starting | |
| 60 = base::TimeDelta::FromSeconds(2); | |
| 61 const base::TimeDelta resize_delay_before_starting | |
| 62 = base::TimeDelta::FromSeconds(5); | |
| 63 const base::TimeDelta duration = base::TimeDelta::FromSeconds(3); | |
| 64 | |
| 58 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = | 65 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
| 59 SolidColorScrollbarLayerImpl::Create( | 66 SolidColorScrollbarLayerImpl::Create( |
| 60 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, | 67 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, |
| 61 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); | 68 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); |
| 62 scrollbar_layer_ = scrollbar.get(); | 69 scrollbar_layer_ = scrollbar.get(); |
| 63 | 70 |
| 64 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); | 71 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); |
| 65 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); | 72 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); |
| 66 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); | 73 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); |
| 67 | 74 |
| 68 scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); | 75 scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); |
| 69 scrollbar_layer_->test_properties()->opacity_can_animate = true; | 76 scrollbar_layer_->test_properties()->opacity_can_animate = true; |
| 70 clip_layer_->SetBounds(gfx::Size(100, 100)); | 77 clip_layer_->SetBounds(gfx::Size(100, 100)); |
| 71 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); | 78 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
| 72 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); | 79 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 73 | 80 |
| 74 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( | 81 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( |
| 75 scroll_layer_ptr->id(), this, base::TimeDelta::FromSeconds(2), | 82 scroll_layer_ptr->id(), this, delay_before_starting, |
| 76 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(3)); | 83 resize_delay_before_starting, duration); |
| 77 } | 84 } |
| 78 | 85 |
| 79 FakeImplTaskRunnerProvider task_runner_provider_; | 86 FakeImplTaskRunnerProvider task_runner_provider_; |
| 80 TestSharedBitmapManager shared_bitmap_manager_; | 87 TestSharedBitmapManager shared_bitmap_manager_; |
| 81 TestTaskGraphRunner task_graph_runner_; | 88 TestTaskGraphRunner task_graph_runner_; |
| 82 FakeLayerTreeHostImpl host_impl_; | 89 FakeLayerTreeHostImpl host_impl_; |
| 83 std::unique_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; | 90 std::unique_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; |
| 84 LayerImpl* clip_layer_; | 91 LayerImpl* clip_layer_; |
| 85 SolidColorScrollbarLayerImpl* scrollbar_layer_; | 92 SolidColorScrollbarLayerImpl* scrollbar_layer_; |
| 86 | 93 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 // The thickness now gets big again. | 386 // The thickness now gets big again. |
| 380 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor()); | 387 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 381 | 388 |
| 382 time += base::TimeDelta::FromSeconds(1); | 389 time += base::TimeDelta::FromSeconds(1); |
| 383 scrollbar_controller_->Animate(time); | 390 scrollbar_controller_->Animate(time); |
| 384 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity()); | 391 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity()); |
| 385 // The thickness now gets big again. | 392 // The thickness now gets big again. |
| 386 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 393 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 387 } | 394 } |
| 388 | 395 |
| 396 // First move the pointer on the scrollbar, then press it, then away. | |
| 397 // Confirm that the bar gets thick and dark. Then mouse up. Confirm that | |
| 398 // the bar gets thin and light. | |
| 399 TEST_F(ScrollbarAnimationControllerThinningTest, | |
| 400 MouseCaptureAndReleaseOutOfBar) { | |
| 401 base::TimeTicks time; | |
| 402 time += base::TimeDelta::FromSeconds(1); | |
|
bokan
2016/09/23 20:21:29
This should be unneeded, right? Without it we'd ju
chaopeng
2016/09/23 20:26:47
No. It isnot checking nullptr, it is checking is i
bokan
2016/09/23 20:30:08
Ugh, my bad, you're right. That's confusing. Ok, f
| |
| 403 | |
| 404 // Move in | |
| 405 scrollbar_controller_->DidMouseMoveNear(0); | |
| 406 | |
| 407 // Jump X seconds, first we need to make the time not 0, second we need to | |
|
bokan
2016/09/23 20:21:29
This isn't quite right. We're making the time not
| |
| 408 // call Animate once to start the animation(initial the last_awaken_time_), | |
| 409 // now you can jump x seconds. | |
| 410 scrollbar_controller_->Animate(time); | |
| 411 time += base::TimeDelta::FromSeconds(4); | |
|
bokan
2016/09/23 20:21:28
I meant you should use the constant here (this sho
| |
| 412 scrollbar_controller_->Animate(time); | |
| 413 | |
| 414 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
| 415 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
| 416 | |
| 417 // Capture | |
| 418 scrollbar_controller_->DidCaptureScrollbarBegin(); | |
| 419 time += base::TimeDelta::FromSeconds(1); | |
| 420 scrollbar_controller_->Animate(time); | |
| 421 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
| 422 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
| 423 | |
| 424 // test for 10 seconds, stay thick and dark | |
| 425 for (int i = 0; i < 10; ++i) { | |
| 426 // move away from bar. | |
| 427 scrollbar_controller_->DidMouseMoveNear(26 + i); | |
| 428 time += base::TimeDelta::FromSeconds(1); | |
| 429 scrollbar_controller_->Animate(time); | |
| 430 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
| 431 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
| 432 } | |
| 433 | |
| 434 // release | |
| 435 scrollbar_controller_->DidCaptureScrollbarEnd(); | |
| 436 | |
| 437 // get thickness and light | |
| 438 time += base::TimeDelta::FromSeconds(1); | |
| 439 scrollbar_controller_->Animate(time); | |
| 440 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
| 441 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
| 442 | |
| 443 time += base::TimeDelta::FromSeconds(1); | |
| 444 scrollbar_controller_->Animate(time); | |
| 445 EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->Opacity()); | |
| 446 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
| 447 | |
| 448 time += base::TimeDelta::FromSeconds(1); | |
| 449 scrollbar_controller_->Animate(time); | |
| 450 EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->Opacity()); | |
| 451 EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
| 452 | |
| 453 time += base::TimeDelta::FromSeconds(1); | |
| 454 scrollbar_controller_->Animate(time); | |
| 455 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity()); | |
| 456 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
| 457 } | |
| 458 | |
| 459 // First move the pointer on the scrollbar, then press it, then away. | |
| 460 // Confirm that the bar gets thick and dark. Then move point on the | |
| 461 // scrollbar and mouse up. Confirm that the bar gets thick and dark. | |
| 462 TEST_F(ScrollbarAnimationControllerThinningTest, MouseCaptureAndReleaseOnBar) { | |
| 463 base::TimeTicks time; | |
| 464 time += base::TimeDelta::FromSeconds(1); | |
| 465 | |
| 466 // Move in | |
| 467 scrollbar_controller_->DidMouseMoveNear(0); | |
| 468 | |
| 469 scrollbar_controller_->Animate(time); | |
| 470 time += base::TimeDelta::FromSeconds(4); | |
| 471 scrollbar_controller_->Animate(time); | |
| 472 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
| 473 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
| 474 | |
| 475 // Capture | |
| 476 scrollbar_controller_->DidCaptureScrollbarBegin(); | |
| 477 time += base::TimeDelta::FromSeconds(1); | |
| 478 scrollbar_controller_->Animate(time); | |
| 479 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
| 480 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
| 481 | |
| 482 // test for 10 seconds, stay thick and dark | |
| 483 for (int i = 0; i < 10; ++i) { | |
| 484 // move away from bar. | |
| 485 scrollbar_controller_->DidMouseMoveNear(26 + i); | |
| 486 time += base::TimeDelta::FromSeconds(1); | |
| 487 scrollbar_controller_->Animate(time); | |
| 488 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
| 489 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
| 490 } | |
| 491 | |
| 492 // move to the bar. | |
| 493 scrollbar_controller_->DidMouseMoveNear(0); | |
| 494 | |
| 495 // release | |
| 496 scrollbar_controller_->DidCaptureScrollbarEnd(); | |
| 497 | |
| 498 // stay thick and dark | |
| 499 // test for 10 seconds, stay thick and dark | |
| 500 for (int i = 0; i < 10; ++i) { | |
| 501 time += base::TimeDelta::FromSeconds(1); | |
| 502 scrollbar_controller_->Animate(time); | |
| 503 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
| 504 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
| 505 } | |
| 506 } | |
| 507 | |
| 389 } // namespace | 508 } // namespace |
| 390 } // namespace cc | 509 } // namespace cc |
| OLD | NEW |