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/FrameView.h" | 9 #include "core/frame/FrameView.h" |
10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
(...skipping 22 matching lines...) Expand all Loading... |
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 = document().querySelector("input"); | 36 Element* input = document().querySelector("input"); |
37 input->focus(); | 37 input->focus(); |
38 // Do not crash in AdvanceToNextMisspelling command. | 38 // Do not crash in AdvanceToNextMisspelling command. |
39 EXPECT_TRUE( | 39 EXPECT_TRUE( |
40 document().frame()->editor().executeCommand("AdvanceToNextMisspelling")); | 40 document().frame()->editor().executeCommand("AdvanceToNextMisspelling")); |
41 } | 41 } |
42 | 42 |
| 43 // Regression test for crbug.com/701309 |
| 44 TEST_F(SpellCheckerTest, AdvanceToNextMisspellingWithImageInTableNoCrash) { |
| 45 setBodyContent( |
| 46 "<div contenteditable>" |
| 47 "<table><tr><td>" |
| 48 "<img src=foo.jpg>" |
| 49 "</td></tr></table>" |
| 50 "zz zz zz" |
| 51 "</div>"); |
| 52 document().querySelector("div")->focus(); |
| 53 updateAllLifecyclePhases(); |
| 54 |
| 55 // Do not crash in advanceToNextMisspelling. |
| 56 document().frame()->spellChecker().advanceToNextMisspelling(false); |
| 57 } |
| 58 |
43 TEST_F(SpellCheckerTest, SpellCheckDoesNotCauseUpdateLayout) { | 59 TEST_F(SpellCheckerTest, SpellCheckDoesNotCauseUpdateLayout) { |
44 setBodyContent("<input>"); | 60 setBodyContent("<input>"); |
45 HTMLInputElement* input = | 61 HTMLInputElement* input = |
46 toHTMLInputElement(document().querySelector("input")); | 62 toHTMLInputElement(document().querySelector("input")); |
47 input->focus(); | 63 input->focus(); |
48 input->setValue("Hello, input field"); | 64 input->setValue("Hello, input field"); |
49 document().updateStyleAndLayout(); | 65 document().updateStyleAndLayout(); |
50 VisibleSelection oldSelection = | 66 VisibleSelection oldSelection = |
51 document() | 67 document() |
52 .frame() | 68 .frame() |
53 ->selection() | 69 ->selection() |
54 .computeVisibleSelectionInDOMTreeDeprecated(); | 70 .computeVisibleSelectionInDOMTreeDeprecated(); |
55 | 71 |
56 Position newPosition(input->innerEditorElement()->firstChild(), 3); | 72 Position newPosition(input->innerEditorElement()->firstChild(), 3); |
57 document().frame()->selection().setSelection( | 73 document().frame()->selection().setSelection( |
58 SelectionInDOMTree::Builder().collapse(newPosition).build()); | 74 SelectionInDOMTree::Builder().collapse(newPosition).build()); |
59 ASSERT_EQ(3u, input->selectionStart()); | 75 ASSERT_EQ(3u, input->selectionStart()); |
60 | 76 |
61 EXPECT_TRUE(frame().spellChecker().isSpellCheckingEnabled()); | 77 EXPECT_TRUE(frame().spellChecker().isSpellCheckingEnabled()); |
62 forceLayout(); | 78 forceLayout(); |
63 int startCount = layoutCount(); | 79 int startCount = layoutCount(); |
64 frame().spellChecker().respondToChangedSelection( | 80 frame().spellChecker().respondToChangedSelection( |
65 oldSelection.start(), | 81 oldSelection.start(), |
66 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle); | 82 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle); |
67 EXPECT_EQ(startCount, layoutCount()); | 83 EXPECT_EQ(startCount, layoutCount()); |
68 } | 84 } |
69 | 85 |
70 } // namespace blink | 86 } // namespace blink |
OLD | NEW |