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..c130404589cbd15111bdde47628280da7f9d0191 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,87 @@ 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 { |
| + layer_tree_root_ = Layer::Create(); |
|
danakj
2013/08/14 21:29:14
does this need to be a member variable? usually th
|
| + scoped_refptr<Layer> content_layer = FakeContentLayer::Create(&client_); |
| + scoped_refptr<Layer> scrollbar_layer = |
| + FakeScrollbarLayer::Create(false, true, content_layer->id()); |
| + layer_tree_root_->AddChild(content_layer); |
|
danakj
2013/08/14 21:29:14
nit: some whitespace in between blocks of calls fo
|
| + layer_tree_root_->AddChild(scrollbar_layer); |
| + layer_tree_host()->SetRootLayer(layer_tree_root_); |
| + 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)); |
| + scrollbar_layer->SetPosition(gfx::Point(300, 300)); |
| + scrollbar_layer->SetBounds(gfx::Size(10, 100)); |
| + layer_tree_root_->SetBounds(gfx::Size(400,400)); |
| + LayerTreeHostDamageTest::SetupTree(); |
|
danakj
2013/08/14 21:29:14
can you EXPECT here that the content_layer does no
|
| + } |
| + |
| + 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 not damage the scrollbars. |
| + EXPECT_FALSE(root_damage.Contains(gfx::Rect(300, 300, 10, 100))); |
|
enne (OOO)
2013/08/14 21:33:41
Can Contains be changed to Intersects here to be m
|
| + EndTest(); |
| + break; |
| + } |
| + return result; |
| + } |
| + |
| + virtual void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, |
| + bool result) OVERRIDE { |
| + ++did_swaps_; |
| + EXPECT_TRUE(result); |
| + 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: |
|
danakj
2013/08/14 21:29:14
Can you add a case that changes the max scroll (th
|
| + host_impl->ScheduleAnimation(); |
|
danakj
2013/08/14 21:29:14
nit: SetNeedsRedraw() instead?
|
| + LayerImpl* root = host_impl->active_tree()->root_layer(); |
| + |
| + root->children()[0]->SetPosition(gfx::Point(1,1)); |
|
danakj
2013/08/14 21:29:14
Add a comment explaining what this case is doing a
|
| + break; |
| + } |
| + |
| + } |
| + |
| + virtual void AfterTest() OVERRIDE { |
| + EXPECT_EQ(3, did_swaps_); |
| + } |
| + |
| + FakeContentLayerClient client_; |
| + scoped_refptr<Layer> layer_tree_root_; |
| + int did_swaps_; |
| +}; |
| + |
| +MULTI_THREAD_TEST_F(LayerTreeHostDamageTestScrollbarDoesDamage); |
| + |
| } // namespace |
| } // namespace cc |