OLD | NEW |
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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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().confirmComposition(); |
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, SetCompositionForInputWithNewCursorPositions) |
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"); |
204 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); | 204 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); |
205 EXPECT_STREQ("hello", input->value().utf8().data()); | 205 EXPECT_STREQ("hello", input->value().utf8().data()); |
206 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); | 206 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); |
207 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); | 207 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); |
208 | 208 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 EXPECT_EQ(7u, controller().getSelectionOffsets().end()); | 245 EXPECT_EQ(7u, controller().getSelectionOffsets().end()); |
246 | 246 |
247 // The cursor exceeds right boundary. | 247 // The cursor exceeds right boundary. |
248 // "heABllo*". | 248 // "heABllo*". |
249 controller().setComposition("AB", underlines, 100, 100); | 249 controller().setComposition("AB", underlines, 100, 100); |
250 EXPECT_STREQ("heABllo", input->value().utf8().data()); | 250 EXPECT_STREQ("heABllo", input->value().utf8().data()); |
251 EXPECT_EQ(7u, controller().getSelectionOffsets().start()); | 251 EXPECT_EQ(7u, controller().getSelectionOffsets().start()); |
252 EXPECT_EQ(7u, controller().getSelectionOffsets().end()); | 252 EXPECT_EQ(7u, controller().getSelectionOffsets().end()); |
253 } | 253 } |
254 | 254 |
255 TEST_F(InputMethodControllerTest, SetCompositionForContentEditableWithDifferentN
ewCursorPositions) | 255 TEST_F(InputMethodControllerTest, SetCompositionForContentEditableWithNewCursorP
ositions) |
256 { | 256 { |
257 // There are 7 nodes and 5+1+5+1+3+4+3 characters: "hello", '\n', "world", "
\n", "012", "3456", "789". | 257 // There are 7 nodes and 5+1+5+1+3+4+3 characters: "hello", '\n', "world", "
\n", "012", "3456", "789". |
258 Element* div = insertHTMLElement( | 258 Element* div = insertHTMLElement( |
259 "<div id='sample' contenteditable='true'>" | 259 "<div id='sample' contenteditable='true'>" |
260 "hello" | 260 "hello" |
261 "<div id='sample2' contenteditable='true'>world" | 261 "<div id='sample2' contenteditable='true'>world" |
262 "<p>012<b>3456</b><i>789</i></p>" | 262 "<p>012<b>3456</b><i>789</i></p>" |
263 "</div>" | 263 "</div>" |
264 "</div>", | 264 "</div>", |
265 "sample"); | 265 "sample"); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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().commitComposition("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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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().confirmComposition(); |
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 |
OLD | NEW |