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

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

Issue 2953683004: Make Position::AfterNode() to take const Node& instead of Node* (Closed)
Patch Set: 2017-06-22T12:37:16 Created 3 years, 6 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 "<div style='user-select:none'>abc</div>"); 78 "<div style='user-select:none'>abc</div>");
79 Element* const input = GetDocument().QuerySelector("input"); 79 Element* const input = GetDocument().QuerySelector("input");
80 80
81 // Simulate double-clicking "abc". 81 // Simulate double-clicking "abc".
82 // TODO(editing-dev): We should remove above comment once we fix [1]. 82 // TODO(editing-dev): We should remove above comment once we fix [1].
83 // [1] http://crbug.com/701657 double-click on user-select:none should not 83 // [1] http://crbug.com/701657 double-click on user-select:none should not
84 // compute selection. 84 // compute selection.
85 VisibleSelection selection = 85 VisibleSelection selection =
86 CreateVisibleSelection(SelectionInDOMTree::Builder() 86 CreateVisibleSelection(SelectionInDOMTree::Builder()
87 .Collapse(Position::BeforeNode(*input)) 87 .Collapse(Position::BeforeNode(*input))
88 .Extend(Position::AfterNode(input)) 88 .Extend(Position::AfterNode(*input))
89 .SetGranularity(kWordGranularity) 89 .SetGranularity(kWordGranularity)
90 .Build()); 90 .Build());
91 selection.AppendTrailingWhitespace(); 91 selection.AppendTrailingWhitespace();
92 92
93 EXPECT_EQ(Position::BeforeNode(*input), selection.Start()); 93 EXPECT_EQ(Position::BeforeNode(*input), selection.Start());
94 EXPECT_EQ(Position::AfterNode(input), selection.End()); 94 EXPECT_EQ(Position::AfterNode(*input), selection.End());
95 } 95 }
96 96
97 TEST_F(VisibleSelectionTest, expandUsingGranularity) { 97 TEST_F(VisibleSelectionTest, expandUsingGranularity) {
98 const char* body_content = 98 const char* body_content =
99 "<span id=host><a id=one>1</a><a id=two>22</a></span>"; 99 "<span id=host><a id=one>1</a><a id=two>22</a></span>";
100 const char* shadow_content = 100 const char* shadow_content =
101 "<p><b id=three>333</b><content select=#two></content><b " 101 "<p><b id=three>333</b><content select=#two></content><b "
102 "id=four>4444</b><span id=space> </span><content " 102 "id=four>4444</b><span id=space> </span><content "
103 "select=#one></content><b id=five>55555</b></p>"; 103 "select=#one></content><b id=five>55555</b></p>";
104 SetBodyContent(body_content); 104 SetBodyContent(body_content);
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
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());
388 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), 388 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2),
389 selection_in_flat_tree.Start()); 389 selection_in_flat_tree.Start());
390 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), 390 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2),
391 selection_in_flat_tree.End()); 391 selection_in_flat_tree.End());
392 } 392 }
(...skipping 139 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/VisibleSelection.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