| 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 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 frame().editor().insertLineBreak(); | 801 frame().editor().insertLineBreak(); |
| 802 EXPECT_STREQ("he\nllo", div->innerText().utf8().data()); | 802 EXPECT_STREQ("he\nllo", div->innerText().utf8().data()); |
| 803 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); | 803 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); |
| 804 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); | 804 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); |
| 805 } | 805 } |
| 806 | 806 |
| 807 TEST_F(InputMethodControllerTest, CompositionInputEventIsComposing) { | 807 TEST_F(InputMethodControllerTest, CompositionInputEventIsComposing) { |
| 808 document().settings()->setScriptEnabled(true); | 808 document().settings()->setScriptEnabled(true); |
| 809 Element* editable = insertHTMLElement( | 809 Element* editable = insertHTMLElement( |
| 810 "<div id='sample' contentEditable='true'></div>", "sample"); | 810 "<div id='sample' contentEditable='true'></div>", "sample"); |
| 811 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); | 811 Element* script = document().createElement("script"); |
| 812 script->setInnerHTML( | 812 script->setInnerHTML( |
| 813 "document.getElementById('sample').addEventListener('beforeinput', " | 813 "document.getElementById('sample').addEventListener('beforeinput', " |
| 814 "function(event) {" | 814 "function(event) {" |
| 815 " document.title = `beforeinput.isComposing:${event.isComposing};`;" | 815 " document.title = `beforeinput.isComposing:${event.isComposing};`;" |
| 816 "});" | 816 "});" |
| 817 "document.getElementById('sample').addEventListener('input', " | 817 "document.getElementById('sample').addEventListener('input', " |
| 818 "function(event) {" | 818 "function(event) {" |
| 819 " document.title += `input.isComposing:${event.isComposing};`;" | 819 " document.title += `input.isComposing:${event.isComposing};`;" |
| 820 "});", | 820 "});", |
| 821 ASSERT_NO_EXCEPTION); | 821 ASSERT_NO_EXCEPTION); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 836 controller().finishComposingText(InputMethodController::KeepSelection); | 836 controller().finishComposingText(InputMethodController::KeepSelection); |
| 837 // Last pair of InputEvent should also be inside composition scope. | 837 // Last pair of InputEvent should also be inside composition scope. |
| 838 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", | 838 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", |
| 839 document().title().utf8().data()); | 839 document().title().utf8().data()); |
| 840 } | 840 } |
| 841 | 841 |
| 842 TEST_F(InputMethodControllerTest, CompositionInputEventData) { | 842 TEST_F(InputMethodControllerTest, CompositionInputEventData) { |
| 843 document().settings()->setScriptEnabled(true); | 843 document().settings()->setScriptEnabled(true); |
| 844 Element* editable = insertHTMLElement( | 844 Element* editable = insertHTMLElement( |
| 845 "<div id='sample' contentEditable='true'></div>", "sample"); | 845 "<div id='sample' contentEditable='true'></div>", "sample"); |
| 846 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); | 846 Element* script = document().createElement("script"); |
| 847 script->setInnerHTML( | 847 script->setInnerHTML( |
| 848 "document.getElementById('sample').addEventListener('beforeinput', " | 848 "document.getElementById('sample').addEventListener('beforeinput', " |
| 849 "function(event) {" | 849 "function(event) {" |
| 850 " document.title = `beforeinput.data:${event.data};`;" | 850 " document.title = `beforeinput.data:${event.data};`;" |
| 851 "});" | 851 "});" |
| 852 "document.getElementById('sample').addEventListener('input', " | 852 "document.getElementById('sample').addEventListener('input', " |
| 853 "function(event) {" | 853 "function(event) {" |
| 854 " document.title += `input.data:${event.data};`;" | 854 " document.title += `input.data:${event.data};`;" |
| 855 "});", | 855 "});", |
| 856 ASSERT_NO_EXCEPTION); | 856 ASSERT_NO_EXCEPTION); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 872 EXPECT_STREQ("beforeinput.data:i;input.data:i;", | 872 EXPECT_STREQ("beforeinput.data:i;input.data:i;", |
| 873 document().title().utf8().data()); | 873 document().title().utf8().data()); |
| 874 | 874 |
| 875 document().setTitle(emptyString()); | 875 document().setTitle(emptyString()); |
| 876 controller().finishComposingText(InputMethodController::KeepSelection); | 876 controller().finishComposingText(InputMethodController::KeepSelection); |
| 877 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", | 877 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", |
| 878 document().title().utf8().data()); | 878 document().title().utf8().data()); |
| 879 } | 879 } |
| 880 | 880 |
| 881 } // namespace blink | 881 } // namespace blink |
| OLD | NEW |