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

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

Issue 2954763002: [MarkersInter...Range #2-9] Change behavior of SpellChecker::GetSpellCheckMarkerTouchingSelection() (Closed)
Patch Set: Actually remove dependency 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.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/spellcheck/SpellChecker.h" 5 #include "core/editing/spellcheck/SpellChecker.h"
6 6
7 #include "core/editing/Editor.h" 7 #include "core/editing/Editor.h"
8 #include "core/editing/markers/DocumentMarkerController.h" 8 #include "core/editing/markers/DocumentMarkerController.h"
9 #include "core/editing/markers/SpellCheckMarker.h" 9 #include "core/editing/markers/SpellCheckMarker.h"
10 #include "core/editing/spellcheck/SpellCheckRequester.h" 10 #include "core/editing/spellcheck/SpellCheckRequester.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 121
122 ASSERT_EQ(1u, GetDocument().Markers().Markers().size()); 122 ASSERT_EQ(1u, GetDocument().Markers().Markers().size());
123 123
124 // The Spelling marker's description should be a newline-separated list of the 124 // The Spelling marker's description should be a newline-separated list of the
125 // suggested replacements 125 // suggested replacements
126 EXPECT_EQ( 126 EXPECT_EQ(
127 "spellcheck\nspillchuck", 127 "spellcheck\nspillchuck",
128 ToSpellCheckMarker(GetDocument().Markers().Markers()[0])->Description()); 128 ToSpellCheckMarker(GetDocument().Markers().Markers()[0])->Description());
129 } 129 }
130 130
131 TEST_F(SpellCheckerTest, 131 TEST_F(SpellCheckerTest, GetSpellCheckMarkerUnderSelection_FirstCharSelected) {
132 GetSpellCheckMarkerTouchingSelection_FirstCharSelected) {
133 SetBodyContent( 132 SetBodyContent(
134 "<div contenteditable>" 133 "<div contenteditable>"
135 "spllchck" 134 "spllchck"
136 "</div>"); 135 "</div>");
137 Element* div = GetDocument().QuerySelector("div"); 136 Element* div = GetDocument().QuerySelector("div");
138 Node* text = div->firstChild(); 137 Node* text = div->firstChild();
139 138
140 GetDocument().Markers().AddSpellingMarker( 139 GetDocument().Markers().AddSpellingMarker(
141 EphemeralRange(Position(text, 0), Position(text, 8))); 140 EphemeralRange(Position(text, 0), Position(text, 8)));
142 141
143 GetDocument().GetFrame()->Selection().SetSelection( 142 GetDocument().GetFrame()->Selection().SetSelection(
144 SelectionInDOMTree::Builder() 143 SelectionInDOMTree::Builder()
145 .SetBaseAndExtent(Position(text, 0), Position(text, 1)) 144 .SetBaseAndExtent(Position(text, 0), Position(text, 1))
146 .Build()); 145 .Build());
147 146
148 Optional<std::pair<Node*, SpellCheckMarker*>> result = 147 Optional<std::pair<Node*, SpellCheckMarker*>> result =
149 GetDocument() 148 GetDocument()
150 .GetFrame() 149 .GetFrame()
151 ->GetSpellChecker() 150 ->GetSpellChecker()
152 .GetSpellCheckMarkerTouchingSelection(); 151 .GetSpellCheckMarkerUnderSelection();
153 EXPECT_TRUE(result); 152 EXPECT_TRUE(result);
154 } 153 }
155 154
156 TEST_F(SpellCheckerTest, 155 TEST_F(SpellCheckerTest, GetSpellCheckMarkerUnderSelection_LastCharSelected) {
157 GetSpellCheckMarkerTouchingSelection_LastCharSelected) {
158 SetBodyContent( 156 SetBodyContent(
159 "<div contenteditable>" 157 "<div contenteditable>"
160 "spllchck" 158 "spllchck"
161 "</div>"); 159 "</div>");
162 Element* div = GetDocument().QuerySelector("div"); 160 Element* div = GetDocument().QuerySelector("div");
163 Node* text = div->firstChild(); 161 Node* text = div->firstChild();
164 162
165 GetDocument().Markers().AddSpellingMarker( 163 GetDocument().Markers().AddSpellingMarker(
166 EphemeralRange(Position(text, 0), Position(text, 8))); 164 EphemeralRange(Position(text, 0), Position(text, 8)));
167 165
168 GetDocument().GetFrame()->Selection().SetSelection( 166 GetDocument().GetFrame()->Selection().SetSelection(
169 SelectionInDOMTree::Builder() 167 SelectionInDOMTree::Builder()
170 .SetBaseAndExtent(Position(text, 7), Position(text, 8)) 168 .SetBaseAndExtent(Position(text, 7), Position(text, 8))
171 .Build()); 169 .Build());
172 170
173 Optional<std::pair<Node*, SpellCheckMarker*>> result = 171 Optional<std::pair<Node*, SpellCheckMarker*>> result =
174 GetDocument() 172 GetDocument()
175 .GetFrame() 173 .GetFrame()
176 ->GetSpellChecker() 174 ->GetSpellChecker()
177 .GetSpellCheckMarkerTouchingSelection(); 175 .GetSpellCheckMarkerUnderSelection();
178 EXPECT_TRUE(result); 176 EXPECT_TRUE(result);
179 } 177 }
180 178
181 TEST_F(SpellCheckerTest, 179 TEST_F(SpellCheckerTest,
182 GetSpellCheckMarkerTouchingSelection_SingleCharWordSelected) { 180 GetSpellCheckMarkerUnderSelection_SingleCharWordSelected) {
183 SetBodyContent( 181 SetBodyContent(
184 "<div contenteditable>" 182 "<div contenteditable>"
185 "s" 183 "s"
186 "</div>"); 184 "</div>");
187 Element* div = GetDocument().QuerySelector("div"); 185 Element* div = GetDocument().QuerySelector("div");
188 Node* text = div->firstChild(); 186 Node* text = div->firstChild();
189 187
190 GetDocument().Markers().AddSpellingMarker( 188 GetDocument().Markers().AddSpellingMarker(
191 EphemeralRange(Position(text, 0), Position(text, 1))); 189 EphemeralRange(Position(text, 0), Position(text, 1)));
192 190
193 GetDocument().GetFrame()->Selection().SetSelection( 191 GetDocument().GetFrame()->Selection().SetSelection(
194 SelectionInDOMTree::Builder() 192 SelectionInDOMTree::Builder()
195 .SetBaseAndExtent(Position(text, 0), Position(text, 1)) 193 .SetBaseAndExtent(Position(text, 0), Position(text, 1))
196 .Build()); 194 .Build());
197 195
198 Optional<std::pair<Node*, SpellCheckMarker*>> result = 196 Optional<std::pair<Node*, SpellCheckMarker*>> result =
199 GetDocument() 197 GetDocument()
200 .GetFrame() 198 .GetFrame()
201 ->GetSpellChecker() 199 ->GetSpellChecker()
202 .GetSpellCheckMarkerTouchingSelection(); 200 .GetSpellCheckMarkerUnderSelection();
203 EXPECT_TRUE(result); 201 EXPECT_TRUE(result);
204 } 202 }
205 203
206 TEST_F(SpellCheckerTest, 204 TEST_F(SpellCheckerTest,
207 GetSpellCheckMarkerTouchingSelection_CaretLeftOfSingleCharWord) { 205 GetSpellCheckMarkerUnderSelection_CaretLeftOfSingleCharWord) {
208 SetBodyContent( 206 SetBodyContent(
209 "<div contenteditable>" 207 "<div contenteditable>"
210 "s" 208 "s"
211 "</div>"); 209 "</div>");
212 Element* div = GetDocument().QuerySelector("div"); 210 Element* div = GetDocument().QuerySelector("div");
213 Node* text = div->firstChild(); 211 Node* text = div->firstChild();
214 212
215 GetDocument().Markers().AddSpellingMarker( 213 GetDocument().Markers().AddSpellingMarker(
216 EphemeralRange(Position(text, 0), Position(text, 1))); 214 EphemeralRange(Position(text, 0), Position(text, 1)));
217 215
218 GetDocument().GetFrame()->Selection().SetSelection( 216 GetDocument().GetFrame()->Selection().SetSelection(
219 SelectionInDOMTree::Builder() 217 SelectionInDOMTree::Builder()
220 .SetBaseAndExtent(Position(text, 0), Position(text, 0)) 218 .SetBaseAndExtent(Position(text, 0), Position(text, 0))
221 .Build()); 219 .Build());
222 220
223 Optional<std::pair<Node*, SpellCheckMarker*>> result = 221 Optional<std::pair<Node*, SpellCheckMarker*>> result =
224 GetDocument() 222 GetDocument()
225 .GetFrame() 223 .GetFrame()
226 ->GetSpellChecker() 224 ->GetSpellChecker()
227 .GetSpellCheckMarkerTouchingSelection(); 225 .GetSpellCheckMarkerUnderSelection();
228 EXPECT_TRUE(result); 226 EXPECT_FALSE(result);
229 } 227 }
230 228
231 TEST_F(SpellCheckerTest, 229 TEST_F(SpellCheckerTest,
232 GetSpellCheckMarkerTouchingSelection_CaretRightOfSingleCharWord) { 230 GetSpellCheckMarkerUnderSelection_CaretRightOfSingleCharWord) {
233 SetBodyContent( 231 SetBodyContent(
234 "<div contenteditable>" 232 "<div contenteditable>"
235 "s" 233 "s"
236 "</div>"); 234 "</div>");
237 Element* div = GetDocument().QuerySelector("div"); 235 Element* div = GetDocument().QuerySelector("div");
238 Node* text = div->firstChild(); 236 Node* text = div->firstChild();
239 237
240 GetDocument().Markers().AddSpellingMarker( 238 GetDocument().Markers().AddSpellingMarker(
241 EphemeralRange(Position(text, 0), Position(text, 1))); 239 EphemeralRange(Position(text, 0), Position(text, 1)));
242 240
243 GetDocument().GetFrame()->Selection().SetSelection( 241 GetDocument().GetFrame()->Selection().SetSelection(
244 SelectionInDOMTree::Builder() 242 SelectionInDOMTree::Builder()
245 .SetBaseAndExtent(Position(text, 1), Position(text, 1)) 243 .SetBaseAndExtent(Position(text, 1), Position(text, 1))
246 .Build()); 244 .Build());
247 245
248 Optional<std::pair<Node*, SpellCheckMarker*>> result = 246 Optional<std::pair<Node*, SpellCheckMarker*>> result =
249 GetDocument() 247 GetDocument()
250 .GetFrame() 248 .GetFrame()
251 ->GetSpellChecker() 249 ->GetSpellChecker()
252 .GetSpellCheckMarkerTouchingSelection(); 250 .GetSpellCheckMarkerUnderSelection();
253 EXPECT_TRUE(result); 251 EXPECT_FALSE(result);
254 } 252 }
255 253
256 TEST_F(SpellCheckerTest, 254 TEST_F(SpellCheckerTest,
257 GetSpellCheckMarkerTouchingSelection_CaretLeftOfMultiCharWord) { 255 GetSpellCheckMarkerUnderSelection_CaretLeftOfMultiCharWord) {
258 SetBodyContent( 256 SetBodyContent(
259 "<div contenteditable>" 257 "<div contenteditable>"
260 "spllchck" 258 "spllchck"
261 "</div>"); 259 "</div>");
262 Element* div = GetDocument().QuerySelector("div"); 260 Element* div = GetDocument().QuerySelector("div");
263 Node* text = div->firstChild(); 261 Node* text = div->firstChild();
264 262
265 GetDocument().Markers().AddSpellingMarker( 263 GetDocument().Markers().AddSpellingMarker(
266 EphemeralRange(Position(text, 0), Position(text, 8))); 264 EphemeralRange(Position(text, 0), Position(text, 8)));
267 265
268 GetDocument().GetFrame()->Selection().SetSelection( 266 GetDocument().GetFrame()->Selection().SetSelection(
269 SelectionInDOMTree::Builder() 267 SelectionInDOMTree::Builder()
270 .SetBaseAndExtent(Position(text, 0), Position(text, 0)) 268 .SetBaseAndExtent(Position(text, 0), Position(text, 0))
271 .Build()); 269 .Build());
272 270
273 Optional<std::pair<Node*, SpellCheckMarker*>> result = 271 Optional<std::pair<Node*, SpellCheckMarker*>> result =
274 GetDocument() 272 GetDocument()
275 .GetFrame() 273 .GetFrame()
276 ->GetSpellChecker() 274 ->GetSpellChecker()
277 .GetSpellCheckMarkerTouchingSelection(); 275 .GetSpellCheckMarkerUnderSelection();
278 EXPECT_TRUE(result); 276 EXPECT_FALSE(result);
279 } 277 }
280 278
281 TEST_F(SpellCheckerTest, 279 TEST_F(SpellCheckerTest,
282 GetSpellCheckMarkerTouchingSelection_CaretRightOfMultiCharWord) { 280 GetSpellCheckMarkerUnderSelection_CaretRightOfMultiCharWord) {
283 SetBodyContent( 281 SetBodyContent(
284 "<div contenteditable>" 282 "<div contenteditable>"
285 "spllchck" 283 "spllchck"
286 "</div>"); 284 "</div>");
287 Element* div = GetDocument().QuerySelector("div"); 285 Element* div = GetDocument().QuerySelector("div");
288 Node* text = div->firstChild(); 286 Node* text = div->firstChild();
289 287
290 GetDocument().Markers().AddSpellingMarker( 288 GetDocument().Markers().AddSpellingMarker(
291 EphemeralRange(Position(text, 0), Position(text, 8))); 289 EphemeralRange(Position(text, 0), Position(text, 8)));
292 290
293 GetDocument().GetFrame()->Selection().SetSelection( 291 GetDocument().GetFrame()->Selection().SetSelection(
294 SelectionInDOMTree::Builder() 292 SelectionInDOMTree::Builder()
295 .SetBaseAndExtent(Position(text, 8), Position(text, 8)) 293 .SetBaseAndExtent(Position(text, 8), Position(text, 8))
296 .Build()); 294 .Build());
297 295
298 Optional<std::pair<Node*, SpellCheckMarker*>> result = 296 Optional<std::pair<Node*, SpellCheckMarker*>> result =
299 GetDocument() 297 GetDocument()
300 .GetFrame() 298 .GetFrame()
301 ->GetSpellChecker() 299 ->GetSpellChecker()
302 .GetSpellCheckMarkerTouchingSelection(); 300 .GetSpellCheckMarkerUnderSelection();
303 EXPECT_TRUE(result); 301 EXPECT_FALSE(result);
304 } 302 }
305 303
306 TEST_F(SpellCheckerTest, 304 TEST_F(SpellCheckerTest, GetSpellCheckMarkerUnderSelection_CaretMiddleOfWord) {
307 GetSpellCheckMarkerTouchingSelection_CaretMiddleOfWord) {
308 SetBodyContent( 305 SetBodyContent(
309 "<div contenteditable>" 306 "<div contenteditable>"
310 "spllchck" 307 "spllchck"
311 "</div>"); 308 "</div>");
312 Element* div = GetDocument().QuerySelector("div"); 309 Element* div = GetDocument().QuerySelector("div");
313 Node* text = div->firstChild(); 310 Node* text = div->firstChild();
314 311
315 GetDocument().Markers().AddSpellingMarker( 312 GetDocument().Markers().AddSpellingMarker(
316 EphemeralRange(Position(text, 0), Position(text, 8))); 313 EphemeralRange(Position(text, 0), Position(text, 8)));
317 314
318 GetDocument().GetFrame()->Selection().SetSelection( 315 GetDocument().GetFrame()->Selection().SetSelection(
319 SelectionInDOMTree::Builder() 316 SelectionInDOMTree::Builder()
320 .SetBaseAndExtent(Position(text, 4), Position(text, 4)) 317 .SetBaseAndExtent(Position(text, 4), Position(text, 4))
321 .Build()); 318 .Build());
322 319
323 Optional<std::pair<Node*, SpellCheckMarker*>> result = 320 Optional<std::pair<Node*, SpellCheckMarker*>> result =
324 GetDocument() 321 GetDocument()
325 .GetFrame() 322 .GetFrame()
326 ->GetSpellChecker() 323 ->GetSpellChecker()
327 .GetSpellCheckMarkerTouchingSelection(); 324 .GetSpellCheckMarkerUnderSelection();
328 EXPECT_TRUE(result); 325 EXPECT_TRUE(result);
329 } 326 }
330 327
331 TEST_F(SpellCheckerTest, 328 TEST_F(SpellCheckerTest,
332 GetSpellCheckMarkerTouchingSelection_CaretOneCharLeftOfMisspelling) { 329 GetSpellCheckMarkerUnderSelection_CaretOneCharLeftOfMisspelling) {
333 SetBodyContent( 330 SetBodyContent(
334 "<div contenteditable>" 331 "<div contenteditable>"
335 "a spllchck" 332 "a spllchck"
336 "</div>"); 333 "</div>");
337 Element* div = GetDocument().QuerySelector("div"); 334 Element* div = GetDocument().QuerySelector("div");
338 Node* text = div->firstChild(); 335 Node* text = div->firstChild();
339 336
340 GetDocument().Markers().AddSpellingMarker( 337 GetDocument().Markers().AddSpellingMarker(
341 EphemeralRange(Position(text, 2), Position(text, 10))); 338 EphemeralRange(Position(text, 2), Position(text, 10)));
342 339
343 GetDocument().GetFrame()->Selection().SetSelection( 340 GetDocument().GetFrame()->Selection().SetSelection(
344 SelectionInDOMTree::Builder() 341 SelectionInDOMTree::Builder()
345 .SetBaseAndExtent(Position(text, 1), Position(text, 1)) 342 .SetBaseAndExtent(Position(text, 1), Position(text, 1))
346 .Build()); 343 .Build());
347 344
348 Optional<std::pair<Node*, SpellCheckMarker*>> result = 345 Optional<std::pair<Node*, SpellCheckMarker*>> result =
349 GetDocument() 346 GetDocument()
350 .GetFrame() 347 .GetFrame()
351 ->GetSpellChecker() 348 ->GetSpellChecker()
352 .GetSpellCheckMarkerTouchingSelection(); 349 .GetSpellCheckMarkerUnderSelection();
353 EXPECT_FALSE(result); 350 EXPECT_FALSE(result);
354 } 351 }
355 352
356 TEST_F(SpellCheckerTest, 353 TEST_F(SpellCheckerTest,
357 GetSpellCheckMarkerTouchingSelection_CaretOneCharRightOfMisspelling) { 354 GetSpellCheckMarkerUnderSelection_CaretOneCharRightOfMisspelling) {
358 SetBodyContent( 355 SetBodyContent(
359 "<div contenteditable>" 356 "<div contenteditable>"
360 "spllchck a" 357 "spllchck a"
361 "</div>"); 358 "</div>");
362 Element* div = GetDocument().QuerySelector("div"); 359 Element* div = GetDocument().QuerySelector("div");
363 Node* text = div->firstChild(); 360 Node* text = div->firstChild();
364 361
365 GetDocument().Markers().AddSpellingMarker( 362 GetDocument().Markers().AddSpellingMarker(
366 EphemeralRange(Position(text, 0), Position(text, 8))); 363 EphemeralRange(Position(text, 0), Position(text, 8)));
367 364
368 GetDocument().GetFrame()->Selection().SetSelection( 365 GetDocument().GetFrame()->Selection().SetSelection(
369 SelectionInDOMTree::Builder() 366 SelectionInDOMTree::Builder()
370 .SetBaseAndExtent(Position(text, 9), Position(text, 9)) 367 .SetBaseAndExtent(Position(text, 9), Position(text, 9))
371 .Build()); 368 .Build());
372 369
373 Optional<std::pair<Node*, SpellCheckMarker*>> result = 370 Optional<std::pair<Node*, SpellCheckMarker*>> result =
374 GetDocument() 371 GetDocument()
375 .GetFrame() 372 .GetFrame()
376 ->GetSpellChecker() 373 ->GetSpellChecker()
377 .GetSpellCheckMarkerTouchingSelection(); 374 .GetSpellCheckMarkerUnderSelection();
378 EXPECT_FALSE(result); 375 EXPECT_FALSE(result);
379 } 376 }
380 377
381 } // namespace blink 378 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698