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/HTMLTextFormControlElement.h" | 5 #include "core/html/HTMLTextFormControlElement.h" |
6 | 6 |
7 #include "core/dom/Text.h" | 7 #include "core/dom/Text.h" |
8 #include "core/editing/FrameSelection.h" | 8 #include "core/editing/FrameSelection.h" |
9 #include "core/editing/Position.h" | 9 #include "core/editing/Position.h" |
10 #include "core/editing/VisibleSelection.h" | 10 #include "core/editing/VisibleSelection.h" |
11 #include "core/editing/VisibleUnits.h" | 11 #include "core/editing/VisibleUnits.h" |
12 #include "core/editing/spellcheck/SpellChecker.h" | 12 #include "core/editing/spellcheck/SpellChecker.h" |
13 #include "core/frame/FrameView.h" | 13 #include "core/frame/FrameView.h" |
14 #include "core/html/HTMLBRElement.h" | 14 #include "core/html/HTMLBRElement.h" |
15 #include "core/html/HTMLDocument.h" | 15 #include "core/html/HTMLDocument.h" |
16 #include "core/html/HTMLInputElement.h" | 16 #include "core/html/HTMLInputElement.h" |
17 #include "core/html/HTMLTextAreaElement.h" | 17 #include "core/html/HTMLTextAreaElement.h" |
18 #include "core/layout/LayoutTreeAsText.h" | 18 #include "core/layout/LayoutTreeAsText.h" |
19 #include "core/loader/EmptyClients.h" | 19 #include "core/loader/EmptyClients.h" |
20 #include "core/page/SpellCheckerClient.h" | 20 #include "core/page/SpellCheckerClient.h" |
21 #include "core/testing/DummyPageHolder.h" | 21 #include "core/testing/DummyPageHolder.h" |
22 #include "platform/testing/UnitTestHelpers.h" | 22 #include "platform/testing/UnitTestHelpers.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "wtf/OwnPtr.h" | 24 #include "wtf/PtrUtil.h" |
| 25 #include <memory> |
25 | 26 |
26 namespace blink { | 27 namespace blink { |
27 | 28 |
28 class HTMLTextFormControlElementTest : public ::testing::Test { | 29 class HTMLTextFormControlElementTest : public ::testing::Test { |
29 protected: | 30 protected: |
30 void SetUp() override; | 31 void SetUp() override; |
31 | 32 |
32 DummyPageHolder& page() const { return *m_dummyPageHolder; } | 33 DummyPageHolder& page() const { return *m_dummyPageHolder; } |
33 HTMLDocument& document() const { return *m_document; } | 34 HTMLDocument& document() const { return *m_document; } |
34 HTMLTextFormControlElement& textControl() const { return *m_textControl; } | 35 HTMLTextFormControlElement& textControl() const { return *m_textControl; } |
35 HTMLInputElement& input() const { return *m_input; } | 36 HTMLInputElement& input() const { return *m_input; } |
36 | 37 |
37 int layoutCount() const { return page().frameView().layoutCount(); } | 38 int layoutCount() const { return page().frameView().layoutCount(); } |
38 void forceLayoutFlag(); | 39 void forceLayoutFlag(); |
39 | 40 |
40 private: | 41 private: |
41 OwnPtr<SpellCheckerClient> m_spellCheckerClient; | 42 std::unique_ptr<SpellCheckerClient> m_spellCheckerClient; |
42 OwnPtr<DummyPageHolder> m_dummyPageHolder; | 43 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
43 | 44 |
44 Persistent<HTMLDocument> m_document; | 45 Persistent<HTMLDocument> m_document; |
45 Persistent<HTMLTextFormControlElement> m_textControl; | 46 Persistent<HTMLTextFormControlElement> m_textControl; |
46 Persistent<HTMLInputElement> m_input; | 47 Persistent<HTMLInputElement> m_input; |
47 }; | 48 }; |
48 | 49 |
49 class DummySpellCheckerClient : public EmptySpellCheckerClient { | 50 class DummySpellCheckerClient : public EmptySpellCheckerClient { |
50 public: | 51 public: |
51 virtual ~DummySpellCheckerClient() { } | 52 virtual ~DummySpellCheckerClient() { } |
52 | 53 |
53 bool isContinuousSpellCheckingEnabled() override { return true; } | 54 bool isContinuousSpellCheckingEnabled() override { return true; } |
54 | 55 |
55 TextCheckerClient& textChecker() override { return m_emptyTextCheckerClient;
} | 56 TextCheckerClient& textChecker() override { return m_emptyTextCheckerClient;
} |
56 | 57 |
57 private: | 58 private: |
58 EmptyTextCheckerClient m_emptyTextCheckerClient; | 59 EmptyTextCheckerClient m_emptyTextCheckerClient; |
59 }; | 60 }; |
60 | 61 |
61 void HTMLTextFormControlElementTest::SetUp() | 62 void HTMLTextFormControlElementTest::SetUp() |
62 { | 63 { |
63 Page::PageClients pageClients; | 64 Page::PageClients pageClients; |
64 fillWithEmptyClients(pageClients); | 65 fillWithEmptyClients(pageClients); |
65 m_spellCheckerClient = adoptPtr(new DummySpellCheckerClient); | 66 m_spellCheckerClient = wrapUnique(new DummySpellCheckerClient); |
66 pageClients.spellCheckerClient = m_spellCheckerClient.get(); | 67 pageClients.spellCheckerClient = m_spellCheckerClient.get(); |
67 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients)
; | 68 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients)
; |
68 | 69 |
69 m_document = toHTMLDocument(&m_dummyPageHolder->document()); | 70 m_document = toHTMLDocument(&m_dummyPageHolder->document()); |
70 m_document->documentElement()->setInnerHTML("<body><textarea id=textarea></t
extarea><input id=input /></body>", ASSERT_NO_EXCEPTION); | 71 m_document->documentElement()->setInnerHTML("<body><textarea id=textarea></t
extarea><input id=input /></body>", ASSERT_NO_EXCEPTION); |
71 m_document->view()->updateAllLifecyclePhases(); | 72 m_document->view()->updateAllLifecyclePhases(); |
72 m_textControl = toHTMLTextFormControlElement(m_document->getElementById("tex
tarea")); | 73 m_textControl = toHTMLTextFormControlElement(m_document->getElementById("tex
tarea")); |
73 m_textControl->focus(); | 74 m_textControl->focus(); |
74 m_input = toHTMLInputElement(m_document->getElementById("input")); | 75 m_input = toHTMLInputElement(m_document->getElementById("input")); |
75 } | 76 } |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 ASSERT_EQ(3, input->selectionStart()); | 209 ASSERT_EQ(3, input->selectionStart()); |
209 | 210 |
210 Persistent<SpellChecker> spellChecker(SpellChecker::create(page().frame())); | 211 Persistent<SpellChecker> spellChecker(SpellChecker::create(page().frame())); |
211 forceLayoutFlag(); | 212 forceLayoutFlag(); |
212 int startCount = layoutCount(); | 213 int startCount = layoutCount(); |
213 spellChecker->respondToChangedSelection(oldSelection, FrameSelection::CloseT
yping | FrameSelection::ClearTypingStyle); | 214 spellChecker->respondToChangedSelection(oldSelection, FrameSelection::CloseT
yping | FrameSelection::ClearTypingStyle); |
214 EXPECT_EQ(startCount, layoutCount()); | 215 EXPECT_EQ(startCount, layoutCount()); |
215 } | 216 } |
216 | 217 |
217 } // namespace blink | 218 } // namespace blink |
OLD | NEW |