| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/editing/InputMethodController.h" |
| 7 |
| 8 #include "core/dom/Text.h" |
| 9 #include "core/editing/FrameSelection.h" |
| 10 #include "core/frame/LocalFrame.h" |
| 11 #include "core/frame/Settings.h" |
| 12 #include "core/html/HTMLDocument.h" |
| 13 #include "core/html/HTMLElement.h" |
| 14 #include "core/html/HTMLInputElement.h" |
| 15 #include "core/testing/DummyPageHolder.h" |
| 16 #include <gtest/gtest.h> |
| 17 |
| 18 using namespace WebCore; |
| 19 |
| 20 namespace WebCore { |
| 21 |
| 22 class InputMethodControllerTest : public ::testing::Test { |
| 23 protected: |
| 24 InputMethodController& controller() { return frame().inputMethodController()
; } |
| 25 HTMLDocument& document() const { return *m_document; } |
| 26 LocalFrame& frame() const { return m_dummyPageHolder->frame(); } |
| 27 |
| 28 private: |
| 29 virtual void SetUp() OVERRIDE; |
| 30 |
| 31 OwnPtr<DummyPageHolder> m_dummyPageHolder; |
| 32 HTMLDocument* m_document; |
| 33 }; |
| 34 |
| 35 void InputMethodControllerTest::SetUp() |
| 36 { |
| 37 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
| 38 m_document = toHTMLDocument(&m_dummyPageHolder->document()); |
| 39 ASSERT(m_document); |
| 40 } |
| 41 |
| 42 } // namespace WebCore |
| 43 |
| 44 namespace { |
| 45 |
| 46 using namespace WebCore; |
| 47 |
| 48 TEST_F(InputMethodControllerTest, setComposition) |
| 49 { |
| 50 document().write("<div contenteditable='true' id='target'>foo</div>"); |
| 51 RefPtrWillBeRawPtr<Element> input = document().getElementById("target"); |
| 52 frame().selection().moveTo(Position(toText(input->firstChild()), 0), DOWNSTR
EAM); |
| 53 frame().inputMethodController().setComposition("bar", Vector<CompositionUnde
rline>(), 0, 0); |
| 54 EXPECT_STREQ("barfoo", input->textContent().utf8().data()); |
| 55 } |
| 56 |
| 57 TEST_F(InputMethodControllerTest, setCompositionCancelCompositionStart) |
| 58 { |
| 59 frame().settings()->setScriptEnabled(true); |
| 60 document().write("<div contenteditable='true' id='target'>foo</div>" |
| 61 "<div id='compositionend'></div>" |
| 62 "<script>" |
| 63 "var target = document.getElementById('target');" |
| 64 "target.addEventListener('compositionstart', function(event) {" |
| 65 " event.preventDefault();" |
| 66 "});" |
| 67 "target.addEventListener('compositionend', function(event) {" |
| 68 " document.getElementById('compositionend').textContent = '1';" |
| 69 "});" |
| 70 "</script>"); |
| 71 document().updateLayout(); |
| 72 RefPtrWillBeRawPtr<Element> target = document().getElementById("target"); |
| 73 document().setFocusedElement(target); |
| 74 frame().selection().moveTo(Position(toText(target->firstChild()), 0), DOWNST
REAM); |
| 75 frame().inputMethodController().setComposition("bar", Vector<CompositionUnde
rline>(), 0, 0); |
| 76 EXPECT_STREQ("foo", target->textContent().utf8().data()); |
| 77 |
| 78 RefPtrWillBeRawPtr<Element> endEvent = document().getElementById("compositio
nend"); |
| 79 EXPECT_STREQ("1", endEvent->textContent().utf8().data()); |
| 80 } |
| 81 |
| 82 TEST_F(InputMethodControllerTest, BackspaceFromEndOfInput) |
| 83 { |
| 84 document().write("<input id='sample'>"); |
| 85 HTMLInputElement* input = toHTMLInputElement(document().getElementById("samp
le")); |
| 86 document().updateLayout(); |
| 87 input->focus(); |
| 88 |
| 89 input->setValue("fooX"); |
| 90 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
| 91 EXPECT_STREQ("fooX", input->value().utf8().data()); |
| 92 controller().extendSelectionAndDelete(1, 0); |
| 93 EXPECT_STREQ("foo", input->value().utf8().data()); |
| 94 |
| 95 input->setValue(String::fromUTF8("foo\xE2\x98\x85")); // U+2605 == "black st
ar" |
| 96 EXPECT_STREQ("foo\xE2\x98\x85", input->value().utf8().data()); |
| 97 controller().extendSelectionAndDelete(1, 0); |
| 98 EXPECT_STREQ("foo", input->value().utf8().data()); |
| 99 |
| 100 input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86")); // U+1F3C6 == "tro
phy" |
| 101 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
| 102 EXPECT_STREQ("foo\xF0\x9F\x8F\x86", input->value().utf8().data()); |
| 103 controller().extendSelectionAndDelete(1, 0); |
| 104 EXPECT_STREQ("foo", input->value().utf8().data()); |
| 105 |
| 106 input->setValue(String::fromUTF8("foo\xE0\xB8\x81\xE0\xB9\x89")); // compose
d U+0E01 "ka kai" + U+0E49 "mai tho" |
| 107 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
| 108 EXPECT_STREQ("foo\xE0\xB8\x81\xE0\xB9\x89", input->value().utf8().data()); |
| 109 controller().extendSelectionAndDelete(1, 0); |
| 110 EXPECT_STREQ("foo", input->value().utf8().data()); |
| 111 |
| 112 } |
| 113 |
| 114 } // namespace WebCore |
| OLD | NEW |