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

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

Issue 2432383002: Get rid of flat tree version of createVisibleSelection() taking two PositionInFlatTree (Closed)
Patch Set: 2016-10-20T15:59:37 Created 4 years, 2 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/VisibleSelection.cpp ('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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/VisibleSelection.h" 5 #include "core/editing/VisibleSelection.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 "core/editing/SelectionAdjuster.h" 9 #include "core/editing/SelectionAdjuster.h"
10 10
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); 208 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host");
209 209
210 Element* body = document().body(); 210 Element* body = document().body();
211 Element* host = body->querySelector("#host"); 211 Element* host = body->querySelector("#host");
212 Element* one = body->querySelector("#one"); 212 Element* one = body->querySelector("#one");
213 Element* six = shadowRoot->querySelector("#s6"); 213 Element* six = shadowRoot->querySelector("#s6");
214 214
215 VisibleSelection selection = 215 VisibleSelection selection =
216 createVisibleSelection(Position::firstPositionInNode(one), 216 createVisibleSelection(Position::firstPositionInNode(one),
217 Position::lastPositionInNode(shadowRoot)); 217 Position::lastPositionInNode(shadowRoot));
218 VisibleSelectionInFlatTree selectionInFlatTree = 218 VisibleSelectionInFlatTree selectionInFlatTree = createVisibleSelection(
219 createVisibleSelection(PositionInFlatTree::firstPositionInNode(one), 219 SelectionInFlatTree::Builder()
220 PositionInFlatTree::lastPositionInNode(host)); 220 .collapse(PositionInFlatTree::firstPositionInNode(one))
221 .extend(PositionInFlatTree::lastPositionInNode(host))
222 .build());
221 223
222 EXPECT_EQ(Position(host, PositionAnchorType::BeforeAnchor), 224 EXPECT_EQ(Position(host, PositionAnchorType::BeforeAnchor),
223 selection.start()); 225 selection.start());
224 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); 226 EXPECT_EQ(Position(one->firstChild(), 0), selection.end());
225 EXPECT_EQ(PositionInFlatTree(one->firstChild(), 0), 227 EXPECT_EQ(PositionInFlatTree(one->firstChild(), 0),
226 selectionInFlatTree.start()); 228 selectionInFlatTree.start());
227 EXPECT_EQ(PositionInFlatTree(six->firstChild(), 2), 229 EXPECT_EQ(PositionInFlatTree(six->firstChild(), 2),
228 selectionInFlatTree.end()); 230 selectionInFlatTree.end());
229 } 231 }
230 232
231 TEST_F(VisibleSelectionTest, ShadowV0DistributedNodes) { 233 TEST_F(VisibleSelectionTest, ShadowV0DistributedNodes) {
232 const char* bodyContent = 234 const char* bodyContent =
233 "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>"; 235 "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>";
234 const char* shadowContent = 236 const char* shadowContent =
235 "<a><span id='s4'>44</span><content select=#two></content><span " 237 "<a><span id='s4'>44</span><content select=#two></content><span "
236 "id='s5'>55</span><content select=#one></content><span " 238 "id='s5'>55</span><content select=#one></content><span "
237 "id='s6'>66</span></a>"; 239 "id='s6'>66</span></a>";
238 setBodyContent(bodyContent); 240 setBodyContent(bodyContent);
239 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); 241 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host");
240 242
241 Element* body = document().body(); 243 Element* body = document().body();
242 Element* one = body->querySelector("#one"); 244 Element* one = body->querySelector("#one");
243 Element* two = body->querySelector("#two"); 245 Element* two = body->querySelector("#two");
244 Element* five = shadowRoot->querySelector("#s5"); 246 Element* five = shadowRoot->querySelector("#s5");
245 247
246 VisibleSelection selection = createVisibleSelection( 248 VisibleSelection selection = createVisibleSelection(
247 Position::firstPositionInNode(one), Position::lastPositionInNode(two)); 249 Position::firstPositionInNode(one), Position::lastPositionInNode(two));
248 VisibleSelectionInFlatTree selectionInFlatTree = 250 VisibleSelectionInFlatTree selectionInFlatTree = createVisibleSelection(
249 createVisibleSelection(PositionInFlatTree::firstPositionInNode(one), 251 SelectionInFlatTree::Builder()
250 PositionInFlatTree::lastPositionInNode(two)); 252 .collapse(PositionInFlatTree::firstPositionInNode(one))
253 .extend(PositionInFlatTree::lastPositionInNode(two))
254 .build());
251 255
252 EXPECT_EQ(Position(one->firstChild(), 0), selection.start()); 256 EXPECT_EQ(Position(one->firstChild(), 0), selection.start());
253 EXPECT_EQ(Position(two->firstChild(), 2), selection.end()); 257 EXPECT_EQ(Position(two->firstChild(), 2), selection.end());
254 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 0), 258 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 0),
255 selectionInFlatTree.start()); 259 selectionInFlatTree.start());
256 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 2), 260 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 2),
257 selectionInFlatTree.end()); 261 selectionInFlatTree.end());
258 } 262 }
259 263
260 TEST_F(VisibleSelectionTest, ShadowNested) { 264 TEST_F(VisibleSelectionTest, ShadowNested) {
(...skipping 19 matching lines...) Expand all
280 // <span id="s6">66</span> 284 // <span id="s6">66</span>
281 // </p> 285 // </p>
282 Element* body = document().body(); 286 Element* body = document().body();
283 Element* host = body->querySelector("#host"); 287 Element* host = body->querySelector("#host");
284 Element* one = body->querySelector("#one"); 288 Element* one = body->querySelector("#one");
285 Element* eight = shadowRoot2->querySelector("#s8"); 289 Element* eight = shadowRoot2->querySelector("#s8");
286 290
287 VisibleSelection selection = 291 VisibleSelection selection =
288 createVisibleSelection(Position::firstPositionInNode(one), 292 createVisibleSelection(Position::firstPositionInNode(one),
289 Position::lastPositionInNode(shadowRoot2)); 293 Position::lastPositionInNode(shadowRoot2));
290 VisibleSelectionInFlatTree selectionInFlatTree = 294 VisibleSelectionInFlatTree selectionInFlatTree = createVisibleSelection(
291 createVisibleSelection(PositionInFlatTree::firstPositionInNode(one), 295 SelectionInFlatTree::Builder()
292 PositionInFlatTree::afterNode(eight)); 296 .collapse(PositionInFlatTree::firstPositionInNode(one))
297 .extend(PositionInFlatTree::afterNode(eight))
298 .build());
293 299
294 EXPECT_EQ(Position(host, PositionAnchorType::BeforeAnchor), 300 EXPECT_EQ(Position(host, PositionAnchorType::BeforeAnchor),
295 selection.start()); 301 selection.start());
296 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); 302 EXPECT_EQ(Position(one->firstChild(), 0), selection.end());
297 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), 303 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2),
298 selectionInFlatTree.start()); 304 selectionInFlatTree.start());
299 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), 305 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2),
300 selectionInFlatTree.end()); 306 selectionInFlatTree.end());
301 } 307 }
302 308
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 selection.updateIfNeeded(); 443 selection.updateIfNeeded();
438 EXPECT_EQ(Position(sample->firstChild(), 0), selection.start()); 444 EXPECT_EQ(Position(sample->firstChild(), 0), selection.start());
439 445
440 VisibleSelectionInFlatTree selectionInFlatTree; 446 VisibleSelectionInFlatTree selectionInFlatTree;
441 SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection); 447 SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection);
442 EXPECT_EQ(PositionInFlatTree(sample->firstChild(), 0), 448 EXPECT_EQ(PositionInFlatTree(sample->firstChild(), 0),
443 selectionInFlatTree.start()); 449 selectionInFlatTree.start());
444 } 450 }
445 451
446 } // namespace blink 452 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/VisibleSelection.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698