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 "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace cc { | 12 namespace cc { |
13 namespace { | 13 namespace { |
14 | 14 |
15 class ScrollbarAnimationControllerThinningTest : public testing::Test { | 15 class ScrollbarAnimationControllerThinningTest : public testing::Test { |
16 public: | 16 public: |
17 ScrollbarAnimationControllerThinningTest() : host_impl_(&proxy_) {} | 17 ScrollbarAnimationControllerThinningTest() : host_impl_(&proxy_) {} |
18 | 18 |
19 protected: | 19 protected: |
20 virtual void SetUp() { | 20 virtual void SetUp() { |
21 scroll_layer_ = LayerImpl::Create(host_impl_.active_tree(), 1); | 21 scroll_layer_ = LayerImpl::Create(host_impl_.active_tree(), 1); |
| 22 clip_layer_ = LayerImpl::Create(host_impl_.active_tree(), 3); |
| 23 scroll_layer_->SetScrollable(clip_layer_->id()); |
| 24 |
22 const int kId = 2; | 25 const int kId = 2; |
23 const int kThumbThickness = 10; | 26 const int kThumbThickness = 10; |
24 const bool kIsLeftSideVerticalScrollbar = false; | 27 const bool kIsLeftSideVerticalScrollbar = false; |
25 scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( | 28 scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( |
26 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, | 29 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, |
27 kIsLeftSideVerticalScrollbar); | 30 kIsLeftSideVerticalScrollbar); |
28 | 31 |
29 scroll_layer_->SetMaxScrollOffset(gfx::Vector2d(50, 50)); | 32 clip_layer_->SetBounds(gfx::Size(100, 100)); // MaxScrollOffset = (50, 50). |
| 33 clip_layer_->AddScrollbar(scrollbar_layer_.get()); |
30 scroll_layer_->SetBounds(gfx::Size(50, 50)); | 34 scroll_layer_->SetBounds(gfx::Size(50, 50)); |
31 scroll_layer_->SetHorizontalScrollbarLayer(scrollbar_layer_.get()); | 35 scroll_layer_->AddScrollbar(scrollbar_layer_.get()); |
32 | 36 |
33 scrollbar_controller_ = ScrollbarAnimationControllerThinning::CreateForTest( | 37 scrollbar_controller_ = ScrollbarAnimationControllerThinning::CreateForTest( |
34 scroll_layer_.get(), | 38 scroll_layer_.get(), |
35 base::TimeDelta::FromSeconds(2), | 39 base::TimeDelta::FromSeconds(2), |
36 base::TimeDelta::FromSeconds(3)); | 40 base::TimeDelta::FromSeconds(3)); |
| 41 |
| 42 clip_layer_->AddChild(scroll_layer_.Pass()); |
37 } | 43 } |
38 | 44 |
39 FakeImplProxy proxy_; | 45 FakeImplProxy proxy_; |
40 FakeLayerTreeHostImpl host_impl_; | 46 FakeLayerTreeHostImpl host_impl_; |
41 scoped_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; | 47 scoped_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; |
| 48 scoped_ptr<LayerImpl> clip_layer_; |
42 scoped_ptr<LayerImpl> scroll_layer_; | 49 scoped_ptr<LayerImpl> scroll_layer_; |
43 scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_; | 50 scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_; |
44 }; | 51 }; |
45 | 52 |
46 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) { | 53 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) { |
47 scrollbar_controller_->Animate(base::TimeTicks()); | 54 scrollbar_controller_->Animate(base::TimeTicks()); |
48 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); | 55 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); |
49 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); | 56 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); |
50 } | 57 } |
51 | 58 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor()); | 224 EXPECT_FLOAT_EQ(0.6f, scrollbar_layer_->thumb_thickness_scale_factor()); |
218 | 225 |
219 time += base::TimeDelta::FromSeconds(1); | 226 time += base::TimeDelta::FromSeconds(1); |
220 scrollbar_controller_->Animate(time); | 227 scrollbar_controller_->Animate(time); |
221 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); | 228 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); |
222 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); | 229 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); |
223 } | 230 } |
224 | 231 |
225 } // namespace | 232 } // namespace |
226 } // namespace cc | 233 } // namespace cc |
OLD | NEW |