Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 | |
| 7 #include "core/layout/LayoutTestHelper.h" | |
| 8 #include "core/layout/LayoutTreeAsText.h" | |
| 9 #include "core/layout/LayoutView.h" | |
| 10 #include "core/paint/ObjectPaintProperties.h" | |
| 11 #include "platform/graphics/paint/TransformPaintPropertyNode.h" | |
| 12 #include "platform/text/TextStream.h" | |
| 13 #include "public/platform/Platform.h" | |
| 14 #include "public/platform/WebUnitTestSupport.h" | |
| 15 #include "wtf/HashMap.h" | |
| 16 #include "wtf/Vector.h" | |
| 17 #include <gtest/gtest.h> | |
| 18 | |
| 19 namespace blink { | |
| 20 | |
| 21 class PaintPropertyTreeBuilderTest : public RenderingTest { | |
| 22 public: | |
| 23 PaintPropertyTreeBuilderTest() | |
| 24 : m_originalSlimmingPaintV2Enabled(RuntimeEnabledFeatures::slimmingPaint V2Enabled()) { } | |
| 25 | |
| 26 void loadTestData(const char* fileName) | |
| 27 { | |
| 28 std::string fullPath(Platform::current()->unitTestSupport()->webKitRootD ir().utf8().data()); | |
|
pdr.
2015/10/20 22:02:31
This can be simplified a bit to avoid so many conv
trchen
2015/10/21 06:16:20
Done.
| |
| 29 fullPath.append("/Source/core/paint/test_data/"); | |
| 30 fullPath.append(fileName); | |
| 31 WebData inputBuffer = Platform::current()->unitTestSupport()->readFromFi le(WebString::fromUTF8(fullPath.c_str())); | |
| 32 setBodyInnerHTML(String(inputBuffer.data(), inputBuffer.size())); | |
| 33 } | |
| 34 | |
| 35 private: | |
| 36 void SetUp() override | |
| 37 { | |
| 38 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); | |
| 39 Settings::setMockScrollbarsEnabled(true); | |
| 40 | |
| 41 RenderingTest::SetUp(); | |
| 42 enableCompositing(); | |
| 43 } | |
| 44 | |
| 45 void TearDown() override | |
| 46 { | |
| 47 RenderingTest::TearDown(); | |
| 48 | |
| 49 Settings::setMockScrollbarsEnabled(false); | |
| 50 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(m_originalSlimmingPain tV2Enabled); | |
| 51 } | |
| 52 | |
| 53 bool m_originalSlimmingPaintV2Enabled; | |
| 54 }; | |
| 55 | |
| 56 TEST_F(PaintPropertyTreeBuilderTest, FixedPosition) | |
| 57 { | |
| 58 loadTestData("fixed-position.html"); | |
| 59 | |
| 60 FrameView* frameView = document().view(); | |
|
pdr.
2015/10/20 22:02:31
Lets move this down to where it's used.
i.e.,
EXP
trchen
2015/10/21 06:16:20
Done.
| |
| 61 | |
| 62 // target1 is a fixed-position element inside an absolute-position scrolling element. | |
| 63 // It should be attached under the viewport to skip scrolling and offset of the parent. | |
| 64 Element* target1 = document().getElementById("target1"); | |
| 65 ObjectPaintProperties* target1Properties = target1->layoutObject()->objectPa intProperties(); | |
| 66 { | |
| 67 TransformationMatrix matrix; | |
| 68 matrix.translate(200, 150); | |
| 69 EXPECT_EQ(matrix, target1Properties->preTranslation()->matrix()); | |
|
jbroman
2015/10/20 23:50:13
I think this could be written as:
EXPECT_EQ(Trans
trchen
2015/10/21 06:16:20
Cool! Didn't know that matrix operations can be ch
| |
| 70 } | |
| 71 EXPECT_EQ(frameView->preTranslation(), target1Properties->preTranslation()-> parent()); | |
| 72 | |
| 73 // target2 is a fixed-position element inside a transformed scrolling elemen t. | |
| 74 // It should be attached under the scrolled box of the transformed element. | |
| 75 Element* target2 = document().getElementById("target2"); | |
| 76 ObjectPaintProperties* target2Properties = target2->layoutObject()->objectPa intProperties(); | |
| 77 Element* scroller = document().getElementById("scroller"); | |
| 78 ObjectPaintProperties* scrollerProperties = scroller->layoutObject()->object PaintProperties(); | |
| 79 { | |
| 80 TransformationMatrix matrix; | |
| 81 matrix.translate(200, 150); | |
| 82 EXPECT_EQ(matrix, target2Properties->preTranslation()->matrix()); | |
| 83 } | |
| 84 EXPECT_EQ(scrollerProperties->scrollTranslation(), target2Properties->preTra nslation()->parent()); | |
| 85 } | |
| 86 | |
| 87 TEST_F(PaintPropertyTreeBuilderTest, PositionAndScroll) | |
| 88 { | |
| 89 loadTestData("position-and-scroll.html"); | |
| 90 | |
| 91 FrameView* frameView = document().view(); | |
| 92 | |
| 93 Element* scroller = document().getElementById("scroller"); | |
| 94 scroller->scrollTo(0, 100); | |
| 95 frameView->updateAllLifecyclePhases(); | |
| 96 ObjectPaintProperties* scrollerProperties = scroller->layoutObject()->object PaintProperties(); | |
| 97 { | |
| 98 TransformationMatrix matrix; | |
| 99 matrix.translate(0, -100); | |
| 100 EXPECT_EQ(matrix, scrollerProperties->scrollTranslation()->matrix()); | |
| 101 } | |
| 102 EXPECT_EQ(frameView->scrollTranslation(), scrollerProperties->scrollTranslat ion()->parent()); | |
| 103 | |
| 104 // The relative-positioned element should have accumulated box offset (exclu de scrolling), | |
| 105 // and should be affected by ancestor scroll transforms. | |
| 106 Element* relPos = document().getElementById("rel-pos"); | |
| 107 ObjectPaintProperties* relPosProperties = relPos->layoutObject()->objectPain tProperties(); | |
| 108 { | |
| 109 TransformationMatrix matrix; | |
| 110 matrix.translate(680, 1120); | |
| 111 EXPECT_EQ(matrix, relPosProperties->preTranslation()->matrix()); | |
| 112 } | |
| 113 EXPECT_EQ(scrollerProperties->scrollTranslation(), relPosProperties->preTran slation()->parent()); | |
| 114 | |
| 115 // The absolute-positioned element should not be affected by non-positioned scroller at all. | |
| 116 Element* absPos = document().getElementById("abs-pos"); | |
| 117 ObjectPaintProperties* absPosProperties = absPos->layoutObject()->objectPain tProperties(); | |
| 118 { | |
| 119 TransformationMatrix matrix; | |
| 120 matrix.translate(123, 456); | |
| 121 EXPECT_EQ(matrix, absPosProperties->preTranslation()->matrix()); | |
| 122 } | |
| 123 EXPECT_EQ(frameView->scrollTranslation(), absPosProperties->preTranslation() ->parent()); | |
| 124 } | |
| 125 | |
| 126 TEST_F(PaintPropertyTreeBuilderTest, FrameScrollingTraditional) | |
| 127 { | |
| 128 loadTestData("long-page.html"); | |
|
pdr.
2015/10/20 22:02:31
This one is so simple it may be better to just inl
trchen
2015/10/21 06:16:20
Done.
| |
| 129 | |
| 130 document().domWindow()->scrollTo(0, 100); | |
| 131 | |
| 132 FrameView* frameView = document().view(); | |
| 133 frameView->updateAllLifecyclePhases(); | |
| 134 EXPECT_EQ(TransformationMatrix(), frameView->preTranslation()->matrix()); | |
| 135 EXPECT_EQ(nullptr, frameView->preTranslation()->parent()); | |
| 136 { | |
| 137 TransformationMatrix matrix; | |
| 138 matrix.translate(0, -100); | |
| 139 EXPECT_EQ(matrix, frameView->scrollTranslation()->matrix()); | |
| 140 } | |
| 141 EXPECT_EQ(frameView->preTranslation(), frameView->scrollTranslation()->paren t()); | |
| 142 | |
| 143 LayoutView* layoutView = document().layoutView(); | |
| 144 ObjectPaintProperties* layoutViewProperties = layoutView->objectPaintPropert ies(); | |
| 145 EXPECT_EQ(nullptr, layoutViewProperties); | |
| 146 } | |
| 147 | |
| 148 // TODO(trchen): Settings::rootLayerScrolls cannot be switched after main frame being created. | |
| 149 // Need to set it during test setup. Besides that, the test still won't work bec ause | |
| 150 // root layer scrolling mode is not compatible with SPv2 at this moment. | |
| 151 // (Duplicate display item ID for FrameView and LayoutView.) | |
| 152 TEST_F(PaintPropertyTreeBuilderTest, DISABLED_FrameScrollingRootLayerScrolls) | |
| 153 { | |
| 154 document().settings()->setRootLayerScrolls(true); | |
| 155 | |
| 156 loadTestData("long-page.html"); | |
| 157 | |
| 158 document().domWindow()->scrollTo(0, 100); | |
| 159 | |
| 160 FrameView* frameView = document().view(); | |
| 161 frameView->updateAllLifecyclePhases(); | |
| 162 EXPECT_EQ(TransformationMatrix(), frameView->preTranslation()->matrix()); | |
| 163 EXPECT_EQ(nullptr, frameView->preTranslation()->parent()); | |
| 164 EXPECT_EQ(TransformationMatrix(), frameView->scrollTranslation()->matrix()); | |
| 165 EXPECT_EQ(frameView->preTranslation(), frameView->scrollTranslation()->paren t()); | |
| 166 | |
| 167 LayoutView* layoutView = document().layoutView(); | |
| 168 ObjectPaintProperties* layoutViewProperties = layoutView->objectPaintPropert ies(); | |
| 169 { | |
| 170 TransformationMatrix matrix; | |
| 171 matrix.translate(0, -100); | |
| 172 EXPECT_EQ(matrix, layoutViewProperties->scrollTranslation()->matrix()); | |
| 173 } | |
| 174 EXPECT_EQ(frameView->scrollTranslation(), layoutViewProperties->scrollTransl ation()->parent()); | |
| 175 } | |
| 176 | |
| 177 TEST_F(PaintPropertyTreeBuilderTest, Perspective) | |
| 178 { | |
| 179 loadTestData("perspective.html"); | |
| 180 | |
| 181 FrameView* frameView = document().view(); | |
|
pdr.
2015/10/20 22:02:31
Lets move this down to where it's used.
i.e.,
EXP
trchen
2015/10/21 06:16:20
Done.
| |
| 182 | |
| 183 Element* perspective = document().getElementById("perspective"); | |
| 184 ObjectPaintProperties* perspectiveProperties = perspective->layoutObject()-> objectPaintProperties(); | |
| 185 { | |
| 186 TransformationMatrix matrix; | |
| 187 matrix.applyPerspective(100); | |
| 188 EXPECT_EQ(matrix, perspectiveProperties->perspective()->matrix()); | |
| 189 } | |
| 190 // The perspective origin is the center of the border box plus accumulated p aint offset. | |
| 191 EXPECT_EQ(FloatPoint3D(250, 250, 0), perspectiveProperties->perspective()->o rigin()); | |
| 192 EXPECT_EQ(frameView->scrollTranslation(), perspectiveProperties->perspective ()->parent()); | |
| 193 | |
| 194 // Adding perspective doesn't clear paint offset. The paint offset will be p assed down to children. | |
| 195 Element* inner = document().getElementById("inner"); | |
| 196 ObjectPaintProperties* innerProperties = inner->layoutObject()->objectPaintP roperties(); | |
| 197 { | |
| 198 TransformationMatrix matrix; | |
| 199 matrix.translate(50, 100); | |
| 200 EXPECT_EQ(matrix, innerProperties->preTranslation()->matrix()); | |
| 201 } | |
| 202 EXPECT_EQ(perspectiveProperties->perspective(), innerProperties->preTranslat ion()->parent()); | |
| 203 } | |
| 204 | |
| 205 TEST_F(PaintPropertyTreeBuilderTest, Transform) | |
| 206 { | |
| 207 loadTestData("transform.html"); | |
| 208 | |
| 209 FrameView* frameView = document().view(); | |
|
pdr.
2015/10/20 22:02:31
Lets move this down to where it's used.
trchen
2015/10/21 06:16:20
Done.
| |
| 210 | |
| 211 Element* transform = document().getElementById("transform"); | |
| 212 ObjectPaintProperties* transformProperties = transform->layoutObject()->obje ctPaintProperties(); | |
| 213 { | |
| 214 TransformationMatrix matrix; | |
| 215 matrix.translate3d(123, 456, 789); | |
| 216 EXPECT_EQ(matrix, transformProperties->transform()->matrix()); | |
| 217 } | |
| 218 EXPECT_EQ(FloatPoint3D(200, 150, 0), transformProperties->transform()->origi n()); | |
| 219 EXPECT_EQ(transformProperties->preTranslation(), transformProperties->transf orm()->parent()); | |
| 220 { | |
| 221 TransformationMatrix matrix; | |
| 222 matrix.translate(50, 100); | |
| 223 EXPECT_EQ(matrix, transformProperties->preTranslation()->matrix()); | |
| 224 } | |
| 225 EXPECT_EQ(frameView->scrollTranslation(), transformProperties->preTranslatio n()->parent()); | |
| 226 | |
|
pdr.
2015/10/20 22:02:31
Nit: extra space.
trchen
2015/10/21 06:16:20
Done.
| |
| 227 } | |
| 228 | |
| 229 } // namespace blink | |
| OLD | NEW |