| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/animation/scrollbar_animation_controller_linear_fade.h" | 5 #include "cc/animation/scrollbar_animation_controller_linear_fade.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_proxy.h" | 8 #include "cc/test/fake_impl_proxy.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_shared_bitmap_manager.h" | 11 #include "cc/test/test_shared_bitmap_manager.h" |
| 12 #include "cc/trees/layer_tree_impl.h" | 12 #include "cc/trees/layer_tree_impl.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 class ScrollbarAnimationControllerLinearFadeTest | 18 class ScrollbarAnimationControllerLinearFadeTest |
| 19 : public testing::Test, | 19 : public testing::Test, |
| 20 public ScrollbarAnimationControllerClient { | 20 public ScrollbarAnimationControllerClient { |
| 21 public: | 21 public: |
| 22 ScrollbarAnimationControllerLinearFadeTest() | 22 ScrollbarAnimationControllerLinearFadeTest() |
| 23 : host_impl_(&proxy_, &shared_bitmap_manager_), needs_frame_count_(0) {} | 23 : host_impl_(&proxy_, &shared_bitmap_manager_) {} |
| 24 | 24 |
| 25 void PostDelayedScrollbarFade(const base::Closure& start_fade, | 25 void StartAnimatingScrollbarAnimationController( |
| 26 base::TimeDelta delay) override { | 26 ScrollbarAnimationController* controller) override { |
| 27 is_animating_ = true; |
| 28 } |
| 29 void StopAnimatingScrollbarAnimationController( |
| 30 ScrollbarAnimationController* controller) override { |
| 31 is_animating_ = false; |
| 32 } |
| 33 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade, |
| 34 base::TimeDelta delay) override { |
| 27 start_fade_ = start_fade; | 35 start_fade_ = start_fade; |
| 28 delay_ = delay; | 36 delay_ = delay; |
| 29 } | 37 } |
| 30 void SetNeedsScrollbarAnimationFrame() override { needs_frame_count_++; } | 38 void SetNeedsRedrawForScrollbarAnimation() override { |
| 39 did_request_redraw_ = true; |
| 40 } |
| 31 | 41 |
| 32 protected: | 42 protected: |
| 33 void SetUp() override { | 43 void SetUp() override { |
| 34 const int kThumbThickness = 10; | 44 const int kThumbThickness = 10; |
| 35 const int kTrackStart = 0; | 45 const int kTrackStart = 0; |
| 36 const bool kIsLeftSideVerticalScrollbar = false; | 46 const bool kIsLeftSideVerticalScrollbar = false; |
| 37 const bool kIsOverlayScrollbar = true; // Allow opacity animations. | 47 const bool kIsOverlayScrollbar = true; // Allow opacity animations. |
| 38 | 48 |
| 39 scoped_ptr<LayerImpl> scroll_layer = | 49 scoped_ptr<LayerImpl> scroll_layer = |
| 40 LayerImpl::Create(host_impl_.active_tree(), 1); | 50 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 41 scrollbar_layer_ = | 51 scrollbar_layer_ = |
| 42 SolidColorScrollbarLayerImpl::Create(host_impl_.active_tree(), | 52 SolidColorScrollbarLayerImpl::Create(host_impl_.active_tree(), |
| 43 2, | 53 2, |
| 44 orientation(), | 54 orientation(), |
| 45 kThumbThickness, | 55 kThumbThickness, |
| 46 kTrackStart, | 56 kTrackStart, |
| 47 kIsLeftSideVerticalScrollbar, | 57 kIsLeftSideVerticalScrollbar, |
| 48 kIsOverlayScrollbar); | 58 kIsOverlayScrollbar); |
| 49 clip_layer_ = LayerImpl::Create(host_impl_.active_tree(), 3); | 59 clip_layer_ = LayerImpl::Create(host_impl_.active_tree(), 3); |
| 50 scroll_layer->SetScrollClipLayer(clip_layer_->id()); | 60 scroll_layer->SetScrollClipLayer(clip_layer_->id()); |
| 51 LayerImpl* scroll_layer_ptr = scroll_layer.get(); | 61 LayerImpl* scroll_layer_ptr = scroll_layer.get(); |
| 52 clip_layer_->AddChild(scroll_layer.Pass()); | 62 clip_layer_->AddChild(scroll_layer.Pass()); |
| 53 | 63 |
| 54 scrollbar_layer_->SetScrollLayerAndClipLayerByIds(scroll_layer_ptr->id(), | 64 scrollbar_layer_->SetScrollLayerAndClipLayerByIds(scroll_layer_ptr->id(), |
| 55 clip_layer_->id()); | 65 clip_layer_->id()); |
| 56 clip_layer_->SetBounds(gfx::Size(100, 100)); | 66 clip_layer_->SetBounds(gfx::Size(100, 100)); |
| 57 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); | 67 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
| 58 | 68 |
| 59 scrollbar_controller_ = ScrollbarAnimationControllerLinearFade::Create( | 69 scrollbar_controller_ = ScrollbarAnimationControllerLinearFade::Create( |
| 60 scroll_layer_ptr, | 70 scroll_layer_ptr, this, base::TimeDelta::FromSeconds(2), |
| 61 this, | 71 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(3)); |
| 62 base::TimeDelta::FromSeconds(2), | |
| 63 base::TimeDelta::FromSeconds(5), | |
| 64 base::TimeDelta::FromSeconds(3)); | |
| 65 } | 72 } |
| 66 | 73 |
| 67 virtual ScrollbarOrientation orientation() const { return HORIZONTAL; } | 74 virtual ScrollbarOrientation orientation() const { return HORIZONTAL; } |
| 68 | 75 |
| 69 FakeImplProxy proxy_; | 76 FakeImplProxy proxy_; |
| 70 TestSharedBitmapManager shared_bitmap_manager_; | 77 TestSharedBitmapManager shared_bitmap_manager_; |
| 71 FakeLayerTreeHostImpl host_impl_; | 78 FakeLayerTreeHostImpl host_impl_; |
| 72 scoped_ptr<ScrollbarAnimationControllerLinearFade> scrollbar_controller_; | 79 scoped_ptr<ScrollbarAnimationControllerLinearFade> scrollbar_controller_; |
| 73 scoped_ptr<LayerImpl> clip_layer_; | 80 scoped_ptr<LayerImpl> clip_layer_; |
| 74 scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_; | 81 scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_; |
| 75 | 82 |
| 76 base::Closure start_fade_; | 83 base::Closure start_fade_; |
| 77 base::TimeDelta delay_; | 84 base::TimeDelta delay_; |
| 78 int needs_frame_count_; | 85 bool is_animating_; |
| 86 bool did_request_redraw_; |
| 79 }; | 87 }; |
| 80 | 88 |
| 81 class VerticalScrollbarAnimationControllerLinearFadeTest | 89 class VerticalScrollbarAnimationControllerLinearFadeTest |
| 82 : public ScrollbarAnimationControllerLinearFadeTest { | 90 : public ScrollbarAnimationControllerLinearFadeTest { |
| 83 protected: | 91 protected: |
| 84 ScrollbarOrientation orientation() const override { return VERTICAL; } | 92 ScrollbarOrientation orientation() const override { return VERTICAL; } |
| 85 }; | 93 }; |
| 86 | 94 |
| 87 TEST_F(ScrollbarAnimationControllerLinearFadeTest, DelayAnimationOnResize) { | 95 TEST_F(ScrollbarAnimationControllerLinearFadeTest, DelayAnimationOnResize) { |
| 88 scrollbar_layer_->SetOpacity(0.0f); | 96 scrollbar_layer_->SetOpacity(0.0f); |
| 89 scrollbar_controller_->DidScrollBegin(); | 97 scrollbar_controller_->DidScrollBegin(); |
| 90 scrollbar_controller_->DidScrollUpdate(true); | 98 scrollbar_controller_->DidScrollUpdate(true); |
| 91 scrollbar_controller_->DidScrollEnd(); | 99 scrollbar_controller_->DidScrollEnd(); |
| 92 // Normal Animation delay of 2 seconds. | 100 // Normal Animation delay of 2 seconds. |
| 93 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 101 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
| 94 EXPECT_EQ(delay_, base::TimeDelta::FromSeconds(2)); | 102 EXPECT_EQ(delay_, base::TimeDelta::FromSeconds(2)); |
| 95 | 103 |
| 96 scrollbar_layer_->SetOpacity(0.0f); | 104 scrollbar_layer_->SetOpacity(0.0f); |
| 97 scrollbar_controller_->DidScrollUpdate(true); | 105 scrollbar_controller_->DidScrollUpdate(true); |
| 98 // Delay animation on resize to 5 seconds. | 106 // Delay animation on resize to 5 seconds. |
| 99 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 107 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
| 100 EXPECT_EQ(delay_, base::TimeDelta::FromSeconds(5)); | 108 EXPECT_EQ(delay_, base::TimeDelta::FromSeconds(5)); |
| 101 } | 109 } |
| 102 | 110 |
| 103 TEST_F(ScrollbarAnimationControllerLinearFadeTest, HiddenInBegin) { | 111 TEST_F(ScrollbarAnimationControllerLinearFadeTest, HiddenInBegin) { |
| 104 scrollbar_layer_->SetOpacity(0.0f); | 112 scrollbar_layer_->SetOpacity(0.0f); |
| 105 scrollbar_controller_->Animate(base::TimeTicks()); | 113 scrollbar_controller_->Animate(base::TimeTicks()); |
| 106 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | 114 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); |
| 107 EXPECT_EQ(0, needs_frame_count_); | |
| 108 } | 115 } |
| 109 | 116 |
| 110 TEST_F(ScrollbarAnimationControllerLinearFadeTest, | 117 TEST_F(ScrollbarAnimationControllerLinearFadeTest, |
| 111 HiddenAfterNonScrollingGesture) { | 118 HiddenAfterNonScrollingGesture) { |
| 112 scrollbar_layer_->SetOpacity(0.0f); | 119 scrollbar_layer_->SetOpacity(0.0f); |
| 113 scrollbar_controller_->DidScrollBegin(); | 120 scrollbar_controller_->DidScrollBegin(); |
| 114 | 121 |
| 115 base::TimeTicks time; | 122 base::TimeTicks time; |
| 116 time += base::TimeDelta::FromSeconds(100); | 123 time += base::TimeDelta::FromSeconds(100); |
| 117 scrollbar_controller_->Animate(time); | 124 scrollbar_controller_->Animate(time); |
| 118 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | 125 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); |
| 119 scrollbar_controller_->DidScrollEnd(); | 126 scrollbar_controller_->DidScrollEnd(); |
| 120 | 127 |
| 121 EXPECT_TRUE(start_fade_.Equals(base::Closure())); | 128 EXPECT_TRUE(start_fade_.Equals(base::Closure())); |
| 122 | 129 |
| 123 time += base::TimeDelta::FromSeconds(100); | 130 time += base::TimeDelta::FromSeconds(100); |
| 124 scrollbar_controller_->Animate(time); | 131 scrollbar_controller_->Animate(time); |
| 125 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | 132 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); |
| 126 | |
| 127 EXPECT_EQ(0, needs_frame_count_); | |
| 128 } | 133 } |
| 129 | 134 |
| 130 TEST_F(ScrollbarAnimationControllerLinearFadeTest, HideOnResize) { | 135 TEST_F(ScrollbarAnimationControllerLinearFadeTest, HideOnResize) { |
| 131 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); | 136 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); |
| 132 ASSERT_TRUE(scroll_layer); | 137 ASSERT_TRUE(scroll_layer); |
| 133 EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds()); | 138 EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds()); |
| 134 | 139 |
| 135 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); | 140 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); |
| 136 | 141 |
| 137 // Shrink along X axis, horizontal scrollbar should appear. | 142 // Shrink along X axis, horizontal scrollbar should appear. |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 base::TimeTicks time; | 261 base::TimeTicks time; |
| 257 time += base::TimeDelta::FromSeconds(1); | 262 time += base::TimeDelta::FromSeconds(1); |
| 258 scrollbar_controller_->DidScrollBegin(); | 263 scrollbar_controller_->DidScrollBegin(); |
| 259 | 264 |
| 260 scrollbar_controller_->DidScrollUpdate(false); | 265 scrollbar_controller_->DidScrollUpdate(false); |
| 261 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 266 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
| 262 | 267 |
| 263 EXPECT_TRUE(start_fade_.Equals(base::Closure())); | 268 EXPECT_TRUE(start_fade_.Equals(base::Closure())); |
| 264 | 269 |
| 265 time += base::TimeDelta::FromSeconds(100); | 270 time += base::TimeDelta::FromSeconds(100); |
| 271 |
| 266 scrollbar_controller_->Animate(time); | 272 scrollbar_controller_->Animate(time); |
| 267 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 273 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
| 268 scrollbar_controller_->DidScrollEnd(); | 274 scrollbar_controller_->DidScrollEnd(); |
| 269 start_fade_.Run(); | 275 start_fade_.Run(); |
| 270 | 276 |
| 271 time += base::TimeDelta::FromSeconds(2); | 277 time += base::TimeDelta::FromSeconds(2); |
| 278 EXPECT_TRUE(is_animating_); |
| 272 scrollbar_controller_->Animate(time); | 279 scrollbar_controller_->Animate(time); |
| 273 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 280 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
| 274 | 281 |
| 275 time += base::TimeDelta::FromSeconds(1); | 282 time += base::TimeDelta::FromSeconds(1); |
| 283 EXPECT_TRUE(is_animating_); |
| 276 scrollbar_controller_->Animate(time); | 284 scrollbar_controller_->Animate(time); |
| 277 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); | 285 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); |
| 278 | 286 |
| 279 time += base::TimeDelta::FromSeconds(1); | 287 time += base::TimeDelta::FromSeconds(1); |
| 288 EXPECT_TRUE(is_animating_); |
| 280 scrollbar_controller_->Animate(time); | 289 scrollbar_controller_->Animate(time); |
| 281 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); | 290 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); |
| 282 | 291 |
| 283 time += base::TimeDelta::FromSeconds(1); | 292 time += base::TimeDelta::FromSeconds(1); |
| 284 | 293 |
| 285 scrollbar_controller_->DidScrollBegin(); | 294 scrollbar_controller_->DidScrollBegin(); |
| 286 scrollbar_controller_->DidScrollUpdate(false); | 295 scrollbar_controller_->DidScrollUpdate(false); |
| 287 scrollbar_controller_->DidScrollEnd(); | 296 scrollbar_controller_->DidScrollEnd(); |
| 297 |
| 288 start_fade_.Run(); | 298 start_fade_.Run(); |
| 289 | 299 |
| 290 time += base::TimeDelta::FromSeconds(2); | 300 time += base::TimeDelta::FromSeconds(2); |
| 301 EXPECT_TRUE(is_animating_); |
| 291 scrollbar_controller_->Animate(time); | 302 scrollbar_controller_->Animate(time); |
| 292 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 303 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
| 293 | 304 |
| 294 time += base::TimeDelta::FromSeconds(1); | 305 time += base::TimeDelta::FromSeconds(1); |
| 306 EXPECT_TRUE(is_animating_); |
| 295 scrollbar_controller_->Animate(time); | 307 scrollbar_controller_->Animate(time); |
| 296 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); | 308 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); |
| 297 | 309 |
| 298 time += base::TimeDelta::FromSeconds(1); | 310 time += base::TimeDelta::FromSeconds(1); |
| 311 EXPECT_TRUE(is_animating_); |
| 299 scrollbar_controller_->Animate(time); | 312 scrollbar_controller_->Animate(time); |
| 300 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); | 313 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); |
| 301 | 314 |
| 302 time += base::TimeDelta::FromSeconds(1); | 315 time += base::TimeDelta::FromSeconds(1); |
| 316 EXPECT_TRUE(is_animating_); |
| 303 scrollbar_controller_->Animate(time); | 317 scrollbar_controller_->Animate(time); |
| 304 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | 318 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); |
| 305 | 319 EXPECT_FALSE(is_animating_); |
| 306 EXPECT_EQ(8, needs_frame_count_); | |
| 307 } | 320 } |
| 308 | 321 |
| 309 TEST_F(ScrollbarAnimationControllerLinearFadeTest, AwakenByProgrammaticScroll) { | 322 TEST_F(ScrollbarAnimationControllerLinearFadeTest, AwakenByProgrammaticScroll) { |
| 310 base::TimeTicks time; | 323 base::TimeTicks time; |
| 311 time += base::TimeDelta::FromSeconds(1); | 324 time += base::TimeDelta::FromSeconds(1); |
| 312 scrollbar_controller_->DidScrollUpdate(false); | 325 scrollbar_controller_->DidScrollUpdate(false); |
| 326 |
| 313 start_fade_.Run(); | 327 start_fade_.Run(); |
| 328 EXPECT_TRUE(is_animating_); |
| 314 scrollbar_controller_->Animate(time); | 329 scrollbar_controller_->Animate(time); |
| 315 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 330 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
| 316 | 331 |
| 317 time += base::TimeDelta::FromSeconds(1); | 332 time += base::TimeDelta::FromSeconds(1); |
| 333 EXPECT_TRUE(is_animating_); |
| 318 scrollbar_controller_->Animate(time); | 334 scrollbar_controller_->Animate(time); |
| 319 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); | 335 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); |
| 320 scrollbar_controller_->DidScrollUpdate(false); | 336 scrollbar_controller_->DidScrollUpdate(false); |
| 337 |
| 321 start_fade_.Run(); | 338 start_fade_.Run(); |
| 322 | 339 time += base::TimeDelta::FromSeconds(2); |
| 323 time += base::TimeDelta::FromSeconds(1); | 340 EXPECT_TRUE(is_animating_); |
| 324 scrollbar_controller_->Animate(time); | 341 scrollbar_controller_->Animate(time); |
| 325 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 342 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
| 326 | 343 |
| 327 time += base::TimeDelta::FromSeconds(1); | 344 time += base::TimeDelta::FromSeconds(1); |
| 345 EXPECT_TRUE(is_animating_); |
| 328 scrollbar_controller_->Animate(time); | 346 scrollbar_controller_->Animate(time); |
| 329 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); | 347 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); |
| 330 | 348 |
| 331 time += base::TimeDelta::FromSeconds(1); | 349 time += base::TimeDelta::FromSeconds(1); |
| 350 EXPECT_TRUE(is_animating_); |
| 332 scrollbar_controller_->Animate(time); | 351 scrollbar_controller_->Animate(time); |
| 333 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); | 352 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); |
| 334 | 353 |
| 335 time += base::TimeDelta::FromSeconds(1); | 354 time += base::TimeDelta::FromSeconds(1); |
| 336 scrollbar_controller_->DidScrollUpdate(false); | 355 scrollbar_controller_->DidScrollUpdate(false); |
| 337 start_fade_.Run(); | 356 start_fade_.Run(); |
| 338 time += base::TimeDelta::FromSeconds(1); | 357 time += base::TimeDelta::FromSeconds(1); |
| 358 EXPECT_TRUE(is_animating_); |
| 339 scrollbar_controller_->Animate(time); | 359 scrollbar_controller_->Animate(time); |
| 340 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 360 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
| 341 | 361 |
| 342 time += base::TimeDelta::FromSeconds(1); | 362 time += base::TimeDelta::FromSeconds(1); |
| 363 EXPECT_TRUE(is_animating_); |
| 343 scrollbar_controller_->Animate(time); | 364 scrollbar_controller_->Animate(time); |
| 344 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); | 365 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); |
| 345 | 366 |
| 346 time += base::TimeDelta::FromSeconds(1); | 367 time += base::TimeDelta::FromSeconds(1); |
| 368 EXPECT_TRUE(is_animating_); |
| 347 scrollbar_controller_->Animate(time); | 369 scrollbar_controller_->Animate(time); |
| 348 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); | 370 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); |
| 349 | 371 |
| 350 time += base::TimeDelta::FromSeconds(1); | 372 time += base::TimeDelta::FromSeconds(1); |
| 373 EXPECT_TRUE(is_animating_); |
| 351 scrollbar_controller_->Animate(time); | 374 scrollbar_controller_->Animate(time); |
| 352 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | 375 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); |
| 353 | 376 EXPECT_FALSE(is_animating_); |
| 354 EXPECT_EQ(11, needs_frame_count_); | |
| 355 } | 377 } |
| 356 | 378 |
| 357 TEST_F(ScrollbarAnimationControllerLinearFadeTest, | 379 TEST_F(ScrollbarAnimationControllerLinearFadeTest, |
| 358 AnimationPreservedByNonScrollingGesture) { | 380 AnimationPreservedByNonScrollingGesture) { |
| 359 base::TimeTicks time; | 381 base::TimeTicks time; |
| 360 time += base::TimeDelta::FromSeconds(1); | 382 time += base::TimeDelta::FromSeconds(1); |
| 361 scrollbar_controller_->DidScrollUpdate(false); | 383 scrollbar_controller_->DidScrollUpdate(false); |
| 362 start_fade_.Run(); | 384 start_fade_.Run(); |
| 385 EXPECT_TRUE(is_animating_); |
| 363 scrollbar_controller_->Animate(time); | 386 scrollbar_controller_->Animate(time); |
| 364 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 387 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
| 365 | 388 |
| 366 time += base::TimeDelta::FromSeconds(1); | 389 time += base::TimeDelta::FromSeconds(1); |
| 390 EXPECT_TRUE(is_animating_); |
| 367 scrollbar_controller_->Animate(time); | 391 scrollbar_controller_->Animate(time); |
| 368 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); | 392 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); |
| 369 | 393 |
| 370 scrollbar_controller_->DidScrollBegin(); | 394 scrollbar_controller_->DidScrollBegin(); |
| 371 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); | 395 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); |
| 372 | 396 |
| 373 time += base::TimeDelta::FromSeconds(1); | 397 time += base::TimeDelta::FromSeconds(1); |
| 398 EXPECT_TRUE(is_animating_); |
| 374 scrollbar_controller_->Animate(time); | 399 scrollbar_controller_->Animate(time); |
| 375 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); | 400 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); |
| 376 | 401 |
| 377 scrollbar_controller_->DidScrollEnd(); | 402 scrollbar_controller_->DidScrollEnd(); |
| 378 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); | 403 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); |
| 379 | 404 |
| 380 time += base::TimeDelta::FromSeconds(1); | 405 time += base::TimeDelta::FromSeconds(1); |
| 406 EXPECT_TRUE(is_animating_); |
| 381 scrollbar_controller_->Animate(time); | 407 scrollbar_controller_->Animate(time); |
| 382 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); | 408 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); |
| 383 | 409 EXPECT_FALSE(is_animating_); |
| 384 scrollbar_controller_->Animate(time); | |
| 385 | |
| 386 EXPECT_EQ(4, needs_frame_count_); | |
| 387 } | 410 } |
| 388 | 411 |
| 389 TEST_F(ScrollbarAnimationControllerLinearFadeTest, | 412 TEST_F(ScrollbarAnimationControllerLinearFadeTest, |
| 390 AnimationOverriddenByScrollingGesture) { | 413 AnimationOverriddenByScrollingGesture) { |
| 391 base::TimeTicks time; | 414 base::TimeTicks time; |
| 392 time += base::TimeDelta::FromSeconds(1); | 415 time += base::TimeDelta::FromSeconds(1); |
| 393 scrollbar_controller_->DidScrollUpdate(false); | 416 scrollbar_controller_->DidScrollUpdate(false); |
| 394 start_fade_.Run(); | 417 start_fade_.Run(); |
| 418 EXPECT_TRUE(is_animating_); |
| 395 scrollbar_controller_->Animate(time); | 419 scrollbar_controller_->Animate(time); |
| 396 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 420 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
| 397 | 421 |
| 398 time += base::TimeDelta::FromSeconds(1); | 422 time += base::TimeDelta::FromSeconds(1); |
| 423 EXPECT_TRUE(is_animating_); |
| 399 scrollbar_controller_->Animate(time); | 424 scrollbar_controller_->Animate(time); |
| 400 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); | 425 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); |
| 401 | 426 |
| 402 scrollbar_controller_->DidScrollBegin(); | 427 scrollbar_controller_->DidScrollBegin(); |
| 403 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); | 428 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->opacity()); |
| 404 | 429 |
| 405 time += base::TimeDelta::FromSeconds(1); | 430 time += base::TimeDelta::FromSeconds(1); |
| 431 EXPECT_TRUE(is_animating_); |
| 406 scrollbar_controller_->Animate(time); | 432 scrollbar_controller_->Animate(time); |
| 407 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); | 433 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->opacity()); |
| 408 | 434 |
| 409 time += base::TimeDelta::FromSeconds(1); | 435 time += base::TimeDelta::FromSeconds(1); |
| 410 scrollbar_controller_->DidScrollUpdate(false); | 436 scrollbar_controller_->DidScrollUpdate(false); |
| 411 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity()); | 437 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity()); |
| 412 | 438 |
| 413 time += base::TimeDelta::FromSeconds(1); | 439 time += base::TimeDelta::FromSeconds(1); |
| 414 scrollbar_controller_->DidScrollEnd(); | 440 scrollbar_controller_->DidScrollEnd(); |
| 415 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity()); | 441 EXPECT_FLOAT_EQ(1, scrollbar_layer_->opacity()); |
| 416 } | 442 } |
| 417 | 443 |
| 418 } // namespace | 444 } // namespace |
| 419 } // namespace cc | 445 } // namespace cc |
| OLD | NEW |