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 243602ba6adc177efe609a1c827e3358b5b7b54e..83cd2dc929af7d85ecdc109d97adaee76a83d0d7 100644 |
| --- a/cc/input/scrollbar_animation_controller_thinning_unittest.cc |
| +++ b/cc/input/scrollbar_animation_controller_thinning_unittest.cc |
| @@ -200,8 +200,8 @@ TEST_F(ScrollbarAnimationControllerThinningTest, BasicAppearAndFadeOut) { |
| } |
| // Scroll content. Move the mouse near the scrollbar and confirm it becomes |
| -// thick. Ensure it fades out after that. |
| -TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearAndFadeOut) { |
| +// thick. Ensure it remains visible as long as the mouse is near the scrollbar. |
| +TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearAndDontFadeOut) { |
| base::TimeTicks time; |
| time += base::TimeDelta::FromSeconds(1); |
| @@ -212,6 +212,7 @@ TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearAndFadeOut) { |
| // An animation should have been enqueued. |
| EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| EXPECT_FALSE(client_.start_fade().is_null()); |
| + EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| // Now move the mouse near the scrollbar. This should cancel the currently |
| // queued fading animation and start animating thickness. |
| @@ -228,15 +229,15 @@ TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearAndFadeOut) { |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| - // Once the thickening animation is complete, it should enqueue the delayed |
| - // fade animation. |
| + // Mouse is still near the Scrollbar. Once the thickness animation is |
| + // complete, the queued delayed fade animation should be still cancelled. |
| EXPECT_FALSE(client_.start_fade().is_null()); |
| - EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| + EXPECT_TRUE(client_.start_fade().IsCancelled()); |
|
bokan
2016/12/06 17:22:28
Merge all occurances of this !is_null and IsCancel
sahel
2016/12/07 22:33:06
right, done.
|
| } |
| // Scroll content. Move the mouse over the scrollbar and confirm it becomes |
| -// thick. Ensure it fades out after that. |
| -TEST_F(ScrollbarAnimationControllerThinningTest, MoveOverAndFadeOut) { |
| +// thick. Ensure it remains visible as long as the mouse is over the scrollbar. |
| +TEST_F(ScrollbarAnimationControllerThinningTest, MoveOverAndDontFadeOut) { |
| base::TimeTicks time; |
| time += base::TimeDelta::FromSeconds(1); |
| @@ -247,6 +248,7 @@ TEST_F(ScrollbarAnimationControllerThinningTest, MoveOverAndFadeOut) { |
| // An animation should have been enqueued. |
| EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| EXPECT_FALSE(client_.start_fade().is_null()); |
| + EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| // Now move the mouse over the scrollbar. This should cancel the currently |
| // queued fading animation and start animating thickness. |
| @@ -263,10 +265,10 @@ TEST_F(ScrollbarAnimationControllerThinningTest, MoveOverAndFadeOut) { |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| - // Once the thickening animation is complete, it should enqueue the delayed |
| - // fade animation. |
| + // Mouse is still over the Scrollbar. Once the thickness animation is |
| + // complete, the queued delayed fade animation should be still cancelled. |
| EXPECT_FALSE(client_.start_fade().is_null()); |
| - EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| + EXPECT_TRUE(client_.start_fade().IsCancelled()); |
| } |
| // Make sure a scrollbar captured before the thickening animation doesn't try |
| @@ -309,6 +311,7 @@ TEST_F(ScrollbarAnimationControllerThinningTest, DontFadeWhileCaptured) { |
| // An animation should have been enqueued. |
| EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| EXPECT_FALSE(client_.start_fade().is_null()); |
| + EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| // Now move the mouse over the scrollbar and animate it until it's thick. |
| scrollbar_controller_->DidMouseMoveNear(0); |
| @@ -318,18 +321,20 @@ TEST_F(ScrollbarAnimationControllerThinningTest, DontFadeWhileCaptured) { |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| - // Since the scrollbar became thick, it should have queued up a fade. |
| + // Since the mouse is over the scrollbar, it should cancel the queued fade. |
| EXPECT_FALSE(client_.start_fade().is_null()); |
| - EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| + EXPECT_TRUE(client_.start_fade().IsCancelled()); |
| - // Make sure capturing the scrollbar stops the fade. |
| + // Make sure the queued fade animation is still cancelled after capturing |
| + // the scrollbar. |
| scrollbar_controller_->DidMouseDown(); |
| EXPECT_FALSE(client_.start_fade().is_null()); |
| EXPECT_TRUE(client_.start_fade().IsCancelled()); |
| } |
| -// Make sure releasing a captured scrollbar causes it to fade out. |
| -TEST_F(ScrollbarAnimationControllerThinningTest, FadeAfterReleased) { |
| +// Make sure releasing a captured scrollbar when the mouse isn't near it, causes |
| +// the scrollbar to fade out. |
| +TEST_F(ScrollbarAnimationControllerThinningTest, FadeAfterReleasedFar) { |
| base::TimeTicks time; |
| time += base::TimeDelta::FromSeconds(1); |
| @@ -340,6 +345,7 @@ TEST_F(ScrollbarAnimationControllerThinningTest, FadeAfterReleased) { |
| // An animation should have been enqueued. |
| EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| EXPECT_FALSE(client_.start_fade().is_null()); |
| + EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| // Now move the mouse over the scrollbar and capture it. |
| scrollbar_controller_->DidMouseMoveNear(0); |
| @@ -347,18 +353,32 @@ TEST_F(ScrollbarAnimationControllerThinningTest, FadeAfterReleased) { |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| - // Since the scrollbar became thick, it should have queued up a fade. |
| + // Since the mouse is still near the scrollbar, the queued fade should be |
| + // cancelled. |
| EXPECT_FALSE(client_.start_fade().is_null()); |
| EXPECT_TRUE(client_.start_fade().IsCancelled()); |
| + // Now move the mouse away from the scrollbar and release it. |
| + scrollbar_controller_->DidMouseMoveNear(26); |
|
bokan
2016/12/06 17:22:28
Use kDefaultMouseMoveDistanceToTriggerAnimation +
sahel
2016/12/07 22:33:06
Done.
|
| scrollbar_controller_->DidMouseUp(); |
| + |
| + scrollbar_controller_->Animate(time); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| + time += kThinningDuration; |
| + scrollbar_controller_->Animate(time); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| + scrollbar_layer_->thumb_thickness_scale_factor()); |
| + |
| + // The thickness animation is complete, a fade out must be queued. |
| EXPECT_FALSE(client_.start_fade().is_null()); |
| EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| } |
| -// Make sure moving near a scrollbar while it's fading out causes it to reset |
| -// the opacity and thicken. |
| -TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearScrollbarWhileFading) { |
| +// Make sure releasing a captured scrollbar when the mouse is near/over it, |
| +// doesn't cause the scrollbar to fade out. |
| +TEST_F(ScrollbarAnimationControllerThinningTest, DontFadeAfterReleasedNear) { |
| base::TimeTicks time; |
| time += base::TimeDelta::FromSeconds(1); |
| @@ -366,36 +386,32 @@ TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearScrollbarWhileFading) { |
| scrollbar_controller_->DidScrollUpdate(false); |
| scrollbar_controller_->DidScrollEnd(); |
| - // An animation should have been enqueued. Start it. |
| + // An animation should have been enqueued. |
| EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| EXPECT_FALSE(client_.start_fade().is_null()); |
| - client_.start_fade().Run(); |
| + EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| - scrollbar_controller_->Animate(time); |
| + // Now move the mouse over the scrollbar and capture it. |
| + scrollbar_controller_->DidMouseMoveNear(0); |
| + scrollbar_controller_->DidMouseDown(); |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| - // Proceed half way through the fade out animation. |
| - time += kFadeDuration / 2; |
| - scrollbar_controller_->Animate(time); |
| - EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); |
| - |
| - // Now move the mouse near the scrollbar. It should reset opacity to 1 |
| - // instantly and start animating to thick. |
| - scrollbar_controller_->DidMouseMoveNear(1); |
| - EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| - EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| - scrollbar_layer_->thumb_thickness_scale_factor()); |
| + // Since the mouse is over the scrollbar, the queued fade must be cancelled. |
| + EXPECT_FALSE(client_.start_fade().is_null()); |
| + EXPECT_TRUE(client_.start_fade().IsCancelled()); |
| - scrollbar_controller_->Animate(time); |
| - time += kThinningDuration; |
| - scrollbar_controller_->Animate(time); |
| + // Mouse is still near the scrollbar, releasing it shouldn't do anything. |
| + scrollbar_controller_->DidMouseUp(); |
| + EXPECT_FALSE(client_.start_fade().is_null()); |
| + EXPECT_TRUE(client_.start_fade().IsCancelled()); |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| } |
| -// Make sure capturing a scrollbar while it's fading out causes it to reset the |
| -// opacity and thicken instantly. |
| -TEST_F(ScrollbarAnimationControllerThinningTest, CaptureScrollbarWhileFading) { |
| +// Make sure moving near a scrollbar while it's fading out causes it to reset |
| +// the opacity and thicken. |
| +TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearScrollbarWhileFading) { |
| base::TimeTicks time; |
| time += base::TimeDelta::FromSeconds(1); |
| @@ -403,14 +419,6 @@ TEST_F(ScrollbarAnimationControllerThinningTest, CaptureScrollbarWhileFading) { |
| scrollbar_controller_->DidScrollUpdate(false); |
| scrollbar_controller_->DidScrollEnd(); |
| - // Move mouse over the scrollbar. |
| - scrollbar_controller_->DidMouseMoveNear(0); |
| - scrollbar_controller_->Animate(time); |
| - time += kThinningDuration; |
| - scrollbar_controller_->Animate(time); |
| - EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| - EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| - |
| // A fade animation should have been enqueued. Start it. |
| EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| EXPECT_FALSE(client_.start_fade().is_null()); |
| @@ -424,13 +432,21 @@ TEST_F(ScrollbarAnimationControllerThinningTest, CaptureScrollbarWhileFading) { |
| scrollbar_controller_->Animate(time); |
| EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); |
| - // Now capture the scrollbar. It should reset opacity to 1 instantly. |
| - scrollbar_controller_->DidMouseDown(); |
| + // Now move the mouse near the scrollbar. It should reset opacity to 1 |
| + // instantly and start animating to thick. |
| + scrollbar_controller_->DidMouseMoveNear(1); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| + scrollbar_layer_->thumb_thickness_scale_factor()); |
| + |
| + scrollbar_controller_->Animate(time); |
| + time += kThinningDuration; |
| + scrollbar_controller_->Animate(time); |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| } |
| -// Make sure we can't capture scrollbar that's completely faded out |
| +// Make sure we can't capture scrollbar that's completely faded out. |
| TEST_F(ScrollbarAnimationControllerThinningTest, TestCantCaptureWhenFaded) { |
| base::TimeTicks time; |
| time += base::TimeDelta::FromSeconds(1); |
| @@ -439,17 +455,9 @@ TEST_F(ScrollbarAnimationControllerThinningTest, TestCantCaptureWhenFaded) { |
| scrollbar_controller_->DidScrollUpdate(false); |
| scrollbar_controller_->DidScrollEnd(); |
| - // Move mouse over the scrollbar. |
| - scrollbar_controller_->DidMouseMoveNear(0); |
| - scrollbar_controller_->Animate(time); |
| - time += kThinningDuration; |
| - scrollbar_controller_->Animate(time); |
| - EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| - EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| - |
| - // A fade animation should have been enqueued. Start it. |
| EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| EXPECT_FALSE(client_.start_fade().is_null()); |
| + EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| client_.start_fade().Run(); |
| scrollbar_controller_->Animate(time); |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| @@ -458,7 +466,16 @@ TEST_F(ScrollbarAnimationControllerThinningTest, TestCantCaptureWhenFaded) { |
| time += kFadeDuration; |
| scrollbar_controller_->Animate(time); |
| EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| - EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| + |
| + // Move mouse over the scrollbar. It shouldn't thicken the scrollbar since |
| + // it's completely faded out. |
| + scrollbar_controller_->DidMouseMoveNear(0); |
| + scrollbar_controller_->Animate(time); |
| + time += kThinningDuration; |
| + scrollbar_controller_->Animate(time); |
| + EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| + scrollbar_layer_->thumb_thickness_scale_factor()); |
| client_.start_fade().Reset(); |
| @@ -466,13 +483,15 @@ TEST_F(ScrollbarAnimationControllerThinningTest, TestCantCaptureWhenFaded) { |
| // completely faded out. |
| scrollbar_controller_->DidMouseDown(); |
| EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| - EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| + EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| + scrollbar_layer_->thumb_thickness_scale_factor()); |
| EXPECT_TRUE(client_.start_fade().is_null()); |
| // Similarly, releasing the scrollbar should have no effect. |
| scrollbar_controller_->DidMouseUp(); |
| EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| - EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| + EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| + scrollbar_layer_->thumb_thickness_scale_factor()); |
| EXPECT_TRUE(client_.start_fade().is_null()); |
| } |
| @@ -498,20 +517,21 @@ TEST_F(ScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) { |
| // Now that we've received a scroll, we should be thick without an animation. |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| - // An animation for the fade should have been enqueued. |
| + // An animation for the fade should have been enqueued and cancelled, since |
|
bokan
2016/12/06 17:22:28
We shouldn't test that's its enqueued anymore. Onl
sahel
2016/12/07 22:33:06
Done.
|
| + // mouse is still near the scrollbar. |
| scrollbar_controller_->DidScrollEnd(); |
| EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| EXPECT_FALSE(client_.start_fade().is_null()); |
| + EXPECT_TRUE(client_.start_fade().IsCancelled()); |
| - client_.start_fade().Run(); |
| scrollbar_controller_->Animate(time); |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| - // Scrollbar should still be thick, even though the scrollbar fades out. |
| + // Scrollbar should still be thick and visible. |
| time += kFadeDuration; |
| scrollbar_controller_->Animate(time); |
| - EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| + EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| } |