Chromium Code Reviews| 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/html/TextControlElement.h" | 5 #include "core/html/TextControlElement.h" |
| 6 | 6 |
| 7 #include <memory> | |
|
yosin_UTC9
2017/02/23 02:52:08
Please move this removal in another patch to make
Xiaocheng
2017/02/23 03:36:43
Done.
| |
| 7 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 8 #include "core/editing/spellcheck/SpellChecker.h" | 9 #include "core/editing/FrameSelection.h" |
| 9 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| 10 #include "core/html/HTMLInputElement.h" | 11 #include "core/html/HTMLInputElement.h" |
| 11 #include "core/html/HTMLTextAreaElement.h" | 12 #include "core/html/HTMLTextAreaElement.h" |
| 12 #include "core/loader/EmptyClients.h" | 13 #include "core/loader/EmptyClients.h" |
| 13 #include "core/page/SpellCheckerClient.h" | |
| 14 #include "core/testing/DummyPageHolder.h" | 14 #include "core/testing/DummyPageHolder.h" |
| 15 #include "platform/testing/UnitTestHelpers.h" | 15 #include "platform/testing/UnitTestHelpers.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "wtf/PtrUtil.h" | 17 #include "wtf/PtrUtil.h" |
| 18 #include <memory> | |
| 19 | 18 |
| 20 namespace blink { | 19 namespace blink { |
| 21 | 20 |
| 22 class TextControlElementTest : public ::testing::Test { | 21 class TextControlElementTest : public ::testing::Test { |
| 23 protected: | 22 protected: |
| 24 void SetUp() override; | 23 void SetUp() override; |
| 25 | 24 |
| 26 DummyPageHolder& page() const { return *m_dummyPageHolder; } | 25 DummyPageHolder& page() const { return *m_dummyPageHolder; } |
| 27 Document& document() const { return *m_document; } | 26 Document& document() const { return *m_document; } |
| 28 TextControlElement& textControl() const { return *m_textControl; } | 27 TextControlElement& textControl() const { return *m_textControl; } |
| 29 HTMLInputElement& input() const { return *m_input; } | 28 HTMLInputElement& input() const { return *m_input; } |
| 30 | 29 |
| 31 int layoutCount() const { return page().frameView().layoutCount(); } | 30 int layoutCount() const { return page().frameView().layoutCount(); } |
| 32 void forceLayoutFlag(); | 31 void forceLayoutFlag(); |
| 33 | 32 |
| 34 private: | 33 private: |
| 35 std::unique_ptr<SpellCheckerClient> m_spellCheckerClient; | |
| 36 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 34 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 37 | 35 |
| 38 Persistent<Document> m_document; | 36 Persistent<Document> m_document; |
| 39 Persistent<TextControlElement> m_textControl; | 37 Persistent<TextControlElement> m_textControl; |
| 40 Persistent<HTMLInputElement> m_input; | 38 Persistent<HTMLInputElement> m_input; |
| 41 }; | 39 }; |
| 42 | 40 |
| 43 class DummySpellCheckerClient : public EmptySpellCheckerClient { | |
| 44 public: | |
| 45 virtual ~DummySpellCheckerClient() {} | |
| 46 | |
| 47 bool isSpellCheckingEnabled() override { return true; } | |
| 48 | |
| 49 TextCheckerClient& textChecker() override { return m_emptyTextCheckerClient; } | |
| 50 | |
| 51 private: | |
| 52 EmptyTextCheckerClient m_emptyTextCheckerClient; | |
| 53 }; | |
| 54 | |
| 55 void TextControlElementTest::SetUp() { | 41 void TextControlElementTest::SetUp() { |
| 56 Page::PageClients pageClients; | 42 Page::PageClients pageClients; |
| 57 fillWithEmptyClients(pageClients); | 43 fillWithEmptyClients(pageClients); |
| 58 m_spellCheckerClient = WTF::wrapUnique(new DummySpellCheckerClient); | |
| 59 pageClients.spellCheckerClient = m_spellCheckerClient.get(); | |
| 60 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients); | 44 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients); |
| 61 | 45 |
| 62 m_document = &m_dummyPageHolder->document(); | 46 m_document = &m_dummyPageHolder->document(); |
| 63 m_document->documentElement()->setInnerHTML( | 47 m_document->documentElement()->setInnerHTML( |
| 64 "<body><textarea id=textarea></textarea><input id=input /></body>"); | 48 "<body><textarea id=textarea></textarea><input id=input /></body>"); |
| 65 m_document->view()->updateAllLifecyclePhases(); | 49 m_document->view()->updateAllLifecyclePhases(); |
| 66 m_textControl = toTextControlElement(m_document->getElementById("textarea")); | 50 m_textControl = toTextControlElement(m_document->getElementById("textarea")); |
| 67 m_textControl->focus(); | 51 m_textControl->focus(); |
| 68 m_input = toHTMLInputElement(m_document->getElementById("input")); | 52 m_input = toHTMLInputElement(m_document->getElementById("input")); |
| 69 } | 53 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 HTMLInputElement* input = | 102 HTMLInputElement* input = |
| 119 toHTMLInputElement(document().getElementById("input")); | 103 toHTMLInputElement(document().getElementById("input")); |
| 120 input->setValue("Hello"); | 104 input->setValue("Hello"); |
| 121 HTMLElement* innerEditor = input->innerEditorElement(); | 105 HTMLElement* innerEditor = input->innerEditorElement(); |
| 122 EXPECT_EQ(5u, TextControlElement::indexForPosition( | 106 EXPECT_EQ(5u, TextControlElement::indexForPosition( |
| 123 innerEditor, | 107 innerEditor, |
| 124 Position(innerEditor, PositionAnchorType::AfterAnchor))); | 108 Position(innerEditor, PositionAnchorType::AfterAnchor))); |
| 125 } | 109 } |
| 126 | 110 |
| 127 } // namespace blink | 111 } // namespace blink |
| OLD | NEW |