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

Side by Side Diff: Source/core/testing/CoreTestHelpers.cpp

Issue 1055633004: Revert "Re-factor VisibleSelectionTest for adding tests for composed tree version" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/testing/CoreTestHelpers.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "core/testing/CoreTestHelpers.h"
7
8 #include "core/dom/Document.h"
9 #include "core/dom/Range.h"
10 #include "core/dom/Text.h"
11 #include "core/html/HTMLElement.h"
12 #include "wtf/text/StringBuilder.h"
13
14 namespace blink {
15
16 namespace {
17
18 // Copied from "dom/Node.cpp".
19 void appendAttributeDesc(const Node& node, StringBuilder& stringBuilder, const Q ualifiedName& name, const char* attrDesc)
20 {
21 if (!node.isElementNode())
22 return;
23
24 String attr = toElement(node).getAttribute(name);
25 if (attr.isEmpty())
26 return;
27
28 stringBuilder.append(attrDesc);
29 stringBuilder.appendLiteral("=\"");
30 stringBuilder.append(attr);
31 stringBuilder.appendLiteral("\"");
32 }
33
34 template <typename PositionType>
35 std::ostream& printPosition(std::ostream& ostream, const PositionType& position)
36 {
37 if (position.isNull())
38 return ostream << "null";
39 ostream << position.anchorNode() << "@";
40 if (position.anchorType() == PositionType::PositionIsOffsetInAnchor)
41 return ostream << position.offsetInContainerNode();
42 return ostream << static_cast<Position::AnchorType>(position.anchorType());
43 }
44
45 } // namespace
46
47 std::ostream& operator<<(std::ostream& ostream, Position::AnchorType anchorType)
48 {
49 switch (anchorType) {
50 case Position::PositionIsAfterAnchor:
51 return ostream << "afterAnchor";
52 case Position::PositionIsAfterChildren:
53 return ostream << "afterChildren";
54 case Position::PositionIsBeforeAnchor:
55 return ostream << "beforeAnchor";
56 case Position::PositionIsBeforeChildren:
57 return ostream << "beforeChildren";
58 case Position::PositionIsOffsetInAnchor:
59 return ostream << "offsetInAnchor";
60 default:
61 return ostream << "anchorType=" << static_cast<int>(anchorType);
62 }
63 }
64
65 // |std::ostream| version of |Node::showNode|
66 std::ostream& operator<<(std::ostream& ostream, const Node& node)
67 {
68 ostream << node.nodeName().utf8().data();
69 if (node.isTextNode())
70 return ostream << " " << node.nodeValue();
71 StringBuilder attrs;
72 appendAttributeDesc(node, attrs, HTMLNames::idAttr, " ID");
73 appendAttributeDesc(node, attrs, HTMLNames::classAttr, " CLASS");
74 appendAttributeDesc(node, attrs, HTMLNames::styleAttr, " STYLE");
75 return ostream << attrs.toString().utf8().data();
76 }
77
78 std::ostream& operator<<(std::ostream& ostream, const Node* node)
79 {
80 if (!node)
81 return ostream << "null";
82 return ostream << *node;
83 }
84
85 std::ostream& operator<<(std::ostream& ostream, const Position& position)
86 {
87 return printPosition(ostream, position);
88 }
89
90 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/testing/CoreTestHelpers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698