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

Side by Side Diff: third_party/WebKit/Source/core/editing/PositionTest.cpp

Issue 1675163002: Rename ComposedTree to FlatTree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wip Created 4 years, 10 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/editing/Position.h" 5 #include "core/editing/Position.h"
6 6
7 #include "core/editing/EditingTestBase.h" 7 #include "core/editing/EditingTestBase.h"
8 8
9 namespace blink { 9 namespace blink {
10 10
11 class PositionTest : public EditingTestBase { 11 class PositionTest : public EditingTestBase {
12 }; 12 };
13 13
14 TEST_F(PositionTest, NodeAsRangeLastNodeNull) 14 TEST_F(PositionTest, NodeAsRangeLastNodeNull)
15 { 15 {
16 EXPECT_EQ(nullptr, Position().nodeAsRangeLastNode()); 16 EXPECT_EQ(nullptr, Position().nodeAsRangeLastNode());
17 EXPECT_EQ(nullptr, PositionInComposedTree().nodeAsRangeLastNode()); 17 EXPECT_EQ(nullptr, PositionInFlatTree().nodeAsRangeLastNode());
18 } 18 }
19 19
20 TEST_F(PositionTest, editingPositionOfWithEditingIgnoresContent) 20 TEST_F(PositionTest, editingPositionOfWithEditingIgnoresContent)
21 { 21 {
22 const char* bodyContent = "<textarea id=textarea></textarea><a id=child1>1</ a><b id=child2>2</b>"; 22 const char* bodyContent = "<textarea id=textarea></textarea><a id=child1>1</ a><b id=child2>2</b>";
23 setBodyContent(bodyContent); 23 setBodyContent(bodyContent);
24 Node* textarea = document().getElementById("textarea"); 24 Node* textarea = document().getElementById("textarea");
25 25
26 EXPECT_EQ(Position::beforeNode(textarea), Position::editingPositionOf(textar ea, 0)); 26 EXPECT_EQ(Position::beforeNode(textarea), Position::editingPositionOf(textar ea, 0));
27 EXPECT_EQ(Position::afterNode(textarea), Position::editingPositionOf(textare a, 1)); 27 EXPECT_EQ(Position::afterNode(textarea), Position::editingPositionOf(textare a, 1));
(...skipping 24 matching lines...) Expand all
52 Node* t3 = EditingStrategy::firstChild(*p3); 52 Node* t3 = EditingStrategy::firstChild(*p3);
53 53
54 EXPECT_EQ(body, Position::inParentBeforeNode(*p1).nodeAsRangeLastNode()); 54 EXPECT_EQ(body, Position::inParentBeforeNode(*p1).nodeAsRangeLastNode());
55 EXPECT_EQ(t1, Position::inParentBeforeNode(*p2).nodeAsRangeLastNode()); 55 EXPECT_EQ(t1, Position::inParentBeforeNode(*p2).nodeAsRangeLastNode());
56 EXPECT_EQ(p2, Position::inParentBeforeNode(*p3).nodeAsRangeLastNode()); 56 EXPECT_EQ(p2, Position::inParentBeforeNode(*p3).nodeAsRangeLastNode());
57 EXPECT_EQ(t1, Position::inParentAfterNode(*p1).nodeAsRangeLastNode()); 57 EXPECT_EQ(t1, Position::inParentAfterNode(*p1).nodeAsRangeLastNode());
58 EXPECT_EQ(p2, Position::inParentAfterNode(*p2).nodeAsRangeLastNode()); 58 EXPECT_EQ(p2, Position::inParentAfterNode(*p2).nodeAsRangeLastNode());
59 EXPECT_EQ(t3, Position::inParentAfterNode(*p3).nodeAsRangeLastNode()); 59 EXPECT_EQ(t3, Position::inParentAfterNode(*p3).nodeAsRangeLastNode());
60 EXPECT_EQ(t3, Position::afterNode(p3).nodeAsRangeLastNode()); 60 EXPECT_EQ(t3, Position::afterNode(p3).nodeAsRangeLastNode());
61 61
62 EXPECT_EQ(body, PositionInComposedTree::inParentBeforeNode(*p1).nodeAsRangeL astNode()); 62 EXPECT_EQ(body, PositionInFlatTree::inParentBeforeNode(*p1).nodeAsRangeLastN ode());
63 EXPECT_EQ(t1, PositionInComposedTree::inParentBeforeNode(*p2).nodeAsRangeLas tNode()); 63 EXPECT_EQ(t1, PositionInFlatTree::inParentBeforeNode(*p2).nodeAsRangeLastNod e());
64 EXPECT_EQ(p2, PositionInComposedTree::inParentBeforeNode(*p3).nodeAsRangeLas tNode()); 64 EXPECT_EQ(p2, PositionInFlatTree::inParentBeforeNode(*p3).nodeAsRangeLastNod e());
65 EXPECT_EQ(t1, PositionInComposedTree::inParentAfterNode(*p1).nodeAsRangeLast Node()); 65 EXPECT_EQ(t1, PositionInFlatTree::inParentAfterNode(*p1).nodeAsRangeLastNode ());
66 EXPECT_EQ(p2, PositionInComposedTree::inParentAfterNode(*p2).nodeAsRangeLast Node()); 66 EXPECT_EQ(p2, PositionInFlatTree::inParentAfterNode(*p2).nodeAsRangeLastNode ());
67 EXPECT_EQ(t3, PositionInComposedTree::inParentAfterNode(*p3).nodeAsRangeLast Node()); 67 EXPECT_EQ(t3, PositionInFlatTree::inParentAfterNode(*p3).nodeAsRangeLastNode ());
68 EXPECT_EQ(t3, PositionInComposedTree::afterNode(p3).nodeAsRangeLastNode()); 68 EXPECT_EQ(t3, PositionInFlatTree::afterNode(p3).nodeAsRangeLastNode());
69 } 69 }
70 70
71 TEST_F(PositionTest, NodeAsRangeLastNodeShadow) 71 TEST_F(PositionTest, NodeAsRangeLastNodeShadow)
72 { 72 {
73 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</ b>33</p>"; 73 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</ b>33</p>";
74 const char* shadowContent = "<a id='a'><content select=#two></content><conte nt select=#one></content></a>"; 74 const char* shadowContent = "<a id='a'><content select=#two></content><conte nt select=#one></content></a>";
75 setBodyContent(bodyContent); 75 setBodyContent(bodyContent);
76 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); 76 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host");
77 77
78 Node* host = document().getElementById("host"); 78 Node* host = document().getElementById("host");
79 Node* n1 = document().getElementById("one"); 79 Node* n1 = document().getElementById("one");
80 Node* n2 = document().getElementById("two"); 80 Node* n2 = document().getElementById("two");
81 Node* t0 = EditingStrategy::firstChild(*host); 81 Node* t0 = EditingStrategy::firstChild(*host);
82 Node* t1 = EditingStrategy::firstChild(*n1); 82 Node* t1 = EditingStrategy::firstChild(*n1);
83 Node* t2 = EditingStrategy::firstChild(*n2); 83 Node* t2 = EditingStrategy::firstChild(*n2);
84 Node* t3 = EditingStrategy::lastChild(*host); 84 Node* t3 = EditingStrategy::lastChild(*host);
85 Node* a = shadowRoot->getElementById("a"); 85 Node* a = shadowRoot->getElementById("a");
86 86
87 EXPECT_EQ(t0, Position::inParentBeforeNode(*n1).nodeAsRangeLastNode()); 87 EXPECT_EQ(t0, Position::inParentBeforeNode(*n1).nodeAsRangeLastNode());
88 EXPECT_EQ(t1, Position::inParentBeforeNode(*n2).nodeAsRangeLastNode()); 88 EXPECT_EQ(t1, Position::inParentBeforeNode(*n2).nodeAsRangeLastNode());
89 EXPECT_EQ(t1, Position::inParentAfterNode(*n1).nodeAsRangeLastNode()); 89 EXPECT_EQ(t1, Position::inParentAfterNode(*n1).nodeAsRangeLastNode());
90 EXPECT_EQ(t2, Position::inParentAfterNode(*n2).nodeAsRangeLastNode()); 90 EXPECT_EQ(t2, Position::inParentAfterNode(*n2).nodeAsRangeLastNode());
91 EXPECT_EQ(t3, Position::afterNode(host).nodeAsRangeLastNode()); 91 EXPECT_EQ(t3, Position::afterNode(host).nodeAsRangeLastNode());
92 92
93 EXPECT_EQ(t2, PositionInComposedTree::inParentBeforeNode(*n1).nodeAsRangeLas tNode()); 93 EXPECT_EQ(t2, PositionInFlatTree::inParentBeforeNode(*n1).nodeAsRangeLastNod e());
94 EXPECT_EQ(a, PositionInComposedTree::inParentBeforeNode(*n2).nodeAsRangeLast Node()); 94 EXPECT_EQ(a, PositionInFlatTree::inParentBeforeNode(*n2).nodeAsRangeLastNode ());
95 EXPECT_EQ(t1, PositionInComposedTree::inParentAfterNode(*n1).nodeAsRangeLast Node()); 95 EXPECT_EQ(t1, PositionInFlatTree::inParentAfterNode(*n1).nodeAsRangeLastNode ());
96 EXPECT_EQ(t2, PositionInComposedTree::inParentAfterNode(*n2).nodeAsRangeLast Node()); 96 EXPECT_EQ(t2, PositionInFlatTree::inParentAfterNode(*n2).nodeAsRangeLastNode ());
97 EXPECT_EQ(t1, PositionInComposedTree::afterNode(host).nodeAsRangeLastNode()) ; 97 EXPECT_EQ(t1, PositionInFlatTree::afterNode(host).nodeAsRangeLastNode());
98 } 98 }
99 99
100 TEST_F(PositionTest, ToPositionInComposedTreeWithActiveInsertionPoint) 100 TEST_F(PositionTest, ToPositionInFlatTreeWithActiveInsertionPoint)
101 { 101 {
102 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; 102 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>";
103 const char* shadowContent = "<a id='a'><content select=#one id='content'></c ontent><content></content></a>"; 103 const char* shadowContent = "<a id='a'><content select=#one id='content'></c ontent><content></content></a>";
104 setBodyContent(bodyContent); 104 setBodyContent(bodyContent);
105 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); 105 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host");
106 RefPtrWillBeRawPtr<Element> anchor = shadowRoot->getElementById("a"); 106 RefPtrWillBeRawPtr<Element> anchor = shadowRoot->getElementById("a");
107 107
108 EXPECT_EQ(PositionInComposedTree(anchor.get(), 0), toPositionInComposedTree( Position(anchor.get(), 0))); 108 EXPECT_EQ(PositionInFlatTree(anchor.get(), 0), toPositionInFlatTree(Position (anchor.get(), 0)));
109 EXPECT_EQ(PositionInComposedTree(anchor.get(), 1), toPositionInComposedTree( Position(anchor.get(), 1))); 109 EXPECT_EQ(PositionInFlatTree(anchor.get(), 1), toPositionInFlatTree(Position (anchor.get(), 1)));
110 EXPECT_EQ(PositionInComposedTree(anchor, PositionAnchorType::AfterChildren), toPositionInComposedTree(Position(anchor.get(), 2))); 110 EXPECT_EQ(PositionInFlatTree(anchor, PositionAnchorType::AfterChildren), toP ositionInFlatTree(Position(anchor.get(), 2)));
111 } 111 }
112 112
113 TEST_F(PositionTest, ToPositionInComposedTreeWithInactiveInsertionPoint) 113 TEST_F(PositionTest, ToPositionInFlatTreeWithInactiveInsertionPoint)
114 { 114 {
115 const char* bodyContent = "<p id='p'><content></content></p>"; 115 const char* bodyContent = "<p id='p'><content></content></p>";
116 setBodyContent(bodyContent); 116 setBodyContent(bodyContent);
117 RefPtrWillBeRawPtr<Element> anchor = document().getElementById("p"); 117 RefPtrWillBeRawPtr<Element> anchor = document().getElementById("p");
118 118
119 EXPECT_EQ(PositionInComposedTree(anchor.get(), 0), toPositionInComposedTree( Position(anchor.get(), 0))); 119 EXPECT_EQ(PositionInFlatTree(anchor.get(), 0), toPositionInFlatTree(Position (anchor.get(), 0)));
120 EXPECT_EQ(PositionInComposedTree(anchor, PositionAnchorType::AfterChildren), toPositionInComposedTree(Position(anchor.get(), 1))); 120 EXPECT_EQ(PositionInFlatTree(anchor, PositionAnchorType::AfterChildren), toP ositionInFlatTree(Position(anchor.get(), 1)));
121 } 121 }
122 122
123 // This test comes from "editing/style/block-style-progress-crash.html". 123 // This test comes from "editing/style/block-style-progress-crash.html".
124 TEST_F(PositionTest, ToPositionInComposedTreeWithNotDistributed) 124 TEST_F(PositionTest, ToPositionInFlatTreeWithNotDistributed)
125 { 125 {
126 setBodyContent("<progress id=sample>foo</progress>"); 126 setBodyContent("<progress id=sample>foo</progress>");
127 Element* sample = document().getElementById("sample"); 127 Element* sample = document().getElementById("sample");
128 128
129 EXPECT_EQ(PositionInComposedTree(sample, PositionAnchorType::AfterChildren), toPositionInComposedTree(Position(sample, 0))); 129 EXPECT_EQ(PositionInFlatTree(sample, PositionAnchorType::AfterChildren), toP ositionInFlatTree(Position(sample, 0)));
130 } 130 }
131 131
132 TEST_F(PositionTest, ToPositionInComposedTreeWithShadowRoot) 132 TEST_F(PositionTest, ToPositionInFlatTreeWithShadowRoot)
133 { 133 {
134 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; 134 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>";
135 const char* shadowContent = "<a><content select=#one></content></a>"; 135 const char* shadowContent = "<a><content select=#one></content></a>";
136 setBodyContent(bodyContent); 136 setBodyContent(bodyContent);
137 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); 137 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host");
138 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); 138 RefPtrWillBeRawPtr<Element> host = document().getElementById("host");
139 139
140 EXPECT_EQ(PositionInComposedTree(host.get(), 0), toPositionInComposedTree(Po sition(shadowRoot.get(), 0))); 140 EXPECT_EQ(PositionInFlatTree(host.get(), 0), toPositionInFlatTree(Position(s hadowRoot.get(), 0)));
141 EXPECT_EQ(PositionInComposedTree(host.get(), PositionAnchorType::AfterChildr en), toPositionInComposedTree(Position(shadowRoot.get(), 1))); 141 EXPECT_EQ(PositionInFlatTree(host.get(), PositionAnchorType::AfterChildren), toPositionInFlatTree(Position(shadowRoot.get(), 1)));
142 } 142 }
143 143
144 TEST_F(PositionTest, ToPositionInComposedTreeWithShadowRootContainingSingleConte nt) 144 TEST_F(PositionTest, ToPositionInFlatTreeWithShadowRootContainingSingleContent)
145 { 145 {
146 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; 146 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>";
147 const char* shadowContent = "<content select=#one></content>"; 147 const char* shadowContent = "<content select=#one></content>";
148 setBodyContent(bodyContent); 148 setBodyContent(bodyContent);
149 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); 149 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host");
150 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); 150 RefPtrWillBeRawPtr<Element> host = document().getElementById("host");
151 151
152 EXPECT_EQ(PositionInComposedTree(host.get(), 0), toPositionInComposedTree(Po sition(shadowRoot.get(), 0))); 152 EXPECT_EQ(PositionInFlatTree(host.get(), 0), toPositionInFlatTree(Position(s hadowRoot.get(), 0)));
153 EXPECT_EQ(PositionInComposedTree(host.get(), PositionAnchorType::AfterChildr en), toPositionInComposedTree(Position(shadowRoot.get(), 1))); 153 EXPECT_EQ(PositionInFlatTree(host.get(), PositionAnchorType::AfterChildren), toPositionInFlatTree(Position(shadowRoot.get(), 1)));
154 } 154 }
155 155
156 TEST_F(PositionTest, ToPositionInComposedTreeWithEmptyShadowRoot) 156 TEST_F(PositionTest, ToPositionInFlatTreeWithEmptyShadowRoot)
157 { 157 {
158 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>"; 158 const char* bodyContent = "<p id='host'>00<b id='one'>11</b>22</p>";
159 const char* shadowContent = ""; 159 const char* shadowContent = "";
160 setBodyContent(bodyContent); 160 setBodyContent(bodyContent);
161 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); 161 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host");
162 RefPtrWillBeRawPtr<Element> host = document().getElementById("host"); 162 RefPtrWillBeRawPtr<Element> host = document().getElementById("host");
163 163
164 EXPECT_EQ(PositionInComposedTree(host, PositionAnchorType::AfterChildren), t oPositionInComposedTree(Position(shadowRoot.get(), 0))); 164 EXPECT_EQ(PositionInFlatTree(host, PositionAnchorType::AfterChildren), toPos itionInFlatTree(Position(shadowRoot.get(), 0)));
165 } 165 }
166 166
167 } // namespace blink 167 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698