Chromium Code Reviews| Index: third_party/WebKit/Source/platform/graphics/paint/GeometryMapperTest.cpp |
| diff --git a/third_party/WebKit/Source/platform/graphics/paint/GeometryMapperTest.cpp b/third_party/WebKit/Source/platform/graphics/paint/GeometryMapperTest.cpp |
| index f71ee303d62aade6e787212e123feaf7e6ab87a9..c8015377bb6f7d16cc6a94df19a5d0463bcafcbd 100644 |
| --- a/third_party/WebKit/Source/platform/graphics/paint/GeometryMapperTest.cpp |
| +++ b/third_party/WebKit/Source/platform/graphics/paint/GeometryMapperTest.cpp |
| @@ -27,11 +27,17 @@ public: |
| return state; |
| } |
| - PrecomputedDataForAncestor& GetPrecomputedDataForAncestor(const PropertyTreeState& propertyTreeState) |
| + PrecomputedDataForAncestor& getPrecomputedDataForAncestor(const PropertyTreeState& propertyTreeState) |
| { |
| - return geometryMapper->GetPrecomputedDataForAncestor(propertyTreeState); |
| + return geometryMapper->getPrecomputedDataForAncestor(propertyTreeState); |
| } |
| + PassRefPtr<TransformPaintPropertyNode> leastCommonAncestor(PassRefPtr<TransformPaintPropertyNode> a, PassRefPtr<TransformPaintPropertyNode> b) |
| + { |
| + return geometryMapper->leastCommonAncestor(a, b); |
| + } |
| + |
|
pdr.
2016/06/30 21:21:50
Nit: extra newline
chrishtr
2016/07/01 17:52:24
Done.
|
| + |
| private: |
| void SetUp() override |
| { |
| @@ -60,12 +66,15 @@ do { \ |
| #define CHECK_MAPPINGS(inputRect, expectedVisualRect, expectedTransformedRect, expectedTransformToAncestor, expectedClipInAncestorSpace, localPropertyTreeState, ancestorPropertyTreeState) \ |
| do { \ |
| + bool success = false; \ |
| EXPECT_RECT_EQ(expectedVisualRect, \ |
| - geometryMapper->LocalToVisualRectInAncestorSpace(inputRect, localPropertyTreeState, ancestorPropertyTreeState)); \ |
| + geometryMapper->localToVisualRectInAncestorSpace(inputRect, localPropertyTreeState, ancestorPropertyTreeState, &success)); \ |
| + EXPECT_TRUE(success); \ |
| EXPECT_RECT_EQ(expectedTransformedRect, \ |
| - geometryMapper->LocalToAncestorRect(inputRect, localPropertyTreeState, ancestorPropertyTreeState)); \ |
| - EXPECT_EQ(expectedTransformToAncestor, GetPrecomputedDataForAncestor(ancestorPropertyTreeState).toAncestorTransforms.get(localPropertyTreeState.transform)); \ |
| - EXPECT_EQ(expectedClipInAncestorSpace, GetPrecomputedDataForAncestor(ancestorPropertyTreeState).toAncestorClipRects.get(localPropertyTreeState.clip)); \ |
| + geometryMapper->localToAncestorRect(inputRect, localPropertyTreeState, ancestorPropertyTreeState, &success)); \ |
| + EXPECT_TRUE(success); \ |
| + EXPECT_EQ(expectedTransformToAncestor, getPrecomputedDataForAncestor(ancestorPropertyTreeState).toAncestorTransforms.get(localPropertyTreeState.transform.get())); \ |
| + EXPECT_EQ(expectedClipInAncestorSpace, getPrecomputedDataForAncestor(ancestorPropertyTreeState).toAncestorClipRects.get(localPropertyTreeState.clip.get())); \ |
| } while (false) |
| TEST_F(GeometryMapperTest, Root) |
| @@ -101,7 +110,7 @@ TEST_F(GeometryMapperTest, TranslationTransform) |
| bool success = false; |
| EXPECT_RECT_EQ(input, |
| - geometryMapper->AncestorToLocalRect(output, localState, rootPropertyTreeState(), &success)); |
| + geometryMapper->ancestorToLocalRect(output, localState, rootPropertyTreeState(), &success)); |
| EXPECT_TRUE(success); |
| } |
| @@ -156,7 +165,7 @@ TEST_F(GeometryMapperTest, NestedTransforms) |
| CHECK_MAPPINGS(input, output, output, final, rootClipNode->clipRect().rect(), localState, rootPropertyTreeState()); |
| // Check the cached matrix for the intermediate transform. |
| - EXPECT_EQ(rotateTransform, GetPrecomputedDataForAncestor(rootPropertyTreeState()).toAncestorTransforms.get(transform1.get())); |
| + EXPECT_EQ(rotateTransform, getPrecomputedDataForAncestor(rootPropertyTreeState()).toAncestorTransforms.get(transform1.get())); |
| } |
| TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) |
| @@ -309,4 +318,60 @@ TEST_F(GeometryMapperTest, TwoClipsWithTransformBetween) |
| } |
| } |
| +TEST_F(GeometryMapperTest, SiblingTransforms) |
| +{ |
| + // These transforms are siblings. Thus mapping from one to the other requires going through the root. |
| + TransformationMatrix rotateTransform1; |
| + rotateTransform1.rotate(45); |
| + RefPtr<TransformPaintPropertyNode> transform1 = TransformPaintPropertyNode::create(rotateTransform1, FloatPoint3D(), rootPropertyTreeState().transform); |
| + |
| + TransformationMatrix rotateTransform2; |
| + rotateTransform2.rotate(-45); |
| + RefPtr<TransformPaintPropertyNode> transform2 = TransformPaintPropertyNode::create(rotateTransform2, FloatPoint3D(), rootPropertyTreeState().transform); |
| + |
| + PropertyTreeState transform1State = rootPropertyTreeState(); |
| + transform1State.transform = transform1; |
| + PropertyTreeState transform2State = rootPropertyTreeState(); |
| + transform2State.transform = transform2; |
| + |
| + bool success; |
| + FloatRect input(0, 0, 100, 100); |
| + FloatRect result = geometryMapper->localToVisualRectInAncestorSpace(input, transform1State, transform2State, &success); |
| + // Fails, because the transform2state is not an ancestor of transform1State. |
| + EXPECT_FALSE(success); |
| + EXPECT_RECT_EQ(input, result); |
| + |
| + result = geometryMapper->localToVisualRectInAncestorSpace(input, transform2State, transform1State, &success); |
| + // Fails, because the transform1state is not an ancestor of transform2State. |
| + EXPECT_FALSE(success); |
| + EXPECT_RECT_EQ(input, result); |
| + |
| + FloatRect expected = rotateTransform2.inverse().mapRect(rotateTransform1.mapRect(input)); |
| + result = geometryMapper->mapToVisualRectInDestinationSpace(input, transform1State, transform2State, &success); |
| + EXPECT_TRUE(success); |
| + EXPECT_RECT_EQ(expected, result); |
|
pdr.
2016/06/30 21:21:50
Can you use real numbers for this test? Maybe tran
|
| +} |
| + |
| +TEST_F(GeometryMapperTest, LeastCommonAncestor) |
| +{ |
| + TransformationMatrix matrix; |
| + RefPtr<TransformPaintPropertyNode> child1 = TransformPaintPropertyNode::create(matrix, FloatPoint3D(), rootPropertyTreeState().transform); |
| + RefPtr<TransformPaintPropertyNode> child2 = TransformPaintPropertyNode::create(matrix, FloatPoint3D(), rootPropertyTreeState().transform); |
| + |
| + RefPtr<TransformPaintPropertyNode> childOfChild1 = TransformPaintPropertyNode::create(matrix, FloatPoint3D(), child1); |
| + RefPtr<TransformPaintPropertyNode> childOfChild2 = TransformPaintPropertyNode::create(matrix, FloatPoint3D(), child2); |
| + |
| + EXPECT_EQ(rootPropertyTreeState().transform, leastCommonAncestor(childOfChild1, childOfChild2)); |
| + EXPECT_EQ(rootPropertyTreeState().transform, leastCommonAncestor(childOfChild1, child2)); |
| + EXPECT_EQ(rootPropertyTreeState().transform, leastCommonAncestor(childOfChild1, rootPropertyTreeState().transform)); |
| + EXPECT_EQ(child1, leastCommonAncestor(childOfChild1, child1)); |
| + |
| + EXPECT_EQ(rootPropertyTreeState().transform, leastCommonAncestor(childOfChild2, childOfChild1)); |
| + EXPECT_EQ(rootPropertyTreeState().transform, leastCommonAncestor(childOfChild2, child1)); |
| + EXPECT_EQ(rootPropertyTreeState().transform, leastCommonAncestor(childOfChild2, rootPropertyTreeState().transform)); |
| + EXPECT_EQ(child2, leastCommonAncestor(childOfChild2, child2)); |
| + |
| + EXPECT_EQ(rootPropertyTreeState().transform, leastCommonAncestor(child1, child2)); |
| +} |
| + |
| } // namespace blink |