Chromium Code Reviews| Index: cc/input/scrollbar_animation_controller_thinning_unittest.cc |
| diff --git a/cc/input/scrollbar_animation_controller_thinning_unittest.cc b/cc/input/scrollbar_animation_controller_thinning_unittest.cc |
| index e1a1aa3cd53a5b79aafd9cd8c544d86f539232cf..90090b1fa69e30d7b20cec2a5a56bd0cb80895af 100644 |
| --- a/cc/input/scrollbar_animation_controller_thinning_unittest.cc |
| +++ b/cc/input/scrollbar_animation_controller_thinning_unittest.cc |
| @@ -55,6 +55,13 @@ class ScrollbarAnimationControllerThinningTest |
| const int kTrackStart = 0; |
| const bool kIsLeftSideVerticalScrollbar = false; |
| const bool kIsOverlayScrollbar = true; |
| + |
| + const base::TimeDelta delay_before_starting |
| + = base::TimeDelta::FromSeconds(2); |
| + const base::TimeDelta resize_delay_before_starting |
| + = base::TimeDelta::FromSeconds(5); |
| + const base::TimeDelta duration = base::TimeDelta::FromSeconds(3); |
| + |
| std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
| SolidColorScrollbarLayerImpl::Create( |
| host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, |
| @@ -72,8 +79,8 @@ class ScrollbarAnimationControllerThinningTest |
| host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( |
| - scroll_layer_ptr->id(), this, base::TimeDelta::FromSeconds(2), |
| - base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(3)); |
| + scroll_layer_ptr->id(), this, delay_before_starting, |
| + resize_delay_before_starting, duration); |
| } |
| FakeImplTaskRunnerProvider task_runner_provider_; |
| @@ -386,5 +393,117 @@ TEST_F(ScrollbarAnimationControllerThinningTest, MouseNearThenOver) { |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| } |
| +// First move the pointer on the scrollbar, then press it, then away. |
| +// Confirm that the bar gets thick and dark. Then mouse up. Confirm that |
| +// the bar gets thin and light. |
| +TEST_F(ScrollbarAnimationControllerThinningTest, |
| + MouseCaptureAndReleaseOutOfBar) { |
| + base::TimeTicks time; |
| + 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
|
| + |
| + // Move in |
| + scrollbar_controller_->DidMouseMoveNear(0); |
| + |
| + // 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
|
| + // call Animate once to start the animation(initial the last_awaken_time_), |
| + // now you can jump x seconds. |
| + scrollbar_controller_->Animate(time); |
| + time += base::TimeDelta::FromSeconds(4); |
|
bokan
2016/09/23 20:21:28
I meant you should use the constant here (this sho
|
| + scrollbar_controller_->Animate(time); |
| + |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| + |
| + // Capture |
| + scrollbar_controller_->DidCaptureScrollbarBegin(); |
| + time += base::TimeDelta::FromSeconds(1); |
| + scrollbar_controller_->Animate(time); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| + |
| + // test for 10 seconds, stay thick and dark |
| + for (int i = 0; i < 10; ++i) { |
| + // move away from bar. |
| + scrollbar_controller_->DidMouseMoveNear(26 + i); |
| + time += base::TimeDelta::FromSeconds(1); |
| + scrollbar_controller_->Animate(time); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| + } |
| + |
| + // release |
| + scrollbar_controller_->DidCaptureScrollbarEnd(); |
| + |
| + // get thickness and light |
| + time += base::TimeDelta::FromSeconds(1); |
| + scrollbar_controller_->Animate(time); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| + |
| + time += base::TimeDelta::FromSeconds(1); |
| + scrollbar_controller_->Animate(time); |
| + EXPECT_FLOAT_EQ(0.9f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| + |
| + time += base::TimeDelta::FromSeconds(1); |
| + scrollbar_controller_->Animate(time); |
| + EXPECT_FLOAT_EQ(0.8f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| + |
| + time += base::TimeDelta::FromSeconds(1); |
| + scrollbar_controller_->Animate(time); |
| + EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| +} |
| + |
| +// First move the pointer on the scrollbar, then press it, then away. |
| +// Confirm that the bar gets thick and dark. Then move point on the |
| +// scrollbar and mouse up. Confirm that the bar gets thick and dark. |
| +TEST_F(ScrollbarAnimationControllerThinningTest, MouseCaptureAndReleaseOnBar) { |
| + base::TimeTicks time; |
| + time += base::TimeDelta::FromSeconds(1); |
| + |
| + // Move in |
| + scrollbar_controller_->DidMouseMoveNear(0); |
| + |
| + scrollbar_controller_->Animate(time); |
| + time += base::TimeDelta::FromSeconds(4); |
| + scrollbar_controller_->Animate(time); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| + |
| + // Capture |
| + scrollbar_controller_->DidCaptureScrollbarBegin(); |
| + time += base::TimeDelta::FromSeconds(1); |
| + scrollbar_controller_->Animate(time); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| + |
| + // test for 10 seconds, stay thick and dark |
| + for (int i = 0; i < 10; ++i) { |
| + // move away from bar. |
| + scrollbar_controller_->DidMouseMoveNear(26 + i); |
| + time += base::TimeDelta::FromSeconds(1); |
| + scrollbar_controller_->Animate(time); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| + } |
| + |
| + // move to the bar. |
| + scrollbar_controller_->DidMouseMoveNear(0); |
| + |
| + // release |
| + scrollbar_controller_->DidCaptureScrollbarEnd(); |
| + |
| + // stay thick and dark |
| + // test for 10 seconds, stay thick and dark |
| + for (int i = 0; i < 10; ++i) { |
| + time += base::TimeDelta::FromSeconds(1); |
| + scrollbar_controller_->Animate(time); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| + } |
| +} |
| + |
| } // namespace |
| } // namespace cc |