OLD | NEW |
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 "config.h" | 5 #include "config.h" |
6 #include "core/editing/VisibleSelection.h" | 6 #include "core/editing/VisibleSelection.h" |
7 | 7 |
8 #include "core/dom/Range.h" | 8 #include "core/dom/Range.h" |
9 #include "core/editing/EditingTestBase.h" | 9 #include "core/editing/EditingTestBase.h" |
10 | 10 |
11 #define LOREM_IPSUM \ | 11 #define LOREM_IPSUM \ |
12 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod te
mpor " \ | 12 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod te
mpor " \ |
13 "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud " \ | 13 "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud " \ |
14 "exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
aute irure " \ | 14 "exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
aute irure " \ |
15 "dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat null
a pariatur." \ | 15 "dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat null
a pariatur." \ |
16 "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia d
eserunt " \ | 16 "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia d
eserunt " \ |
17 "mollit anim id est laborum." | 17 "mollit anim id est laborum." |
18 | 18 |
19 namespace blink { | 19 namespace blink { |
20 | 20 |
| 21 using VisibleSelectionInComposedTree = VisibleSelectionTemplate<EditingInCompose
dTreeStrategy>; |
| 22 |
21 class VisibleSelectionTest : public EditingTestBase { | 23 class VisibleSelectionTest : public EditingTestBase { |
22 protected: | 24 protected: |
23 // Helper function to set the VisibleSelection base/extent. | 25 // Helper function to set the VisibleSelection base/extent. |
24 void setSelection(VisibleSelection& selection, int base) { setSelection(sele
ction, base, base); } | 26 void setSelection(VisibleSelection& selection, int base) { setSelection(sele
ction, base, base); } |
25 | 27 |
26 // Helper function to set the VisibleSelection base/extent. | 28 // Helper function to set the VisibleSelection base/extent. |
27 void setSelection(VisibleSelection& selection, int base, int extend) | 29 void setSelection(VisibleSelection& selection, int base, int extend) |
28 { | 30 { |
29 Node* node = document().body()->firstChild(); | 31 Node* node = document().body()->firstChild(); |
30 selection.setBase(Position(node, base)); | 32 selection.setBase(Position(node, base)); |
31 selection.setExtent(Position(node, extend)); | 33 selection.setExtent(Position(node, extend)); |
32 } | 34 } |
33 | 35 |
34 static bool equalPositions(const Position&, const PositionInComposedTree&); | 36 // Helper function to set the VisibleSelection base/extent. |
35 static void testComposedTreePositionsToEqualToDOMTreePositions(const Visible
Selection&); | 37 template <typename Strategy> |
| 38 void setSelection(VisibleSelectionTemplate<Strategy>& selection, int base) |
| 39 { |
| 40 setSelection(selection, base, base); |
| 41 } |
| 42 |
| 43 // Helper function to set the VisibleSelection base/extent. |
| 44 template <typename Strategy> |
| 45 void setSelection(VisibleSelectionTemplate<Strategy>& selection, int base, i
nt extend) |
| 46 { |
| 47 Node* node = document().body()->firstChild(); |
| 48 selection.setBase(PositionAlgorithm<Strategy>(node, base)); |
| 49 selection.setExtent(PositionAlgorithm<Strategy>(node, extend)); |
| 50 } |
36 }; | 51 }; |
37 | 52 |
38 bool VisibleSelectionTest::equalPositions(const Position& positionInDOMTree, con
st PositionInComposedTree& positionInComposedTree) | 53 static void testComposedTreePositionsToEqualToDOMTreePositions(const VisibleSele
ction& selection, const VisibleSelectionInComposedTree& selectionInComposedTree) |
39 { | 54 { |
40 // Since DOM tree positions can't be map to composed tree version, e.g. | 55 // Since DOM tree positions can't be map to composed tree version, e.g. |
41 // shadow root, not distributed node, we map a position in composed tree | 56 // shadow root, not distributed node, we map a position in composed tree |
42 // to DOM tree position. | 57 // to DOM tree position. |
43 return positionInDOMTree == toPositionInDOMTree(positionInComposedTree); | 58 EXPECT_EQ(selection.start(), toPositionInDOMTree(selectionInComposedTree.sta
rt())); |
44 } | 59 EXPECT_EQ(selection.end(), toPositionInDOMTree(selectionInComposedTree.end()
)); |
45 | 60 EXPECT_EQ(selection.base(), toPositionInDOMTree(selectionInComposedTree.base
())); |
46 void VisibleSelectionTest::testComposedTreePositionsToEqualToDOMTreePositions(co
nst VisibleSelection& selection) | 61 EXPECT_EQ(selection.extent(), toPositionInDOMTree(selectionInComposedTree.ex
tent())); |
47 { | |
48 EXPECT_TRUE(equalPositions(selection.start(), VisibleSelection::InComposedTr
ee::selectionStart(selection))); | |
49 EXPECT_TRUE(equalPositions(selection.end(), VisibleSelection::InComposedTree
::selectionEnd(selection))); | |
50 EXPECT_TRUE(equalPositions(selection.base(), VisibleSelection::InComposedTre
e::selectionBase(selection))); | |
51 EXPECT_TRUE(equalPositions(selection.extent(), VisibleSelection::InComposedT
ree::selectionExtent(selection))); | |
52 } | 62 } |
53 | 63 |
54 TEST_F(VisibleSelectionTest, Initialisation) | 64 TEST_F(VisibleSelectionTest, Initialisation) |
55 { | 65 { |
56 setBodyContent(LOREM_IPSUM); | 66 setBodyContent(LOREM_IPSUM); |
57 | 67 |
58 VisibleSelection selection; | 68 VisibleSelection selection; |
| 69 VisibleSelectionInComposedTree selectionInComposedTree; |
59 setSelection(selection, 0); | 70 setSelection(selection, 0); |
| 71 setSelection(selectionInComposedTree, 0); |
60 | 72 |
61 EXPECT_FALSE(selection.isNone()); | 73 EXPECT_FALSE(selection.isNone()); |
62 EXPECT_TRUE(selection.isCaret()); | 74 EXPECT_TRUE(selection.isCaret()); |
63 | 75 |
64 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 76 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
65 EXPECT_EQ(0, range->startOffset()); | 77 EXPECT_EQ(0, range->startOffset()); |
66 EXPECT_EQ(0, range->endOffset()); | 78 EXPECT_EQ(0, range->endOffset()); |
67 EXPECT_EQ("", range->text()); | 79 EXPECT_EQ("", range->text()); |
68 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 80 testComposedTreePositionsToEqualToDOMTreePositions(selection, selectionInCom
posedTree); |
69 } | 81 } |
70 | 82 |
71 TEST_F(VisibleSelectionTest, ShadowCrossing) | 83 TEST_F(VisibleSelectionTest, ShadowCrossing) |
72 { | 84 { |
73 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; | 85 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; |
74 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two>
</content><span id='s5'>55</span><content select=#one></content><span id='s6'>66
</span></a>"; | 86 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two>
</content><span id='s5'>55</span><content select=#one></content><span id='s6'>66
</span></a>"; |
75 setBodyContent(bodyContent); | 87 setBodyContent(bodyContent); |
76 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); | 88 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
77 | 89 |
78 RefPtrWillBeRawPtr<Element> body = document().body(); | 90 RefPtrWillBeRawPtr<Element> body = document().body(); |
79 RefPtrWillBeRawPtr<Element> host = body->querySelector("#host", ASSERT_NO_EX
CEPTION); | 91 RefPtrWillBeRawPtr<Element> host = body->querySelector("#host", ASSERT_NO_EX
CEPTION); |
80 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); | 92 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); |
81 RefPtrWillBeRawPtr<Element> six = shadowRoot->querySelector("#s6", ASSERT_NO
_EXCEPTION); | 93 RefPtrWillBeRawPtr<Element> six = shadowRoot->querySelector("#s6", ASSERT_NO
_EXCEPTION); |
82 | 94 |
83 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio
n::lastPositionInNode(shadowRoot.get())); | 95 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio
n::lastPositionInNode(shadowRoot.get())); |
| 96 VisibleSelectionInComposedTree selectionInComposedTree(selection); |
84 | 97 |
85 EXPECT_EQ(Position(host.get(), PositionAnchorType::BeforeAnchor), selection.
start()); | 98 EXPECT_EQ(Position(host.get(), PositionAnchorType::BeforeAnchor), selection.
start()); |
86 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); | 99 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); |
87 EXPECT_EQ(PositionInComposedTree(one->firstChild(), 0), selection.startInCom
posedTree()); | 100 EXPECT_EQ(PositionInComposedTree(one->firstChild(), 0), selectionInComposedT
ree.start()); |
88 EXPECT_EQ(PositionInComposedTree(six->firstChild(), 2), selection.endInCompo
sedTree()); | 101 EXPECT_EQ(PositionInComposedTree(six->firstChild(), 2), selectionInComposedT
ree.end()); |
89 } | 102 } |
90 | 103 |
91 TEST_F(VisibleSelectionTest, ShadowDistributedNodes) | 104 TEST_F(VisibleSelectionTest, ShadowDistributedNodes) |
92 { | 105 { |
93 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; | 106 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; |
94 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two>
</content><span id='s5'>55</span><content select=#one></content><span id='s6'>66
</span></a>"; | 107 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two>
</content><span id='s5'>55</span><content select=#one></content><span id='s6'>66
</span></a>"; |
95 setBodyContent(bodyContent); | 108 setBodyContent(bodyContent); |
96 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); | 109 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
97 | 110 |
98 RefPtrWillBeRawPtr<Element> body = document().body(); | 111 RefPtrWillBeRawPtr<Element> body = document().body(); |
99 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); | 112 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); |
100 RefPtrWillBeRawPtr<Element> two = body->querySelector("#two", ASSERT_NO_EXCE
PTION); | 113 RefPtrWillBeRawPtr<Element> two = body->querySelector("#two", ASSERT_NO_EXCE
PTION); |
101 RefPtrWillBeRawPtr<Element> five = shadowRoot->querySelector("#s5", ASSERT_N
O_EXCEPTION); | 114 RefPtrWillBeRawPtr<Element> five = shadowRoot->querySelector("#s5", ASSERT_N
O_EXCEPTION); |
102 | 115 |
103 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio
n::lastPositionInNode(two.get())); | 116 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio
n::lastPositionInNode(two.get())); |
| 117 VisibleSelectionInComposedTree selectionInComposedTree(selection); |
104 | 118 |
105 EXPECT_EQ(Position(one->firstChild(), 0), selection.start()); | 119 EXPECT_EQ(Position(one->firstChild(), 0), selection.start()); |
106 EXPECT_EQ(Position(two->firstChild(), 2), selection.end()); | 120 EXPECT_EQ(Position(two->firstChild(), 2), selection.end()); |
107 EXPECT_EQ(PositionInComposedTree(five->firstChild(), 0), selection.startInCo
mposedTree()); | 121 EXPECT_EQ(PositionInComposedTree(five->firstChild(), 0), selectionInComposed
Tree.start()); |
108 EXPECT_EQ(PositionInComposedTree(five->firstChild(), 2), selection.endInComp
osedTree()); | 122 EXPECT_EQ(PositionInComposedTree(five->firstChild(), 2), selectionInComposed
Tree.end()); |
109 } | 123 } |
110 | 124 |
111 TEST_F(VisibleSelectionTest, ShadowNested) | 125 TEST_F(VisibleSelectionTest, ShadowNested) |
112 { | 126 { |
113 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; | 127 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; |
114 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two>
</content><span id='s5'>55</span><content select=#one></content><span id='s6'>66
</span></a>"; | 128 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two>
</content><span id='s5'>55</span><content select=#one></content><span id='s6'>66
</span></a>"; |
115 const char* shadowContent2 = "<span id='s7'>77</span><content></content><spa
n id='s8'>88</span>"; | 129 const char* shadowContent2 = "<span id='s7'>77</span><content></content><spa
n id='s8'>88</span>"; |
116 setBodyContent(bodyContent); | 130 setBodyContent(bodyContent); |
117 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); | 131 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
118 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot2 = createShadowRootForElementWithI
DAndSetInnerHTML(*shadowRoot, "s5", shadowContent2); | 132 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot2 = createShadowRootForElementWithI
DAndSetInnerHTML(*shadowRoot, "s5", shadowContent2); |
119 | 133 |
| 134 // Composed tree is something like below: |
| 135 // <p id="host"> |
| 136 // <span id="s4">44</span> |
| 137 // <b id="two">22</b> |
| 138 // <span id="s5"><span id="s7">77>55</span id="s8">88</span> |
| 139 // <b id="one">11</b> |
| 140 // <span id="s6">66</span> |
| 141 // </p> |
120 RefPtrWillBeRawPtr<Element> body = document().body(); | 142 RefPtrWillBeRawPtr<Element> body = document().body(); |
121 RefPtrWillBeRawPtr<Element> host = body->querySelector("#host", ASSERT_NO_EX
CEPTION); | 143 RefPtrWillBeRawPtr<Element> host = body->querySelector("#host", ASSERT_NO_EX
CEPTION); |
122 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); | 144 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); |
123 RefPtrWillBeRawPtr<Element> eight = shadowRoot2->querySelector("#s8", ASSERT
_NO_EXCEPTION); | 145 RefPtrWillBeRawPtr<Element> eight = shadowRoot2->querySelector("#s8", ASSERT
_NO_EXCEPTION); |
124 | 146 |
125 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio
n::lastPositionInNode(shadowRoot2.get())); | 147 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio
n::lastPositionInNode(shadowRoot2.get())); |
| 148 VisibleSelectionInComposedTree selectionInComposedTree(selection); |
126 | 149 |
127 EXPECT_EQ(Position(host.get(), PositionAnchorType::BeforeAnchor), selection.
start()); | 150 EXPECT_EQ(Position(host.get(), PositionAnchorType::BeforeAnchor), selection.
start()); |
128 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); | 151 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); |
129 EXPECT_EQ(PositionInComposedTree(eight->firstChild(), 2), selection.startInC
omposedTree()); | 152 EXPECT_EQ(PositionInComposedTree(eight->firstChild(), 2), selectionInCompose
dTree.start()); |
130 EXPECT_EQ(PositionInComposedTree(one->firstChild(), 0), selection.endInCompo
sedTree()); | 153 EXPECT_EQ(PositionInComposedTree(one->firstChild(), 0), selectionInComposedT
ree.end()); |
131 } | 154 } |
132 | 155 |
133 TEST_F(VisibleSelectionTest, WordGranularity) | 156 TEST_F(VisibleSelectionTest, WordGranularity) |
134 { | 157 { |
135 setBodyContent(LOREM_IPSUM); | 158 setBodyContent(LOREM_IPSUM); |
136 | 159 |
137 VisibleSelection selection; | 160 VisibleSelection selection; |
| 161 VisibleSelectionInComposedTree selectionInComposedTree; |
138 | 162 |
139 // Beginning of a word. | 163 // Beginning of a word. |
140 { | 164 { |
141 setSelection(selection, 0); | 165 setSelection(selection, 0); |
| 166 setSelection(selectionInComposedTree, 0); |
142 selection.expandUsingGranularity(WordGranularity); | 167 selection.expandUsingGranularity(WordGranularity); |
| 168 selectionInComposedTree.expandUsingGranularity(WordGranularity); |
143 | 169 |
144 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 170 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
145 EXPECT_EQ(0, range->startOffset()); | 171 EXPECT_EQ(0, range->startOffset()); |
146 EXPECT_EQ(5, range->endOffset()); | 172 EXPECT_EQ(5, range->endOffset()); |
147 EXPECT_EQ("Lorem", range->text()); | 173 EXPECT_EQ("Lorem", range->text()); |
148 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 174 testComposedTreePositionsToEqualToDOMTreePositions(selection, selectionI
nComposedTree); |
149 | 175 |
150 } | 176 } |
151 | 177 |
152 // Middle of a word. | 178 // Middle of a word. |
153 { | 179 { |
154 setSelection(selection, 8); | 180 setSelection(selection, 8); |
| 181 setSelection(selectionInComposedTree, 8); |
155 selection.expandUsingGranularity(WordGranularity); | 182 selection.expandUsingGranularity(WordGranularity); |
| 183 selectionInComposedTree.expandUsingGranularity(WordGranularity); |
156 | 184 |
157 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 185 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
158 EXPECT_EQ(6, range->startOffset()); | 186 EXPECT_EQ(6, range->startOffset()); |
159 EXPECT_EQ(11, range->endOffset()); | 187 EXPECT_EQ(11, range->endOffset()); |
160 EXPECT_EQ("ipsum", range->text()); | 188 EXPECT_EQ("ipsum", range->text()); |
161 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 189 testComposedTreePositionsToEqualToDOMTreePositions(selection, selectionI
nComposedTree); |
162 | 190 |
163 } | 191 } |
164 | 192 |
165 // End of a word. | 193 // End of a word. |
166 // FIXME: that sounds buggy, we might want to select the word _before_ inste
ad | 194 // FIXME: that sounds buggy, we might want to select the word _before_ inste
ad |
167 // of the space... | 195 // of the space... |
168 { | 196 { |
169 setSelection(selection, 5); | 197 setSelection(selection, 5); |
| 198 setSelection(selectionInComposedTree, 5); |
170 selection.expandUsingGranularity(WordGranularity); | 199 selection.expandUsingGranularity(WordGranularity); |
| 200 selectionInComposedTree.expandUsingGranularity(WordGranularity); |
171 | 201 |
172 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 202 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
173 EXPECT_EQ(5, range->startOffset()); | 203 EXPECT_EQ(5, range->startOffset()); |
174 EXPECT_EQ(6, range->endOffset()); | 204 EXPECT_EQ(6, range->endOffset()); |
175 EXPECT_EQ(" ", range->text()); | 205 EXPECT_EQ(" ", range->text()); |
176 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 206 testComposedTreePositionsToEqualToDOMTreePositions(selection, selectionI
nComposedTree); |
177 } | 207 } |
178 | 208 |
179 // Before comma. | 209 // Before comma. |
180 // FIXME: that sounds buggy, we might want to select the word _before_ inste
ad | 210 // FIXME: that sounds buggy, we might want to select the word _before_ inste
ad |
181 // of the comma. | 211 // of the comma. |
182 { | 212 { |
183 setSelection(selection, 26); | 213 setSelection(selection, 26); |
| 214 setSelection(selectionInComposedTree, 26); |
184 selection.expandUsingGranularity(WordGranularity); | 215 selection.expandUsingGranularity(WordGranularity); |
| 216 selectionInComposedTree.expandUsingGranularity(WordGranularity); |
185 | 217 |
186 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 218 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
187 EXPECT_EQ(26, range->startOffset()); | 219 EXPECT_EQ(26, range->startOffset()); |
188 EXPECT_EQ(27, range->endOffset()); | 220 EXPECT_EQ(27, range->endOffset()); |
189 EXPECT_EQ(",", range->text()); | 221 EXPECT_EQ(",", range->text()); |
190 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 222 testComposedTreePositionsToEqualToDOMTreePositions(selection, selectionI
nComposedTree); |
191 } | 223 } |
192 | 224 |
193 // After comma. | 225 // After comma. |
194 { | 226 { |
195 setSelection(selection, 27); | 227 setSelection(selection, 27); |
| 228 setSelection(selectionInComposedTree, 27); |
196 selection.expandUsingGranularity(WordGranularity); | 229 selection.expandUsingGranularity(WordGranularity); |
| 230 selectionInComposedTree.expandUsingGranularity(WordGranularity); |
197 | 231 |
198 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 232 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
199 EXPECT_EQ(27, range->startOffset()); | 233 EXPECT_EQ(27, range->startOffset()); |
200 EXPECT_EQ(28, range->endOffset()); | 234 EXPECT_EQ(28, range->endOffset()); |
201 EXPECT_EQ(" ", range->text()); | 235 EXPECT_EQ(" ", range->text()); |
202 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 236 testComposedTreePositionsToEqualToDOMTreePositions(selection, selectionI
nComposedTree); |
203 } | 237 } |
204 | 238 |
205 // When selecting part of a word. | 239 // When selecting part of a word. |
206 { | 240 { |
207 setSelection(selection, 0, 1); | 241 setSelection(selection, 0, 1); |
| 242 setSelection(selectionInComposedTree, 0, 1); |
208 selection.expandUsingGranularity(WordGranularity); | 243 selection.expandUsingGranularity(WordGranularity); |
| 244 selectionInComposedTree.expandUsingGranularity(WordGranularity); |
209 | 245 |
210 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 246 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
211 EXPECT_EQ(0, range->startOffset()); | 247 EXPECT_EQ(0, range->startOffset()); |
212 EXPECT_EQ(5, range->endOffset()); | 248 EXPECT_EQ(5, range->endOffset()); |
213 EXPECT_EQ("Lorem", range->text()); | 249 EXPECT_EQ("Lorem", range->text()); |
214 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 250 testComposedTreePositionsToEqualToDOMTreePositions(selection, selectionI
nComposedTree); |
215 } | 251 } |
216 | 252 |
217 // When selecting part of two words. | 253 // When selecting part of two words. |
218 { | 254 { |
219 setSelection(selection, 2, 8); | 255 setSelection(selection, 2, 8); |
| 256 setSelection(selectionInComposedTree, 2, 8); |
220 selection.expandUsingGranularity(WordGranularity); | 257 selection.expandUsingGranularity(WordGranularity); |
| 258 selectionInComposedTree.expandUsingGranularity(WordGranularity); |
221 | 259 |
222 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 260 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
223 EXPECT_EQ(0, range->startOffset()); | 261 EXPECT_EQ(0, range->startOffset()); |
224 EXPECT_EQ(11, range->endOffset()); | 262 EXPECT_EQ(11, range->endOffset()); |
225 EXPECT_EQ("Lorem ipsum", range->text()); | 263 EXPECT_EQ("Lorem ipsum", range->text()); |
226 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 264 testComposedTreePositionsToEqualToDOMTreePositions(selection, selectionI
nComposedTree); |
227 } | 265 } |
228 } | 266 } |
229 | 267 |
230 } // namespace blink | 268 } // namespace blink |
OLD | NEW |