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 static void testComposedTreePositionsToEqualToDOMTreePositions(const Visible Selection&, const VisibleSelectionInComposedTree&); |
35 static void testComposedTreePositionsToEqualToDOMTreePositions(const Visible Selection&); | 37 |
38 // Helper function to set the VisibleSelection base/extent. | |
39 template <typename Strategy> | |
40 void setSelection(VisibleSelectionTemplate<Strategy>& selection, int base) | |
41 { | |
42 setSelection(selection, base, base); | |
43 } | |
44 | |
45 // Helper function to set the VisibleSelection base/extent. | |
46 template <typename Strategy> | |
47 void setSelection(VisibleSelectionTemplate<Strategy>& selection, int base, i nt extend) | |
48 { | |
49 Node* node = document().body()->firstChild(); | |
50 selection.setBase(PositionAlgorithm<Strategy>(node, base)); | |
51 selection.setExtent(PositionAlgorithm<Strategy>(node, extend)); | |
52 } | |
36 }; | 53 }; |
37 | 54 |
38 bool VisibleSelectionTest::equalPositions(const Position& positionInDOMTree, con st PositionInComposedTree& positionInComposedTree) | 55 void VisibleSelectionTest::testComposedTreePositionsToEqualToDOMTreePositions(co nst VisibleSelection& selection, const VisibleSelectionInComposedTree& selection InComposedTree) |
yoichio
2015/09/28 06:12:26
Just use |static void| rather than declaring class
yosin_UTC9
2015/09/28 06:34:41
Done.
| |
39 { | 56 { |
40 // Since DOM tree positions can't be map to composed tree version, e.g. | 57 // 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 | 58 // shadow root, not distributed node, we map a position in composed tree |
42 // to DOM tree position. | 59 // to DOM tree position. |
43 return positionInDOMTree == toPositionInDOMTree(positionInComposedTree); | 60 EXPECT_EQ(selection.start(), toPositionInDOMTree(selectionInComposedTree.sta rt())); |
44 } | 61 EXPECT_EQ(selection.end(), toPositionInDOMTree(selectionInComposedTree.end() )); |
45 | 62 EXPECT_EQ(selection.base(), toPositionInDOMTree(selectionInComposedTree.base ())); |
46 void VisibleSelectionTest::testComposedTreePositionsToEqualToDOMTreePositions(co nst VisibleSelection& selection) | 63 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 } | 64 } |
53 | 65 |
54 TEST_F(VisibleSelectionTest, Initialisation) | 66 TEST_F(VisibleSelectionTest, Initialisation) |
55 { | 67 { |
56 setBodyContent(LOREM_IPSUM); | 68 setBodyContent(LOREM_IPSUM); |
57 | 69 |
58 VisibleSelection selection; | 70 VisibleSelection selection; |
71 VisibleSelectionInComposedTree selectionInComposedTree; | |
59 setSelection(selection, 0); | 72 setSelection(selection, 0); |
73 setSelection(selectionInComposedTree, 0); | |
60 | 74 |
61 EXPECT_FALSE(selection.isNone()); | 75 EXPECT_FALSE(selection.isNone()); |
62 EXPECT_TRUE(selection.isCaret()); | 76 EXPECT_TRUE(selection.isCaret()); |
63 | 77 |
64 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 78 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
65 EXPECT_EQ(0, range->startOffset()); | 79 EXPECT_EQ(0, range->startOffset()); |
66 EXPECT_EQ(0, range->endOffset()); | 80 EXPECT_EQ(0, range->endOffset()); |
67 EXPECT_EQ("", range->text()); | 81 EXPECT_EQ("", range->text()); |
68 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 82 testComposedTreePositionsToEqualToDOMTreePositions(selection, selectionInCom posedTree); |
69 } | 83 } |
70 | 84 |
71 TEST_F(VisibleSelectionTest, ShadowCrossing) | 85 TEST_F(VisibleSelectionTest, ShadowCrossing) |
72 { | 86 { |
73 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</ b>33</p>"; | 87 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>"; | 88 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); | 89 setBodyContent(bodyContent); |
76 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); | 90 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); |
77 | 91 |
78 RefPtrWillBeRawPtr<Element> body = document().body(); | 92 RefPtrWillBeRawPtr<Element> body = document().body(); |
79 RefPtrWillBeRawPtr<Element> host = body->querySelector("#host", ASSERT_NO_EX CEPTION); | 93 RefPtrWillBeRawPtr<Element> host = body->querySelector("#host", ASSERT_NO_EX CEPTION); |
80 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE PTION); | 94 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE PTION); |
81 RefPtrWillBeRawPtr<Element> six = shadowRoot->querySelector("#s6", ASSERT_NO _EXCEPTION); | 95 RefPtrWillBeRawPtr<Element> six = shadowRoot->querySelector("#s6", ASSERT_NO _EXCEPTION); |
82 | 96 |
83 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio n::lastPositionInNode(shadowRoot.get())); | 97 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio n::lastPositionInNode(shadowRoot.get())); |
98 VisibleSelectionInComposedTree selectionInComposedTree(selection); | |
84 | 99 |
85 EXPECT_EQ(Position(host.get(), PositionAnchorType::BeforeAnchor), selection. start()); | 100 EXPECT_EQ(Position(host.get(), PositionAnchorType::BeforeAnchor), selection. start()); |
86 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); | 101 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); |
87 EXPECT_EQ(PositionInComposedTree(one->firstChild(), 0), selection.startInCom posedTree()); | 102 EXPECT_EQ(PositionInComposedTree(one->firstChild(), 0), selectionInComposedT ree.start()); |
88 EXPECT_EQ(PositionInComposedTree(six->firstChild(), 2), selection.endInCompo sedTree()); | 103 EXPECT_EQ(PositionInComposedTree(six->firstChild(), 2), selectionInComposedT ree.end()); |
89 } | 104 } |
90 | 105 |
91 TEST_F(VisibleSelectionTest, ShadowDistributedNodes) | 106 TEST_F(VisibleSelectionTest, ShadowDistributedNodes) |
92 { | 107 { |
93 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</ b>33</p>"; | 108 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>"; | 109 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); | 110 setBodyContent(bodyContent); |
96 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); | 111 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); |
97 | 112 |
98 RefPtrWillBeRawPtr<Element> body = document().body(); | 113 RefPtrWillBeRawPtr<Element> body = document().body(); |
99 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE PTION); | 114 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE PTION); |
100 RefPtrWillBeRawPtr<Element> two = body->querySelector("#two", ASSERT_NO_EXCE PTION); | 115 RefPtrWillBeRawPtr<Element> two = body->querySelector("#two", ASSERT_NO_EXCE PTION); |
101 RefPtrWillBeRawPtr<Element> five = shadowRoot->querySelector("#s5", ASSERT_N O_EXCEPTION); | 116 RefPtrWillBeRawPtr<Element> five = shadowRoot->querySelector("#s5", ASSERT_N O_EXCEPTION); |
102 | 117 |
103 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio n::lastPositionInNode(two.get())); | 118 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio n::lastPositionInNode(two.get())); |
119 VisibleSelectionInComposedTree selectionInComposedTree(selection); | |
104 | 120 |
105 EXPECT_EQ(Position(one->firstChild(), 0), selection.start()); | 121 EXPECT_EQ(Position(one->firstChild(), 0), selection.start()); |
106 EXPECT_EQ(Position(two->firstChild(), 2), selection.end()); | 122 EXPECT_EQ(Position(two->firstChild(), 2), selection.end()); |
107 EXPECT_EQ(PositionInComposedTree(five->firstChild(), 0), selection.startInCo mposedTree()); | 123 EXPECT_EQ(PositionInComposedTree(five->firstChild(), 0), selectionInComposed Tree.start()); |
108 EXPECT_EQ(PositionInComposedTree(five->firstChild(), 2), selection.endInComp osedTree()); | 124 EXPECT_EQ(PositionInComposedTree(five->firstChild(), 2), selectionInComposed Tree.end()); |
109 } | 125 } |
110 | 126 |
111 TEST_F(VisibleSelectionTest, ShadowNested) | 127 TEST_F(VisibleSelectionTest, ShadowNested) |
112 { | 128 { |
113 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</ b>33</p>"; | 129 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>"; | 130 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>"; | 131 const char* shadowContent2 = "<span id='s7'>77</span><content></content><spa n id='s8'>88</span>"; |
116 setBodyContent(bodyContent); | 132 setBodyContent(bodyContent); |
117 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); | 133 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent, "host"); |
118 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot2 = createShadowRootForElementWithI DAndSetInnerHTML(*shadowRoot, "s5", shadowContent2); | 134 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot2 = createShadowRootForElementWithI DAndSetInnerHTML(*shadowRoot, "s5", shadowContent2); |
119 | 135 |
136 // Composed tree is something like below: | |
137 // <p id="host"> | |
138 // <span id="s4">44</span> | |
139 // <b id="two">22</b> | |
140 // <span id="s5"><span id="s7">77>55</span id="s8">88</span> | |
141 // <b id="one">11</b> | |
142 // <span id="s6">66</span> | |
143 // </p> | |
120 RefPtrWillBeRawPtr<Element> body = document().body(); | 144 RefPtrWillBeRawPtr<Element> body = document().body(); |
121 RefPtrWillBeRawPtr<Element> host = body->querySelector("#host", ASSERT_NO_EX CEPTION); | 145 RefPtrWillBeRawPtr<Element> host = body->querySelector("#host", ASSERT_NO_EX CEPTION); |
122 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE PTION); | 146 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE PTION); |
123 RefPtrWillBeRawPtr<Element> eight = shadowRoot2->querySelector("#s8", ASSERT _NO_EXCEPTION); | 147 RefPtrWillBeRawPtr<Element> eight = shadowRoot2->querySelector("#s8", ASSERT _NO_EXCEPTION); |
124 | 148 |
125 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio n::lastPositionInNode(shadowRoot2.get())); | 149 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio n::lastPositionInNode(shadowRoot2.get())); |
150 VisibleSelectionInComposedTree selectionInComposedTree(selection); | |
126 | 151 |
127 EXPECT_EQ(Position(host.get(), PositionAnchorType::BeforeAnchor), selection. start()); | 152 EXPECT_EQ(Position(host.get(), PositionAnchorType::BeforeAnchor), selection. start()); |
128 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); | 153 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); |
129 EXPECT_EQ(PositionInComposedTree(eight->firstChild(), 2), selection.startInC omposedTree()); | 154 EXPECT_EQ(PositionInComposedTree(eight->firstChild(), 2), selectionInCompose dTree.start()); |
130 EXPECT_EQ(PositionInComposedTree(one->firstChild(), 0), selection.endInCompo sedTree()); | 155 EXPECT_EQ(PositionInComposedTree(one->firstChild(), 0), selectionInComposedT ree.end()); |
131 } | 156 } |
132 | 157 |
133 TEST_F(VisibleSelectionTest, WordGranularity) | 158 TEST_F(VisibleSelectionTest, WordGranularity) |
134 { | 159 { |
135 setBodyContent(LOREM_IPSUM); | 160 setBodyContent(LOREM_IPSUM); |
136 | 161 |
137 VisibleSelection selection; | 162 VisibleSelection selection; |
163 VisibleSelectionInComposedTree selectionInComposedTree; | |
138 | 164 |
139 // Beginning of a word. | 165 // Beginning of a word. |
140 { | 166 { |
141 setSelection(selection, 0); | 167 setSelection(selection, 0); |
168 setSelection(selectionInComposedTree, 0); | |
142 selection.expandUsingGranularity(WordGranularity); | 169 selection.expandUsingGranularity(WordGranularity); |
170 selectionInComposedTree.expandUsingGranularity(WordGranularity); | |
143 | 171 |
144 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 172 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
145 EXPECT_EQ(0, range->startOffset()); | 173 EXPECT_EQ(0, range->startOffset()); |
146 EXPECT_EQ(5, range->endOffset()); | 174 EXPECT_EQ(5, range->endOffset()); |
147 EXPECT_EQ("Lorem", range->text()); | 175 EXPECT_EQ("Lorem", range->text()); |
148 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 176 testComposedTreePositionsToEqualToDOMTreePositions(selection, selectionI nComposedTree); |
149 | 177 |
150 } | 178 } |
151 | 179 |
152 // Middle of a word. | 180 // Middle of a word. |
153 { | 181 { |
154 setSelection(selection, 8); | 182 setSelection(selection, 8); |
183 setSelection(selectionInComposedTree, 8); | |
155 selection.expandUsingGranularity(WordGranularity); | 184 selection.expandUsingGranularity(WordGranularity); |
185 selectionInComposedTree.expandUsingGranularity(WordGranularity); | |
156 | 186 |
157 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 187 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
158 EXPECT_EQ(6, range->startOffset()); | 188 EXPECT_EQ(6, range->startOffset()); |
159 EXPECT_EQ(11, range->endOffset()); | 189 EXPECT_EQ(11, range->endOffset()); |
160 EXPECT_EQ("ipsum", range->text()); | 190 EXPECT_EQ("ipsum", range->text()); |
161 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 191 testComposedTreePositionsToEqualToDOMTreePositions(selection, selectionI nComposedTree); |
162 | 192 |
163 } | 193 } |
164 | 194 |
165 // End of a word. | 195 // End of a word. |
166 // FIXME: that sounds buggy, we might want to select the word _before_ inste ad | 196 // FIXME: that sounds buggy, we might want to select the word _before_ inste ad |
167 // of the space... | 197 // of the space... |
168 { | 198 { |
169 setSelection(selection, 5); | 199 setSelection(selection, 5); |
200 setSelection(selectionInComposedTree, 5); | |
170 selection.expandUsingGranularity(WordGranularity); | 201 selection.expandUsingGranularity(WordGranularity); |
202 selectionInComposedTree.expandUsingGranularity(WordGranularity); | |
171 | 203 |
172 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 204 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
173 EXPECT_EQ(5, range->startOffset()); | 205 EXPECT_EQ(5, range->startOffset()); |
174 EXPECT_EQ(6, range->endOffset()); | 206 EXPECT_EQ(6, range->endOffset()); |
175 EXPECT_EQ(" ", range->text()); | 207 EXPECT_EQ(" ", range->text()); |
176 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 208 testComposedTreePositionsToEqualToDOMTreePositions(selection, selectionI nComposedTree); |
177 } | 209 } |
178 | 210 |
179 // Before comma. | 211 // Before comma. |
180 // FIXME: that sounds buggy, we might want to select the word _before_ inste ad | 212 // FIXME: that sounds buggy, we might want to select the word _before_ inste ad |
181 // of the comma. | 213 // of the comma. |
182 { | 214 { |
183 setSelection(selection, 26); | 215 setSelection(selection, 26); |
216 setSelection(selectionInComposedTree, 26); | |
184 selection.expandUsingGranularity(WordGranularity); | 217 selection.expandUsingGranularity(WordGranularity); |
218 selectionInComposedTree.expandUsingGranularity(WordGranularity); | |
185 | 219 |
186 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 220 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
187 EXPECT_EQ(26, range->startOffset()); | 221 EXPECT_EQ(26, range->startOffset()); |
188 EXPECT_EQ(27, range->endOffset()); | 222 EXPECT_EQ(27, range->endOffset()); |
189 EXPECT_EQ(",", range->text()); | 223 EXPECT_EQ(",", range->text()); |
190 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 224 testComposedTreePositionsToEqualToDOMTreePositions(selection, selectionI nComposedTree); |
191 } | 225 } |
192 | 226 |
193 // After comma. | 227 // After comma. |
194 { | 228 { |
195 setSelection(selection, 27); | 229 setSelection(selection, 27); |
230 setSelection(selectionInComposedTree, 27); | |
196 selection.expandUsingGranularity(WordGranularity); | 231 selection.expandUsingGranularity(WordGranularity); |
232 selectionInComposedTree.expandUsingGranularity(WordGranularity); | |
197 | 233 |
198 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 234 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
199 EXPECT_EQ(27, range->startOffset()); | 235 EXPECT_EQ(27, range->startOffset()); |
200 EXPECT_EQ(28, range->endOffset()); | 236 EXPECT_EQ(28, range->endOffset()); |
201 EXPECT_EQ(" ", range->text()); | 237 EXPECT_EQ(" ", range->text()); |
202 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 238 testComposedTreePositionsToEqualToDOMTreePositions(selection, selectionI nComposedTree); |
203 } | 239 } |
204 | 240 |
205 // When selecting part of a word. | 241 // When selecting part of a word. |
206 { | 242 { |
207 setSelection(selection, 0, 1); | 243 setSelection(selection, 0, 1); |
244 setSelection(selectionInComposedTree, 0, 1); | |
208 selection.expandUsingGranularity(WordGranularity); | 245 selection.expandUsingGranularity(WordGranularity); |
246 selectionInComposedTree.expandUsingGranularity(WordGranularity); | |
209 | 247 |
210 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 248 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
211 EXPECT_EQ(0, range->startOffset()); | 249 EXPECT_EQ(0, range->startOffset()); |
212 EXPECT_EQ(5, range->endOffset()); | 250 EXPECT_EQ(5, range->endOffset()); |
213 EXPECT_EQ("Lorem", range->text()); | 251 EXPECT_EQ("Lorem", range->text()); |
214 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 252 testComposedTreePositionsToEqualToDOMTreePositions(selection, selectionI nComposedTree); |
215 } | 253 } |
216 | 254 |
217 // When selecting part of two words. | 255 // When selecting part of two words. |
218 { | 256 { |
219 setSelection(selection, 2, 8); | 257 setSelection(selection, 2, 8); |
258 setSelection(selectionInComposedTree, 2, 8); | |
220 selection.expandUsingGranularity(WordGranularity); | 259 selection.expandUsingGranularity(WordGranularity); |
260 selectionInComposedTree.expandUsingGranularity(WordGranularity); | |
221 | 261 |
222 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 262 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
223 EXPECT_EQ(0, range->startOffset()); | 263 EXPECT_EQ(0, range->startOffset()); |
224 EXPECT_EQ(11, range->endOffset()); | 264 EXPECT_EQ(11, range->endOffset()); |
225 EXPECT_EQ("Lorem ipsum", range->text()); | 265 EXPECT_EQ("Lorem ipsum", range->text()); |
226 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 266 testComposedTreePositionsToEqualToDOMTreePositions(selection, selectionI nComposedTree); |
227 } | 267 } |
228 } | 268 } |
229 | 269 |
230 } // namespace blink | 270 } // namespace blink |
OLD | NEW |