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

Side by Side Diff: cc/layers/scrollbar_layer_unittest.cc

Issue 18341009: Refactor cc scrollbar layers to separate solid-color vs desktop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments; plumb scrollbar color via flag. Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/layers/scrollbar_layer.h" 5 #include "cc/layers/scrollbar_layer.h"
6 6
7 #include "base/containers/hash_tables.h" 7 #include "base/containers/hash_tables.h"
8 #include "cc/animation/scrollbar_animation_controller.h" 8 #include "cc/animation/scrollbar_animation_controller.h"
9 #include "cc/debug/test_web_graphics_context_3d.h" 9 #include "cc/debug/test_web_graphics_context_3d.h"
10 #include "cc/layers/append_quads_data.h" 10 #include "cc/layers/append_quads_data.h"
11 #include "cc/layers/scrollbar_layer_impl.h" 11 #include "cc/layers/scrollbar_layer_impl.h"
12 #include "cc/layers/scrollbar_layer_interface.h"
13 #include "cc/layers/solid_color_scrollbar_layer.h"
14 #include "cc/layers/solid_color_scrollbar_layer_impl.h"
12 #include "cc/quads/solid_color_draw_quad.h" 15 #include "cc/quads/solid_color_draw_quad.h"
13 #include "cc/resources/resource_update_queue.h" 16 #include "cc/resources/resource_update_queue.h"
14 #include "cc/test/fake_impl_proxy.h" 17 #include "cc/test/fake_impl_proxy.h"
15 #include "cc/test/fake_layer_tree_host.h" 18 #include "cc/test/fake_layer_tree_host.h"
16 #include "cc/test/fake_layer_tree_host_client.h" 19 #include "cc/test/fake_layer_tree_host_client.h"
17 #include "cc/test/fake_layer_tree_host_impl.h" 20 #include "cc/test/fake_layer_tree_host_impl.h"
18 #include "cc/test/fake_scrollbar.h" 21 #include "cc/test/fake_scrollbar.h"
19 #include "cc/test/fake_scrollbar_layer.h" 22 #include "cc/test/fake_scrollbar_layer.h"
20 #include "cc/test/geometry_test_utils.h" 23 #include "cc/test/geometry_test_utils.h"
21 #include "cc/test/layer_tree_test.h" 24 #include "cc/test/layer_tree_test.h"
22 #include "cc/test/mock_quad_culler.h" 25 #include "cc/test/mock_quad_culler.h"
23 #include "cc/trees/layer_tree_host.h" 26 #include "cc/trees/layer_tree_host.h"
24 #include "cc/trees/layer_tree_impl.h" 27 #include "cc/trees/layer_tree_impl.h"
25 #include "cc/trees/single_thread_proxy.h" 28 #include "cc/trees/single_thread_proxy.h"
26 #include "cc/trees/tree_synchronizer.h" 29 #include "cc/trees/tree_synchronizer.h"
27 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
29 32
30 namespace cc { 33 namespace cc {
31 namespace { 34 namespace {
32 35
33 LayerImpl* LayerImplForScrollAreaAndScrollbar( 36 LayerImpl* LayerImplForScrollAreaAndScrollbar(
34 FakeLayerTreeHost* host, 37 FakeLayerTreeHost* host,
35 scoped_ptr<Scrollbar> scrollbar, 38 scoped_ptr<Scrollbar> scrollbar,
36 bool reverse_order) { 39 bool reverse_order,
40 bool use_solid_color_scrollbar,
41 int thumb_thickness) {
37 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 42 scoped_refptr<Layer> layer_tree_root = Layer::Create();
38 scoped_refptr<Layer> child1 = Layer::Create(); 43 scoped_refptr<Layer> child1 = Layer::Create();
39 scoped_refptr<Layer> child2 = 44 scoped_refptr<Layer> child2;
40 ScrollbarLayer::Create(scrollbar.Pass(), 45 if (use_solid_color_scrollbar) {
41 child1->id()); 46 child2 = SolidColorScrollbarLayer::Create(
47 scrollbar->Orientation(), thumb_thickness, child1->id());
48 } else {
49 child2 = ScrollbarLayer::Create(scrollbar.Pass(), child1->id());
50 }
42 layer_tree_root->AddChild(child1); 51 layer_tree_root->AddChild(child1);
43 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); 52 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1);
44 host->SetRootLayer(layer_tree_root); 53 host->SetRootLayer(layer_tree_root);
45 return host->CommitAndCreateLayerImplTree(); 54 return host->CommitAndCreateLayerImplTree();
46 } 55 }
47 56
48 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { 57 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) {
49 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); 58 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
50 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 59 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
51 LayerImpl* layer_impl_tree_root = 60 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
52 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); 61 host.get(), scrollbar.Pass(), false, false, 0);
53 62
54 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; 63 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0];
55 ScrollbarLayerImpl* cc_child2 = static_cast<ScrollbarLayerImpl*>( 64 ScrollbarLayerImpl* cc_child2 = static_cast<ScrollbarLayerImpl*>(
56 layer_impl_tree_root->children()[1]); 65 layer_impl_tree_root->children()[1]);
57 66
58 EXPECT_EQ(cc_child1->horizontal_scrollbar_layer(), cc_child2); 67 EXPECT_EQ(cc_child1->horizontal_scrollbar_layer(), cc_child2);
59 } 68 }
60 69
61 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { 70 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) {
62 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); 71 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
63 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 72 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
64 LayerImpl* layer_impl_tree_root = 73 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
65 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), true); 74 host.get(), scrollbar.Pass(), true, false, 0);
66 75
67 ScrollbarLayerImpl* cc_child1 = static_cast<ScrollbarLayerImpl*>( 76 ScrollbarLayerImpl* cc_child1 = static_cast<ScrollbarLayerImpl*>(
68 layer_impl_tree_root->children()[0]); 77 layer_impl_tree_root->children()[0]);
69 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; 78 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1];
70 79
71 EXPECT_EQ(cc_child2->horizontal_scrollbar_layer(), cc_child1); 80 EXPECT_EQ(cc_child2->horizontal_scrollbar_layer(), cc_child1);
72 } 81 }
73 82
74 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { 83 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
75 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); 84 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
76 85
77 // Create and attach a non-overlay scrollbar. 86 // Create and attach a non-overlay scrollbar.
78 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 87 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
79 LayerImpl* layer_impl_tree_root = 88 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
80 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); 89 host.get(), scrollbar.Pass(), false, false, 0);
81 ScrollbarLayerImpl* scrollbar_layer_impl = 90 ScrollbarLayerImpl* scrollbar_layer_impl =
82 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); 91 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
83 92
84 // When the scrollbar is not an overlay scrollbar, the scroll should be 93 // When the scrollbar is not an overlay scrollbar, the scroll should be
85 // responded to on the main thread as the compositor does not yet implement 94 // responded to on the main thread as the compositor does not yet implement
86 // scrollbar scrolling. 95 // scrollbar scrolling.
87 EXPECT_EQ(InputHandler::ScrollOnMainThread, 96 EXPECT_EQ(InputHandler::ScrollOnMainThread,
88 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), 97 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0),
89 InputHandler::Gesture)); 98 InputHandler::Gesture));
90 99
91 // Create and attach an overlay scrollbar. 100 // Create and attach an overlay scrollbar.
92 scrollbar.reset(new FakeScrollbar(false, false, true)); 101 scrollbar.reset(new FakeScrollbar(false, false, true));
93 102
94 layer_impl_tree_root = 103 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
95 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); 104 host.get(), scrollbar.Pass(), false, false, 0);
96 scrollbar_layer_impl = 105 scrollbar_layer_impl =
97 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); 106 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
98 107
99 // The user shouldn't be able to drag an overlay scrollbar and the scroll 108 // The user shouldn't be able to drag an overlay scrollbar and the scroll
100 // may be handled in the compositor. 109 // may be handled in the compositor.
101 EXPECT_EQ(InputHandler::ScrollIgnored, 110 EXPECT_EQ(InputHandler::ScrollIgnored,
102 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), 111 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0),
103 InputHandler::Gesture)); 112 InputHandler::Gesture));
104 } 113 }
105 114
(...skipping 18 matching lines...) Expand all
124 layer_tree_root->AddChild(scrollbar_layer); 133 layer_tree_root->AddChild(scrollbar_layer);
125 134
126 layer_tree_root->SavePaintProperties(); 135 layer_tree_root->SavePaintProperties();
127 content_layer->SavePaintProperties(); 136 content_layer->SavePaintProperties();
128 137
129 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); 138 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree();
130 139
131 ScrollbarLayerImpl* cc_scrollbar_layer = 140 ScrollbarLayerImpl* cc_scrollbar_layer =
132 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); 141 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
133 142
134 EXPECT_EQ(10.f, cc_scrollbar_layer->CurrentPos()); 143 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos());
135 EXPECT_EQ(30, cc_scrollbar_layer->Maximum()); 144 EXPECT_EQ(30, cc_scrollbar_layer->maximum());
136 145
137 layer_tree_root->SetScrollOffset(gfx::Vector2d(100, 200)); 146 layer_tree_root->SetScrollOffset(gfx::Vector2d(100, 200));
138 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(300, 500)); 147 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(300, 500));
139 layer_tree_root->SetBounds(gfx::Size(1000, 2000)); 148 layer_tree_root->SetBounds(gfx::Size(1000, 2000));
140 layer_tree_root->SavePaintProperties(); 149 layer_tree_root->SavePaintProperties();
141 content_layer->SetBounds(gfx::Size(1000, 2000)); 150 content_layer->SetBounds(gfx::Size(1000, 2000));
142 content_layer->SavePaintProperties(); 151 content_layer->SavePaintProperties();
143 152
144 ScrollbarAnimationController* scrollbar_controller = 153 ScrollbarAnimationController* scrollbar_controller =
145 layer_impl_tree_root->scrollbar_animation_controller(); 154 layer_impl_tree_root->scrollbar_animation_controller();
146 layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); 155 layer_impl_tree_root = host->CommitAndCreateLayerImplTree();
147 EXPECT_EQ(scrollbar_controller, 156 EXPECT_EQ(scrollbar_controller,
148 layer_impl_tree_root->scrollbar_animation_controller()); 157 layer_impl_tree_root->scrollbar_animation_controller());
149 158
150 EXPECT_EQ(100.f, cc_scrollbar_layer->CurrentPos()); 159 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos());
151 EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); 160 EXPECT_EQ(300, cc_scrollbar_layer->maximum());
152 161
153 layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34)); 162 layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34));
154 163
155 EXPECT_EQ(112.f, cc_scrollbar_layer->CurrentPos()); 164 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos());
156 EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); 165 EXPECT_EQ(300, cc_scrollbar_layer->maximum());
157 } 166 }
158 167
159 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { 168 TEST(ScrollbarLayerTest, SolidColorDrawQuads) {
169 const int kThumbThickness = 3;
170 const int kTrackLength = 100;
171
160 LayerTreeSettings layer_tree_settings; 172 LayerTreeSettings layer_tree_settings;
161 layer_tree_settings.solid_color_scrollbars = true;
162 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3;
163 scoped_ptr<FakeLayerTreeHost> host = 173 scoped_ptr<FakeLayerTreeHost> host =
164 FakeLayerTreeHost::Create(layer_tree_settings); 174 FakeLayerTreeHost::Create(layer_tree_settings);
165 175
166 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); 176 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
167 LayerImpl* layer_impl_tree_root = 177 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
168 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); 178 host.get(), scrollbar.Pass(), false, true, kThumbThickness);
169 ScrollbarLayerImpl* scrollbar_layer_impl = 179 ScrollbarLayerImplBase* scrollbar_layer_impl =
170 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); 180 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
171 scrollbar_layer_impl->SetThumbThickness(3); 181 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness));
172 scrollbar_layer_impl->SetCurrentPos(10.f); 182 scrollbar_layer_impl->SetCurrentPos(10.f);
173 scrollbar_layer_impl->SetMaximum(100); 183 scrollbar_layer_impl->SetMaximum(100);
174 scrollbar_layer_impl->SetTrackLength(100);
175 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f); 184 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f);
176 185
177 // Thickness should be overridden to 3. 186 // Thickness should be overridden to 3.
178 { 187 {
179 MockQuadCuller quad_culler; 188 MockQuadCuller quad_culler;
180 AppendQuadsData data; 189 AppendQuadsData data;
181 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); 190 scrollbar_layer_impl->AppendQuads(&quad_culler, &data);
182 191
183 const QuadList& quads = quad_culler.quad_list(); 192 const QuadList& quads = quad_culler.quad_list();
184 ASSERT_EQ(1u, quads.size()); 193 ASSERT_EQ(1u, quads.size());
(...skipping 26 matching lines...) Expand all
211 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); 220 scrollbar_layer_impl->AppendQuads(&quad_culler, &data);
212 221
213 const QuadList& quads = quad_culler.quad_list(); 222 const QuadList& quads = quad_culler.quad_list();
214 ASSERT_EQ(1u, quads.size()); 223 ASSERT_EQ(1u, quads.size());
215 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); 224 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material);
216 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect); 225 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect);
217 } 226 }
218 } 227 }
219 228
220 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { 229 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) {
230 const int kThumbThickness = 3;
231 const int kTrackLength = 10;
232
221 LayerTreeSettings layer_tree_settings; 233 LayerTreeSettings layer_tree_settings;
222 layer_tree_settings.solid_color_scrollbars = true;
223 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3;
224 scoped_ptr<FakeLayerTreeHost> host = 234 scoped_ptr<FakeLayerTreeHost> host =
225 FakeLayerTreeHost::Create(layer_tree_settings); 235 FakeLayerTreeHost::Create(layer_tree_settings);
226 236
227 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); 237 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
228 LayerImpl* layer_impl_tree_root = 238 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
229 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); 239 host.get(), scrollbar.Pass(), false, true, kThumbThickness);
230 ScrollbarLayerImpl* scrollbar_layer_impl = 240 ScrollbarLayerImplBase* scrollbar_layer_impl =
231 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); 241 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
232 242
233 scrollbar_layer_impl->SetThumbThickness(3); 243 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness));
234 scrollbar_layer_impl->SetTrackLength(10);
235 scrollbar_layer_impl->SetCurrentPos(4.f); 244 scrollbar_layer_impl->SetCurrentPos(4.f);
236 scrollbar_layer_impl->SetMaximum(8); 245 scrollbar_layer_impl->SetMaximum(8);
237 246
238 layer_impl_tree_root->SetScrollable(true); 247 layer_impl_tree_root->SetScrollable(true);
239 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); 248 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl);
240 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8)); 249 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8));
241 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); 250 layer_impl_tree_root->SetBounds(gfx::Size(2, 2));
242 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f)); 251 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f));
243 252
244 { 253 {
245 MockQuadCuller quad_culler; 254 MockQuadCuller quad_culler;
246 AppendQuadsData data; 255 AppendQuadsData data;
247 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); 256 scrollbar_layer_impl->AppendQuads(&quad_culler, &data);
248 257
249 const QuadList& quads = quad_culler.quad_list(); 258 const QuadList& quads = quad_culler.quad_list();
250 ASSERT_EQ(1u, quads.size()); 259 ASSERT_EQ(1u, quads.size());
251 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); 260 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material);
252 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect); 261 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect);
253 } 262 }
254 } 263 }
255 264
256 class ScrollbarLayerSolidColorThumbTest : public testing::Test { 265 class ScrollbarLayerSolidColorThumbTest : public testing::Test {
257 public: 266 public:
258 ScrollbarLayerSolidColorThumbTest() { 267 ScrollbarLayerSolidColorThumbTest() {
259 LayerTreeSettings layer_tree_settings; 268 LayerTreeSettings layer_tree_settings;
260 layer_tree_settings.solid_color_scrollbars = true;
261 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); 269 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_));
262 270
263 horizontal_scrollbar_layer_ = ScrollbarLayerImpl::Create( 271 const int kThumbThickness = 3;
264 host_impl_->active_tree(), 1, HORIZONTAL); 272
265 vertical_scrollbar_layer_ = ScrollbarLayerImpl::Create( 273 horizontal_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create(
266 host_impl_->active_tree(), 2, VERTICAL); 274 host_impl_->active_tree(), 1, HORIZONTAL, kThumbThickness);
275 vertical_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create(
276 host_impl_->active_tree(), 2, VERTICAL, kThumbThickness);
267 } 277 }
268 278
269 protected: 279 protected:
270 FakeImplProxy proxy_; 280 FakeImplProxy proxy_;
271 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; 281 scoped_ptr<FakeLayerTreeHostImpl> host_impl_;
272 scoped_ptr<ScrollbarLayerImpl> horizontal_scrollbar_layer_; 282 scoped_ptr<SolidColorScrollbarLayerImpl> horizontal_scrollbar_layer_;
273 scoped_ptr<ScrollbarLayerImpl> vertical_scrollbar_layer_; 283 scoped_ptr<SolidColorScrollbarLayerImpl> vertical_scrollbar_layer_;
274 }; 284 };
275 285
276 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { 286 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) {
277 horizontal_scrollbar_layer_->SetCurrentPos(0); 287 horizontal_scrollbar_layer_->SetCurrentPos(0);
278 horizontal_scrollbar_layer_->SetMaximum(10); 288 horizontal_scrollbar_layer_->SetMaximum(10);
279 horizontal_scrollbar_layer_->SetThumbThickness(3);
280 289
281 // Simple case - one third of the scrollable area is visible, so the thumb 290 // Simple case - one third of the scrollable area is visible, so the thumb
282 // should be one third as long as the track. 291 // should be one third as long as the track.
283 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.33f); 292 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.33f);
284 horizontal_scrollbar_layer_->SetTrackLength(100); 293 horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3));
285 EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); 294 EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width());
286 295
287 // The thumb's length should never be less than its thickness. 296 // The thumb's length should never be less than its thickness.
288 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.01f); 297 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.01f);
289 horizontal_scrollbar_layer_->SetTrackLength(100); 298 horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3));
290 EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); 299 EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width());
291 } 300 }
292 301
293 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) { 302 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) {
294 horizontal_scrollbar_layer_->SetTrackLength(100); 303 horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3));
295 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.1f); 304 horizontal_scrollbar_layer_->SetVisibleToTotalLengthRatio(0.1f);
296 horizontal_scrollbar_layer_->SetThumbThickness(3);
297 305
298 horizontal_scrollbar_layer_->SetCurrentPos(0); 306 horizontal_scrollbar_layer_->SetCurrentPos(0);
299 horizontal_scrollbar_layer_->SetMaximum(100); 307 horizontal_scrollbar_layer_->SetMaximum(100);
300 EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); 308 EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x());
301 EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); 309 EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width());
302 310
303 horizontal_scrollbar_layer_->SetCurrentPos(100); 311 horizontal_scrollbar_layer_->SetCurrentPos(100);
304 // The thumb is 10px long and the track is 100px, so the maximum thumb 312 // The thumb is 10px long and the track is 100px, so the maximum thumb
305 // position is 90px. 313 // position is 90px.
306 EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); 314 EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x());
307 315
308 horizontal_scrollbar_layer_->SetCurrentPos(80); 316 horizontal_scrollbar_layer_->SetCurrentPos(80);
309 // The scroll position is 80% of the maximum, so the thumb's position should 317 // The scroll position is 80% of the maximum, so the thumb's position should
310 // be at 80% of its maximum or 72px. 318 // be at 80% of its maximum or 72px.
311 EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); 319 EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x());
312 } 320 }
313 321
314 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) { 322 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) {
315 ScrollbarLayerImpl* layers[2] = 323 SolidColorScrollbarLayerImpl* layers[2] =
316 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; 324 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() };
317 for (size_t i = 0; i < 2; ++i) { 325 for (size_t i = 0; i < 2; ++i) {
318 layers[i]->SetTrackLength(100);
319 layers[i]->SetVisibleToTotalLengthRatio(0.2f); 326 layers[i]->SetVisibleToTotalLengthRatio(0.2f);
320 layers[i]->SetThumbThickness(3);
321 layers[i]->SetCurrentPos(25); 327 layers[i]->SetCurrentPos(25);
322 layers[i]->SetMaximum(100); 328 layers[i]->SetMaximum(100);
323 } 329 }
330 layers[0]->SetBounds(gfx::Size(100, 3));
331 layers[1]->SetBounds(gfx::Size(3, 100));
324 332
325 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f), 333 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f),
326 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); 334 horizontal_scrollbar_layer_->ComputeThumbQuadRect());
327 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f), 335 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f),
328 vertical_scrollbar_layer_->ComputeThumbQuadRect()); 336 vertical_scrollbar_layer_->ComputeThumbQuadRect());
329 337
330 horizontal_scrollbar_layer_->SetVerticalAdjust(10.f); 338 horizontal_scrollbar_layer_->SetVerticalAdjust(10.f);
331 vertical_scrollbar_layer_->SetVerticalAdjust(10.f); 339 vertical_scrollbar_layer_->SetVerticalAdjust(10.f);
332 340
333 // The vertical adjustment factor has two effects: 341 // The vertical adjustment factor has two effects:
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 459
452 460
453 class ScrollbarLayerTestResourceCreation : public testing::Test { 461 class ScrollbarLayerTestResourceCreation : public testing::Test {
454 public: 462 public:
455 ScrollbarLayerTestResourceCreation() 463 ScrollbarLayerTestResourceCreation()
456 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 464 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
457 465
458 void TestResourceUpload(int num_updates, 466 void TestResourceUpload(int num_updates,
459 size_t expected_resources, 467 size_t expected_resources,
460 int expected_created, 468 int expected_created,
461 int expected_deleted) { 469 int expected_deleted,
470 bool use_solid_color_scrollbar) {
462 layer_tree_host_.reset( 471 layer_tree_host_.reset(
463 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); 472 new MockLayerTreeHost(&fake_client_, layer_tree_settings_));
464 473
465 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); 474 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false));
466 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 475 scoped_refptr<Layer> layer_tree_root = Layer::Create();
467 scoped_refptr<Layer> content_layer = Layer::Create(); 476 scoped_refptr<Layer> content_layer = Layer::Create();
468 scoped_refptr<Layer> scrollbar_layer = 477 scoped_refptr<Layer> scrollbar_layer;
469 ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); 478 if (use_solid_color_scrollbar) {
479 const int kThumbThickness = 3;
480 scrollbar_layer =
481 SolidColorScrollbarLayer::Create(scrollbar->Orientation(),
482 kThumbThickness,
483 layer_tree_root->id());
484 } else {
485 scrollbar_layer =
486 ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id());
487 }
470 layer_tree_root->AddChild(content_layer); 488 layer_tree_root->AddChild(content_layer);
471 layer_tree_root->AddChild(scrollbar_layer); 489 layer_tree_root->AddChild(scrollbar_layer);
472 490
473 layer_tree_host_->InitializeOutputSurfaceIfNeeded(); 491 layer_tree_host_->InitializeOutputSurfaceIfNeeded();
474 layer_tree_host_->SetRootLayer(layer_tree_root); 492 layer_tree_host_->SetRootLayer(layer_tree_root);
475 493
476 scrollbar_layer->SetIsDrawable(true); 494 scrollbar_layer->SetIsDrawable(true);
477 scrollbar_layer->SetBounds(gfx::Size(100, 100)); 495 scrollbar_layer->SetBounds(gfx::Size(100, 100));
478 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); 496 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20));
479 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50)); 497 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50));
(...skipping 25 matching lines...) Expand all
505 scrollbar_layer->ClearRenderSurface(); 523 scrollbar_layer->ClearRenderSurface();
506 } 524 }
507 525
508 protected: 526 protected:
509 FakeLayerTreeHostClient fake_client_; 527 FakeLayerTreeHostClient fake_client_;
510 LayerTreeSettings layer_tree_settings_; 528 LayerTreeSettings layer_tree_settings_;
511 scoped_ptr<MockLayerTreeHost> layer_tree_host_; 529 scoped_ptr<MockLayerTreeHost> layer_tree_host_;
512 }; 530 };
513 531
514 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { 532 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) {
515 layer_tree_settings_.solid_color_scrollbars = false; 533 bool use_solid_color_scrollbars = false;
516 TestResourceUpload(0, 0, 0, 0); 534 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
517 int num_updates[3] = {1, 5, 10}; 535 int num_updates[3] = {1, 5, 10};
518 for (int j = 0; j < 3; j++) { 536 for (int j = 0; j < 3; j++) {
519 TestResourceUpload( 537 TestResourceUpload(num_updates[j],
520 num_updates[j], 2, num_updates[j] * 2, (num_updates[j] - 1) * 2); 538 2,
539 num_updates[j] * 2,
540 (num_updates[j] - 1) * 2,
541 use_solid_color_scrollbars);
521 } 542 }
522 } 543 }
523 544
524 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { 545 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) {
525 layer_tree_settings_.solid_color_scrollbars = true; 546 bool use_solid_color_scrollbars = true;
526 TestResourceUpload(0, 0, 0, 0); 547 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
527 TestResourceUpload(1, 0, 0, 0); 548 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars);
528 } 549 }
529 550
530 class ScaledScrollbarLayerTestResourceCreation : public testing::Test { 551 class ScaledScrollbarLayerTestResourceCreation : public testing::Test {
531 public: 552 public:
532 ScaledScrollbarLayerTestResourceCreation() 553 ScaledScrollbarLayerTestResourceCreation()
533 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 554 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
534 555
535 void TestResourceUpload(const float test_scale) { 556 void TestResourceUpload(const float test_scale) {
536 layer_tree_host_.reset( 557 layer_tree_host_.reset(
537 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); 558 new MockLayerTreeHost(&fake_client_, layer_tree_settings_));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 scrollbar_layer->ClearRenderSurface(); 616 scrollbar_layer->ClearRenderSurface();
596 } 617 }
597 618
598 protected: 619 protected:
599 FakeLayerTreeHostClient fake_client_; 620 FakeLayerTreeHostClient fake_client_;
600 LayerTreeSettings layer_tree_settings_; 621 LayerTreeSettings layer_tree_settings_;
601 scoped_ptr<MockLayerTreeHost> layer_tree_host_; 622 scoped_ptr<MockLayerTreeHost> layer_tree_host_;
602 }; 623 };
603 624
604 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { 625 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) {
605 layer_tree_settings_.solid_color_scrollbars = false;
606 // Pick a test scale that moves the scrollbar's (non-zero) position to 626 // Pick a test scale that moves the scrollbar's (non-zero) position to
607 // a non-pixel-aligned location. 627 // a non-pixel-aligned location.
608 TestResourceUpload(.041f); 628 TestResourceUpload(.041f);
609 TestResourceUpload(1.41f); 629 TestResourceUpload(1.41f);
610 TestResourceUpload(4.1f); 630 TestResourceUpload(4.1f);
611 } 631 }
612 632
613 } // namespace 633 } // namespace
614 } // namespace cc 634 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698