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 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)
| |
| 22 public: | |
| 23 DumpContext(TextStream& newOut) : out(newOut) { } | |
| 24 | |
| 25 void dumpLayoutTreeAndPropertyTrees(const FrameView& frameView) | |
| 26 { | |
| 27 transformTreeIndexToChildrenList.append(ChildrenList()); | |
| 28 | |
| 29 out << "=== Layout Tree ===\n"; | |
| 30 dumpLayoutTreeAndCollectPropertyNodes(frameView, 0); | |
| 31 out << "\n=== Transform Tree ===\n"; | |
| 32 dumpTransformTree(nullptr, 0); | |
| 33 } | |
| 34 private: | |
| 35 void dumpLayoutTreeAndCollectPropertyNodes(const FrameView& frameView, int i ndent) | |
| 36 { | |
| 37 writeIndent(out, indent); | |
| 38 out << "FrameView " << frameView.frameRect() << " scroll={" << toFloatSi ze(frameView.scrollOffsetDouble()) << "}"; | |
| 39 if (frameView.preTranslation()) | |
| 40 out << " preTranslation=#" << collectTransformNode(*frameView.preTra nslation()); | |
| 41 if (frameView.scrollTranslation()) | |
| 42 out << " scrollTranslation=#" << collectTransformNode(*frameView.scr ollTranslation()); | |
| 43 out << "\n"; | |
| 44 if (frameView.layoutView()) | |
| 45 dumpLayoutTreeAndCollectPropertyNodes(*frameView.layoutView(), inden t + 1); | |
| 46 } | |
| 47 | |
| 48 void dumpLayoutTreeAndCollectPropertyNodes(const LayoutObject& object, int i ndent) | |
| 49 { | |
| 50 writeIndent(out, indent); | |
| 51 LayoutTreeAsText::writeLayoutObject(out, object, LayoutAsTextShowIDAndCl ass); | |
| 52 if (ObjectPaintProperties* properties = object.objectPaintProperties()) { | |
| 53 if (properties->preTranslation()) | |
| 54 out << " preTranslation=#" << collectTransformNode(*properties-> preTranslation()); | |
| 55 if (properties->transform()) | |
| 56 out << " transform=#" << collectTransformNode(*properties->trans form()); | |
| 57 if (properties->perspective()) | |
| 58 out << " perspective=#" << collectTransformNode(*properties->per spective()); | |
| 59 if (properties->scrollTranslation()) | |
| 60 out << " scrollTranslation=#" << collectTransformNode(*propertie s->scrollTranslation()); | |
| 61 } | |
| 62 out << "\n"; | |
| 63 for (const LayoutObject* child = object.slowFirstChild(); child; child = child->nextSibling()) | |
| 64 dumpLayoutTreeAndCollectPropertyNodes(*child, indent + 1); | |
| 65 } | |
| 66 | |
| 67 void dumpTransformTree(const TransformPaintPropertyNode* node, int indent) | |
| 68 { | |
| 69 writeIndent(out, indent); | |
| 70 size_t index = 0; | |
| 71 if (!node) { | |
| 72 out << "#0 Root"; | |
| 73 } else { | |
| 74 index = transformTreeNodeToIndex.get(node); | |
| 75 out << "#" << index << " "; | |
| 76 std::stringstream buf; | |
| 77 PrintTo(*node, &buf); | |
| 78 out << buf.str().c_str(); | |
| 79 } | |
| 80 out << "\n"; | |
| 81 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)
| |
| 82 dumpTransformTree(child, indent + 1); | |
| 83 } | |
| 84 | |
| 85 size_t collectTransformNode(const TransformPaintPropertyNode& node) | |
| 86 { | |
| 87 size_t index = transformTreeIndexToChildrenList.size(); | |
| 88 transformTreeIndexToChildrenList.append(ChildrenList()); | |
| 89 ASSERT(!transformTreeNodeToIndex.contains(&node)); | |
| 90 transformTreeNodeToIndex.set(&node, index); | |
| 91 | |
| 92 size_t parent = 0; | |
| 93 if (node.parent()) { | |
| 94 ASSERT(transformTreeNodeToIndex.contains(node.parent())); | |
| 95 parent = transformTreeNodeToIndex.get(node.parent()); | |
| 96 } | |
| 97 transformTreeIndexToChildrenList[parent].append(&node); | |
| 98 | |
| 99 return index; | |
| 100 } | |
| 101 typedef Vector<const TransformPaintPropertyNode*> ChildrenList; | |
| 102 Vector<ChildrenList> transformTreeIndexToChildrenList; | |
| 103 HashMap<const TransformPaintPropertyNode*, size_t> transformTreeNodeToIndex; | |
| 104 | |
| 105 TextStream& out; | |
| 106 }; | |
| 107 | |
| 108 class PaintPropertyTreeBuilderTest : public RenderingTest { | |
| 109 public: | |
| 110 PaintPropertyTreeBuilderTest() | |
| 111 : m_originalSlimmingPaintV2Enabled(RuntimeEnabledFeatures::slimmingPaint V2Enabled()) { } | |
| 112 | |
| 113 void runTest(const char* fileName) | |
| 114 { | |
| 115 std::string fullPath(Platform::current()->unitTestSupport()->webKitRootD ir().utf8().data()); | |
| 116 fullPath.append("/Source/core/paint/paint_property_tree_builder_tests/") ; | |
| 117 fullPath.append(fileName); | |
| 118 WebData inputBuffer = Platform::current()->unitTestSupport()->readFromFi le(WebString::fromUTF8(fullPath.c_str())); | |
| 119 std::string inputData(inputBuffer.data(), inputBuffer.size()); | |
| 120 setBodyInnerHTML(inputData.c_str()); | |
| 121 | |
| 122 TextStream outputBuffer; | |
| 123 DumpContext(outputBuffer).dumpLayoutTreeAndPropertyTrees(*document().vie w()); | |
| 124 | |
| 125 std::string expectationFullPath(fullPath); | |
| 126 expectationFullPath.append("-expected.txt"); | |
| 127 WebData expectationBuffer = Platform::current()->unitTestSupport()->read FromFile(WebString::fromUTF8(expectationFullPath.c_str())); | |
| 128 std::string expectationData(expectationBuffer.data(), expectationBuffer. size()); | |
| 129 EXPECT_STREQ(expectationData.c_str(), outputBuffer.release().utf8().data ()); | |
| 130 } | |
| 131 | |
| 132 private: | |
| 133 void SetUp() override | |
| 134 { | |
| 135 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); | |
| 136 Settings::setMockScrollbarsEnabled(true); | |
| 137 | |
| 138 RenderingTest::SetUp(); | |
| 139 enableCompositing(); | |
| 140 } | |
| 141 | |
| 142 void TearDown() override | |
| 143 { | |
| 144 RenderingTest::TearDown(); | |
| 145 | |
| 146 Settings::setMockScrollbarsEnabled(false); | |
| 147 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(m_originalSlimmingPain tV2Enabled); | |
| 148 } | |
| 149 | |
| 150 bool m_originalSlimmingPaintV2Enabled; | |
| 151 }; | |
| 152 | |
| 153 TEST_F(PaintPropertyTreeBuilderTest, FixedPosition) | |
| 154 { | |
| 155 runTest("fixed-position.html"); | |
| 156 } | |
| 157 | |
| 158 } // namespace blink | |
| OLD | NEW |