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

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

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

Powered by Google App Engine
This is Rietveld 408576698