scrollbar_layer_unittest.cc revision a93a17c8d99d686bd4a1511e5504e5e6cc9fcadf
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 3// found in the LICENSE file. 4 5#include "cc/layers/scrollbar_layer.h" 6 7#include "cc/animation/scrollbar_animation_controller.h" 8#include "cc/layers/append_quads_data.h" 9#include "cc/layers/scrollbar_layer_impl.h" 10#include "cc/quads/solid_color_draw_quad.h" 11#include "cc/resources/prioritized_resource_manager.h" 12#include "cc/resources/priority_calculator.h" 13#include "cc/resources/resource_update_queue.h" 14#include "cc/test/fake_impl_proxy.h" 15#include "cc/test/fake_layer_tree_host_client.h" 16#include "cc/test/fake_layer_tree_host_impl.h" 17#include "cc/test/fake_scrollbar_theme_painter.h" 18#include "cc/test/fake_web_scrollbar.h" 19#include "cc/test/fake_web_scrollbar_theme_geometry.h" 20#include "cc/test/geometry_test_utils.h" 21#include "cc/test/layer_tree_test.h" 22#include "cc/test/mock_quad_culler.h" 23#include "cc/test/test_web_graphics_context_3d.h" 24#include "cc/trees/layer_tree_impl.h" 25#include "cc/trees/single_thread_proxy.h" 26#include "cc/trees/tree_synchronizer.h" 27#include "testing/gmock/include/gmock/gmock.h" 28#include "testing/gtest/include/gtest/gtest.h" 29#include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h" 30#include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbarThemeGeometry.h" 31 32namespace cc { 33namespace { 34 35scoped_ptr<LayerImpl> LayerImplForScrollAreaAndScrollbar( 36 FakeLayerTreeHostImpl* host_impl, 37 scoped_ptr<WebKit::WebScrollbar> scrollbar, 38 bool reverse_order) { 39 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 40 scoped_refptr<Layer> child1 = Layer::Create(); 41 scoped_refptr<Layer> child2 = 42 ScrollbarLayer::Create(scrollbar.Pass(), 43 FakeScrollbarThemePainter::Create(false) 44 .PassAs<ScrollbarThemePainter>(), 45 FakeWebScrollbarThemeGeometry::Create(true), 46 child1->id()); 47 layer_tree_root->AddChild(child1); 48 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); 49 scoped_ptr<LayerImpl> layer_impl = 50 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 51 scoped_ptr<LayerImpl>(), 52 host_impl->active_tree()); 53 TreeSynchronizer::PushProperties(layer_tree_root.get(), layer_impl.get()); 54 return layer_impl.Pass(); 55} 56 57TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { 58 FakeImplProxy proxy; 59 FakeLayerTreeHostImpl host_impl(&proxy); 60 61 { 62 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::Create()); 63 scoped_ptr<LayerImpl> layer_impl_tree_root = 64 LayerImplForScrollAreaAndScrollbar( 65 &host_impl, scrollbar.Pass(), false); 66 67 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; 68 ScrollbarLayerImpl* cc_child2 = static_cast<ScrollbarLayerImpl*>( 69 layer_impl_tree_root->children()[1]); 70 71 EXPECT_EQ(cc_child1->horizontal_scrollbar_layer(), cc_child2); 72 } 73 { 74 // another traverse order 75 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::Create()); 76 scoped_ptr<LayerImpl> layer_impl_tree_root = 77 LayerImplForScrollAreaAndScrollbar( 78 &host_impl, scrollbar.Pass(), true); 79 80 ScrollbarLayerImpl* cc_child1 = static_cast<ScrollbarLayerImpl*>( 81 layer_impl_tree_root->children()[0]); 82 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; 83 84 EXPECT_EQ(cc_child2->horizontal_scrollbar_layer(), cc_child1); 85 } 86} 87 88TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { 89 FakeImplProxy proxy; 90 FakeLayerTreeHostImpl host_impl(&proxy); 91 92 // Create and attach a non-overlay scrollbar. 93 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::Create()); 94 static_cast<FakeWebScrollbar*>(scrollbar.get())->set_overlay(false); 95 scoped_ptr<LayerImpl> layer_impl_tree_root = 96 LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false); 97 ScrollbarLayerImpl* scrollbar_layer_impl = 98 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); 99 100 // When the scrollbar is not an overlay scrollbar, the scroll should be 101 // responded to on the main thread as the compositor does not yet implement 102 // scrollbar scrolling. 103 EXPECT_EQ(InputHandler::ScrollOnMainThread, 104 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), 105 InputHandler::Gesture)); 106 107 // Create and attach an overlay scrollbar. 108 scrollbar = FakeWebScrollbar::Create(); 109 static_cast<FakeWebScrollbar*>(scrollbar.get())->set_overlay(true); 110 111 layer_impl_tree_root = 112 LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false); 113 scrollbar_layer_impl = 114 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); 115 116 // The user shouldn't be able to drag an overlay scrollbar and the scroll 117 // may be handled in the compositor. 118 EXPECT_EQ(InputHandler::ScrollIgnored, 119 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), 120 InputHandler::Gesture)); 121} 122 123TEST(ScrollbarLayerTest, ScrollOffsetSynchronization) { 124 FakeImplProxy proxy; 125 FakeLayerTreeHostImpl host_impl(&proxy); 126 127 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::Create()); 128 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 129 scoped_refptr<Layer> content_layer = Layer::Create(); 130 scoped_refptr<Layer> scrollbar_layer = 131 ScrollbarLayer::Create(scrollbar.Pass(), 132 FakeScrollbarThemePainter::Create(false) 133 .PassAs<ScrollbarThemePainter>(), 134 FakeWebScrollbarThemeGeometry::Create(true), 135 layer_tree_root->id()); 136 layer_tree_root->AddChild(content_layer); 137 layer_tree_root->AddChild(scrollbar_layer); 138 139 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); 140 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50)); 141 layer_tree_root->SetBounds(gfx::Size(100, 200)); 142 layer_tree_root->SavePaintProperties(); 143 content_layer->SetBounds(gfx::Size(100, 200)); 144 content_layer->SavePaintProperties(); 145 146 scoped_ptr<LayerImpl> layer_impl_tree_root = 147 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 148 scoped_ptr<LayerImpl>(), 149 host_impl.active_tree()); 150 TreeSynchronizer::PushProperties(layer_tree_root.get(), 151 layer_impl_tree_root.get()); 152 153 ScrollbarLayerImpl* cc_scrollbar_layer = 154 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); 155 156 EXPECT_EQ(10.f, cc_scrollbar_layer->CurrentPos()); 157 EXPECT_EQ(100, cc_scrollbar_layer->TotalSize()); 158 EXPECT_EQ(30, cc_scrollbar_layer->Maximum()); 159 160 layer_tree_root->SetScrollOffset(gfx::Vector2d(100, 200)); 161 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(300, 500)); 162 layer_tree_root->SetBounds(gfx::Size(1000, 2000)); 163 layer_tree_root->SavePaintProperties(); 164 content_layer->SetBounds(gfx::Size(1000, 2000)); 165 content_layer->SavePaintProperties(); 166 167 ScrollbarAnimationController* scrollbar_controller = 168 layer_impl_tree_root->scrollbar_animation_controller(); 169 layer_impl_tree_root = 170 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 171 layer_impl_tree_root.Pass(), 172 host_impl.active_tree()); 173 TreeSynchronizer::PushProperties(layer_tree_root.get(), 174 layer_impl_tree_root.get()); 175 EXPECT_EQ(scrollbar_controller, 176 layer_impl_tree_root->scrollbar_animation_controller()); 177 178 EXPECT_EQ(100.f, cc_scrollbar_layer->CurrentPos()); 179 EXPECT_EQ(1000, cc_scrollbar_layer->TotalSize()); 180 EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); 181 182 layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34)); 183 184 EXPECT_EQ(112.f, cc_scrollbar_layer->CurrentPos()); 185 EXPECT_EQ(1000, cc_scrollbar_layer->TotalSize()); 186 EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); 187} 188 189TEST(ScrollbarLayerTest, SolidColorDrawQuads) { 190 LayerTreeSettings layer_tree_settings; 191 layer_tree_settings.solid_color_scrollbars = true; 192 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3; 193 FakeImplProxy proxy; 194 FakeLayerTreeHostImpl host_impl(layer_tree_settings, &proxy); 195 196 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::Create()); 197 static_cast<FakeWebScrollbar*>(scrollbar.get())->set_overlay(true); 198 scoped_ptr<LayerImpl> layer_impl_tree_root = 199 LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false); 200 ScrollbarLayerImpl* scrollbar_layer_impl = 201 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); 202 scrollbar_layer_impl->SetThumbSize(gfx::Size(4, 4)); 203 scrollbar_layer_impl->SetViewportWithinScrollableArea( 204 gfx::RectF(10.f, 0.f, 40.f, 0.f), gfx::SizeF(100.f, 100.f)); 205 206 // Thickness should be overridden to 3. 207 { 208 MockQuadCuller quad_culler; 209 AppendQuadsData data; 210 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); 211 212 const QuadList& quads = quad_culler.quad_list(); 213 ASSERT_EQ(1u, quads.size()); 214 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); 215 EXPECT_RECT_EQ(gfx::Rect(1, 0, 4, 3), quads[0]->rect); 216 } 217 218 // Contents scale should scale the draw quad. 219 scrollbar_layer_impl->draw_properties().contents_scale_x = 2.f; 220 scrollbar_layer_impl->draw_properties().contents_scale_y = 2.f; 221 { 222 MockQuadCuller quad_culler; 223 AppendQuadsData data; 224 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); 225 226 const QuadList& quads = quad_culler.quad_list(); 227 ASSERT_EQ(1u, quads.size()); 228 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); 229 EXPECT_RECT_EQ(gfx::Rect(2, 0, 8, 6), quads[0]->rect); 230 } 231 scrollbar_layer_impl->draw_properties().contents_scale_x = 1.f; 232 scrollbar_layer_impl->draw_properties().contents_scale_y = 1.f; 233 234 // For solid color scrollbars, position and size should reflect the 235 // viewport, not the geometry object. 236 scrollbar_layer_impl->SetViewportWithinScrollableArea( 237 gfx::RectF(40.f, 0.f, 20.f, 0.f), 238 gfx::SizeF(100.f, 100.f)); 239 { 240 MockQuadCuller quad_culler; 241 AppendQuadsData data; 242 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); 243 244 const QuadList& quads = quad_culler.quad_list(); 245 ASSERT_EQ(1u, quads.size()); 246 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); 247 EXPECT_RECT_EQ(gfx::Rect(4, 0, 2, 3), quads[0]->rect); 248 } 249} 250 251TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { 252 LayerTreeSettings layer_tree_settings; 253 layer_tree_settings.solid_color_scrollbars = true; 254 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3; 255 FakeImplProxy proxy; 256 FakeLayerTreeHostImpl host_impl(layer_tree_settings, &proxy); 257 258 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::Create()); 259 static_cast<FakeWebScrollbar*>(scrollbar.get())->set_overlay(true); 260 scoped_ptr<LayerImpl> layer_impl_tree_root = 261 LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false); 262 ScrollbarLayerImpl* scrollbar_layer_impl = 263 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); 264 265 // Make sure that this ends up calling SetViewportWithinScrollableArea. 266 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); 267 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8)); 268 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); 269 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f)); 270 271 { 272 MockQuadCuller quad_culler; 273 AppendQuadsData data; 274 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); 275 276 const QuadList& quads = quad_culler.quad_list(); 277 ASSERT_EQ(1u, quads.size()); 278 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); 279 EXPECT_RECT_EQ(gfx::Rect(4, 0, 2, 3), quads[0]->rect); 280 } 281} 282 283class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest { 284 public: 285 ScrollbarLayerTestMaxTextureSize() {} 286 287 void SetScrollbarBounds(gfx::Size bounds) { bounds_ = bounds; } 288 289 virtual void BeginTest() OVERRIDE { 290 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::Create()); 291 scrollbar_layer_ = 292 ScrollbarLayer::Create(scrollbar.Pass(), 293 FakeScrollbarThemePainter::Create(false) 294 .PassAs<ScrollbarThemePainter>(), 295 FakeWebScrollbarThemeGeometry::Create(true), 296 1); 297 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); 298 scrollbar_layer_->SetBounds(bounds_); 299 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); 300 301 scroll_layer_ = Layer::Create(); 302 scrollbar_layer_->SetScrollLayerId(scroll_layer_->id()); 303 layer_tree_host()->root_layer()->AddChild(scroll_layer_); 304 305 PostSetNeedsCommitToMainThread(); 306 } 307 308 virtual void DidCommitAndDrawFrame() OVERRIDE { 309 const int kMaxTextureSize = 310 layer_tree_host()->GetRendererCapabilities().max_texture_size; 311 312 // Check first that we're actually testing something. 313 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize); 314 315 EXPECT_EQ(scrollbar_layer_->content_bounds().width(), 316 kMaxTextureSize - 1); 317 EXPECT_EQ(scrollbar_layer_->content_bounds().height(), 318 kMaxTextureSize - 1); 319 320 EndTest(); 321 } 322 323 virtual void AfterTest() OVERRIDE {} 324 325 private: 326 scoped_refptr<ScrollbarLayer> scrollbar_layer_; 327 scoped_refptr<Layer> scroll_layer_; 328 gfx::Size bounds_; 329}; 330 331TEST_F(ScrollbarLayerTestMaxTextureSize, DirectRenderer) { 332 scoped_ptr<TestWebGraphicsContext3D> context = 333 TestWebGraphicsContext3D::Create(); 334 int max_size = 0; 335 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); 336 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); 337 RunTest(true, false, true); 338} 339 340TEST_F(ScrollbarLayerTestMaxTextureSize, DelegatingRenderer) { 341 scoped_ptr<TestWebGraphicsContext3D> context = 342 TestWebGraphicsContext3D::Create(); 343 int max_size = 0; 344 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); 345 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); 346 RunTest(true, true, true); 347} 348 349class MockLayerTreeHost : public LayerTreeHost { 350 public: 351 MockLayerTreeHost(LayerTreeHostClient* client, 352 const LayerTreeSettings& settings) 353 : LayerTreeHost(client, settings) { 354 Initialize(scoped_ptr<Thread>(NULL)); 355 } 356}; 357 358 359class ScrollbarLayerTestResourceCreation : public testing::Test { 360 public: 361 ScrollbarLayerTestResourceCreation() 362 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 363 364 void TestResourceUpload(size_t expected_resources) { 365 layer_tree_host_.reset( 366 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); 367 368 scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::Create()); 369 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 370 scoped_refptr<Layer> content_layer = Layer::Create(); 371 scoped_refptr<Layer> scrollbar_layer = 372 ScrollbarLayer::Create(scrollbar.Pass(), 373 FakeScrollbarThemePainter::Create(false) 374 .PassAs<ScrollbarThemePainter>(), 375 FakeWebScrollbarThemeGeometry::Create(true), 376 layer_tree_root->id()); 377 layer_tree_root->AddChild(content_layer); 378 layer_tree_root->AddChild(scrollbar_layer); 379 380 layer_tree_host_->InitializeOutputSurfaceIfNeeded(); 381 layer_tree_host_->contents_texture_manager()-> 382 SetMaxMemoryLimitBytes(1024 * 1024); 383 layer_tree_host_->SetRootLayer(layer_tree_root); 384 385 scrollbar_layer->SetIsDrawable(true); 386 scrollbar_layer->SetBounds(gfx::Size(100, 100)); 387 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); 388 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50)); 389 layer_tree_root->SetBounds(gfx::Size(100, 200)); 390 content_layer->SetBounds(gfx::Size(100, 200)); 391 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200); 392 scrollbar_layer->draw_properties().visible_content_rect = 393 gfx::Rect(0, 0, 100, 200); 394 scrollbar_layer->CreateRenderSurface(); 395 scrollbar_layer->draw_properties().render_target = scrollbar_layer; 396 397 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 398 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); 399 400 PriorityCalculator calculator; 401 ResourceUpdateQueue queue; 402 OcclusionTracker occlusion_tracker(gfx::Rect(), false); 403 404 scrollbar_layer->SetTexturePriorities(calculator); 405 layer_tree_host_->contents_texture_manager()->PrioritizeTextures(); 406 scrollbar_layer->Update(&queue, &occlusion_tracker, NULL); 407 EXPECT_EQ(0u, queue.FullUploadSize()); 408 EXPECT_EQ(expected_resources, queue.PartialUploadSize()); 409 410 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 411 } 412 413 protected: 414 FakeLayerTreeHostClient fake_client_; 415 LayerTreeSettings layer_tree_settings_; 416 scoped_ptr<MockLayerTreeHost> layer_tree_host_; 417}; 418 419TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { 420 layer_tree_settings_.solid_color_scrollbars = false; 421 TestResourceUpload(2); 422} 423 424TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { 425 layer_tree_settings_.solid_color_scrollbars = true; 426 TestResourceUpload(0); 427} 428 429TEST(ScrollbarLayerTest, PinchZoomScrollbarUpdates) { 430 FakeImplProxy proxy; 431 FakeLayerTreeHostImpl host_impl(&proxy); 432 433 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 434 layer_tree_root->SetScrollable(true); 435 436 scoped_refptr<Layer> content_layer = Layer::Create(); 437 scoped_ptr<WebKit::WebScrollbar> scrollbar1(FakeWebScrollbar::Create()); 438 scoped_refptr<Layer> scrollbar_layer_horizontal = 439 ScrollbarLayer::Create(scrollbar1.Pass(), 440 FakeScrollbarThemePainter::Create(false) 441 .PassAs<ScrollbarThemePainter>(), 442 FakeWebScrollbarThemeGeometry::Create(true), 443 Layer::PINCH_ZOOM_ROOT_SCROLL_LAYER_ID); 444 scoped_ptr<WebKit::WebScrollbar> scrollbar2(FakeWebScrollbar::Create()); 445 scoped_refptr<Layer> scrollbar_layer_vertical = 446 ScrollbarLayer::Create(scrollbar2.Pass(), 447 FakeScrollbarThemePainter::Create(false) 448 .PassAs<ScrollbarThemePainter>(), 449 FakeWebScrollbarThemeGeometry::Create(true), 450 Layer::PINCH_ZOOM_ROOT_SCROLL_LAYER_ID); 451 452 layer_tree_root->AddChild(content_layer); 453 layer_tree_root->AddChild(scrollbar_layer_horizontal); 454 layer_tree_root->AddChild(scrollbar_layer_vertical); 455 456 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); 457 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50)); 458 layer_tree_root->SetBounds(gfx::Size(100, 200)); 459 layer_tree_root->SavePaintProperties(); 460 content_layer->SetBounds(gfx::Size(100, 200)); 461 content_layer->SavePaintProperties(); 462 463 scoped_ptr<LayerImpl> layer_impl_tree_root = 464 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 465 scoped_ptr<LayerImpl>(), 466 host_impl.active_tree()); 467 TreeSynchronizer::PushProperties(layer_tree_root.get(), 468 layer_impl_tree_root.get()); 469 470 ScrollbarLayerImpl* pinch_zoom_horizontal = 471 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); 472 ScrollbarLayerImpl* pinch_zoom_vertical = 473 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[2]); 474 475 // Need a root layer in the active tree in order for DidUpdateScroll() 476 // to work. 477 host_impl.active_tree()->SetRootLayer(layer_impl_tree_root.Pass()); 478 host_impl.active_tree()->FindRootScrollLayer(); 479 480 // Manually set the pinch-zoom layers: normally this is done by 481 // LayerTreeHost. 482 host_impl.active_tree()-> 483 SetPinchZoomHorizontalLayerId(pinch_zoom_horizontal->id()); 484 host_impl.active_tree()-> 485 SetPinchZoomVerticalLayerId(pinch_zoom_vertical->id()); 486 487 host_impl.active_tree()->DidUpdateScroll(); 488 489 EXPECT_EQ(10.f, pinch_zoom_horizontal->CurrentPos()); 490 EXPECT_EQ(100, pinch_zoom_horizontal->TotalSize()); 491 EXPECT_EQ(30, pinch_zoom_horizontal->Maximum()); 492 EXPECT_EQ(20.f, pinch_zoom_vertical->CurrentPos()); 493 EXPECT_EQ(200, pinch_zoom_vertical->TotalSize()); 494 EXPECT_EQ(50, pinch_zoom_vertical->Maximum()); 495} 496 497} // namespace 498} // namespace cc 499