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

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

Issue 2725603002: createFragmentFromMarkupWithContext() should use EphemeralRange. (Closed)
Patch Set: Y Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/EphemeralRange.h" 5 #include "core/editing/EphemeralRange.h"
6 6
7 #include "core/dom/Range.h" 7 #include "core/dom/Range.h"
8 #include "core/editing/EditingTestBase.h" 8 #include "core/editing/EditingTestBase.h"
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Tree iterators have only |operator !=| ATM. 141 // Tree iterators have only |operator !=| ATM.
142 EXPECT_FALSE(iterable.begin() != iterable.end()); 142 EXPECT_FALSE(iterable.begin() != iterable.end());
143 143
144 const EphemeralRange singlePositionRange(getBodyRange()->startPosition()); 144 const EphemeralRange singlePositionRange(getBodyRange()->startPosition());
145 EXPECT_FALSE(singlePositionRange.isNull()); 145 EXPECT_FALSE(singlePositionRange.isNull());
146 EXPECT_EQ(std::string(), traverseRange(singlePositionRange)); 146 EXPECT_EQ(std::string(), traverseRange(singlePositionRange));
147 EXPECT_EQ(singlePositionRange.startPosition().nodeAsRangeFirstNode(), 147 EXPECT_EQ(singlePositionRange.startPosition().nodeAsRangeFirstNode(),
148 singlePositionRange.endPosition().nodeAsRangePastLastNode()); 148 singlePositionRange.endPosition().nodeAsRangePastLastNode());
149 } 149 }
150 150
151 TEST_F(EphemeralRangeTest, commonAncesstorDOM) {
152 const char* bodyContent =
153 "<p id='host'>00<b id='one'>11</b><b id='two'>22</b><b "
154 "id='three'>33</b></p>";
155 setBodyContent(bodyContent);
156
157 Range* range = getBodyRange();
Xiaocheng 2017/03/05 06:31:19 There's no need to create an EphemeralRange from R
tanvir 2017/03/06 07:05:11 Done.
158 range->setStart(document().getElementById("one"), 0,
159 IGNORE_EXCEPTION_FOR_TESTING);
160 range->setEnd(document().getElementById("two"), 0,
161 IGNORE_EXCEPTION_FOR_TESTING);
162
163 const EphemeralRange ephemeralRange(range->startPosition(),
164 range->endPosition());
165 const Node* commonAncestor = document().getElementById("host");
166 EXPECT_EQ(commonAncestor, ephemeralRange.commonAncestorContainer());
167 }
168
169 TEST_F(EphemeralRangeTest, commonAncesstorFlatTree) {
170 const char* bodyContent =
171 "<b id=zero>0</b><p id=host><b id=one>1</b><b id=two>22</b></p><b "
172 "id=three>333</b>";
173 const char* shadowContent =
174 "<p id=four>4444</p><content select=#two></content><content "
175 "select=#one></content><p id=five>55555</p>";
176 setBodyContent(bodyContent);
177 setShadowContent(shadowContent, "host");
Xiaocheng 2017/03/05 06:31:19 Do instead: ... ShadowRoot* shadowRoot = setShado
tanvir 2017/03/06 07:05:11 Done the changes!! Thanks for the explanation.
178
179 Range* range = getBodyRange();
180 range->setStart(document().getElementById("one"), 0,
181 IGNORE_EXCEPTION_FOR_TESTING);
182 range->setEnd(document().getElementById("five"), 0,
183 IGNORE_EXCEPTION_FOR_TESTING);
184
185 const EphemeralRangeInFlatTree ephemeralRange(
186 toPositionInFlatTree(range->startPosition()),
187 toPositionInFlatTree(range->endPosition()));
188 EXPECT_EQ(document().documentElement(),
189 ephemeralRange.commonAncestorContainer());
190 }
191
151 } // namespace blink 192 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698