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

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

Issue 2962473002: Make Position::LastPositionInNode() to take const Node& instead of Node* (Closed)
Patch Set: 2017-06-26T14:00:00 Created 3 years, 5 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 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // For http://crbug.com/695317 247 // For http://crbug.com/695317
248 TEST_F(VisibleSelectionTest, SelectAllWithInputElement) { 248 TEST_F(VisibleSelectionTest, SelectAllWithInputElement) {
249 SetBodyContent("<input>123"); 249 SetBodyContent("<input>123");
250 Element* const html_element = GetDocument().documentElement(); 250 Element* const html_element = GetDocument().documentElement();
251 Element* const input = GetDocument().QuerySelector("input"); 251 Element* const input = GetDocument().QuerySelector("input");
252 Node* const last_child = GetDocument().body()->lastChild(); 252 Node* const last_child = GetDocument().body()->lastChild();
253 253
254 const VisibleSelection& visible_selectin_in_dom_tree = CreateVisibleSelection( 254 const VisibleSelection& visible_selectin_in_dom_tree = CreateVisibleSelection(
255 SelectionInDOMTree::Builder() 255 SelectionInDOMTree::Builder()
256 .Collapse(Position::FirstPositionInNode(*html_element)) 256 .Collapse(Position::FirstPositionInNode(*html_element))
257 .Extend(Position::LastPositionInNode(html_element)) 257 .Extend(Position::LastPositionInNode(*html_element))
258 .Build()); 258 .Build());
259 EXPECT_EQ(SelectionInDOMTree::Builder() 259 EXPECT_EQ(SelectionInDOMTree::Builder()
260 .Collapse(Position::BeforeNode(*input)) 260 .Collapse(Position::BeforeNode(*input))
261 .Extend(Position(last_child, 3)) 261 .Extend(Position(last_child, 3))
262 .Build(), 262 .Build(),
263 visible_selectin_in_dom_tree.AsSelection()); 263 visible_selectin_in_dom_tree.AsSelection());
264 264
265 const VisibleSelectionInFlatTree& visible_selectin_in_flat_tree = 265 const VisibleSelectionInFlatTree& visible_selectin_in_flat_tree =
266 CreateVisibleSelection( 266 CreateVisibleSelection(
267 SelectionInFlatTree::Builder() 267 SelectionInFlatTree::Builder()
268 .Collapse(PositionInFlatTree::FirstPositionInNode(*html_element)) 268 .Collapse(PositionInFlatTree::FirstPositionInNode(*html_element))
269 .Extend(PositionInFlatTree::LastPositionInNode(html_element)) 269 .Extend(PositionInFlatTree::LastPositionInNode(*html_element))
270 .Build()); 270 .Build());
271 EXPECT_EQ(SelectionInFlatTree::Builder() 271 EXPECT_EQ(SelectionInFlatTree::Builder()
272 .Collapse(PositionInFlatTree::BeforeNode(*input)) 272 .Collapse(PositionInFlatTree::BeforeNode(*input))
273 .Extend(PositionInFlatTree(last_child, 3)) 273 .Extend(PositionInFlatTree(last_child, 3))
274 .Build(), 274 .Build(),
275 visible_selectin_in_flat_tree.AsSelection()); 275 visible_selectin_in_flat_tree.AsSelection());
276 } 276 }
277 277
278 TEST_F(VisibleSelectionTest, ShadowCrossing) { 278 TEST_F(VisibleSelectionTest, ShadowCrossing) {
279 const char* body_content = 279 const char* body_content =
280 "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>"; 280 "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>";
281 const char* shadow_content = 281 const char* shadow_content =
282 "<a><span id='s4'>44</span><content select=#two></content><span " 282 "<a><span id='s4'>44</span><content select=#two></content><span "
283 "id='s5'>55</span><content select=#one></content><span " 283 "id='s5'>55</span><content select=#one></content><span "
284 "id='s6'>66</span></a>"; 284 "id='s6'>66</span></a>";
285 SetBodyContent(body_content); 285 SetBodyContent(body_content);
286 ShadowRoot* shadow_root = SetShadowContent(shadow_content, "host"); 286 ShadowRoot* shadow_root = SetShadowContent(shadow_content, "host");
287 287
288 Element* body = GetDocument().body(); 288 Element* body = GetDocument().body();
289 Element* host = body->QuerySelector("#host"); 289 Element* host = body->QuerySelector("#host");
290 Element* one = body->QuerySelector("#one"); 290 Element* one = body->QuerySelector("#one");
291 Element* six = shadow_root->QuerySelector("#s6"); 291 Element* six = shadow_root->QuerySelector("#s6");
292 292
293 VisibleSelection selection = CreateVisibleSelection( 293 VisibleSelection selection = CreateVisibleSelection(
294 SelectionInDOMTree::Builder() 294 SelectionInDOMTree::Builder()
295 .Collapse(Position::FirstPositionInNode(*one)) 295 .Collapse(Position::FirstPositionInNode(*one))
296 .Extend(Position::LastPositionInNode(shadow_root)) 296 .Extend(Position::LastPositionInNode(*shadow_root))
297 .Build()); 297 .Build());
298 VisibleSelectionInFlatTree selection_in_flat_tree = CreateVisibleSelection( 298 VisibleSelectionInFlatTree selection_in_flat_tree = CreateVisibleSelection(
299 SelectionInFlatTree::Builder() 299 SelectionInFlatTree::Builder()
300 .Collapse(PositionInFlatTree::FirstPositionInNode(*one)) 300 .Collapse(PositionInFlatTree::FirstPositionInNode(*one))
301 .Extend(PositionInFlatTree::LastPositionInNode(host)) 301 .Extend(PositionInFlatTree::LastPositionInNode(*host))
302 .Build()); 302 .Build());
303 303
304 EXPECT_EQ(Position(host, PositionAnchorType::kBeforeAnchor), 304 EXPECT_EQ(Position(host, PositionAnchorType::kBeforeAnchor),
305 selection.Start()); 305 selection.Start());
306 EXPECT_EQ(Position(one->firstChild(), 0), selection.End()); 306 EXPECT_EQ(Position(one->firstChild(), 0), selection.End());
307 EXPECT_EQ(PositionInFlatTree(one->firstChild(), 0), 307 EXPECT_EQ(PositionInFlatTree(one->firstChild(), 0),
308 selection_in_flat_tree.Start()); 308 selection_in_flat_tree.Start());
309 EXPECT_EQ(PositionInFlatTree(six->firstChild(), 2), 309 EXPECT_EQ(PositionInFlatTree(six->firstChild(), 2),
310 selection_in_flat_tree.End()); 310 selection_in_flat_tree.End());
311 } 311 }
312 312
313 TEST_F(VisibleSelectionTest, ShadowV0DistributedNodes) { 313 TEST_F(VisibleSelectionTest, ShadowV0DistributedNodes) {
314 const char* body_content = 314 const char* body_content =
315 "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>"; 315 "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>";
316 const char* shadow_content = 316 const char* shadow_content =
317 "<a><span id='s4'>44</span><content select=#two></content><span " 317 "<a><span id='s4'>44</span><content select=#two></content><span "
318 "id='s5'>55</span><content select=#one></content><span " 318 "id='s5'>55</span><content select=#one></content><span "
319 "id='s6'>66</span></a>"; 319 "id='s6'>66</span></a>";
320 SetBodyContent(body_content); 320 SetBodyContent(body_content);
321 ShadowRoot* shadow_root = SetShadowContent(shadow_content, "host"); 321 ShadowRoot* shadow_root = SetShadowContent(shadow_content, "host");
322 322
323 Element* body = GetDocument().body(); 323 Element* body = GetDocument().body();
324 Element* one = body->QuerySelector("#one"); 324 Element* one = body->QuerySelector("#one");
325 Element* two = body->QuerySelector("#two"); 325 Element* two = body->QuerySelector("#two");
326 Element* five = shadow_root->QuerySelector("#s5"); 326 Element* five = shadow_root->QuerySelector("#s5");
327 327
328 VisibleSelection selection = 328 VisibleSelection selection =
329 CreateVisibleSelection(SelectionInDOMTree::Builder() 329 CreateVisibleSelection(SelectionInDOMTree::Builder()
330 .Collapse(Position::FirstPositionInNode(*one)) 330 .Collapse(Position::FirstPositionInNode(*one))
331 .Extend(Position::LastPositionInNode(two)) 331 .Extend(Position::LastPositionInNode(*two))
332 .Build()); 332 .Build());
333 VisibleSelectionInFlatTree selection_in_flat_tree = CreateVisibleSelection( 333 VisibleSelectionInFlatTree selection_in_flat_tree = CreateVisibleSelection(
334 SelectionInFlatTree::Builder() 334 SelectionInFlatTree::Builder()
335 .Collapse(PositionInFlatTree::FirstPositionInNode(*one)) 335 .Collapse(PositionInFlatTree::FirstPositionInNode(*one))
336 .Extend(PositionInFlatTree::LastPositionInNode(two)) 336 .Extend(PositionInFlatTree::LastPositionInNode(*two))
337 .Build()); 337 .Build());
338 338
339 EXPECT_EQ(Position(one->firstChild(), 0), selection.Start()); 339 EXPECT_EQ(Position(one->firstChild(), 0), selection.Start());
340 EXPECT_EQ(Position(two->firstChild(), 2), selection.End()); 340 EXPECT_EQ(Position(two->firstChild(), 2), selection.End());
341 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 0), 341 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 0),
342 selection_in_flat_tree.Start()); 342 selection_in_flat_tree.Start());
343 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 2), 343 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 2),
344 selection_in_flat_tree.End()); 344 selection_in_flat_tree.End());
345 } 345 }
346 346
(...skipping 20 matching lines...) Expand all
367 // <span id="s6">66</span> 367 // <span id="s6">66</span>
368 // </p> 368 // </p>
369 Element* body = GetDocument().body(); 369 Element* body = GetDocument().body();
370 Element* host = body->QuerySelector("#host"); 370 Element* host = body->QuerySelector("#host");
371 Element* one = body->QuerySelector("#one"); 371 Element* one = body->QuerySelector("#one");
372 Element* eight = shadow_root2->QuerySelector("#s8"); 372 Element* eight = shadow_root2->QuerySelector("#s8");
373 373
374 VisibleSelection selection = CreateVisibleSelection( 374 VisibleSelection selection = CreateVisibleSelection(
375 SelectionInDOMTree::Builder() 375 SelectionInDOMTree::Builder()
376 .Collapse(Position::FirstPositionInNode(*one)) 376 .Collapse(Position::FirstPositionInNode(*one))
377 .Extend(Position::LastPositionInNode(shadow_root2)) 377 .Extend(Position::LastPositionInNode(*shadow_root2))
378 .Build()); 378 .Build());
379 VisibleSelectionInFlatTree selection_in_flat_tree = CreateVisibleSelection( 379 VisibleSelectionInFlatTree selection_in_flat_tree = CreateVisibleSelection(
380 SelectionInFlatTree::Builder() 380 SelectionInFlatTree::Builder()
381 .Collapse(PositionInFlatTree::FirstPositionInNode(*one)) 381 .Collapse(PositionInFlatTree::FirstPositionInNode(*one))
382 .Extend(PositionInFlatTree::AfterNode(*eight)) 382 .Extend(PositionInFlatTree::AfterNode(*eight))
383 .Build()); 383 .Build());
384 384
385 EXPECT_EQ(Position(host, PositionAnchorType::kBeforeAnchor), 385 EXPECT_EQ(Position(host, PositionAnchorType::kBeforeAnchor),
386 selection.Start()); 386 selection.Start());
387 EXPECT_EQ(Position(one->firstChild(), 0), selection.End()); 387 EXPECT_EQ(Position(one->firstChild(), 0), selection.End());
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 Element* host = GetDocument().getElementById("host"); 532 Element* host = GetDocument().getElementById("host");
533 host->AppendChild(sample); 533 host->AppendChild(sample);
534 GetDocument().UpdateStyleAndLayout(); 534 GetDocument().UpdateStyleAndLayout();
535 535
536 // Simulates to restore selection from undo stack. 536 // Simulates to restore selection from undo stack.
537 selection = CreateVisibleSelection(selection.AsSelection()); 537 selection = CreateVisibleSelection(selection.AsSelection());
538 EXPECT_EQ(Position(sample->firstChild(), 0), selection.Start()); 538 EXPECT_EQ(Position(sample->firstChild(), 0), selection.Start());
539 } 539 }
540 540
541 } // namespace blink 541 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/VisiblePosition.cpp ('k') | third_party/WebKit/Source/core/editing/VisibleUnits.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698