| 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, SetCompositionWithEmptyText) | 
|  | 353 { | 
|  | 354     Element* div = insertHTMLElement( | 
|  | 355         "<div id='sample' contenteditable='true'>hello</div>", | 
|  | 356         "sample"); | 
|  | 357 | 
|  | 358     controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); | 
|  | 359     EXPECT_STREQ("hello", div->innerText().utf8().data()); | 
|  | 360     EXPECT_EQ(2u, controller().getSelectionOffsets().start()); | 
|  | 361     EXPECT_EQ(2u, controller().getSelectionOffsets().end()); | 
|  | 362 | 
|  | 363     Vector<CompositionUnderline> underlines0; | 
|  | 364     underlines0.append(CompositionUnderline(0, 0, Color(255, 0, 0), false, 0)); | 
|  | 365     Vector<CompositionUnderline> underlines2; | 
|  | 366     underlines2.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); | 
|  | 367 | 
|  | 368     controller().setComposition("AB", underlines2, 2, 2); | 
|  | 369     // With previous composition. | 
|  | 370     controller().setComposition("", underlines0, 2, 2); | 
|  | 371     EXPECT_STREQ("hello", div->innerText().utf8().data()); | 
|  | 372     EXPECT_EQ(4u, controller().getSelectionOffsets().start()); | 
|  | 373     EXPECT_EQ(4u, controller().getSelectionOffsets().end()); | 
|  | 374 | 
|  | 375     // Without previous composition. | 
|  | 376     controller().setComposition("", underlines0, -1, -1); | 
|  | 377     EXPECT_STREQ("hello", div->innerText().utf8().data()); | 
|  | 378     EXPECT_EQ(3u, controller().getSelectionOffsets().start()); | 
|  | 379     EXPECT_EQ(3u, controller().getSelectionOffsets().end()); | 
|  | 380 } | 
|  | 381 | 
| 352 TEST_F(InputMethodControllerTest, CompositionInputEventIsComposing) | 382 TEST_F(InputMethodControllerTest, CompositionInputEventIsComposing) | 
| 353 { | 383 { | 
| 354     document().settings()->setScriptEnabled(true); | 384     document().settings()->setScriptEnabled(true); | 
| 355     Element* editable = insertHTMLElement("<div id='sample' contentEditable='tru
     e'></div>", "sample"); | 385     Element* editable = insertHTMLElement("<div id='sample' contentEditable='tru
     e'></div>", "sample"); | 
| 356     Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); | 386     Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); | 
| 357     script->setInnerHTML( | 387     script->setInnerHTML( | 
| 358         "document.getElementById('sample').addEventListener('beforeinput', funct
     ion(event) {" | 388         "document.getElementById('sample').addEventListener('beforeinput', funct
     ion(event) {" | 
| 359         "    document.title = `beforeinput.isComposing:${event.isComposing};`;" | 389         "    document.title = `beforeinput.isComposing:${event.isComposing};`;" | 
| 360         "});" | 390         "});" | 
| 361         "document.getElementById('sample').addEventListener('input', function(ev
     ent) {" | 391         "document.getElementById('sample').addEventListener('input', function(ev
     ent) {" | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 408     document().setTitle(emptyString()); | 438     document().setTitle(emptyString()); | 
| 409     controller().setComposition("ni", underlines, 0, 1); | 439     controller().setComposition("ni", underlines, 0, 1); | 
| 410     EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8()
     .data()); | 440     EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8()
     .data()); | 
| 411 | 441 | 
| 412     document().setTitle(emptyString()); | 442     document().setTitle(emptyString()); | 
| 413     controller().confirmComposition(); | 443     controller().confirmComposition(); | 
| 414     EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8()
     .data()); | 444     EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8()
     .data()); | 
| 415 } | 445 } | 
| 416 | 446 | 
| 417 } // namespace blink | 447 } // namespace blink | 
| OLD | NEW | 
|---|