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