| 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/animation/scrollbar_animation_controller_thinning.h" | 5 #include "cc/animation/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_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/test_shared_bitmap_manager.h" | 10 #include "cc/test/test_shared_bitmap_manager.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 scrollbar_layer_->SetScrollLayerAndClipLayerByIds(scroll_layer_ptr->id(), | 52 scrollbar_layer_->SetScrollLayerAndClipLayerByIds(scroll_layer_ptr->id(), |
| 53 clip_layer_->id()); | 53 clip_layer_->id()); |
| 54 clip_layer_->SetBounds(gfx::Size(100, 100)); | 54 clip_layer_->SetBounds(gfx::Size(100, 100)); |
| 55 scroll_layer_ptr->SetBounds(gfx::Size(50, 50)); | 55 scroll_layer_ptr->SetBounds(gfx::Size(50, 50)); |
| 56 | 56 |
| 57 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( | 57 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( |
| 58 scroll_layer_ptr, | 58 scroll_layer_ptr, |
| 59 this, | 59 this, |
| 60 base::TimeDelta::FromSeconds(2), | 60 base::TimeDelta::FromSeconds(2), |
| 61 base::TimeDelta::FromSeconds(5), |
| 61 base::TimeDelta::FromSeconds(3)); | 62 base::TimeDelta::FromSeconds(3)); |
| 62 } | 63 } |
| 63 | 64 |
| 64 FakeImplProxy proxy_; | 65 FakeImplProxy proxy_; |
| 65 TestSharedBitmapManager shared_bitmap_manager_; | 66 TestSharedBitmapManager shared_bitmap_manager_; |
| 66 FakeLayerTreeHostImpl host_impl_; | 67 FakeLayerTreeHostImpl host_impl_; |
| 67 scoped_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; | 68 scoped_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; |
| 68 scoped_ptr<LayerImpl> clip_layer_; | 69 scoped_ptr<LayerImpl> clip_layer_; |
| 69 scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_; | 70 scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_; |
| 70 | 71 |
| 71 base::Closure start_fade_; | 72 base::Closure start_fade_; |
| 72 }; | 73 }; |
| 73 | 74 |
| 74 // Check initialization of scrollbar. | 75 // Check initialization of scrollbar. |
| 75 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) { | 76 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) { |
| 76 scrollbar_controller_->Animate(base::TimeTicks()); | 77 scrollbar_controller_->Animate(base::TimeTicks()); |
| 77 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); | 78 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); |
| 78 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); | 79 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 79 } | 80 } |
| 80 | 81 |
| 81 // Scroll content. Confirm the scrollbar gets dark and then becomes light | 82 // Scroll content. Confirm the scrollbar gets dark and then becomes light |
| 82 // after stopping. | 83 // after stopping. |
| 83 TEST_F(ScrollbarAnimationControllerThinningTest, AwakenByProgrammaticScroll) { | 84 TEST_F(ScrollbarAnimationControllerThinningTest, AwakenByProgrammaticScroll) { |
| 84 base::TimeTicks time; | 85 base::TimeTicks time; |
| 85 time += base::TimeDelta::FromSeconds(1); | 86 time += base::TimeDelta::FromSeconds(1); |
| 86 scrollbar_controller_->DidScrollUpdate(); | 87 scrollbar_controller_->DidScrollUpdate(false); |
| 87 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 88 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
| 88 // Scrollbar doesn't change size if triggered by scroll. | 89 // Scrollbar doesn't change size if triggered by scroll. |
| 89 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); | 90 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 90 | 91 |
| 91 start_fade_.Run(); | 92 start_fade_.Run(); |
| 92 | 93 |
| 93 time += base::TimeDelta::FromSeconds(1); | 94 time += base::TimeDelta::FromSeconds(1); |
| 94 scrollbar_controller_->Animate(time); | 95 scrollbar_controller_->Animate(time); |
| 95 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 96 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
| 96 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); | 97 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 97 | 98 |
| 98 // Subsequent scroll restarts animation. | 99 // Subsequent scroll restarts animation. |
| 99 scrollbar_controller_->DidScrollUpdate(); | 100 scrollbar_controller_->DidScrollUpdate(false); |
| 100 | 101 |
| 101 start_fade_.Run(); | 102 start_fade_.Run(); |
| 102 | 103 |
| 103 time += base::TimeDelta::FromSeconds(2); | 104 time += base::TimeDelta::FromSeconds(2); |
| 104 scrollbar_controller_->Animate(time); | 105 scrollbar_controller_->Animate(time); |
| 105 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 106 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
| 106 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); | 107 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 107 | 108 |
| 108 time += base::TimeDelta::FromSeconds(1); | 109 time += base::TimeDelta::FromSeconds(1); |
| 109 scrollbar_controller_->Animate(time); | 110 scrollbar_controller_->Animate(time); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 127 base::TimeTicks time; | 128 base::TimeTicks time; |
| 128 time += base::TimeDelta::FromSeconds(1); | 129 time += base::TimeDelta::FromSeconds(1); |
| 129 | 130 |
| 130 scrollbar_controller_->DidMouseMoveNear(1); | 131 scrollbar_controller_->DidMouseMoveNear(1); |
| 131 scrollbar_controller_->Animate(time); | 132 scrollbar_controller_->Animate(time); |
| 132 time += base::TimeDelta::FromSeconds(3); | 133 time += base::TimeDelta::FromSeconds(3); |
| 133 | 134 |
| 134 scrollbar_controller_->Animate(time); | 135 scrollbar_controller_->Animate(time); |
| 135 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 136 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 136 | 137 |
| 137 scrollbar_controller_->DidScrollUpdate(); | 138 scrollbar_controller_->DidScrollUpdate(false); |
| 138 start_fade_.Run(); | 139 start_fade_.Run(); |
| 139 scrollbar_controller_->Animate(time); | 140 scrollbar_controller_->Animate(time); |
| 140 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 141 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
| 141 // Scrollbar should still be thick. | 142 // Scrollbar should still be thick. |
| 142 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 143 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 143 | 144 |
| 144 time += base::TimeDelta::FromSeconds(5); | 145 time += base::TimeDelta::FromSeconds(5); |
| 145 scrollbar_controller_->Animate(time); | 146 scrollbar_controller_->Animate(time); |
| 146 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); | 147 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); |
| 147 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 148 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 | 331 |
| 331 time += base::TimeDelta::FromSeconds(1); | 332 time += base::TimeDelta::FromSeconds(1); |
| 332 scrollbar_controller_->Animate(time); | 333 scrollbar_controller_->Animate(time); |
| 333 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); | 334 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); |
| 334 // The thickness now gets big again. | 335 // The thickness now gets big again. |
| 335 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 336 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 336 } | 337 } |
| 337 | 338 |
| 338 } // namespace | 339 } // namespace |
| 339 } // namespace cc | 340 } // namespace cc |
| OLD | NEW |