| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/spellcheck/SpellChecker.h" | 5 #include "core/editing/spellcheck/SpellChecker.h" |
| 6 | 6 |
| 7 #include "core/editing/Editor.h" | 7 #include "core/editing/Editor.h" |
| 8 #include "core/editing/spellcheck/SpellCheckTestBase.h" | 8 #include "core/editing/spellcheck/SpellCheckTestBase.h" |
| 9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
| 10 #include "core/frame/LocalFrameView.h" | 10 #include "core/frame/LocalFrameView.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 Page().GetFrameView().SetFrameRect(frame_rect); | 29 Page().GetFrameView().SetFrameRect(frame_rect); |
| 30 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); | 30 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 TEST_F(SpellCheckerTest, AdvanceToNextMisspellingWithEmptyInputNoCrash) { | 33 TEST_F(SpellCheckerTest, AdvanceToNextMisspellingWithEmptyInputNoCrash) { |
| 34 SetBodyContent("<input placeholder='placeholder'>abc"); | 34 SetBodyContent("<input placeholder='placeholder'>abc"); |
| 35 UpdateAllLifecyclePhases(); | 35 UpdateAllLifecyclePhases(); |
| 36 Element* input = GetDocument().QuerySelector("input"); | 36 Element* input = GetDocument().QuerySelector("input"); |
| 37 input->focus(); | 37 input->focus(); |
| 38 // Do not crash in advanceToNextMisspelling. | 38 // Do not crash in advanceToNextMisspelling. |
| 39 GetDocument().GetFrame()->GetSpellChecker().AdvanceToNextMisspelling(false); | 39 GetSpellChecker().AdvanceToNextMisspelling(false); |
| 40 } | 40 } |
| 41 | 41 |
| 42 // Regression test for crbug.com/701309 | 42 // Regression test for crbug.com/701309 |
| 43 TEST_F(SpellCheckerTest, AdvanceToNextMisspellingWithImageInTableNoCrash) { | 43 TEST_F(SpellCheckerTest, AdvanceToNextMisspellingWithImageInTableNoCrash) { |
| 44 SetBodyContent( | 44 SetBodyContent( |
| 45 "<div contenteditable>" | 45 "<div contenteditable>" |
| 46 "<table><tr><td>" | 46 "<table><tr><td>" |
| 47 "<img src=foo.jpg>" | 47 "<img src=foo.jpg>" |
| 48 "</td></tr></table>" | 48 "</td></tr></table>" |
| 49 "zz zz zz" | 49 "zz zz zz" |
| 50 "</div>"); | 50 "</div>"); |
| 51 GetDocument().QuerySelector("div")->focus(); | 51 GetDocument().QuerySelector("div")->focus(); |
| 52 UpdateAllLifecyclePhases(); | 52 UpdateAllLifecyclePhases(); |
| 53 | 53 |
| 54 // Do not crash in advanceToNextMisspelling. | 54 // Do not crash in advanceToNextMisspelling. |
| 55 GetDocument().GetFrame()->GetSpellChecker().AdvanceToNextMisspelling(false); | 55 GetSpellChecker().AdvanceToNextMisspelling(false); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Regression test for crbug.com/728801 | 58 // Regression test for crbug.com/728801 |
| 59 TEST_F(SpellCheckerTest, AdvancedToNextMisspellingWrapSearchNoCrash) { | 59 TEST_F(SpellCheckerTest, AdvancedToNextMisspellingWrapSearchNoCrash) { |
| 60 SetBodyContent("<div contenteditable> zz zz zz </div>"); | 60 SetBodyContent("<div contenteditable> zz zz zz </div>"); |
| 61 | 61 |
| 62 Element* div = GetDocument().QuerySelector("div"); | 62 Element* div = GetDocument().QuerySelector("div"); |
| 63 div->focus(); | 63 div->focus(); |
| 64 Selection().SetSelection(SelectionInDOMTree::Builder() | 64 Selection().SetSelection(SelectionInDOMTree::Builder() |
| 65 .Collapse(Position::LastPositionInNode(div)) | 65 .Collapse(Position::LastPositionInNode(div)) |
| 66 .Build()); | 66 .Build()); |
| 67 UpdateAllLifecyclePhases(); | 67 UpdateAllLifecyclePhases(); |
| 68 | 68 |
| 69 // TODO(xiaochengh): We should have SpellCheckTestBase::GetSpellChecker(). | 69 GetSpellChecker().AdvanceToNextMisspelling(false); |
| 70 GetFrame().GetSpellChecker().AdvanceToNextMisspelling(false); | |
| 71 } | 70 } |
| 72 | 71 |
| 73 TEST_F(SpellCheckerTest, SpellCheckDoesNotCauseUpdateLayout) { | 72 TEST_F(SpellCheckerTest, SpellCheckDoesNotCauseUpdateLayout) { |
| 74 SetBodyContent("<input>"); | 73 SetBodyContent("<input>"); |
| 75 HTMLInputElement* input = | 74 HTMLInputElement* input = |
| 76 toHTMLInputElement(GetDocument().QuerySelector("input")); | 75 toHTMLInputElement(GetDocument().QuerySelector("input")); |
| 77 input->focus(); | 76 input->focus(); |
| 78 input->setValue("Hello, input field"); | 77 input->setValue("Hello, input field"); |
| 79 GetDocument().UpdateStyleAndLayout(); | 78 GetDocument().UpdateStyleAndLayout(); |
| 80 VisibleSelection old_selection = | 79 VisibleSelection old_selection = |
| 81 GetDocument() | 80 GetDocument() |
| 82 .GetFrame() | 81 .GetFrame() |
| 83 ->Selection() | 82 ->Selection() |
| 84 .ComputeVisibleSelectionInDOMTreeDeprecated(); | 83 .ComputeVisibleSelectionInDOMTreeDeprecated(); |
| 85 | 84 |
| 86 Position new_position(input->InnerEditorElement()->firstChild(), 3); | 85 Position new_position(input->InnerEditorElement()->firstChild(), 3); |
| 87 GetDocument().GetFrame()->Selection().SetSelection( | 86 GetDocument().GetFrame()->Selection().SetSelection( |
| 88 SelectionInDOMTree::Builder().Collapse(new_position).Build()); | 87 SelectionInDOMTree::Builder().Collapse(new_position).Build()); |
| 89 ASSERT_EQ(3u, input->selectionStart()); | 88 ASSERT_EQ(3u, input->selectionStart()); |
| 90 | 89 |
| 91 EXPECT_TRUE(GetFrame().GetSpellChecker().IsSpellCheckingEnabled()); | 90 EXPECT_TRUE(GetSpellChecker().IsSpellCheckingEnabled()); |
| 92 ForceLayout(); | 91 ForceLayout(); |
| 93 int start_count = LayoutCount(); | 92 int start_count = LayoutCount(); |
| 94 GetFrame().GetSpellChecker().RespondToChangedSelection( | 93 GetSpellChecker().RespondToChangedSelection( |
| 95 old_selection.Start(), | 94 old_selection.Start(), |
| 96 FrameSelection::kCloseTyping | FrameSelection::kClearTypingStyle); | 95 FrameSelection::kCloseTyping | FrameSelection::kClearTypingStyle); |
| 97 EXPECT_EQ(start_count, LayoutCount()); | 96 EXPECT_EQ(start_count, LayoutCount()); |
| 98 } | 97 } |
| 99 | 98 |
| 100 } // namespace blink | 99 } // namespace blink |
| OLD | NEW |