| 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 af4913f8026b15cf7dc9fdb0f1393e7f3ac4e5c8..1889da43b47cc391524210d5aa0a7603800eabd4 100644
|
| --- a/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
|
| +++ b/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
|
| @@ -1196,4 +1196,213 @@ TEST_F(InputMethodControllerTest, CommitPlainTextWithUnderlineReplace) {
|
| EXPECT_EQ(15u, document().markers().markers()[0]->endOffset());
|
| }
|
|
|
| +TEST_F(InputMethodControllerTest, WhitespaceFixupAroundMarker) {
|
| + Element* div = insertHTMLElement(
|
| + "<div id='sample' contenteditable>Initial text blah</div>", "sample");
|
| +
|
| + // Add marker under "text" (use TextMatch since Composition markers don't
|
| + // persist across editing operations)
|
| + EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
|
| + document().markers().addMarker(markerRange.startPosition(),
|
| + markerRange.endPosition(),
|
| + DocumentMarker::TextMatch);
|
| + // Delete "Initial"
|
| + Vector<CompositionUnderline> emptyUnderlines;
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
|
| + controller().commitText(String(""), emptyUnderlines, 0);
|
| +
|
| + // Delete "blah"
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 6, 10);
|
| + controller().commitText(String(""), emptyUnderlines, 0);
|
| +
|
| + // Check that the marker is still attached to "text" and doesn't include
|
| + // either space around it
|
| + 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, WhitespaceFixupAroundMarker2) {
|
| + Element* div = insertHTMLElement(
|
| + "<div id='sample' contenteditable>Initial text blah</div>", "sample");
|
| +
|
| + // Add marker under " text" (use TextMatch since Composition markers don't
|
| + // persist across editing operations)
|
| + EphemeralRange markerRange = PlainTextRange(7, 12).createRange(*div);
|
| + document().markers().addMarker(markerRange.startPosition(),
|
| + markerRange.endPosition(),
|
| + DocumentMarker::TextMatch);
|
| + // Delete "Initial"
|
| + Vector<CompositionUnderline> emptyUnderlines;
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
|
| + controller().commitText(String(""), emptyUnderlines, 0);
|
| +
|
| + // Delete "blah"
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 6, 10);
|
| + controller().commitText(String(""), emptyUnderlines, 0);
|
| +
|
| + // before "text" but not the space after
|
| + EXPECT_EQ(1u, document().markers().markers().size());
|
| + EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
|
| + EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
|
| +}
|
| +
|
| +TEST_F(InputMethodControllerTest, WhitespaceFixupAroundMarker3) {
|
| + Element* div = insertHTMLElement(
|
| + "<div id='sample' contenteditable>Initial text blah</div>", "sample");
|
| +
|
| + // Add marker under "text " (use TextMatch since Composition markers don't
|
| + // persist across editing operations)
|
| + EphemeralRange markerRange = PlainTextRange(8, 13).createRange(*div);
|
| + document().markers().addMarker(markerRange.startPosition(),
|
| + markerRange.endPosition(),
|
| + DocumentMarker::TextMatch);
|
| + // Delete "Initial"
|
| + Vector<CompositionUnderline> emptyUnderlines;
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
|
| + controller().commitText(String(""), emptyUnderlines, 0);
|
| +
|
| + // Delete "blah"
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 6, 10);
|
| + controller().commitText(String(""), emptyUnderlines, 0);
|
| +
|
| + // Check that the marker is still attached to "text " and includes the space
|
| + // after "text" but not the space before
|
| + EXPECT_EQ(1u, document().markers().markers().size());
|
| + EXPECT_EQ(1u, document().markers().markers()[0]->startOffset());
|
| + EXPECT_EQ(6u, document().markers().markers()[0]->endOffset());
|
| +}
|
| +
|
| +TEST_F(InputMethodControllerTest, WhitespaceFixupAroundMarker4) {
|
| + Element* div = insertHTMLElement(
|
| + "<div id='sample' contenteditable>Initial text blah</div>", "sample");
|
| +
|
| + // Add marker under " text " (use TextMatch since Composition markers don't
|
| + // persist across editing operations)
|
| + EphemeralRange markerRange = PlainTextRange(7, 13).createRange(*div);
|
| + document().markers().addMarker(markerRange.startPosition(),
|
| + markerRange.endPosition(),
|
| + DocumentMarker::TextMatch);
|
| +
|
| + // Delete "Initial"
|
| + Vector<CompositionUnderline> emptyUnderlines;
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
|
| + controller().commitText(String(""), emptyUnderlines, 0);
|
| +
|
| + // Delete "blah"
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 6, 10);
|
| + controller().commitText(String(""), emptyUnderlines, 0);
|
| +
|
| + // Check that the marker is still attached to " text " and includes both the
|
| + // space before "text" and the space after
|
| + EXPECT_EQ(1u, document().markers().markers().size());
|
| + EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
|
| + EXPECT_EQ(6u, document().markers().markers()[0]->endOffset());
|
| +}
|
| +
|
| +TEST_F(InputMethodControllerTest, ReplaceStartOfMarker) {
|
| + Element* div = insertHTMLElement(
|
| + "<div id='sample' contenteditable>Initial text</div>", "sample");
|
| +
|
| + // Add marker under "Initial text"
|
| + EphemeralRange markerRange = PlainTextRange(0, 12).createRange(*div);
|
| + document().markers().addMarker(markerRange.startPosition(),
|
| + markerRange.endPosition(),
|
| + DocumentMarker::TextMatch);
|
| +
|
| + // Replace "Initial" with "Original"
|
| + Vector<CompositionUnderline> emptyUnderlines;
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
|
| + controller().commitText(String("Original"), emptyUnderlines, 0);
|
| +
|
| + // Verify marker is under "Original text"
|
| + EXPECT_EQ(1u, document().markers().markers().size());
|
| + EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
|
| + EXPECT_EQ(13u, document().markers().markers()[0]->endOffset());
|
| +}
|
| +
|
| +TEST_F(InputMethodControllerTest, ReplaceEndOfMarker) {
|
| + Element* div = insertHTMLElement(
|
| + "<div id='sample' contenteditable>Initial text</div>", "sample");
|
| +
|
| + // Add marker under "Initial text"
|
| + EphemeralRange markerRange = PlainTextRange(0, 12).createRange(*div);
|
| + document().markers().addMarker(markerRange.startPosition(),
|
| + markerRange.endPosition(),
|
| + DocumentMarker::TextMatch);
|
| +
|
| + // Replace "text" with "string"
|
| + Vector<CompositionUnderline> emptyUnderlines;
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 8, 12);
|
| + controller().commitText(String("string"), emptyUnderlines, 0);
|
| +
|
| + // Verify marker is under "Initial string"
|
| + EXPECT_EQ(1u, document().markers().markers().size());
|
| + EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
|
| + EXPECT_EQ(14u, document().markers().markers()[0]->endOffset());
|
| +}
|
| +
|
| +TEST_F(InputMethodControllerTest, ReplaceEntireMarker) {
|
| + Element* div = insertHTMLElement(
|
| + "<div id='sample' contenteditable>Initial text</div>", "sample");
|
| +
|
| + // Add marker under "text"
|
| + EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
|
| + document().markers().addMarker(markerRange.startPosition(),
|
| + markerRange.endPosition(),
|
| + DocumentMarker::TextMatch);
|
| +
|
| + // Replace "text" with "string"
|
| + Vector<CompositionUnderline> emptyUnderlines;
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 8, 12);
|
| + controller().commitText(String("string"), emptyUnderlines, 0);
|
| +
|
| + // Verify marker is under "string"
|
| + EXPECT_EQ(1u, document().markers().markers().size());
|
| + EXPECT_EQ(8u, document().markers().markers()[0]->startOffset());
|
| + EXPECT_EQ(14u, document().markers().markers()[0]->endOffset());
|
| +}
|
| +
|
| +TEST_F(InputMethodControllerTest, ReplaceTextWithMarkerAtBeginning) {
|
| + Element* div = insertHTMLElement(
|
| + "<div id='sample' contenteditable>Initial text</div>", "sample");
|
| +
|
| + // Add marker under "Initial"
|
| + EphemeralRange markerRange = PlainTextRange(0, 7).createRange(*div);
|
| + document().markers().addMarker(markerRange.startPosition(),
|
| + markerRange.endPosition(),
|
| + DocumentMarker::TextMatch);
|
| +
|
| + EXPECT_EQ(1u, document().markers().markers().size());
|
| +
|
| + // Replace "Initial text" with "New string"
|
| + Vector<CompositionUnderline> emptyUnderlines;
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 0, 12);
|
| + controller().commitText(String("New string"), emptyUnderlines, 0);
|
| +
|
| + // Verify marker was removed
|
| + EXPECT_EQ(0u, document().markers().markers().size());
|
| +}
|
| +
|
| +TEST_F(InputMethodControllerTest, ReplaceTextWithMarkerAtEnd) {
|
| + Element* div = insertHTMLElement(
|
| + "<div id='sample' contenteditable>Initial text</div>", "sample");
|
| +
|
| + // Add marker under "text"
|
| + EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
|
| + document().markers().addMarker(markerRange.startPosition(),
|
| + markerRange.endPosition(),
|
| + DocumentMarker::TextMatch);
|
| +
|
| + EXPECT_EQ(1u, document().markers().markers().size());
|
| +
|
| + // Replace "Initial text" with "New string"
|
| + Vector<CompositionUnderline> emptyUnderlines;
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 0, 12);
|
| + controller().commitText(String("New string"), emptyUnderlines, 0);
|
| +
|
| + // Verify marker was removed
|
| + EXPECT_EQ(0u, document().markers().markers().size());
|
| +}
|
| +
|
| } // namespace blink
|
|
|