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

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

Issue 2732963002: Make SelectionController::setNonDirectionalSelectionIfNeeded() to take SelectionInFlatTree (Closed)
Patch Set: 2017-03-07T13:12:10 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/SelectionController.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 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/SelectionController.h" 5 #include "core/editing/SelectionController.h"
6 6
7 #include "core/editing/EditingTestBase.h" 7 #include "core/editing/EditingTestBase.h"
8 #include "core/editing/FrameSelection.h" 8 #include "core/editing/FrameSelection.h"
9 #include "core/frame/FrameView.h" 9 #include "core/frame/FrameView.h"
10 #include "core/frame/Settings.h" 10 #include "core/frame/Settings.h"
11 #include "core/input/EventHandler.h" 11 #include "core/input/EventHandler.h"
12 12
13 namespace blink { 13 namespace blink {
14 14
15 class SelectionControllerTest : public EditingTestBase { 15 class SelectionControllerTest : public EditingTestBase {
16 protected: 16 protected:
17 SelectionControllerTest() = default; 17 SelectionControllerTest() = default;
18 18
19 const VisibleSelection& visibleSelectionInDOMTree() const { 19 const VisibleSelection& visibleSelectionInDOMTree() const {
20 return selection().computeVisibleSelectionInDOMTreeDeprecated(); 20 return selection().computeVisibleSelectionInDOMTreeDeprecated();
21 } 21 }
22 22
23 const VisibleSelectionInFlatTree& visibleSelectionInFlatTree() const { 23 const VisibleSelectionInFlatTree& visibleSelectionInFlatTree() const {
24 return selection().selectionInFlatTree(); 24 return selection().selectionInFlatTree();
25 } 25 }
26 26
27 void setNonDirectionalSelectionIfNeeded(const VisibleSelectionInFlatTree&, 27 void setNonDirectionalSelectionIfNeeded(const SelectionInFlatTree&,
28 TextGranularity); 28 TextGranularity);
29 29
30 private: 30 private:
31 DISALLOW_COPY_AND_ASSIGN(SelectionControllerTest); 31 DISALLOW_COPY_AND_ASSIGN(SelectionControllerTest);
32 }; 32 };
33 33
34 void SelectionControllerTest::setNonDirectionalSelectionIfNeeded( 34 void SelectionControllerTest::setNonDirectionalSelectionIfNeeded(
35 const VisibleSelectionInFlatTree& newSelection, 35 const SelectionInFlatTree& newSelection,
36 TextGranularity granularity) { 36 TextGranularity granularity) {
37 frame() 37 frame()
38 .eventHandler() 38 .eventHandler()
39 .selectionController() 39 .selectionController()
40 .setNonDirectionalSelectionIfNeeded( 40 .setNonDirectionalSelectionIfNeeded(
41 newSelection, granularity, SelectionController::DoNotAdjustEndpoints, 41 newSelection, granularity, SelectionController::DoNotAdjustEndpoints,
42 HandleVisibility::NotVisible); 42 HandleVisibility::NotVisible);
43 } 43 }
44 44
45 TEST_F(SelectionControllerTest, setNonDirectionalSelectionIfNeeded) { 45 TEST_F(SelectionControllerTest, setNonDirectionalSelectionIfNeeded) {
46 const char* bodyContent = "<span id=top>top</span><span id=host></span>"; 46 const char* bodyContent = "<span id=top>top</span><span id=host></span>";
47 const char* shadowContent = "<span id=bottom>bottom</span>"; 47 const char* shadowContent = "<span id=bottom>bottom</span>";
48 setBodyContent(bodyContent); 48 setBodyContent(bodyContent);
49 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); 49 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host");
50 50
51 Node* top = document().getElementById("top")->firstChild(); 51 Node* top = document().getElementById("top")->firstChild();
52 Node* bottom = shadowRoot->getElementById("bottom")->firstChild(); 52 Node* bottom = shadowRoot->getElementById("bottom")->firstChild();
53 Node* host = document().getElementById("host"); 53 Node* host = document().getElementById("host");
54 54
55 // top to bottom 55 // top to bottom
56 setNonDirectionalSelectionIfNeeded( 56 setNonDirectionalSelectionIfNeeded(SelectionInFlatTree::Builder()
57 createVisibleSelection(SelectionInFlatTree::Builder() 57 .collapse(PositionInFlatTree(top, 1))
58 .collapse(PositionInFlatTree(top, 1)) 58 .extend(PositionInFlatTree(bottom, 3))
59 .extend(PositionInFlatTree(bottom, 3)) 59 .build(),
60 .build()), 60 CharacterGranularity);
61 CharacterGranularity);
62 EXPECT_EQ(Position(top, 1), visibleSelectionInDOMTree().base()); 61 EXPECT_EQ(Position(top, 1), visibleSelectionInDOMTree().base());
63 EXPECT_EQ(Position::beforeNode(host), visibleSelectionInDOMTree().extent()); 62 EXPECT_EQ(Position::beforeNode(host), visibleSelectionInDOMTree().extent());
64 EXPECT_EQ(Position(top, 1), visibleSelectionInDOMTree().start()); 63 EXPECT_EQ(Position(top, 1), visibleSelectionInDOMTree().start());
65 EXPECT_EQ(Position(top, 3), visibleSelectionInDOMTree().end()); 64 EXPECT_EQ(Position(top, 3), visibleSelectionInDOMTree().end());
66 65
67 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().base()); 66 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().base());
68 EXPECT_EQ(PositionInFlatTree(bottom, 3), 67 EXPECT_EQ(PositionInFlatTree(bottom, 3),
69 visibleSelectionInFlatTree().extent()); 68 visibleSelectionInFlatTree().extent());
70 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().start()); 69 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().start());
71 EXPECT_EQ(PositionInFlatTree(bottom, 3), visibleSelectionInFlatTree().end()); 70 EXPECT_EQ(PositionInFlatTree(bottom, 3), visibleSelectionInFlatTree().end());
72 71
73 // bottom to top 72 // bottom to top
74 setNonDirectionalSelectionIfNeeded( 73 setNonDirectionalSelectionIfNeeded(
75 createVisibleSelection(SelectionInFlatTree::Builder() 74 SelectionInFlatTree::Builder()
76 .collapse(PositionInFlatTree(bottom, 3)) 75 .collapse(PositionInFlatTree(bottom, 3))
77 .extend(PositionInFlatTree(top, 1)) 76 .extend(PositionInFlatTree(top, 1))
78 .build()), 77 .build(),
79 CharacterGranularity); 78 CharacterGranularity);
80 EXPECT_EQ(Position(bottom, 3), visibleSelectionInDOMTree().base()); 79 EXPECT_EQ(Position(bottom, 3), visibleSelectionInDOMTree().base());
81 EXPECT_EQ(Position::beforeNode(bottom->parentNode()), 80 EXPECT_EQ(Position::beforeNode(bottom->parentNode()),
82 visibleSelectionInDOMTree().extent()); 81 visibleSelectionInDOMTree().extent());
83 EXPECT_EQ(Position(bottom, 0), visibleSelectionInDOMTree().start()); 82 EXPECT_EQ(Position(bottom, 0), visibleSelectionInDOMTree().start());
84 EXPECT_EQ(Position(bottom, 3), visibleSelectionInDOMTree().end()); 83 EXPECT_EQ(Position(bottom, 3), visibleSelectionInDOMTree().end());
85 84
86 EXPECT_EQ(PositionInFlatTree(bottom, 3), visibleSelectionInFlatTree().base()); 85 EXPECT_EQ(PositionInFlatTree(bottom, 3), visibleSelectionInFlatTree().base());
87 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().extent()); 86 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().extent());
88 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().start()); 87 EXPECT_EQ(PositionInFlatTree(top, 1), visibleSelectionInFlatTree().start());
(...skipping 10 matching lines...) Expand all
99 "sample.addEventListener('onselectstart', " 98 "sample.addEventListener('onselectstart', "
100 " event => elem.parentNode.removeChild(elem));"); 99 " event => elem.parentNode.removeChild(elem));");
101 document().body()->appendChild(script); 100 document().body()->appendChild(script);
102 document().view()->updateAllLifecyclePhases(); 101 document().view()->updateAllLifecyclePhases();
103 frame().eventHandler().selectionController().handleGestureLongPress( 102 frame().eventHandler().selectionController().handleGestureLongPress(
104 WebGestureEvent(), 103 WebGestureEvent(),
105 frame().eventHandler().hitTestResultAtPoint(IntPoint(8, 8))); 104 frame().eventHandler().hitTestResultAtPoint(IntPoint(8, 8)));
106 } 105 }
107 106
108 } // namespace blink 107 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/SelectionController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698