Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: cc/input/scrollbar_animation_controller_unittest.cc

Issue 2824693002: Refactor LayerTreeImpl's scrollbar map to be keyed on element ids (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/scrollbar_animation_controller.h" 5 #include "cc/input/scrollbar_animation_controller.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 26 matching lines...) Expand all
37 : host_impl_(host_impl) {} 37 : host_impl_(host_impl) {}
38 virtual ~MockScrollbarAnimationControllerClient() {} 38 virtual ~MockScrollbarAnimationControllerClient() {}
39 39
40 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade, 40 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade,
41 base::TimeDelta delay) override { 41 base::TimeDelta delay) override {
42 start_fade_ = start_fade; 42 start_fade_ = start_fade;
43 delay_ = delay; 43 delay_ = delay;
44 } 44 }
45 void SetNeedsRedrawForScrollbarAnimation() override {} 45 void SetNeedsRedrawForScrollbarAnimation() override {}
46 void SetNeedsAnimateForScrollbarAnimation() override {} 46 void SetNeedsAnimateForScrollbarAnimation() override {}
47 ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override { 47 ScrollbarSet ScrollbarsFor(ElementId scroll_element_id) const override {
48 return host_impl_->ScrollbarsFor(scroll_layer_id); 48 return host_impl_->ScrollbarsFor(scroll_element_id);
49 } 49 }
50 MOCK_METHOD0(DidChangeScrollbarVisibility, void()); 50 MOCK_METHOD0(DidChangeScrollbarVisibility, void());
51 51
52 base::Closure& start_fade() { return start_fade_; } 52 base::Closure& start_fade() { return start_fade_; }
53 base::TimeDelta& delay() { return delay_; } 53 base::TimeDelta& delay() { return delay_; }
54 54
55 private: 55 private:
56 base::Closure start_fade_; 56 base::Closure start_fade_;
57 base::TimeDelta delay_; 57 base::TimeDelta delay_;
58 LayerTreeHostImpl* host_impl_; 58 LayerTreeHostImpl* host_impl_;
(...skipping 16 matching lines...) Expand all
75 const base::TimeDelta kResizeFadeOutDelay = base::TimeDelta::FromSeconds(5); 75 const base::TimeDelta kResizeFadeOutDelay = base::TimeDelta::FromSeconds(5);
76 const base::TimeDelta kFadeOutDuration = base::TimeDelta::FromSeconds(3); 76 const base::TimeDelta kFadeOutDuration = base::TimeDelta::FromSeconds(3);
77 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2); 77 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2);
78 78
79 void SetUp() override { 79 void SetUp() override {
80 std::unique_ptr<LayerImpl> scroll_layer = 80 std::unique_ptr<LayerImpl> scroll_layer =
81 LayerImpl::Create(host_impl_.active_tree(), 1); 81 LayerImpl::Create(host_impl_.active_tree(), 1);
82 std::unique_ptr<LayerImpl> clip = 82 std::unique_ptr<LayerImpl> clip =
83 LayerImpl::Create(host_impl_.active_tree(), 2); 83 LayerImpl::Create(host_impl_.active_tree(), 2);
84 clip_layer_ = clip.get(); 84 clip_layer_ = clip.get();
85 scroll_layer->SetElementId(
86 LayerIdToElementIdForTesting(scroll_layer->id()));
85 scroll_layer->SetScrollClipLayer(clip_layer_->id()); 87 scroll_layer->SetScrollClipLayer(clip_layer_->id());
86 LayerImpl* scroll_layer_ptr = scroll_layer.get(); 88 LayerImpl* scroll_layer_ptr = scroll_layer.get();
87 89
88 const int kTrackStart = 0; 90 const int kTrackStart = 0;
89 const bool kIsLeftSideVerticalScrollbar = false; 91 const bool kIsLeftSideVerticalScrollbar = false;
90 const bool kIsOverlayScrollbar = true; 92 const bool kIsOverlayScrollbar = true;
91 93
92 std::unique_ptr<SolidColorScrollbarLayerImpl> h_scrollbar = 94 std::unique_ptr<SolidColorScrollbarLayerImpl> h_scrollbar =
93 SolidColorScrollbarLayerImpl::Create( 95 SolidColorScrollbarLayerImpl::Create(
94 host_impl_.active_tree(), 3, HORIZONTAL, kThumbThickness, 96 host_impl_.active_tree(), 3, HORIZONTAL, kThumbThickness,
(...skipping 15 matching lines...) Expand all
110 h_scrollbar_layer_->SetScrollInfo(scroll_layer_ptr->id(), 112 h_scrollbar_layer_->SetScrollInfo(scroll_layer_ptr->id(),
111 scroll_layer_ptr->element_id()); 113 scroll_layer_ptr->element_id());
112 v_scrollbar_layer_->test_properties()->opacity_can_animate = true; 114 v_scrollbar_layer_->test_properties()->opacity_can_animate = true;
113 h_scrollbar_layer_->test_properties()->opacity_can_animate = true; 115 h_scrollbar_layer_->test_properties()->opacity_can_animate = true;
114 clip_layer_->SetBounds(gfx::Size(100, 100)); 116 clip_layer_->SetBounds(gfx::Size(100, 100));
115 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); 117 scroll_layer_ptr->SetBounds(gfx::Size(200, 200));
116 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); 118 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting();
117 119
118 scrollbar_controller_ = ScrollbarAnimationController:: 120 scrollbar_controller_ = ScrollbarAnimationController::
119 CreateScrollbarAnimationControllerAuraOverlay( 121 CreateScrollbarAnimationControllerAuraOverlay(
120 scroll_layer_ptr->id(), &client_, kShowDelay, kFadeOutDelay, 122 scroll_layer_ptr->element_id(), &client_, kShowDelay, kFadeOutDelay,
121 kResizeFadeOutDelay, kFadeOutDuration, kThinningDuration); 123 kResizeFadeOutDelay, kFadeOutDuration, kThinningDuration);
122 } 124 }
123 125
124 FakeImplTaskRunnerProvider task_runner_provider_; 126 FakeImplTaskRunnerProvider task_runner_provider_;
125 TestTaskGraphRunner task_graph_runner_; 127 TestTaskGraphRunner task_graph_runner_;
126 FakeLayerTreeHostImpl host_impl_; 128 FakeLayerTreeHostImpl host_impl_;
127 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; 129 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_;
128 LayerImpl* clip_layer_; 130 LayerImpl* clip_layer_;
129 SolidColorScrollbarLayerImpl* v_scrollbar_layer_; 131 SolidColorScrollbarLayerImpl* v_scrollbar_layer_;
130 SolidColorScrollbarLayerImpl* h_scrollbar_layer_; 132 SolidColorScrollbarLayerImpl* h_scrollbar_layer_;
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 base::TimeDelta delay) override { 1128 base::TimeDelta delay) override {
1127 start_fade_ = start_fade; 1129 start_fade_ = start_fade;
1128 delay_ = delay; 1130 delay_ = delay;
1129 } 1131 }
1130 void SetNeedsRedrawForScrollbarAnimation() override { 1132 void SetNeedsRedrawForScrollbarAnimation() override {
1131 did_request_redraw_ = true; 1133 did_request_redraw_ = true;
1132 } 1134 }
1133 void SetNeedsAnimateForScrollbarAnimation() override { 1135 void SetNeedsAnimateForScrollbarAnimation() override {
1134 did_request_animate_ = true; 1136 did_request_animate_ = true;
1135 } 1137 }
1136 ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override { 1138 ScrollbarSet ScrollbarsFor(ElementId scroll_element_id) const override {
1137 return host_impl_.ScrollbarsFor(scroll_layer_id); 1139 return host_impl_.ScrollbarsFor(scroll_element_id);
1138 } 1140 }
1139 void DidChangeScrollbarVisibility() override {} 1141 void DidChangeScrollbarVisibility() override {}
1140 1142
1141 protected: 1143 protected:
1142 void SetUp() override { 1144 void SetUp() override {
1143 const int kTrackStart = 0; 1145 const int kTrackStart = 0;
1144 const bool kIsLeftSideVerticalScrollbar = false; 1146 const bool kIsLeftSideVerticalScrollbar = false;
1145 const bool kIsOverlayScrollbar = true; // Allow opacity animations. 1147 const bool kIsOverlayScrollbar = true; // Allow opacity animations.
1146 1148
1147 std::unique_ptr<LayerImpl> scroll_layer = 1149 std::unique_ptr<LayerImpl> scroll_layer =
1148 LayerImpl::Create(host_impl_.active_tree(), 1); 1150 LayerImpl::Create(host_impl_.active_tree(), 1);
1149 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = 1151 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar =
1150 SolidColorScrollbarLayerImpl::Create( 1152 SolidColorScrollbarLayerImpl::Create(
1151 host_impl_.active_tree(), 2, orientation(), kThumbThickness, 1153 host_impl_.active_tree(), 2, orientation(), kThumbThickness,
1152 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); 1154 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar);
1153 scrollbar_layer_ = scrollbar.get(); 1155 scrollbar_layer_ = scrollbar.get();
1154 scrollbar_layer_->test_properties()->opacity_can_animate = true; 1156 scrollbar_layer_->test_properties()->opacity_can_animate = true;
1155 std::unique_ptr<LayerImpl> clip = 1157 std::unique_ptr<LayerImpl> clip =
1156 LayerImpl::Create(host_impl_.active_tree(), 3); 1158 LayerImpl::Create(host_impl_.active_tree(), 3);
1157 clip_layer_ = clip.get(); 1159 clip_layer_ = clip.get();
1160 scroll_layer->SetElementId(
1161 LayerIdToElementIdForTesting(scroll_layer->id()));
1158 scroll_layer->SetScrollClipLayer(clip_layer_->id()); 1162 scroll_layer->SetScrollClipLayer(clip_layer_->id());
1159 LayerImpl* scroll_layer_ptr = scroll_layer.get(); 1163 LayerImpl* scroll_layer_ptr = scroll_layer.get();
1160 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); 1164 scroll_layer->test_properties()->AddChild(std::move(scrollbar));
1161 clip->test_properties()->AddChild(std::move(scroll_layer)); 1165 clip->test_properties()->AddChild(std::move(scroll_layer));
1162 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); 1166 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip));
1163 1167
1164 scrollbar_layer_->SetScrollInfo(scroll_layer_ptr->id(), 1168 scrollbar_layer_->SetScrollInfo(scroll_layer_ptr->id(),
1165 scroll_layer_ptr->element_id()); 1169 scroll_layer_ptr->element_id());
1166 clip_layer_->SetBounds(gfx::Size(100, 100)); 1170 clip_layer_->SetBounds(gfx::Size(100, 100));
1167 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); 1171 scroll_layer_ptr->SetBounds(gfx::Size(200, 200));
1168 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); 1172 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting();
1169 1173
1170 scrollbar_controller_ = 1174 scrollbar_controller_ =
1171 ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid( 1175 ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid(
1172 scroll_layer_ptr->id(), this, base::TimeDelta::FromSeconds(2), 1176 scroll_layer_ptr->element_id(), this,
1173 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(3)); 1177 base::TimeDelta::FromSeconds(2), base::TimeDelta::FromSeconds(5),
1178 base::TimeDelta::FromSeconds(3));
1174 } 1179 }
1175 1180
1176 virtual ScrollbarOrientation orientation() const { return HORIZONTAL; } 1181 virtual ScrollbarOrientation orientation() const { return HORIZONTAL; }
1177 1182
1178 FakeImplTaskRunnerProvider task_runner_provider_; 1183 FakeImplTaskRunnerProvider task_runner_provider_;
1179 TestTaskGraphRunner task_graph_runner_; 1184 TestTaskGraphRunner task_graph_runner_;
1180 FakeLayerTreeHostImpl host_impl_; 1185 FakeLayerTreeHostImpl host_impl_;
1181 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; 1186 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_;
1182 LayerImpl* clip_layer_; 1187 LayerImpl* clip_layer_;
1183 SolidColorScrollbarLayerImpl* scrollbar_layer_; 1188 SolidColorScrollbarLayerImpl* scrollbar_layer_;
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); 1602 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity());
1598 1603
1599 time += base::TimeDelta::FromSeconds(1); 1604 time += base::TimeDelta::FromSeconds(1);
1600 scrollbar_controller_->DidScrollEnd(); 1605 scrollbar_controller_->DidScrollEnd();
1601 EXPECT_FALSE(did_request_animate_); 1606 EXPECT_FALSE(did_request_animate_);
1602 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); 1607 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity());
1603 } 1608 }
1604 1609
1605 } // namespace 1610 } // namespace
1606 } // namespace cc 1611 } // namespace cc
OLDNEW
« no previous file with comments | « cc/input/scrollbar_animation_controller.cc ('k') | cc/input/single_scrollbar_animation_controller_thinning.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698