| 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 remains visible as long as the mouse is near the scrollbar. | 206 // thick. Ensure it remains visible as long as the mouse is near the scrollbar. |
| 204 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearAndDontFadeOut) { | 207 TEST_F(SingleScrollbarAnimationControllerThinningTest, MoveNearAndDontFadeOut) { |
| 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 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 218 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 216 | 219 |
| 217 // Now move the mouse near the scrollbar. This should cancel the currently | 220 // Now move the mouse near the scrollbar. This should cancel the currently |
| 218 // queued fading animation and start animating thickness. | 221 // queued fading animation and start animating thickness. |
| 219 scrollbar_controller_->DidMouseMoveNear(1); | 222 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1); |
| 220 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 223 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 221 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 224 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 222 scrollbar_layer_->thumb_thickness_scale_factor()); | 225 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 223 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 226 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
| 224 | 227 |
| 225 // Scrollbar should become thick. | 228 // Scrollbar should become thick. |
| 226 scrollbar_controller_->Animate(time); | 229 scrollbar_controller_->Animate(time); |
| 227 time += kThinningDuration; | 230 time += kThinningDuration; |
| 228 scrollbar_controller_->Animate(time); | 231 scrollbar_controller_->Animate(time); |
| 229 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 232 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 230 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 233 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 231 | 234 |
| 232 // Mouse is still near the Scrollbar. Once the thickness animation is | 235 // Mouse is still near the Scrollbar. Once the thickness animation is |
| 233 // complete, the queued delayed fade animation should be either cancelled or | 236 // complete, the queued delayed fade animation should be either cancelled or |
| 234 // null. | 237 // null. |
| 235 EXPECT_TRUE(client_.start_fade().is_null() || | 238 EXPECT_TRUE(client_.start_fade().is_null() || |
| 236 client_.start_fade().IsCancelled()); | 239 client_.start_fade().IsCancelled()); |
| 237 } | 240 } |
| 238 | 241 |
| 239 // Scroll content. Move the mouse over the scrollbar and confirm it becomes | 242 // Scroll content. Move the mouse over the scrollbar and confirm it becomes |
| 240 // thick. Ensure it remains visible as long as the mouse is over the scrollbar. | 243 // thick. Ensure it remains visible as long as the mouse is over the scrollbar. |
| 241 TEST_F(ScrollbarAnimationControllerThinningTest, MoveOverAndDontFadeOut) { | 244 TEST_F(SingleScrollbarAnimationControllerThinningTest, MoveOverAndDontFadeOut) { |
| 242 base::TimeTicks time; | 245 base::TimeTicks time; |
| 243 time += base::TimeDelta::FromSeconds(1); | 246 time += base::TimeDelta::FromSeconds(1); |
| 244 | 247 |
| 245 scrollbar_controller_->DidScrollBegin(); | 248 scrollbar_controller_->DidScrollBegin(); |
| 246 scrollbar_controller_->DidScrollUpdate(false); | 249 scrollbar_controller_->DidScrollUpdate(false); |
| 247 scrollbar_controller_->DidScrollEnd(); | 250 scrollbar_controller_->DidScrollEnd(); |
| 248 | 251 |
| 249 // An animation should have been enqueued. | 252 // An animation should have been enqueued. |
| 250 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 253 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 251 EXPECT_FALSE(client_.start_fade().is_null()); | 254 EXPECT_FALSE(client_.start_fade().is_null()); |
| 252 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 255 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 253 | 256 |
| 254 // Now move the mouse over the scrollbar. This should cancel the currently | 257 // Now move the mouse over the scrollbar. This should cancel the currently |
| 255 // queued fading animation and start animating thickness. | 258 // queued fading animation and start animating thickness. |
| 256 scrollbar_controller_->DidMouseMoveNear(0); | 259 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 257 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 260 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 258 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 261 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 259 scrollbar_layer_->thumb_thickness_scale_factor()); | 262 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 260 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 263 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
| 261 | 264 |
| 262 // Scrollbar should become thick. | 265 // Scrollbar should become thick. |
| 263 scrollbar_controller_->Animate(time); | 266 scrollbar_controller_->Animate(time); |
| 264 time += kThinningDuration; | 267 time += kThinningDuration; |
| 265 scrollbar_controller_->Animate(time); | 268 scrollbar_controller_->Animate(time); |
| 266 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 269 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 267 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 270 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 268 | 271 |
| 269 // Mouse is still over the Scrollbar. Once the thickness animation is | 272 // Mouse is still over the Scrollbar. Once the thickness animation is |
| 270 // complete, the queued delayed fade animation should be either null or | 273 // complete, the queued delayed fade animation should be either null or |
| 271 // cancelled. | 274 // cancelled. |
| 272 EXPECT_TRUE(client_.start_fade().is_null() || | 275 EXPECT_TRUE(client_.start_fade().is_null() || |
| 273 client_.start_fade().IsCancelled()); | 276 client_.start_fade().IsCancelled()); |
| 274 } | 277 } |
| 275 | 278 |
| 276 // Make sure a scrollbar captured before the thickening animation doesn't try | 279 // Make sure a scrollbar captured before the thickening animation doesn't try |
| 277 // to fade out. | 280 // to fade out. |
| 278 TEST_F(ScrollbarAnimationControllerThinningTest, | 281 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 279 DontFadeWhileCapturedBeforeThick) { | 282 DontFadeWhileCapturedBeforeThick) { |
| 280 base::TimeTicks time; | 283 base::TimeTicks time; |
| 281 time += base::TimeDelta::FromSeconds(1); | 284 time += base::TimeDelta::FromSeconds(1); |
| 282 | 285 |
| 283 scrollbar_controller_->DidScrollBegin(); | 286 scrollbar_controller_->DidScrollBegin(); |
| 284 scrollbar_controller_->DidScrollUpdate(false); | 287 scrollbar_controller_->DidScrollUpdate(false); |
| 285 scrollbar_controller_->DidScrollEnd(); | 288 scrollbar_controller_->DidScrollEnd(); |
| 286 | 289 |
| 287 // An animation should have been enqueued. | 290 // An animation should have been enqueued. |
| 288 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 291 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 289 EXPECT_FALSE(client_.start_fade().is_null()); | 292 EXPECT_FALSE(client_.start_fade().is_null()); |
| 290 | 293 |
| 291 // Now move the mouse over the scrollbar and capture it. It should become | 294 // Now move the mouse over the scrollbar and capture it. It should become |
| 292 // thick without need for an animation. | 295 // thick without need for an animation. |
| 293 scrollbar_controller_->DidMouseMoveNear(0); | 296 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 294 scrollbar_controller_->DidMouseDown(); | 297 scrollbar_controller_->DidMouseDown(); |
| 295 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 298 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 296 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 299 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 297 | 300 |
| 298 // The fade animation should have been cleared or cancelled. | 301 // The fade animation should have been cleared or cancelled. |
| 299 EXPECT_TRUE(client_.start_fade().is_null() || | 302 EXPECT_TRUE(client_.start_fade().is_null() || |
| 300 client_.start_fade().IsCancelled()); | 303 client_.start_fade().IsCancelled()); |
| 301 } | 304 } |
| 302 | 305 |
| 303 // Make sure a scrollbar captured after a thickening animation doesn't try to | 306 // Make sure a scrollbar captured after a thickening animation doesn't try to |
| 304 // fade out. | 307 // fade out. |
| 305 TEST_F(ScrollbarAnimationControllerThinningTest, DontFadeWhileCaptured) { | 308 TEST_F(SingleScrollbarAnimationControllerThinningTest, DontFadeWhileCaptured) { |
| 306 base::TimeTicks time; | 309 base::TimeTicks time; |
| 307 time += base::TimeDelta::FromSeconds(1); | 310 time += base::TimeDelta::FromSeconds(1); |
| 308 | 311 |
| 309 scrollbar_controller_->DidScrollBegin(); | 312 scrollbar_controller_->DidScrollBegin(); |
| 310 scrollbar_controller_->DidScrollUpdate(false); | 313 scrollbar_controller_->DidScrollUpdate(false); |
| 311 scrollbar_controller_->DidScrollEnd(); | 314 scrollbar_controller_->DidScrollEnd(); |
| 312 | 315 |
| 313 // An animation should have been enqueued. | 316 // An animation should have been enqueued. |
| 314 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 317 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 315 EXPECT_FALSE(client_.start_fade().is_null()); | 318 EXPECT_FALSE(client_.start_fade().is_null()); |
| 316 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 319 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 317 | 320 |
| 318 // Now move the mouse over the scrollbar and animate it until it's thick. | 321 // Now move the mouse over the scrollbar and animate it until it's thick. |
| 319 scrollbar_controller_->DidMouseMoveNear(0); | 322 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 320 scrollbar_controller_->Animate(time); | 323 scrollbar_controller_->Animate(time); |
| 321 time += kThinningDuration; | 324 time += kThinningDuration; |
| 322 scrollbar_controller_->Animate(time); | 325 scrollbar_controller_->Animate(time); |
| 323 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 326 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 324 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 327 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 325 | 328 |
| 326 // Since the mouse is over the scrollbar, it should either clear or cancel the | 329 // Since the mouse is over the scrollbar, it should either clear or cancel the |
| 327 // queued fade. | 330 // queued fade. |
| 328 EXPECT_TRUE(client_.start_fade().is_null() || | 331 EXPECT_TRUE(client_.start_fade().is_null() || |
| 329 client_.start_fade().IsCancelled()); | 332 client_.start_fade().IsCancelled()); |
| 330 | 333 |
| 331 // Make sure the queued fade animation is still null or cancelled after | 334 // Make sure the queued fade animation is still null or cancelled after |
| 332 // capturing the scrollbar. | 335 // capturing the scrollbar. |
| 333 scrollbar_controller_->DidMouseDown(); | 336 scrollbar_controller_->DidMouseDown(); |
| 334 EXPECT_TRUE(client_.start_fade().is_null() || | 337 EXPECT_TRUE(client_.start_fade().is_null() || |
| 335 client_.start_fade().IsCancelled()); | 338 client_.start_fade().IsCancelled()); |
| 336 } | 339 } |
| 337 | 340 |
| 338 // Make sure releasing a captured scrollbar when the mouse isn't near it, causes | 341 // Make sure releasing a captured scrollbar when the mouse isn't near it, causes |
| 339 // the scrollbar to fade out. | 342 // the scrollbar to fade out. |
| 340 TEST_F(ScrollbarAnimationControllerThinningTest, FadeAfterReleasedFar) { | 343 TEST_F(SingleScrollbarAnimationControllerThinningTest, FadeAfterReleasedFar) { |
| 341 base::TimeTicks time; | 344 base::TimeTicks time; |
| 342 time += base::TimeDelta::FromSeconds(1); | 345 time += base::TimeDelta::FromSeconds(1); |
| 343 | 346 |
| 344 scrollbar_controller_->DidScrollBegin(); | 347 scrollbar_controller_->DidScrollBegin(); |
| 345 scrollbar_controller_->DidScrollUpdate(false); | 348 scrollbar_controller_->DidScrollUpdate(false); |
| 346 scrollbar_controller_->DidScrollEnd(); | 349 scrollbar_controller_->DidScrollEnd(); |
| 347 | 350 |
| 348 // An animation should have been enqueued. | 351 // An animation should have been enqueued. |
| 349 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 352 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 350 EXPECT_FALSE(client_.start_fade().is_null()); | 353 EXPECT_FALSE(client_.start_fade().is_null()); |
| 351 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 354 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 352 | 355 |
| 353 // Now move the mouse over the scrollbar and capture it. | 356 // Now move the mouse over the scrollbar and capture it. |
| 354 scrollbar_controller_->DidMouseMoveNear(0); | 357 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 355 scrollbar_controller_->DidMouseDown(); | 358 scrollbar_controller_->DidMouseDown(); |
| 356 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 359 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 357 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 360 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 358 | 361 |
| 359 // Since the mouse is still near the scrollbar, the queued fade should be | 362 // Since the mouse is still near the scrollbar, the queued fade should be |
| 360 // either null or cancelled. | 363 // either null or cancelled. |
| 361 EXPECT_TRUE(client_.start_fade().is_null() || | 364 EXPECT_TRUE(client_.start_fade().is_null() || |
| 362 client_.start_fade().IsCancelled()); | 365 client_.start_fade().IsCancelled()); |
| 363 | 366 |
| 364 // Now move the mouse away from the scrollbar and release it. | 367 // Now move the mouse away from the scrollbar and release it. |
| 365 scrollbar_controller_->DidMouseMoveNear( | 368 scrollbar_controller_->DidMouseMoveNear( |
| 366 kDefaultMouseMoveDistanceToTriggerAnimation + 1); | 369 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation + 1); |
| 367 scrollbar_controller_->DidMouseUp(); | 370 scrollbar_controller_->DidMouseUp(); |
| 368 | 371 |
| 369 scrollbar_controller_->Animate(time); | 372 scrollbar_controller_->Animate(time); |
| 370 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 373 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 371 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 374 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 372 time += kThinningDuration; | 375 time += kThinningDuration; |
| 373 scrollbar_controller_->Animate(time); | 376 scrollbar_controller_->Animate(time); |
| 374 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 377 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 375 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 378 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 376 scrollbar_layer_->thumb_thickness_scale_factor()); | 379 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 377 | 380 |
| 378 // The thickness animation is complete, a fade out must be queued. | 381 // The thickness animation is complete, a fade out must be queued. |
| 379 EXPECT_FALSE(client_.start_fade().is_null()); | 382 EXPECT_FALSE(client_.start_fade().is_null()); |
| 380 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 383 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 381 } | 384 } |
| 382 | 385 |
| 383 // Make sure releasing a captured scrollbar when the mouse is near/over it, | 386 // Make sure releasing a captured scrollbar when the mouse is near/over it, |
| 384 // doesn't cause the scrollbar to fade out. | 387 // doesn't cause the scrollbar to fade out. |
| 385 TEST_F(ScrollbarAnimationControllerThinningTest, DontFadeAfterReleasedNear) { | 388 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 389 DontFadeAfterReleasedNear) { |
| 386 base::TimeTicks time; | 390 base::TimeTicks time; |
| 387 time += base::TimeDelta::FromSeconds(1); | 391 time += base::TimeDelta::FromSeconds(1); |
| 388 | 392 |
| 389 scrollbar_controller_->DidScrollBegin(); | 393 scrollbar_controller_->DidScrollBegin(); |
| 390 scrollbar_controller_->DidScrollUpdate(false); | 394 scrollbar_controller_->DidScrollUpdate(false); |
| 391 scrollbar_controller_->DidScrollEnd(); | 395 scrollbar_controller_->DidScrollEnd(); |
| 392 | 396 |
| 393 // An animation should have been enqueued. | 397 // An animation should have been enqueued. |
| 394 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 398 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 395 EXPECT_FALSE(client_.start_fade().is_null()); | 399 EXPECT_FALSE(client_.start_fade().is_null()); |
| 396 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 400 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 397 | 401 |
| 398 // Now move the mouse over the scrollbar and capture it. | 402 // Now move the mouse over the scrollbar and capture it. |
| 399 scrollbar_controller_->DidMouseMoveNear(0); | 403 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 400 scrollbar_controller_->DidMouseDown(); | 404 scrollbar_controller_->DidMouseDown(); |
| 401 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 405 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 402 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 406 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 403 | 407 |
| 404 // Since the mouse is over the scrollbar, the queued fade must be either | 408 // Since the mouse is over the scrollbar, the queued fade must be either |
| 405 // null or cancelled. | 409 // null or cancelled. |
| 406 EXPECT_TRUE(client_.start_fade().is_null() || | 410 EXPECT_TRUE(client_.start_fade().is_null() || |
| 407 client_.start_fade().IsCancelled()); | 411 client_.start_fade().IsCancelled()); |
| 408 | 412 |
| 409 // Mouse is still near the scrollbar, releasing it shouldn't do anything. | 413 // Mouse is still near the scrollbar, releasing it shouldn't do anything. |
| 410 scrollbar_controller_->DidMouseUp(); | 414 scrollbar_controller_->DidMouseUp(); |
| 411 EXPECT_TRUE(client_.start_fade().is_null() || | 415 EXPECT_TRUE(client_.start_fade().is_null() || |
| 412 client_.start_fade().IsCancelled()); | 416 client_.start_fade().IsCancelled()); |
| 413 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 417 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 414 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 418 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 415 } | 419 } |
| 416 | 420 |
| 417 // Make sure moving near a scrollbar while it's fading out causes it to reset | 421 // Make sure moving near a scrollbar while it's fading out causes it to reset |
| 418 // the opacity and thicken. | 422 // the opacity and thicken. |
| 419 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearScrollbarWhileFading) { | 423 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 424 MoveNearScrollbarWhileFading) { |
| 420 base::TimeTicks time; | 425 base::TimeTicks time; |
| 421 time += base::TimeDelta::FromSeconds(1); | 426 time += base::TimeDelta::FromSeconds(1); |
| 422 | 427 |
| 423 scrollbar_controller_->DidScrollBegin(); | 428 scrollbar_controller_->DidScrollBegin(); |
| 424 scrollbar_controller_->DidScrollUpdate(false); | 429 scrollbar_controller_->DidScrollUpdate(false); |
| 425 scrollbar_controller_->DidScrollEnd(); | 430 scrollbar_controller_->DidScrollEnd(); |
| 426 | 431 |
| 427 // A fade animation should have been enqueued. Start it. | 432 // A fade animation should have been enqueued. Start it. |
| 428 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 433 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 429 EXPECT_FALSE(client_.start_fade().is_null()); | 434 EXPECT_FALSE(client_.start_fade().is_null()); |
| 430 client_.start_fade().Run(); | 435 client_.start_fade().Run(); |
| 431 | 436 |
| 432 scrollbar_controller_->Animate(time); | 437 scrollbar_controller_->Animate(time); |
| 433 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 438 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 434 | 439 |
| 435 // Proceed half way through the fade out animation. | 440 // Proceed half way through the fade out animation. |
| 436 time += kFadeDuration / 2; | 441 time += kFadeDuration / 2; |
| 437 scrollbar_controller_->Animate(time); | 442 scrollbar_controller_->Animate(time); |
| 438 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); | 443 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); |
| 439 | 444 |
| 440 // Now move the mouse near the scrollbar. It should reset opacity to 1 | 445 // Now move the mouse near the scrollbar. It should reset opacity to 1 |
| 441 // instantly and start animating to thick. | 446 // instantly and start animating to thick. |
| 442 scrollbar_controller_->DidMouseMoveNear(1); | 447 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1); |
| 443 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 448 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 444 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 449 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 445 scrollbar_layer_->thumb_thickness_scale_factor()); | 450 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 446 | 451 |
| 447 scrollbar_controller_->Animate(time); | 452 scrollbar_controller_->Animate(time); |
| 448 time += kThinningDuration; | 453 time += kThinningDuration; |
| 449 scrollbar_controller_->Animate(time); | 454 scrollbar_controller_->Animate(time); |
| 450 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 455 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 451 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 456 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 452 } | 457 } |
| 453 | 458 |
| 454 // Make sure we can't capture scrollbar that's completely faded out. | 459 // Make sure we can't capture scrollbar that's completely faded out. |
| 455 TEST_F(ScrollbarAnimationControllerThinningTest, TestCantCaptureWhenFaded) { | 460 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 461 TestCantCaptureWhenFaded) { |
| 456 base::TimeTicks time; | 462 base::TimeTicks time; |
| 457 time += base::TimeDelta::FromSeconds(1); | 463 time += base::TimeDelta::FromSeconds(1); |
| 458 | 464 |
| 459 scrollbar_controller_->DidScrollBegin(); | 465 scrollbar_controller_->DidScrollBegin(); |
| 460 scrollbar_controller_->DidScrollUpdate(false); | 466 scrollbar_controller_->DidScrollUpdate(false); |
| 461 scrollbar_controller_->DidScrollEnd(); | 467 scrollbar_controller_->DidScrollEnd(); |
| 462 | 468 |
| 463 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 469 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 464 EXPECT_FALSE(client_.start_fade().is_null()); | 470 EXPECT_FALSE(client_.start_fade().is_null()); |
| 465 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 471 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 466 client_.start_fade().Run(); | 472 client_.start_fade().Run(); |
| 467 scrollbar_controller_->Animate(time); | 473 scrollbar_controller_->Animate(time); |
| 468 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 474 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 469 | 475 |
| 470 // Fade the scrollbar out completely. | 476 // Fade the scrollbar out completely. |
| 471 time += kFadeDuration; | 477 time += kFadeDuration; |
| 472 scrollbar_controller_->Animate(time); | 478 scrollbar_controller_->Animate(time); |
| 473 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 479 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 474 | 480 |
| 475 // Move mouse over the scrollbar. It shouldn't thicken the scrollbar since | 481 // Move mouse over the scrollbar. It shouldn't thicken the scrollbar since |
| 476 // it's completely faded out. | 482 // it's completely faded out. |
| 477 scrollbar_controller_->DidMouseMoveNear(0); | 483 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 478 scrollbar_controller_->Animate(time); | 484 scrollbar_controller_->Animate(time); |
| 479 time += kThinningDuration; | 485 time += kThinningDuration; |
| 480 scrollbar_controller_->Animate(time); | 486 scrollbar_controller_->Animate(time); |
| 481 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 487 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 482 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 488 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 483 scrollbar_layer_->thumb_thickness_scale_factor()); | 489 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 484 | 490 |
| 485 client_.start_fade().Reset(); | 491 client_.start_fade().Reset(); |
| 486 | 492 |
| 487 // Now try to capture the scrollbar. It shouldn't do anything since it's | 493 // Now try to capture the scrollbar. It shouldn't do anything since it's |
| 488 // completely faded out. | 494 // completely faded out. |
| 489 scrollbar_controller_->DidMouseDown(); | 495 scrollbar_controller_->DidMouseDown(); |
| 490 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 496 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 491 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 497 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 492 scrollbar_layer_->thumb_thickness_scale_factor()); | 498 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 493 EXPECT_TRUE(client_.start_fade().is_null()); | 499 EXPECT_TRUE(client_.start_fade().is_null()); |
| 494 | 500 |
| 495 // Similarly, releasing the scrollbar should have no effect. | 501 // Similarly, releasing the scrollbar should have no effect. |
| 496 scrollbar_controller_->DidMouseUp(); | 502 scrollbar_controller_->DidMouseUp(); |
| 497 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 503 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 498 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 504 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 499 scrollbar_layer_->thumb_thickness_scale_factor()); | 505 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 500 EXPECT_TRUE(client_.start_fade().is_null()); | 506 EXPECT_TRUE(client_.start_fade().is_null()); |
| 501 } | 507 } |
| 502 | 508 |
| 503 // Initiate a scroll when the pointer is already near the scrollbar. It should | 509 // Initiate a scroll when the pointer is already near the scrollbar. It should |
| 504 // appear thick and remain thick. | 510 // appear thick and remain thick. |
| 505 TEST_F(ScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) { | 511 TEST_F(SingleScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) { |
| 506 base::TimeTicks time; | 512 base::TimeTicks time; |
| 507 time += base::TimeDelta::FromSeconds(1); | 513 time += base::TimeDelta::FromSeconds(1); |
| 508 | 514 |
| 509 scrollbar_controller_->DidMouseMoveNear(1); | 515 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1); |
| 510 scrollbar_controller_->Animate(time); | 516 scrollbar_controller_->Animate(time); |
| 511 time += kThinningDuration; | 517 time += kThinningDuration; |
| 512 | 518 |
| 513 // Since the scrollbar isn't visible yet (because we haven't scrolled), we | 519 // Since the scrollbar isn't visible yet (because we haven't scrolled), we |
| 514 // shouldn't have applied the thickening. | 520 // shouldn't have applied the thickening. |
| 515 scrollbar_controller_->Animate(time); | 521 scrollbar_controller_->Animate(time); |
| 516 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 522 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 517 scrollbar_layer_->thumb_thickness_scale_factor()); | 523 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 518 | 524 |
| 519 scrollbar_controller_->DidScrollBegin(); | 525 scrollbar_controller_->DidScrollBegin(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 535 | 541 |
| 536 // Scrollbar should still be thick and visible. | 542 // Scrollbar should still be thick and visible. |
| 537 time += kFadeDuration; | 543 time += kFadeDuration; |
| 538 scrollbar_controller_->Animate(time); | 544 scrollbar_controller_->Animate(time); |
| 539 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 545 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 540 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 546 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 541 } | 547 } |
| 542 | 548 |
| 543 // Move the pointer near the scrollbar. Confirm it gets thick and narrow when | 549 // Move the pointer near the scrollbar. Confirm it gets thick and narrow when |
| 544 // moved away. | 550 // moved away. |
| 545 TEST_F(ScrollbarAnimationControllerThinningTest, MouseNear) { | 551 TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseNear) { |
| 546 base::TimeTicks time; | 552 base::TimeTicks time; |
| 547 time += base::TimeDelta::FromSeconds(1); | 553 time += base::TimeDelta::FromSeconds(1); |
| 548 | 554 |
| 549 // Scroll to make the scrollbars visible. | 555 // Scroll to make the scrollbars visible. |
| 550 scrollbar_controller_->DidScrollBegin(); | 556 scrollbar_controller_->DidScrollBegin(); |
| 551 scrollbar_controller_->DidScrollUpdate(false); | 557 scrollbar_controller_->DidScrollUpdate(false); |
| 552 scrollbar_controller_->DidScrollEnd(); | 558 scrollbar_controller_->DidScrollEnd(); |
| 553 | 559 |
| 554 scrollbar_controller_->DidMouseMoveNear(1); | 560 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1); |
| 555 scrollbar_controller_->Animate(time); | 561 scrollbar_controller_->Animate(time); |
| 556 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 562 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 557 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 563 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 558 scrollbar_layer_->thumb_thickness_scale_factor()); | 564 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 559 | 565 |
| 560 // Should animate to thickened. | 566 // Should animate to thickened. |
| 561 time += kThinningDuration; | 567 time += kThinningDuration; |
| 562 scrollbar_controller_->Animate(time); | 568 scrollbar_controller_->Animate(time); |
| 563 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 569 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 564 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 570 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 565 | 571 |
| 566 // Subsequent moves within the nearness threshold should not change anything. | 572 // Subsequent moves within the nearness threshold should not change anything. |
| 567 scrollbar_controller_->DidMouseMoveNear(2); | 573 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 2); |
| 568 scrollbar_controller_->Animate(time); | 574 scrollbar_controller_->Animate(time); |
| 569 time += base::TimeDelta::FromSeconds(10); | 575 time += base::TimeDelta::FromSeconds(10); |
| 570 scrollbar_controller_->Animate(time); | 576 scrollbar_controller_->Animate(time); |
| 571 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 577 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 572 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 578 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 573 | 579 |
| 574 // Now move away from bar. | 580 // Now move away from bar. |
| 575 scrollbar_controller_->DidMouseMoveNear( | 581 scrollbar_controller_->DidMouseMoveNear( |
| 576 kDefaultMouseMoveDistanceToTriggerAnimation); | 582 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation); |
| 577 scrollbar_controller_->Animate(time); | 583 scrollbar_controller_->Animate(time); |
| 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(kIdleThicknessScale, | 587 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 582 scrollbar_layer_->thumb_thickness_scale_factor()); | 588 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 583 } | 589 } |
| 584 | 590 |
| 585 // Move the pointer over the scrollbar. Make sure it gets thick that it gets | 591 // Move the pointer over the scrollbar. Make sure it gets thick that it gets |
| 586 // thin when moved away. | 592 // thin when moved away. |
| 587 TEST_F(ScrollbarAnimationControllerThinningTest, MouseOver) { | 593 TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseOver) { |
| 588 // Scroll to make the scrollbars visible. | 594 // Scroll to make the scrollbars visible. |
| 589 scrollbar_controller_->DidScrollBegin(); | 595 scrollbar_controller_->DidScrollBegin(); |
| 590 scrollbar_controller_->DidScrollUpdate(false); | 596 scrollbar_controller_->DidScrollUpdate(false); |
| 591 scrollbar_controller_->DidScrollEnd(); | 597 scrollbar_controller_->DidScrollEnd(); |
| 592 | 598 |
| 593 base::TimeTicks time; | 599 base::TimeTicks time; |
| 594 time += base::TimeDelta::FromSeconds(1); | 600 time += base::TimeDelta::FromSeconds(1); |
| 595 | 601 |
| 596 scrollbar_controller_->DidMouseMoveNear(0); | 602 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 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(kIdleThicknessScale, | 605 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 600 scrollbar_layer_->thumb_thickness_scale_factor()); | 606 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 601 | 607 |
| 602 // Should animate to thickened. | 608 // Should animate to thickened. |
| 603 time += kThinningDuration; | 609 time += kThinningDuration; |
| 604 scrollbar_controller_->Animate(time); | 610 scrollbar_controller_->Animate(time); |
| 605 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 611 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 606 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 612 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 607 | 613 |
| 608 // Subsequent moves should not change anything. | 614 // Subsequent moves should not change anything. |
| 609 scrollbar_controller_->DidMouseMoveNear(0); | 615 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 610 scrollbar_controller_->Animate(time); | 616 scrollbar_controller_->Animate(time); |
| 611 time += base::TimeDelta::FromSeconds(10); | 617 time += base::TimeDelta::FromSeconds(10); |
| 612 scrollbar_controller_->Animate(time); | 618 scrollbar_controller_->Animate(time); |
| 613 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 619 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 614 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 620 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 615 | 621 |
| 616 // Moving off the scrollbar but still withing the "near" threshold should do | 622 // Moving off the scrollbar but still withing the "near" threshold should do |
| 617 // nothing. | 623 // nothing. |
| 618 scrollbar_controller_->DidMouseMoveNear( | 624 scrollbar_controller_->DidMouseMoveNear( |
| 619 kDefaultMouseMoveDistanceToTriggerAnimation - 1.f); | 625 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation - 1.f); |
| 620 scrollbar_controller_->Animate(time); | 626 scrollbar_controller_->Animate(time); |
| 621 time += base::TimeDelta::FromSeconds(10); | 627 time += base::TimeDelta::FromSeconds(10); |
| 622 scrollbar_controller_->Animate(time); | 628 scrollbar_controller_->Animate(time); |
| 623 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 629 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 624 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 630 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 625 | 631 |
| 626 // Now move away from bar. | 632 // Now move away from bar. |
| 627 scrollbar_controller_->DidMouseMoveNear( | 633 scrollbar_controller_->DidMouseMoveNear( |
| 628 kDefaultMouseMoveDistanceToTriggerAnimation); | 634 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation); |
| 629 scrollbar_controller_->Animate(time); | 635 scrollbar_controller_->Animate(time); |
| 630 time += kThinningDuration; | 636 time += kThinningDuration; |
| 631 scrollbar_controller_->Animate(time); | 637 scrollbar_controller_->Animate(time); |
| 632 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 638 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 633 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 639 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 634 scrollbar_layer_->thumb_thickness_scale_factor()); | 640 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 635 } | 641 } |
| 636 | 642 |
| 637 // First move the pointer over the scrollbar off of it. Make sure the thinning | 643 // First move the pointer over the scrollbar off of it. Make sure the thinning |
| 638 // animation kicked off in DidMouseMoveOffScrollbar gets overridden by the | 644 // animation kicked off in DidMouseMoveOffScrollbar gets overridden by the |
| 639 // thickening animation in the DidMouseMoveNear call. | 645 // thickening animation in the DidMouseMoveNear call. |
| 640 TEST_F(ScrollbarAnimationControllerThinningTest, | 646 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 641 MouseNearThenAwayWhileAnimating) { | 647 MouseNearThenAwayWhileAnimating) { |
| 642 // Scroll to make the scrollbars visible. | 648 // Scroll to make the scrollbars visible. |
| 643 scrollbar_controller_->DidScrollBegin(); | 649 scrollbar_controller_->DidScrollBegin(); |
| 644 scrollbar_controller_->DidScrollUpdate(false); | 650 scrollbar_controller_->DidScrollUpdate(false); |
| 645 scrollbar_controller_->DidScrollEnd(); | 651 scrollbar_controller_->DidScrollEnd(); |
| 646 | 652 |
| 647 base::TimeTicks time; | 653 base::TimeTicks time; |
| 648 time += base::TimeDelta::FromSeconds(1); | 654 time += base::TimeDelta::FromSeconds(1); |
| 649 | 655 |
| 650 scrollbar_controller_->DidMouseMoveNear(0); | 656 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 651 scrollbar_controller_->Animate(time); | 657 scrollbar_controller_->Animate(time); |
| 652 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 658 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 653 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 659 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 654 scrollbar_layer_->thumb_thickness_scale_factor()); | 660 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 655 | 661 |
| 656 // Should animate to thickened. | 662 // Should animate to thickened. |
| 657 time += kThinningDuration; | 663 time += kThinningDuration; |
| 658 scrollbar_controller_->Animate(time); | 664 scrollbar_controller_->Animate(time); |
| 659 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 665 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 660 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 666 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 661 | 667 |
| 662 // This is tricky. The DidMouseLeave() is sent before the | 668 // This is tricky. The DidMouseLeave() is sent before the |
| 663 // subsequent DidMouseMoveNear(), if the mouse moves in that direction. | 669 // subsequent DidMouseMoveNear(), if the mouse moves in that direction. |
| 664 // This results in the thumb thinning. We want to make sure that when the | 670 // This results in the thumb thinning. We want to make sure that when the |
| 665 // thumb starts expanding it doesn't first narrow to the idle thinness. | 671 // thumb starts expanding it doesn't first narrow to the idle thinness. |
| 666 time += base::TimeDelta::FromSeconds(1); | 672 time += base::TimeDelta::FromSeconds(1); |
| 667 scrollbar_controller_->DidMouseLeave(); | 673 scrollbar_controller_->DidMouseLeave(); |
| 668 scrollbar_controller_->Animate(time); | 674 scrollbar_controller_->Animate(time); |
| 669 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 675 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 670 | 676 |
| 671 // Let the animation run half of the way through the thinning animation. | 677 // Let the animation run half of the way through the thinning animation. |
| 672 time += kThinningDuration / 2; | 678 time += kThinningDuration / 2; |
| 673 scrollbar_controller_->Animate(time); | 679 scrollbar_controller_->Animate(time); |
| 674 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, | 680 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, |
| 675 scrollbar_layer_->thumb_thickness_scale_factor()); | 681 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 676 | 682 |
| 677 // Now we get a notification for the mouse moving over the scroller. The | 683 // Now we get a notification for the mouse moving over the scroller. The |
| 678 // animation is reset to the thickening direction but we won't start | 684 // animation is reset to the thickening direction but we won't start |
| 679 // thickening until the new animation catches up to the current thickness. | 685 // thickening until the new animation catches up to the current thickness. |
| 680 scrollbar_controller_->DidMouseMoveNear(1); | 686 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1); |
| 681 scrollbar_controller_->Animate(time); | 687 scrollbar_controller_->Animate(time); |
| 682 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, | 688 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, |
| 683 scrollbar_layer_->thumb_thickness_scale_factor()); | 689 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 684 | 690 |
| 685 // Until we reach the half way point, the animation will have no effect. | 691 // Until we reach the half way point, the animation will have no effect. |
| 686 time += kThinningDuration / 4; | 692 time += kThinningDuration / 4; |
| 687 scrollbar_controller_->Animate(time); | 693 scrollbar_controller_->Animate(time); |
| 688 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, | 694 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, |
| 689 scrollbar_layer_->thumb_thickness_scale_factor()); | 695 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 690 | 696 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 702 | 708 |
| 703 // And all the way to the end. | 709 // And all the way to the end. |
| 704 time += kThinningDuration / 4; | 710 time += kThinningDuration / 4; |
| 705 scrollbar_controller_->Animate(time); | 711 scrollbar_controller_->Animate(time); |
| 706 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 712 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 707 } | 713 } |
| 708 | 714 |
| 709 // First move the pointer on the scrollbar, then press it, then away. | 715 // First move the pointer on the scrollbar, then press it, then away. |
| 710 // Confirm that the bar gets thick. Then mouse up. Confirm that | 716 // Confirm that the bar gets thick. Then mouse up. Confirm that |
| 711 // the bar gets thin. | 717 // the bar gets thin. |
| 712 TEST_F(ScrollbarAnimationControllerThinningTest, | 718 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 713 MouseCaptureAndReleaseOutOfBar) { | 719 MouseCaptureAndReleaseOutOfBar) { |
| 714 // Scroll to make the scrollbars visible. | 720 // Scroll to make the scrollbars visible. |
| 715 scrollbar_controller_->DidScrollBegin(); | 721 scrollbar_controller_->DidScrollBegin(); |
| 716 scrollbar_controller_->DidScrollUpdate(false); | 722 scrollbar_controller_->DidScrollUpdate(false); |
| 717 scrollbar_controller_->DidScrollEnd(); | 723 scrollbar_controller_->DidScrollEnd(); |
| 718 | 724 |
| 719 base::TimeTicks time; | 725 base::TimeTicks time; |
| 720 time += base::TimeDelta::FromSeconds(1); | 726 time += base::TimeDelta::FromSeconds(1); |
| 721 | 727 |
| 722 // Move over the scrollbar. | 728 // Move over the scrollbar. |
| 723 scrollbar_controller_->DidMouseMoveNear(0); | 729 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 724 scrollbar_controller_->Animate(time); | 730 scrollbar_controller_->Animate(time); |
| 725 time += kFadeDuration; | 731 time += kFadeDuration; |
| 726 scrollbar_controller_->Animate(time); | 732 scrollbar_controller_->Animate(time); |
| 727 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 733 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 728 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 734 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 729 | 735 |
| 730 // Capture | 736 // Capture |
| 731 scrollbar_controller_->DidMouseDown(); | 737 scrollbar_controller_->DidMouseDown(); |
| 732 time += base::TimeDelta::FromSeconds(1); | 738 time += base::TimeDelta::FromSeconds(1); |
| 733 scrollbar_controller_->Animate(time); | 739 scrollbar_controller_->Animate(time); |
| 734 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 740 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 735 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 741 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 736 | 742 |
| 737 // Should stay thick for a while. | 743 // Should stay thick for a while. |
| 738 time += base::TimeDelta::FromSeconds(10); | 744 time += base::TimeDelta::FromSeconds(10); |
| 739 scrollbar_controller_->Animate(time); | 745 scrollbar_controller_->Animate(time); |
| 740 | 746 |
| 741 // Move outside the "near" threshold. Because the scrollbar is captured it | 747 // Move outside the "near" threshold. Because the scrollbar is captured it |
| 742 // should remain thick. | 748 // should remain thick. |
| 743 scrollbar_controller_->DidMouseMoveNear( | 749 scrollbar_controller_->DidMouseMoveNear( |
| 744 kDefaultMouseMoveDistanceToTriggerAnimation); | 750 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation); |
| 745 time += kThinningDuration; | 751 time += kThinningDuration; |
| 746 scrollbar_controller_->Animate(time); | 752 scrollbar_controller_->Animate(time); |
| 747 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 753 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 748 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 754 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 749 | 755 |
| 750 // Release. | 756 // Release. |
| 751 scrollbar_controller_->DidMouseUp(); | 757 scrollbar_controller_->DidMouseUp(); |
| 752 | 758 |
| 753 // Should become thin. | 759 // Should become thin. |
| 754 time += base::TimeDelta::FromSeconds(1); | 760 time += base::TimeDelta::FromSeconds(1); |
| 755 scrollbar_controller_->Animate(time); | 761 scrollbar_controller_->Animate(time); |
| 756 time += kThinningDuration; | 762 time += kThinningDuration; |
| 757 scrollbar_controller_->Animate(time); | 763 scrollbar_controller_->Animate(time); |
| 758 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 764 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 759 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 765 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 760 scrollbar_layer_->thumb_thickness_scale_factor()); | 766 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 761 } | 767 } |
| 762 | 768 |
| 763 // First move the pointer on the scrollbar, then press it, then away. Confirm | 769 // First move the pointer on the scrollbar, then press it, then away. Confirm |
| 764 // that the bar gets thick. Then move point on the scrollbar and mouse up. | 770 // that the bar gets thick. Then move point on the scrollbar and mouse up. |
| 765 // Confirm that the bar stays thick. | 771 // Confirm that the bar stays thick. |
| 766 TEST_F(ScrollbarAnimationControllerThinningTest, MouseCaptureAndReleaseOnBar) { | 772 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 773 MouseCaptureAndReleaseOnBar) { |
| 767 // Scroll to make the scrollbars visible. | 774 // Scroll to make the scrollbars visible. |
| 768 scrollbar_controller_->DidScrollBegin(); | 775 scrollbar_controller_->DidScrollBegin(); |
| 769 scrollbar_controller_->DidScrollUpdate(false); | 776 scrollbar_controller_->DidScrollUpdate(false); |
| 770 scrollbar_controller_->DidScrollEnd(); | 777 scrollbar_controller_->DidScrollEnd(); |
| 771 | 778 |
| 772 base::TimeTicks time; | 779 base::TimeTicks time; |
| 773 time += base::TimeDelta::FromSeconds(1); | 780 time += base::TimeDelta::FromSeconds(1); |
| 774 | 781 |
| 775 // Move over scrollbar. | 782 // Move over scrollbar. |
| 776 scrollbar_controller_->DidMouseMoveNear(0); | 783 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 777 scrollbar_controller_->Animate(time); | 784 scrollbar_controller_->Animate(time); |
| 778 time += kThinningDuration; | 785 time += kThinningDuration; |
| 779 scrollbar_controller_->Animate(time); | 786 scrollbar_controller_->Animate(time); |
| 780 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 787 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 781 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 788 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 782 | 789 |
| 783 // Capture. Nothing should change. | 790 // Capture. Nothing should change. |
| 784 scrollbar_controller_->DidMouseDown(); | 791 scrollbar_controller_->DidMouseDown(); |
| 785 time += base::TimeDelta::FromSeconds(1); | 792 time += base::TimeDelta::FromSeconds(1); |
| 786 scrollbar_controller_->Animate(time); | 793 scrollbar_controller_->Animate(time); |
| 787 time += base::TimeDelta::FromSeconds(10); | 794 time += base::TimeDelta::FromSeconds(10); |
| 788 scrollbar_controller_->Animate(time); | 795 scrollbar_controller_->Animate(time); |
| 789 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 796 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 790 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 797 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 791 | 798 |
| 792 // Move away from scrollbar. Nothing should change. | 799 // Move away from scrollbar. Nothing should change. |
| 793 scrollbar_controller_->DidMouseMoveNear( | 800 scrollbar_controller_->DidMouseMoveNear( |
| 794 kDefaultMouseMoveDistanceToTriggerAnimation); | 801 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation); |
| 795 time += base::TimeDelta::FromSeconds(1); | 802 time += base::TimeDelta::FromSeconds(1); |
| 796 scrollbar_controller_->Animate(time); | 803 scrollbar_controller_->Animate(time); |
| 797 time += base::TimeDelta::FromSeconds(10); | 804 time += base::TimeDelta::FromSeconds(10); |
| 798 scrollbar_controller_->Animate(time); | 805 scrollbar_controller_->Animate(time); |
| 799 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 806 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 800 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 807 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 801 | 808 |
| 802 // Move over scrollbar and release. Since we're near the scrollbar, it should | 809 // Move over scrollbar and release. Since we're near the scrollbar, it should |
| 803 // remain thick. | 810 // remain thick. |
| 804 scrollbar_controller_->DidMouseMoveNear(0); | 811 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 805 scrollbar_controller_->DidMouseUp(); | 812 scrollbar_controller_->DidMouseUp(); |
| 806 time += base::TimeDelta::FromSeconds(1); | 813 time += base::TimeDelta::FromSeconds(1); |
| 807 scrollbar_controller_->Animate(time); | 814 scrollbar_controller_->Animate(time); |
| 808 time += base::TimeDelta::FromSeconds(10); | 815 time += base::TimeDelta::FromSeconds(10); |
| 809 scrollbar_controller_->Animate(time); | 816 scrollbar_controller_->Animate(time); |
| 810 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 817 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 811 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 818 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 812 } | 819 } |
| 813 | 820 |
| 814 // Move mouse on scrollbar and capture then move out of window. Confirm that | 821 // Move mouse on scrollbar and capture then move out of window. Confirm that |
| 815 // the bar stays thick. | 822 // the bar stays thick. |
| 816 TEST_F(ScrollbarAnimationControllerThinningTest, | 823 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 817 MouseCapturedAndExitWindowFromScrollbar) { | 824 MouseCapturedAndExitWindowFromScrollbar) { |
| 818 // Scroll to make the scrollbars visible. | 825 // Scroll to make the scrollbars visible. |
| 819 scrollbar_controller_->DidScrollBegin(); | 826 scrollbar_controller_->DidScrollBegin(); |
| 820 scrollbar_controller_->DidScrollUpdate(false); | 827 scrollbar_controller_->DidScrollUpdate(false); |
| 821 scrollbar_controller_->DidScrollEnd(); | 828 scrollbar_controller_->DidScrollEnd(); |
| 822 | 829 |
| 823 base::TimeTicks time; | 830 base::TimeTicks time; |
| 824 time += base::TimeDelta::FromSeconds(1); | 831 time += base::TimeDelta::FromSeconds(1); |
| 825 | 832 |
| 826 // Move mouse over scrollbar. | 833 // Move mouse over scrollbar. |
| 827 scrollbar_controller_->DidMouseMoveNear(0); | 834 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 0); |
| 828 scrollbar_controller_->Animate(time); | 835 scrollbar_controller_->Animate(time); |
| 829 time += kThinningDuration; | 836 time += kThinningDuration; |
| 830 scrollbar_controller_->Animate(time); | 837 scrollbar_controller_->Animate(time); |
| 831 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 838 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 832 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 839 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 833 | 840 |
| 834 // Capture. | 841 // Capture. |
| 835 scrollbar_controller_->DidMouseDown(); | 842 scrollbar_controller_->DidMouseDown(); |
| 836 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 843 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 837 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 844 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 838 | 845 |
| 839 // Move out of window. Since the scrollbar is capture, it shouldn't change in | 846 // Move out of window. Since the scrollbar is capture, it shouldn't change in |
| 840 // any way. | 847 // any way. |
| 841 scrollbar_controller_->DidMouseLeave(); | 848 scrollbar_controller_->DidMouseLeave(); |
| 842 scrollbar_controller_->Animate(time); | 849 scrollbar_controller_->Animate(time); |
| 843 time += kThinningDuration; | 850 time += kThinningDuration; |
| 844 scrollbar_controller_->Animate(time); | 851 scrollbar_controller_->Animate(time); |
| 845 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 852 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 846 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 853 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 847 } | 854 } |
| 848 | 855 |
| 849 // Tests that the thickening/thinning effects are animated. | 856 // Tests that the thickening/thinning effects are animated. |
| 850 TEST_F(ScrollbarAnimationControllerThinningTest, ThicknessAnimated) { | 857 TEST_F(SingleScrollbarAnimationControllerThinningTest, ThicknessAnimated) { |
| 851 // Scroll to make the scrollbars visible. | 858 // Scroll to make the scrollbars visible. |
| 852 scrollbar_controller_->DidScrollBegin(); | 859 scrollbar_controller_->DidScrollBegin(); |
| 853 scrollbar_controller_->DidScrollUpdate(false); | 860 scrollbar_controller_->DidScrollUpdate(false); |
| 854 scrollbar_controller_->DidScrollEnd(); | 861 scrollbar_controller_->DidScrollEnd(); |
| 855 | 862 |
| 856 base::TimeTicks time; | 863 base::TimeTicks time; |
| 857 time += base::TimeDelta::FromSeconds(1); | 864 time += base::TimeDelta::FromSeconds(1); |
| 858 | 865 |
| 859 // Move mouse near scrollbar. Test that at half the duration time, the | 866 // Move mouse near scrollbar. Test that at half the duration time, the |
| 860 // thickness is half way through its animation. | 867 // thickness is half way through its animation. |
| 861 scrollbar_controller_->DidMouseMoveNear(1); | 868 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1); |
| 862 scrollbar_controller_->Animate(time); | 869 scrollbar_controller_->Animate(time); |
| 863 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 870 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 864 scrollbar_layer_->thumb_thickness_scale_factor()); | 871 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 865 | 872 |
| 866 time += kThinningDuration / 2; | 873 time += kThinningDuration / 2; |
| 867 scrollbar_controller_->Animate(time); | 874 scrollbar_controller_->Animate(time); |
| 868 EXPECT_FLOAT_EQ(kIdleThicknessScale + (1.0f - kIdleThicknessScale) / 2.0f, | 875 EXPECT_FLOAT_EQ(kIdleThicknessScale + (1.0f - kIdleThicknessScale) / 2.0f, |
| 869 scrollbar_layer_->thumb_thickness_scale_factor()); | 876 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 870 | 877 |
| 871 time += kThinningDuration / 2; | 878 time += kThinningDuration / 2; |
| 872 scrollbar_controller_->Animate(time); | 879 scrollbar_controller_->Animate(time); |
| 873 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 880 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 874 | 881 |
| 875 // Move mouse away from scrollbar. Same check. | 882 // Move mouse away from scrollbar. Same check. |
| 876 time += base::TimeDelta::FromSeconds(1); | 883 time += base::TimeDelta::FromSeconds(1); |
| 877 scrollbar_controller_->DidMouseMoveNear( | 884 scrollbar_controller_->DidMouseMoveNear( |
| 878 kDefaultMouseMoveDistanceToTriggerAnimation); | 885 HORIZONTAL, kDefaultMouseMoveDistanceToTriggerAnimation); |
| 879 scrollbar_controller_->Animate(time); | 886 scrollbar_controller_->Animate(time); |
| 880 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 887 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 881 | 888 |
| 882 time += kThinningDuration / 2; | 889 time += kThinningDuration / 2; |
| 883 scrollbar_controller_->Animate(time); | 890 scrollbar_controller_->Animate(time); |
| 884 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, | 891 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, |
| 885 scrollbar_layer_->thumb_thickness_scale_factor()); | 892 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 886 | 893 |
| 887 time += kThinningDuration / 2; | 894 time += kThinningDuration / 2; |
| 888 scrollbar_controller_->Animate(time); | 895 scrollbar_controller_->Animate(time); |
| 889 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 896 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 890 scrollbar_layer_->thumb_thickness_scale_factor()); | 897 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 891 } | 898 } |
| 892 | 899 |
| 893 // Tests that main thread scroll updates immediatley queue a fade animation | 900 // Tests that main thread scroll updates immediatley queue a fade animation |
| 894 // without requiring a ScrollEnd. | 901 // without requiring a ScrollEnd. |
| 895 TEST_F(ScrollbarAnimationControllerThinningTest, MainThreadScrollQueuesFade) { | 902 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 903 MainThreadScrollQueuesFade) { |
| 896 ASSERT_TRUE(client_.start_fade().is_null()); | 904 ASSERT_TRUE(client_.start_fade().is_null()); |
| 897 | 905 |
| 898 // A ScrollUpdate without a ScrollBegin indicates a main thread scroll update | 906 // A ScrollUpdate without a ScrollBegin indicates a main thread scroll update |
| 899 // so we should schedule a fade animation without waiting for a ScrollEnd | 907 // so we should schedule a fade animation without waiting for a ScrollEnd |
| 900 // (which will never come). | 908 // (which will never come). |
| 901 scrollbar_controller_->DidScrollUpdate(false); | 909 scrollbar_controller_->DidScrollUpdate(false); |
| 902 EXPECT_FALSE(client_.start_fade().is_null()); | 910 EXPECT_FALSE(client_.start_fade().is_null()); |
| 903 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 911 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 904 | 912 |
| 905 client_.start_fade().Reset(); | 913 client_.start_fade().Reset(); |
| 906 | 914 |
| 907 // If we got a ScrollBegin, we shouldn't schedule the fade animation until we | 915 // If we got a ScrollBegin, we shouldn't schedule the fade animation until we |
| 908 // get a corresponding ScrollEnd. | 916 // get a corresponding ScrollEnd. |
| 909 scrollbar_controller_->DidScrollBegin(); | 917 scrollbar_controller_->DidScrollBegin(); |
| 910 scrollbar_controller_->DidScrollUpdate(false); | 918 scrollbar_controller_->DidScrollUpdate(false); |
| 911 EXPECT_TRUE(client_.start_fade().is_null()); | 919 EXPECT_TRUE(client_.start_fade().is_null()); |
| 912 scrollbar_controller_->DidScrollEnd(); | 920 scrollbar_controller_->DidScrollEnd(); |
| 913 EXPECT_FALSE(client_.start_fade().is_null()); | 921 EXPECT_FALSE(client_.start_fade().is_null()); |
| 914 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 922 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 915 } | 923 } |
| 916 | 924 |
| 917 // Make sure that if the scroll update is as a result of a resize, we use the | 925 // Make sure that if the scroll update is as a result of a resize, we use the |
| 918 // resize delay time instead of the default one. | 926 // resize delay time instead of the default one. |
| 919 TEST_F(ScrollbarAnimationControllerThinningTest, ResizeFadeDuration) { | 927 TEST_F(SingleScrollbarAnimationControllerThinningTest, ResizeFadeDuration) { |
| 920 ASSERT_TRUE(client_.delay().is_zero()); | 928 ASSERT_TRUE(client_.delay().is_zero()); |
| 921 | 929 |
| 922 scrollbar_controller_->DidScrollUpdate(true); | 930 scrollbar_controller_->DidScrollUpdate(true); |
| 923 EXPECT_FALSE(client_.start_fade().is_null()); | 931 EXPECT_FALSE(client_.start_fade().is_null()); |
| 924 EXPECT_EQ(kResizeDelayBeforeStarting, client_.delay()); | 932 EXPECT_EQ(kResizeDelayBeforeStarting, client_.delay()); |
| 925 | 933 |
| 926 client_.delay() = base::TimeDelta(); | 934 client_.delay() = base::TimeDelta(); |
| 927 | 935 |
| 928 // We should use the gesture delay rather than the resize delay if we're in a | 936 // We should use the gesture delay rather than the resize delay if we're in a |
| 929 // gesture scroll, even if the resize param is set. | 937 // gesture scroll, even if the resize param is set. |
| 930 scrollbar_controller_->DidScrollBegin(); | 938 scrollbar_controller_->DidScrollBegin(); |
| 931 scrollbar_controller_->DidScrollUpdate(true); | 939 scrollbar_controller_->DidScrollUpdate(true); |
| 932 scrollbar_controller_->DidScrollEnd(); | 940 scrollbar_controller_->DidScrollEnd(); |
| 933 | 941 |
| 934 EXPECT_FALSE(client_.start_fade().is_null()); | 942 EXPECT_FALSE(client_.start_fade().is_null()); |
| 935 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 943 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 936 } | 944 } |
| 937 | 945 |
| 938 // Tests that the fade effect is animated. | 946 // Tests that the fade effect is animated. |
| 939 TEST_F(ScrollbarAnimationControllerThinningTest, FadeAnimated) { | 947 TEST_F(SingleScrollbarAnimationControllerThinningTest, FadeAnimated) { |
| 940 // Scroll to make the scrollbars visible. | 948 // Scroll to make the scrollbars visible. |
| 941 scrollbar_controller_->DidScrollBegin(); | 949 scrollbar_controller_->DidScrollBegin(); |
| 942 scrollbar_controller_->DidScrollUpdate(false); | 950 scrollbar_controller_->DidScrollUpdate(false); |
| 943 scrollbar_controller_->DidScrollEnd(); | 951 scrollbar_controller_->DidScrollEnd(); |
| 944 | 952 |
| 945 // Appearance is instant. | 953 // Appearance is instant. |
| 946 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 954 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 947 | 955 |
| 948 // An animation should have been enqueued. | 956 // An animation should have been enqueued. |
| 949 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 957 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 960 time += kFadeDuration / 2; | 968 time += kFadeDuration / 2; |
| 961 scrollbar_controller_->Animate(time); | 969 scrollbar_controller_->Animate(time); |
| 962 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); | 970 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); |
| 963 | 971 |
| 964 time += kFadeDuration / 2; | 972 time += kFadeDuration / 2; |
| 965 scrollbar_controller_->Animate(time); | 973 scrollbar_controller_->Animate(time); |
| 966 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 974 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 967 } | 975 } |
| 968 | 976 |
| 969 // Tests that the controller tells the client when the scrollbars hide/show. | 977 // Tests that the controller tells the client when the scrollbars hide/show. |
| 970 TEST_F(ScrollbarAnimationControllerThinningTest, NotifyChangedVisibility) { | 978 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 979 NotifyChangedVisibility) { |
| 971 base::TimeTicks time; | 980 base::TimeTicks time; |
| 972 time += base::TimeDelta::FromSeconds(1); | 981 time += base::TimeDelta::FromSeconds(1); |
| 973 | 982 |
| 974 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); | 983 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); |
| 975 // Scroll to make the scrollbars visible. | 984 // Scroll to make the scrollbars visible. |
| 976 scrollbar_controller_->DidScrollBegin(); | 985 scrollbar_controller_->DidScrollBegin(); |
| 977 scrollbar_controller_->DidScrollUpdate(false); | 986 scrollbar_controller_->DidScrollUpdate(false); |
| 978 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); | 987 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); |
| 979 Mock::VerifyAndClearExpectations(&client_); | 988 Mock::VerifyAndClearExpectations(&client_); |
| 980 | 989 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1009 // Calling DidScrollUpdate without a begin (i.e. update from commit) should | 1018 // Calling DidScrollUpdate without a begin (i.e. update from commit) should |
| 1010 // also notify. | 1019 // also notify. |
| 1011 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); | 1020 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); |
| 1012 scrollbar_controller_->DidScrollUpdate(false); | 1021 scrollbar_controller_->DidScrollUpdate(false); |
| 1013 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); | 1022 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); |
| 1014 Mock::VerifyAndClearExpectations(&client_); | 1023 Mock::VerifyAndClearExpectations(&client_); |
| 1015 } | 1024 } |
| 1016 | 1025 |
| 1017 } // namespace | 1026 } // namespace |
| 1018 } // namespace cc | 1027 } // namespace cc |
| OLD | NEW |