Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / testing / CoreTestPrinters.cpp
blob9d2f50627fb3140fdd0a8c829d6924899215e91a
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.
5 #include "config.h"
7 #include "core/dom/Document.h"
8 #include "core/dom/Range.h"
9 #include "core/dom/Text.h"
10 #include "core/html/HTMLElement.h"
11 #include "wtf/text/StringBuilder.h"
12 #include <ios>
13 #include <ostream> // NOLINT
15 namespace blink {
17 namespace {
19 // Copied from "dom/Node.cpp".
20 void appendAttributeDesc(const Node& node, StringBuilder& stringBuilder, const QualifiedName& name, const char* attrDesc)
22 if (!node.isElementNode())
23 return;
25 String attr = toElement(node).getAttribute(name);
26 if (attr.isEmpty())
27 return;
29 stringBuilder.append(attrDesc);
30 stringBuilder.appendLiteral("=\"");
31 stringBuilder.append(attr);
32 stringBuilder.appendLiteral("\"");
35 template <typename PositionType>
36 std::ostream& printPosition(std::ostream& ostream, const PositionType& position)
38 if (position.isNull())
39 return ostream << "null";
40 ostream << position.anchorNode() << "@";
41 if (position.isOffsetInAnchor())
42 return ostream << position.offsetInContainerNode();
43 return ostream << position.anchorType();
46 } // namespace
48 std::ostream& operator<<(std::ostream& ostream, PositionAnchorType anchorType)
50 switch (anchorType) {
51 case PositionAnchorType::AfterAnchor:
52 return ostream << "afterAnchor";
53 case PositionAnchorType::AfterChildren:
54 return ostream << "afterChildren";
55 case PositionAnchorType::BeforeAnchor:
56 return ostream << "beforeAnchor";
57 case PositionAnchorType::BeforeChildren:
58 return ostream << "beforeChildren";
59 case PositionAnchorType::OffsetInAnchor:
60 return ostream << "offsetInAnchor";
62 ASSERT_NOT_REACHED();
63 return ostream << "anchorType=" << static_cast<int>(anchorType);
66 // |std::ostream| version of |Node::showNode|
67 std::ostream& operator<<(std::ostream& ostream, const Node& node)
69 ostream << node.nodeName().utf8().data();
70 if (node.isTextNode())
71 return ostream << " " << node.nodeValue();
72 StringBuilder attrs;
73 appendAttributeDesc(node, attrs, HTMLNames::idAttr, " ID");
74 appendAttributeDesc(node, attrs, HTMLNames::classAttr, " CLASS");
75 appendAttributeDesc(node, attrs, HTMLNames::styleAttr, " STYLE");
76 return ostream << attrs.toString().utf8().data();
79 std::ostream& operator<<(std::ostream& ostream, const Node* node)
81 if (!node)
82 return ostream << "null";
83 return ostream << *node;
86 std::ostream& operator<<(std::ostream& ostream, const Position& position)
88 return printPosition(ostream, position);
91 std::ostream& operator<<(std::ostream& ostream, const PositionInComposedTree& position)
93 return printPosition(ostream, position);
96 } // namespace blink