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/geometry_test_utils.h" |
10 #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" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 namespace cc { | 15 namespace cc { |
14 namespace { | 16 namespace { |
15 | 17 |
16 class ScrollbarAnimationControllerThinningTest | 18 class ScrollbarAnimationControllerThinningTest |
17 : public testing::Test, | 19 : public testing::Test, |
18 public ScrollbarAnimationControllerClient { | 20 public ScrollbarAnimationControllerClient { |
19 public: | 21 public: |
20 ScrollbarAnimationControllerThinningTest() | 22 ScrollbarAnimationControllerThinningTest() |
(...skipping 24 matching lines...) Expand all Loading... |
45 kId, | 47 kId, |
46 HORIZONTAL, | 48 HORIZONTAL, |
47 kThumbThickness, | 49 kThumbThickness, |
48 kTrackStart, | 50 kTrackStart, |
49 kIsLeftSideVerticalScrollbar, | 51 kIsLeftSideVerticalScrollbar, |
50 kIsOverlayScrollbar); | 52 kIsOverlayScrollbar); |
51 | 53 |
52 scrollbar_layer_->SetScrollLayerAndClipLayerByIds(scroll_layer_ptr->id(), | 54 scrollbar_layer_->SetScrollLayerAndClipLayerByIds(scroll_layer_ptr->id(), |
53 clip_layer_->id()); | 55 clip_layer_->id()); |
54 clip_layer_->SetBounds(gfx::Size(100, 100)); | 56 clip_layer_->SetBounds(gfx::Size(100, 100)); |
55 scroll_layer_ptr->SetBounds(gfx::Size(50, 50)); | 57 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
56 | 58 |
57 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( | 59 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( |
58 scroll_layer_ptr, | 60 scroll_layer_ptr, |
59 this, | 61 this, |
60 base::TimeDelta::FromSeconds(2), | 62 base::TimeDelta::FromSeconds(2), |
61 base::TimeDelta::FromSeconds(5), | 63 base::TimeDelta::FromSeconds(5), |
62 base::TimeDelta::FromSeconds(3)); | 64 base::TimeDelta::FromSeconds(3)); |
63 } | 65 } |
64 | 66 |
65 FakeImplProxy proxy_; | 67 FakeImplProxy proxy_; |
66 TestSharedBitmapManager shared_bitmap_manager_; | 68 TestSharedBitmapManager shared_bitmap_manager_; |
67 FakeLayerTreeHostImpl host_impl_; | 69 FakeLayerTreeHostImpl host_impl_; |
68 scoped_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; | 70 scoped_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; |
69 scoped_ptr<LayerImpl> clip_layer_; | 71 scoped_ptr<LayerImpl> clip_layer_; |
70 scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_; | 72 scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_; |
71 | 73 |
72 base::Closure start_fade_; | 74 base::Closure start_fade_; |
73 }; | 75 }; |
74 | 76 |
75 // Check initialization of scrollbar. | 77 // Check initialization of scrollbar. |
76 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) { | 78 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) { |
77 scrollbar_controller_->Animate(base::TimeTicks()); | 79 scrollbar_controller_->Animate(base::TimeTicks()); |
78 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); | 80 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); |
79 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); | 81 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); |
80 } | 82 } |
81 | 83 |
| 84 // Check that scrollbar disappears when the layer becomes non-scrollable. |
| 85 TEST_F(ScrollbarAnimationControllerThinningTest, HideOnResize) { |
| 86 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); |
| 87 ASSERT_TRUE(scroll_layer); |
| 88 EXPECT_SIZE_EQ(gfx::Size(200, 200), scroll_layer->bounds()); |
| 89 |
| 90 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); |
| 91 |
| 92 // Shrink along X axis, horizontal scrollbar should appear. |
| 93 clip_layer_->SetBounds(gfx::Size(100, 200)); |
| 94 EXPECT_SIZE_EQ(gfx::Size(100, 200), clip_layer_->bounds()); |
| 95 |
| 96 scrollbar_controller_->DidScrollBegin(); |
| 97 |
| 98 scrollbar_controller_->DidScrollUpdate(false); |
| 99 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
| 100 |
| 101 scrollbar_controller_->DidScrollEnd(); |
| 102 |
| 103 // Shrink along Y axis and expand along X, horizontal scrollbar |
| 104 // should disappear. |
| 105 clip_layer_->SetBounds(gfx::Size(200, 100)); |
| 106 EXPECT_SIZE_EQ(gfx::Size(200, 100), clip_layer_->bounds()); |
| 107 |
| 108 scrollbar_controller_->DidScrollBegin(); |
| 109 |
| 110 scrollbar_controller_->DidScrollUpdate(false); |
| 111 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->opacity()); |
| 112 |
| 113 scrollbar_controller_->DidScrollEnd(); |
| 114 } |
| 115 |
82 // Scroll content. Confirm the scrollbar gets dark and then becomes light | 116 // Scroll content. Confirm the scrollbar gets dark and then becomes light |
83 // after stopping. | 117 // after stopping. |
84 TEST_F(ScrollbarAnimationControllerThinningTest, AwakenByProgrammaticScroll) { | 118 TEST_F(ScrollbarAnimationControllerThinningTest, AwakenByProgrammaticScroll) { |
85 base::TimeTicks time; | 119 base::TimeTicks time; |
86 time += base::TimeDelta::FromSeconds(1); | 120 time += base::TimeDelta::FromSeconds(1); |
87 scrollbar_controller_->DidScrollUpdate(false); | 121 scrollbar_controller_->DidScrollUpdate(false); |
88 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); | 122 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->opacity()); |
89 // Scrollbar doesn't change size if triggered by scroll. | 123 // Scrollbar doesn't change size if triggered by scroll. |
90 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); | 124 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); |
91 | 125 |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 365 |
332 time += base::TimeDelta::FromSeconds(1); | 366 time += base::TimeDelta::FromSeconds(1); |
333 scrollbar_controller_->Animate(time); | 367 scrollbar_controller_->Animate(time); |
334 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); | 368 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->opacity()); |
335 // The thickness now gets big again. | 369 // The thickness now gets big again. |
336 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 370 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
337 } | 371 } |
338 | 372 |
339 } // namespace | 373 } // namespace |
340 } // namespace cc | 374 } // namespace cc |
OLD | NEW |