| 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/Document.h" |
| 7 #include "core/dom/Text.h" | 8 #include "core/dom/Text.h" |
| 8 #include "core/editing/FrameSelection.h" | 9 #include "core/editing/FrameSelection.h" |
| 9 #include "core/editing/Position.h" | 10 #include "core/editing/Position.h" |
| 10 #include "core/editing/VisibleSelection.h" | 11 #include "core/editing/VisibleSelection.h" |
| 11 #include "core/editing/VisibleUnits.h" | 12 #include "core/editing/VisibleUnits.h" |
| 12 #include "core/editing/spellcheck/SpellChecker.h" | 13 #include "core/editing/spellcheck/SpellChecker.h" |
| 13 #include "core/frame/FrameView.h" | 14 #include "core/frame/FrameView.h" |
| 14 #include "core/html/HTMLBRElement.h" | 15 #include "core/html/HTMLBRElement.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/PtrUtil.h" | 24 #include "wtf/PtrUtil.h" |
| 25 #include <memory> | 25 #include <memory> |
| 26 | 26 |
| 27 namespace blink { | 27 namespace blink { |
| 28 | 28 |
| 29 class HTMLTextFormControlElementTest : public ::testing::Test { | 29 class HTMLTextFormControlElementTest : public ::testing::Test { |
| 30 protected: | 30 protected: |
| 31 void SetUp() override; | 31 void SetUp() override; |
| 32 | 32 |
| 33 DummyPageHolder& page() const { return *m_dummyPageHolder; } | 33 DummyPageHolder& page() const { return *m_dummyPageHolder; } |
| 34 HTMLDocument& document() const { return *m_document; } | 34 Document& document() const { return *m_document; } |
| 35 HTMLTextFormControlElement& textControl() const { return *m_textControl; } | 35 HTMLTextFormControlElement& textControl() const { return *m_textControl; } |
| 36 HTMLInputElement& input() const { return *m_input; } | 36 HTMLInputElement& input() const { return *m_input; } |
| 37 | 37 |
| 38 int layoutCount() const { return page().frameView().layoutCount(); } | 38 int layoutCount() const { return page().frameView().layoutCount(); } |
| 39 void forceLayoutFlag(); | 39 void forceLayoutFlag(); |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 std::unique_ptr<SpellCheckerClient> m_spellCheckerClient; | 42 std::unique_ptr<SpellCheckerClient> m_spellCheckerClient; |
| 43 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 43 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 44 | 44 |
| 45 Persistent<HTMLDocument> m_document; | 45 Persistent<Document> m_document; |
| 46 Persistent<HTMLTextFormControlElement> m_textControl; | 46 Persistent<HTMLTextFormControlElement> m_textControl; |
| 47 Persistent<HTMLInputElement> m_input; | 47 Persistent<HTMLInputElement> m_input; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 class DummySpellCheckerClient : public EmptySpellCheckerClient { | 50 class DummySpellCheckerClient : public EmptySpellCheckerClient { |
| 51 public: | 51 public: |
| 52 virtual ~DummySpellCheckerClient() { } | 52 virtual ~DummySpellCheckerClient() { } |
| 53 | 53 |
| 54 bool isContinuousSpellCheckingEnabled() override { return true; } | 54 bool isContinuousSpellCheckingEnabled() override { return true; } |
| 55 | 55 |
| 56 TextCheckerClient& textChecker() override { return m_emptyTextCheckerClient;
} | 56 TextCheckerClient& textChecker() override { return m_emptyTextCheckerClient;
} |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 EmptyTextCheckerClient m_emptyTextCheckerClient; | 59 EmptyTextCheckerClient m_emptyTextCheckerClient; |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 void HTMLTextFormControlElementTest::SetUp() | 62 void HTMLTextFormControlElementTest::SetUp() |
| 63 { | 63 { |
| 64 Page::PageClients pageClients; | 64 Page::PageClients pageClients; |
| 65 fillWithEmptyClients(pageClients); | 65 fillWithEmptyClients(pageClients); |
| 66 m_spellCheckerClient = wrapUnique(new DummySpellCheckerClient); | 66 m_spellCheckerClient = wrapUnique(new DummySpellCheckerClient); |
| 67 pageClients.spellCheckerClient = m_spellCheckerClient.get(); | 67 pageClients.spellCheckerClient = m_spellCheckerClient.get(); |
| 68 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients)
; | 68 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients)
; |
| 69 | 69 |
| 70 m_document = toHTMLDocument(&m_dummyPageHolder->document()); | 70 m_document = &m_dummyPageHolder->document(); |
| 71 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); |
| 72 m_document->view()->updateAllLifecyclePhases(); | 72 m_document->view()->updateAllLifecyclePhases(); |
| 73 m_textControl = toHTMLTextFormControlElement(m_document->getElementById("tex
tarea")); | 73 m_textControl = toHTMLTextFormControlElement(m_document->getElementById("tex
tarea")); |
| 74 m_textControl->focus(); | 74 m_textControl->focus(); |
| 75 m_input = toHTMLInputElement(m_document->getElementById("input")); | 75 m_input = toHTMLInputElement(m_document->getElementById("input")); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void HTMLTextFormControlElementTest::forceLayoutFlag() | 78 void HTMLTextFormControlElementTest::forceLayoutFlag() |
| 79 { | 79 { |
| 80 FrameView& frameView = page().frameView(); | 80 FrameView& frameView = page().frameView(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 static VisiblePosition startOfWord(const VisiblePosition& position) | 137 static VisiblePosition startOfWord(const VisiblePosition& position) |
| 138 { | 138 { |
| 139 return startOfWord(position, LeftWordIfOnBoundary); | 139 return startOfWord(position, LeftWordIfOnBoundary); |
| 140 } | 140 } |
| 141 | 141 |
| 142 static VisiblePosition endOfWord(const VisiblePosition& position) | 142 static VisiblePosition endOfWord(const VisiblePosition& position) |
| 143 { | 143 { |
| 144 return endOfWord(position, RightWordIfOnBoundary); | 144 return endOfWord(position, RightWordIfOnBoundary); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void testBoundary(HTMLDocument& document, HTMLTextFormControlElement& textContro
l) | 147 void testBoundary(Document& document, HTMLTextFormControlElement& textControl) |
| 148 { | 148 { |
| 149 for (unsigned i = 0; i < textControl.innerEditorValue().length(); i++) { | 149 for (unsigned i = 0; i < textControl.innerEditorValue().length(); i++) { |
| 150 textControl.setSelectionRange(i, i); | 150 textControl.setSelectionRange(i, i); |
| 151 Position position = document.frame()->selection().start(); | 151 Position position = document.frame()->selection().start(); |
| 152 SCOPED_TRACE(::testing::Message() << "offset " << position.computeEditin
gOffset() << " of " << nodePositionAsStringForTesting(position.anchorNode()).asc
ii().data()); | 152 SCOPED_TRACE(::testing::Message() << "offset " << position.computeEditin
gOffset() << " of " << nodePositionAsStringForTesting(position.anchorNode()).asc
ii().data()); |
| 153 { | 153 { |
| 154 SCOPED_TRACE("HTMLTextFormControlElement::startOfWord"); | 154 SCOPED_TRACE("HTMLTextFormControlElement::startOfWord"); |
| 155 testFunctionEquivalence(position, HTMLTextFormControlElement::startO
fWord, startOfWord); | 155 testFunctionEquivalence(position, HTMLTextFormControlElement::startO
fWord, startOfWord); |
| 156 } | 156 } |
| 157 { | 157 { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 ASSERT_EQ(3, input->selectionStart()); | 209 ASSERT_EQ(3, input->selectionStart()); |
| 210 | 210 |
| 211 Persistent<SpellChecker> spellChecker(SpellChecker::create(page().frame())); | 211 Persistent<SpellChecker> spellChecker(SpellChecker::create(page().frame())); |
| 212 forceLayoutFlag(); | 212 forceLayoutFlag(); |
| 213 int startCount = layoutCount(); | 213 int startCount = layoutCount(); |
| 214 spellChecker->respondToChangedSelection(oldSelection, FrameSelection::CloseT
yping | FrameSelection::ClearTypingStyle); | 214 spellChecker->respondToChangedSelection(oldSelection, FrameSelection::CloseT
yping | FrameSelection::ClearTypingStyle); |
| 215 EXPECT_EQ(startCount, layoutCount()); | 215 EXPECT_EQ(startCount, layoutCount()); |
| 216 } | 216 } |
| 217 | 217 |
| 218 } // namespace blink | 218 } // namespace blink |
| OLD | NEW |