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