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..03a1e0c4ae53b9f6b09844ca70848f35b96ac5f9 |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilderTest.cpp |
@@ -0,0 +1,158 @@ |
+// 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 DumpContext { |
jbroman
2015/10/16 17:31:55
nit: This should be in an anonymous namespace, to
trchen
2015/10/20 05:11:47
WontFix (obsolete)
|
+public: |
+ DumpContext(TextStream& newOut) : out(newOut) { } |
+ |
+ void dumpLayoutTreeAndPropertyTrees(const FrameView& frameView) |
+ { |
+ transformTreeIndexToChildrenList.append(ChildrenList()); |
+ |
+ out << "=== Layout Tree ===\n"; |
+ dumpLayoutTreeAndCollectPropertyNodes(frameView, 0); |
+ out << "\n=== Transform Tree ===\n"; |
+ dumpTransformTree(nullptr, 0); |
+ } |
+private: |
+ void dumpLayoutTreeAndCollectPropertyNodes(const FrameView& frameView, int indent) |
+ { |
+ writeIndent(out, indent); |
+ out << "FrameView " << frameView.frameRect() << " scroll={" << toFloatSize(frameView.scrollOffsetDouble()) << "}"; |
+ if (frameView.preTranslation()) |
+ out << " preTranslation=#" << collectTransformNode(*frameView.preTranslation()); |
+ if (frameView.scrollTranslation()) |
+ out << " scrollTranslation=#" << collectTransformNode(*frameView.scrollTranslation()); |
+ out << "\n"; |
+ if (frameView.layoutView()) |
+ dumpLayoutTreeAndCollectPropertyNodes(*frameView.layoutView(), indent + 1); |
+ } |
+ |
+ void dumpLayoutTreeAndCollectPropertyNodes(const LayoutObject& object, int indent) |
+ { |
+ writeIndent(out, indent); |
+ LayoutTreeAsText::writeLayoutObject(out, object, LayoutAsTextShowIDAndClass); |
+ if (ObjectPaintProperties* properties = object.objectPaintProperties()) { |
+ if (properties->preTranslation()) |
+ out << " preTranslation=#" << collectTransformNode(*properties->preTranslation()); |
+ if (properties->transform()) |
+ out << " transform=#" << collectTransformNode(*properties->transform()); |
+ if (properties->perspective()) |
+ out << " perspective=#" << collectTransformNode(*properties->perspective()); |
+ if (properties->scrollTranslation()) |
+ out << " scrollTranslation=#" << collectTransformNode(*properties->scrollTranslation()); |
+ } |
+ out << "\n"; |
+ for (const LayoutObject* child = object.slowFirstChild(); child; child = child->nextSibling()) |
+ dumpLayoutTreeAndCollectPropertyNodes(*child, indent + 1); |
+ } |
+ |
+ void dumpTransformTree(const TransformPaintPropertyNode* node, int indent) |
+ { |
+ writeIndent(out, indent); |
+ size_t index = 0; |
+ if (!node) { |
+ out << "#0 Root"; |
+ } else { |
+ index = transformTreeNodeToIndex.get(node); |
+ out << "#" << index << " "; |
+ std::stringstream buf; |
+ PrintTo(*node, &buf); |
+ out << buf.str().c_str(); |
+ } |
+ out << "\n"; |
+ for (auto child: transformTreeIndexToChildrenList[index]) |
jbroman
2015/10/16 17:31:55
nit: style dictates a space on both sides of the p
jbroman
2015/10/19 15:12:45
By period I mean colon.
trchen
2015/10/20 05:11:47
WontFix (obsolete)
|
+ dumpTransformTree(child, indent + 1); |
+ } |
+ |
+ size_t collectTransformNode(const TransformPaintPropertyNode& node) |
+ { |
+ size_t index = transformTreeIndexToChildrenList.size(); |
+ transformTreeIndexToChildrenList.append(ChildrenList()); |
+ ASSERT(!transformTreeNodeToIndex.contains(&node)); |
+ transformTreeNodeToIndex.set(&node, index); |
+ |
+ size_t parent = 0; |
+ if (node.parent()) { |
+ ASSERT(transformTreeNodeToIndex.contains(node.parent())); |
+ parent = transformTreeNodeToIndex.get(node.parent()); |
+ } |
+ transformTreeIndexToChildrenList[parent].append(&node); |
+ |
+ return index; |
+ } |
+ typedef Vector<const TransformPaintPropertyNode*> ChildrenList; |
+ Vector<ChildrenList> transformTreeIndexToChildrenList; |
+ HashMap<const TransformPaintPropertyNode*, size_t> transformTreeNodeToIndex; |
+ |
+ TextStream& out; |
+}; |
+ |
+class PaintPropertyTreeBuilderTest : public RenderingTest { |
+public: |
+ PaintPropertyTreeBuilderTest() |
+ : m_originalSlimmingPaintV2Enabled(RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { } |
+ |
+ void runTest(const char* fileName) |
+ { |
+ std::string fullPath(Platform::current()->unitTestSupport()->webKitRootDir().utf8().data()); |
+ fullPath.append("/Source/core/paint/paint_property_tree_builder_tests/"); |
+ fullPath.append(fileName); |
+ WebData inputBuffer = Platform::current()->unitTestSupport()->readFromFile(WebString::fromUTF8(fullPath.c_str())); |
+ std::string inputData(inputBuffer.data(), inputBuffer.size()); |
+ setBodyInnerHTML(inputData.c_str()); |
+ |
+ TextStream outputBuffer; |
+ DumpContext(outputBuffer).dumpLayoutTreeAndPropertyTrees(*document().view()); |
+ |
+ std::string expectationFullPath(fullPath); |
+ expectationFullPath.append("-expected.txt"); |
+ WebData expectationBuffer = Platform::current()->unitTestSupport()->readFromFile(WebString::fromUTF8(expectationFullPath.c_str())); |
+ std::string expectationData(expectationBuffer.data(), expectationBuffer.size()); |
+ EXPECT_STREQ(expectationData.c_str(), outputBuffer.release().utf8().data()); |
+ } |
+ |
+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) |
+{ |
+ runTest("fixed-position.html"); |
+} |
+ |
+} // namespace blink |