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

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

Issue 2972863003: Introduce CreateVisibleSelectionWithGranularity() (Closed)
Patch Set: 2017-07-06T16:26:15 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 EXPECT_EQ(selection.Base(), 57 EXPECT_EQ(selection.Base(),
58 ToPositionInDOMTree(selection_in_flat_tree.Base())); 58 ToPositionInDOMTree(selection_in_flat_tree.Base()));
59 EXPECT_EQ(selection.Extent(), 59 EXPECT_EQ(selection.Extent(),
60 ToPositionInDOMTree(selection_in_flat_tree.Extent())); 60 ToPositionInDOMTree(selection_in_flat_tree.Extent()));
61 } 61 }
62 62
63 template <typename Strategy> 63 template <typename Strategy>
64 VisibleSelectionTemplate<Strategy> ExpandUsingGranularity( 64 VisibleSelectionTemplate<Strategy> ExpandUsingGranularity(
65 const VisibleSelectionTemplate<Strategy>& selection, 65 const VisibleSelectionTemplate<Strategy>& selection,
66 TextGranularity granularity) { 66 TextGranularity granularity) {
67 return CreateVisibleSelection( 67 return CreateVisibleSelectionWithGranularity(
68 typename SelectionTemplate<Strategy>::Builder() 68 typename SelectionTemplate<Strategy>::Builder()
69 .SetBaseAndExtent(selection.Base(), selection.Extent()) 69 .SetBaseAndExtent(selection.Base(), selection.Extent())
70 .SetGranularity(granularity) 70 .Build(),
71 .Build()); 71 granularity);
72 } 72 }
73 73
74 // For http://crbug.com/700368 74 // For http://crbug.com/700368
75 TEST_F(VisibleSelectionTest, appendTrailingWhitespaceWithAfterAnchor) { 75 TEST_F(VisibleSelectionTest, appendTrailingWhitespaceWithAfterAnchor) {
76 SetBodyContent( 76 SetBodyContent(
77 "<input type=checkbox>" 77 "<input type=checkbox>"
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 const VisibleSelection selection = 85 const VisibleSelection selection = CreateVisibleSelectionWithGranularity(
86 CreateVisibleSelection(SelectionInDOMTree::Builder() 86 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 .Build(),
90 .Build()); 90 kWordGranularity);
91 const VisibleSelection result = selection.AppendTrailingWhitespace(); 91 const VisibleSelection result = selection.AppendTrailingWhitespace();
92 92
93 EXPECT_EQ(Position::BeforeNode(*input), result.Start()); 93 EXPECT_EQ(Position::BeforeNode(*input), result.Start());
94 EXPECT_EQ(Position::AfterNode(*input), result.End()); 94 EXPECT_EQ(Position::AfterNode(*input), result.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 =
(...skipping 431 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

Powered by Google App Engine
This is Rietveld 408576698