Chromium Code Reviews| Index: cc/trees/layer_tree_host_unittest_damage.cc |
| diff --git a/cc/trees/layer_tree_host_unittest_damage.cc b/cc/trees/layer_tree_host_unittest_damage.cc |
| index e8ae7a211f2f3d0fef7149d1b8a1345cae81e270..15b337b4c618d325740e9dd74d0f2a154a58d9b3 100644 |
| --- a/cc/trees/layer_tree_host_unittest_damage.cc |
| +++ b/cc/trees/layer_tree_host_unittest_damage.cc |
| @@ -6,6 +6,7 @@ |
| #include "cc/test/fake_content_layer.h" |
| #include "cc/test/fake_content_layer_client.h" |
| +#include "cc/test/fake_scrollbar_layer.h" |
| #include "cc/test/layer_tree_test.h" |
| #include "cc/trees/damage_tracker.h" |
| #include "cc/trees/layer_tree_impl.h" |
| @@ -285,5 +286,104 @@ class LayerTreeHostDamageTestForcedFullDamage : public LayerTreeHostDamageTest { |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostDamageTestForcedFullDamage); |
| +class LayerTreeHostDamageTestScrollbarDoesDamage |
| + : public LayerTreeHostDamageTest { |
| + virtual void BeginTest() OVERRIDE { |
| + did_swaps_ = 0; |
| + PostSetNeedsCommitToMainThread(); |
| + } |
| + |
| + virtual void SetupTree() OVERRIDE { |
| + scoped_refptr<Layer> root_layer = Layer::Create(); |
| + root_layer->SetBounds(gfx::Size(400,400)); |
| + layer_tree_host()->SetRootLayer(root_layer); |
| + |
| + scoped_refptr<Layer> content_layer = FakeContentLayer::Create(&client_); |
| + content_layer->SetScrollable(true); |
| + content_layer->SetScrollOffset(gfx::Vector2d(10, 20)); |
| + content_layer->SetMaxScrollOffset(gfx::Vector2d(30, 50)); |
| + content_layer->SetBounds(gfx::Size(100, 200)); |
| + root_layer->AddChild(content_layer); |
| + |
| + scoped_refptr<Layer> scrollbar_layer = |
| + FakeScrollbarLayer::Create(false, true, content_layer->id()); |
| + scrollbar_layer->SetPosition(gfx::Point(300, 300)); |
| + scrollbar_layer->SetBounds(gfx::Size(10, 100)); |
| + root_layer->AddChild(scrollbar_layer); |
| + |
| + gfx::RectF content_rect(content_layer->position(), |
| + content_layer->bounds()); |
| + gfx::RectF scrollbar_rect(scrollbar_layer->position(), |
| + scrollbar_layer->bounds()); |
| + EXPECT_FALSE(content_rect.Intersects(scrollbar_rect)); |
| + |
| + LayerTreeHostDamageTest::SetupTree(); |
| + } |
| + |
| + virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| + LayerTreeHostImpl::FrameData* frame_data, |
| + bool result) OVERRIDE { |
| + EXPECT_TRUE(result); |
| + RenderSurfaceImpl* root_surface = |
| + host_impl->active_tree()->root_layer()->render_surface(); |
| + gfx::RectF root_damage = |
| + root_surface->damage_tracker()->current_damage_rect(); |
| + root_damage.Intersect(root_surface->content_rect()); |
| + switch (did_swaps_) { |
| + case 0: |
| + // The first frame has damage, so we should draw and swap. |
| + break; |
| + case 1: |
| + // The second frame should damage the scrollbars. |
| + EXPECT_TRUE(root_damage.Contains(gfx::Rect(300, 300, 10, 100))); |
| + break; |
| + case 2: |
| + // The third frame should damage the scrollbars. |
| + EXPECT_TRUE(root_damage.Contains(gfx::Rect(300, 300, 10, 100))); |
| + break; |
| + case 3: |
| + // The fourth frame should not damage the scrollbars. |
| + EXPECT_FALSE(root_damage.Intersects(gfx::Rect(300, 300, 10, 100))); |
| + EndTest(); |
| + break; |
| + } |
| + return result; |
| + } |
| + |
| + virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| + bool result) OVERRIDE { |
| + ++did_swaps_; |
| + EXPECT_TRUE(result); |
| + LayerImpl* root = host_impl->active_tree()->root_layer(); |
| + switch (did_swaps_) { |
| + case 1: |
| + host_impl->ScrollBegin(gfx::Point(1,1), InputHandler::Wheel); |
| + EXPECT_TRUE(host_impl->ScrollBy(gfx::Point(), |
| + gfx::Vector2dF(10.0, 10.0))); |
| + break; |
| + case 2: |
| + root->children()[0]->SetMaxScrollOffset(gfx::Vector2d(60, 100)); |
| + host_impl->SetNeedsRedraw(); |
| + break; |
| + case 3: |
| + // Test that modifying the position of the content layer (not |
| + // scrolling) won't damage the scrollbar. |
| + root->children()[0]->SetPosition(gfx::Point(1,1)); |
|
enne (OOO)
2013/08/14 22:20:46
Could you also set the scrollbar to the same offse
|
| + host_impl->SetNeedsRedraw(); |
| + break; |
| + } |
| + |
| + } |
| + |
| + virtual void AfterTest() OVERRIDE { |
| + EXPECT_EQ(4, did_swaps_); |
| + } |
| + |
| + FakeContentLayerClient client_; |
| + int did_swaps_; |
| +}; |
| + |
| +MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarDoesDamage); |
|
danakj
2013/08/14 22:17:20
nit: Can this be SINGLE_AND_MULTI_THREAD_TEST_F?
|
| + |
| } // namespace |
| } // namespace cc |