| 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/single_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" |
| 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 // These constants are hard-coded and should match the values in | 24 // These constants are hard-coded and should match the values in |
| 25 // scrollbar_animation_controller_thinning.cc. | 25 // single_scrollbar_animation_controller_thinning.cc. |
| 26 const float kIdleThicknessScale = 0.4f; | 26 const float kIdleThicknessScale = 0.4f; |
| 27 const float kDefaultMouseMoveDistanceToTriggerAnimation = 25.f; | 27 const float kDefaultMouseMoveDistanceToTriggerAnimation = 25.f; |
| 28 | 28 |
| 29 class MockScrollbarAnimationControllerClient | 29 class MockSingleScrollbarAnimationControllerClient |
| 30 : public ScrollbarAnimationControllerClient { | 30 : public ScrollbarAnimationControllerClient { |
| 31 public: | 31 public: |
| 32 explicit MockScrollbarAnimationControllerClient(LayerTreeHostImpl* host_impl) | 32 explicit MockSingleScrollbarAnimationControllerClient( |
| 33 LayerTreeHostImpl* host_impl) |
| 33 : host_impl_(host_impl) {} | 34 : host_impl_(host_impl) {} |
| 34 virtual ~MockScrollbarAnimationControllerClient() {} | 35 virtual ~MockSingleScrollbarAnimationControllerClient() {} |
| 35 | 36 |
| 36 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade, | 37 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade, |
| 37 base::TimeDelta delay) override { | 38 base::TimeDelta delay) override { |
| 38 start_fade_ = start_fade; | 39 start_fade_ = start_fade; |
| 39 delay_ = delay; | 40 delay_ = delay; |
| 40 } | 41 } |
| 41 void SetNeedsRedrawForScrollbarAnimation() override {} | 42 void SetNeedsRedrawForScrollbarAnimation() override {} |
| 42 void SetNeedsAnimateForScrollbarAnimation() override {} | 43 void SetNeedsAnimateForScrollbarAnimation() override {} |
| 43 ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override { | 44 ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override { |
| 44 return host_impl_->ScrollbarsFor(scroll_layer_id); | 45 return host_impl_->ScrollbarsFor(scroll_layer_id); |
| 45 } | 46 } |
| 46 MOCK_METHOD0(DidChangeScrollbarVisibility, void()); | 47 MOCK_METHOD0(DidChangeScrollbarVisibility, void()); |
| 47 | 48 |
| 48 base::Closure& start_fade() { return start_fade_; } | 49 base::Closure& start_fade() { return start_fade_; } |
| 49 base::TimeDelta& delay() { return delay_; } | 50 base::TimeDelta& delay() { return delay_; } |
| 50 | 51 |
| 51 private: | 52 private: |
| 52 base::Closure start_fade_; | 53 base::Closure start_fade_; |
| 53 base::TimeDelta delay_; | 54 base::TimeDelta delay_; |
| 54 LayerTreeHostImpl* host_impl_; | 55 LayerTreeHostImpl* host_impl_; |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 class ScrollbarAnimationControllerThinningTest : public testing::Test { | 58 class SingleScrollbarAnimationControllerThinningTest : public testing::Test { |
| 58 public: | 59 public: |
| 59 ScrollbarAnimationControllerThinningTest() | 60 SingleScrollbarAnimationControllerThinningTest() |
| 60 : host_impl_(&task_runner_provider_, &task_graph_runner_), | 61 : host_impl_(&task_runner_provider_, &task_graph_runner_), |
| 61 client_(&host_impl_) {} | 62 client_(&host_impl_) {} |
| 62 | 63 |
| 63 protected: | 64 protected: |
| 64 const base::TimeDelta kDelayBeforeStarting = base::TimeDelta::FromSeconds(2); | 65 const base::TimeDelta kDelayBeforeStarting = base::TimeDelta::FromSeconds(2); |
| 65 const base::TimeDelta kResizeDelayBeforeStarting = | 66 const base::TimeDelta kResizeDelayBeforeStarting = |
| 66 base::TimeDelta::FromSeconds(5); | 67 base::TimeDelta::FromSeconds(5); |
| 67 const base::TimeDelta kFadeDuration = base::TimeDelta::FromSeconds(3); | 68 const base::TimeDelta kFadeDuration = base::TimeDelta::FromSeconds(3); |
| 68 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2); | 69 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2); |
| 69 | 70 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 91 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); | 92 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); |
| 92 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); | 93 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); |
| 93 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); | 94 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); |
| 94 | 95 |
| 95 scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); | 96 scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); |
| 96 scrollbar_layer_->test_properties()->opacity_can_animate = true; | 97 scrollbar_layer_->test_properties()->opacity_can_animate = true; |
| 97 clip_layer_->SetBounds(gfx::Size(100, 100)); | 98 clip_layer_->SetBounds(gfx::Size(100, 100)); |
| 98 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); | 99 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
| 99 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); | 100 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 100 | 101 |
| 101 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( | 102 scrollbar_controller_ = SingleScrollbarAnimationControllerThinning::Create( |
| 102 scroll_layer_ptr->id(), &client_, kDelayBeforeStarting, | 103 scroll_layer_ptr->id(), HORIZONTAL, &client_, kDelayBeforeStarting, |
| 103 kResizeDelayBeforeStarting, kFadeDuration, kThinningDuration); | 104 kResizeDelayBeforeStarting, kFadeDuration, kThinningDuration); |
| 104 } | 105 } |
| 105 | 106 |
| 106 FakeImplTaskRunnerProvider task_runner_provider_; | 107 FakeImplTaskRunnerProvider task_runner_provider_; |
| 107 TestTaskGraphRunner task_graph_runner_; | 108 TestTaskGraphRunner task_graph_runner_; |
| 108 FakeLayerTreeHostImpl host_impl_; | 109 FakeLayerTreeHostImpl host_impl_; |
| 109 std::unique_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; | 110 std::unique_ptr<SingleScrollbarAnimationControllerThinning> |
| 111 scrollbar_controller_; |
| 110 LayerImpl* clip_layer_; | 112 LayerImpl* clip_layer_; |
| 111 SolidColorScrollbarLayerImpl* scrollbar_layer_; | 113 SolidColorScrollbarLayerImpl* scrollbar_layer_; |
| 112 NiceMock<MockScrollbarAnimationControllerClient> client_; | 114 NiceMock<MockSingleScrollbarAnimationControllerClient> client_; |
| 113 }; | 115 }; |
| 114 | 116 |
| 115 // Check initialization of scrollbar. Should start off invisible and thin. | 117 // Check initialization of scrollbar. Should start off invisible and thin. |
| 116 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) { | 118 TEST_F(SingleScrollbarAnimationControllerThinningTest, Idle) { |
| 117 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 119 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 118 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); | 120 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 121 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 119 } | 122 } |
| 120 | 123 |
| 121 // Check that scrollbar appears again when the layer becomes scrollable. | 124 // Check that scrollbar appears again when the layer becomes scrollable. |
| 122 TEST_F(ScrollbarAnimationControllerThinningTest, AppearOnResize) { | 125 TEST_F(SingleScrollbarAnimationControllerThinningTest, AppearOnResize) { |
| 123 scrollbar_controller_->DidScrollBegin(); | 126 scrollbar_controller_->DidScrollBegin(); |
| 124 scrollbar_controller_->DidScrollUpdate(false); | 127 scrollbar_controller_->DidScrollUpdate(false); |
| 125 scrollbar_controller_->DidScrollEnd(); | 128 scrollbar_controller_->DidScrollEnd(); |
| 126 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 129 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 127 | 130 |
| 128 // Make the Layer non-scrollable, scrollbar disappears. | 131 // Make the Layer non-scrollable, scrollbar disappears. |
| 129 clip_layer_->SetBounds(gfx::Size(200, 200)); | 132 clip_layer_->SetBounds(gfx::Size(200, 200)); |
| 130 scrollbar_controller_->DidScrollUpdate(false); | 133 scrollbar_controller_->DidScrollUpdate(false); |
| 131 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 134 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 132 | 135 |
| 133 // Make the layer scrollable, scrollbar appears again. | 136 // Make the layer scrollable, scrollbar appears again. |
| 134 clip_layer_->SetBounds(gfx::Size(100, 100)); | 137 clip_layer_->SetBounds(gfx::Size(100, 100)); |
| 135 scrollbar_controller_->DidScrollUpdate(false); | 138 scrollbar_controller_->DidScrollUpdate(false); |
| 136 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 139 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 137 } | 140 } |
| 138 | 141 |
| 139 // Check that scrollbar disappears when the layer becomes non-scrollable. | 142 // Check that scrollbar disappears when the layer becomes non-scrollable. |
| 140 TEST_F(ScrollbarAnimationControllerThinningTest, HideOnResize) { | 143 TEST_F(SingleScrollbarAnimationControllerThinningTest, HideOnResize) { |
| 141 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); | 144 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); |
| 142 ASSERT_TRUE(scroll_layer); | 145 ASSERT_TRUE(scroll_layer); |
| 143 EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds()); | 146 EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds()); |
| 144 | 147 |
| 145 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); | 148 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); |
| 146 | 149 |
| 147 // Shrink along X axis, horizontal scrollbar should appear. | 150 // Shrink along X axis, horizontal scrollbar should appear. |
| 148 clip_layer_->SetBounds(gfx::Size(100, 200)); | 151 clip_layer_->SetBounds(gfx::Size(100, 200)); |
| 149 EXPECT_EQ(gfx::Size(100, 200), clip_layer_->bounds()); | 152 EXPECT_EQ(gfx::Size(100, 200), clip_layer_->bounds()); |
| 150 | 153 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 162 | 165 |
| 163 scrollbar_controller_->DidScrollBegin(); | 166 scrollbar_controller_->DidScrollBegin(); |
| 164 | 167 |
| 165 scrollbar_controller_->DidScrollUpdate(false); | 168 scrollbar_controller_->DidScrollUpdate(false); |
| 166 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 169 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 167 | 170 |
| 168 scrollbar_controller_->DidScrollEnd(); | 171 scrollbar_controller_->DidScrollEnd(); |
| 169 } | 172 } |
| 170 | 173 |
| 171 // Scroll content. Confirm the scrollbar appears and fades out. | 174 // Scroll content. Confirm the scrollbar appears and fades out. |
| 172 TEST_F(ScrollbarAnimationControllerThinningTest, BasicAppearAndFadeOut) { | 175 TEST_F(SingleScrollbarAnimationControllerThinningTest, BasicAppearAndFadeOut) { |
| 173 base::TimeTicks time; | 176 base::TimeTicks time; |
| 174 time += base::TimeDelta::FromSeconds(1); | 177 time += base::TimeDelta::FromSeconds(1); |
| 175 | 178 |
| 176 // Scrollbar should be invisible by default. | 179 // Scrollbar should be invisible by default. |
| 177 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 180 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 178 | 181 |
| 179 // Scrollbar should appear only on scroll update. | 182 // Scrollbar should appear only on scroll update. |
| 180 scrollbar_controller_->DidScrollBegin(); | 183 scrollbar_controller_->DidScrollBegin(); |
| 181 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 184 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 182 | 185 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 194 // Scrollbar should fade out over kFadeDuration. | 197 // Scrollbar should fade out over kFadeDuration. |
| 195 scrollbar_controller_->Animate(time); | 198 scrollbar_controller_->Animate(time); |
| 196 time += kFadeDuration; | 199 time += kFadeDuration; |
| 197 scrollbar_controller_->Animate(time); | 200 scrollbar_controller_->Animate(time); |
| 198 | 201 |
| 199 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 202 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 200 } | 203 } |
| 201 | 204 |
| 202 // Scroll content. Move the mouse near the scrollbar and confirm it becomes | 205 // Scroll content. Move the mouse near the scrollbar and confirm it becomes |
| 203 // thick. Ensure it fades out after that. | 206 // thick. Ensure it fades out after that. |
| 204 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearAndFadeOut) { | 207 TEST_F(SingleScrollbarAnimationControllerThinningTest, MoveNearAndFadeOut) { |
| 205 base::TimeTicks time; | 208 base::TimeTicks time; |
| 206 time += base::TimeDelta::FromSeconds(1); | 209 time += base::TimeDelta::FromSeconds(1); |
| 207 | 210 |
| 208 scrollbar_controller_->DidScrollBegin(); | 211 scrollbar_controller_->DidScrollBegin(); |
| 209 scrollbar_controller_->DidScrollUpdate(false); | 212 scrollbar_controller_->DidScrollUpdate(false); |
| 210 scrollbar_controller_->DidScrollEnd(); | 213 scrollbar_controller_->DidScrollEnd(); |
| 211 | 214 |
| 212 // An animation should have been enqueued. | 215 // An animation should have been enqueued. |
| 213 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 216 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 214 EXPECT_FALSE(client_.start_fade().is_null()); | 217 EXPECT_FALSE(client_.start_fade().is_null()); |
| 215 | 218 |
| 216 // Now move the mouse near the scrollbar. This should cancel the currently | 219 // Now move the mouse near the scrollbar. This should cancel the currently |
| 217 // queued fading animation and start animating thickness. | 220 // queued fading animation and start animating thickness. |
| 218 scrollbar_controller_->DidMouseMoveNear(1); | 221 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1); |
| 219 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 222 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 220 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 223 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 221 scrollbar_layer_->thumb_thickness_scale_factor()); | 224 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 222 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 225 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
| 223 | 226 |
| 224 // Scrollbar should become thick. | 227 // Scrollbar should become thick. |
| 225 scrollbar_controller_->Animate(time); | 228 scrollbar_controller_->Animate(time); |
| 226 time += kThinningDuration; | 229 time += kThinningDuration; |
| 227 scrollbar_controller_->Animate(time); | 230 scrollbar_controller_->Animate(time); |
| 228 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 231 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 229 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 232 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 230 | 233 |
| 231 // Once the thickening animation is complete, it should enqueue the delayed | 234 // Once the thickening animation is complete, it should enqueue the delayed |
| 232 // fade animation. | 235 // fade animation. |
| 233 EXPECT_FALSE(client_.start_fade().is_null()); | 236 EXPECT_FALSE(client_.start_fade().is_null()); |
| 234 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 237 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 235 } | 238 } |
| 236 | 239 |
| 237 // Scroll content. Move the mouse over the scrollbar and confirm it becomes | 240 // Scroll content. Move the mouse over the scrollbar and confirm it becomes |
| 238 // thick. Ensure it fades out after that. | 241 // thick. Ensure it fades out after that. |
| 239 TEST_F(ScrollbarAnimationControllerThinningTest, MoveOverAndFadeOut) { | 242 TEST_F(SingleScrollbarAnimationControllerThinningTest, MoveOverAndFadeOut) { |
| 240 base::TimeTicks time; | 243 base::TimeTicks time; |
| 241 time += base::TimeDelta::FromSeconds(1); | 244 time += base::TimeDelta::FromSeconds(1); |
| 242 | 245 |
| 243 scrollbar_controller_->DidScrollBegin(); | 246 scrollbar_controller_->DidScrollBegin(); |
| 244 scrollbar_controller_->DidScrollUpdate(false); | 247 scrollbar_controller_->DidScrollUpdate(false); |
| 245 scrollbar_controller_->DidScrollEnd(); | 248 scrollbar_controller_->DidScrollEnd(); |
| 246 | 249 |
| 247 // An animation should have been enqueued. | 250 // An animation should have been enqueued. |
| 248 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 251 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 249 EXPECT_FALSE(client_.start_fade().is_null()); | 252 EXPECT_FALSE(client_.start_fade().is_null()); |
| 250 | 253 |
| 251 // Now move the mouse over the scrollbar. This should cancel the currently | 254 // Now move the mouse over the scrollbar. This should cancel the currently |
| 252 // queued fading animation and start animating thickness. | 255 // queued fading animation and start animating thickness. |
| 253 scrollbar_controller_->DidMouseMoveNear(0); | 256 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 254 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 257 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 255 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 258 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 256 scrollbar_layer_->thumb_thickness_scale_factor()); | 259 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 257 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 260 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
| 258 | 261 |
| 259 // Scrollbar should become thick. | 262 // Scrollbar should become thick. |
| 260 scrollbar_controller_->Animate(time); | 263 scrollbar_controller_->Animate(time); |
| 261 time += kThinningDuration; | 264 time += kThinningDuration; |
| 262 scrollbar_controller_->Animate(time); | 265 scrollbar_controller_->Animate(time); |
| 263 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 266 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 264 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 267 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 265 | 268 |
| 266 // Once the thickening animation is complete, it should enqueue the delayed | 269 // Once the thickening animation is complete, it should enqueue the delayed |
| 267 // fade animation. | 270 // fade animation. |
| 268 EXPECT_FALSE(client_.start_fade().is_null()); | 271 EXPECT_FALSE(client_.start_fade().is_null()); |
| 269 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 272 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 270 } | 273 } |
| 271 | 274 |
| 272 // Make sure a scrollbar captured before the thickening animation doesn't try | 275 // Make sure a scrollbar captured before the thickening animation doesn't try |
| 273 // to fade out. | 276 // to fade out. |
| 274 TEST_F(ScrollbarAnimationControllerThinningTest, | 277 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 275 DontFadeWhileCapturedBeforeThick) { | 278 DontFadeWhileCapturedBeforeThick) { |
| 276 base::TimeTicks time; | 279 base::TimeTicks time; |
| 277 time += base::TimeDelta::FromSeconds(1); | 280 time += base::TimeDelta::FromSeconds(1); |
| 278 | 281 |
| 279 scrollbar_controller_->DidScrollBegin(); | 282 scrollbar_controller_->DidScrollBegin(); |
| 280 scrollbar_controller_->DidScrollUpdate(false); | 283 scrollbar_controller_->DidScrollUpdate(false); |
| 281 scrollbar_controller_->DidScrollEnd(); | 284 scrollbar_controller_->DidScrollEnd(); |
| 282 | 285 |
| 283 // An animation should have been enqueued. | 286 // An animation should have been enqueued. |
| 284 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 287 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 285 EXPECT_FALSE(client_.start_fade().is_null()); | 288 EXPECT_FALSE(client_.start_fade().is_null()); |
| 286 | 289 |
| 287 // Now move the mouse over the scrollbar and capture it. It should become | 290 // Now move the mouse over the scrollbar and capture it. It should become |
| 288 // thick without need for an animation. | 291 // thick without need for an animation. |
| 289 scrollbar_controller_->DidMouseMoveNear(0); | 292 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 290 scrollbar_controller_->DidMouseDown(); | 293 scrollbar_controller_->DidMouseDown(); |
| 291 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 294 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 292 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 295 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 293 | 296 |
| 294 // The fade animation should have been cancelled. | 297 // The fade animation should have been cancelled. |
| 295 EXPECT_FALSE(client_.start_fade().is_null()); | 298 EXPECT_FALSE(client_.start_fade().is_null()); |
| 296 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 299 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
| 297 } | 300 } |
| 298 | 301 |
| 299 // Make sure a scrollbar captured after a thickening animation doesn't try to | 302 // Make sure a scrollbar captured after a thickening animation doesn't try to |
| 300 // fade out. | 303 // fade out. |
| 301 TEST_F(ScrollbarAnimationControllerThinningTest, DontFadeWhileCaptured) { | 304 TEST_F(SingleScrollbarAnimationControllerThinningTest, DontFadeWhileCaptured) { |
| 302 base::TimeTicks time; | 305 base::TimeTicks time; |
| 303 time += base::TimeDelta::FromSeconds(1); | 306 time += base::TimeDelta::FromSeconds(1); |
| 304 | 307 |
| 305 scrollbar_controller_->DidScrollBegin(); | 308 scrollbar_controller_->DidScrollBegin(); |
| 306 scrollbar_controller_->DidScrollUpdate(false); | 309 scrollbar_controller_->DidScrollUpdate(false); |
| 307 scrollbar_controller_->DidScrollEnd(); | 310 scrollbar_controller_->DidScrollEnd(); |
| 308 | 311 |
| 309 // An animation should have been enqueued. | 312 // An animation should have been enqueued. |
| 310 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 313 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 311 EXPECT_FALSE(client_.start_fade().is_null()); | 314 EXPECT_FALSE(client_.start_fade().is_null()); |
| 312 | 315 |
| 313 // Now move the mouse over the scrollbar and animate it until it's thick. | 316 // Now move the mouse over the scrollbar and animate it until it's thick. |
| 314 scrollbar_controller_->DidMouseMoveNear(0); | 317 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 315 scrollbar_controller_->Animate(time); | 318 scrollbar_controller_->Animate(time); |
| 316 time += kThinningDuration; | 319 time += kThinningDuration; |
| 317 scrollbar_controller_->Animate(time); | 320 scrollbar_controller_->Animate(time); |
| 318 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 321 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 319 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 322 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 320 | 323 |
| 321 // Since the scrollbar became thick, it should have queued up a fade. | 324 // Since the scrollbar became thick, it should have queued up a fade. |
| 322 EXPECT_FALSE(client_.start_fade().is_null()); | 325 EXPECT_FALSE(client_.start_fade().is_null()); |
| 323 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 326 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 324 | 327 |
| 325 // Make sure capturing the scrollbar stops the fade. | 328 // Make sure capturing the scrollbar stops the fade. |
| 326 scrollbar_controller_->DidMouseDown(); | 329 scrollbar_controller_->DidMouseDown(); |
| 327 EXPECT_FALSE(client_.start_fade().is_null()); | 330 EXPECT_FALSE(client_.start_fade().is_null()); |
| 328 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 331 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
| 329 } | 332 } |
| 330 | 333 |
| 331 // Make sure releasing a captured scrollbar causes it to fade out. | 334 // Make sure releasing a captured scrollbar causes it to fade out. |
| 332 TEST_F(ScrollbarAnimationControllerThinningTest, FadeAfterReleased) { | 335 TEST_F(SingleScrollbarAnimationControllerThinningTest, FadeAfterReleased) { |
| 333 base::TimeTicks time; | 336 base::TimeTicks time; |
| 334 time += base::TimeDelta::FromSeconds(1); | 337 time += base::TimeDelta::FromSeconds(1); |
| 335 | 338 |
| 336 scrollbar_controller_->DidScrollBegin(); | 339 scrollbar_controller_->DidScrollBegin(); |
| 337 scrollbar_controller_->DidScrollUpdate(false); | 340 scrollbar_controller_->DidScrollUpdate(false); |
| 338 scrollbar_controller_->DidScrollEnd(); | 341 scrollbar_controller_->DidScrollEnd(); |
| 339 | 342 |
| 340 // An animation should have been enqueued. | 343 // An animation should have been enqueued. |
| 341 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 344 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 342 EXPECT_FALSE(client_.start_fade().is_null()); | 345 EXPECT_FALSE(client_.start_fade().is_null()); |
| 343 | 346 |
| 344 // Now move the mouse over the scrollbar and capture it. | 347 // Now move the mouse over the scrollbar and capture it. |
| 345 scrollbar_controller_->DidMouseMoveNear(0); | 348 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 346 scrollbar_controller_->DidMouseDown(); | 349 scrollbar_controller_->DidMouseDown(); |
| 347 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 350 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 348 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 351 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 349 | 352 |
| 350 // Since the scrollbar became thick, it should have queued up a fade. | 353 // Since the scrollbar became thick, it should have queued up a fade. |
| 351 EXPECT_FALSE(client_.start_fade().is_null()); | 354 EXPECT_FALSE(client_.start_fade().is_null()); |
| 352 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 355 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
| 353 | 356 |
| 354 scrollbar_controller_->DidMouseUp(); | 357 scrollbar_controller_->DidMouseUp(); |
| 355 EXPECT_FALSE(client_.start_fade().is_null()); | 358 EXPECT_FALSE(client_.start_fade().is_null()); |
| 356 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 359 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 357 } | 360 } |
| 358 | 361 |
| 359 // Make sure moving near a scrollbar while it's fading out causes it to reset | 362 // Make sure moving near a scrollbar while it's fading out causes it to reset |
| 360 // the opacity and thicken. | 363 // the opacity and thicken. |
| 361 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearScrollbarWhileFading) { | 364 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 365 MoveNearScrollbarWhileFading) { |
| 362 base::TimeTicks time; | 366 base::TimeTicks time; |
| 363 time += base::TimeDelta::FromSeconds(1); | 367 time += base::TimeDelta::FromSeconds(1); |
| 364 | 368 |
| 365 scrollbar_controller_->DidScrollBegin(); | 369 scrollbar_controller_->DidScrollBegin(); |
| 366 scrollbar_controller_->DidScrollUpdate(false); | 370 scrollbar_controller_->DidScrollUpdate(false); |
| 367 scrollbar_controller_->DidScrollEnd(); | 371 scrollbar_controller_->DidScrollEnd(); |
| 368 | 372 |
| 369 // An animation should have been enqueued. Start it. | 373 // An animation should have been enqueued. Start it. |
| 370 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 374 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 371 EXPECT_FALSE(client_.start_fade().is_null()); | 375 EXPECT_FALSE(client_.start_fade().is_null()); |
| 372 client_.start_fade().Run(); | 376 client_.start_fade().Run(); |
| 373 | 377 |
| 374 scrollbar_controller_->Animate(time); | 378 scrollbar_controller_->Animate(time); |
| 375 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 379 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 376 | 380 |
| 377 // Proceed half way through the fade out animation. | 381 // Proceed half way through the fade out animation. |
| 378 time += kFadeDuration / 2; | 382 time += kFadeDuration / 2; |
| 379 scrollbar_controller_->Animate(time); | 383 scrollbar_controller_->Animate(time); |
| 380 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); | 384 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); |
| 381 | 385 |
| 382 // Now move the mouse near the scrollbar. It should reset opacity to 1 | 386 // Now move the mouse near the scrollbar. It should reset opacity to 1 |
| 383 // instantly and start animating to thick. | 387 // instantly and start animating to thick. |
| 384 scrollbar_controller_->DidMouseMoveNear(1); | 388 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1); |
| 385 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 389 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 386 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 390 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 387 scrollbar_layer_->thumb_thickness_scale_factor()); | 391 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 388 | 392 |
| 389 scrollbar_controller_->Animate(time); | 393 scrollbar_controller_->Animate(time); |
| 390 time += kThinningDuration; | 394 time += kThinningDuration; |
| 391 scrollbar_controller_->Animate(time); | 395 scrollbar_controller_->Animate(time); |
| 392 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 396 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 393 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 397 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 394 } | 398 } |
| 395 | 399 |
| 396 // Make sure capturing a scrollbar while it's fading out causes it to reset the | 400 // Make sure capturing a scrollbar while it's fading out causes it to reset the |
| 397 // opacity and thicken instantly. | 401 // opacity and thicken instantly. |
| 398 TEST_F(ScrollbarAnimationControllerThinningTest, CaptureScrollbarWhileFading) { | 402 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 403 CaptureScrollbarWhileFading) { |
| 399 base::TimeTicks time; | 404 base::TimeTicks time; |
| 400 time += base::TimeDelta::FromSeconds(1); | 405 time += base::TimeDelta::FromSeconds(1); |
| 401 | 406 |
| 402 scrollbar_controller_->DidScrollBegin(); | 407 scrollbar_controller_->DidScrollBegin(); |
| 403 scrollbar_controller_->DidScrollUpdate(false); | 408 scrollbar_controller_->DidScrollUpdate(false); |
| 404 scrollbar_controller_->DidScrollEnd(); | 409 scrollbar_controller_->DidScrollEnd(); |
| 405 | 410 |
| 406 // Move mouse over the scrollbar. | 411 // Move mouse over the scrollbar. |
| 407 scrollbar_controller_->DidMouseMoveNear(0); | 412 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 408 scrollbar_controller_->Animate(time); | 413 scrollbar_controller_->Animate(time); |
| 409 time += kThinningDuration; | 414 time += kThinningDuration; |
| 410 scrollbar_controller_->Animate(time); | 415 scrollbar_controller_->Animate(time); |
| 411 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 416 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 412 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 417 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 413 | 418 |
| 414 // A fade animation should have been enqueued. Start it. | 419 // A fade animation should have been enqueued. Start it. |
| 415 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 420 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 416 EXPECT_FALSE(client_.start_fade().is_null()); | 421 EXPECT_FALSE(client_.start_fade().is_null()); |
| 417 client_.start_fade().Run(); | 422 client_.start_fade().Run(); |
| 418 | 423 |
| 419 scrollbar_controller_->Animate(time); | 424 scrollbar_controller_->Animate(time); |
| 420 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 425 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 421 | 426 |
| 422 // Proceed half way through the fade out animation. | 427 // Proceed half way through the fade out animation. |
| 423 time += kFadeDuration / 2; | 428 time += kFadeDuration / 2; |
| 424 scrollbar_controller_->Animate(time); | 429 scrollbar_controller_->Animate(time); |
| 425 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); | 430 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); |
| 426 | 431 |
| 427 // Now capture the scrollbar. It should reset opacity to 1 instantly. | 432 // Now capture the scrollbar. It should reset opacity to 1 instantly. |
| 428 scrollbar_controller_->DidMouseDown(); | 433 scrollbar_controller_->DidMouseDown(); |
| 429 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 434 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 430 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 435 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 431 } | 436 } |
| 432 | 437 |
| 433 // Make sure we can't capture scrollbar that's completely faded out | 438 // Make sure we can't capture scrollbar that's completely faded out |
| 434 TEST_F(ScrollbarAnimationControllerThinningTest, TestCantCaptureWhenFaded) { | 439 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 440 TestCantCaptureWhenFaded) { |
| 435 base::TimeTicks time; | 441 base::TimeTicks time; |
| 436 time += base::TimeDelta::FromSeconds(1); | 442 time += base::TimeDelta::FromSeconds(1); |
| 437 | 443 |
| 438 scrollbar_controller_->DidScrollBegin(); | 444 scrollbar_controller_->DidScrollBegin(); |
| 439 scrollbar_controller_->DidScrollUpdate(false); | 445 scrollbar_controller_->DidScrollUpdate(false); |
| 440 scrollbar_controller_->DidScrollEnd(); | 446 scrollbar_controller_->DidScrollEnd(); |
| 441 | 447 |
| 442 // Move mouse over the scrollbar. | 448 // Move mouse over the scrollbar. |
| 443 scrollbar_controller_->DidMouseMoveNear(0); | 449 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 444 scrollbar_controller_->Animate(time); | 450 scrollbar_controller_->Animate(time); |
| 445 time += kThinningDuration; | 451 time += kThinningDuration; |
| 446 scrollbar_controller_->Animate(time); | 452 scrollbar_controller_->Animate(time); |
| 447 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 453 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 448 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 454 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 449 | 455 |
| 450 // A fade animation should have been enqueued. Start it. | 456 // A fade animation should have been enqueued. Start it. |
| 451 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 457 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 452 EXPECT_FALSE(client_.start_fade().is_null()); | 458 EXPECT_FALSE(client_.start_fade().is_null()); |
| 453 client_.start_fade().Run(); | 459 client_.start_fade().Run(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 471 | 477 |
| 472 // Similarly, releasing the scrollbar should have no effect. | 478 // Similarly, releasing the scrollbar should have no effect. |
| 473 scrollbar_controller_->DidMouseUp(); | 479 scrollbar_controller_->DidMouseUp(); |
| 474 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 480 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 475 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 481 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 476 EXPECT_TRUE(client_.start_fade().is_null()); | 482 EXPECT_TRUE(client_.start_fade().is_null()); |
| 477 } | 483 } |
| 478 | 484 |
| 479 // Initiate a scroll when the pointer is already near the scrollbar. It should | 485 // Initiate a scroll when the pointer is already near the scrollbar. It should |
| 480 // appear thick and remain thick. | 486 // appear thick and remain thick. |
| 481 TEST_F(ScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) { | 487 TEST_F(SingleScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) { |
| 482 base::TimeTicks time; | 488 base::TimeTicks time; |
| 483 time += base::TimeDelta::FromSeconds(1); | 489 time += base::TimeDelta::FromSeconds(1); |
| 484 | 490 |
| 485 scrollbar_controller_->DidMouseMoveNear(1); | 491 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1); |
| 486 scrollbar_controller_->Animate(time); | 492 scrollbar_controller_->Animate(time); |
| 487 time += kThinningDuration; | 493 time += kThinningDuration; |
| 488 | 494 |
| 489 // Since the scrollbar isn't visible yet (because we haven't scrolled), we | 495 // Since the scrollbar isn't visible yet (because we haven't scrolled), we |
| 490 // shouldn't have applied the thickening. | 496 // shouldn't have applied the thickening. |
| 491 scrollbar_controller_->Animate(time); | 497 scrollbar_controller_->Animate(time); |
| 492 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 498 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 493 scrollbar_layer_->thumb_thickness_scale_factor()); | 499 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 494 | 500 |
| 495 scrollbar_controller_->DidScrollBegin(); | 501 scrollbar_controller_->DidScrollBegin(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 510 | 516 |
| 511 // Scrollbar should still be thick, even though the scrollbar fades out. | 517 // Scrollbar should still be thick, even though the scrollbar fades out. |
| 512 time += kFadeDuration; | 518 time += kFadeDuration; |
| 513 scrollbar_controller_->Animate(time); | 519 scrollbar_controller_->Animate(time); |
| 514 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 520 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 515 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 521 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 516 } | 522 } |
| 517 | 523 |
| 518 // Move the pointer near the scrollbar. Confirm it gets thick and narrow when | 524 // Move the pointer near the scrollbar. Confirm it gets thick and narrow when |
| 519 // moved away. | 525 // moved away. |
| 520 TEST_F(ScrollbarAnimationControllerThinningTest, MouseNear) { | 526 TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseNear) { |
| 521 base::TimeTicks time; | 527 base::TimeTicks time; |
| 522 time += base::TimeDelta::FromSeconds(1); | 528 time += base::TimeDelta::FromSeconds(1); |
| 523 | 529 |
| 524 // Scroll to make the scrollbars visible. | 530 // Scroll to make the scrollbars visible. |
| 525 scrollbar_controller_->DidScrollBegin(); | 531 scrollbar_controller_->DidScrollBegin(); |
| 526 scrollbar_controller_->DidScrollUpdate(false); | 532 scrollbar_controller_->DidScrollUpdate(false); |
| 527 scrollbar_controller_->DidScrollEnd(); | 533 scrollbar_controller_->DidScrollEnd(); |
| 528 | 534 |
| 529 scrollbar_controller_->DidMouseMoveNear(1); | 535 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1); |
| 530 scrollbar_controller_->Animate(time); | 536 scrollbar_controller_->Animate(time); |
| 531 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 537 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 532 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 538 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 533 scrollbar_layer_->thumb_thickness_scale_factor()); | 539 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 534 | 540 |
| 535 // Should animate to thickened. | 541 // Should animate to thickened. |
| 536 time += kThinningDuration; | 542 time += kThinningDuration; |
| 537 scrollbar_controller_->Animate(time); | 543 scrollbar_controller_->Animate(time); |
| 538 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 544 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 539 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 545 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 540 | 546 |
| 541 // Subsequent moves within the nearness threshold should not change anything. | 547 // Subsequent moves within the nearness threshold should not change anything. |
| 542 scrollbar_controller_->DidMouseMoveNear(2); | 548 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 2); |
| 543 scrollbar_controller_->Animate(time); | 549 scrollbar_controller_->Animate(time); |
| 544 time += base::TimeDelta::FromSeconds(10); | 550 time += base::TimeDelta::FromSeconds(10); |
| 545 scrollbar_controller_->Animate(time); | 551 scrollbar_controller_->Animate(time); |
| 546 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 552 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 547 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 553 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 548 | 554 |
| 549 // Now move away from bar. | 555 // Now move away from bar. |
| 550 scrollbar_controller_->DidMouseMoveNear( | 556 scrollbar_controller_->DidMouseMoveNear( |
| 551 kDefaultMouseMoveDistanceToTriggerAnimation); | 557 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation); |
| 552 scrollbar_controller_->Animate(time); | 558 scrollbar_controller_->Animate(time); |
| 553 time += kThinningDuration; | 559 time += kThinningDuration; |
| 554 scrollbar_controller_->Animate(time); | 560 scrollbar_controller_->Animate(time); |
| 555 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 561 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 556 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 562 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 557 scrollbar_layer_->thumb_thickness_scale_factor()); | 563 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 558 } | 564 } |
| 559 | 565 |
| 560 // Move the pointer over the scrollbar. Make sure it gets thick that it gets | 566 // Move the pointer over the scrollbar. Make sure it gets thick that it gets |
| 561 // thin when moved away. | 567 // thin when moved away. |
| 562 TEST_F(ScrollbarAnimationControllerThinningTest, MouseOver) { | 568 TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseOver) { |
| 563 // Scroll to make the scrollbars visible. | 569 // Scroll to make the scrollbars visible. |
| 564 scrollbar_controller_->DidScrollBegin(); | 570 scrollbar_controller_->DidScrollBegin(); |
| 565 scrollbar_controller_->DidScrollUpdate(false); | 571 scrollbar_controller_->DidScrollUpdate(false); |
| 566 scrollbar_controller_->DidScrollEnd(); | 572 scrollbar_controller_->DidScrollEnd(); |
| 567 | 573 |
| 568 base::TimeTicks time; | 574 base::TimeTicks time; |
| 569 time += base::TimeDelta::FromSeconds(1); | 575 time += base::TimeDelta::FromSeconds(1); |
| 570 | 576 |
| 571 scrollbar_controller_->DidMouseMoveNear(0); | 577 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 572 scrollbar_controller_->Animate(time); | 578 scrollbar_controller_->Animate(time); |
| 573 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 579 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 574 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 580 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 575 scrollbar_layer_->thumb_thickness_scale_factor()); | 581 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 576 | 582 |
| 577 // Should animate to thickened. | 583 // Should animate to thickened. |
| 578 time += kThinningDuration; | 584 time += kThinningDuration; |
| 579 scrollbar_controller_->Animate(time); | 585 scrollbar_controller_->Animate(time); |
| 580 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 586 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 581 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 587 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 582 | 588 |
| 583 // Subsequent moves should not change anything. | 589 // Subsequent moves should not change anything. |
| 584 scrollbar_controller_->DidMouseMoveNear(0); | 590 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 585 scrollbar_controller_->Animate(time); | 591 scrollbar_controller_->Animate(time); |
| 586 time += base::TimeDelta::FromSeconds(10); | 592 time += base::TimeDelta::FromSeconds(10); |
| 587 scrollbar_controller_->Animate(time); | 593 scrollbar_controller_->Animate(time); |
| 588 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 594 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 589 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 595 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 590 | 596 |
| 591 // Moving off the scrollbar but still withing the "near" threshold should do | 597 // Moving off the scrollbar but still withing the "near" threshold should do |
| 592 // nothing. | 598 // nothing. |
| 593 scrollbar_controller_->DidMouseMoveNear( | 599 scrollbar_controller_->DidMouseMoveNear( |
| 594 kDefaultMouseMoveDistanceToTriggerAnimation - 1.f); | 600 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation - 1.f); |
| 595 scrollbar_controller_->Animate(time); | 601 scrollbar_controller_->Animate(time); |
| 596 time += base::TimeDelta::FromSeconds(10); | 602 time += base::TimeDelta::FromSeconds(10); |
| 597 scrollbar_controller_->Animate(time); | 603 scrollbar_controller_->Animate(time); |
| 598 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 604 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 599 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 605 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 600 | 606 |
| 601 // Now move away from bar. | 607 // Now move away from bar. |
| 602 scrollbar_controller_->DidMouseMoveNear( | 608 scrollbar_controller_->DidMouseMoveNear( |
| 603 kDefaultMouseMoveDistanceToTriggerAnimation); | 609 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation); |
| 604 scrollbar_controller_->Animate(time); | 610 scrollbar_controller_->Animate(time); |
| 605 time += kThinningDuration; | 611 time += kThinningDuration; |
| 606 scrollbar_controller_->Animate(time); | 612 scrollbar_controller_->Animate(time); |
| 607 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 613 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 608 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 614 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 609 scrollbar_layer_->thumb_thickness_scale_factor()); | 615 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 610 } | 616 } |
| 611 | 617 |
| 612 // First move the pointer over the scrollbar off of it. Make sure the thinning | 618 // First move the pointer over the scrollbar off of it. Make sure the thinning |
| 613 // animation kicked off in DidMouseMoveOffScrollbar gets overridden by the | 619 // animation kicked off in DidMouseMoveOffScrollbar gets overridden by the |
| 614 // thickening animation in the DidMouseMoveNear call. | 620 // thickening animation in the DidMouseMoveNear call. |
| 615 TEST_F(ScrollbarAnimationControllerThinningTest, | 621 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 616 MouseNearThenAwayWhileAnimating) { | 622 MouseNearThenAwayWhileAnimating) { |
| 617 // Scroll to make the scrollbars visible. | 623 // Scroll to make the scrollbars visible. |
| 618 scrollbar_controller_->DidScrollBegin(); | 624 scrollbar_controller_->DidScrollBegin(); |
| 619 scrollbar_controller_->DidScrollUpdate(false); | 625 scrollbar_controller_->DidScrollUpdate(false); |
| 620 scrollbar_controller_->DidScrollEnd(); | 626 scrollbar_controller_->DidScrollEnd(); |
| 621 | 627 |
| 622 base::TimeTicks time; | 628 base::TimeTicks time; |
| 623 time += base::TimeDelta::FromSeconds(1); | 629 time += base::TimeDelta::FromSeconds(1); |
| 624 | 630 |
| 625 scrollbar_controller_->DidMouseMoveNear(0); | 631 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 626 scrollbar_controller_->Animate(time); | 632 scrollbar_controller_->Animate(time); |
| 627 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 633 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 628 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 634 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 629 scrollbar_layer_->thumb_thickness_scale_factor()); | 635 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 630 | 636 |
| 631 // Should animate to thickened. | 637 // Should animate to thickened. |
| 632 time += kThinningDuration; | 638 time += kThinningDuration; |
| 633 scrollbar_controller_->Animate(time); | 639 scrollbar_controller_->Animate(time); |
| 634 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 640 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 635 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 641 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 636 | 642 |
| 637 // This is tricky. The DidMouseLeave() is sent before the | 643 // This is tricky. The DidMouseLeave() is sent before the |
| 638 // subsequent DidMouseMoveNear(), if the mouse moves in that direction. | 644 // subsequent DidMouseMoveNear(), if the mouse moves in that direction. |
| 639 // This results in the thumb thinning. We want to make sure that when the | 645 // This results in the thumb thinning. We want to make sure that when the |
| 640 // thumb starts expanding it doesn't first narrow to the idle thinness. | 646 // thumb starts expanding it doesn't first narrow to the idle thinness. |
| 641 time += base::TimeDelta::FromSeconds(1); | 647 time += base::TimeDelta::FromSeconds(1); |
| 642 scrollbar_controller_->DidMouseLeave(); | 648 scrollbar_controller_->DidMouseLeave(); |
| 643 scrollbar_controller_->Animate(time); | 649 scrollbar_controller_->Animate(time); |
| 644 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 650 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 645 | 651 |
| 646 // Let the animation run half of the way through the thinning animation. | 652 // Let the animation run half of the way through the thinning animation. |
| 647 time += kThinningDuration / 2; | 653 time += kThinningDuration / 2; |
| 648 scrollbar_controller_->Animate(time); | 654 scrollbar_controller_->Animate(time); |
| 649 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, | 655 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, |
| 650 scrollbar_layer_->thumb_thickness_scale_factor()); | 656 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 651 | 657 |
| 652 // Now we get a notification for the mouse moving over the scroller. The | 658 // Now we get a notification for the mouse moving over the scroller. The |
| 653 // animation is reset to the thickening direction but we won't start | 659 // animation is reset to the thickening direction but we won't start |
| 654 // thickening until the new animation catches up to the current thickness. | 660 // thickening until the new animation catches up to the current thickness. |
| 655 scrollbar_controller_->DidMouseMoveNear(1); | 661 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1); |
| 656 scrollbar_controller_->Animate(time); | 662 scrollbar_controller_->Animate(time); |
| 657 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, | 663 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, |
| 658 scrollbar_layer_->thumb_thickness_scale_factor()); | 664 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 659 | 665 |
| 660 // Until we reach the half way point, the animation will have no effect. | 666 // Until we reach the half way point, the animation will have no effect. |
| 661 time += kThinningDuration / 4; | 667 time += kThinningDuration / 4; |
| 662 scrollbar_controller_->Animate(time); | 668 scrollbar_controller_->Animate(time); |
| 663 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, | 669 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, |
| 664 scrollbar_layer_->thumb_thickness_scale_factor()); | 670 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 665 | 671 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 677 | 683 |
| 678 // And all the way to the end. | 684 // And all the way to the end. |
| 679 time += kThinningDuration / 4; | 685 time += kThinningDuration / 4; |
| 680 scrollbar_controller_->Animate(time); | 686 scrollbar_controller_->Animate(time); |
| 681 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 687 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 682 } | 688 } |
| 683 | 689 |
| 684 // First move the pointer on the scrollbar, then press it, then away. | 690 // First move the pointer on the scrollbar, then press it, then away. |
| 685 // Confirm that the bar gets thick. Then mouse up. Confirm that | 691 // Confirm that the bar gets thick. Then mouse up. Confirm that |
| 686 // the bar gets thin. | 692 // the bar gets thin. |
| 687 TEST_F(ScrollbarAnimationControllerThinningTest, | 693 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 688 MouseCaptureAndReleaseOutOfBar) { | 694 MouseCaptureAndReleaseOutOfBar) { |
| 689 // Scroll to make the scrollbars visible. | 695 // Scroll to make the scrollbars visible. |
| 690 scrollbar_controller_->DidScrollBegin(); | 696 scrollbar_controller_->DidScrollBegin(); |
| 691 scrollbar_controller_->DidScrollUpdate(false); | 697 scrollbar_controller_->DidScrollUpdate(false); |
| 692 scrollbar_controller_->DidScrollEnd(); | 698 scrollbar_controller_->DidScrollEnd(); |
| 693 | 699 |
| 694 base::TimeTicks time; | 700 base::TimeTicks time; |
| 695 time += base::TimeDelta::FromSeconds(1); | 701 time += base::TimeDelta::FromSeconds(1); |
| 696 | 702 |
| 697 // Move over the scrollbar. | 703 // Move over the scrollbar. |
| 698 scrollbar_controller_->DidMouseMoveNear(0); | 704 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 699 scrollbar_controller_->Animate(time); | 705 scrollbar_controller_->Animate(time); |
| 700 time += kFadeDuration; | 706 time += kFadeDuration; |
| 701 scrollbar_controller_->Animate(time); | 707 scrollbar_controller_->Animate(time); |
| 702 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 708 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 703 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 709 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 704 | 710 |
| 705 // Capture | 711 // Capture |
| 706 scrollbar_controller_->DidMouseDown(); | 712 scrollbar_controller_->DidMouseDown(); |
| 707 time += base::TimeDelta::FromSeconds(1); | 713 time += base::TimeDelta::FromSeconds(1); |
| 708 scrollbar_controller_->Animate(time); | 714 scrollbar_controller_->Animate(time); |
| 709 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 715 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 710 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 716 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 711 | 717 |
| 712 // Should stay thick for a while. | 718 // Should stay thick for a while. |
| 713 time += base::TimeDelta::FromSeconds(10); | 719 time += base::TimeDelta::FromSeconds(10); |
| 714 scrollbar_controller_->Animate(time); | 720 scrollbar_controller_->Animate(time); |
| 715 | 721 |
| 716 // Move outside the "near" threshold. Because the scrollbar is captured it | 722 // Move outside the "near" threshold. Because the scrollbar is captured it |
| 717 // should remain thick. | 723 // should remain thick. |
| 718 scrollbar_controller_->DidMouseMoveNear( | 724 scrollbar_controller_->DidMouseMoveNear( |
| 719 kDefaultMouseMoveDistanceToTriggerAnimation); | 725 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation); |
| 720 time += kThinningDuration; | 726 time += kThinningDuration; |
| 721 scrollbar_controller_->Animate(time); | 727 scrollbar_controller_->Animate(time); |
| 722 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 728 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 723 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 729 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 724 | 730 |
| 725 // Release. | 731 // Release. |
| 726 scrollbar_controller_->DidMouseUp(); | 732 scrollbar_controller_->DidMouseUp(); |
| 727 | 733 |
| 728 // Should become thin. | 734 // Should become thin. |
| 729 time += base::TimeDelta::FromSeconds(1); | 735 time += base::TimeDelta::FromSeconds(1); |
| 730 scrollbar_controller_->Animate(time); | 736 scrollbar_controller_->Animate(time); |
| 731 time += kThinningDuration; | 737 time += kThinningDuration; |
| 732 scrollbar_controller_->Animate(time); | 738 scrollbar_controller_->Animate(time); |
| 733 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 739 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 734 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 740 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 735 scrollbar_layer_->thumb_thickness_scale_factor()); | 741 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 736 } | 742 } |
| 737 | 743 |
| 738 // First move the pointer on the scrollbar, then press it, then away. Confirm | 744 // First move the pointer on the scrollbar, then press it, then away. Confirm |
| 739 // that the bar gets thick. Then move point on the scrollbar and mouse up. | 745 // that the bar gets thick. Then move point on the scrollbar and mouse up. |
| 740 // Confirm that the bar stays thick. | 746 // Confirm that the bar stays thick. |
| 741 TEST_F(ScrollbarAnimationControllerThinningTest, MouseCaptureAndReleaseOnBar) { | 747 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 748 MouseCaptureAndReleaseOnBar) { |
| 742 // Scroll to make the scrollbars visible. | 749 // Scroll to make the scrollbars visible. |
| 743 scrollbar_controller_->DidScrollBegin(); | 750 scrollbar_controller_->DidScrollBegin(); |
| 744 scrollbar_controller_->DidScrollUpdate(false); | 751 scrollbar_controller_->DidScrollUpdate(false); |
| 745 scrollbar_controller_->DidScrollEnd(); | 752 scrollbar_controller_->DidScrollEnd(); |
| 746 | 753 |
| 747 base::TimeTicks time; | 754 base::TimeTicks time; |
| 748 time += base::TimeDelta::FromSeconds(1); | 755 time += base::TimeDelta::FromSeconds(1); |
| 749 | 756 |
| 750 // Move over scrollbar. | 757 // Move over scrollbar. |
| 751 scrollbar_controller_->DidMouseMoveNear(0); | 758 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 752 scrollbar_controller_->Animate(time); | 759 scrollbar_controller_->Animate(time); |
| 753 time += kThinningDuration; | 760 time += kThinningDuration; |
| 754 scrollbar_controller_->Animate(time); | 761 scrollbar_controller_->Animate(time); |
| 755 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 762 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 756 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 763 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 757 | 764 |
| 758 // Capture. Nothing should change. | 765 // Capture. Nothing should change. |
| 759 scrollbar_controller_->DidMouseDown(); | 766 scrollbar_controller_->DidMouseDown(); |
| 760 time += base::TimeDelta::FromSeconds(1); | 767 time += base::TimeDelta::FromSeconds(1); |
| 761 scrollbar_controller_->Animate(time); | 768 scrollbar_controller_->Animate(time); |
| 762 time += base::TimeDelta::FromSeconds(10); | 769 time += base::TimeDelta::FromSeconds(10); |
| 763 scrollbar_controller_->Animate(time); | 770 scrollbar_controller_->Animate(time); |
| 764 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 771 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 765 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 772 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 766 | 773 |
| 767 // Move away from scrollbar. Nothing should change. | 774 // Move away from scrollbar. Nothing should change. |
| 768 scrollbar_controller_->DidMouseMoveNear( | 775 scrollbar_controller_->DidMouseMoveNear( |
| 769 kDefaultMouseMoveDistanceToTriggerAnimation); | 776 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation); |
| 770 time += base::TimeDelta::FromSeconds(1); | 777 time += base::TimeDelta::FromSeconds(1); |
| 771 scrollbar_controller_->Animate(time); | 778 scrollbar_controller_->Animate(time); |
| 772 time += base::TimeDelta::FromSeconds(10); | 779 time += base::TimeDelta::FromSeconds(10); |
| 773 scrollbar_controller_->Animate(time); | 780 scrollbar_controller_->Animate(time); |
| 774 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 781 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 775 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 782 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 776 | 783 |
| 777 // Move over scrollbar and release. Since we're near the scrollbar, it should | 784 // Move over scrollbar and release. Since we're near the scrollbar, it should |
| 778 // remain thick. | 785 // remain thick. |
| 779 scrollbar_controller_->DidMouseMoveNear(0); | 786 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 780 scrollbar_controller_->DidMouseUp(); | 787 scrollbar_controller_->DidMouseUp(); |
| 781 time += base::TimeDelta::FromSeconds(1); | 788 time += base::TimeDelta::FromSeconds(1); |
| 782 scrollbar_controller_->Animate(time); | 789 scrollbar_controller_->Animate(time); |
| 783 time += base::TimeDelta::FromSeconds(10); | 790 time += base::TimeDelta::FromSeconds(10); |
| 784 scrollbar_controller_->Animate(time); | 791 scrollbar_controller_->Animate(time); |
| 785 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 792 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 786 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 793 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 787 } | 794 } |
| 788 | 795 |
| 789 // Move mouse on scrollbar and capture then move out of window. Confirm that | 796 // Move mouse on scrollbar and capture then move out of window. Confirm that |
| 790 // the bar stays thick. | 797 // the bar stays thick. |
| 791 TEST_F(ScrollbarAnimationControllerThinningTest, | 798 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 792 MouseCapturedAndExitWindowFromScrollbar) { | 799 MouseCapturedAndExitWindowFromScrollbar) { |
| 793 // Scroll to make the scrollbars visible. | 800 // Scroll to make the scrollbars visible. |
| 794 scrollbar_controller_->DidScrollBegin(); | 801 scrollbar_controller_->DidScrollBegin(); |
| 795 scrollbar_controller_->DidScrollUpdate(false); | 802 scrollbar_controller_->DidScrollUpdate(false); |
| 796 scrollbar_controller_->DidScrollEnd(); | 803 scrollbar_controller_->DidScrollEnd(); |
| 797 | 804 |
| 798 base::TimeTicks time; | 805 base::TimeTicks time; |
| 799 time += base::TimeDelta::FromSeconds(1); | 806 time += base::TimeDelta::FromSeconds(1); |
| 800 | 807 |
| 801 // Move mouse over scrollbar. | 808 // Move mouse over scrollbar. |
| 802 scrollbar_controller_->DidMouseMoveNear(0); | 809 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 803 scrollbar_controller_->Animate(time); | 810 scrollbar_controller_->Animate(time); |
| 804 time += kThinningDuration; | 811 time += kThinningDuration; |
| 805 scrollbar_controller_->Animate(time); | 812 scrollbar_controller_->Animate(time); |
| 806 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 813 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 807 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 814 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 808 | 815 |
| 809 // Capture. | 816 // Capture. |
| 810 scrollbar_controller_->DidMouseDown(); | 817 scrollbar_controller_->DidMouseDown(); |
| 811 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 818 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 812 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 819 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 813 | 820 |
| 814 // Move out of window. Since the scrollbar is capture, it shouldn't change in | 821 // Move out of window. Since the scrollbar is capture, it shouldn't change in |
| 815 // any way. | 822 // any way. |
| 816 scrollbar_controller_->DidMouseLeave(); | 823 scrollbar_controller_->DidMouseLeave(); |
| 817 scrollbar_controller_->Animate(time); | 824 scrollbar_controller_->Animate(time); |
| 818 time += kThinningDuration; | 825 time += kThinningDuration; |
| 819 scrollbar_controller_->Animate(time); | 826 scrollbar_controller_->Animate(time); |
| 820 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 827 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 821 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 828 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 822 } | 829 } |
| 823 | 830 |
| 824 // Tests that the thickening/thinning effects are animated. | 831 // Tests that the thickening/thinning effects are animated. |
| 825 TEST_F(ScrollbarAnimationControllerThinningTest, ThicknessAnimated) { | 832 TEST_F(SingleScrollbarAnimationControllerThinningTest, ThicknessAnimated) { |
| 826 // Scroll to make the scrollbars visible. | 833 // Scroll to make the scrollbars visible. |
| 827 scrollbar_controller_->DidScrollBegin(); | 834 scrollbar_controller_->DidScrollBegin(); |
| 828 scrollbar_controller_->DidScrollUpdate(false); | 835 scrollbar_controller_->DidScrollUpdate(false); |
| 829 scrollbar_controller_->DidScrollEnd(); | 836 scrollbar_controller_->DidScrollEnd(); |
| 830 | 837 |
| 831 base::TimeTicks time; | 838 base::TimeTicks time; |
| 832 time += base::TimeDelta::FromSeconds(1); | 839 time += base::TimeDelta::FromSeconds(1); |
| 833 | 840 |
| 834 // Move mouse near scrollbar. Test that at half the duration time, the | 841 // Move mouse near scrollbar. Test that at half the duration time, the |
| 835 // thickness is half way through its animation. | 842 // thickness is half way through its animation. |
| 836 scrollbar_controller_->DidMouseMoveNear(1); | 843 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1); |
| 837 scrollbar_controller_->Animate(time); | 844 scrollbar_controller_->Animate(time); |
| 838 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 845 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 839 scrollbar_layer_->thumb_thickness_scale_factor()); | 846 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 840 | 847 |
| 841 time += kThinningDuration / 2; | 848 time += kThinningDuration / 2; |
| 842 scrollbar_controller_->Animate(time); | 849 scrollbar_controller_->Animate(time); |
| 843 EXPECT_FLOAT_EQ(kIdleThicknessScale + (1.0f - kIdleThicknessScale) / 2.0f, | 850 EXPECT_FLOAT_EQ(kIdleThicknessScale + (1.0f - kIdleThicknessScale) / 2.0f, |
| 844 scrollbar_layer_->thumb_thickness_scale_factor()); | 851 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 845 | 852 |
| 846 time += kThinningDuration / 2; | 853 time += kThinningDuration / 2; |
| 847 scrollbar_controller_->Animate(time); | 854 scrollbar_controller_->Animate(time); |
| 848 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 855 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 849 | 856 |
| 850 // Move mouse away from scrollbar. Same check. | 857 // Move mouse away from scrollbar. Same check. |
| 851 time += base::TimeDelta::FromSeconds(1); | 858 time += base::TimeDelta::FromSeconds(1); |
| 852 scrollbar_controller_->DidMouseMoveNear( | 859 scrollbar_controller_->DidMouseMoveNear( |
| 853 kDefaultMouseMoveDistanceToTriggerAnimation); | 860 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation); |
| 854 scrollbar_controller_->Animate(time); | 861 scrollbar_controller_->Animate(time); |
| 855 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 862 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 856 | 863 |
| 857 time += kThinningDuration / 2; | 864 time += kThinningDuration / 2; |
| 858 scrollbar_controller_->Animate(time); | 865 scrollbar_controller_->Animate(time); |
| 859 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, | 866 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, |
| 860 scrollbar_layer_->thumb_thickness_scale_factor()); | 867 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 861 | 868 |
| 862 time += kThinningDuration / 2; | 869 time += kThinningDuration / 2; |
| 863 scrollbar_controller_->Animate(time); | 870 scrollbar_controller_->Animate(time); |
| 864 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 871 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 865 scrollbar_layer_->thumb_thickness_scale_factor()); | 872 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 866 } | 873 } |
| 867 | 874 |
| 868 // Tests that main thread scroll updates immediatley queue a fade animation | 875 // Tests that main thread scroll updates immediatley queue a fade animation |
| 869 // without requiring a ScrollEnd. | 876 // without requiring a ScrollEnd. |
| 870 TEST_F(ScrollbarAnimationControllerThinningTest, MainThreadScrollQueuesFade) { | 877 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 878 MainThreadScrollQueuesFade) { |
| 871 ASSERT_TRUE(client_.start_fade().is_null()); | 879 ASSERT_TRUE(client_.start_fade().is_null()); |
| 872 | 880 |
| 873 // A ScrollUpdate without a ScrollBegin indicates a main thread scroll update | 881 // A ScrollUpdate without a ScrollBegin indicates a main thread scroll update |
| 874 // so we should schedule a fade animation without waiting for a ScrollEnd | 882 // so we should schedule a fade animation without waiting for a ScrollEnd |
| 875 // (which will never come). | 883 // (which will never come). |
| 876 scrollbar_controller_->DidScrollUpdate(false); | 884 scrollbar_controller_->DidScrollUpdate(false); |
| 877 EXPECT_FALSE(client_.start_fade().is_null()); | 885 EXPECT_FALSE(client_.start_fade().is_null()); |
| 878 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 886 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 879 | 887 |
| 880 client_.start_fade().Reset(); | 888 client_.start_fade().Reset(); |
| 881 | 889 |
| 882 // If we got a ScrollBegin, we shouldn't schedule the fade animation until we | 890 // If we got a ScrollBegin, we shouldn't schedule the fade animation until we |
| 883 // get a corresponding ScrollEnd. | 891 // get a corresponding ScrollEnd. |
| 884 scrollbar_controller_->DidScrollBegin(); | 892 scrollbar_controller_->DidScrollBegin(); |
| 885 scrollbar_controller_->DidScrollUpdate(false); | 893 scrollbar_controller_->DidScrollUpdate(false); |
| 886 EXPECT_TRUE(client_.start_fade().is_null()); | 894 EXPECT_TRUE(client_.start_fade().is_null()); |
| 887 scrollbar_controller_->DidScrollEnd(); | 895 scrollbar_controller_->DidScrollEnd(); |
| 888 EXPECT_FALSE(client_.start_fade().is_null()); | 896 EXPECT_FALSE(client_.start_fade().is_null()); |
| 889 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 897 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 890 } | 898 } |
| 891 | 899 |
| 892 // Make sure that if the scroll update is as a result of a resize, we use the | 900 // Make sure that if the scroll update is as a result of a resize, we use the |
| 893 // resize delay time instead of the default one. | 901 // resize delay time instead of the default one. |
| 894 TEST_F(ScrollbarAnimationControllerThinningTest, ResizeFadeDuration) { | 902 TEST_F(SingleScrollbarAnimationControllerThinningTest, ResizeFadeDuration) { |
| 895 ASSERT_TRUE(client_.delay().is_zero()); | 903 ASSERT_TRUE(client_.delay().is_zero()); |
| 896 | 904 |
| 897 scrollbar_controller_->DidScrollUpdate(true); | 905 scrollbar_controller_->DidScrollUpdate(true); |
| 898 EXPECT_FALSE(client_.start_fade().is_null()); | 906 EXPECT_FALSE(client_.start_fade().is_null()); |
| 899 EXPECT_EQ(kResizeDelayBeforeStarting, client_.delay()); | 907 EXPECT_EQ(kResizeDelayBeforeStarting, client_.delay()); |
| 900 | 908 |
| 901 client_.delay() = base::TimeDelta(); | 909 client_.delay() = base::TimeDelta(); |
| 902 | 910 |
| 903 // We should use the gesture delay rather than the resize delay if we're in a | 911 // We should use the gesture delay rather than the resize delay if we're in a |
| 904 // gesture scroll, even if the resize param is set. | 912 // gesture scroll, even if the resize param is set. |
| 905 scrollbar_controller_->DidScrollBegin(); | 913 scrollbar_controller_->DidScrollBegin(); |
| 906 scrollbar_controller_->DidScrollUpdate(true); | 914 scrollbar_controller_->DidScrollUpdate(true); |
| 907 scrollbar_controller_->DidScrollEnd(); | 915 scrollbar_controller_->DidScrollEnd(); |
| 908 | 916 |
| 909 EXPECT_FALSE(client_.start_fade().is_null()); | 917 EXPECT_FALSE(client_.start_fade().is_null()); |
| 910 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 918 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 911 } | 919 } |
| 912 | 920 |
| 913 // Tests that the fade effect is animated. | 921 // Tests that the fade effect is animated. |
| 914 TEST_F(ScrollbarAnimationControllerThinningTest, FadeAnimated) { | 922 TEST_F(SingleScrollbarAnimationControllerThinningTest, FadeAnimated) { |
| 915 // Scroll to make the scrollbars visible. | 923 // Scroll to make the scrollbars visible. |
| 916 scrollbar_controller_->DidScrollBegin(); | 924 scrollbar_controller_->DidScrollBegin(); |
| 917 scrollbar_controller_->DidScrollUpdate(false); | 925 scrollbar_controller_->DidScrollUpdate(false); |
| 918 scrollbar_controller_->DidScrollEnd(); | 926 scrollbar_controller_->DidScrollEnd(); |
| 919 | 927 |
| 920 // Appearance is instant. | 928 // Appearance is instant. |
| 921 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 929 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 922 | 930 |
| 923 // An animation should have been enqueued. | 931 // An animation should have been enqueued. |
| 924 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 932 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 935 time += kFadeDuration / 2; | 943 time += kFadeDuration / 2; |
| 936 scrollbar_controller_->Animate(time); | 944 scrollbar_controller_->Animate(time); |
| 937 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); | 945 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); |
| 938 | 946 |
| 939 time += kFadeDuration / 2; | 947 time += kFadeDuration / 2; |
| 940 scrollbar_controller_->Animate(time); | 948 scrollbar_controller_->Animate(time); |
| 941 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 949 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 942 } | 950 } |
| 943 | 951 |
| 944 // Tests that the controller tells the client when the scrollbars hide/show. | 952 // Tests that the controller tells the client when the scrollbars hide/show. |
| 945 TEST_F(ScrollbarAnimationControllerThinningTest, NotifyChangedVisibility) { | 953 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 954 NotifyChangedVisibility) { |
| 946 base::TimeTicks time; | 955 base::TimeTicks time; |
| 947 time += base::TimeDelta::FromSeconds(1); | 956 time += base::TimeDelta::FromSeconds(1); |
| 948 | 957 |
| 949 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); | 958 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); |
| 950 // Scroll to make the scrollbars visible. | 959 // Scroll to make the scrollbars visible. |
| 951 scrollbar_controller_->DidScrollBegin(); | 960 scrollbar_controller_->DidScrollBegin(); |
| 952 scrollbar_controller_->DidScrollUpdate(false); | 961 scrollbar_controller_->DidScrollUpdate(false); |
| 953 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); | 962 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); |
| 954 Mock::VerifyAndClearExpectations(&client_); | 963 Mock::VerifyAndClearExpectations(&client_); |
| 955 | 964 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 984 // Calling DidScrollUpdate without a begin (i.e. update from commit) should | 993 // Calling DidScrollUpdate without a begin (i.e. update from commit) should |
| 985 // also notify. | 994 // also notify. |
| 986 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); | 995 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); |
| 987 scrollbar_controller_->DidScrollUpdate(false); | 996 scrollbar_controller_->DidScrollUpdate(false); |
| 988 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); | 997 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); |
| 989 Mock::VerifyAndClearExpectations(&client_); | 998 Mock::VerifyAndClearExpectations(&client_); |
| 990 } | 999 } |
| 991 | 1000 |
| 992 } // namespace | 1001 } // namespace |
| 993 } // namespace cc | 1002 } // namespace cc |
| OLD | NEW |