Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: third_party/WebKit/Source/core/editing/spellcheck/SpellCheckerTest.cpp

Issue 2749153003: Add null position check in SpellChecker::findFirstMisspelling (Closed)
Patch Set: Add bug number Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 command.
56 EXPECT_TRUE(
57 document().frame()->editor().executeCommand("AdvanceToNextMisspelling"));
yosin_UTC9 2017/03/15 03:50:48 It is better to call |SpellChecker::advanceToNextM
Xiaocheng 2017/03/15 18:12:26 Done.
58 }
59
43 TEST_F(SpellCheckerTest, SpellCheckDoesNotCauseUpdateLayout) { 60 TEST_F(SpellCheckerTest, SpellCheckDoesNotCauseUpdateLayout) {
44 setBodyContent("<input>"); 61 setBodyContent("<input>");
45 HTMLInputElement* input = 62 HTMLInputElement* input =
46 toHTMLInputElement(document().querySelector("input")); 63 toHTMLInputElement(document().querySelector("input"));
47 input->focus(); 64 input->focus();
48 input->setValue("Hello, input field"); 65 input->setValue("Hello, input field");
49 document().updateStyleAndLayout(); 66 document().updateStyleAndLayout();
50 VisibleSelection oldSelection = 67 VisibleSelection oldSelection =
51 document() 68 document()
52 .frame() 69 .frame()
53 ->selection() 70 ->selection()
54 .computeVisibleSelectionInDOMTreeDeprecated(); 71 .computeVisibleSelectionInDOMTreeDeprecated();
55 72
56 Position newPosition(input->innerEditorElement()->firstChild(), 3); 73 Position newPosition(input->innerEditorElement()->firstChild(), 3);
57 document().frame()->selection().setSelection( 74 document().frame()->selection().setSelection(
58 SelectionInDOMTree::Builder().collapse(newPosition).build()); 75 SelectionInDOMTree::Builder().collapse(newPosition).build());
59 ASSERT_EQ(3u, input->selectionStart()); 76 ASSERT_EQ(3u, input->selectionStart());
60 77
61 EXPECT_TRUE(frame().spellChecker().isSpellCheckingEnabled()); 78 EXPECT_TRUE(frame().spellChecker().isSpellCheckingEnabled());
62 forceLayout(); 79 forceLayout();
63 int startCount = layoutCount(); 80 int startCount = layoutCount();
64 frame().spellChecker().respondToChangedSelection( 81 frame().spellChecker().respondToChangedSelection(
65 oldSelection.start(), 82 oldSelection.start(),
66 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle); 83 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle);
67 EXPECT_EQ(startCount, layoutCount()); 84 EXPECT_EQ(startCount, layoutCount());
68 } 85 }
69 86
70 } // namespace blink 87 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698