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

Side by Side Diff: Source/core/editing/SurroundingTextTest.cpp

Issue 1313883002: Introduce firstRangeOf() as replacement of VisibleSelection::firstRange() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-25T17:47:14 Created 5 years, 4 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 | « Source/core/editing/InputMethodController.cpp ('k') | Source/core/editing/VisibleSelection.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "config.h" 5 #include "config.h"
6 #include "core/editing/SurroundingText.h" 6 #include "core/editing/SurroundingText.h"
7 7
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/Range.h" 9 #include "core/dom/Range.h"
10 #include "core/dom/Text.h" 10 #include "core/dom/Text.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 EXPECT_EQ(7u, surroundingText.endOffsetInContent()); 109 EXPECT_EQ(7u, surroundingText.endOffsetInContent());
110 } 110 }
111 } 111 }
112 112
113 TEST_F(SurroundingTextTest, BasicRangeSelection) 113 TEST_F(SurroundingTextTest, BasicRangeSelection)
114 { 114 {
115 setHTML(String("<p id='selection'>Lorem ipsum dolor sit amet</p>")); 115 setHTML(String("<p id='selection'>Lorem ipsum dolor sit amet</p>"));
116 116
117 { 117 {
118 VisibleSelection selection = select(0, 5); 118 VisibleSelection selection = select(0, 5);
119 SurroundingText surroundingText(*selection.firstRange(), 1); 119 SurroundingText surroundingText(*firstRangeOf(selection), 1);
120 120
121 EXPECT_EQ("Lorem ", surroundingText.content()); 121 EXPECT_EQ("Lorem ", surroundingText.content());
122 EXPECT_EQ(0u, surroundingText.startOffsetInContent()); 122 EXPECT_EQ(0u, surroundingText.startOffsetInContent());
123 EXPECT_EQ(5u, surroundingText.endOffsetInContent()); 123 EXPECT_EQ(5u, surroundingText.endOffsetInContent());
124 } 124 }
125 125
126 { 126 {
127 VisibleSelection selection = select(0, 5); 127 VisibleSelection selection = select(0, 5);
128 SurroundingText surroundingText(*selection.firstRange(), 5); 128 SurroundingText surroundingText(*firstRangeOf(selection), 5);
129 129
130 EXPECT_EQ("Lorem ip", surroundingText.content().simplifyWhiteSpace()); 130 EXPECT_EQ("Lorem ip", surroundingText.content().simplifyWhiteSpace());
131 EXPECT_EQ(1u, surroundingText.startOffsetInContent()); 131 EXPECT_EQ(1u, surroundingText.startOffsetInContent());
132 EXPECT_EQ(6u, surroundingText.endOffsetInContent()); 132 EXPECT_EQ(6u, surroundingText.endOffsetInContent());
133 } 133 }
134 134
135 { 135 {
136 VisibleSelection selection = select(0, 5); 136 VisibleSelection selection = select(0, 5);
137 SurroundingText surroundingText(*selection.firstRange(), 42); 137 SurroundingText surroundingText(*firstRangeOf(selection), 42);
138 138
139 EXPECT_EQ("Lorem ipsum dolor sit amet", surroundingText.content().simpli fyWhiteSpace()); 139 EXPECT_EQ("Lorem ipsum dolor sit amet", surroundingText.content().simpli fyWhiteSpace());
140 EXPECT_EQ(1u, surroundingText.startOffsetInContent()); 140 EXPECT_EQ(1u, surroundingText.startOffsetInContent());
141 EXPECT_EQ(6u, surroundingText.endOffsetInContent()); 141 EXPECT_EQ(6u, surroundingText.endOffsetInContent());
142 } 142 }
143 143
144 { 144 {
145 VisibleSelection selection = select(6, 11); 145 VisibleSelection selection = select(6, 11);
146 SurroundingText surroundingText(*selection.firstRange(), 2); 146 SurroundingText surroundingText(*firstRangeOf(selection), 2);
147 147
148 EXPECT_EQ(" ipsum ", surroundingText.content()); 148 EXPECT_EQ(" ipsum ", surroundingText.content());
149 EXPECT_EQ(1u, surroundingText.startOffsetInContent()); 149 EXPECT_EQ(1u, surroundingText.startOffsetInContent());
150 EXPECT_EQ(6u, surroundingText.endOffsetInContent()); 150 EXPECT_EQ(6u, surroundingText.endOffsetInContent());
151 } 151 }
152 152
153 { 153 {
154 VisibleSelection selection = select(6, 11); 154 VisibleSelection selection = select(6, 11);
155 SurroundingText surroundingText(*selection.firstRange(), 42); 155 SurroundingText surroundingText(*firstRangeOf(selection), 42);
156 156
157 EXPECT_EQ("Lorem ipsum dolor sit amet", surroundingText.content().simpli fyWhiteSpace()); 157 EXPECT_EQ("Lorem ipsum dolor sit amet", surroundingText.content().simpli fyWhiteSpace());
158 EXPECT_EQ(7u, surroundingText.startOffsetInContent()); 158 EXPECT_EQ(7u, surroundingText.startOffsetInContent());
159 EXPECT_EQ(12u, surroundingText.endOffsetInContent()); 159 EXPECT_EQ(12u, surroundingText.endOffsetInContent());
160 } 160 }
161 } 161 }
162 162
163 TEST_F(SurroundingTextTest, TreeCaretSelection) 163 TEST_F(SurroundingTextTest, TreeCaretSelection)
164 { 164 {
165 setHTML(String("<div>This is outside of <p id='selection'>foo bar</p> the se lected node</div>")); 165 setHTML(String("<div>This is outside of <p id='selection'>foo bar</p> the se lected node</div>"));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 EXPECT_EQ(26u, surroundingText.endOffsetInContent()); 209 EXPECT_EQ(26u, surroundingText.endOffsetInContent());
210 } 210 }
211 } 211 }
212 212
213 TEST_F(SurroundingTextTest, TreeRangeSelection) 213 TEST_F(SurroundingTextTest, TreeRangeSelection)
214 { 214 {
215 setHTML(String("<div>This is outside of <p id='selection'>foo bar</p> the se lected node</div>")); 215 setHTML(String("<div>This is outside of <p id='selection'>foo bar</p> the se lected node</div>"));
216 216
217 { 217 {
218 VisibleSelection selection = select(0, 1); 218 VisibleSelection selection = select(0, 1);
219 SurroundingText surroundingText(*selection.firstRange(), 1); 219 SurroundingText surroundingText(*firstRangeOf(selection), 1);
220 220
221 EXPECT_EQ("fo", surroundingText.content().simplifyWhiteSpace()); 221 EXPECT_EQ("fo", surroundingText.content().simplifyWhiteSpace());
222 EXPECT_EQ(0u, surroundingText.startOffsetInContent()); 222 EXPECT_EQ(0u, surroundingText.startOffsetInContent());
223 EXPECT_EQ(1u, surroundingText.endOffsetInContent()); 223 EXPECT_EQ(1u, surroundingText.endOffsetInContent());
224 } 224 }
225 225
226 { 226 {
227 VisibleSelection selection = select(0, 3); 227 VisibleSelection selection = select(0, 3);
228 SurroundingText surroundingText(*selection.firstRange(), 12); 228 SurroundingText surroundingText(*firstRangeOf(selection), 12);
229 229
230 EXPECT_EQ("e of foo bar", surroundingText.content().simplifyWhiteSpace() ); 230 EXPECT_EQ("e of foo bar", surroundingText.content().simplifyWhiteSpace() );
231 EXPECT_EQ(5u, surroundingText.startOffsetInContent()); 231 EXPECT_EQ(5u, surroundingText.startOffsetInContent());
232 EXPECT_EQ(8u, surroundingText.endOffsetInContent()); 232 EXPECT_EQ(8u, surroundingText.endOffsetInContent());
233 } 233 }
234 234
235 { 235 {
236 VisibleSelection selection = select(0, 3); 236 VisibleSelection selection = select(0, 3);
237 SurroundingText surroundingText(*selection.firstRange(), 1337); 237 SurroundingText surroundingText(*firstRangeOf(selection), 1337);
238 238
239 EXPECT_EQ("This is outside of foo bar the selected node", surroundingTex t.content().simplifyWhiteSpace()); 239 EXPECT_EQ("This is outside of foo bar the selected node", surroundingTex t.content().simplifyWhiteSpace());
240 EXPECT_EQ(20u, surroundingText.startOffsetInContent()); 240 EXPECT_EQ(20u, surroundingText.startOffsetInContent());
241 EXPECT_EQ(23u, surroundingText.endOffsetInContent()); 241 EXPECT_EQ(23u, surroundingText.endOffsetInContent());
242 } 242 }
243 243
244 { 244 {
245 VisibleSelection selection = select(4, 7); 245 VisibleSelection selection = select(4, 7);
246 SurroundingText surroundingText(*selection.firstRange(), 12); 246 SurroundingText surroundingText(*firstRangeOf(selection), 12);
247 247
248 EXPECT_EQ("foo bar the se", surroundingText.content().simplifyWhiteSpace ()); 248 EXPECT_EQ("foo bar the se", surroundingText.content().simplifyWhiteSpace ());
249 EXPECT_EQ(5u, surroundingText.startOffsetInContent()); 249 EXPECT_EQ(5u, surroundingText.startOffsetInContent());
250 EXPECT_EQ(8u, surroundingText.endOffsetInContent()); 250 EXPECT_EQ(8u, surroundingText.endOffsetInContent());
251 } 251 }
252 252
253 { 253 {
254 VisibleSelection selection = select(0, 7); 254 VisibleSelection selection = select(0, 7);
255 SurroundingText surroundingText(*selection.firstRange(), 1337); 255 SurroundingText surroundingText(*firstRangeOf(selection), 1337);
256 256
257 EXPECT_EQ("This is outside of foo bar the selected node", surroundingTex t.content().simplifyWhiteSpace()); 257 EXPECT_EQ("This is outside of foo bar the selected node", surroundingTex t.content().simplifyWhiteSpace());
258 EXPECT_EQ(20u, surroundingText.startOffsetInContent()); 258 EXPECT_EQ(20u, surroundingText.startOffsetInContent());
259 EXPECT_EQ(27u, surroundingText.endOffsetInContent()); 259 EXPECT_EQ(27u, surroundingText.endOffsetInContent());
260 } 260 }
261 } 261 }
262 262
263 } // namespace blink 263 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/InputMethodController.cpp ('k') | Source/core/editing/VisibleSelection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698