Chromium Code Reviews

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

Issue 1995333002: Handle newCursorPosition correctly for Android's commitText() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change for aelias@'s review Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/Element.h" 8 #include "core/dom/Element.h"
9 #include "core/dom/Range.h" 9 #include "core/dom/Range.h"
10 #include "core/editing/Editor.h" 10 #include "core/editing/Editor.h"
(...skipping 102 matching lines...)
113 113
114 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) 114 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText)
115 { 115 {
116 insertHTMLElement( 116 insertHTMLElement(
117 "<div id='sample' contenteditable='true'>hello world</div>", "sample"); 117 "<div id='sample' contenteditable='true'>hello world</div>", "sample");
118 118
119 Vector<CompositionUnderline> underlines; 119 Vector<CompositionUnderline> underlines;
120 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 120 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
121 controller().setCompositionFromExistingText(underlines, 0, 5); 121 controller().setCompositionFromExistingText(underlines, 0, 5);
122 122
123 controller().confirmComposition(); 123 controller().replaceComposition();
124 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode()); 124 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode());
125 EXPECT_EQ(0, frame().selection().end().computeOffsetInContainerNode()); 125 EXPECT_EQ(0, frame().selection().end().computeOffsetInContainerNode());
126 } 126 }
127 127
128 TEST_F(InputMethodControllerTest, DeleteBySettingEmptyComposition) 128 TEST_F(InputMethodControllerTest, DeleteBySettingEmptyComposition)
129 { 129 {
130 HTMLInputElement* input = toHTMLInputElement( 130 HTMLInputElement* input = toHTMLInputElement(
131 insertHTMLElement("<input id='sample'>", "sample")); 131 insertHTMLElement("<input id='sample'>", "sample"));
132 132
133 input->setValue("foo "); 133 input->setValue("foo ");
(...skipping 49 matching lines...)
183 } 183 }
184 184
185 TEST_F(InputMethodControllerTest, ConfirmPasswordComposition) 185 TEST_F(InputMethodControllerTest, ConfirmPasswordComposition)
186 { 186 {
187 HTMLInputElement* input = toHTMLInputElement( 187 HTMLInputElement* input = toHTMLInputElement(
188 insertHTMLElement("<input id='sample' type='password' size='24'>", "samp le")); 188 insertHTMLElement("<input id='sample' type='password' size='24'>", "samp le"));
189 189
190 Vector<CompositionUnderline> underlines; 190 Vector<CompositionUnderline> underlines;
191 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 191 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
192 controller().setComposition("foo", underlines, 0, 3); 192 controller().setComposition("foo", underlines, 0, 3);
193 controller().confirmComposition(); 193 controller().replaceComposition();
194 194
195 EXPECT_STREQ("foo", input->value().utf8().data()); 195 EXPECT_STREQ("foo", input->value().utf8().data());
196 } 196 }
197 197
198 TEST_F(InputMethodControllerTest, SetCompositionForInputWithDifferentNewCursorPo sitions) 198 TEST_F(InputMethodControllerTest, SetCompositionForInputWithDifferentNewCursorPo sitions)
199 { 199 {
200 HTMLInputElement* input = toHTMLInputElement( 200 HTMLInputElement* input = toHTMLInputElement(
201 insertHTMLElement("<input id='sample'>", "sample")); 201 insertHTMLElement("<input id='sample'>", "sample"));
202 202
203 input->setValue("hello"); 203 input->setValue("hello");
(...skipping 194 matching lines...)
398 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); 398 EXPECT_EQ(1u, controller().getSelectionOffsets().start());
399 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); 399 EXPECT_EQ(1u, controller().getSelectionOffsets().end());
400 } 400 }
401 401
402 TEST_F(InputMethodControllerTest, InsertLineBreakAfterConfirmingText) 402 TEST_F(InputMethodControllerTest, InsertLineBreakAfterConfirmingText)
403 { 403 {
404 Element* div = insertHTMLElement( 404 Element* div = insertHTMLElement(
405 "<div id='sample' contenteditable='true'></div>", 405 "<div id='sample' contenteditable='true'></div>",
406 "sample"); 406 "sample");
407 407
408 controller().confirmCompositionOrInsertText("hello", InputMethodController:: ConfirmCompositionBehavior::KeepSelection); 408 controller().confirmComposition("hello");
409 EXPECT_STREQ("hello", div->innerText().utf8().data()); 409 EXPECT_STREQ("hello", div->innerText().utf8().data());
410 410
411 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); 411 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
412 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); 412 EXPECT_EQ(2u, controller().getSelectionOffsets().start());
413 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); 413 EXPECT_EQ(2u, controller().getSelectionOffsets().end());
414 414
415 frame().editor().insertLineBreak(); 415 frame().editor().insertLineBreak();
416 EXPECT_STREQ("he\nllo", div->innerText().utf8().data()); 416 EXPECT_STREQ("he\nllo", div->innerText().utf8().data());
417 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); 417 EXPECT_EQ(3u, controller().getSelectionOffsets().start());
418 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); 418 EXPECT_EQ(3u, controller().getSelectionOffsets().end());
(...skipping 18 matching lines...)
437 // Simulate composition in the |contentEditable|. 437 // Simulate composition in the |contentEditable|.
438 Vector<CompositionUnderline> underlines; 438 Vector<CompositionUnderline> underlines;
439 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 439 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
440 editable->focus(); 440 editable->focus();
441 441
442 document().setTitle(emptyString()); 442 document().setTitle(emptyString());
443 controller().setComposition("foo", underlines, 0, 3); 443 controller().setComposition("foo", underlines, 0, 3);
444 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", documen t().title().utf8().data()); 444 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", documen t().title().utf8().data());
445 445
446 document().setTitle(emptyString()); 446 document().setTitle(emptyString());
447 controller().confirmComposition(); 447 controller().replaceComposition();
448 // Last pair of InputEvent should also be inside composition scope. 448 // Last pair of InputEvent should also be inside composition scope.
449 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", documen t().title().utf8().data()); 449 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", documen t().title().utf8().data());
450 } 450 }
451 451
452 TEST_F(InputMethodControllerTest, CompositionInputEventData) 452 TEST_F(InputMethodControllerTest, CompositionInputEventData)
453 { 453 {
454 document().settings()->setScriptEnabled(true); 454 document().settings()->setScriptEnabled(true);
455 Element* editable = insertHTMLElement("<div id='sample' contentEditable='tru e'></div>", "sample"); 455 Element* editable = insertHTMLElement("<div id='sample' contentEditable='tru e'></div>", "sample");
456 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); 456 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION);
457 script->setInnerHTML( 457 script->setInnerHTML(
(...skipping 14 matching lines...)
472 472
473 document().setTitle(emptyString()); 473 document().setTitle(emptyString());
474 controller().setComposition("n", underlines, 0, 1); 474 controller().setComposition("n", underlines, 0, 1);
475 EXPECT_STREQ("beforeinput.data:n;input.data:n;", document().title().utf8().d ata()); 475 EXPECT_STREQ("beforeinput.data:n;input.data:n;", document().title().utf8().d ata());
476 476
477 document().setTitle(emptyString()); 477 document().setTitle(emptyString());
478 controller().setComposition("ni", underlines, 0, 1); 478 controller().setComposition("ni", underlines, 0, 1);
479 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data()); 479 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data());
480 480
481 document().setTitle(emptyString()); 481 document().setTitle(emptyString());
482 controller().confirmComposition(); 482 controller().replaceComposition();
483 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data()); 483 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data());
484 } 484 }
485 485
486 } // namespace blink 486 } // namespace blink
OLDNEW

Powered by Google App Engine