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/single_scrollbar_animation_controller_thinning.h" | 5 #include "cc/input/single_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 17 matching lines...) Expand all Loading... | |
28 kDefaultMouseMoveDistanceToTriggerAnimation; | 28 kDefaultMouseMoveDistanceToTriggerAnimation; |
29 | 29 |
30 class MockSingleScrollbarAnimationControllerClient | 30 class MockSingleScrollbarAnimationControllerClient |
31 : public ScrollbarAnimationControllerClient { | 31 : public ScrollbarAnimationControllerClient { |
32 public: | 32 public: |
33 explicit MockSingleScrollbarAnimationControllerClient( | 33 explicit MockSingleScrollbarAnimationControllerClient( |
34 LayerTreeHostImpl* host_impl) | 34 LayerTreeHostImpl* host_impl) |
35 : host_impl_(host_impl) {} | 35 : host_impl_(host_impl) {} |
36 virtual ~MockSingleScrollbarAnimationControllerClient() {} | 36 virtual ~MockSingleScrollbarAnimationControllerClient() {} |
37 | 37 |
38 ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override { | 38 ScrollbarSet ScrollbarsFor(ElementId scroll_element_id) const override { |
39 return host_impl_->ScrollbarsFor(scroll_layer_id); | 39 return host_impl_->ScrollbarsFor(scroll_element_id); |
40 } | 40 } |
41 | 41 |
42 MOCK_METHOD2(PostDelayedScrollbarAnimationTask, | 42 MOCK_METHOD2(PostDelayedScrollbarAnimationTask, |
43 void(const base::Closure& start_fade, base::TimeDelta delay)); | 43 void(const base::Closure& start_fade, base::TimeDelta delay)); |
44 MOCK_METHOD0(SetNeedsRedrawForScrollbarAnimation, void()); | 44 MOCK_METHOD0(SetNeedsRedrawForScrollbarAnimation, void()); |
45 MOCK_METHOD0(SetNeedsAnimateForScrollbarAnimation, void()); | 45 MOCK_METHOD0(SetNeedsAnimateForScrollbarAnimation, void()); |
46 MOCK_METHOD0(DidChangeScrollbarVisibility, void()); | 46 MOCK_METHOD0(DidChangeScrollbarVisibility, void()); |
47 MOCK_METHOD0(start_fade, base::Closure()); | 47 MOCK_METHOD0(start_fade, base::Closure()); |
48 MOCK_METHOD0(delay, base::TimeDelta()); | 48 MOCK_METHOD0(delay, base::TimeDelta()); |
49 | 49 |
50 private: | 50 private: |
51 LayerTreeHostImpl* host_impl_; | 51 LayerTreeHostImpl* host_impl_; |
52 }; | 52 }; |
53 | 53 |
54 class SingleScrollbarAnimationControllerThinningTest : public testing::Test { | 54 class SingleScrollbarAnimationControllerThinningTest : public testing::Test { |
55 public: | 55 public: |
56 SingleScrollbarAnimationControllerThinningTest() | 56 SingleScrollbarAnimationControllerThinningTest() |
57 : host_impl_(&task_runner_provider_, &task_graph_runner_), | 57 : host_impl_(&task_runner_provider_, &task_graph_runner_), |
58 client_(&host_impl_) {} | 58 client_(&host_impl_) {} |
59 | 59 |
60 protected: | 60 protected: |
61 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2); | 61 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2); |
62 | 62 |
63 void SetUp() override { | 63 void SetUp() override { |
64 std::unique_ptr<LayerImpl> scroll_layer = | 64 std::unique_ptr<LayerImpl> scroll_layer = |
65 LayerImpl::Create(host_impl_.active_tree(), 1); | 65 LayerImpl::Create(host_impl_.active_tree(), 1); |
66 std::unique_ptr<LayerImpl> clip = | 66 std::unique_ptr<LayerImpl> clip = |
67 LayerImpl::Create(host_impl_.active_tree(), 3); | 67 LayerImpl::Create(host_impl_.active_tree(), 3); |
68 scroll_layer->SetElementId( | |
69 LayerIdToElementIdForTesting(scroll_layer->id())); | |
68 clip_layer_ = clip.get(); | 70 clip_layer_ = clip.get(); |
69 scroll_layer->SetScrollClipLayer(clip_layer_->id()); | 71 scroll_layer->SetScrollClipLayer(clip_layer_->id()); |
70 LayerImpl* scroll_layer_ptr = scroll_layer.get(); | 72 LayerImpl* scroll_layer_ptr = scroll_layer.get(); |
71 | 73 |
72 const int kId = 2; | 74 const int kId = 2; |
73 const int kThumbThickness = 10; | 75 const int kThumbThickness = 10; |
74 const int kTrackStart = 0; | 76 const int kTrackStart = 0; |
75 const bool kIsLeftSideVerticalScrollbar = false; | 77 const bool kIsLeftSideVerticalScrollbar = false; |
76 const bool kIsOverlayScrollbar = true; | 78 const bool kIsOverlayScrollbar = true; |
77 | 79 |
78 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = | 80 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
79 SolidColorScrollbarLayerImpl::Create( | 81 SolidColorScrollbarLayerImpl::Create( |
80 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, | 82 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, |
81 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); | 83 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); |
82 scrollbar_layer_ = scrollbar.get(); | 84 scrollbar_layer_ = scrollbar.get(); |
83 | 85 |
84 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); | 86 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); |
85 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); | 87 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); |
86 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); | 88 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); |
87 | 89 |
88 scrollbar_layer_->SetScrollInfo(scroll_layer_ptr->id(), | 90 scrollbar_layer_->SetScrollInfo(scroll_layer_ptr->id(), |
89 scroll_layer_ptr->element_id()); | 91 scroll_layer_ptr->element_id()); |
90 scrollbar_layer_->test_properties()->opacity_can_animate = true; | 92 scrollbar_layer_->test_properties()->opacity_can_animate = true; |
91 clip_layer_->SetBounds(gfx::Size(100, 100)); | 93 clip_layer_->SetBounds(gfx::Size(100, 100)); |
92 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); | 94 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
93 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); | 95 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
94 | 96 |
95 scrollbar_controller_ = SingleScrollbarAnimationControllerThinning::Create( | 97 scrollbar_controller_ = SingleScrollbarAnimationControllerThinning::Create( |
96 scroll_layer_ptr->id(), HORIZONTAL, &client_, kThinningDuration); | 98 scroll_layer_ptr->element_id(), HORIZONTAL, &client_, |
99 kThinningDuration); | |
wkorman
2017/04/19 18:07:09
I think I dreamed that I knew what a thinning scro
| |
97 } | 100 } |
98 | 101 |
99 FakeImplTaskRunnerProvider task_runner_provider_; | 102 FakeImplTaskRunnerProvider task_runner_provider_; |
100 TestTaskGraphRunner task_graph_runner_; | 103 TestTaskGraphRunner task_graph_runner_; |
101 FakeLayerTreeHostImpl host_impl_; | 104 FakeLayerTreeHostImpl host_impl_; |
102 std::unique_ptr<SingleScrollbarAnimationControllerThinning> | 105 std::unique_ptr<SingleScrollbarAnimationControllerThinning> |
103 scrollbar_controller_; | 106 scrollbar_controller_; |
104 LayerImpl* clip_layer_; | 107 LayerImpl* clip_layer_; |
105 SolidColorScrollbarLayerImpl* scrollbar_layer_; | 108 SolidColorScrollbarLayerImpl* scrollbar_layer_; |
106 NiceMock<MockSingleScrollbarAnimationControllerClient> client_; | 109 NiceMock<MockSingleScrollbarAnimationControllerClient> client_; |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 scrollbar_layer_->thumb_thickness_scale_factor()); | 377 scrollbar_layer_->thumb_thickness_scale_factor()); |
375 | 378 |
376 time += kThinningDuration / 2; | 379 time += kThinningDuration / 2; |
377 scrollbar_controller_->Animate(time); | 380 scrollbar_controller_->Animate(time); |
378 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 381 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
379 scrollbar_layer_->thumb_thickness_scale_factor()); | 382 scrollbar_layer_->thumb_thickness_scale_factor()); |
380 } | 383 } |
381 | 384 |
382 } // namespace | 385 } // namespace |
383 } // namespace cc | 386 } // namespace cc |
OLD | NEW |