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

Unified Diff: third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilderTest.cpp

Issue 1407543003: Preliminary paint property walk implementation for SPv2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor bug fix (perspective does not clear paint offset). switch test to unit test style. add a few … Created 5 years, 2 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: third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilderTest.cpp
diff --git a/third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilderTest.cpp b/third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilderTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..547ab29892d7127c72fed26d2bac3a2be8e50b5a
--- /dev/null
+++ b/third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilderTest.cpp
@@ -0,0 +1,229 @@
+// Copyright 2015 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 "config.h"
+
+#include "core/layout/LayoutTestHelper.h"
+#include "core/layout/LayoutTreeAsText.h"
+#include "core/layout/LayoutView.h"
+#include "core/paint/ObjectPaintProperties.h"
+#include "platform/graphics/paint/TransformPaintPropertyNode.h"
+#include "platform/text/TextStream.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebUnitTestSupport.h"
+#include "wtf/HashMap.h"
+#include "wtf/Vector.h"
+#include <gtest/gtest.h>
+
+namespace blink {
+
+class PaintPropertyTreeBuilderTest : public RenderingTest {
+public:
+ PaintPropertyTreeBuilderTest()
+ : m_originalSlimmingPaintV2Enabled(RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { }
+
+ void loadTestData(const char* fileName)
+ {
+ std::string fullPath(Platform::current()->unitTestSupport()->webKitRootDir().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.
+ fullPath.append("/Source/core/paint/test_data/");
+ fullPath.append(fileName);
+ WebData inputBuffer = Platform::current()->unitTestSupport()->readFromFile(WebString::fromUTF8(fullPath.c_str()));
+ setBodyInnerHTML(String(inputBuffer.data(), inputBuffer.size()));
+ }
+
+private:
+ void SetUp() override
+ {
+ RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true);
+ Settings::setMockScrollbarsEnabled(true);
+
+ RenderingTest::SetUp();
+ enableCompositing();
+ }
+
+ void TearDown() override
+ {
+ RenderingTest::TearDown();
+
+ Settings::setMockScrollbarsEnabled(false);
+ RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(m_originalSlimmingPaintV2Enabled);
+ }
+
+ bool m_originalSlimmingPaintV2Enabled;
+};
+
+TEST_F(PaintPropertyTreeBuilderTest, FixedPosition)
+{
+ loadTestData("fixed-position.html");
+
+ 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.
+
+ // target1 is a fixed-position element inside an absolute-position scrolling element.
+ // It should be attached under the viewport to skip scrolling and offset of the parent.
+ Element* target1 = document().getElementById("target1");
+ ObjectPaintProperties* target1Properties = target1->layoutObject()->objectPaintProperties();
+ {
+ TransformationMatrix matrix;
+ matrix.translate(200, 150);
+ 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
+ }
+ EXPECT_EQ(frameView->preTranslation(), target1Properties->preTranslation()->parent());
+
+ // target2 is a fixed-position element inside a transformed scrolling element.
+ // It should be attached under the scrolled box of the transformed element.
+ Element* target2 = document().getElementById("target2");
+ ObjectPaintProperties* target2Properties = target2->layoutObject()->objectPaintProperties();
+ Element* scroller = document().getElementById("scroller");
+ ObjectPaintProperties* scrollerProperties = scroller->layoutObject()->objectPaintProperties();
+ {
+ TransformationMatrix matrix;
+ matrix.translate(200, 150);
+ EXPECT_EQ(matrix, target2Properties->preTranslation()->matrix());
+ }
+ EXPECT_EQ(scrollerProperties->scrollTranslation(), target2Properties->preTranslation()->parent());
+}
+
+TEST_F(PaintPropertyTreeBuilderTest, PositionAndScroll)
+{
+ loadTestData("position-and-scroll.html");
+
+ FrameView* frameView = document().view();
+
+ Element* scroller = document().getElementById("scroller");
+ scroller->scrollTo(0, 100);
+ frameView->updateAllLifecyclePhases();
+ ObjectPaintProperties* scrollerProperties = scroller->layoutObject()->objectPaintProperties();
+ {
+ TransformationMatrix matrix;
+ matrix.translate(0, -100);
+ EXPECT_EQ(matrix, scrollerProperties->scrollTranslation()->matrix());
+ }
+ EXPECT_EQ(frameView->scrollTranslation(), scrollerProperties->scrollTranslation()->parent());
+
+ // The relative-positioned element should have accumulated box offset (exclude scrolling),
+ // and should be affected by ancestor scroll transforms.
+ Element* relPos = document().getElementById("rel-pos");
+ ObjectPaintProperties* relPosProperties = relPos->layoutObject()->objectPaintProperties();
+ {
+ TransformationMatrix matrix;
+ matrix.translate(680, 1120);
+ EXPECT_EQ(matrix, relPosProperties->preTranslation()->matrix());
+ }
+ EXPECT_EQ(scrollerProperties->scrollTranslation(), relPosProperties->preTranslation()->parent());
+
+ // The absolute-positioned element should not be affected by non-positioned scroller at all.
+ Element* absPos = document().getElementById("abs-pos");
+ ObjectPaintProperties* absPosProperties = absPos->layoutObject()->objectPaintProperties();
+ {
+ TransformationMatrix matrix;
+ matrix.translate(123, 456);
+ EXPECT_EQ(matrix, absPosProperties->preTranslation()->matrix());
+ }
+ EXPECT_EQ(frameView->scrollTranslation(), absPosProperties->preTranslation()->parent());
+}
+
+TEST_F(PaintPropertyTreeBuilderTest, FrameScrollingTraditional)
+{
+ 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.
+
+ document().domWindow()->scrollTo(0, 100);
+
+ FrameView* frameView = document().view();
+ frameView->updateAllLifecyclePhases();
+ EXPECT_EQ(TransformationMatrix(), frameView->preTranslation()->matrix());
+ EXPECT_EQ(nullptr, frameView->preTranslation()->parent());
+ {
+ TransformationMatrix matrix;
+ matrix.translate(0, -100);
+ EXPECT_EQ(matrix, frameView->scrollTranslation()->matrix());
+ }
+ EXPECT_EQ(frameView->preTranslation(), frameView->scrollTranslation()->parent());
+
+ LayoutView* layoutView = document().layoutView();
+ ObjectPaintProperties* layoutViewProperties = layoutView->objectPaintProperties();
+ EXPECT_EQ(nullptr, layoutViewProperties);
+}
+
+// TODO(trchen): Settings::rootLayerScrolls cannot be switched after main frame being created.
+// Need to set it during test setup. Besides that, the test still won't work because
+// root layer scrolling mode is not compatible with SPv2 at this moment.
+// (Duplicate display item ID for FrameView and LayoutView.)
+TEST_F(PaintPropertyTreeBuilderTest, DISABLED_FrameScrollingRootLayerScrolls)
+{
+ document().settings()->setRootLayerScrolls(true);
+
+ loadTestData("long-page.html");
+
+ document().domWindow()->scrollTo(0, 100);
+
+ FrameView* frameView = document().view();
+ frameView->updateAllLifecyclePhases();
+ EXPECT_EQ(TransformationMatrix(), frameView->preTranslation()->matrix());
+ EXPECT_EQ(nullptr, frameView->preTranslation()->parent());
+ EXPECT_EQ(TransformationMatrix(), frameView->scrollTranslation()->matrix());
+ EXPECT_EQ(frameView->preTranslation(), frameView->scrollTranslation()->parent());
+
+ LayoutView* layoutView = document().layoutView();
+ ObjectPaintProperties* layoutViewProperties = layoutView->objectPaintProperties();
+ {
+ TransformationMatrix matrix;
+ matrix.translate(0, -100);
+ EXPECT_EQ(matrix, layoutViewProperties->scrollTranslation()->matrix());
+ }
+ EXPECT_EQ(frameView->scrollTranslation(), layoutViewProperties->scrollTranslation()->parent());
+}
+
+TEST_F(PaintPropertyTreeBuilderTest, Perspective)
+{
+ loadTestData("perspective.html");
+
+ 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.
+
+ Element* perspective = document().getElementById("perspective");
+ ObjectPaintProperties* perspectiveProperties = perspective->layoutObject()->objectPaintProperties();
+ {
+ TransformationMatrix matrix;
+ matrix.applyPerspective(100);
+ EXPECT_EQ(matrix, perspectiveProperties->perspective()->matrix());
+ }
+ // The perspective origin is the center of the border box plus accumulated paint offset.
+ EXPECT_EQ(FloatPoint3D(250, 250, 0), perspectiveProperties->perspective()->origin());
+ EXPECT_EQ(frameView->scrollTranslation(), perspectiveProperties->perspective()->parent());
+
+ // Adding perspective doesn't clear paint offset. The paint offset will be passed down to children.
+ Element* inner = document().getElementById("inner");
+ ObjectPaintProperties* innerProperties = inner->layoutObject()->objectPaintProperties();
+ {
+ TransformationMatrix matrix;
+ matrix.translate(50, 100);
+ EXPECT_EQ(matrix, innerProperties->preTranslation()->matrix());
+ }
+ EXPECT_EQ(perspectiveProperties->perspective(), innerProperties->preTranslation()->parent());
+}
+
+TEST_F(PaintPropertyTreeBuilderTest, Transform)
+{
+ loadTestData("transform.html");
+
+ 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.
+
+ Element* transform = document().getElementById("transform");
+ ObjectPaintProperties* transformProperties = transform->layoutObject()->objectPaintProperties();
+ {
+ TransformationMatrix matrix;
+ matrix.translate3d(123, 456, 789);
+ EXPECT_EQ(matrix, transformProperties->transform()->matrix());
+ }
+ EXPECT_EQ(FloatPoint3D(200, 150, 0), transformProperties->transform()->origin());
+ EXPECT_EQ(transformProperties->preTranslation(), transformProperties->transform()->parent());
+ {
+ TransformationMatrix matrix;
+ matrix.translate(50, 100);
+ EXPECT_EQ(matrix, transformProperties->preTranslation()->matrix());
+ }
+ EXPECT_EQ(frameView->scrollTranslation(), transformProperties->preTranslation()->parent());
+
pdr. 2015/10/20 22:02:31 Nit: extra space.
trchen 2015/10/21 06:16:20 Done.
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698