Chromium Code Reviews| Index: cc/trees/layer_tree_host_common_unittest.cc |
| diff --git a/cc/trees/layer_tree_host_common_unittest.cc b/cc/trees/layer_tree_host_common_unittest.cc |
| index 969398354c27a08fbe0a5efc614eac2302d1ede4..2230b1a3b5de431b21980fd9accb36d61bed0ab0 100644 |
| --- a/cc/trees/layer_tree_host_common_unittest.cc |
| +++ b/cc/trees/layer_tree_host_common_unittest.cc |
| @@ -7048,6 +7048,106 @@ TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithScrollChild) { |
| scroll_child_impl->ScreenSpaceTransform()); |
| } |
| +TEST_F(LayerTreeHostCommonTest, StickyPositionNested) { |
| + scoped_refptr<Layer> root = Layer::Create(); |
| + scoped_refptr<Layer> container = Layer::Create(); |
| + scoped_refptr<Layer> scroller = Layer::Create(); |
| + scoped_refptr<Layer> outer_sticky = Layer::Create(); |
| + scoped_refptr<Layer> inner_sticky = Layer::Create(); |
| + |
| + root->AddChild(container); |
| + container->AddChild(scroller); |
| + scroller->AddChild(outer_sticky); |
| + outer_sticky->AddChild(inner_sticky); |
| + host()->SetRootLayer(root); |
| + scroller->SetScrollClipLayerId(container->id()); |
| + |
| + root->SetBounds(gfx::Size(100, 100)); |
| + container->SetBounds(gfx::Size(100, 100)); |
| + scroller->SetBounds(gfx::Size(100, 1000)); |
| + outer_sticky->SetBounds(gfx::Size(10, 50)); |
| + outer_sticky->SetPosition(gfx::PointF(0, 50)); |
| + inner_sticky->SetBounds(gfx::Size(10, 10)); |
| + inner_sticky->SetPosition(gfx::PointF(0, 0)); |
| + |
| + LayerStickyPositionConstraint outer_sticky_pos; |
| + outer_sticky_pos.is_sticky = true; |
| + outer_sticky_pos.is_anchored_top = true; |
| + outer_sticky_pos.top_offset = 10.0f; |
| + outer_sticky_pos.parent_relative_sticky_box_offset = gfx::Point(0, 50); |
| + outer_sticky_pos.scroll_container_relative_sticky_box_rect = |
| + gfx::Rect(0, 50, 50, 50); |
| + outer_sticky_pos.scroll_container_relative_containing_block_rect = |
| + gfx::Rect(0, 0, 50, 200); |
| + outer_sticky->SetStickyPositionConstraint(outer_sticky_pos); |
| + |
| + LayerStickyPositionConstraint inner_sticky_pos; |
| + inner_sticky_pos.is_sticky = true; |
| + inner_sticky_pos.is_anchored_top = true; |
| + inner_sticky_pos.top_offset = 25.0f; |
| + inner_sticky_pos.parent_relative_sticky_box_offset = gfx::Point(0, 0); |
| + inner_sticky_pos.scroll_container_relative_sticky_box_rect = |
| + gfx::Rect(0, 50, 10, 10); |
| + inner_sticky_pos.scroll_container_relative_containing_block_rect = |
| + gfx::Rect(0, 50, 10, 50); |
| + inner_sticky->SetStickyPositionConstraint(inner_sticky_pos); |
| + |
| + ExecuteCalculateDrawProperties(root.get()); |
| + host()->host_impl()->CreatePendingTree(); |
| + host()->CommitAndCreatePendingTree(); |
| + host()->host_impl()->ActivateSyncTree(); |
| + LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| + |
| + LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| + LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| + LayerImpl* outer_sticky_impl = layer_tree_impl->LayerById(outer_sticky->id()); |
| + LayerImpl* inner_sticky_impl = layer_tree_impl->LayerById(inner_sticky->id()); |
| + |
| + ExecuteCalculateDrawProperties(root_impl); |
| + |
| + // Before any scrolling is done, the sticky elements should still be at their |
| + // original positions. |
| + EXPECT_VECTOR2DF_EQ( |
| + gfx::Vector2dF(0.f, 50.f), |
| + outer_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| + EXPECT_VECTOR2DF_EQ( |
| + gfx::Vector2dF(0.f, 50.f), |
| + inner_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| + |
| + // Scroll less than the sticking point. Both sticky elements should move with |
| + // scroll as we haven't gotten to the sticky item locations yet. |
| + SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| + ExecuteCalculateDrawProperties(root_impl); |
| + EXPECT_VECTOR2DF_EQ( |
| + gfx::Vector2dF(0.f, 45.f), |
| + outer_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| + EXPECT_VECTOR2DF_EQ( |
| + gfx::Vector2dF(0.f, 45.f), |
| + inner_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| + |
| + // Scroll such that the inner sticky should stick, but the outer one should |
| + // keep going as it hasnt reached its position yet. |
| + SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f)); |
| + ExecuteCalculateDrawProperties(root_impl); |
| + EXPECT_VECTOR2DF_EQ( |
| + gfx::Vector2dF(0.f, 20.f), |
| + outer_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| + EXPECT_VECTOR2DF_EQ( |
| + gfx::Vector2dF(0.f, 25.f), |
| + inner_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| + |
| + // Keep going, both should stick. |
| + SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 100.f)); |
| + ExecuteCalculateDrawProperties(root_impl); |
| + EXPECT_VECTOR2DF_EQ( |
| + gfx::Vector2dF(0.f, 10.f), |
| + outer_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| + // TODO(smcgruer): Fails. I'm not sure why. Value is actually [0,50]. |
|
smcgruer
2017/02/14 17:02:06
flackr : Not sure why this fails. I'd expect it to
|
| + EXPECT_VECTOR2DF_EQ( |
| + gfx::Vector2dF(0.f, 25.f), |
| + inner_sticky_impl->ScreenSpaceTransform().To2dTranslation()); |
| +} |
| + |
| TEST_F(LayerTreeHostCommonTest, StickyPositionTop) { |
| scoped_refptr<Layer> root = Layer::Create(); |
| scoped_refptr<Layer> container = Layer::Create(); |
| @@ -7735,21 +7835,21 @@ TEST_F(LayerTreeHostCommonTest, StickyPositionCompositedContainer) { |
| SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f)); |
| ExecuteCalculateDrawProperties(root_impl); |
| EXPECT_VECTOR2DF_EQ( |
| - gfx::Vector2dF(20.f, 10.f), |
| + gfx::Vector2dF(20.f, -15.f), |
|
smcgruer
2017/02/14 17:02:06
flackr : These changes are also suspicious. I just
|
| sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| // And if we scroll a little further it remains there. |
| SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); |
| ExecuteCalculateDrawProperties(root_impl); |
| EXPECT_VECTOR2DF_EQ( |
| - gfx::Vector2dF(20.f, 10.f), |
| + gfx::Vector2dF(20.f, -15.f), |
| sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| // And hits the bottom of the container. |
| SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f)); |
| ExecuteCalculateDrawProperties(root_impl); |
| EXPECT_VECTOR2DF_EQ( |
| - gfx::Vector2dF(20.f, 5.f), |
| + gfx::Vector2dF(20.f, -20.f), |
| sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| } |