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

Unified Diff: third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp

Issue 2665923002: Modify DocumentMarkerController to support overlapping and nested DocumentMarkers (Closed)
Patch Set: Use range-for statement in setMarkersActive() Created 3 years, 10 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 | « no previous file | third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp b/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
index d89e9b19ad8f2db0cc69b8d18b08dddfb492fb34..6f38120bbae30f32b7b56f2ea98029b1b55de458 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
@@ -1196,4 +1196,157 @@ TEST_F(InputMethodControllerTest, CommitPlainTextWithUnderlineReplace) {
EXPECT_EQ(15u, document().markers().markers()[0]->endOffset());
}
+TEST_F(InputMethodControllerTest, DeleteStartOfMarker) {
+ Element* div = insertHTMLElement(
+ "<div id='sample' contenteditable>Initial text.</div>", "sample");
+
+ // Add marker to "Initial"
+ EphemeralRange markerRange = PlainTextRange(0, 7).createRange(*div);
+ document().markers().addMarker(markerRange.startPosition(),
+ markerRange.endPosition(),
+ DocumentMarker::TextMatch);
+
+ Vector<CompositionUnderline> emptyUnderlines;
+ // Set composition to "Ini"
+ controller().setCompositionFromExistingText(emptyUnderlines, 0, 3);
+ // Delete "Ini"
+ controller().commitText(String(""), emptyUnderlines, 0);
+
+ // Check that the marker is still attached to "tial"
+ EXPECT_EQ(1u, document().markers().markers().size());
+ EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
+ EXPECT_EQ(4u, document().markers().markers()[0]->endOffset());
+}
+
+TEST_F(InputMethodControllerTest, DeleteBeforeStartOfMarker) {
+ Element* div = insertHTMLElement(
+ "<div id='sample' contenteditable>Initial text.</div>", "sample");
+
+ // Add marker to "text"
+ EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
+ document().markers().addMarker(markerRange.startPosition(),
+ markerRange.endPosition(),
+ DocumentMarker::TextMatch);
+
+ Vector<CompositionUnderline> emptyUnderlines;
+ // Set composition to "Initial"
+ controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
+
+ // Delete "Initial"
+ controller().commitText(String(""), emptyUnderlines, 0);
+
+ // Check that the marker is still attached to "text"
+ EXPECT_EQ(1u, document().markers().markers().size());
+ EXPECT_EQ(1u, document().markers().markers()[0]->startOffset());
+ EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
+}
+
+TEST_F(InputMethodControllerTest, DeleteBeforeAndIncludingStartOfMarker) {
+ Element* div = insertHTMLElement(
+ "<div id='sample' contenteditable>Initial text.</div>", "sample");
+
+ // Add marker to "text"
+ EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
+ document().markers().addMarker(markerRange.startPosition(),
+ markerRange.endPosition(),
+ DocumentMarker::TextMatch);
+
+ Vector<CompositionUnderline> emptyUnderlines;
+ // Set composition to "Initial te"
+ controller().setCompositionFromExistingText(emptyUnderlines, 0, 10);
+
+ // Delete "Initial te"
+ controller().commitText(String(""), emptyUnderlines, 0);
+
+ // Check that the marker is still attached to "xt"
+ EXPECT_EQ(1u, document().markers().markers().size());
+ EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
+ EXPECT_EQ(2u, document().markers().markers()[0]->endOffset());
+}
+
+TEST_F(InputMethodControllerTest, DeleteEndOfMarker) {
+ Element* div = insertHTMLElement(
+ "<div id='sample' contenteditable>Initial text.</div>", "sample");
+
+ // Add marker to "text"
+ EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
+ document().markers().addMarker(markerRange.startPosition(),
+ markerRange.endPosition(),
+ DocumentMarker::TextMatch);
+
+ Vector<CompositionUnderline> emptyUnderlines;
+ // Set composition to "xt."
+ controller().setCompositionFromExistingText(emptyUnderlines, 10, 13);
+
+ // Delete "xt."
+ controller().commitText(String(""), emptyUnderlines, 0);
+
+ // Check that the marker is still attached to "te"
+ EXPECT_EQ(1u, document().markers().markers().size());
+ EXPECT_EQ(8u, document().markers().markers()[0]->startOffset());
+ EXPECT_EQ(10u, document().markers().markers()[0]->endOffset());
+}
+
+TEST_F(InputMethodControllerTest, DeleteBeforeEndOfMarker) {
+ Element* div = insertHTMLElement(
+ "<div id='sample' contenteditable>Initial text.</div>", "sample");
+
+ // Add marker to "text"
+ EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
+ document().markers().addMarker(markerRange.startPosition(),
+ markerRange.endPosition(),
+ DocumentMarker::TextMatch);
+
+ Vector<CompositionUnderline> emptyUnderlines;
+ // Set composition to "Initial"
+ controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
+
+ // Delete "Initial"
+ controller().commitText(String(""), emptyUnderlines, 0);
+
+ // Check that the marker is still attached to "text"
+ EXPECT_EQ(1u, document().markers().markers().size());
+ EXPECT_EQ(1u, document().markers().markers()[0]->startOffset());
+ EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
+}
+
+TEST_F(InputMethodControllerTest, DeleteSplittingNestedMarkers) {
+ Element* div = insertHTMLElement(
+ "<div id='sample' contenteditable>Initial text.</div>", "sample");
+
+ EphemeralRange markerRange = PlainTextRange(0, 6).createRange(*div);
+ document().markers().addMarker(markerRange.startPosition(),
+ markerRange.endPosition(),
+ DocumentMarker::TextMatch);
+
+ markerRange = PlainTextRange(1, 9).createRange(*div);
+ document().markers().addMarker(markerRange.startPosition(),
+ markerRange.endPosition(),
+ DocumentMarker::TextMatch);
+
+ markerRange = PlainTextRange(2, 3).createRange(*div);
+ document().markers().addMarker(markerRange.startPosition(),
+ markerRange.endPosition(),
+ DocumentMarker::TextMatch);
+
+ Vector<CompositionUnderline> emptyUnderlines;
+ controller().setCompositionFromExistingText(emptyUnderlines, 5, 7);
+
+ controller().commitText(String(""), emptyUnderlines, 0);
+
+ EXPECT_EQ(4u, document().markers().markers().size());
+
+ EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
+ EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
+
+ EXPECT_EQ(1u, document().markers().markers()[1]->startOffset());
+ EXPECT_EQ(5u, document().markers().markers()[1]->endOffset());
+
+ EXPECT_EQ(2u, document().markers().markers()[2]->startOffset());
+ EXPECT_EQ(3u, document().markers().markers()[2]->endOffset());
+
+ EXPECT_EQ(5u, document().markers().markers()[3]->startOffset());
+ EXPECT_EQ(7u, document().markers().markers()[3]->endOffset());
+}
+
} // namespace blink
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698