| 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/events/MouseEvent.h" | 10 #include "core/events/MouseEvent.h" |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 EXPECT_EQ(24u, controller().getSelectionOffsets().end()); | 342 EXPECT_EQ(24u, controller().getSelectionOffsets().end()); |
| 343 | 343 |
| 344 // The cursor exceeds right boundary. | 344 // The cursor exceeds right boundary. |
| 345 // "hello\nworld\n01234AB56789*". | 345 // "hello\nworld\n01234AB56789*". |
| 346 controller().setComposition("AB", underlines, 100, 100); | 346 controller().setComposition("AB", underlines, 100, 100); |
| 347 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data()); | 347 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data()); |
| 348 EXPECT_EQ(24u, controller().getSelectionOffsets().start()); | 348 EXPECT_EQ(24u, controller().getSelectionOffsets().start()); |
| 349 EXPECT_EQ(24u, controller().getSelectionOffsets().end()); | 349 EXPECT_EQ(24u, controller().getSelectionOffsets().end()); |
| 350 } | 350 } |
| 351 | 351 |
| 352 TEST_F(InputMethodControllerTest, CompositionFireBeforeInput) | 352 TEST_F(InputMethodControllerTest, CompositionInputEventIsComposing) |
| 353 { | 353 { |
| 354 document().settings()->setScriptEnabled(true); | 354 document().settings()->setScriptEnabled(true); |
| 355 Element* editable = insertHTMLElement("<div id='sample' contentEditable='tru
e'></div>", "sample"); | 355 Element* editable = insertHTMLElement("<div id='sample' contentEditable='tru
e'></div>", "sample"); |
| 356 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); | 356 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); |
| 357 script->setInnerHTML( | 357 script->setInnerHTML( |
| 358 "document.getElementById('sample').addEventListener('beforeinput', funct
ion(event) {" | 358 "document.getElementById('sample').addEventListener('beforeinput', funct
ion(event) {" |
| 359 " document.title = `beforeinput.isComposing:${event.isComposing};`;" | 359 " document.title = `beforeinput.isComposing:${event.isComposing};`;" |
| 360 "});" | 360 "});" |
| 361 "document.getElementById('sample').addEventListener('input', function(ev
ent) {" | 361 "document.getElementById('sample').addEventListener('input', function(ev
ent) {" |
| 362 " document.title += `input.isComposing:${event.isComposing};`;" | 362 " document.title += `input.isComposing:${event.isComposing};`;" |
| 363 "});", | 363 "});", |
| 364 ASSERT_NO_EXCEPTION); | 364 ASSERT_NO_EXCEPTION); |
| 365 document().body()->appendChild(script, ASSERT_NO_EXCEPTION); | 365 document().body()->appendChild(script, ASSERT_NO_EXCEPTION); |
| 366 document().view()->updateAllLifecyclePhases(); | 366 document().view()->updateAllLifecyclePhases(); |
| 367 | 367 |
| 368 // Simulate composition in the |contentEditable|. | 368 // Simulate composition in the |contentEditable|. |
| 369 Vector<CompositionUnderline> underlines; | 369 Vector<CompositionUnderline> underlines; |
| 370 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 370 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 371 editable->focus(); | 371 editable->focus(); |
| 372 | 372 |
| 373 document().setTitle(emptyString()); | 373 document().setTitle(emptyString()); |
| 374 controller().setComposition("foo", underlines, 0, 3); | 374 controller().setComposition("foo", underlines, 0, 3); |
| 375 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", documen
t().title().utf8().data()); | 375 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", documen
t().title().utf8().data()); |
| 376 | 376 |
| 377 document().setTitle(emptyString()); | 377 document().setTitle(emptyString()); |
| 378 controller().confirmComposition(); | 378 controller().confirmComposition(); |
| 379 // Last 'beforeinput' should also be inside composition scope. | 379 // Last pair of InputEvent should also be inside composition scope. |
| 380 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", documen
t().title().utf8().data()); | 380 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", documen
t().title().utf8().data()); |
| 381 } | 381 } |
| 382 | 382 |
| 383 TEST_F(InputMethodControllerTest, CompositionInputEventData) |
| 384 { |
| 385 document().settings()->setScriptEnabled(true); |
| 386 Element* editable = insertHTMLElement("<div id='sample' contentEditable='tru
e'></div>", "sample"); |
| 387 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); |
| 388 script->setInnerHTML( |
| 389 "document.getElementById('sample').addEventListener('beforeinput', funct
ion(event) {" |
| 390 " document.title = `beforeinput.data:${event.data};`;" |
| 391 "});" |
| 392 "document.getElementById('sample').addEventListener('input', function(ev
ent) {" |
| 393 " document.title += `input.data:${event.data};`;" |
| 394 "});", |
| 395 ASSERT_NO_EXCEPTION); |
| 396 document().body()->appendChild(script, ASSERT_NO_EXCEPTION); |
| 397 document().view()->updateAllLifecyclePhases(); |
| 398 |
| 399 // Simulate composition in the |contentEditable|. |
| 400 Vector<CompositionUnderline> underlines; |
| 401 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 402 editable->focus(); |
| 403 |
| 404 document().setTitle(emptyString()); |
| 405 controller().setComposition("n", underlines, 0, 1); |
| 406 EXPECT_STREQ("beforeinput.data:n;input.data:n;", document().title().utf8().d
ata()); |
| 407 |
| 408 document().setTitle(emptyString()); |
| 409 controller().setComposition("ni", underlines, 0, 1); |
| 410 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8()
.data()); |
| 411 |
| 412 document().setTitle(emptyString()); |
| 413 controller().confirmComposition(); |
| 414 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8()
.data()); |
| 415 } |
| 416 |
| 383 } // namespace blink | 417 } // namespace blink |
| OLD | NEW |