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

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

Issue 2925363002: Add SpellChecker::GetSpellCheckMarkerTouchingSelection() (Closed)
Patch Set: Respond to commments Created 3 years, 6 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/spellcheck/SpellCheckerTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/spellcheck/SpellCheckerTest.cpp b/third_party/WebKit/Source/core/editing/spellcheck/SpellCheckerTest.cpp
index ec53a097f52189bc508098f8747b94bbcc821df1..f950f5c46e1e908bd1867bc996cc4bb46ad7ae3b 100644
--- a/third_party/WebKit/Source/core/editing/spellcheck/SpellCheckerTest.cpp
+++ b/third_party/WebKit/Source/core/editing/spellcheck/SpellCheckerTest.cpp
@@ -129,4 +129,254 @@ TEST_F(SpellCheckerTest, MarkAndReplaceForHandlesMultipleReplacements) {
ToSpellCheckMarker(GetDocument().Markers().Markers()[0])->Description());
}
+TEST_F(SpellCheckerTest,
+ GetSpellCheckMarkerTouchingSelection_FirstCharSelected) {
+ SetBodyContent(
+ "<div contenteditable>"
+ "spllchck"
+ "</div>");
+ Element* div = GetDocument().QuerySelector("div");
+ Node* text = div->firstChild();
+
+ GetDocument().Markers().AddSpellingMarker(
+ EphemeralRange(Position(text, 0), Position(text, 8)));
+
+ GetDocument().GetFrame()->Selection().SetSelection(
+ SelectionInDOMTree::Builder()
+ .SetBaseAndExtent(Position(text, 0), Position(text, 1))
+ .Build());
+
+ Optional<std::pair<Node*, SpellCheckMarker*>> result =
+ GetDocument()
+ .GetFrame()
+ ->GetSpellChecker()
+ .GetSpellCheckMarkerTouchingSelection();
+ EXPECT_TRUE(result);
+}
+
+TEST_F(SpellCheckerTest,
+ GetSpellCheckMarkerTouchingSelection_LastCharSelected) {
+ SetBodyContent(
+ "<div contenteditable>"
+ "spllchck"
+ "</div>");
+ Element* div = GetDocument().QuerySelector("div");
+ Node* text = div->firstChild();
+
+ GetDocument().Markers().AddSpellingMarker(
+ EphemeralRange(Position(text, 0), Position(text, 8)));
+
+ GetDocument().GetFrame()->Selection().SetSelection(
+ SelectionInDOMTree::Builder()
+ .SetBaseAndExtent(Position(text, 7), Position(text, 8))
+ .Build());
+
+ Optional<std::pair<Node*, SpellCheckMarker*>> result =
+ GetDocument()
+ .GetFrame()
+ ->GetSpellChecker()
+ .GetSpellCheckMarkerTouchingSelection();
+ EXPECT_TRUE(result);
+}
+
+TEST_F(SpellCheckerTest,
+ GetSpellCheckMarkerTouchingSelection_SingleCharWordSelected) {
+ SetBodyContent(
+ "<div contenteditable>"
+ "s"
+ "</div>");
+ Element* div = GetDocument().QuerySelector("div");
+ Node* text = div->firstChild();
+
+ GetDocument().Markers().AddSpellingMarker(
+ EphemeralRange(Position(text, 0), Position(text, 1)));
+
+ GetDocument().GetFrame()->Selection().SetSelection(
+ SelectionInDOMTree::Builder()
+ .SetBaseAndExtent(Position(text, 0), Position(text, 1))
+ .Build());
+
+ Optional<std::pair<Node*, SpellCheckMarker*>> result =
+ GetDocument()
+ .GetFrame()
+ ->GetSpellChecker()
+ .GetSpellCheckMarkerTouchingSelection();
+ EXPECT_TRUE(result);
+}
+
+TEST_F(SpellCheckerTest,
+ GetSpellCheckMarkerTouchingSelection_CaretLeftOfSingleCharWord) {
+ SetBodyContent(
+ "<div contenteditable>"
+ "s"
+ "</div>");
+ Element* div = GetDocument().QuerySelector("div");
+ Node* text = div->firstChild();
+
+ GetDocument().Markers().AddSpellingMarker(
+ EphemeralRange(Position(text, 0), Position(text, 1)));
+
+ GetDocument().GetFrame()->Selection().SetSelection(
+ SelectionInDOMTree::Builder()
+ .SetBaseAndExtent(Position(text, 0), Position(text, 0))
+ .Build());
+
+ Optional<std::pair<Node*, SpellCheckMarker*>> result =
+ GetDocument()
+ .GetFrame()
+ ->GetSpellChecker()
+ .GetSpellCheckMarkerTouchingSelection();
+ EXPECT_TRUE(result);
+}
+
+TEST_F(SpellCheckerTest,
+ GetSpellCheckMarkerTouchingSelection_CaretRightOfSingleCharWord) {
+ SetBodyContent(
+ "<div contenteditable>"
+ "s"
+ "</div>");
+ Element* div = GetDocument().QuerySelector("div");
+ Node* text = div->firstChild();
+
+ GetDocument().Markers().AddSpellingMarker(
+ EphemeralRange(Position(text, 0), Position(text, 1)));
+
+ GetDocument().GetFrame()->Selection().SetSelection(
+ SelectionInDOMTree::Builder()
+ .SetBaseAndExtent(Position(text, 1), Position(text, 1))
+ .Build());
+
+ Optional<std::pair<Node*, SpellCheckMarker*>> result =
+ GetDocument()
+ .GetFrame()
+ ->GetSpellChecker()
+ .GetSpellCheckMarkerTouchingSelection();
+ EXPECT_TRUE(result);
+}
+
+TEST_F(SpellCheckerTest,
+ GetSpellCheckMarkerTouchingSelection_CaretLeftOfMultiCharWord) {
+ SetBodyContent(
+ "<div contenteditable>"
+ "spllchck"
+ "</div>");
+ Element* div = GetDocument().QuerySelector("div");
+ Node* text = div->firstChild();
+
+ GetDocument().Markers().AddSpellingMarker(
+ EphemeralRange(Position(text, 0), Position(text, 8)));
+
+ GetDocument().GetFrame()->Selection().SetSelection(
+ SelectionInDOMTree::Builder()
+ .SetBaseAndExtent(Position(text, 0), Position(text, 0))
+ .Build());
+
+ Optional<std::pair<Node*, SpellCheckMarker*>> result =
+ GetDocument()
+ .GetFrame()
+ ->GetSpellChecker()
+ .GetSpellCheckMarkerTouchingSelection();
+ EXPECT_TRUE(result);
+}
+
+TEST_F(SpellCheckerTest,
+ GetSpellCheckMarkerTouchingSelection_CaretRightOfMultiCharWord) {
+ SetBodyContent(
+ "<div contenteditable>"
+ "spllchck"
+ "</div>");
+ Element* div = GetDocument().QuerySelector("div");
+ Node* text = div->firstChild();
+
+ GetDocument().Markers().AddSpellingMarker(
+ EphemeralRange(Position(text, 0), Position(text, 8)));
+
+ GetDocument().GetFrame()->Selection().SetSelection(
+ SelectionInDOMTree::Builder()
+ .SetBaseAndExtent(Position(text, 8), Position(text, 8))
+ .Build());
+
+ Optional<std::pair<Node*, SpellCheckMarker*>> result =
+ GetDocument()
+ .GetFrame()
+ ->GetSpellChecker()
+ .GetSpellCheckMarkerTouchingSelection();
+ EXPECT_TRUE(result);
+}
+
+TEST_F(SpellCheckerTest,
+ GetSpellCheckMarkerTouchingSelection_CaretMiddleOfWord) {
+ SetBodyContent(
+ "<div contenteditable>"
+ "spllchck"
+ "</div>");
+ Element* div = GetDocument().QuerySelector("div");
+ Node* text = div->firstChild();
+
+ GetDocument().Markers().AddSpellingMarker(
+ EphemeralRange(Position(text, 0), Position(text, 8)));
+
+ GetDocument().GetFrame()->Selection().SetSelection(
+ SelectionInDOMTree::Builder()
+ .SetBaseAndExtent(Position(text, 4), Position(text, 4))
+ .Build());
+
+ Optional<std::pair<Node*, SpellCheckMarker*>> result =
+ GetDocument()
+ .GetFrame()
+ ->GetSpellChecker()
+ .GetSpellCheckMarkerTouchingSelection();
+ EXPECT_TRUE(result);
+}
+
+TEST_F(SpellCheckerTest,
+ GetSpellCheckMarkerTouchingSelection_CaretOneCharLeftOfMisspelling) {
+ SetBodyContent(
+ "<div contenteditable>"
+ "a spllchck"
+ "</div>");
+ Element* div = GetDocument().QuerySelector("div");
+ Node* text = div->firstChild();
+
+ GetDocument().Markers().AddSpellingMarker(
+ EphemeralRange(Position(text, 2), Position(text, 10)));
+
+ GetDocument().GetFrame()->Selection().SetSelection(
+ SelectionInDOMTree::Builder()
+ .SetBaseAndExtent(Position(text, 1), Position(text, 1))
+ .Build());
+
+ Optional<std::pair<Node*, SpellCheckMarker*>> result =
+ GetDocument()
+ .GetFrame()
+ ->GetSpellChecker()
+ .GetSpellCheckMarkerTouchingSelection();
+ EXPECT_FALSE(result);
+}
+
+TEST_F(SpellCheckerTest,
+ GetSpellCheckMarkerTouchingSelection_CaretOneCharRightOfMisspelling) {
+ SetBodyContent(
+ "<div contenteditable>"
+ "spllchck a"
+ "</div>");
+ Element* div = GetDocument().QuerySelector("div");
+ Node* text = div->firstChild();
+
+ GetDocument().Markers().AddSpellingMarker(
+ EphemeralRange(Position(text, 0), Position(text, 8)));
+
+ GetDocument().GetFrame()->Selection().SetSelection(
+ SelectionInDOMTree::Builder()
+ .SetBaseAndExtent(Position(text, 9), Position(text, 9))
+ .Build());
+
+ Optional<std::pair<Node*, SpellCheckMarker*>> result =
+ GetDocument()
+ .GetFrame()
+ ->GetSpellChecker()
+ .GetSpellCheckMarkerTouchingSelection();
+ EXPECT_FALSE(result);
+}
+
} // namespace blink
« 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