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/frame/LocalFrame.h" 9 #include "core/html/HTMLDocument.h" 10 #include "core/html/HTMLInputElement.h" 11 #include "core/testing/DummyPageHolder.h" 12 #include <gtest/gtest.h> 13 14 using namespace blink; 15 using namespace WebCore; 16 17 namespace { 18 19 class InputMethodControllerTest : public ::testing::Test { 20 protected: 21 InputMethodController& controller() { return frame().inputMethodController(); } 22 HTMLDocument& document() const { return *m_document; } 23 LocalFrame& frame() const { return m_dummyPageHolder->frame(); } 24 25 private: 26 virtual void SetUp() OVERRIDE; 27 28 OwnPtr<DummyPageHolder> m_dummyPageHolder; 29 HTMLDocument* m_document; 30 }; 31 32 void InputMethodControllerTest::SetUp() 33 { 34 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); 35 m_document = toHTMLDocument(&m_dummyPageHolder->document()); 36 ASSERT(m_document); 37 } 38 39 TEST_F(InputMethodControllerTest, BackspaceFromEndOfInput) 40 { 41 document().write("<input id='sample'>"); 42 HTMLInputElement* input = toHTMLInputElement(document().getElementById("sample")); 43 document().updateLayout(); 44 input->focus(); 45 46 input->setValue("fooX"); 47 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); 48 EXPECT_STREQ("fooX", input->value().utf8().data()); 49 controller().extendSelectionAndDelete(0, 0); 50 EXPECT_STREQ("fooX", input->value().utf8().data()); 51 52 input->setValue("fooX"); 53 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); 54 EXPECT_STREQ("fooX", input->value().utf8().data()); 55 controller().extendSelectionAndDelete(1, 0); 56 EXPECT_STREQ("foo", input->value().utf8().data()); 57 58 input->setValue(String::fromUTF8("foo\xE2\x98\x85")); // U+2605 == "black star" 59 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); 60 EXPECT_STREQ("foo\xE2\x98\x85", input->value().utf8().data()); 61 controller().extendSelectionAndDelete(1, 0); 62 EXPECT_STREQ("foo", input->value().utf8().data()); 63 64 input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86")); // U+1F3C6 == "trophy" 65 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); 66 EXPECT_STREQ("foo\xF0\x9F\x8F\x86", input->value().utf8().data()); 67 controller().extendSelectionAndDelete(1, 0); 68 EXPECT_STREQ("foo", input->value().utf8().data()); 69 70 input->setValue(String::fromUTF8("foo\xE0\xB8\x81\xE0\xB9\x89")); // composed U+0E01 "ka kai" + U+0E49 "mai tho" 71 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); 72 EXPECT_STREQ("foo\xE0\xB8\x81\xE0\xB9\x89", input->value().utf8().data()); 73 controller().extendSelectionAndDelete(1, 0); 74 EXPECT_STREQ("foo", input->value().utf8().data()); 75 76 input->setValue("fooX"); 77 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); 78 EXPECT_STREQ("fooX", input->value().utf8().data()); 79 controller().extendSelectionAndDelete(0, 1); 80 EXPECT_STREQ("fooX", input->value().utf8().data()); 81 } 82 83 } // namespace 84