| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/input/scrollbar_animation_controller_thinning.h" | 5 #include "cc/input/scrollbar_animation_controller.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 const float kIdleThicknessScale = |
| 25 // scrollbar_animation_controller_thinning.cc. | 25 SingleScrollbarAnimationControllerThinning::kIdleThicknessScale; |
| 26 const float kIdleThicknessScale = 0.4f; | 26 const float kDefaultMouseMoveDistanceToTriggerAnimation = |
| 27 const float kDefaultMouseMoveDistanceToTriggerAnimation = 25.f; | 27 SingleScrollbarAnimationControllerThinning:: |
| 28 kDefaultMouseMoveDistanceToTriggerAnimation; |
| 28 | 29 |
| 29 class MockScrollbarAnimationControllerClient | 30 class MockScrollbarAnimationControllerClient |
| 30 : public ScrollbarAnimationControllerClient { | 31 : public ScrollbarAnimationControllerClient { |
| 31 public: | 32 public: |
| 32 explicit MockScrollbarAnimationControllerClient(LayerTreeHostImpl* host_impl) | 33 explicit MockScrollbarAnimationControllerClient(LayerTreeHostImpl* host_impl) |
| 33 : host_impl_(host_impl) {} | 34 : host_impl_(host_impl) {} |
| 34 virtual ~MockScrollbarAnimationControllerClient() {} | 35 virtual ~MockScrollbarAnimationControllerClient() {} |
| 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 ScrollbarAnimationControllerAuraOverlayTest : public testing::Test { |
| 58 public: | 59 public: |
| 59 ScrollbarAnimationControllerThinningTest() | 60 ScrollbarAnimationControllerAuraOverlayTest() |
| 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 void ExpectScrollbarsOpacity(float opacity) { | 64 void ExpectScrollbarsOpacity(float opacity) { |
| 64 EXPECT_FLOAT_EQ(opacity, v_scrollbar_layer_->Opacity()); | 65 EXPECT_FLOAT_EQ(opacity, v_scrollbar_layer_->Opacity()); |
| 65 EXPECT_FLOAT_EQ(opacity, h_scrollbar_layer_->Opacity()); | 66 EXPECT_FLOAT_EQ(opacity, h_scrollbar_layer_->Opacity()); |
| 66 } | 67 } |
| 67 | 68 |
| 68 protected: | 69 protected: |
| 69 const base::TimeDelta kDelayBeforeStarting = base::TimeDelta::FromSeconds(2); | 70 const base::TimeDelta kDelayBeforeStarting = base::TimeDelta::FromSeconds(2); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); | 104 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); |
| 104 | 105 |
| 105 v_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); | 106 v_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); |
| 106 h_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); | 107 h_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); |
| 107 v_scrollbar_layer_->test_properties()->opacity_can_animate = true; | 108 v_scrollbar_layer_->test_properties()->opacity_can_animate = true; |
| 108 h_scrollbar_layer_->test_properties()->opacity_can_animate = true; | 109 h_scrollbar_layer_->test_properties()->opacity_can_animate = true; |
| 109 clip_layer_->SetBounds(gfx::Size(100, 100)); | 110 clip_layer_->SetBounds(gfx::Size(100, 100)); |
| 110 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); | 111 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
| 111 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); | 112 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 112 | 113 |
| 113 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( | 114 scrollbar_controller_ = ScrollbarAnimationController:: |
| 114 scroll_layer_ptr->id(), &client_, kDelayBeforeStarting, | 115 CreateScrollbarAnimationControllerAuraOverlay( |
| 115 kResizeDelayBeforeStarting, kFadeDuration, kThinningDuration); | 116 scroll_layer_ptr->id(), &client_, kDelayBeforeStarting, |
| 117 kResizeDelayBeforeStarting, kFadeDuration, kThinningDuration); |
| 116 } | 118 } |
| 117 | 119 |
| 118 FakeImplTaskRunnerProvider task_runner_provider_; | 120 FakeImplTaskRunnerProvider task_runner_provider_; |
| 119 TestTaskGraphRunner task_graph_runner_; | 121 TestTaskGraphRunner task_graph_runner_; |
| 120 FakeLayerTreeHostImpl host_impl_; | 122 FakeLayerTreeHostImpl host_impl_; |
| 121 std::unique_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; | 123 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; |
| 122 LayerImpl* clip_layer_; | 124 LayerImpl* clip_layer_; |
| 123 SolidColorScrollbarLayerImpl* v_scrollbar_layer_; | 125 SolidColorScrollbarLayerImpl* v_scrollbar_layer_; |
| 124 SolidColorScrollbarLayerImpl* h_scrollbar_layer_; | 126 SolidColorScrollbarLayerImpl* h_scrollbar_layer_; |
| 125 NiceMock<MockScrollbarAnimationControllerClient> client_; | 127 NiceMock<MockScrollbarAnimationControllerClient> client_; |
| 126 }; | 128 }; |
| 127 | 129 |
| 128 // Check initialization of scrollbar. Should start off invisible and thin. | 130 // Check initialization of scrollbar. Should start off invisible and thin. |
| 129 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) { | 131 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, Idle) { |
| 130 ExpectScrollbarsOpacity(0); | 132 ExpectScrollbarsOpacity(0); |
| 131 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); | 133 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); |
| 132 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 134 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 133 v_scrollbar_layer_->thumb_thickness_scale_factor()); | 135 v_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 134 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 136 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 135 v_scrollbar_layer_->thumb_thickness_scale_factor()); | 137 v_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 136 } | 138 } |
| 137 | 139 |
| 138 // Check that scrollbar appears again when the layer becomes scrollable. | 140 // Check that scrollbar appears again when the layer becomes scrollable. |
| 139 TEST_F(ScrollbarAnimationControllerThinningTest, AppearOnResize) { | 141 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, AppearOnResize) { |
| 140 base::TimeTicks time; | 142 base::TimeTicks time; |
| 141 time += base::TimeDelta::FromSeconds(1); | 143 time += base::TimeDelta::FromSeconds(1); |
| 142 | 144 |
| 143 scrollbar_controller_->DidScrollBegin(); | 145 scrollbar_controller_->DidScrollBegin(); |
| 144 scrollbar_controller_->DidScrollUpdate(false); | 146 scrollbar_controller_->DidScrollUpdate(false); |
| 145 scrollbar_controller_->DidScrollEnd(); | 147 scrollbar_controller_->DidScrollEnd(); |
| 146 ExpectScrollbarsOpacity(1); | 148 ExpectScrollbarsOpacity(1); |
| 147 | 149 |
| 148 // Make the Layer non-scrollable, scrollbar disappears. | 150 // Make the Layer non-scrollable, scrollbar disappears. |
| 149 clip_layer_->SetBounds(gfx::Size(200, 200)); | 151 clip_layer_->SetBounds(gfx::Size(200, 200)); |
| 150 scrollbar_controller_->DidScrollUpdate(false); | 152 scrollbar_controller_->DidScrollUpdate(false); |
| 151 ExpectScrollbarsOpacity(0); | 153 ExpectScrollbarsOpacity(0); |
| 152 | 154 |
| 153 // Make the layer scrollable, scrollbar appears again. | 155 // Make the layer scrollable, scrollbar appears again. |
| 154 clip_layer_->SetBounds(gfx::Size(100, 100)); | 156 clip_layer_->SetBounds(gfx::Size(100, 100)); |
| 155 scrollbar_controller_->DidScrollUpdate(false); | 157 scrollbar_controller_->DidScrollUpdate(false); |
| 156 ExpectScrollbarsOpacity(1); | 158 ExpectScrollbarsOpacity(1); |
| 157 } | 159 } |
| 158 | 160 |
| 159 // Check that scrollbar disappears when the layer becomes non-scrollable. | 161 // Check that scrollbar disappears when the layer becomes non-scrollable. |
| 160 TEST_F(ScrollbarAnimationControllerThinningTest, HideOnResize) { | 162 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, HideOnResize) { |
| 161 base::TimeTicks time; | 163 base::TimeTicks time; |
| 162 time += base::TimeDelta::FromSeconds(1); | 164 time += base::TimeDelta::FromSeconds(1); |
| 163 | 165 |
| 164 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); | 166 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); |
| 165 ASSERT_TRUE(scroll_layer); | 167 ASSERT_TRUE(scroll_layer); |
| 166 EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds()); | 168 EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds()); |
| 167 | 169 |
| 168 // Shrink along X axis, horizontal scrollbar should appear. | 170 // Shrink along X axis, horizontal scrollbar should appear. |
| 169 clip_layer_->SetBounds(gfx::Size(100, 200)); | 171 clip_layer_->SetBounds(gfx::Size(100, 200)); |
| 170 EXPECT_EQ(gfx::Size(100, 200), clip_layer_->bounds()); | 172 EXPECT_EQ(gfx::Size(100, 200), clip_layer_->bounds()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 183 | 185 |
| 184 scrollbar_controller_->DidScrollBegin(); | 186 scrollbar_controller_->DidScrollBegin(); |
| 185 | 187 |
| 186 scrollbar_controller_->DidScrollUpdate(false); | 188 scrollbar_controller_->DidScrollUpdate(false); |
| 187 EXPECT_FLOAT_EQ(0.0f, h_scrollbar_layer_->Opacity()); | 189 EXPECT_FLOAT_EQ(0.0f, h_scrollbar_layer_->Opacity()); |
| 188 | 190 |
| 189 scrollbar_controller_->DidScrollEnd(); | 191 scrollbar_controller_->DidScrollEnd(); |
| 190 } | 192 } |
| 191 | 193 |
| 192 // Scroll content. Confirm the scrollbar appears and fades out. | 194 // Scroll content. Confirm the scrollbar appears and fades out. |
| 193 TEST_F(ScrollbarAnimationControllerThinningTest, BasicAppearAndFadeOut) { | 195 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, BasicAppearAndFadeOut) { |
| 194 base::TimeTicks time; | 196 base::TimeTicks time; |
| 195 time += base::TimeDelta::FromSeconds(1); | 197 time += base::TimeDelta::FromSeconds(1); |
| 196 | 198 |
| 197 // Scrollbar should be invisible. | 199 // Scrollbar should be invisible. |
| 198 ExpectScrollbarsOpacity(0); | 200 ExpectScrollbarsOpacity(0); |
| 199 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); | 201 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); |
| 200 | 202 |
| 201 // Scrollbar should appear only on scroll update. | 203 // Scrollbar should appear only on scroll update. |
| 202 scrollbar_controller_->DidScrollBegin(); | 204 scrollbar_controller_->DidScrollBegin(); |
| 203 ExpectScrollbarsOpacity(0); | 205 ExpectScrollbarsOpacity(0); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 220 scrollbar_controller_->Animate(time); | 222 scrollbar_controller_->Animate(time); |
| 221 time += kFadeDuration; | 223 time += kFadeDuration; |
| 222 scrollbar_controller_->Animate(time); | 224 scrollbar_controller_->Animate(time); |
| 223 | 225 |
| 224 ExpectScrollbarsOpacity(0); | 226 ExpectScrollbarsOpacity(0); |
| 225 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); | 227 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); |
| 226 } | 228 } |
| 227 | 229 |
| 228 // Scroll content. Move the mouse near the scrollbar and confirm it becomes | 230 // Scroll content. Move the mouse near the scrollbar and confirm it becomes |
| 229 // thick. Ensure it remains visible as long as the mouse is near the scrollbar. | 231 // thick. Ensure it remains visible as long as the mouse is near the scrollbar. |
| 230 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearAndDontFadeOut) { | 232 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveNearAndDontFadeOut) { |
| 231 base::TimeTicks time; | 233 base::TimeTicks time; |
| 232 time += base::TimeDelta::FromSeconds(1); | 234 time += base::TimeDelta::FromSeconds(1); |
| 233 | 235 |
| 234 scrollbar_controller_->DidScrollBegin(); | 236 scrollbar_controller_->DidScrollBegin(); |
| 235 scrollbar_controller_->DidScrollUpdate(false); | 237 scrollbar_controller_->DidScrollUpdate(false); |
| 236 scrollbar_controller_->DidScrollEnd(); | 238 scrollbar_controller_->DidScrollEnd(); |
| 237 | 239 |
| 238 // An animation should have been enqueued. | 240 // An animation should have been enqueued. |
| 239 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 241 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 240 EXPECT_FALSE(client_.start_fade().is_null()); | 242 EXPECT_FALSE(client_.start_fade().is_null()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 261 | 263 |
| 262 // Mouse is still near the Scrollbar. Once the thickness animation is | 264 // Mouse is still near the Scrollbar. Once the thickness animation is |
| 263 // complete, the queued delayed fade animation should be either cancelled or | 265 // complete, the queued delayed fade animation should be either cancelled or |
| 264 // null. | 266 // null. |
| 265 EXPECT_TRUE(client_.start_fade().is_null() || | 267 EXPECT_TRUE(client_.start_fade().is_null() || |
| 266 client_.start_fade().IsCancelled()); | 268 client_.start_fade().IsCancelled()); |
| 267 } | 269 } |
| 268 | 270 |
| 269 // Scroll content. Move the mouse over the scrollbar and confirm it becomes | 271 // Scroll content. Move the mouse over the scrollbar and confirm it becomes |
| 270 // thick. Ensure it remains visible as long as the mouse is over the scrollbar. | 272 // thick. Ensure it remains visible as long as the mouse is over the scrollbar. |
| 271 TEST_F(ScrollbarAnimationControllerThinningTest, MoveOverAndDontFadeOut) { | 273 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveOverAndDontFadeOut) { |
| 272 base::TimeTicks time; | 274 base::TimeTicks time; |
| 273 time += base::TimeDelta::FromSeconds(1); | 275 time += base::TimeDelta::FromSeconds(1); |
| 274 | 276 |
| 275 scrollbar_controller_->DidScrollBegin(); | 277 scrollbar_controller_->DidScrollBegin(); |
| 276 scrollbar_controller_->DidScrollUpdate(false); | 278 scrollbar_controller_->DidScrollUpdate(false); |
| 277 scrollbar_controller_->DidScrollEnd(); | 279 scrollbar_controller_->DidScrollEnd(); |
| 278 | 280 |
| 279 // An animation should have been enqueued. | 281 // An animation should have been enqueued. |
| 280 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 282 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 281 EXPECT_FALSE(client_.start_fade().is_null()); | 283 EXPECT_FALSE(client_.start_fade().is_null()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 302 | 304 |
| 303 // Mouse is still over the Scrollbar. Once the thickness animation is | 305 // Mouse is still over the Scrollbar. Once the thickness animation is |
| 304 // complete, the queued delayed fade animation should be either cancelled or | 306 // complete, the queued delayed fade animation should be either cancelled or |
| 305 // null. | 307 // null. |
| 306 EXPECT_TRUE(client_.start_fade().is_null() || | 308 EXPECT_TRUE(client_.start_fade().is_null() || |
| 307 client_.start_fade().IsCancelled()); | 309 client_.start_fade().IsCancelled()); |
| 308 } | 310 } |
| 309 | 311 |
| 310 // Make sure a scrollbar captured before the thickening animation doesn't try | 312 // Make sure a scrollbar captured before the thickening animation doesn't try |
| 311 // to fade out. | 313 // to fade out. |
| 312 TEST_F(ScrollbarAnimationControllerThinningTest, | 314 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, |
| 313 DontFadeWhileCapturedBeforeThick) { | 315 DontFadeWhileCapturedBeforeThick) { |
| 314 base::TimeTicks time; | 316 base::TimeTicks time; |
| 315 time += base::TimeDelta::FromSeconds(1); | 317 time += base::TimeDelta::FromSeconds(1); |
| 316 | 318 |
| 317 scrollbar_controller_->DidScrollBegin(); | 319 scrollbar_controller_->DidScrollBegin(); |
| 318 scrollbar_controller_->DidScrollUpdate(false); | 320 scrollbar_controller_->DidScrollUpdate(false); |
| 319 scrollbar_controller_->DidScrollEnd(); | 321 scrollbar_controller_->DidScrollEnd(); |
| 320 | 322 |
| 321 // An animation should have been enqueued. | 323 // An animation should have been enqueued. |
| 322 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 324 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 323 EXPECT_FALSE(client_.start_fade().is_null()); | 325 EXPECT_FALSE(client_.start_fade().is_null()); |
| 324 | 326 |
| 325 // Now move the mouse over the scrollbar and capture it. It should become | 327 // Now move the mouse over the scrollbar and capture it. It should become |
| 326 // thick without need for an animation. | 328 // thick without need for an animation. |
| 327 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); | 329 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 0); |
| 328 scrollbar_controller_->DidMouseDown(); | 330 scrollbar_controller_->DidMouseDown(); |
| 329 ExpectScrollbarsOpacity(1); | 331 ExpectScrollbarsOpacity(1); |
| 330 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 332 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 331 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 333 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 332 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 334 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 333 | 335 |
| 334 // The fade animation should have been cleared or cancelled. | 336 // The fade animation should have been cleared or cancelled. |
| 335 EXPECT_TRUE(client_.start_fade().is_null() || | 337 EXPECT_TRUE(client_.start_fade().is_null() || |
| 336 client_.start_fade().IsCancelled()); | 338 client_.start_fade().IsCancelled()); |
| 337 } | 339 } |
| 338 | 340 |
| 339 // Make sure a scrollbar captured then move mouse away doesn't try to fade out. | 341 // Make sure a scrollbar captured then move mouse away doesn't try to fade out. |
| 340 TEST_F(ScrollbarAnimationControllerThinningTest, | 342 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, |
| 341 DontFadeWhileCapturedThenAway) { | 343 DontFadeWhileCapturedThenAway) { |
| 342 base::TimeTicks time; | 344 base::TimeTicks time; |
| 343 time += base::TimeDelta::FromSeconds(1); | 345 time += base::TimeDelta::FromSeconds(1); |
| 344 | 346 |
| 345 scrollbar_controller_->DidScrollBegin(); | 347 scrollbar_controller_->DidScrollBegin(); |
| 346 scrollbar_controller_->DidScrollUpdate(false); | 348 scrollbar_controller_->DidScrollUpdate(false); |
| 347 scrollbar_controller_->DidScrollEnd(); | 349 scrollbar_controller_->DidScrollEnd(); |
| 348 | 350 |
| 349 // An animation should have been enqueued. | 351 // An animation should have been enqueued. |
| 350 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 352 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 367 // cancelled. | 369 // cancelled. |
| 368 scrollbar_controller_->DidMouseMoveNear( | 370 scrollbar_controller_->DidMouseMoveNear( |
| 369 VERTICAL, kDefaultMouseMoveDistanceToTriggerAnimation); | 371 VERTICAL, kDefaultMouseMoveDistanceToTriggerAnimation); |
| 370 | 372 |
| 371 EXPECT_TRUE(client_.start_fade().is_null() || | 373 EXPECT_TRUE(client_.start_fade().is_null() || |
| 372 client_.start_fade().IsCancelled()); | 374 client_.start_fade().IsCancelled()); |
| 373 } | 375 } |
| 374 | 376 |
| 375 // Make sure a scrollbar captured after a thickening animation doesn't try to | 377 // Make sure a scrollbar captured after a thickening animation doesn't try to |
| 376 // fade out. | 378 // fade out. |
| 377 TEST_F(ScrollbarAnimationControllerThinningTest, DontFadeWhileCaptured) { | 379 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, DontFadeWhileCaptured) { |
| 378 base::TimeTicks time; | 380 base::TimeTicks time; |
| 379 time += base::TimeDelta::FromSeconds(1); | 381 time += base::TimeDelta::FromSeconds(1); |
| 380 | 382 |
| 381 scrollbar_controller_->DidScrollBegin(); | 383 scrollbar_controller_->DidScrollBegin(); |
| 382 scrollbar_controller_->DidScrollUpdate(false); | 384 scrollbar_controller_->DidScrollUpdate(false); |
| 383 scrollbar_controller_->DidScrollEnd(); | 385 scrollbar_controller_->DidScrollEnd(); |
| 384 | 386 |
| 385 // An animation should have been enqueued. | 387 // An animation should have been enqueued. |
| 386 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 388 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 387 EXPECT_FALSE(client_.start_fade().is_null()); | 389 EXPECT_FALSE(client_.start_fade().is_null()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 404 | 406 |
| 405 // Make sure the queued fade animation is still null or cancelled after | 407 // Make sure the queued fade animation is still null or cancelled after |
| 406 // capturing the scrollbar. | 408 // capturing the scrollbar. |
| 407 scrollbar_controller_->DidMouseDown(); | 409 scrollbar_controller_->DidMouseDown(); |
| 408 EXPECT_TRUE(client_.start_fade().is_null() || | 410 EXPECT_TRUE(client_.start_fade().is_null() || |
| 409 client_.start_fade().IsCancelled()); | 411 client_.start_fade().IsCancelled()); |
| 410 } | 412 } |
| 411 | 413 |
| 412 // Make sure releasing a captured scrollbar when the mouse isn't near it, causes | 414 // Make sure releasing a captured scrollbar when the mouse isn't near it, causes |
| 413 // the scrollbar to fade out. | 415 // the scrollbar to fade out. |
| 414 TEST_F(ScrollbarAnimationControllerThinningTest, FadeAfterReleasedFar) { | 416 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAfterReleasedFar) { |
| 415 base::TimeTicks time; | 417 base::TimeTicks time; |
| 416 time += base::TimeDelta::FromSeconds(1); | 418 time += base::TimeDelta::FromSeconds(1); |
| 417 | 419 |
| 418 scrollbar_controller_->DidScrollBegin(); | 420 scrollbar_controller_->DidScrollBegin(); |
| 419 scrollbar_controller_->DidScrollUpdate(false); | 421 scrollbar_controller_->DidScrollUpdate(false); |
| 420 scrollbar_controller_->DidScrollEnd(); | 422 scrollbar_controller_->DidScrollEnd(); |
| 421 | 423 |
| 422 // An animation should have been enqueued. | 424 // An animation should have been enqueued. |
| 423 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 425 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 424 EXPECT_FALSE(client_.start_fade().is_null()); | 426 EXPECT_FALSE(client_.start_fade().is_null()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 455 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 457 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 456 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 458 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 457 | 459 |
| 458 // The thickness animation is complete, a fade out must be queued. | 460 // The thickness animation is complete, a fade out must be queued. |
| 459 EXPECT_FALSE(client_.start_fade().is_null()); | 461 EXPECT_FALSE(client_.start_fade().is_null()); |
| 460 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 462 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 461 } | 463 } |
| 462 | 464 |
| 463 // Make sure releasing a captured scrollbar when the mouse is near/over it, | 465 // Make sure releasing a captured scrollbar when the mouse is near/over it, |
| 464 // doesn't cause the scrollbar to fade out. | 466 // doesn't cause the scrollbar to fade out. |
| 465 TEST_F(ScrollbarAnimationControllerThinningTest, DontFadeAfterReleasedNear) { | 467 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, DontFadeAfterReleasedNear) { |
| 466 base::TimeTicks time; | 468 base::TimeTicks time; |
| 467 time += base::TimeDelta::FromSeconds(1); | 469 time += base::TimeDelta::FromSeconds(1); |
| 468 | 470 |
| 469 scrollbar_controller_->DidScrollBegin(); | 471 scrollbar_controller_->DidScrollBegin(); |
| 470 scrollbar_controller_->DidScrollUpdate(false); | 472 scrollbar_controller_->DidScrollUpdate(false); |
| 471 scrollbar_controller_->DidScrollEnd(); | 473 scrollbar_controller_->DidScrollEnd(); |
| 472 | 474 |
| 473 // An animation should have been enqueued. | 475 // An animation should have been enqueued. |
| 474 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 476 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 475 EXPECT_FALSE(client_.start_fade().is_null()); | 477 EXPECT_FALSE(client_.start_fade().is_null()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 493 EXPECT_TRUE(client_.start_fade().is_null() || | 495 EXPECT_TRUE(client_.start_fade().is_null() || |
| 494 client_.start_fade().IsCancelled()); | 496 client_.start_fade().IsCancelled()); |
| 495 ExpectScrollbarsOpacity(1); | 497 ExpectScrollbarsOpacity(1); |
| 496 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 498 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 497 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 499 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 498 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 500 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 499 } | 501 } |
| 500 | 502 |
| 501 // Make sure moving near a scrollbar while it's fading out causes it to reset | 503 // Make sure moving near a scrollbar while it's fading out causes it to reset |
| 502 // the opacity and thicken. | 504 // the opacity and thicken. |
| 503 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearScrollbarWhileFading) { | 505 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, |
| 506 MoveNearScrollbarWhileFading) { |
| 504 base::TimeTicks time; | 507 base::TimeTicks time; |
| 505 time += base::TimeDelta::FromSeconds(1); | 508 time += base::TimeDelta::FromSeconds(1); |
| 506 | 509 |
| 507 scrollbar_controller_->DidScrollBegin(); | 510 scrollbar_controller_->DidScrollBegin(); |
| 508 scrollbar_controller_->DidScrollUpdate(false); | 511 scrollbar_controller_->DidScrollUpdate(false); |
| 509 scrollbar_controller_->DidScrollEnd(); | 512 scrollbar_controller_->DidScrollEnd(); |
| 510 | 513 |
| 511 // A fade animation should have been enqueued. Start it. | 514 // A fade animation should have been enqueued. Start it. |
| 512 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 515 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 513 EXPECT_FALSE(client_.start_fade().is_null()); | 516 EXPECT_FALSE(client_.start_fade().is_null()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 533 scrollbar_controller_->Animate(time); | 536 scrollbar_controller_->Animate(time); |
| 534 time += kThinningDuration; | 537 time += kThinningDuration; |
| 535 scrollbar_controller_->Animate(time); | 538 scrollbar_controller_->Animate(time); |
| 536 ExpectScrollbarsOpacity(1); | 539 ExpectScrollbarsOpacity(1); |
| 537 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 540 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 538 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 541 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 539 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 542 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 540 } | 543 } |
| 541 | 544 |
| 542 // Make sure we can't capture scrollbar that's completely faded out. | 545 // Make sure we can't capture scrollbar that's completely faded out. |
| 543 TEST_F(ScrollbarAnimationControllerThinningTest, TestCantCaptureWhenFaded) { | 546 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, TestCantCaptureWhenFaded) { |
| 544 base::TimeTicks time; | 547 base::TimeTicks time; |
| 545 time += base::TimeDelta::FromSeconds(1); | 548 time += base::TimeDelta::FromSeconds(1); |
| 546 | 549 |
| 547 scrollbar_controller_->DidScrollBegin(); | 550 scrollbar_controller_->DidScrollBegin(); |
| 548 scrollbar_controller_->DidScrollUpdate(false); | 551 scrollbar_controller_->DidScrollUpdate(false); |
| 549 scrollbar_controller_->DidScrollEnd(); | 552 scrollbar_controller_->DidScrollEnd(); |
| 550 | 553 |
| 551 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 554 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 552 EXPECT_FALSE(client_.start_fade().is_null()); | 555 EXPECT_FALSE(client_.start_fade().is_null()); |
| 553 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 556 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 scrollbar_controller_->DidMouseUp(); | 589 scrollbar_controller_->DidMouseUp(); |
| 587 ExpectScrollbarsOpacity(0); | 590 ExpectScrollbarsOpacity(0); |
| 588 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 591 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 589 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 592 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 590 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 593 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 591 EXPECT_TRUE(client_.start_fade().is_null()); | 594 EXPECT_TRUE(client_.start_fade().is_null()); |
| 592 } | 595 } |
| 593 | 596 |
| 594 // Initiate a scroll when the pointer is already near the scrollbar. It should | 597 // Initiate a scroll when the pointer is already near the scrollbar. It should |
| 595 // appear thick and remain thick. | 598 // appear thick and remain thick. |
| 596 TEST_F(ScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) { | 599 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, ScrollWithMouseNear) { |
| 597 base::TimeTicks time; | 600 base::TimeTicks time; |
| 598 time += base::TimeDelta::FromSeconds(1); | 601 time += base::TimeDelta::FromSeconds(1); |
| 599 | 602 |
| 600 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); | 603 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); |
| 601 scrollbar_controller_->Animate(time); | 604 scrollbar_controller_->Animate(time); |
| 602 time += kThinningDuration; | 605 time += kThinningDuration; |
| 603 | 606 |
| 604 // Since the scrollbar isn't visible yet (because we haven't scrolled), we | 607 // Since the scrollbar isn't visible yet (because we haven't scrolled), we |
| 605 // shouldn't have applied the thickening. | 608 // shouldn't have applied the thickening. |
| 606 scrollbar_controller_->Animate(time); | 609 scrollbar_controller_->Animate(time); |
| 607 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 610 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 608 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 611 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 609 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 612 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 610 | 613 |
| 611 scrollbar_controller_->DidScrollBegin(); | 614 scrollbar_controller_->DidScrollBegin(); |
| 612 scrollbar_controller_->DidScrollUpdate(false); | 615 scrollbar_controller_->DidScrollUpdate(false); |
| 613 | 616 |
| 614 // Now that we've received a scroll, we should be thick without an animation. | 617 // Now that we've received a scroll, we should be thick without an animation. |
| 615 ExpectScrollbarsOpacity(1); | 618 ExpectScrollbarsOpacity(1); |
| 616 | 619 |
| 617 // An animation for the fade should be either null or cancelled, since | 620 // An animation for the fade should be either null or cancelled, since |
| 618 // mouse is still near the scrollbar. | 621 // mouse is still near the scrollbar. |
| 619 scrollbar_controller_->DidScrollEnd(); | 622 scrollbar_controller_->DidScrollEnd(); |
| 620 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | |
| 621 EXPECT_TRUE(client_.start_fade().is_null() || | 623 EXPECT_TRUE(client_.start_fade().is_null() || |
| 622 client_.start_fade().IsCancelled()); | 624 client_.start_fade().IsCancelled()); |
| 623 | 625 |
| 624 scrollbar_controller_->Animate(time); | 626 scrollbar_controller_->Animate(time); |
| 625 ExpectScrollbarsOpacity(1); | 627 ExpectScrollbarsOpacity(1); |
| 626 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 628 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 627 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 629 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 628 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 630 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 629 | 631 |
| 630 // Scrollbar should still be thick and visible. | 632 // Scrollbar should still be thick and visible. |
| 631 time += kFadeDuration; | 633 time += kFadeDuration; |
| 632 scrollbar_controller_->Animate(time); | 634 scrollbar_controller_->Animate(time); |
| 633 ExpectScrollbarsOpacity(1); | 635 ExpectScrollbarsOpacity(1); |
| 634 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 636 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 635 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 637 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 636 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 638 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 637 } | 639 } |
| 638 | 640 |
| 639 // Tests that main thread scroll updates immediatley queue a fade animation | 641 // Tests that main thread scroll updates immediatley queue a fade animation |
| 640 // without requiring a ScrollEnd. | 642 // without requiring a ScrollEnd. |
| 641 TEST_F(ScrollbarAnimationControllerThinningTest, MainThreadScrollQueuesFade) { | 643 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, |
| 644 MainThreadScrollQueuesFade) { |
| 642 ASSERT_TRUE(client_.start_fade().is_null()); | 645 ASSERT_TRUE(client_.start_fade().is_null()); |
| 643 | 646 |
| 644 // A ScrollUpdate without a ScrollBegin indicates a main thread scroll update | 647 // A ScrollUpdate without a ScrollBegin indicates a main thread scroll update |
| 645 // so we should schedule a fade animation without waiting for a ScrollEnd | 648 // so we should schedule a fade animation without waiting for a ScrollEnd |
| 646 // (which will never come). | 649 // (which will never come). |
| 647 scrollbar_controller_->DidScrollUpdate(false); | 650 scrollbar_controller_->DidScrollUpdate(false); |
| 648 EXPECT_FALSE(client_.start_fade().is_null()); | 651 EXPECT_FALSE(client_.start_fade().is_null()); |
| 649 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 652 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 650 | 653 |
| 651 client_.start_fade().Reset(); | 654 client_.start_fade().Reset(); |
| 652 | 655 |
| 653 // If we got a ScrollBegin, we shouldn't schedule the fade animation until we | 656 // If we got a ScrollBegin, we shouldn't schedule the fade animation until we |
| 654 // get a corresponding ScrollEnd. | 657 // get a corresponding ScrollEnd. |
| 655 scrollbar_controller_->DidScrollBegin(); | 658 scrollbar_controller_->DidScrollBegin(); |
| 656 scrollbar_controller_->DidScrollUpdate(false); | 659 scrollbar_controller_->DidScrollUpdate(false); |
| 657 EXPECT_TRUE(client_.start_fade().is_null()); | 660 EXPECT_TRUE(client_.start_fade().is_null()); |
| 658 scrollbar_controller_->DidScrollEnd(); | 661 scrollbar_controller_->DidScrollEnd(); |
| 659 EXPECT_FALSE(client_.start_fade().is_null()); | 662 EXPECT_FALSE(client_.start_fade().is_null()); |
| 660 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 663 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 661 } | 664 } |
| 662 | 665 |
| 663 // Make sure that if the scroll update is as a result of a resize, we use the | 666 // Make sure that if the scroll update is as a result of a resize, we use the |
| 664 // resize delay time instead of the default one. | 667 // resize delay time instead of the default one. |
| 665 TEST_F(ScrollbarAnimationControllerThinningTest, ResizeFadeDuration) { | 668 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, ResizeFadeDuration) { |
| 666 ASSERT_TRUE(client_.delay().is_zero()); | 669 ASSERT_TRUE(client_.delay().is_zero()); |
| 667 | 670 |
| 668 scrollbar_controller_->DidScrollUpdate(true); | 671 scrollbar_controller_->DidScrollUpdate(true); |
| 669 EXPECT_FALSE(client_.start_fade().is_null()); | 672 EXPECT_FALSE(client_.start_fade().is_null()); |
| 670 EXPECT_EQ(kResizeDelayBeforeStarting, client_.delay()); | 673 EXPECT_EQ(kResizeDelayBeforeStarting, client_.delay()); |
| 671 | 674 |
| 672 client_.delay() = base::TimeDelta(); | 675 client_.delay() = base::TimeDelta(); |
| 673 | 676 |
| 674 // We should use the gesture delay rather than the resize delay if we're in a | 677 // We should use the gesture delay rather than the resize delay if we're in a |
| 675 // gesture scroll, even if the resize param is set. | 678 // gesture scroll, even if the resize param is set. |
| 676 scrollbar_controller_->DidScrollBegin(); | 679 scrollbar_controller_->DidScrollBegin(); |
| 677 scrollbar_controller_->DidScrollUpdate(true); | 680 scrollbar_controller_->DidScrollUpdate(true); |
| 678 scrollbar_controller_->DidScrollEnd(); | 681 scrollbar_controller_->DidScrollEnd(); |
| 679 | 682 |
| 680 EXPECT_FALSE(client_.start_fade().is_null()); | 683 EXPECT_FALSE(client_.start_fade().is_null()); |
| 681 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 684 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 682 } | 685 } |
| 683 | 686 |
| 684 // Tests that the fade effect is animated. | 687 // Tests that the fade effect is animated. |
| 685 TEST_F(ScrollbarAnimationControllerThinningTest, FadeAnimated) { | 688 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAnimated) { |
| 686 base::TimeTicks time; | 689 base::TimeTicks time; |
| 687 time += base::TimeDelta::FromSeconds(1); | 690 time += base::TimeDelta::FromSeconds(1); |
| 688 | 691 |
| 689 // Scroll to make the scrollbars visible. | 692 // Scroll to make the scrollbars visible. |
| 690 scrollbar_controller_->DidScrollBegin(); | 693 scrollbar_controller_->DidScrollBegin(); |
| 691 scrollbar_controller_->DidScrollUpdate(false); | 694 scrollbar_controller_->DidScrollUpdate(false); |
| 692 scrollbar_controller_->DidScrollEnd(); | 695 scrollbar_controller_->DidScrollEnd(); |
| 693 | 696 |
| 694 // Appearance is instant. | 697 // Appearance is instant. |
| 695 ExpectScrollbarsOpacity(1); | 698 ExpectScrollbarsOpacity(1); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 706 time += kFadeDuration / 2; | 709 time += kFadeDuration / 2; |
| 707 scrollbar_controller_->Animate(time); | 710 scrollbar_controller_->Animate(time); |
| 708 ExpectScrollbarsOpacity(.5f); | 711 ExpectScrollbarsOpacity(.5f); |
| 709 | 712 |
| 710 time += kFadeDuration / 2; | 713 time += kFadeDuration / 2; |
| 711 scrollbar_controller_->Animate(time); | 714 scrollbar_controller_->Animate(time); |
| 712 ExpectScrollbarsOpacity(0); | 715 ExpectScrollbarsOpacity(0); |
| 713 } | 716 } |
| 714 | 717 |
| 715 // Tests that the controller tells the client when the scrollbars hide/show. | 718 // Tests that the controller tells the client when the scrollbars hide/show. |
| 716 TEST_F(ScrollbarAnimationControllerThinningTest, NotifyChangedVisibility) { | 719 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, NotifyChangedVisibility) { |
| 717 base::TimeTicks time; | 720 base::TimeTicks time; |
| 718 time += base::TimeDelta::FromSeconds(1); | 721 time += base::TimeDelta::FromSeconds(1); |
| 719 | 722 |
| 720 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); | 723 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); |
| 721 // Scroll to make the scrollbars visible. | 724 // Scroll to make the scrollbars visible. |
| 722 scrollbar_controller_->DidScrollBegin(); | 725 scrollbar_controller_->DidScrollBegin(); |
| 723 scrollbar_controller_->DidScrollUpdate(false); | 726 scrollbar_controller_->DidScrollUpdate(false); |
| 724 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); | 727 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); |
| 725 Mock::VerifyAndClearExpectations(&client_); | 728 Mock::VerifyAndClearExpectations(&client_); |
| 726 | 729 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 755 // Calling DidScrollUpdate without a begin (i.e. update from commit) should | 758 // Calling DidScrollUpdate without a begin (i.e. update from commit) should |
| 756 // also notify. | 759 // also notify. |
| 757 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); | 760 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); |
| 758 scrollbar_controller_->DidScrollUpdate(false); | 761 scrollbar_controller_->DidScrollUpdate(false); |
| 759 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); | 762 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); |
| 760 Mock::VerifyAndClearExpectations(&client_); | 763 Mock::VerifyAndClearExpectations(&client_); |
| 761 } | 764 } |
| 762 | 765 |
| 763 // Move the pointer near each scrollbar. Confirm it gets thick and narrow when | 766 // Move the pointer near each scrollbar. Confirm it gets thick and narrow when |
| 764 // moved away. | 767 // moved away. |
| 765 TEST_F(ScrollbarAnimationControllerThinningTest, MouseNearEach) { | 768 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearEach) { |
| 766 base::TimeTicks time; | 769 base::TimeTicks time; |
| 767 time += base::TimeDelta::FromSeconds(1); | 770 time += base::TimeDelta::FromSeconds(1); |
| 768 | 771 |
| 769 // Scroll to make the scrollbars visible. | 772 // Scroll to make the scrollbars visible. |
| 770 scrollbar_controller_->DidScrollBegin(); | 773 scrollbar_controller_->DidScrollBegin(); |
| 771 scrollbar_controller_->DidScrollUpdate(false); | 774 scrollbar_controller_->DidScrollUpdate(false); |
| 772 scrollbar_controller_->DidScrollEnd(); | 775 scrollbar_controller_->DidScrollEnd(); |
| 773 | 776 |
| 774 // Near vertical scrollbar | 777 // Near vertical scrollbar |
| 775 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); | 778 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 v_scrollbar_layer_->thumb_thickness_scale_factor()); | 851 v_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 849 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 852 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 850 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 853 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 851 | 854 |
| 852 // An animation should have been enqueued. | 855 // An animation should have been enqueued. |
| 853 EXPECT_FALSE(client_.start_fade().is_null()); | 856 EXPECT_FALSE(client_.start_fade().is_null()); |
| 854 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 857 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 855 } | 858 } |
| 856 | 859 |
| 857 // Move mouse near both scrollbars at the same time. | 860 // Move mouse near both scrollbars at the same time. |
| 858 TEST_F(ScrollbarAnimationControllerThinningTest, MouseNearBoth) { | 861 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearBoth) { |
| 859 base::TimeTicks time; | 862 base::TimeTicks time; |
| 860 time += base::TimeDelta::FromSeconds(1); | 863 time += base::TimeDelta::FromSeconds(1); |
| 861 | 864 |
| 862 // Scroll to make the scrollbars visible. | 865 // Scroll to make the scrollbars visible. |
| 863 scrollbar_controller_->DidScrollBegin(); | 866 scrollbar_controller_->DidScrollBegin(); |
| 864 scrollbar_controller_->DidScrollUpdate(false); | 867 scrollbar_controller_->DidScrollUpdate(false); |
| 865 scrollbar_controller_->DidScrollEnd(); | 868 scrollbar_controller_->DidScrollEnd(); |
| 866 | 869 |
| 867 // Near both Scrollbar | 870 // Near both Scrollbar |
| 868 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); | 871 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); |
| 869 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1); | 872 scrollbar_controller_->DidMouseMoveNear(HORIZONTAL, 1); |
| 870 scrollbar_controller_->Animate(time); | 873 scrollbar_controller_->Animate(time); |
| 871 ExpectScrollbarsOpacity(1); | 874 ExpectScrollbarsOpacity(1); |
| 872 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 875 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 873 v_scrollbar_layer_->thumb_thickness_scale_factor()); | 876 v_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 874 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 877 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 875 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 878 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 876 | 879 |
| 877 // Should animate to thickened. | 880 // Should animate to thickened. |
| 878 time += kThinningDuration; | 881 time += kThinningDuration; |
| 879 scrollbar_controller_->Animate(time); | 882 scrollbar_controller_->Animate(time); |
| 880 ExpectScrollbarsOpacity(1); | 883 ExpectScrollbarsOpacity(1); |
| 881 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); | 884 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 882 EXPECT_FLOAT_EQ(1, h_scrollbar_layer_->thumb_thickness_scale_factor()); | 885 EXPECT_FLOAT_EQ(1, h_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 883 } | 886 } |
| 884 | 887 |
| 885 // Move mouse from one to the other scrollbar before animation is finished, then | 888 // Move mouse from one to the other scrollbar before animation is finished, then |
| 886 // away before animation finished. | 889 // away before animation finished. |
| 887 TEST_F(ScrollbarAnimationControllerThinningTest, | 890 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, |
| 888 MouseNearOtherBeforeAnimationFinished) { | 891 MouseNearOtherBeforeAnimationFinished) { |
| 889 base::TimeTicks time; | 892 base::TimeTicks time; |
| 890 time += base::TimeDelta::FromSeconds(1); | 893 time += base::TimeDelta::FromSeconds(1); |
| 891 | 894 |
| 892 // Scroll to make the scrollbars visible. | 895 // Scroll to make the scrollbars visible. |
| 893 scrollbar_controller_->DidScrollBegin(); | 896 scrollbar_controller_->DidScrollBegin(); |
| 894 scrollbar_controller_->DidScrollUpdate(false); | 897 scrollbar_controller_->DidScrollUpdate(false); |
| 895 scrollbar_controller_->DidScrollEnd(); | 898 scrollbar_controller_->DidScrollEnd(); |
| 896 | 899 |
| 897 // Near vertical scrollbar. | 900 // Near vertical scrollbar. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 944 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 942 h_scrollbar_layer_->thumb_thickness_scale_factor()); | 945 h_scrollbar_layer_->thumb_thickness_scale_factor()); |
| 943 | 946 |
| 944 // An animation should have been enqueued. | 947 // An animation should have been enqueued. |
| 945 EXPECT_FALSE(client_.start_fade().is_null()); | 948 EXPECT_FALSE(client_.start_fade().is_null()); |
| 946 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 949 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 947 } | 950 } |
| 948 | 951 |
| 949 // Ensure we have a delay fadeout animation after mouse leave without a mouse | 952 // Ensure we have a delay fadeout animation after mouse leave without a mouse |
| 950 // move. | 953 // move. |
| 951 TEST_F(ScrollbarAnimationControllerThinningTest, MouseLeaveFadeOut) { | 954 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseLeaveFadeOut) { |
| 952 base::TimeTicks time; | 955 base::TimeTicks time; |
| 953 time += base::TimeDelta::FromSeconds(1); | 956 time += base::TimeDelta::FromSeconds(1); |
| 954 | 957 |
| 955 // Move mouse near scrollbar. | 958 // Move mouse near scrollbar. |
| 956 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); | 959 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1); |
| 957 | 960 |
| 958 // Scroll to make the scrollbars visible. | 961 // Scroll to make the scrollbars visible. |
| 959 scrollbar_controller_->DidScrollBegin(); | 962 scrollbar_controller_->DidScrollBegin(); |
| 960 scrollbar_controller_->DidScrollUpdate(false); | 963 scrollbar_controller_->DidScrollUpdate(false); |
| 961 scrollbar_controller_->DidScrollEnd(); | 964 scrollbar_controller_->DidScrollEnd(); |
| 962 | 965 |
| 963 // Should not have delay fadeout animation. | 966 // Should not have delay fadeout animation. |
| 964 EXPECT_TRUE(client_.start_fade().is_null() || | 967 EXPECT_TRUE(client_.start_fade().is_null() || |
| 965 client_.start_fade().IsCancelled()); | 968 client_.start_fade().IsCancelled()); |
| 966 | 969 |
| 967 // Mouse leave. | 970 // Mouse leave. |
| 968 scrollbar_controller_->DidMouseLeave(); | 971 scrollbar_controller_->DidMouseLeave(); |
| 969 | 972 |
| 970 // An animation should have been enqueued. | 973 // An animation should have been enqueued. |
| 971 EXPECT_FALSE(client_.start_fade().is_null()); | 974 EXPECT_FALSE(client_.start_fade().is_null()); |
| 972 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 975 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 973 } | 976 } |
| 974 | 977 |
| 978 class ScrollbarAnimationControllerAndroidTest |
| 979 : public testing::Test, |
| 980 public ScrollbarAnimationControllerClient { |
| 981 public: |
| 982 ScrollbarAnimationControllerAndroidTest() |
| 983 : host_impl_(&task_runner_provider_, &task_graph_runner_), |
| 984 did_request_redraw_(false), |
| 985 did_request_animate_(false) {} |
| 986 |
| 987 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade, |
| 988 base::TimeDelta delay) override { |
| 989 start_fade_ = start_fade; |
| 990 delay_ = delay; |
| 991 } |
| 992 void SetNeedsRedrawForScrollbarAnimation() override { |
| 993 did_request_redraw_ = true; |
| 994 } |
| 995 void SetNeedsAnimateForScrollbarAnimation() override { |
| 996 did_request_animate_ = true; |
| 997 } |
| 998 ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override { |
| 999 return host_impl_.ScrollbarsFor(scroll_layer_id); |
| 1000 } |
| 1001 void DidChangeScrollbarVisibility() override {} |
| 1002 |
| 1003 protected: |
| 1004 void SetUp() override { |
| 1005 const int kThumbThickness = 10; |
| 1006 const int kTrackStart = 0; |
| 1007 const bool kIsLeftSideVerticalScrollbar = false; |
| 1008 const bool kIsOverlayScrollbar = true; // Allow opacity animations. |
| 1009 |
| 1010 std::unique_ptr<LayerImpl> scroll_layer = |
| 1011 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 1012 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
| 1013 SolidColorScrollbarLayerImpl::Create( |
| 1014 host_impl_.active_tree(), 2, orientation(), kThumbThickness, |
| 1015 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); |
| 1016 scrollbar_layer_ = scrollbar.get(); |
| 1017 scrollbar_layer_->test_properties()->opacity_can_animate = true; |
| 1018 std::unique_ptr<LayerImpl> clip = |
| 1019 LayerImpl::Create(host_impl_.active_tree(), 3); |
| 1020 clip_layer_ = clip.get(); |
| 1021 scroll_layer->SetScrollClipLayer(clip_layer_->id()); |
| 1022 LayerImpl* scroll_layer_ptr = scroll_layer.get(); |
| 1023 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); |
| 1024 clip->test_properties()->AddChild(std::move(scroll_layer)); |
| 1025 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); |
| 1026 |
| 1027 scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); |
| 1028 clip_layer_->SetBounds(gfx::Size(100, 100)); |
| 1029 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
| 1030 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 1031 |
| 1032 scrollbar_controller_ = |
| 1033 ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid( |
| 1034 scroll_layer_ptr->id(), this, base::TimeDelta::FromSeconds(2), |
| 1035 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(3)); |
| 1036 } |
| 1037 |
| 1038 virtual ScrollbarOrientation orientation() const { return HORIZONTAL; } |
| 1039 |
| 1040 FakeImplTaskRunnerProvider task_runner_provider_; |
| 1041 TestTaskGraphRunner task_graph_runner_; |
| 1042 FakeLayerTreeHostImpl host_impl_; |
| 1043 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; |
| 1044 LayerImpl* clip_layer_; |
| 1045 SolidColorScrollbarLayerImpl* scrollbar_layer_; |
| 1046 |
| 1047 base::Closure start_fade_; |
| 1048 base::TimeDelta delay_; |
| 1049 bool did_request_redraw_; |
| 1050 bool did_request_animate_; |
| 1051 }; |
| 1052 |
| 1053 class VerticalScrollbarAnimationControllerAndroidTest |
| 1054 : public ScrollbarAnimationControllerAndroidTest { |
| 1055 protected: |
| 1056 ScrollbarOrientation orientation() const override { return VERTICAL; } |
| 1057 }; |
| 1058 |
| 1059 TEST_F(ScrollbarAnimationControllerAndroidTest, DelayAnimationOnResize) { |
| 1060 scrollbar_layer_->layer_tree_impl() |
| 1061 ->property_trees() |
| 1062 ->effect_tree.OnOpacityAnimated(0.0f, |
| 1063 scrollbar_layer_->effect_tree_index(), |
| 1064 scrollbar_layer_->layer_tree_impl()); |
| 1065 scrollbar_controller_->DidScrollBegin(); |
| 1066 scrollbar_controller_->DidScrollUpdate(true); |
| 1067 scrollbar_controller_->DidScrollEnd(); |
| 1068 // Normal Animation delay of 2 seconds. |
| 1069 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 1070 EXPECT_EQ(delay_, base::TimeDelta::FromSeconds(2)); |
| 1071 |
| 1072 scrollbar_layer_->layer_tree_impl() |
| 1073 ->property_trees() |
| 1074 ->effect_tree.OnOpacityAnimated(0.0f, |
| 1075 scrollbar_layer_->effect_tree_index(), |
| 1076 scrollbar_layer_->layer_tree_impl()); |
| 1077 scrollbar_controller_->DidScrollUpdate(true); |
| 1078 // Delay animation on resize to 5 seconds. |
| 1079 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 1080 EXPECT_EQ(delay_, base::TimeDelta::FromSeconds(5)); |
| 1081 } |
| 1082 |
| 1083 TEST_F(ScrollbarAnimationControllerAndroidTest, HiddenInBegin) { |
| 1084 scrollbar_layer_->layer_tree_impl() |
| 1085 ->property_trees() |
| 1086 ->effect_tree.OnOpacityAnimated(0.0f, |
| 1087 scrollbar_layer_->effect_tree_index(), |
| 1088 scrollbar_layer_->layer_tree_impl()); |
| 1089 scrollbar_controller_->Animate(base::TimeTicks()); |
| 1090 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 1091 } |
| 1092 |
| 1093 TEST_F(ScrollbarAnimationControllerAndroidTest, |
| 1094 HiddenAfterNonScrollingGesture) { |
| 1095 scrollbar_layer_->layer_tree_impl() |
| 1096 ->property_trees() |
| 1097 ->effect_tree.OnOpacityAnimated(0.0f, |
| 1098 scrollbar_layer_->effect_tree_index(), |
| 1099 scrollbar_layer_->layer_tree_impl()); |
| 1100 scrollbar_controller_->DidScrollBegin(); |
| 1101 |
| 1102 base::TimeTicks time; |
| 1103 time += base::TimeDelta::FromSeconds(100); |
| 1104 scrollbar_controller_->Animate(time); |
| 1105 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 1106 scrollbar_controller_->DidScrollEnd(); |
| 1107 |
| 1108 EXPECT_TRUE(start_fade_.Equals(base::Closure())); |
| 1109 |
| 1110 time += base::TimeDelta::FromSeconds(100); |
| 1111 scrollbar_controller_->Animate(time); |
| 1112 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 1113 } |
| 1114 |
| 1115 TEST_F(ScrollbarAnimationControllerAndroidTest, HideOnResize) { |
| 1116 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); |
| 1117 ASSERT_TRUE(scroll_layer); |
| 1118 EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds()); |
| 1119 |
| 1120 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); |
| 1121 |
| 1122 // Shrink along X axis, horizontal scrollbar should appear. |
| 1123 clip_layer_->SetBounds(gfx::Size(100, 200)); |
| 1124 EXPECT_EQ(gfx::Size(100, 200), clip_layer_->bounds()); |
| 1125 |
| 1126 scrollbar_controller_->DidScrollBegin(); |
| 1127 |
| 1128 scrollbar_controller_->DidScrollUpdate(false); |
| 1129 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 1130 |
| 1131 scrollbar_controller_->DidScrollEnd(); |
| 1132 |
| 1133 // Shrink along Y axis and expand along X, horizontal scrollbar |
| 1134 // should disappear. |
| 1135 clip_layer_->SetBounds(gfx::Size(200, 100)); |
| 1136 EXPECT_EQ(gfx::Size(200, 100), clip_layer_->bounds()); |
| 1137 |
| 1138 scrollbar_controller_->DidScrollBegin(); |
| 1139 |
| 1140 scrollbar_controller_->DidScrollUpdate(false); |
| 1141 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 1142 |
| 1143 scrollbar_controller_->DidScrollEnd(); |
| 1144 } |
| 1145 |
| 1146 TEST_F(VerticalScrollbarAnimationControllerAndroidTest, HideOnResize) { |
| 1147 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); |
| 1148 ASSERT_TRUE(scroll_layer); |
| 1149 EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds()); |
| 1150 |
| 1151 EXPECT_EQ(VERTICAL, scrollbar_layer_->orientation()); |
| 1152 |
| 1153 // Shrink along X axis, vertical scrollbar should remain invisible. |
| 1154 clip_layer_->SetBounds(gfx::Size(100, 200)); |
| 1155 EXPECT_EQ(gfx::Size(100, 200), clip_layer_->bounds()); |
| 1156 |
| 1157 scrollbar_controller_->DidScrollBegin(); |
| 1158 |
| 1159 scrollbar_controller_->DidScrollUpdate(false); |
| 1160 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 1161 |
| 1162 scrollbar_controller_->DidScrollEnd(); |
| 1163 |
| 1164 // Shrink along Y axis and expand along X, vertical scrollbar should appear. |
| 1165 clip_layer_->SetBounds(gfx::Size(200, 100)); |
| 1166 EXPECT_EQ(gfx::Size(200, 100), clip_layer_->bounds()); |
| 1167 |
| 1168 scrollbar_controller_->DidScrollBegin(); |
| 1169 |
| 1170 scrollbar_controller_->DidScrollUpdate(false); |
| 1171 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 1172 |
| 1173 scrollbar_controller_->DidScrollEnd(); |
| 1174 } |
| 1175 |
| 1176 TEST_F(ScrollbarAnimationControllerAndroidTest, HideOnUserNonScrollableHorz) { |
| 1177 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); |
| 1178 |
| 1179 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); |
| 1180 ASSERT_TRUE(scroll_layer); |
| 1181 scroll_layer->set_user_scrollable_horizontal(false); |
| 1182 |
| 1183 scrollbar_controller_->DidScrollBegin(); |
| 1184 |
| 1185 scrollbar_controller_->DidScrollUpdate(false); |
| 1186 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 1187 |
| 1188 scrollbar_controller_->DidScrollEnd(); |
| 1189 } |
| 1190 |
| 1191 TEST_F(ScrollbarAnimationControllerAndroidTest, ShowOnUserNonScrollableVert) { |
| 1192 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); |
| 1193 |
| 1194 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); |
| 1195 ASSERT_TRUE(scroll_layer); |
| 1196 scroll_layer->set_user_scrollable_vertical(false); |
| 1197 |
| 1198 scrollbar_controller_->DidScrollBegin(); |
| 1199 |
| 1200 scrollbar_controller_->DidScrollUpdate(false); |
| 1201 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 1202 |
| 1203 scrollbar_controller_->DidScrollEnd(); |
| 1204 } |
| 1205 |
| 1206 TEST_F(VerticalScrollbarAnimationControllerAndroidTest, |
| 1207 HideOnUserNonScrollableVert) { |
| 1208 EXPECT_EQ(VERTICAL, scrollbar_layer_->orientation()); |
| 1209 |
| 1210 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); |
| 1211 ASSERT_TRUE(scroll_layer); |
| 1212 scroll_layer->set_user_scrollable_vertical(false); |
| 1213 |
| 1214 scrollbar_controller_->DidScrollBegin(); |
| 1215 |
| 1216 scrollbar_controller_->DidScrollUpdate(false); |
| 1217 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 1218 |
| 1219 scrollbar_controller_->DidScrollEnd(); |
| 1220 } |
| 1221 |
| 1222 TEST_F(VerticalScrollbarAnimationControllerAndroidTest, |
| 1223 ShowOnUserNonScrollableHorz) { |
| 1224 EXPECT_EQ(VERTICAL, scrollbar_layer_->orientation()); |
| 1225 |
| 1226 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); |
| 1227 ASSERT_TRUE(scroll_layer); |
| 1228 scroll_layer->set_user_scrollable_horizontal(false); |
| 1229 |
| 1230 scrollbar_controller_->DidScrollBegin(); |
| 1231 |
| 1232 scrollbar_controller_->DidScrollUpdate(false); |
| 1233 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 1234 |
| 1235 scrollbar_controller_->DidScrollEnd(); |
| 1236 } |
| 1237 |
| 1238 TEST_F(ScrollbarAnimationControllerAndroidTest, AwakenByScrollingGesture) { |
| 1239 base::TimeTicks time; |
| 1240 time += base::TimeDelta::FromSeconds(1); |
| 1241 scrollbar_controller_->DidScrollBegin(); |
| 1242 EXPECT_FALSE(did_request_animate_); |
| 1243 |
| 1244 scrollbar_controller_->DidScrollUpdate(false); |
| 1245 EXPECT_FALSE(did_request_animate_); |
| 1246 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 1247 |
| 1248 EXPECT_TRUE(start_fade_.Equals(base::Closure())); |
| 1249 |
| 1250 time += base::TimeDelta::FromSeconds(100); |
| 1251 |
| 1252 scrollbar_controller_->Animate(time); |
| 1253 EXPECT_FALSE(did_request_animate_); |
| 1254 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 1255 scrollbar_controller_->DidScrollEnd(); |
| 1256 EXPECT_FALSE(did_request_animate_); |
| 1257 start_fade_.Run(); |
| 1258 EXPECT_TRUE(did_request_animate_); |
| 1259 did_request_animate_ = false; |
| 1260 |
| 1261 time += base::TimeDelta::FromSeconds(2); |
| 1262 scrollbar_controller_->Animate(time); |
| 1263 EXPECT_TRUE(did_request_animate_); |
| 1264 did_request_animate_ = false; |
| 1265 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 1266 |
| 1267 time += base::TimeDelta::FromSeconds(1); |
| 1268 scrollbar_controller_->Animate(time); |
| 1269 EXPECT_TRUE(did_request_animate_); |
| 1270 did_request_animate_ = false; |
| 1271 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity()); |
| 1272 |
| 1273 time += base::TimeDelta::FromSeconds(1); |
| 1274 scrollbar_controller_->Animate(time); |
| 1275 EXPECT_TRUE(did_request_animate_); |
| 1276 did_request_animate_ = false; |
| 1277 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity()); |
| 1278 |
| 1279 time += base::TimeDelta::FromSeconds(1); |
| 1280 |
| 1281 scrollbar_controller_->DidScrollBegin(); |
| 1282 scrollbar_controller_->DidScrollUpdate(false); |
| 1283 scrollbar_controller_->DidScrollEnd(); |
| 1284 |
| 1285 start_fade_.Run(); |
| 1286 EXPECT_TRUE(did_request_animate_); |
| 1287 did_request_animate_ = false; |
| 1288 |
| 1289 time += base::TimeDelta::FromSeconds(2); |
| 1290 scrollbar_controller_->Animate(time); |
| 1291 EXPECT_TRUE(did_request_animate_); |
| 1292 did_request_animate_ = false; |
| 1293 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 1294 |
| 1295 time += base::TimeDelta::FromSeconds(1); |
| 1296 scrollbar_controller_->Animate(time); |
| 1297 EXPECT_TRUE(did_request_animate_); |
| 1298 did_request_animate_ = false; |
| 1299 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity()); |
| 1300 |
| 1301 time += base::TimeDelta::FromSeconds(1); |
| 1302 scrollbar_controller_->Animate(time); |
| 1303 EXPECT_TRUE(did_request_animate_); |
| 1304 did_request_animate_ = false; |
| 1305 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity()); |
| 1306 |
| 1307 time += base::TimeDelta::FromSeconds(1); |
| 1308 scrollbar_controller_->Animate(time); |
| 1309 EXPECT_FALSE(did_request_animate_); |
| 1310 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 1311 } |
| 1312 |
| 1313 TEST_F(ScrollbarAnimationControllerAndroidTest, AwakenByProgrammaticScroll) { |
| 1314 base::TimeTicks time; |
| 1315 time += base::TimeDelta::FromSeconds(1); |
| 1316 scrollbar_controller_->DidScrollUpdate(false); |
| 1317 EXPECT_FALSE(did_request_animate_); |
| 1318 |
| 1319 start_fade_.Run(); |
| 1320 EXPECT_TRUE(did_request_animate_); |
| 1321 did_request_animate_ = false; |
| 1322 scrollbar_controller_->Animate(time); |
| 1323 EXPECT_TRUE(did_request_animate_); |
| 1324 did_request_animate_ = false; |
| 1325 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 1326 |
| 1327 time += base::TimeDelta::FromSeconds(1); |
| 1328 scrollbar_controller_->Animate(time); |
| 1329 EXPECT_TRUE(did_request_animate_); |
| 1330 did_request_animate_ = false; |
| 1331 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity()); |
| 1332 scrollbar_controller_->DidScrollUpdate(false); |
| 1333 EXPECT_FALSE(did_request_animate_); |
| 1334 |
| 1335 start_fade_.Run(); |
| 1336 EXPECT_TRUE(did_request_animate_); |
| 1337 did_request_animate_ = false; |
| 1338 time += base::TimeDelta::FromSeconds(2); |
| 1339 scrollbar_controller_->Animate(time); |
| 1340 EXPECT_TRUE(did_request_animate_); |
| 1341 did_request_animate_ = false; |
| 1342 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 1343 |
| 1344 time += base::TimeDelta::FromSeconds(1); |
| 1345 scrollbar_controller_->Animate(time); |
| 1346 EXPECT_TRUE(did_request_animate_); |
| 1347 did_request_animate_ = false; |
| 1348 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity()); |
| 1349 |
| 1350 time += base::TimeDelta::FromSeconds(1); |
| 1351 scrollbar_controller_->Animate(time); |
| 1352 EXPECT_TRUE(did_request_animate_); |
| 1353 did_request_animate_ = false; |
| 1354 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity()); |
| 1355 |
| 1356 time += base::TimeDelta::FromSeconds(1); |
| 1357 scrollbar_controller_->DidScrollUpdate(false); |
| 1358 start_fade_.Run(); |
| 1359 time += base::TimeDelta::FromSeconds(1); |
| 1360 scrollbar_controller_->Animate(time); |
| 1361 EXPECT_TRUE(did_request_animate_); |
| 1362 did_request_animate_ = false; |
| 1363 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 1364 |
| 1365 time += base::TimeDelta::FromSeconds(1); |
| 1366 scrollbar_controller_->Animate(time); |
| 1367 EXPECT_TRUE(did_request_animate_); |
| 1368 did_request_animate_ = false; |
| 1369 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity()); |
| 1370 |
| 1371 time += base::TimeDelta::FromSeconds(1); |
| 1372 scrollbar_controller_->Animate(time); |
| 1373 EXPECT_TRUE(did_request_animate_); |
| 1374 did_request_animate_ = false; |
| 1375 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity()); |
| 1376 |
| 1377 time += base::TimeDelta::FromSeconds(1); |
| 1378 scrollbar_controller_->Animate(time); |
| 1379 EXPECT_FALSE(did_request_animate_); |
| 1380 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 1381 } |
| 1382 |
| 1383 TEST_F(ScrollbarAnimationControllerAndroidTest, |
| 1384 AnimationPreservedByNonScrollingGesture) { |
| 1385 base::TimeTicks time; |
| 1386 time += base::TimeDelta::FromSeconds(1); |
| 1387 scrollbar_controller_->DidScrollUpdate(false); |
| 1388 start_fade_.Run(); |
| 1389 EXPECT_TRUE(did_request_animate_); |
| 1390 did_request_animate_ = false; |
| 1391 scrollbar_controller_->Animate(time); |
| 1392 EXPECT_TRUE(did_request_animate_); |
| 1393 did_request_animate_ = false; |
| 1394 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 1395 |
| 1396 time += base::TimeDelta::FromSeconds(1); |
| 1397 scrollbar_controller_->Animate(time); |
| 1398 EXPECT_TRUE(did_request_animate_); |
| 1399 did_request_animate_ = false; |
| 1400 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity()); |
| 1401 |
| 1402 scrollbar_controller_->DidScrollBegin(); |
| 1403 EXPECT_FALSE(did_request_animate_); |
| 1404 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity()); |
| 1405 |
| 1406 time += base::TimeDelta::FromSeconds(1); |
| 1407 scrollbar_controller_->Animate(time); |
| 1408 EXPECT_TRUE(did_request_animate_); |
| 1409 did_request_animate_ = false; |
| 1410 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity()); |
| 1411 |
| 1412 scrollbar_controller_->DidScrollEnd(); |
| 1413 EXPECT_FALSE(did_request_animate_); |
| 1414 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity()); |
| 1415 |
| 1416 time += base::TimeDelta::FromSeconds(1); |
| 1417 scrollbar_controller_->Animate(time); |
| 1418 EXPECT_FALSE(did_request_animate_); |
| 1419 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 1420 } |
| 1421 |
| 1422 TEST_F(ScrollbarAnimationControllerAndroidTest, |
| 1423 AnimationOverriddenByScrollingGesture) { |
| 1424 base::TimeTicks time; |
| 1425 time += base::TimeDelta::FromSeconds(1); |
| 1426 scrollbar_controller_->DidScrollUpdate(false); |
| 1427 EXPECT_FALSE(did_request_animate_); |
| 1428 start_fade_.Run(); |
| 1429 EXPECT_TRUE(did_request_animate_); |
| 1430 did_request_animate_ = false; |
| 1431 scrollbar_controller_->Animate(time); |
| 1432 EXPECT_TRUE(did_request_animate_); |
| 1433 did_request_animate_ = false; |
| 1434 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 1435 |
| 1436 time += base::TimeDelta::FromSeconds(1); |
| 1437 scrollbar_controller_->Animate(time); |
| 1438 EXPECT_TRUE(did_request_animate_); |
| 1439 did_request_animate_ = false; |
| 1440 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity()); |
| 1441 |
| 1442 scrollbar_controller_->DidScrollBegin(); |
| 1443 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity()); |
| 1444 |
| 1445 time += base::TimeDelta::FromSeconds(1); |
| 1446 scrollbar_controller_->Animate(time); |
| 1447 EXPECT_TRUE(did_request_animate_); |
| 1448 did_request_animate_ = false; |
| 1449 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity()); |
| 1450 |
| 1451 time += base::TimeDelta::FromSeconds(1); |
| 1452 scrollbar_controller_->DidScrollUpdate(false); |
| 1453 EXPECT_FALSE(did_request_animate_); |
| 1454 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); |
| 1455 |
| 1456 time += base::TimeDelta::FromSeconds(1); |
| 1457 scrollbar_controller_->DidScrollEnd(); |
| 1458 EXPECT_FALSE(did_request_animate_); |
| 1459 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); |
| 1460 } |
| 1461 |
| 975 } // namespace | 1462 } // namespace |
| 976 } // namespace cc | 1463 } // namespace cc |
| OLD | NEW |