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

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

Issue 17550008: Make IsSolidColor() a property on CC scrollbar layers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use DCHECK(layer_tree_host()) instead. Created 7 years, 6 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 "cc/animation/scrollbar_animation_controller.h" 7 #include "cc/animation/scrollbar_animation_controller.h"
8 #include "cc/layers/append_quads_data.h" 8 #include "cc/layers/append_quads_data.h"
9 #include "cc/layers/scrollbar_layer_impl.h" 9 #include "cc/layers/scrollbar_layer_impl.h"
10 #include "cc/quads/solid_color_draw_quad.h" 10 #include "cc/quads/solid_color_draw_quad.h"
(...skipping 11 matching lines...) Expand all
22 #include "cc/trees/layer_tree_impl.h" 22 #include "cc/trees/layer_tree_impl.h"
23 #include "cc/trees/single_thread_proxy.h" 23 #include "cc/trees/single_thread_proxy.h"
24 #include "cc/trees/tree_synchronizer.h" 24 #include "cc/trees/tree_synchronizer.h"
25 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 27
28 namespace cc { 28 namespace cc {
29 namespace { 29 namespace {
30 30
31 scoped_ptr<LayerImpl> LayerImplForScrollAreaAndScrollbar( 31 scoped_ptr<LayerImpl> LayerImplForScrollAreaAndScrollbar(
32 LayerTreeHost* host,
32 FakeLayerTreeHostImpl* host_impl, 33 FakeLayerTreeHostImpl* host_impl,
33 scoped_ptr<Scrollbar> scrollbar, 34 scoped_ptr<Scrollbar> scrollbar,
34 bool reverse_order) { 35 bool reverse_order, bool is_solid_color) {
35 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 36 scoped_refptr<Layer> layer_tree_root = Layer::Create();
36 scoped_refptr<Layer> child1 = Layer::Create(); 37 scoped_refptr<Layer> child1 = Layer::Create();
37 scoped_refptr<Layer> child2 = 38 scoped_refptr<Layer> child2 =
38 ScrollbarLayer::Create(scrollbar.Pass(), 39 ScrollbarLayer::Create(scrollbar.Pass(), child1->id(), is_solid_color);
39 child1->id());
40 layer_tree_root->AddChild(child1); 40 layer_tree_root->AddChild(child1);
41 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); 41 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1);
42 layer_tree_root->SetLayerTreeHost(host);
42 scoped_ptr<LayerImpl> layer_impl = 43 scoped_ptr<LayerImpl> layer_impl =
43 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 44 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
44 scoped_ptr<LayerImpl>(), 45 scoped_ptr<LayerImpl>(),
45 host_impl->active_tree()); 46 host_impl->active_tree());
46 TreeSynchronizer::PushProperties(layer_tree_root.get(), layer_impl.get()); 47 TreeSynchronizer::PushProperties(layer_tree_root.get(), layer_impl.get());
47 return layer_impl.Pass(); 48 return layer_impl.Pass();
48 } 49 }
49 50
51 class MockLayerTreeHost : public LayerTreeHost {
52 public:
53 MockLayerTreeHost(LayerTreeHostClient* client,
54 const LayerTreeSettings& settings)
55 : LayerTreeHost(client, settings) {
56 Initialize(NULL);
57 }
58 };
59
50 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { 60 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) {
51 FakeImplProxy proxy; 61 FakeImplProxy proxy;
52 FakeLayerTreeHostImpl host_impl(&proxy); 62 FakeLayerTreeHostImpl host_impl(&proxy);
53 63 FakeLayerTreeHostClient fake_client(FakeLayerTreeHostClient::DIRECT_SOFTWARE);
64 LayerTreeSettings layer_tree_settings;
65 scoped_ptr<MockLayerTreeHost> layer_tree_host(
66 new MockLayerTreeHost(&fake_client, layer_tree_settings));
54 { 67 {
55 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 68 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
56 scoped_ptr<LayerImpl> layer_impl_tree_root = 69 scoped_ptr<LayerImpl> layer_impl_tree_root =
57 LayerImplForScrollAreaAndScrollbar( 70 LayerImplForScrollAreaAndScrollbar(
58 &host_impl, scrollbar.Pass(), false); 71 layer_tree_host.get(), &host_impl, scrollbar.Pass(), false, false);
59 72
60 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; 73 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0];
61 ScrollbarLayerImpl* cc_child2 = static_cast<ScrollbarLayerImpl*>( 74 ScrollbarLayerImpl* cc_child2 = static_cast<ScrollbarLayerImpl*>(
62 layer_impl_tree_root->children()[1]); 75 layer_impl_tree_root->children()[1]);
63 76
64 EXPECT_EQ(cc_child1->horizontal_scrollbar_layer(), cc_child2); 77 EXPECT_EQ(cc_child1->horizontal_scrollbar_layer(), cc_child2);
65 } 78 }
66 { 79 {
67 // another traverse order 80 // another traverse order
68 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 81 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
69 scoped_ptr<LayerImpl> layer_impl_tree_root = 82 scoped_ptr<LayerImpl> layer_impl_tree_root =
70 LayerImplForScrollAreaAndScrollbar( 83 LayerImplForScrollAreaAndScrollbar(
71 &host_impl, scrollbar.Pass(), true); 84 layer_tree_host.get(), &host_impl, scrollbar.Pass(), true, false);
72 85
73 ScrollbarLayerImpl* cc_child1 = static_cast<ScrollbarLayerImpl*>( 86 ScrollbarLayerImpl* cc_child1 = static_cast<ScrollbarLayerImpl*>(
74 layer_impl_tree_root->children()[0]); 87 layer_impl_tree_root->children()[0]);
75 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; 88 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1];
76 89
77 EXPECT_EQ(cc_child2->horizontal_scrollbar_layer(), cc_child1); 90 EXPECT_EQ(cc_child2->horizontal_scrollbar_layer(), cc_child1);
78 } 91 }
79 } 92 }
80 93
81 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { 94 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
82 FakeImplProxy proxy; 95 FakeImplProxy proxy;
83 FakeLayerTreeHostImpl host_impl(&proxy); 96 FakeLayerTreeHostImpl host_impl(&proxy);
97 FakeLayerTreeHostClient fake_client(FakeLayerTreeHostClient::DIRECT_SOFTWARE);
98 LayerTreeSettings layer_tree_settings;
99 scoped_ptr<MockLayerTreeHost> layer_tree_host(
100 new MockLayerTreeHost(&fake_client, layer_tree_settings));
84 101
85 // Create and attach a non-overlay scrollbar. 102 // Create and attach a non-overlay scrollbar.
86 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 103 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
87 scoped_ptr<LayerImpl> layer_impl_tree_root = 104 scoped_ptr<LayerImpl> layer_impl_tree_root =
88 LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false); 105 LayerImplForScrollAreaAndScrollbar(
106 layer_tree_host.get(), &host_impl, scrollbar.Pass(), false, false);
89 ScrollbarLayerImpl* scrollbar_layer_impl = 107 ScrollbarLayerImpl* scrollbar_layer_impl =
90 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); 108 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
91 109
92 // When the scrollbar is not an overlay scrollbar, the scroll should be 110 // When the scrollbar is not an overlay scrollbar, the scroll should be
93 // responded to on the main thread as the compositor does not yet implement 111 // responded to on the main thread as the compositor does not yet implement
94 // scrollbar scrolling. 112 // scrollbar scrolling.
95 EXPECT_EQ(InputHandler::ScrollOnMainThread, 113 EXPECT_EQ(InputHandler::ScrollOnMainThread,
96 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), 114 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0),
97 InputHandler::Gesture)); 115 InputHandler::Gesture));
98 116
99 // Create and attach an overlay scrollbar. 117 // Create and attach an overlay scrollbar.
100 scrollbar.reset(new FakeScrollbar(false, false, true)); 118 scrollbar.reset(new FakeScrollbar(false, false, true));
101 119
102 layer_impl_tree_root = 120 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
103 LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false); 121 layer_tree_host.get(), &host_impl, scrollbar.Pass(), false, false);
104 scrollbar_layer_impl = 122 scrollbar_layer_impl =
105 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); 123 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
106 124
107 // The user shouldn't be able to drag an overlay scrollbar and the scroll 125 // The user shouldn't be able to drag an overlay scrollbar and the scroll
108 // may be handled in the compositor. 126 // may be handled in the compositor.
109 EXPECT_EQ(InputHandler::ScrollIgnored, 127 EXPECT_EQ(InputHandler::ScrollIgnored,
110 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), 128 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0),
111 InputHandler::Gesture)); 129 InputHandler::Gesture));
112 } 130 }
113 131
114 TEST(ScrollbarLayerTest, ScrollOffsetSynchronization) { 132 TEST(ScrollbarLayerTest, ScrollOffsetSynchronization) {
115 FakeImplProxy proxy; 133 FakeImplProxy proxy;
116 FakeLayerTreeHostImpl host_impl(&proxy); 134 FakeLayerTreeHostImpl host_impl(&proxy);
135 FakeLayerTreeHostClient fake_client(FakeLayerTreeHostClient::DIRECT_SOFTWARE);
136 LayerTreeSettings layer_tree_settings;
137 scoped_ptr<MockLayerTreeHost> layer_tree_host(
138 new MockLayerTreeHost(&fake_client, layer_tree_settings));
117 139
118 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 140 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
119 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 141 scoped_refptr<Layer> layer_tree_root = Layer::Create();
120 scoped_refptr<Layer> content_layer = Layer::Create(); 142 scoped_refptr<Layer> content_layer = Layer::Create();
121 scoped_refptr<Layer> scrollbar_layer = 143 scoped_refptr<Layer> scrollbar_layer =
122 ScrollbarLayer::Create(scrollbar.Pass(), 144 ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id(), false);
123 layer_tree_root->id());
124 layer_tree_root->AddChild(content_layer); 145 layer_tree_root->AddChild(content_layer);
125 layer_tree_root->AddChild(scrollbar_layer); 146 layer_tree_root->AddChild(scrollbar_layer);
147 layer_tree_root->SetLayerTreeHost(layer_tree_host.get());
126 148
127 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); 149 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20));
128 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50)); 150 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50));
129 layer_tree_root->SetBounds(gfx::Size(100, 200)); 151 layer_tree_root->SetBounds(gfx::Size(100, 200));
130 layer_tree_root->SavePaintProperties(); 152 layer_tree_root->SavePaintProperties();
131 content_layer->SetBounds(gfx::Size(100, 200)); 153 content_layer->SetBounds(gfx::Size(100, 200));
132 content_layer->SavePaintProperties(); 154 content_layer->SavePaintProperties();
133 155
134 scoped_ptr<LayerImpl> layer_impl_tree_root = 156 scoped_ptr<LayerImpl> layer_impl_tree_root =
135 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 157 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
(...skipping 28 matching lines...) Expand all
164 186
165 EXPECT_EQ(100.f, cc_scrollbar_layer->CurrentPos()); 187 EXPECT_EQ(100.f, cc_scrollbar_layer->CurrentPos());
166 EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); 188 EXPECT_EQ(300, cc_scrollbar_layer->Maximum());
167 189
168 layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34)); 190 layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34));
169 191
170 EXPECT_EQ(112.f, cc_scrollbar_layer->CurrentPos()); 192 EXPECT_EQ(112.f, cc_scrollbar_layer->CurrentPos());
171 EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); 193 EXPECT_EQ(300, cc_scrollbar_layer->Maximum());
172 } 194 }
173 195
174 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { 196 class SolidScrollbarLayerQuadTest
197 : public ::testing::TestWithParam<bool> {
198 public:
199 SolidScrollbarLayerQuadTest()
200 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {
201 layer_tree_settings.force_solid_color_scrollbars = GetParam();
202 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3;
203 layer_tree_host_.reset(
204 new MockLayerTreeHost(&fake_client_, layer_tree_settings));
205
206 host_impl =
207 make_scoped_ptr(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy));
208 scrollbar = make_scoped_ptr(new FakeScrollbar(false, true, true));
209 layer_impl_tree_root =
210 LayerImplForScrollAreaAndScrollbar(layer_tree_host_.get(),
211 host_impl.get(),
212 scrollbar.Pass(),
213 false,
214 !GetParam());
215 scrollbar_layer_impl =
216 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
217 }
218
219 protected:
175 LayerTreeSettings layer_tree_settings; 220 LayerTreeSettings layer_tree_settings;
176 layer_tree_settings.solid_color_scrollbars = true;
177 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3;
178 FakeImplProxy proxy; 221 FakeImplProxy proxy;
179 FakeLayerTreeHostImpl host_impl(layer_tree_settings, &proxy); 222 scoped_ptr<FakeLayerTreeHostImpl> host_impl;
223 scoped_ptr<Scrollbar> scrollbar;
224 scoped_ptr<LayerImpl> layer_impl_tree_root;
225 ScrollbarLayerImpl* scrollbar_layer_impl;
226 FakeLayerTreeHostClient fake_client_;
227 scoped_ptr<MockLayerTreeHost> layer_tree_host_;
228 };
180 229
181 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); 230 TEST_P(SolidScrollbarLayerQuadTest, DrawQuads) {
182 scoped_ptr<LayerImpl> layer_impl_tree_root =
183 LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false);
184 ScrollbarLayerImpl* scrollbar_layer_impl =
185 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
186 scrollbar_layer_impl->set_thumb_thickness(3); 231 scrollbar_layer_impl->set_thumb_thickness(3);
187 scrollbar_layer_impl->SetCurrentPos(10.f); 232 scrollbar_layer_impl->SetCurrentPos(10.f);
188 scrollbar_layer_impl->SetMaximum(100); 233 scrollbar_layer_impl->SetMaximum(100);
189 scrollbar_layer_impl->set_track_length(100); 234 scrollbar_layer_impl->set_track_length(100);
190 scrollbar_layer_impl->set_visible_to_total_length_ratio(0.4f); 235 scrollbar_layer_impl->set_visible_to_total_length_ratio(0.4f);
191 236
192 // Thickness should be overridden to 3. 237 // Thickness should be overridden to 3.
193 { 238 {
194 MockQuadCuller quad_culler; 239 MockQuadCuller quad_culler;
195 AppendQuadsData data; 240 AppendQuadsData data;
(...skipping 29 matching lines...) Expand all
225 AppendQuadsData data; 270 AppendQuadsData data;
226 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); 271 scrollbar_layer_impl->AppendQuads(&quad_culler, &data);
227 272
228 const QuadList& quads = quad_culler.quad_list(); 273 const QuadList& quads = quad_culler.quad_list();
229 ASSERT_EQ(1u, quads.size()); 274 ASSERT_EQ(1u, quads.size());
230 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); 275 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material);
231 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect); 276 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect);
232 } 277 }
233 } 278 }
234 279
235 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { 280 TEST_P(SolidScrollbarLayerQuadTest, LayerDrivenSolidColorDrawQuads) {
236 LayerTreeSettings layer_tree_settings;
237 layer_tree_settings.solid_color_scrollbars = true;
238 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3;
239 FakeImplProxy proxy;
240 FakeLayerTreeHostImpl host_impl(layer_tree_settings, &proxy);
241
242 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
243 scoped_ptr<LayerImpl> layer_impl_tree_root =
244 LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false);
245 ScrollbarLayerImpl* scrollbar_layer_impl =
246 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
247
248 scrollbar_layer_impl->set_thumb_thickness(3); 281 scrollbar_layer_impl->set_thumb_thickness(3);
249 scrollbar_layer_impl->set_track_length(10); 282 scrollbar_layer_impl->set_track_length(10);
250 scrollbar_layer_impl->SetCurrentPos(4.f); 283 scrollbar_layer_impl->SetCurrentPos(4.f);
251 scrollbar_layer_impl->SetMaximum(8); 284 scrollbar_layer_impl->SetMaximum(8);
252 285
253 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); 286 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl);
254 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8)); 287 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8));
255 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); 288 layer_impl_tree_root->SetBounds(gfx::Size(2, 2));
256 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f)); 289 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f));
257 290
258 { 291 {
259 MockQuadCuller quad_culler; 292 MockQuadCuller quad_culler;
260 AppendQuadsData data; 293 AppendQuadsData data;
261 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); 294 scrollbar_layer_impl->AppendQuads(&quad_culler, &data);
262 295
263 const QuadList& quads = quad_culler.quad_list(); 296 const QuadList& quads = quad_culler.quad_list();
264 ASSERT_EQ(1u, quads.size()); 297 ASSERT_EQ(1u, quads.size());
265 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); 298 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material);
266 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect); 299 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect);
267 } 300 }
268 } 301 }
269 302
270 class ScrollbarLayerSolidColorThumbTest : public testing::Test { 303 INSTANTIATE_TEST_CASE_P(ParameterizedSolidColorScrollbarTest,
304 SolidScrollbarLayerQuadTest,
305 ::testing::Values(true, false));
306
307 class ScrollbarLayerSolidColorThumbTest : public testing::TestWithParam<bool> {
271 public: 308 public:
272 ScrollbarLayerSolidColorThumbTest() { 309 ScrollbarLayerSolidColorThumbTest() {
273 LayerTreeSettings layer_tree_settings; 310 LayerTreeSettings layer_tree_settings;
274 layer_tree_settings.solid_color_scrollbars = true; 311 layer_tree_settings.force_solid_color_scrollbars = GetParam();
275 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); 312 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_));
276 313
277 horizontal_scrollbar_layer_ = ScrollbarLayerImpl::Create( 314 horizontal_scrollbar_layer_ = ScrollbarLayerImpl::Create(
278 host_impl_->active_tree(), 1, HORIZONTAL); 315 host_impl_->active_tree(), 1, HORIZONTAL, true);
279 vertical_scrollbar_layer_ = ScrollbarLayerImpl::Create( 316 vertical_scrollbar_layer_ = ScrollbarLayerImpl::Create(
280 host_impl_->active_tree(), 2, VERTICAL); 317 host_impl_->active_tree(), 2, VERTICAL, true);
281 } 318 }
282 319
283 protected: 320 protected:
284 FakeImplProxy proxy_; 321 FakeImplProxy proxy_;
285 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; 322 scoped_ptr<FakeLayerTreeHostImpl> host_impl_;
286 scoped_ptr<ScrollbarLayerImpl> horizontal_scrollbar_layer_; 323 scoped_ptr<ScrollbarLayerImpl> horizontal_scrollbar_layer_;
287 scoped_ptr<ScrollbarLayerImpl> vertical_scrollbar_layer_; 324 scoped_ptr<ScrollbarLayerImpl> vertical_scrollbar_layer_;
288 }; 325 };
289 326
290 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { 327 TEST_P(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) {
291 horizontal_scrollbar_layer_->SetCurrentPos(0); 328 horizontal_scrollbar_layer_->SetCurrentPos(0);
292 horizontal_scrollbar_layer_->SetMaximum(10); 329 horizontal_scrollbar_layer_->SetMaximum(10);
293 horizontal_scrollbar_layer_->set_thumb_thickness(3); 330 horizontal_scrollbar_layer_->set_thumb_thickness(3);
294 331
295 // Simple case - one third of the scrollable area is visible, so the thumb 332 // Simple case - one third of the scrollable area is visible, so the thumb
296 // should be one third as long as the track. 333 // should be one third as long as the track.
297 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.33f); 334 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.33f);
298 horizontal_scrollbar_layer_->set_track_length(100); 335 horizontal_scrollbar_layer_->set_track_length(100);
299 EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); 336 EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width());
300 337
301 // The thumb's length should never be less than its thickness. 338 // The thumb's length should never be less than its thickness.
302 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.01f); 339 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.01f);
303 horizontal_scrollbar_layer_->set_track_length(100); 340 horizontal_scrollbar_layer_->set_track_length(100);
304 EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); 341 EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width());
305 } 342 }
306 343
307 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) { 344 TEST_P(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) {
308 horizontal_scrollbar_layer_->set_track_length(100); 345 horizontal_scrollbar_layer_->set_track_length(100);
309 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.1f); 346 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.1f);
310 horizontal_scrollbar_layer_->set_thumb_thickness(3); 347 horizontal_scrollbar_layer_->set_thumb_thickness(3);
311 348
312 horizontal_scrollbar_layer_->SetCurrentPos(0); 349 horizontal_scrollbar_layer_->SetCurrentPos(0);
313 horizontal_scrollbar_layer_->SetMaximum(100); 350 horizontal_scrollbar_layer_->SetMaximum(100);
314 EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); 351 EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x());
315 EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); 352 EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width());
316 353
317 horizontal_scrollbar_layer_->SetCurrentPos(100); 354 horizontal_scrollbar_layer_->SetCurrentPos(100);
318 // The thumb is 10px long and the track is 100px, so the maximum thumb 355 // The thumb is 10px long and the track is 100px, so the maximum thumb
319 // position is 90px. 356 // position is 90px.
320 EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); 357 EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x());
321 358
322 horizontal_scrollbar_layer_->SetCurrentPos(80); 359 horizontal_scrollbar_layer_->SetCurrentPos(80);
323 // The scroll position is 80% of the maximum, so the thumb's position should 360 // The scroll position is 80% of the maximum, so the thumb's position should
324 // be at 80% of its maximum or 72px. 361 // be at 80% of its maximum or 72px.
325 EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); 362 EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x());
326 } 363 }
327 364
328 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) { 365 TEST_P(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) {
329 ScrollbarLayerImpl* layers[2] = 366 ScrollbarLayerImpl* layers[2] =
330 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; 367 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() };
331 for (size_t i = 0; i < 2; ++i) { 368 for (size_t i = 0; i < 2; ++i) {
332 layers[i]->set_track_length(100); 369 layers[i]->set_track_length(100);
333 layers[i]->set_visible_to_total_length_ratio(0.2f); 370 layers[i]->set_visible_to_total_length_ratio(0.2f);
334 layers[i]->set_thumb_thickness(3); 371 layers[i]->set_thumb_thickness(3);
335 layers[i]->SetCurrentPos(25); 372 layers[i]->SetCurrentPos(25);
336 layers[i]->SetMaximum(100); 373 layers[i]->SetMaximum(100);
337 } 374 }
338 375
339 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f), 376 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f),
340 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); 377 horizontal_scrollbar_layer_->ComputeThumbQuadRect());
341 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f), 378 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f),
342 vertical_scrollbar_layer_->ComputeThumbQuadRect()); 379 vertical_scrollbar_layer_->ComputeThumbQuadRect());
343 380
344 horizontal_scrollbar_layer_->set_vertical_adjust(10.f); 381 horizontal_scrollbar_layer_->set_vertical_adjust(10.f);
345 vertical_scrollbar_layer_->set_vertical_adjust(10.f); 382 vertical_scrollbar_layer_->set_vertical_adjust(10.f);
346 383
347 // The vertical adjustment factor has two effects: 384 // The vertical adjustment factor has two effects:
348 // 1.) Moves the horizontal scrollbar down 385 // 1.) Moves the horizontal scrollbar down
349 // 2.) Increases the vertical scrollbar's effective track length which both 386 // 2.) Increases the vertical scrollbar's effective track length which both
350 // increases the thumb's length and its position within the track. 387 // increases the thumb's length and its position within the track.
351 EXPECT_RECT_EQ(gfx::Rect(20.f, 10.f, 20.f, 3.f), 388 EXPECT_RECT_EQ(gfx::Rect(20.f, 10.f, 20.f, 3.f),
352 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); 389 horizontal_scrollbar_layer_->ComputeThumbQuadRect());
353 EXPECT_RECT_EQ(gfx::Rect(0.f, 22, 3.f, 22.f), 390 EXPECT_RECT_EQ(gfx::Rect(0.f, 22, 3.f, 22.f),
354 vertical_scrollbar_layer_->ComputeThumbQuadRect()); 391 vertical_scrollbar_layer_->ComputeThumbQuadRect());
355 } 392 }
356 393
394 INSTANTIATE_TEST_CASE_P(ParameterizedSolidColorThumbTest,
395 ScrollbarLayerSolidColorThumbTest,
396 ::testing::Values(true, false));
397
357 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest { 398 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest {
358 public: 399 public:
359 ScrollbarLayerTestMaxTextureSize() {} 400 ScrollbarLayerTestMaxTextureSize() {}
360 401
361 void SetScrollbarBounds(gfx::Size bounds) { bounds_ = bounds; } 402 void SetScrollbarBounds(gfx::Size bounds) { bounds_ = bounds; }
362 403
363 virtual void BeginTest() OVERRIDE { 404 virtual void BeginTest() OVERRIDE {
364 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 405 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
365 scrollbar_layer_ = ScrollbarLayer::Create(scrollbar.Pass(), 1); 406 scrollbar_layer_ = ScrollbarLayer::Create(scrollbar.Pass(), 1, false);
366 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); 407 scrollbar_layer_->SetLayerTreeHost(layer_tree_host());
367 scrollbar_layer_->SetBounds(bounds_); 408 scrollbar_layer_->SetBounds(bounds_);
368 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); 409 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_);
369 410
370 scroll_layer_ = Layer::Create(); 411 scroll_layer_ = Layer::Create();
371 scrollbar_layer_->SetScrollLayerId(scroll_layer_->id()); 412 scrollbar_layer_->SetScrollLayerId(scroll_layer_->id());
372 layer_tree_host()->root_layer()->AddChild(scroll_layer_); 413 layer_tree_host()->root_layer()->AddChild(scroll_layer_);
373 414
374 PostSetNeedsCommitToMainThread(); 415 PostSetNeedsCommitToMainThread();
375 } 416 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 449
409 TEST_F(ScrollbarLayerTestMaxTextureSize, DelegatingRenderer) { 450 TEST_F(ScrollbarLayerTestMaxTextureSize, DelegatingRenderer) {
410 scoped_ptr<TestWebGraphicsContext3D> context = 451 scoped_ptr<TestWebGraphicsContext3D> context =
411 TestWebGraphicsContext3D::Create(); 452 TestWebGraphicsContext3D::Create();
412 int max_size = 0; 453 int max_size = 0;
413 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); 454 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size);
414 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); 455 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100));
415 RunTest(true, true, true); 456 RunTest(true, true, true);
416 } 457 }
417 458
418 class MockLayerTreeHost : public LayerTreeHost {
419 public:
420 MockLayerTreeHost(LayerTreeHostClient* client,
421 const LayerTreeSettings& settings)
422 : LayerTreeHost(client, settings) {
423 Initialize(NULL);
424 }
425 };
426
427
428 class ScrollbarLayerTestResourceCreation : public testing::Test { 459 class ScrollbarLayerTestResourceCreation : public testing::Test {
429 public: 460 public:
430 ScrollbarLayerTestResourceCreation() 461 ScrollbarLayerTestResourceCreation()
431 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 462 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
432 463
433 void TestResourceUpload(size_t expected_resources) { 464 void TestResourceUpload(size_t expected_resources) {
434 layer_tree_host_.reset( 465 layer_tree_host_.reset(
435 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); 466 new MockLayerTreeHost(&fake_client_, layer_tree_settings_));
436 467
437 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); 468 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false));
438 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 469 scoped_refptr<Layer> layer_tree_root = Layer::Create();
439 scoped_refptr<Layer> content_layer = Layer::Create(); 470 scoped_refptr<Layer> content_layer = Layer::Create();
440 scoped_refptr<Layer> scrollbar_layer = 471 scoped_refptr<Layer> scrollbar_layer =
441 ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); 472 ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id(), false);
442 layer_tree_root->AddChild(content_layer); 473 layer_tree_root->AddChild(content_layer);
443 layer_tree_root->AddChild(scrollbar_layer); 474 layer_tree_root->AddChild(scrollbar_layer);
444 475
445 layer_tree_host_->InitializeOutputSurfaceIfNeeded(); 476 layer_tree_host_->InitializeOutputSurfaceIfNeeded();
446 layer_tree_host_->contents_texture_manager()-> 477 layer_tree_host_->contents_texture_manager()->
447 SetMaxMemoryLimitBytes(1024 * 1024); 478 SetMaxMemoryLimitBytes(1024 * 1024);
448 layer_tree_host_->SetRootLayer(layer_tree_root); 479 layer_tree_host_->SetRootLayer(layer_tree_root);
449 480
450 scrollbar_layer->SetIsDrawable(true); 481 scrollbar_layer->SetIsDrawable(true);
451 scrollbar_layer->SetBounds(gfx::Size(100, 100)); 482 scrollbar_layer->SetBounds(gfx::Size(100, 100));
(...skipping 23 matching lines...) Expand all
475 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 506 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
476 } 507 }
477 508
478 protected: 509 protected:
479 FakeLayerTreeHostClient fake_client_; 510 FakeLayerTreeHostClient fake_client_;
480 LayerTreeSettings layer_tree_settings_; 511 LayerTreeSettings layer_tree_settings_;
481 scoped_ptr<MockLayerTreeHost> layer_tree_host_; 512 scoped_ptr<MockLayerTreeHost> layer_tree_host_;
482 }; 513 };
483 514
484 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { 515 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) {
485 layer_tree_settings_.solid_color_scrollbars = false; 516 layer_tree_settings_.force_solid_color_scrollbars = false;
486 TestResourceUpload(2); 517 TestResourceUpload(2);
487 } 518 }
488 519
489 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { 520 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) {
490 layer_tree_settings_.solid_color_scrollbars = true; 521 layer_tree_settings_.force_solid_color_scrollbars = true;
491 TestResourceUpload(0); 522 TestResourceUpload(0);
492 } 523 }
493 524
494 class ScaledScrollbarLayerTestResourceCreation : public testing::Test { 525 class ScaledScrollbarLayerTestResourceCreation : public testing::Test {
495 public: 526 public:
496 ScaledScrollbarLayerTestResourceCreation() 527 ScaledScrollbarLayerTestResourceCreation()
497 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 528 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
498 529
499 void TestResourceUpload(size_t expected_resources, const float test_scale) { 530 void TestResourceUpload(size_t expected_resources, const float test_scale) {
500 layer_tree_host_.reset( 531 layer_tree_host_.reset(
501 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); 532 new MockLayerTreeHost(&fake_client_, layer_tree_settings_));
502 533
503 gfx::Point scrollbar_location(0, 185); 534 gfx::Point scrollbar_location(0, 185);
504 scoped_ptr<FakeScrollbar> scrollbar(new FakeScrollbar(false, true, false)); 535 scoped_ptr<FakeScrollbar> scrollbar(new FakeScrollbar(false, true, false));
505 scrollbar->set_location(scrollbar_location); 536 scrollbar->set_location(scrollbar_location);
506 537
507 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 538 scoped_refptr<Layer> layer_tree_root = Layer::Create();
508 scoped_refptr<Layer> content_layer = Layer::Create(); 539 scoped_refptr<Layer> content_layer = Layer::Create();
509 scoped_refptr<Layer> scrollbar_layer = 540 scoped_refptr<Layer> scrollbar_layer = ScrollbarLayer::Create(
510 ScrollbarLayer::Create(scrollbar.PassAs<cc::Scrollbar>(), 541 scrollbar.PassAs<cc::Scrollbar>(), layer_tree_root->id(), false);
511 layer_tree_root->id());
512 layer_tree_root->AddChild(content_layer); 542 layer_tree_root->AddChild(content_layer);
513 layer_tree_root->AddChild(scrollbar_layer); 543 layer_tree_root->AddChild(scrollbar_layer);
514 544
515 layer_tree_host_->InitializeOutputSurfaceIfNeeded(); 545 layer_tree_host_->InitializeOutputSurfaceIfNeeded();
516 layer_tree_host_->contents_texture_manager()-> 546 layer_tree_host_->contents_texture_manager()->
517 SetMaxMemoryLimitBytes(1024 * 1024); 547 SetMaxMemoryLimitBytes(1024 * 1024);
518 layer_tree_host_->SetRootLayer(layer_tree_root); 548 layer_tree_host_->SetRootLayer(layer_tree_root);
519 549
520 scrollbar_layer->SetIsDrawable(true); 550 scrollbar_layer->SetIsDrawable(true);
521 scrollbar_layer->SetBounds(gfx::Size(100, 15)); 551 scrollbar_layer->SetBounds(gfx::Size(100, 15));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 598 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
569 } 599 }
570 600
571 protected: 601 protected:
572 FakeLayerTreeHostClient fake_client_; 602 FakeLayerTreeHostClient fake_client_;
573 LayerTreeSettings layer_tree_settings_; 603 LayerTreeSettings layer_tree_settings_;
574 scoped_ptr<MockLayerTreeHost> layer_tree_host_; 604 scoped_ptr<MockLayerTreeHost> layer_tree_host_;
575 }; 605 };
576 606
577 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { 607 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) {
578 layer_tree_settings_.solid_color_scrollbars = false; 608 layer_tree_settings_.force_solid_color_scrollbars = false;
579 // Pick a test scale that moves the scrollbar's (non-zero) position to 609 // Pick a test scale that moves the scrollbar's (non-zero) position to
580 // a non-pixel-aligned location. 610 // a non-pixel-aligned location.
581 TestResourceUpload(2, 1.41f); 611 TestResourceUpload(2, 1.41f);
582 } 612 }
583 613
584 } // namespace 614 } // namespace
585 } // namespace cc 615 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698