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

Unified Diff: cc/trees/layer_tree_host_common_unittest.cc

Issue 2251303003: Implement position: sticky updates on compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup and add unit test for impl side sticky position update. Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
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 a4b4caafe2f5ad0c98145b1863b7e87ba50a8746..39ac44ffc963777b5dde8ba92d3e25fc92c09102 100644
--- a/cc/trees/layer_tree_host_common_unittest.cc
+++ b/cc/trees/layer_tree_host_common_unittest.cc
@@ -6915,6 +6915,75 @@ TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithScrollChild) {
scroll_child_impl->ScreenSpaceTransform());
}
+TEST_F(LayerTreeHostCommonTest, StickyPosition) {
+ scoped_refptr<Layer> root = Layer::Create();
+ scoped_refptr<Layer> container = Layer::Create();
+ scoped_refptr<Layer> scroller = Layer::Create();
+ scoped_refptr<Layer> sticky_pos = Layer::Create();
+ root->AddChild(container);
+ container->AddChild(scroller);
+ scroller->AddChild(sticky_pos);
+ host()->SetRootLayer(root);
+ scroller->SetScrollClipLayerId(container->id());
+
+ LayerStickyPositionConstraint sticky_position;
+ sticky_position.is_sticky = true;
+ sticky_position.is_anchored_top = true;
+ sticky_position.top_offset = 10.0f;
+ sticky_position.absolute_sticky_box_rect = gfx::Rect(10, 20, 10, 10);
+ sticky_position.absolute_containing_block_rect = gfx::Rect(0, 0, 50, 50);
ajuma 2016/09/08 22:08:53 Please also include tests that use the other stick
flackr 2016/09/20 17:08:47 Done.
+ sticky_pos->SetStickyPositionConstraint(sticky_position);
+
+ root->SetBounds(gfx::Size(100, 100));
+ container->SetBounds(gfx::Size(100, 100));
+ scroller->SetBounds(gfx::Size(1000, 1000));
+ sticky_pos->SetBounds(gfx::Size(10, 10));
+ sticky_pos->SetPosition(gfx::PointF(10, 20));
+
+ 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* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
+
+ ExecuteCalculateDrawProperties(root_impl);
+ EXPECT_VECTOR2DF_EQ(
+ gfx::Vector2dF(10.f, 20.f),
+ sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
+
+ // Scroll less than sticking point, sticky element should move with scroll as
+ // we haven't gotten to the initial sticky item location yet.
+ SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
+ ExecuteCalculateDrawProperties(root_impl);
+ EXPECT_VECTOR2DF_EQ(
+ gfx::Vector2dF(5.f, 15.f),
+ sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
+
+ // Scroll past the sticking point, the Y coordinate should now be clamped.
+ SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
+ ExecuteCalculateDrawProperties(root_impl);
+ EXPECT_VECTOR2DF_EQ(
+ gfx::Vector2dF(-5.f, 10.f),
+ sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
+ SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f));
+ ExecuteCalculateDrawProperties(root_impl);
+ EXPECT_VECTOR2DF_EQ(
+ gfx::Vector2dF(-5.f, 10.f),
+ sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
+
+ // Scroll past the end of the sticky container (note: this element does not
+ // have its own layer as it does not need to be composited).
+ SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f));
+ ExecuteCalculateDrawProperties(root_impl);
+ EXPECT_VECTOR2DF_EQ(
+ gfx::Vector2dF(-5.f, -10.f),
+ sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
+}
+
TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> container = Layer::Create();

Powered by Google App Engine
This is Rietveld 408576698