Chromium Code Reviews| 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 322e8367a663e6d78cfa4130f6ab1f462080a257..e533d91ade00719b9b60b43970ef7664aff52975 100644 |
| --- a/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp |
| +++ b/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp |
| @@ -1290,4 +1290,300 @@ TEST_F(InputMethodControllerTest, SelectionWhenFocusChangeFinishesComposition) { |
| .computeOffsetInContainerNode()); |
| } |
| +static String getMarkedText(DocumentMarkerController& documentMarkerController, |
|
yosin_UTC9
2017/02/28 01:29:37
Could you move IMCTest changes into separate CL to
|
| + Node* node, |
| + int markerIndex) { |
| + DocumentMarker* marker = documentMarkerController.markers()[markerIndex]; |
| + return node->textContent().substring( |
| + marker->startOffset(), marker->endOffset() - marker->startOffset()); |
| +} |
| + |
| +// TODO(crbug.com/696652): setCompositionFromExistingText() is counting the |
|
yosin_UTC9
2017/02/28 01:29:37
I would like to discuss this issue in crbug.com/69
|
| +// offsets funny in the next few tests because the string starts with a space. |
| +// The 5, 9 offsets will need to be changed to 6, 10 once this is fixed |
| + |
| +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, 5, 9); |
| + controller().commitText(String(""), emptyUnderlines, 0); |
| + |
| + ASSERT_STREQ(" text ", div->innerHTML().utf8().data()); |
| + |
| + // Check that the marker is still attached to "text" and doesn't include |
| + // either space around it |
| + EXPECT_EQ(1u, document().markers().markersFor(div->firstChild()).size()); |
| + ASSERT_STREQ( |
| + "text", |
| + getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| +} |
| + |
| +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, 5, 9); |
| + controller().commitText(String(""), emptyUnderlines, 0); |
| + |
| + ASSERT_STREQ(" text ", div->innerHTML().utf8().data()); |
| + |
| + // before "text" but not the space after |
| + EXPECT_EQ(1u, document().markers().markers().size()); |
| + ASSERT_STREQ( |
| + " text", |
| + getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| +} |
| + |
| +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, 5, 9); |
| + controller().commitText(String(""), emptyUnderlines, 0); |
| + |
| + ASSERT_STREQ(" text ", div->innerHTML().utf8().data()); |
| + |
| + // 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()); |
| + ASSERT_STREQ( |
| + "text ", |
| + getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| +} |
| + |
| +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, 5, 9); |
| + controller().commitText(String(""), emptyUnderlines, 0); |
| + |
| + ASSERT_STREQ(" text ", div->innerHTML().utf8().data()); |
| + |
| + // 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()); |
| + ASSERT_STREQ( |
| + " text ", |
| + getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| +} |
| + |
| +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); |
| + |
| + ASSERT_STREQ("Original text", div->innerHTML().utf8().data()); |
| + |
| + // Verify marker is under "Original text" |
| + EXPECT_EQ(1u, document().markers().markers().size()); |
| + ASSERT_STREQ( |
| + "Original text", |
| + getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| +} |
| + |
| +TEST_F(InputMethodControllerTest, ReplaceBeforeAndAfterStartOfMarker) { |
| + Element* div = insertHTMLElement( |
| + "<div id='sample' contenteditable>This is some initial text</div>", |
| + "sample"); |
| + |
| + // Add marker under "initial text" |
| + EphemeralRange markerRange = PlainTextRange(13, 25).createRange(*div); |
| + document().markers().addMarker(markerRange.startPosition(), |
| + markerRange.endPosition(), |
| + DocumentMarker::TextMatch); |
| + |
| + // Replace "some initial" with "boring" |
| + Vector<CompositionUnderline> emptyUnderlines; |
| + controller().setCompositionFromExistingText(emptyUnderlines, 8, 20); |
| + controller().commitText(String("boring"), emptyUnderlines, 0); |
| + |
| + ASSERT_STREQ("This is boring text", div->innerHTML().utf8().data()); |
| + |
| + // Verify marker is under " text" |
| + EXPECT_EQ(1u, document().markers().markers().size()); |
| + ASSERT_STREQ( |
| + " text", |
| + getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| +} |
| + |
| +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); |
| + |
| + ASSERT_STREQ("Initial string", div->innerHTML().utf8().data()); |
| + |
| + // Verify marker is under "Initial string" |
| + EXPECT_EQ(1u, document().markers().markers().size()); |
| + ASSERT_STREQ( |
| + "Initial string", |
| + getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| +} |
| + |
| +TEST_F(InputMethodControllerTest, ReplaceBeforeAndAfterEndOfMarker) { |
| + Element* div = insertHTMLElement( |
| + "<div id='sample' contenteditable>This is some initial text</div>", |
| + "sample"); |
| + |
| + // Add marker under "some initial" |
| + EphemeralRange markerRange = PlainTextRange(8, 20).createRange(*div); |
| + document().markers().addMarker(markerRange.startPosition(), |
| + markerRange.endPosition(), |
| + DocumentMarker::TextMatch); |
| + |
| + // Replace "initial text" with "content" |
| + Vector<CompositionUnderline> emptyUnderlines; |
| + controller().setCompositionFromExistingText(emptyUnderlines, 13, 25); |
| + controller().commitText(String("content"), emptyUnderlines, 0); |
| + |
| + ASSERT_STREQ("This is some content", div->innerHTML().utf8().data()); |
| + |
| + // Verify marker is under "some " |
| + EXPECT_EQ(1u, document().markers().markers().size()); |
| + ASSERT_STREQ( |
| + "some ", |
| + getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| +} |
| + |
| +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); |
| + |
| + ASSERT_STREQ("Initial string", div->innerHTML().utf8().data()); |
| + |
| + // Verify marker is under "string" |
| + EXPECT_EQ(1u, document().markers().markers().size()); |
| + ASSERT_STREQ( |
| + "string", |
| + getMarkedText(document().markers(), div->firstChild(), 0).utf8().data()); |
| +} |
| + |
| +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); |
| + |
| + ASSERT_STREQ("New string", div->innerHTML().utf8().data()); |
| + |
| + // 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); |
| + |
| + ASSERT_STREQ("New string", div->innerHTML().utf8().data()); |
| + |
| + // Verify marker was removed |
| + EXPECT_EQ(0u, document().markers().markers().size()); |
| +} |
| + |
| } // namespace blink |