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

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

Issue 1889053003: Fix InputConnection.deleteSurroundingText() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change some comments. Created 4 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 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 "core/editing/InputMethodController.h" 5 #include "core/editing/InputMethodController.h"
6 6
7 #include "core/dom/Element.h" 7 #include "core/dom/Element.h"
8 #include "core/dom/Range.h" 8 #include "core/dom/Range.h"
9 #include "core/editing/FrameSelection.h" 9 #include "core/editing/FrameSelection.h"
10 #include "core/events/MouseEvent.h" 10 #include "core/events/MouseEvent.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 insertHTMLElement("<input id='sample' type='password' size='24'>", "samp le")); 187 insertHTMLElement("<input id='sample' type='password' size='24'>", "samp le"));
188 188
189 Vector<CompositionUnderline> underlines; 189 Vector<CompositionUnderline> underlines;
190 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 190 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
191 controller().setComposition("foo", underlines, 0, 3); 191 controller().setComposition("foo", underlines, 0, 3);
192 controller().confirmComposition(); 192 controller().confirmComposition();
193 193
194 EXPECT_STREQ("foo", input->value().utf8().data()); 194 EXPECT_STREQ("foo", input->value().utf8().data());
195 } 195 }
196 196
197 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithEmptyText)
198 {
199 HTMLInputElement* input = toHTMLInputElement(
200 insertHTMLElement("<input id='sample'>", "sample"));
201
202 input->setValue("");
203 EXPECT_STREQ("", input->value().utf8().data());
204 controller().deleteSurroundingText(0, 0);
205 EXPECT_STREQ("", input->value().utf8().data());
206
207 input->setValue("");
208 EXPECT_STREQ("", input->value().utf8().data());
209 controller().deleteSurroundingText(1, 0);
210 EXPECT_STREQ("", input->value().utf8().data());
211
212 input->setValue("");
213 EXPECT_STREQ("", input->value().utf8().data());
214 controller().deleteSurroundingText(0, 1);
215 EXPECT_STREQ("", input->value().utf8().data());
216
217 input->setValue("");
218 EXPECT_STREQ("", input->value().utf8().data());
219 controller().deleteSurroundingText(1, 1);
220 EXPECT_STREQ("", input->value().utf8().data());
221 }
222
223 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithRangeSelection)
224 {
225 HTMLInputElement* input = toHTMLInputElement(
226 insertHTMLElement("<input id='sample'>", "sample"));
227
228 input->setValue("hello");
229 EXPECT_STREQ("hello", input->value().utf8().data());
230 controller().setEditableSelectionOffsets(PlainTextRange(1, 4));
231 controller().deleteSurroundingText(0, 0);
232 EXPECT_STREQ("hello", input->value().utf8().data());
233
234 input->setValue("hello");
235 EXPECT_STREQ("hello", input->value().utf8().data());
236 controller().setEditableSelectionOffsets(PlainTextRange(1, 4));
237 controller().deleteSurroundingText(1, 1);
238 EXPECT_STREQ("ell", input->value().utf8().data());
239
240 input->setValue("hello");
241 EXPECT_STREQ("hello", input->value().utf8().data());
242 controller().setEditableSelectionOffsets(PlainTextRange(1, 4));
243 controller().deleteSurroundingText(100, 0);
244 EXPECT_STREQ("ello", input->value().utf8().data());
245
246 input->setValue("hello");
247 EXPECT_STREQ("hello", input->value().utf8().data());
248 controller().setEditableSelectionOffsets(PlainTextRange(1, 4));
249 controller().deleteSurroundingText(0, 100);
250 EXPECT_STREQ("hell", input->value().utf8().data());
251
252 input->setValue("hello");
253 EXPECT_STREQ("hello", input->value().utf8().data());
254 controller().setEditableSelectionOffsets(PlainTextRange(1, 4));
255 controller().deleteSurroundingText(100, 100);
256 EXPECT_STREQ("ell", input->value().utf8().data());
257 }
258
259 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithCursorSelection)
260 {
261 HTMLInputElement* input = toHTMLInputElement(
262 insertHTMLElement("<input id='sample'>", "sample"));
263
264 input->setValue("hello");
265 EXPECT_STREQ("hello", input->value().utf8().data());
266 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
267 controller().deleteSurroundingText(1, 0);
268 EXPECT_STREQ("hllo", input->value().utf8().data());
269
270 input->setValue("hello");
271 EXPECT_STREQ("hello", input->value().utf8().data());
272 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
273 controller().deleteSurroundingText(0, 1);
274 EXPECT_STREQ("helo", input->value().utf8().data());
275
276 input->setValue("hello");
277 EXPECT_STREQ("hello", input->value().utf8().data());
278 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
279 controller().deleteSurroundingText(0, 0);
280 EXPECT_STREQ("hello", input->value().utf8().data());
281
282 input->setValue("hello");
283 EXPECT_STREQ("hello", input->value().utf8().data());
284 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
285 controller().deleteSurroundingText(1, 1);
286 EXPECT_STREQ("hlo", input->value().utf8().data());
287
288 input->setValue("hello");
289 EXPECT_STREQ("hello", input->value().utf8().data());
290 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
291 controller().deleteSurroundingText(100, 0);
292 EXPECT_STREQ("llo", input->value().utf8().data());
293
294 input->setValue("hello");
295 EXPECT_STREQ("hello", input->value().utf8().data());
296 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
297 controller().deleteSurroundingText(0, 100);
298 EXPECT_STREQ("he", input->value().utf8().data());
299
300 input->setValue("hello");
301 EXPECT_STREQ("hello", input->value().utf8().data());
302 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
303 controller().deleteSurroundingText(100, 100);
304 EXPECT_STREQ("", input->value().utf8().data());
305
306 input->setValue("h");
307 EXPECT_STREQ("h", input->value().utf8().data());
308 controller().setEditableSelectionOffsets(PlainTextRange(1, 1));
309 controller().deleteSurroundingText(1, 0);
310 EXPECT_STREQ("", input->value().utf8().data());
311
312 input->setValue("h");
313 EXPECT_STREQ("h", input->value().utf8().data());
314 controller().setEditableSelectionOffsets(PlainTextRange(0, 0));
315 controller().deleteSurroundingText(0, 1);
316 EXPECT_STREQ("", input->value().utf8().data());
317 }
318
319 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithMultiCodeTextOnTheLef t)
320 {
321 HTMLInputElement* input = toHTMLInputElement(
322 insertHTMLElement("<input id='sample'>", "sample"));
323
324 // U+2605 == "black star". It takes up 1 space.
325 input->setValue(String::fromUTF8("foo\xE2\x98\x85"));
326 controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
327 EXPECT_STREQ("foo\xE2\x98\x85", input->value().utf8().data());
328 controller().deleteSurroundingText(1, 0);
329 EXPECT_STREQ("foo", input->value().utf8().data());
330
331 // U+1F3C6 == "trophy". It takes up 2 space.
332 input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86"));
333 controller().setEditableSelectionOffsets(PlainTextRange(5, 5));
334 EXPECT_STREQ("foo\xF0\x9F\x8F\x86", input->value().utf8().data());
335 controller().deleteSurroundingText(1, 0);
336 EXPECT_STREQ("foo", input->value().utf8().data());
337
338 // composed U+0E01 "ka kai" + U+0E49 "mai tho". It takes up 2 space.
339 input->setValue(String::fromUTF8("foo\xE0\xB8\x81\xE0\xB9\x89"));
340 controller().setEditableSelectionOffsets(PlainTextRange(5, 5));
341 EXPECT_STREQ("foo\xE0\xB8\x81\xE0\xB9\x89", input->value().utf8().data());
342 controller().deleteSurroundingText(1, 0);
343 EXPECT_STREQ("foo", input->value().utf8().data());
344
345 // "trophy" + "trophy".
346 input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86"));
347 controller().setEditableSelectionOffsets(PlainTextRange(7, 7));
348 EXPECT_STREQ("foo\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86", input->value().utf8().da ta());
349 controller().deleteSurroundingText(2, 0);
350 EXPECT_STREQ("foo\xF0\x9F\x8F\x86", input->value().utf8().data());
351
352 // "trophy" + "trophy".
353 input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86"));
354 controller().setEditableSelectionOffsets(PlainTextRange(7, 7));
355 EXPECT_STREQ("foo\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86", input->value().utf8().da ta());
356 controller().deleteSurroundingText(3, 0);
357 EXPECT_STREQ("foo", input->value().utf8().data());
358
359 // "trophy" + "trophy".
360 input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86"));
361 controller().setEditableSelectionOffsets(PlainTextRange(7, 7));
362 EXPECT_STREQ("foo\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86", input->value().utf8().da ta());
363 controller().deleteSurroundingText(4, 0);
364 EXPECT_STREQ("foo", input->value().utf8().data());
365
366 // "trophy" + "trophy".
367 input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86"));
368 controller().setEditableSelectionOffsets(PlainTextRange(7, 7));
369 EXPECT_STREQ("foo\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86", input->value().utf8().da ta());
370 controller().deleteSurroundingText(5, 0);
371 EXPECT_STREQ("fo", input->value().utf8().data());
372 }
373
374 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithMultiCodeTextOnTheRig ht)
375 {
376 HTMLInputElement* input = toHTMLInputElement(
377 insertHTMLElement("<input id='sample'>", "sample"));
378
379 // U+2605 == "black star". It takes up 1 space.
380 input->setValue(String::fromUTF8("\xE2\x98\x85 foo"));
381 controller().setEditableSelectionOffsets(PlainTextRange(0, 0));
382 EXPECT_STREQ("\xE2\x98\x85 foo", input->value().utf8().data());
383 controller().deleteSurroundingText(0, 1);
384 EXPECT_STREQ(" foo", input->value().utf8().data());
385
386 // U+1F3C6 == "trophy". It takes up 2 space.
387 input->setValue(String::fromUTF8("\xF0\x9F\x8F\x86 foo"));
388 controller().setEditableSelectionOffsets(PlainTextRange(0, 0));
389 EXPECT_STREQ("\xF0\x9F\x8F\x86 foo", input->value().utf8().data());
390 controller().deleteSurroundingText(0, 1);
391 EXPECT_STREQ(" foo", input->value().utf8().data());
392
393 // composed U+0E01 "ka kai" + U+0E49 "mai tho". It takes up 2 space.
394 input->setValue(String::fromUTF8("\xE0\xB8\x81\xE0\xB9\x89 foo"));
395 controller().setEditableSelectionOffsets(PlainTextRange(0, 0));
396 EXPECT_STREQ("\xE0\xB8\x81\xE0\xB9\x89 foo", input->value().utf8().data());
397 controller().deleteSurroundingText(0, 1);
398 EXPECT_STREQ(" foo", input->value().utf8().data());
399
400 // "trophy" + "trophy".
401 input->setValue(String::fromUTF8("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86 foo"));
402 controller().setEditableSelectionOffsets(PlainTextRange(0, 0));
403 EXPECT_STREQ("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86 foo", input->value().utf8().d ata());
404 controller().deleteSurroundingText(0, 2);
405 EXPECT_STREQ("\xF0\x9F\x8F\x86 foo", input->value().utf8().data());
406
407 // "trophy" + "trophy".
408 input->setValue(String::fromUTF8("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86 foo"));
409 controller().setEditableSelectionOffsets(PlainTextRange(0, 0));
410 EXPECT_STREQ("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86 foo", input->value().utf8().d ata());
411 controller().deleteSurroundingText(0, 3);
412 EXPECT_STREQ(" foo", input->value().utf8().data());
413
414 // "trophy" + "trophy".
415 input->setValue(String::fromUTF8("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86 foo"));
416 controller().setEditableSelectionOffsets(PlainTextRange(0, 0));
417 EXPECT_STREQ("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86 foo", input->value().utf8().d ata());
418 controller().deleteSurroundingText(0, 4);
419 EXPECT_STREQ(" foo", input->value().utf8().data());
420
421 // "trophy" + "trophy".
422 input->setValue(String::fromUTF8("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86 foo"));
423 controller().setEditableSelectionOffsets(PlainTextRange(0, 0));
424 EXPECT_STREQ("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86 foo", input->value().utf8().d ata());
425 controller().deleteSurroundingText(0, 5);
426 EXPECT_STREQ("foo", input->value().utf8().data());
427 }
428
429 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithMultiCodeTextOnBothSi des)
430 {
431 HTMLInputElement* input = toHTMLInputElement(
432 insertHTMLElement("<input id='sample'>", "sample"));
433
434 // "trophy" + "trophy".
435 input->setValue(String::fromUTF8("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86"));
436 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
437 EXPECT_STREQ("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86", input->value().utf8().data( ));
438 controller().deleteSurroundingText(1, 1);
439 EXPECT_STREQ("", input->value().utf8().data());
440 }
441
442 TEST_F(InputMethodControllerTest, DeleteSurroundingTextForMultipleNodes)
443 {
yabinh 2016/07/06 02:15:02 There are 3 child nodes: "hello", "\n", "world".
444 Element* div = insertHTMLElement(
445 "<div id='sample' contenteditable='true'>"
446 "hello"
447 "<div id='sample2' contenteditable='true'>world</div>"
448 "</div>",
449 "sample");
450
451 controller().setEditableSelectionOffsets(PlainTextRange(6, 6));
452 EXPECT_STREQ("hello\nworld", div->innerText().utf8().data());
453 EXPECT_EQ(6u, controller().getSelectionOffsets().start());
454 EXPECT_EQ(6u, controller().getSelectionOffsets().end());
455
yabinh 2016/07/06 02:15:02 Cursor is before the third child node.
456 controller().deleteSurroundingText(1, 0);
457 EXPECT_STREQ("helloworld", div->innerText().utf8().data());
458
459 controller().deleteSurroundingText(5, 0);
460 EXPECT_STREQ("world", div->innerText().utf8().data());
461 }
462
197 TEST_F(InputMethodControllerTest, SetCompositionForInputWithDifferentNewCursorPo sitions) 463 TEST_F(InputMethodControllerTest, SetCompositionForInputWithDifferentNewCursorPo sitions)
198 { 464 {
199 HTMLInputElement* input = toHTMLInputElement( 465 HTMLInputElement* input = toHTMLInputElement(
200 insertHTMLElement("<input id='sample'>", "sample")); 466 insertHTMLElement("<input id='sample'>", "sample"));
201 467
202 input->setValue("hello"); 468 input->setValue("hello");
203 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); 469 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
204 EXPECT_STREQ("hello", input->value().utf8().data()); 470 EXPECT_STREQ("hello", input->value().utf8().data());
205 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); 471 EXPECT_EQ(2u, controller().getSelectionOffsets().start());
206 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); 472 EXPECT_EQ(2u, controller().getSelectionOffsets().end());
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 controller().setComposition("foo", underlines, 0, 3); 637 controller().setComposition("foo", underlines, 0, 3);
372 EXPECT_STREQ("beforeinput.isComposing:true", document().title().utf8().data( )); 638 EXPECT_STREQ("beforeinput.isComposing:true", document().title().utf8().data( ));
373 639
374 document().setTitle(emptyString()); 640 document().setTitle(emptyString());
375 controller().confirmComposition(); 641 controller().confirmComposition();
376 // Last 'beforeinput' should also be inside composition scope. 642 // Last 'beforeinput' should also be inside composition scope.
377 EXPECT_STREQ("beforeinput.isComposing:true", document().title().utf8().data( )); 643 EXPECT_STREQ("beforeinput.isComposing:true", document().title().utf8().data( ));
378 } 644 }
379 645
380 } // namespace blink 646 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698