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

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: 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 13 matching lines...) Expand all
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 FakeLayerTreeHostImpl* host_impl, 32 FakeLayerTreeHostImpl* host_impl,
33 scoped_ptr<Scrollbar> scrollbar, 33 scoped_ptr<Scrollbar> scrollbar,
34 bool reverse_order) { 34 bool reverse_order, bool is_solid_color = false) {
aelias_OOO_until_Jul13 2013/06/21 23:34:35 Default params aren't allowed by the style guide.
wjmaclean 2013/06/24 14:06:41 Removed.
35 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 35 scoped_refptr<Layer> layer_tree_root = Layer::Create();
36 scoped_refptr<Layer> child1 = Layer::Create(); 36 scoped_refptr<Layer> child1 = Layer::Create();
37 scoped_refptr<Layer> child2 = 37 scoped_refptr<Layer> child2 =
38 ScrollbarLayer::Create(scrollbar.Pass(), 38 ScrollbarLayer::Create(scrollbar.Pass(), child1->id(), is_solid_color);
39 child1->id());
40 layer_tree_root->AddChild(child1); 39 layer_tree_root->AddChild(child1);
41 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); 40 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1);
42 scoped_ptr<LayerImpl> layer_impl = 41 scoped_ptr<LayerImpl> layer_impl =
43 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 42 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
44 scoped_ptr<LayerImpl>(), 43 scoped_ptr<LayerImpl>(),
45 host_impl->active_tree()); 44 host_impl->active_tree());
46 TreeSynchronizer::PushProperties(layer_tree_root.get(), layer_impl.get()); 45 TreeSynchronizer::PushProperties(layer_tree_root.get(), layer_impl.get());
47 return layer_impl.Pass(); 46 return layer_impl.Pass();
48 } 47 }
49 48
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 111 }
113 112
114 TEST(ScrollbarLayerTest, ScrollOffsetSynchronization) { 113 TEST(ScrollbarLayerTest, ScrollOffsetSynchronization) {
115 FakeImplProxy proxy; 114 FakeImplProxy proxy;
116 FakeLayerTreeHostImpl host_impl(&proxy); 115 FakeLayerTreeHostImpl host_impl(&proxy);
117 116
118 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 117 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
119 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 118 scoped_refptr<Layer> layer_tree_root = Layer::Create();
120 scoped_refptr<Layer> content_layer = Layer::Create(); 119 scoped_refptr<Layer> content_layer = Layer::Create();
121 scoped_refptr<Layer> scrollbar_layer = 120 scoped_refptr<Layer> scrollbar_layer =
122 ScrollbarLayer::Create(scrollbar.Pass(), 121 ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id(), false);
123 layer_tree_root->id());
124 layer_tree_root->AddChild(content_layer); 122 layer_tree_root->AddChild(content_layer);
125 layer_tree_root->AddChild(scrollbar_layer); 123 layer_tree_root->AddChild(scrollbar_layer);
126 124
127 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); 125 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20));
128 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50)); 126 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50));
129 layer_tree_root->SetBounds(gfx::Size(100, 200)); 127 layer_tree_root->SetBounds(gfx::Size(100, 200));
130 layer_tree_root->SavePaintProperties(); 128 layer_tree_root->SavePaintProperties();
131 content_layer->SetBounds(gfx::Size(100, 200)); 129 content_layer->SetBounds(gfx::Size(100, 200));
132 content_layer->SavePaintProperties(); 130 content_layer->SavePaintProperties();
133 131
(...skipping 30 matching lines...) Expand all
164 162
165 EXPECT_EQ(100.f, cc_scrollbar_layer->CurrentPos()); 163 EXPECT_EQ(100.f, cc_scrollbar_layer->CurrentPos());
166 EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); 164 EXPECT_EQ(300, cc_scrollbar_layer->Maximum());
167 165
168 layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34)); 166 layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34));
169 167
170 EXPECT_EQ(112.f, cc_scrollbar_layer->CurrentPos()); 168 EXPECT_EQ(112.f, cc_scrollbar_layer->CurrentPos());
171 EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); 169 EXPECT_EQ(300, cc_scrollbar_layer->Maximum());
172 } 170 }
173 171
174 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { 172 class SolidScrollbarLayerQuadTest
173 : public ::testing::TestWithParam<bool> {
174 public:
175 SolidScrollbarLayerQuadTest() {
176 layer_tree_settings.force_solid_color_scrollbars = GetParam();
177 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3;
178
179 host_impl =
180 make_scoped_ptr(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy));
181 scrollbar = make_scoped_ptr(new FakeScrollbar(false, true, true));
182 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
183 host_impl.get(), scrollbar.Pass(), false, !GetParam());
184 scrollbar_layer_impl =
185 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
186 }
187
188 protected:
175 LayerTreeSettings layer_tree_settings; 189 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; 190 FakeImplProxy proxy;
179 FakeLayerTreeHostImpl host_impl(layer_tree_settings, &proxy); 191 scoped_ptr<FakeLayerTreeHostImpl> host_impl;
192 scoped_ptr<Scrollbar> scrollbar;
193 scoped_ptr<LayerImpl> layer_impl_tree_root;
194 ScrollbarLayerImpl* scrollbar_layer_impl;
195 };
180 196
181 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); 197 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); 198 scrollbar_layer_impl->set_thumb_thickness(3);
187 scrollbar_layer_impl->SetCurrentPos(10.f); 199 scrollbar_layer_impl->SetCurrentPos(10.f);
188 scrollbar_layer_impl->SetMaximum(100); 200 scrollbar_layer_impl->SetMaximum(100);
189 scrollbar_layer_impl->set_track_length(100); 201 scrollbar_layer_impl->set_track_length(100);
190 scrollbar_layer_impl->set_visible_to_total_length_ratio(0.4f); 202 scrollbar_layer_impl->set_visible_to_total_length_ratio(0.4f);
191 203
192 // Thickness should be overridden to 3. 204 // Thickness should be overridden to 3.
193 { 205 {
194 MockQuadCuller quad_culler; 206 MockQuadCuller quad_culler;
195 AppendQuadsData data; 207 AppendQuadsData data;
(...skipping 29 matching lines...) Expand all
225 AppendQuadsData data; 237 AppendQuadsData data;
226 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); 238 scrollbar_layer_impl->AppendQuads(&quad_culler, &data);
227 239
228 const QuadList& quads = quad_culler.quad_list(); 240 const QuadList& quads = quad_culler.quad_list();
229 ASSERT_EQ(1u, quads.size()); 241 ASSERT_EQ(1u, quads.size());
230 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); 242 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material);
231 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect); 243 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect);
232 } 244 }
233 } 245 }
234 246
235 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { 247 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); 248 scrollbar_layer_impl->set_thumb_thickness(3);
249 scrollbar_layer_impl->set_track_length(10); 249 scrollbar_layer_impl->set_track_length(10);
250 scrollbar_layer_impl->SetCurrentPos(4.f); 250 scrollbar_layer_impl->SetCurrentPos(4.f);
251 scrollbar_layer_impl->SetMaximum(8); 251 scrollbar_layer_impl->SetMaximum(8);
252 252
253 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); 253 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl);
254 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8)); 254 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8));
255 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); 255 layer_impl_tree_root->SetBounds(gfx::Size(2, 2));
256 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f)); 256 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f));
257 257
258 { 258 {
259 MockQuadCuller quad_culler; 259 MockQuadCuller quad_culler;
260 AppendQuadsData data; 260 AppendQuadsData data;
261 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); 261 scrollbar_layer_impl->AppendQuads(&quad_culler, &data);
262 262
263 const QuadList& quads = quad_culler.quad_list(); 263 const QuadList& quads = quad_culler.quad_list();
264 ASSERT_EQ(1u, quads.size()); 264 ASSERT_EQ(1u, quads.size());
265 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); 265 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material);
266 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect); 266 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect);
267 } 267 }
268 } 268 }
269 269
270 class ScrollbarLayerSolidColorThumbTest : public testing::Test { 270 INSTANTIATE_TEST_CASE_P(ParameterizedSolidColorScrollbarTest,
271 SolidScrollbarLayerQuadTest,
272 ::testing::Values(true, false));
273
274 class ScrollbarLayerSolidColorThumbTest : public testing::TestWithParam<bool> {
271 public: 275 public:
272 ScrollbarLayerSolidColorThumbTest() { 276 ScrollbarLayerSolidColorThumbTest() {
273 LayerTreeSettings layer_tree_settings; 277 LayerTreeSettings layer_tree_settings;
274 layer_tree_settings.solid_color_scrollbars = true; 278 layer_tree_settings.force_solid_color_scrollbars = GetParam();
275 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); 279 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_));
276 280
277 horizontal_scrollbar_layer_ = ScrollbarLayerImpl::Create( 281 horizontal_scrollbar_layer_ = ScrollbarLayerImpl::Create(
278 host_impl_->active_tree(), 1, HORIZONTAL); 282 host_impl_->active_tree(), 1, HORIZONTAL, !GetParam());
279 vertical_scrollbar_layer_ = ScrollbarLayerImpl::Create( 283 vertical_scrollbar_layer_ = ScrollbarLayerImpl::Create(
280 host_impl_->active_tree(), 2, VERTICAL); 284 host_impl_->active_tree(), 2, VERTICAL, !GetParam());
281 } 285 }
282 286
283 protected: 287 protected:
284 FakeImplProxy proxy_; 288 FakeImplProxy proxy_;
285 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; 289 scoped_ptr<FakeLayerTreeHostImpl> host_impl_;
286 scoped_ptr<ScrollbarLayerImpl> horizontal_scrollbar_layer_; 290 scoped_ptr<ScrollbarLayerImpl> horizontal_scrollbar_layer_;
287 scoped_ptr<ScrollbarLayerImpl> vertical_scrollbar_layer_; 291 scoped_ptr<ScrollbarLayerImpl> vertical_scrollbar_layer_;
288 }; 292 };
289 293
290 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { 294 TEST_P(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) {
291 horizontal_scrollbar_layer_->SetCurrentPos(0); 295 horizontal_scrollbar_layer_->SetCurrentPos(0);
292 horizontal_scrollbar_layer_->SetMaximum(10); 296 horizontal_scrollbar_layer_->SetMaximum(10);
293 horizontal_scrollbar_layer_->set_thumb_thickness(3); 297 horizontal_scrollbar_layer_->set_thumb_thickness(3);
294 298
295 // Simple case - one third of the scrollable area is visible, so the thumb 299 // Simple case - one third of the scrollable area is visible, so the thumb
296 // should be one third as long as the track. 300 // should be one third as long as the track.
297 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.33f); 301 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.33f);
298 horizontal_scrollbar_layer_->set_track_length(100); 302 horizontal_scrollbar_layer_->set_track_length(100);
299 EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); 303 EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width());
300 304
301 // The thumb's length should never be less than its thickness. 305 // The thumb's length should never be less than its thickness.
302 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.01f); 306 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.01f);
303 horizontal_scrollbar_layer_->set_track_length(100); 307 horizontal_scrollbar_layer_->set_track_length(100);
304 EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); 308 EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width());
305 } 309 }
306 310
307 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) { 311 TEST_P(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) {
308 horizontal_scrollbar_layer_->set_track_length(100); 312 horizontal_scrollbar_layer_->set_track_length(100);
309 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.1f); 313 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.1f);
310 horizontal_scrollbar_layer_->set_thumb_thickness(3); 314 horizontal_scrollbar_layer_->set_thumb_thickness(3);
311 315
312 horizontal_scrollbar_layer_->SetCurrentPos(0); 316 horizontal_scrollbar_layer_->SetCurrentPos(0);
313 horizontal_scrollbar_layer_->SetMaximum(100); 317 horizontal_scrollbar_layer_->SetMaximum(100);
314 EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); 318 EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x());
315 EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); 319 EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width());
316 320
317 horizontal_scrollbar_layer_->SetCurrentPos(100); 321 horizontal_scrollbar_layer_->SetCurrentPos(100);
318 // The thumb is 10px long and the track is 100px, so the maximum thumb 322 // The thumb is 10px long and the track is 100px, so the maximum thumb
319 // position is 90px. 323 // position is 90px.
320 EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); 324 EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x());
321 325
322 horizontal_scrollbar_layer_->SetCurrentPos(80); 326 horizontal_scrollbar_layer_->SetCurrentPos(80);
323 // The scroll position is 80% of the maximum, so the thumb's position should 327 // The scroll position is 80% of the maximum, so the thumb's position should
324 // be at 80% of its maximum or 72px. 328 // be at 80% of its maximum or 72px.
325 EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); 329 EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x());
326 } 330 }
327 331
328 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) { 332 TEST_P(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) {
329 ScrollbarLayerImpl* layers[2] = 333 ScrollbarLayerImpl* layers[2] =
330 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; 334 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() };
331 for (size_t i = 0; i < 2; ++i) { 335 for (size_t i = 0; i < 2; ++i) {
332 layers[i]->set_track_length(100); 336 layers[i]->set_track_length(100);
333 layers[i]->set_visible_to_total_length_ratio(0.2f); 337 layers[i]->set_visible_to_total_length_ratio(0.2f);
334 layers[i]->set_thumb_thickness(3); 338 layers[i]->set_thumb_thickness(3);
335 layers[i]->SetCurrentPos(25); 339 layers[i]->SetCurrentPos(25);
336 layers[i]->SetMaximum(100); 340 layers[i]->SetMaximum(100);
337 } 341 }
338 342
339 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f), 343 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f),
340 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); 344 horizontal_scrollbar_layer_->ComputeThumbQuadRect());
341 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f), 345 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f),
342 vertical_scrollbar_layer_->ComputeThumbQuadRect()); 346 vertical_scrollbar_layer_->ComputeThumbQuadRect());
343 347
344 horizontal_scrollbar_layer_->set_vertical_adjust(10.f); 348 horizontal_scrollbar_layer_->set_vertical_adjust(10.f);
345 vertical_scrollbar_layer_->set_vertical_adjust(10.f); 349 vertical_scrollbar_layer_->set_vertical_adjust(10.f);
346 350
347 // The vertical adjustment factor has two effects: 351 // The vertical adjustment factor has two effects:
348 // 1.) Moves the horizontal scrollbar down 352 // 1.) Moves the horizontal scrollbar down
349 // 2.) Increases the vertical scrollbar's effective track length which both 353 // 2.) Increases the vertical scrollbar's effective track length which both
350 // increases the thumb's length and its position within the track. 354 // 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), 355 EXPECT_RECT_EQ(gfx::Rect(20.f, 10.f, 20.f, 3.f),
352 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); 356 horizontal_scrollbar_layer_->ComputeThumbQuadRect());
353 EXPECT_RECT_EQ(gfx::Rect(0.f, 22, 3.f, 22.f), 357 EXPECT_RECT_EQ(gfx::Rect(0.f, 22, 3.f, 22.f),
354 vertical_scrollbar_layer_->ComputeThumbQuadRect()); 358 vertical_scrollbar_layer_->ComputeThumbQuadRect());
355 } 359 }
356 360
361 INSTANTIATE_TEST_CASE_P(ParameterizedSolidColorThumbTest,
362 ScrollbarLayerSolidColorThumbTest,
363 ::testing::Values(true, false));
364
357 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest { 365 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest {
358 public: 366 public:
359 ScrollbarLayerTestMaxTextureSize() {} 367 ScrollbarLayerTestMaxTextureSize() {}
360 368
361 void SetScrollbarBounds(gfx::Size bounds) { bounds_ = bounds; } 369 void SetScrollbarBounds(gfx::Size bounds) { bounds_ = bounds; }
362 370
363 virtual void BeginTest() OVERRIDE { 371 virtual void BeginTest() OVERRIDE {
364 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 372 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
365 scrollbar_layer_ = ScrollbarLayer::Create(scrollbar.Pass(), 1); 373 scrollbar_layer_ = ScrollbarLayer::Create(scrollbar.Pass(), 1, false);
366 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); 374 scrollbar_layer_->SetLayerTreeHost(layer_tree_host());
367 scrollbar_layer_->SetBounds(bounds_); 375 scrollbar_layer_->SetBounds(bounds_);
368 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); 376 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_);
369 377
370 scroll_layer_ = Layer::Create(); 378 scroll_layer_ = Layer::Create();
371 scrollbar_layer_->SetScrollLayerId(scroll_layer_->id()); 379 scrollbar_layer_->SetScrollLayerId(scroll_layer_->id());
372 layer_tree_host()->root_layer()->AddChild(scroll_layer_); 380 layer_tree_host()->root_layer()->AddChild(scroll_layer_);
373 381
374 PostSetNeedsCommitToMainThread(); 382 PostSetNeedsCommitToMainThread();
375 } 383 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 439 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
432 440
433 void TestResourceUpload(size_t expected_resources) { 441 void TestResourceUpload(size_t expected_resources) {
434 layer_tree_host_.reset( 442 layer_tree_host_.reset(
435 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); 443 new MockLayerTreeHost(&fake_client_, layer_tree_settings_));
436 444
437 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); 445 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false));
438 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 446 scoped_refptr<Layer> layer_tree_root = Layer::Create();
439 scoped_refptr<Layer> content_layer = Layer::Create(); 447 scoped_refptr<Layer> content_layer = Layer::Create();
440 scoped_refptr<Layer> scrollbar_layer = 448 scoped_refptr<Layer> scrollbar_layer =
441 ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); 449 ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id(), false);
442 layer_tree_root->AddChild(content_layer); 450 layer_tree_root->AddChild(content_layer);
443 layer_tree_root->AddChild(scrollbar_layer); 451 layer_tree_root->AddChild(scrollbar_layer);
444 452
445 layer_tree_host_->InitializeOutputSurfaceIfNeeded(); 453 layer_tree_host_->InitializeOutputSurfaceIfNeeded();
446 layer_tree_host_->contents_texture_manager()-> 454 layer_tree_host_->contents_texture_manager()->
447 SetMaxMemoryLimitBytes(1024 * 1024); 455 SetMaxMemoryLimitBytes(1024 * 1024);
448 layer_tree_host_->SetRootLayer(layer_tree_root); 456 layer_tree_host_->SetRootLayer(layer_tree_root);
449 457
450 scrollbar_layer->SetIsDrawable(true); 458 scrollbar_layer->SetIsDrawable(true);
451 scrollbar_layer->SetBounds(gfx::Size(100, 100)); 459 scrollbar_layer->SetBounds(gfx::Size(100, 100));
(...skipping 23 matching lines...) Expand all
475 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 483 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
476 } 484 }
477 485
478 protected: 486 protected:
479 FakeLayerTreeHostClient fake_client_; 487 FakeLayerTreeHostClient fake_client_;
480 LayerTreeSettings layer_tree_settings_; 488 LayerTreeSettings layer_tree_settings_;
481 scoped_ptr<MockLayerTreeHost> layer_tree_host_; 489 scoped_ptr<MockLayerTreeHost> layer_tree_host_;
482 }; 490 };
483 491
484 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { 492 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) {
485 layer_tree_settings_.solid_color_scrollbars = false; 493 layer_tree_settings_.force_solid_color_scrollbars = false;
486 TestResourceUpload(2); 494 TestResourceUpload(2);
487 } 495 }
488 496
489 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { 497 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) {
490 layer_tree_settings_.solid_color_scrollbars = true; 498 layer_tree_settings_.force_solid_color_scrollbars = true;
491 TestResourceUpload(0); 499 TestResourceUpload(0);
492 } 500 }
493 501
494 class ScaledScrollbarLayerTestResourceCreation : public testing::Test { 502 class ScaledScrollbarLayerTestResourceCreation : public testing::Test {
495 public: 503 public:
496 ScaledScrollbarLayerTestResourceCreation() 504 ScaledScrollbarLayerTestResourceCreation()
497 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 505 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
498 506
499 void TestResourceUpload(size_t expected_resources, const float test_scale) { 507 void TestResourceUpload(size_t expected_resources, const float test_scale) {
500 layer_tree_host_.reset( 508 layer_tree_host_.reset(
501 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); 509 new MockLayerTreeHost(&fake_client_, layer_tree_settings_));
502 510
503 gfx::Point scrollbar_location(0, 185); 511 gfx::Point scrollbar_location(0, 185);
504 scoped_ptr<FakeScrollbar> scrollbar(new FakeScrollbar(false, true, false)); 512 scoped_ptr<FakeScrollbar> scrollbar(new FakeScrollbar(false, true, false));
505 scrollbar->set_location(scrollbar_location); 513 scrollbar->set_location(scrollbar_location);
506 514
507 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 515 scoped_refptr<Layer> layer_tree_root = Layer::Create();
508 scoped_refptr<Layer> content_layer = Layer::Create(); 516 scoped_refptr<Layer> content_layer = Layer::Create();
509 scoped_refptr<Layer> scrollbar_layer = 517 scoped_refptr<Layer> scrollbar_layer = ScrollbarLayer::Create(
510 ScrollbarLayer::Create(scrollbar.PassAs<cc::Scrollbar>(), 518 scrollbar.PassAs<cc::Scrollbar>(), layer_tree_root->id(), false);
511 layer_tree_root->id());
512 layer_tree_root->AddChild(content_layer); 519 layer_tree_root->AddChild(content_layer);
513 layer_tree_root->AddChild(scrollbar_layer); 520 layer_tree_root->AddChild(scrollbar_layer);
514 521
515 layer_tree_host_->InitializeOutputSurfaceIfNeeded(); 522 layer_tree_host_->InitializeOutputSurfaceIfNeeded();
516 layer_tree_host_->contents_texture_manager()-> 523 layer_tree_host_->contents_texture_manager()->
517 SetMaxMemoryLimitBytes(1024 * 1024); 524 SetMaxMemoryLimitBytes(1024 * 1024);
518 layer_tree_host_->SetRootLayer(layer_tree_root); 525 layer_tree_host_->SetRootLayer(layer_tree_root);
519 526
520 scrollbar_layer->SetIsDrawable(true); 527 scrollbar_layer->SetIsDrawable(true);
521 scrollbar_layer->SetBounds(gfx::Size(100, 15)); 528 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()); 575 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
569 } 576 }
570 577
571 protected: 578 protected:
572 FakeLayerTreeHostClient fake_client_; 579 FakeLayerTreeHostClient fake_client_;
573 LayerTreeSettings layer_tree_settings_; 580 LayerTreeSettings layer_tree_settings_;
574 scoped_ptr<MockLayerTreeHost> layer_tree_host_; 581 scoped_ptr<MockLayerTreeHost> layer_tree_host_;
575 }; 582 };
576 583
577 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { 584 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) {
578 layer_tree_settings_.solid_color_scrollbars = false; 585 layer_tree_settings_.force_solid_color_scrollbars = false;
579 // Pick a test scale that moves the scrollbar's (non-zero) position to 586 // Pick a test scale that moves the scrollbar's (non-zero) position to
580 // a non-pixel-aligned location. 587 // a non-pixel-aligned location.
581 TestResourceUpload(2, 1.41f); 588 TestResourceUpload(2, 1.41f);
582 } 589 }
583 590
584 } // namespace 591 } // namespace
585 } // namespace cc 592 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698