| 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/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| 11 #include "core/html/HTMLDocument.h" | 11 #include "core/html/HTMLDocument.h" |
| 12 #include "core/html/HTMLInputElement.h" | 12 #include "core/html/HTMLInputElement.h" |
| 13 #include "core/testing/DummyPageHolder.h" | 13 #include "core/testing/DummyPageHolder.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 class InputMethodControllerTest : public ::testing::Test { | 18 class InputMethodControllerTest : public ::testing::Test { |
| 19 protected: | 19 protected: |
| 20 InputMethodController& controller() { return frame().inputMethodController()
; } | 20 InputMethodController& controller() { return frame().inputMethodController()
; } |
| 21 HTMLDocument& document() const { return *m_document; } | 21 HTMLDocument& document() const { return *m_document; } |
| 22 LocalFrame& frame() const { return m_dummyPageHolder->frame(); } | 22 LocalFrame& frame() const { return m_dummyPageHolder->frame(); } |
| 23 Element* insertHTMLElement(const char* elementCode, const char* elementId); | 23 Element* insertHTMLElement(const char* elementCode, const char* elementId); |
| 24 | 24 |
| 25 private: | 25 private: |
| 26 void SetUp() override; | 26 void SetUp() override; |
| 27 | 27 |
| 28 OwnPtr<DummyPageHolder> m_dummyPageHolder; | 28 OwnPtr<DummyPageHolder> m_dummyPageHolder; |
| 29 RefPtrWillBePersistent<HTMLDocument> m_document; | 29 Persistent<HTMLDocument> m_document; |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 void InputMethodControllerTest::SetUp() | 32 void InputMethodControllerTest::SetUp() |
| 33 { | 33 { |
| 34 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | 34 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
| 35 m_document = toHTMLDocument(&m_dummyPageHolder->document()); | 35 m_document = toHTMLDocument(&m_dummyPageHolder->document()); |
| 36 ASSERT(m_document); | 36 ASSERT(m_document); |
| 37 } | 37 } |
| 38 | 38 |
| 39 Element* InputMethodControllerTest::insertHTMLElement( | 39 Element* InputMethodControllerTest::insertHTMLElement( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 TEST_F(InputMethodControllerTest, SetCompositionFromExistingText) | 91 TEST_F(InputMethodControllerTest, SetCompositionFromExistingText) |
| 92 { | 92 { |
| 93 Element* div = insertHTMLElement( | 93 Element* div = insertHTMLElement( |
| 94 "<div id='sample' contenteditable='true'>hello world</div>", "sample"); | 94 "<div id='sample' contenteditable='true'>hello world</div>", "sample"); |
| 95 | 95 |
| 96 Vector<CompositionUnderline> underlines; | 96 Vector<CompositionUnderline> underlines; |
| 97 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 97 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 98 controller().setCompositionFromExistingText(underlines, 0, 5); | 98 controller().setCompositionFromExistingText(underlines, 0, 5); |
| 99 | 99 |
| 100 RefPtrWillBeRawPtr<Range> range = controller().compositionRange(); | 100 RawPtr<Range> range = controller().compositionRange(); |
| 101 EXPECT_EQ(0, range->startOffset()); | 101 EXPECT_EQ(0, range->startOffset()); |
| 102 EXPECT_EQ(5, range->endOffset()); | 102 EXPECT_EQ(5, range->endOffset()); |
| 103 | 103 |
| 104 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range.get())); | 104 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range.get())); |
| 105 EXPECT_EQ(0u, plainTextRange.start()); | 105 EXPECT_EQ(0u, plainTextRange.start()); |
| 106 EXPECT_EQ(5u, plainTextRange.end()); | 106 EXPECT_EQ(5u, plainTextRange.end()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) | 109 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) |
| 110 { | 110 { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 { | 150 { |
| 151 // Creates a div with one leading new line char. The new line char is hidden | 151 // Creates a div with one leading new line char. The new line char is hidden |
| 152 // from the user and IME, but is visible to InputMethodController. | 152 // from the user and IME, but is visible to InputMethodController. |
| 153 Element* div = insertHTMLElement( | 153 Element* div = insertHTMLElement( |
| 154 "<div id='sample' contenteditable='true'>\nhello world</div>", "sample")
; | 154 "<div id='sample' contenteditable='true'>\nhello world</div>", "sample")
; |
| 155 | 155 |
| 156 Vector<CompositionUnderline> underlines; | 156 Vector<CompositionUnderline> underlines; |
| 157 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 157 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 158 controller().setCompositionFromExistingText(underlines, 0, 5); | 158 controller().setCompositionFromExistingText(underlines, 0, 5); |
| 159 | 159 |
| 160 RefPtrWillBeRawPtr<Range> range = controller().compositionRange(); | 160 RawPtr<Range> range = controller().compositionRange(); |
| 161 EXPECT_EQ(1, range->startOffset()); | 161 EXPECT_EQ(1, range->startOffset()); |
| 162 EXPECT_EQ(6, range->endOffset()); | 162 EXPECT_EQ(6, range->endOffset()); |
| 163 | 163 |
| 164 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range.get())); | 164 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range.get())); |
| 165 EXPECT_EQ(0u, plainTextRange.start()); | 165 EXPECT_EQ(0u, plainTextRange.start()); |
| 166 EXPECT_EQ(5u, plainTextRange.end()); | 166 EXPECT_EQ(5u, plainTextRange.end()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 TEST_F(InputMethodControllerTest, SetCompositionFromExistingTextWithInvalidOffse
ts) | 169 TEST_F(InputMethodControllerTest, SetCompositionFromExistingTextWithInvalidOffse
ts) |
| 170 { | 170 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 184 | 184 |
| 185 Vector<CompositionUnderline> underlines; | 185 Vector<CompositionUnderline> underlines; |
| 186 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 186 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 187 controller().setComposition("foo", underlines, 0, 3); | 187 controller().setComposition("foo", underlines, 0, 3); |
| 188 controller().confirmComposition(); | 188 controller().confirmComposition(); |
| 189 | 189 |
| 190 EXPECT_STREQ("foo", input->value().utf8().data()); | 190 EXPECT_STREQ("foo", input->value().utf8().data()); |
| 191 } | 191 } |
| 192 | 192 |
| 193 } // namespace blink | 193 } // namespace blink |
| OLD | NEW |