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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 EXPECT_STREQ("foo", input->value().utf8().data()); | 78 EXPECT_STREQ("foo", input->value().utf8().data()); |
79 | 79 |
80 input->setValue( | 80 input->setValue( |
81 String::fromUTF8("foo\xF0\x9F\x8F\x86")); // U+1F3C6 == "trophy" | 81 String::fromUTF8("foo\xF0\x9F\x8F\x86")); // U+1F3C6 == "trophy" |
82 document().updateStyleAndLayout(); | 82 document().updateStyleAndLayout(); |
83 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 83 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
84 EXPECT_STREQ("foo\xF0\x9F\x8F\x86", input->value().utf8().data()); | 84 EXPECT_STREQ("foo\xF0\x9F\x8F\x86", input->value().utf8().data()); |
85 controller().extendSelectionAndDelete(1, 0); | 85 controller().extendSelectionAndDelete(1, 0); |
86 EXPECT_STREQ("foo", input->value().utf8().data()); | 86 EXPECT_STREQ("foo", input->value().utf8().data()); |
87 | 87 |
88 input->setValue(String::fromUTF8( | 88 // composed U+0E01 "ka kai" + U+0E49 "mai tho" |
89 "foo\xE0\xB8\x81\xE0\xB9\x89")); // composed U+0E01 "ka kai" + U+0E49 "ma
i tho" | 89 input->setValue(String::fromUTF8("foo\xE0\xB8\x81\xE0\xB9\x89")); |
90 document().updateStyleAndLayout(); | 90 document().updateStyleAndLayout(); |
91 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 91 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
92 EXPECT_STREQ("foo\xE0\xB8\x81\xE0\xB9\x89", input->value().utf8().data()); | 92 EXPECT_STREQ("foo\xE0\xB8\x81\xE0\xB9\x89", input->value().utf8().data()); |
93 controller().extendSelectionAndDelete(1, 0); | 93 controller().extendSelectionAndDelete(1, 0); |
94 EXPECT_STREQ("foo", input->value().utf8().data()); | 94 EXPECT_STREQ("foo", input->value().utf8().data()); |
95 | 95 |
96 input->setValue("fooX"); | 96 input->setValue("fooX"); |
97 document().updateStyleAndLayout(); | 97 document().updateStyleAndLayout(); |
98 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 98 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
99 EXPECT_STREQ("fooX", input->value().utf8().data()); | 99 EXPECT_STREQ("fooX", input->value().utf8().data()); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 // The caret exceeds right boundary. | 254 // The caret exceeds right boundary. |
255 // "heABllo*". | 255 // "heABllo*". |
256 controller().setComposition("AB", underlines, 100, 100); | 256 controller().setComposition("AB", underlines, 100, 100); |
257 EXPECT_STREQ("heABllo", input->value().utf8().data()); | 257 EXPECT_STREQ("heABllo", input->value().utf8().data()); |
258 EXPECT_EQ(7u, controller().getSelectionOffsets().start()); | 258 EXPECT_EQ(7u, controller().getSelectionOffsets().start()); |
259 EXPECT_EQ(7u, controller().getSelectionOffsets().end()); | 259 EXPECT_EQ(7u, controller().getSelectionOffsets().end()); |
260 } | 260 } |
261 | 261 |
262 TEST_F(InputMethodControllerTest, | 262 TEST_F(InputMethodControllerTest, |
263 SetCompositionForContentEditableWithNewCaretPositions) { | 263 SetCompositionForContentEditableWithNewCaretPositions) { |
264 // There are 7 nodes and 5+1+5+1+3+4+3 characters: "hello", '\n', "world", "\n
", "012", "3456", "789". | 264 // There are 7 nodes and 5+1+5+1+3+4+3 characters: "hello", '\n', "world", |
| 265 // "\n", "012", "3456", "789". |
265 Element* div = insertHTMLElement( | 266 Element* div = insertHTMLElement( |
266 "<div id='sample' contenteditable='true'>" | 267 "<div id='sample' contenteditable='true'>" |
267 "hello" | 268 "hello" |
268 "<div id='sample2' contenteditable='true'>world" | 269 "<div id='sample2' contenteditable='true'>world" |
269 "<p>012<b>3456</b><i>789</i></p>" | 270 "<p>012<b>3456</b><i>789</i></p>" |
270 "</div>" | 271 "</div>" |
271 "</div>", | 272 "</div>", |
272 "sample"); | 273 "sample"); |
273 | 274 |
274 controller().setEditableSelectionOffsets(PlainTextRange(17, 17)); | 275 controller().setEditableSelectionOffsets(PlainTextRange(17, 17)); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", | 488 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", |
488 document().title().utf8().data()); | 489 document().title().utf8().data()); |
489 | 490 |
490 document().setTitle(emptyString()); | 491 document().setTitle(emptyString()); |
491 controller().finishComposingText(InputMethodController::KeepSelection); | 492 controller().finishComposingText(InputMethodController::KeepSelection); |
492 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", | 493 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", |
493 document().title().utf8().data()); | 494 document().title().utf8().data()); |
494 } | 495 } |
495 | 496 |
496 } // namespace blink | 497 } // namespace blink |
OLD | NEW |