| Index: cc/trees/draw_property_utils_unittest.cc
|
| diff --git a/cc/trees/draw_property_utils_unittest.cc b/cc/trees/draw_property_utils_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..96c7e6683fc73da3f10a4dfe13f7c1a2448c86b5
|
| --- /dev/null
|
| +++ b/cc/trees/draw_property_utils_unittest.cc
|
| @@ -0,0 +1,205 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "cc/trees/draw_property_utils.h"
|
| +
|
| +#include <stddef.h>
|
| +
|
| +#include "base/memory/ref_counted.h"
|
| +#include "cc/layers/layer.h"
|
| +#include "cc/layers/layer_sticky_position_constraint.h"
|
| +#include "cc/test/geometry_test_utils.h"
|
| +#include "cc/test/layer_test_common.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace cc {
|
| +namespace draw_property_utils {
|
| +
|
| +namespace {
|
| +class DrawPropertyUtilsTest : public LayerTestCommon::LayerImplTest,
|
| + public testing::Test {};
|
| +} // namespace
|
| +
|
| +TEST_F(DrawPropertyUtilsTest, CalculateTotalStickyOffsetToScroller) {
|
| + scoped_refptr<Layer> root = Layer::Create();
|
| + scoped_refptr<Layer> container = Layer::Create();
|
| + scoped_refptr<Layer> scroller = Layer::Create();
|
| + scoped_refptr<Layer> child_sticky = Layer::Create();
|
| + scoped_refptr<Layer> grandchild_sticky = Layer::Create();
|
| + scoped_refptr<Layer> great_grandchild_layer = Layer::Create();
|
| +
|
| + root->AddChild(container);
|
| + container->AddChild(scroller);
|
| + scroller->AddChild(child_sticky);
|
| + child_sticky->AddChild(grandchild_sticky);
|
| + grandchild_sticky->AddChild(great_grandchild_layer);
|
| +
|
| + host()->SetRootLayer(root);
|
| + scroller->SetScrollClipLayerId(container->id());
|
| +
|
| + LayerStickyPositionConstraint child_sticky_pos;
|
| + child_sticky_pos.is_sticky = true;
|
| + child_sticky_pos.local_sticky_offset = gfx::Vector2dF(10, 50);
|
| + child_sticky->SetStickyPositionConstraint(child_sticky_pos);
|
| +
|
| + LayerStickyPositionConstraint grandchild_sticky_pos;
|
| + grandchild_sticky_pos.is_sticky = true;
|
| + grandchild_sticky_pos.nearest_layer_shifting_containing_block =
|
| + child_sticky.get();
|
| + grandchild_sticky_pos.local_sticky_offset = gfx::Vector2dF(100, 0);
|
| + grandchild_sticky->SetStickyPositionConstraint(grandchild_sticky_pos);
|
| +
|
| + host()->host_impl()->CreatePendingTree();
|
| + host()->CommitAndCreatePendingTree();
|
| + host()->host_impl()->ActivateSyncTree();
|
| +
|
| + gfx::Vector2dF offset =
|
| + CalculateTotalStickyOffsetToScroller(child_sticky.get(), scroller->id());
|
| + EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(10, 50), offset);
|
| +
|
| + offset = CalculateTotalStickyOffsetToScroller(grandchild_sticky.get(),
|
| + scroller->id());
|
| + EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(110, 50), offset);
|
| +
|
| + // The great grandchild, although not sticky itself, should be able to locate
|
| + // its nearest sticky ancestor and walk up from there.
|
| + offset = CalculateTotalStickyOffsetToScroller(great_grandchild_layer.get(),
|
| + scroller->id());
|
| + EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(110, 50), offset);
|
| +}
|
| +
|
| +TEST_F(DrawPropertyUtilsTest, CalculateTotalStickyOffsetToScrollerComplex) {
|
| + scoped_refptr<Layer> root = Layer::Create();
|
| + scoped_refptr<Layer> container = Layer::Create();
|
| + scoped_refptr<Layer> scroller = Layer::Create();
|
| + scoped_refptr<Layer> child_sticky = Layer::Create();
|
| + scoped_refptr<Layer> grandchild_sticky = Layer::Create();
|
| + scoped_refptr<Layer> great_grandchild_sticky = Layer::Create();
|
| +
|
| + root->AddChild(container);
|
| + container->AddChild(scroller);
|
| + scroller->AddChild(child_sticky);
|
| + child_sticky->AddChild(grandchild_sticky);
|
| + grandchild_sticky->AddChild(great_grandchild_sticky);
|
| +
|
| + host()->SetRootLayer(root);
|
| + scroller->SetScrollClipLayerId(container->id());
|
| +
|
| + LayerStickyPositionConstraint child_sticky_pos;
|
| + child_sticky_pos.is_sticky = true;
|
| + child_sticky_pos.local_sticky_offset = gfx::Vector2dF(10, 50);
|
| + child_sticky->SetStickyPositionConstraint(child_sticky_pos);
|
| +
|
| + LayerStickyPositionConstraint grandchild_sticky_pos;
|
| + grandchild_sticky_pos.is_sticky = true;
|
| + grandchild_sticky_pos.nearest_layer_shifting_containing_block =
|
| + child_sticky.get();
|
| + grandchild_sticky_pos.local_sticky_offset = gfx::Vector2dF(100, 0);
|
| + grandchild_sticky->SetStickyPositionConstraint(grandchild_sticky_pos);
|
| +
|
| + // We are considering the grandchild to be something like an inline element
|
| + // that doesn't become a containing block for the great-grandchild. Therefore,
|
| + // the great-grandchild points at both the child and grandchild, but should
|
| + // accumulate both (via the grandchild) in the walk.
|
| + LayerStickyPositionConstraint great_grandchild_sticky_pos;
|
| + great_grandchild_sticky_pos.is_sticky = true;
|
| + great_grandchild_sticky_pos.local_sticky_offset = gfx::Vector2dF(0, 20);
|
| + great_grandchild_sticky_pos.nearest_layer_shifting_sticky_box =
|
| + grandchild_sticky.get();
|
| + great_grandchild_sticky_pos.nearest_layer_shifting_containing_block =
|
| + child_sticky.get();
|
| + great_grandchild_sticky->SetStickyPositionConstraint(
|
| + great_grandchild_sticky_pos);
|
| +
|
| + host()->host_impl()->CreatePendingTree();
|
| + host()->CommitAndCreatePendingTree();
|
| + host()->host_impl()->ActivateSyncTree();
|
| +
|
| + gfx::Vector2dF offset =
|
| + CalculateTotalStickyOffsetToScroller(child_sticky.get(), scroller->id());
|
| + EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(10, 50), offset);
|
| +
|
| + offset = CalculateTotalStickyOffsetToScroller(grandchild_sticky.get(),
|
| + scroller->id());
|
| + EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(110, 50), offset);
|
| +
|
| + offset = CalculateTotalStickyOffsetToScroller(great_grandchild_sticky.get(),
|
| + scroller->id());
|
| + EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(110, 70), offset);
|
| +}
|
| +
|
| +TEST_F(DrawPropertyUtilsTest,
|
| + CalculateTotalStickyOffsetToScrollerNoStickyLayers) {
|
| + scoped_refptr<Layer> root = Layer::Create();
|
| + scoped_refptr<Layer> container = Layer::Create();
|
| + scoped_refptr<Layer> other_container = Layer::Create();
|
| + scoped_refptr<Layer> scroller = Layer::Create();
|
| + scoped_refptr<Layer> first_child = Layer::Create();
|
| + scoped_refptr<Layer> second_child = Layer::Create();
|
| + scoped_refptr<Layer> first_grandchild = Layer::Create();
|
| +
|
| + root->AddChild(container);
|
| + root->AddChild(other_container);
|
| + container->AddChild(scroller);
|
| + scroller->AddChild(first_child);
|
| + scroller->AddChild(second_child);
|
| + first_child->AddChild(first_grandchild);
|
| +
|
| + host()->SetRootLayer(root);
|
| + scroller->SetScrollClipLayerId(container->id());
|
| +
|
| + LayerStickyPositionConstraint sticky_position;
|
| + sticky_position.is_sticky = true;
|
| + sticky_position.local_sticky_offset = gfx::Vector2dF(10, 50);
|
| + second_child->SetStickyPositionConstraint(sticky_position);
|
| +
|
| + host()->host_impl()->CreatePendingTree();
|
| + host()->CommitAndCreatePendingTree();
|
| + host()->host_impl()->ActivateSyncTree();
|
| +
|
| + // We should ignore second_child, as it is not between us and the scroller.
|
| + gfx::Vector2dF offset = CalculateTotalStickyOffsetToScroller(
|
| + first_grandchild.get(), scroller->id());
|
| + EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(0, 0), offset);
|
| +
|
| + // There is no scroller above other_container, so its offset is zero.
|
| + offset = CalculateTotalStickyOffsetToScroller(other_container.get(), -1);
|
| + EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(0, 0), offset);
|
| +}
|
| +
|
| +TEST_F(DrawPropertyUtilsTest,
|
| + CalculateTotalStickyOffsetToScrollerNoStickyLayersBelowScroller) {
|
| + scoped_refptr<Layer> root = Layer::Create();
|
| + scoped_refptr<Layer> sticky = Layer::Create();
|
| + scoped_refptr<Layer> container = Layer::Create();
|
| + scoped_refptr<Layer> scroller = Layer::Create();
|
| + scoped_refptr<Layer> first_child = Layer::Create();
|
| + scoped_refptr<Layer> first_grandchild = Layer::Create();
|
| +
|
| + root->AddChild(sticky);
|
| + sticky->AddChild(container);
|
| + container->AddChild(scroller);
|
| + scroller->AddChild(first_child);
|
| + first_child->AddChild(first_grandchild);
|
| +
|
| + host()->SetRootLayer(root);
|
| + scroller->SetScrollClipLayerId(container->id());
|
| +
|
| + LayerStickyPositionConstraint sticky_position;
|
| + sticky_position.is_sticky = true;
|
| + sticky_position.local_sticky_offset = gfx::Vector2dF(10, 50);
|
| + sticky->SetStickyPositionConstraint(sticky_position);
|
| +
|
| + host()->host_impl()->CreatePendingTree();
|
| + host()->CommitAndCreatePendingTree();
|
| + host()->host_impl()->ActivateSyncTree();
|
| +
|
| + // We should ignore the sticky element above the scroller.
|
| + gfx::Vector2dF offset = CalculateTotalStickyOffsetToScroller(
|
| + first_grandchild.get(), scroller->id());
|
| + EXPECT_VECTOR2DF_EQ(gfx::Vector2dF(0, 0), offset);
|
| +}
|
| +
|
| +} // namespace draw_property_utils
|
| +} // namespace cc
|
|
|