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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 element->focus(); | 50 element->focus(); |
51 return element; | 51 return element; |
52 } | 52 } |
53 | 53 |
54 TEST_F(InputMethodControllerTest, BackspaceFromEndOfInput) | 54 TEST_F(InputMethodControllerTest, BackspaceFromEndOfInput) |
55 { | 55 { |
56 HTMLInputElement* input = toHTMLInputElement( | 56 HTMLInputElement* input = toHTMLInputElement( |
57 insertHTMLElement("<input id='sample'>", "sample")); | 57 insertHTMLElement("<input id='sample'>", "sample")); |
58 | 58 |
59 input->setValue("fooX"); | 59 input->setValue("fooX"); |
| 60 document().updateStyleAndLayout(); |
60 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 61 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
61 EXPECT_STREQ("fooX", input->value().utf8().data()); | 62 EXPECT_STREQ("fooX", input->value().utf8().data()); |
62 controller().extendSelectionAndDelete(0, 0); | 63 controller().extendSelectionAndDelete(0, 0); |
63 EXPECT_STREQ("fooX", input->value().utf8().data()); | 64 EXPECT_STREQ("fooX", input->value().utf8().data()); |
64 | 65 |
65 input->setValue("fooX"); | 66 input->setValue("fooX"); |
| 67 document().updateStyleAndLayout(); |
66 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 68 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
67 EXPECT_STREQ("fooX", input->value().utf8().data()); | 69 EXPECT_STREQ("fooX", input->value().utf8().data()); |
68 controller().extendSelectionAndDelete(1, 0); | 70 controller().extendSelectionAndDelete(1, 0); |
69 EXPECT_STREQ("foo", input->value().utf8().data()); | 71 EXPECT_STREQ("foo", input->value().utf8().data()); |
70 | 72 |
71 input->setValue(String::fromUTF8("foo\xE2\x98\x85")); // U+2605 == "black st
ar" | 73 input->setValue(String::fromUTF8("foo\xE2\x98\x85")); // U+2605 == "black st
ar" |
| 74 document().updateStyleAndLayout(); |
72 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 75 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
73 EXPECT_STREQ("foo\xE2\x98\x85", input->value().utf8().data()); | 76 EXPECT_STREQ("foo\xE2\x98\x85", input->value().utf8().data()); |
74 controller().extendSelectionAndDelete(1, 0); | 77 controller().extendSelectionAndDelete(1, 0); |
75 EXPECT_STREQ("foo", input->value().utf8().data()); | 78 EXPECT_STREQ("foo", input->value().utf8().data()); |
76 | 79 |
77 input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86")); // U+1F3C6 == "tro
phy" | 80 input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86")); // U+1F3C6 == "tro
phy" |
| 81 document().updateStyleAndLayout(); |
78 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 82 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
79 EXPECT_STREQ("foo\xF0\x9F\x8F\x86", input->value().utf8().data()); | 83 EXPECT_STREQ("foo\xF0\x9F\x8F\x86", input->value().utf8().data()); |
80 controller().extendSelectionAndDelete(1, 0); | 84 controller().extendSelectionAndDelete(1, 0); |
81 EXPECT_STREQ("foo", input->value().utf8().data()); | 85 EXPECT_STREQ("foo", input->value().utf8().data()); |
82 | 86 |
83 input->setValue(String::fromUTF8("foo\xE0\xB8\x81\xE0\xB9\x89")); // compose
d U+0E01 "ka kai" + U+0E49 "mai tho" | 87 input->setValue(String::fromUTF8("foo\xE0\xB8\x81\xE0\xB9\x89")); // compose
d U+0E01 "ka kai" + U+0E49 "mai tho" |
| 88 document().updateStyleAndLayout(); |
84 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 89 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
85 EXPECT_STREQ("foo\xE0\xB8\x81\xE0\xB9\x89", input->value().utf8().data()); | 90 EXPECT_STREQ("foo\xE0\xB8\x81\xE0\xB9\x89", input->value().utf8().data()); |
86 controller().extendSelectionAndDelete(1, 0); | 91 controller().extendSelectionAndDelete(1, 0); |
87 EXPECT_STREQ("foo", input->value().utf8().data()); | 92 EXPECT_STREQ("foo", input->value().utf8().data()); |
88 | 93 |
89 input->setValue("fooX"); | 94 input->setValue("fooX"); |
| 95 document().updateStyleAndLayout(); |
90 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 96 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
91 EXPECT_STREQ("fooX", input->value().utf8().data()); | 97 EXPECT_STREQ("fooX", input->value().utf8().data()); |
92 controller().extendSelectionAndDelete(0, 1); | 98 controller().extendSelectionAndDelete(0, 1); |
93 EXPECT_STREQ("fooX", input->value().utf8().data()); | 99 EXPECT_STREQ("fooX", input->value().utf8().data()); |
94 } | 100 } |
95 | 101 |
96 TEST_F(InputMethodControllerTest, SetCompositionFromExistingText) | 102 TEST_F(InputMethodControllerTest, SetCompositionFromExistingText) |
97 { | 103 { |
98 Element* div = insertHTMLElement( | 104 Element* div = insertHTMLElement( |
99 "<div id='sample' contenteditable='true'>hello world</div>", "sample"); | 105 "<div id='sample' contenteditable='true'>hello world</div>", "sample"); |
(...skipping 24 matching lines...) Expand all Loading... |
124 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode()); | 130 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode()); |
125 EXPECT_EQ(0, frame().selection().end().computeOffsetInContainerNode()); | 131 EXPECT_EQ(0, frame().selection().end().computeOffsetInContainerNode()); |
126 } | 132 } |
127 | 133 |
128 TEST_F(InputMethodControllerTest, DeleteBySettingEmptyComposition) | 134 TEST_F(InputMethodControllerTest, DeleteBySettingEmptyComposition) |
129 { | 135 { |
130 HTMLInputElement* input = toHTMLInputElement( | 136 HTMLInputElement* input = toHTMLInputElement( |
131 insertHTMLElement("<input id='sample'>", "sample")); | 137 insertHTMLElement("<input id='sample'>", "sample")); |
132 | 138 |
133 input->setValue("foo "); | 139 input->setValue("foo "); |
| 140 document().updateStyleAndLayout(); |
134 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 141 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
135 EXPECT_STREQ("foo ", input->value().utf8().data()); | 142 EXPECT_STREQ("foo ", input->value().utf8().data()); |
136 controller().extendSelectionAndDelete(0, 0); | 143 controller().extendSelectionAndDelete(0, 0); |
137 EXPECT_STREQ("foo ", input->value().utf8().data()); | 144 EXPECT_STREQ("foo ", input->value().utf8().data()); |
138 | 145 |
139 input->setValue("foo "); | 146 input->setValue("foo "); |
| 147 document().updateStyleAndLayout(); |
140 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 148 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
141 EXPECT_STREQ("foo ", input->value().utf8().data()); | 149 EXPECT_STREQ("foo ", input->value().utf8().data()); |
142 controller().extendSelectionAndDelete(1, 0); | 150 controller().extendSelectionAndDelete(1, 0); |
143 EXPECT_STREQ("foo", input->value().utf8().data()); | 151 EXPECT_STREQ("foo", input->value().utf8().data()); |
144 | 152 |
145 Vector<CompositionUnderline> underlines; | 153 Vector<CompositionUnderline> underlines; |
146 underlines.append(CompositionUnderline(0, 3, Color(255, 0, 0), false, 0)); | 154 underlines.append(CompositionUnderline(0, 3, Color(255, 0, 0), false, 0)); |
147 controller().setCompositionFromExistingText(underlines, 0, 3); | 155 controller().setCompositionFromExistingText(underlines, 0, 3); |
148 | 156 |
149 controller().setComposition(String(""), underlines, 0, 3); | 157 controller().setComposition(String(""), underlines, 0, 3); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 202 |
195 EXPECT_STREQ("foo", input->value().utf8().data()); | 203 EXPECT_STREQ("foo", input->value().utf8().data()); |
196 } | 204 } |
197 | 205 |
198 TEST_F(InputMethodControllerTest, SetCompositionForInputWithDifferentNewCursorPo
sitions) | 206 TEST_F(InputMethodControllerTest, SetCompositionForInputWithDifferentNewCursorPo
sitions) |
199 { | 207 { |
200 HTMLInputElement* input = toHTMLInputElement( | 208 HTMLInputElement* input = toHTMLInputElement( |
201 insertHTMLElement("<input id='sample'>", "sample")); | 209 insertHTMLElement("<input id='sample'>", "sample")); |
202 | 210 |
203 input->setValue("hello"); | 211 input->setValue("hello"); |
| 212 document().updateStyleAndLayout(); |
204 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); | 213 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); |
205 EXPECT_STREQ("hello", input->value().utf8().data()); | 214 EXPECT_STREQ("hello", input->value().utf8().data()); |
206 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); | 215 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); |
207 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); | 216 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); |
208 | 217 |
209 Vector<CompositionUnderline> underlines; | 218 Vector<CompositionUnderline> underlines; |
210 underlines.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); | 219 underlines.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); |
211 | 220 |
212 // The cursor exceeds left boundary. | 221 // The cursor exceeds left boundary. |
213 // "*heABllo", where * stands for cursor. | 222 // "*heABllo", where * stands for cursor. |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 document().setTitle(emptyString()); | 486 document().setTitle(emptyString()); |
478 controller().setComposition("ni", underlines, 0, 1); | 487 controller().setComposition("ni", underlines, 0, 1); |
479 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8()
.data()); | 488 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8()
.data()); |
480 | 489 |
481 document().setTitle(emptyString()); | 490 document().setTitle(emptyString()); |
482 controller().confirmComposition(); | 491 controller().confirmComposition(); |
483 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8()
.data()); | 492 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8()
.data()); |
484 } | 493 } |
485 | 494 |
486 } // namespace blink | 495 } // namespace blink |
OLD | NEW |