Chromium Code Reviews| 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/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/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 insertHTMLElement("<input id='sample' type='password' size='24'>", "samp le")); | 183 insertHTMLElement("<input id='sample' type='password' size='24'>", "samp le")); |
| 184 | 184 |
| 185 Vector<CompositionUnderline> underlines; | 185 Vector<CompositionUnderline> underlines; |
| 186 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 186 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 187 controller().setComposition("foo", underlines, 0, 3); | 187 controller().setComposition("foo", underlines, 0, 3); |
| 188 controller().confirmComposition(); | 188 controller().confirmComposition(); |
| 189 | 189 |
| 190 EXPECT_STREQ("foo", input->value().utf8().data()); | 190 EXPECT_STREQ("foo", input->value().utf8().data()); |
| 191 } | 191 } |
| 192 | 192 |
| 193 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithEmptyText) | |
| 194 { | |
| 195 HTMLInputElement* input = toHTMLInputElement( | |
| 196 insertHTMLElement("<input id='sample'>", "sample")); | |
| 197 | |
| 198 input->setValue(""); | |
| 199 EXPECT_STREQ("", input->value().utf8().data()); | |
| 200 controller().deleteSurroundingText(0, 0); | |
| 201 EXPECT_STREQ("", input->value().utf8().data()); | |
| 202 | |
| 203 input->setValue(""); | |
| 204 EXPECT_STREQ("", input->value().utf8().data()); | |
| 205 controller().deleteSurroundingText(1, 0); | |
| 206 EXPECT_STREQ("", input->value().utf8().data()); | |
| 207 | |
| 208 input->setValue(""); | |
| 209 EXPECT_STREQ("", input->value().utf8().data()); | |
| 210 controller().deleteSurroundingText(0, 1); | |
| 211 EXPECT_STREQ("", input->value().utf8().data()); | |
| 212 } | |
| 213 | |
| 214 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithRangeSelection) | |
| 215 { | |
| 216 HTMLInputElement* input = toHTMLInputElement( | |
| 217 insertHTMLElement("<input id='sample'>", "sample")); | |
| 218 | |
| 219 input->setValue("hello"); | |
| 220 EXPECT_STREQ("hello", input->value().utf8().data()); | |
| 221 controller().setEditableSelectionOffsets(PlainTextRange(1, 4)); | |
| 222 controller().deleteSurroundingText(0, 0); | |
| 223 EXPECT_STREQ("hello", input->value().utf8().data()); | |
| 224 | |
| 225 input->setValue("hello"); | |
| 226 EXPECT_STREQ("hello", input->value().utf8().data()); | |
| 227 controller().setEditableSelectionOffsets(PlainTextRange(1, 4)); | |
| 228 controller().deleteSurroundingText(1, 1); | |
| 229 EXPECT_STREQ("ell", input->value().utf8().data()); | |
| 230 | |
| 231 input->setValue("hello"); | |
| 232 EXPECT_STREQ("hello", input->value().utf8().data()); | |
| 233 controller().setEditableSelectionOffsets(PlainTextRange(1, 4)); | |
| 234 controller().deleteSurroundingText(100, 0); | |
| 235 EXPECT_STREQ("ello", input->value().utf8().data()); | |
| 236 | |
| 237 input->setValue("hello"); | |
| 238 EXPECT_STREQ("hello", input->value().utf8().data()); | |
| 239 controller().setEditableSelectionOffsets(PlainTextRange(1, 4)); | |
| 240 controller().deleteSurroundingText(0, 100); | |
| 241 EXPECT_STREQ("hell", input->value().utf8().data()); | |
| 242 } | |
| 243 | |
| 244 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithCursorSelection) | |
| 245 { | |
| 246 HTMLInputElement* input = toHTMLInputElement( | |
| 247 insertHTMLElement("<input id='sample'>", "sample")); | |
| 248 | |
| 249 input->setValue("hello"); | |
| 250 EXPECT_STREQ("hello", input->value().utf8().data()); | |
| 251 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); | |
| 252 controller().deleteSurroundingText(0, 0); | |
| 253 EXPECT_STREQ("hello", input->value().utf8().data()); | |
| 254 | |
| 255 input->setValue("hello"); | |
| 256 EXPECT_STREQ("hello", input->value().utf8().data()); | |
| 257 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); | |
| 258 controller().deleteSurroundingText(1, 1); | |
| 259 EXPECT_STREQ("hlo", input->value().utf8().data()); | |
| 260 | |
| 261 input->setValue("hello"); | |
| 262 EXPECT_STREQ("hello", input->value().utf8().data()); | |
| 263 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); | |
| 264 controller().deleteSurroundingText(100, 0); | |
| 265 EXPECT_STREQ("llo", input->value().utf8().data()); | |
| 266 | |
| 267 input->setValue("hello"); | |
| 268 EXPECT_STREQ("hello", input->value().utf8().data()); | |
| 269 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); | |
| 270 controller().deleteSurroundingText(0, 100); | |
| 271 EXPECT_STREQ("he", input->value().utf8().data()); | |
| 272 } | |
| 273 | |
| 274 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithMultiCodeTextOnTheLef t) | |
| 275 { | |
| 276 HTMLInputElement* input = toHTMLInputElement( | |
| 277 insertHTMLElement("<input id='sample'>", "sample")); | |
| 278 | |
| 279 // U+2605 == "black star". It takes up 1 space. | |
| 280 input->setValue(String::fromUTF8("foo\xE2\x98\x85")); | |
| 281 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | |
| 282 EXPECT_STREQ("foo\xE2\x98\x85", input->value().utf8().data()); | |
| 283 controller().deleteSurroundingText(1, 0); | |
| 284 EXPECT_STREQ("foo", input->value().utf8().data()); | |
| 285 | |
| 286 // U+1F3C6 == "trophy". It takes up 2 space. | |
| 287 input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86")); | |
| 288 controller().setEditableSelectionOffsets(PlainTextRange(5, 5)); | |
| 289 EXPECT_STREQ("foo\xF0\x9F\x8F\x86", input->value().utf8().data()); | |
| 290 controller().deleteSurroundingText(1, 0); | |
| 291 EXPECT_STREQ("foo", input->value().utf8().data()); | |
| 292 | |
| 293 // composed U+0E01 "ka kai" + U+0E49 "mai tho". It takes up 2 space. | |
| 294 input->setValue(String::fromUTF8("foo\xE0\xB8\x81\xE0\xB9\x89")); | |
| 295 controller().setEditableSelectionOffsets(PlainTextRange(5, 5)); | |
| 296 EXPECT_STREQ("foo\xE0\xB8\x81\xE0\xB9\x89", input->value().utf8().data()); | |
| 297 controller().deleteSurroundingText(1, 0); | |
| 298 EXPECT_STREQ("foo", input->value().utf8().data()); | |
| 299 | |
| 300 // "trophy" + "trophy". | |
| 301 input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86")); | |
| 302 controller().setEditableSelectionOffsets(PlainTextRange(7, 7)); | |
| 303 EXPECT_STREQ("foo\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86", input->value().utf8().da ta()); | |
| 304 controller().deleteSurroundingText(2, 0); | |
| 305 EXPECT_STREQ("foo\xF0\x9F\x8F\x86", input->value().utf8().data()); | |
| 306 | |
| 307 // "trophy" + "trophy". | |
| 308 input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86")); | |
| 309 controller().setEditableSelectionOffsets(PlainTextRange(7, 7)); | |
| 310 EXPECT_STREQ("foo\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86", input->value().utf8().da ta()); | |
| 311 controller().deleteSurroundingText(3, 0); | |
| 312 EXPECT_STREQ("foo", input->value().utf8().data()); | |
| 313 | |
| 314 // "trophy" + "trophy". | |
| 315 input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86")); | |
| 316 controller().setEditableSelectionOffsets(PlainTextRange(7, 7)); | |
| 317 EXPECT_STREQ("foo\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86", input->value().utf8().da ta()); | |
| 318 controller().deleteSurroundingText(4, 0); | |
| 319 EXPECT_STREQ("foo", input->value().utf8().data()); | |
| 320 | |
| 321 // "trophy" + "trophy". | |
| 322 input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86")); | |
| 323 controller().setEditableSelectionOffsets(PlainTextRange(7, 7)); | |
| 324 EXPECT_STREQ("foo\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86", input->value().utf8().da ta()); | |
| 325 controller().deleteSurroundingText(5, 0); | |
| 326 EXPECT_STREQ("fo", input->value().utf8().data()); | |
| 327 } | |
| 328 | |
| 329 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithMultiCodeTextOnTheRig ht) | |
| 330 { | |
| 331 HTMLInputElement* input = toHTMLInputElement( | |
| 332 insertHTMLElement("<input id='sample'>", "sample")); | |
| 333 | |
| 334 // U+2605 == "black star". It takes up 1 space. | |
| 335 input->setValue(String::fromUTF8("\xE2\x98\x85 foo")); | |
| 336 controller().setEditableSelectionOffsets(PlainTextRange(0, 0)); | |
| 337 EXPECT_STREQ("\xE2\x98\x85 foo", input->value().utf8().data()); | |
| 338 controller().deleteSurroundingText(0, 1); | |
| 339 EXPECT_STREQ(" foo", input->value().utf8().data()); | |
| 340 | |
| 341 // U+1F3C6 == "trophy". It takes up 2 space. | |
| 342 input->setValue(String::fromUTF8("\xF0\x9F\x8F\x86 foo")); | |
| 343 controller().setEditableSelectionOffsets(PlainTextRange(0, 0)); | |
| 344 EXPECT_STREQ("\xF0\x9F\x8F\x86 foo", input->value().utf8().data()); | |
| 345 controller().deleteSurroundingText(0, 1); | |
| 346 EXPECT_STREQ(" foo", input->value().utf8().data()); | |
| 347 | |
| 348 // composed U+0E01 "ka kai" + U+0E49 "mai tho". It takes up 2 space. | |
| 349 input->setValue(String::fromUTF8("\xE0\xB8\x81\xE0\xB9\x89 foo")); | |
| 350 controller().setEditableSelectionOffsets(PlainTextRange(0, 0)); | |
| 351 EXPECT_STREQ("\xE0\xB8\x81\xE0\xB9\x89 foo", input->value().utf8().data()); | |
| 352 controller().deleteSurroundingText(0, 1); | |
| 353 EXPECT_STREQ(" foo", input->value().utf8().data()); | |
| 354 | |
| 355 // "trophy" + "trophy". | |
|
yosin_UTC9
2016/04/26 08:18:54
Are below tests handle grapheme clusters?
+nona@ f
Seigo Nonaka
2016/04/26 08:48:39
Looks like this is the case that the IME specifies
| |
| 356 input->setValue(String::fromUTF8("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86 foo")); | |
| 357 controller().setEditableSelectionOffsets(PlainTextRange(0, 0)); | |
| 358 EXPECT_STREQ("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86 foo", input->value().utf8().d ata()); | |
| 359 controller().deleteSurroundingText(0, 2); | |
| 360 EXPECT_STREQ("\xF0\x9F\x8F\x86 foo", input->value().utf8().data()); | |
| 361 | |
| 362 // "trophy" + "trophy". | |
| 363 input->setValue(String::fromUTF8("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86 foo")); | |
| 364 controller().setEditableSelectionOffsets(PlainTextRange(0, 0)); | |
| 365 EXPECT_STREQ("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86 foo", input->value().utf8().d ata()); | |
| 366 controller().deleteSurroundingText(0, 3); | |
| 367 EXPECT_STREQ(" foo", input->value().utf8().data()); | |
| 368 | |
| 369 // "trophy" + "trophy". | |
| 370 input->setValue(String::fromUTF8("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86 foo")); | |
| 371 controller().setEditableSelectionOffsets(PlainTextRange(0, 0)); | |
| 372 EXPECT_STREQ("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86 foo", input->value().utf8().d ata()); | |
| 373 controller().deleteSurroundingText(0, 4); | |
| 374 EXPECT_STREQ(" foo", input->value().utf8().data()); | |
| 375 | |
| 376 // "trophy" + "trophy". | |
| 377 input->setValue(String::fromUTF8("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86 foo")); | |
| 378 controller().setEditableSelectionOffsets(PlainTextRange(0, 0)); | |
| 379 EXPECT_STREQ("\xF0\x9F\x8F\x86\xF0\x9F\x8F\x86 foo", input->value().utf8().d ata()); | |
| 380 controller().deleteSurroundingText(0, 5); | |
| 381 EXPECT_STREQ("foo", input->value().utf8().data()); | |
| 382 } | |
| 383 | |
| 193 } // namespace blink | 384 } // namespace blink |
| OLD | NEW |