| 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 12541b3a1a0a01eded967cafbc7f6e764e5e6df9..2185551b73430dc3dbbee19722ab38a046917a12 100644
|
| --- a/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
|
| +++ b/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
|
| @@ -11,6 +11,7 @@
|
| #include "core/editing/Editor.h"
|
| #include "core/editing/FrameSelection.h"
|
| #include "core/editing/markers/DocumentMarkerController.h"
|
| +#include "core/editing/markers/SuggestionMarker.h"
|
| #include "core/events/MouseEvent.h"
|
| #include "core/frame/FrameView.h"
|
| #include "core/frame/LocalFrame.h"
|
| @@ -1380,7 +1381,11 @@ TEST_F(InputMethodControllerTest, CommitPlainTextWithUnderlineReplace) {
|
|
|
| controller().setCompositionFromExistingText(underlines, 8, 12);
|
|
|
| - underlines.push_back(CompositionUnderline(1, 11, Color(255, 0, 0), false, 0));
|
| + // Adding an empty string as a suggestion causes the CompositionUnderline to
|
| + // persist across editing operations, which is required for this and the next
|
| + // few tests
|
| + underlines.push_back(
|
| + CompositionUnderline(1, 11, Color(255, 0, 0), false, 0, {""}));
|
|
|
| controller().commitText(String("string"), underlines, 0);
|
|
|
| @@ -1621,6 +1626,106 @@ TEST_F(InputMethodControllerTest,
|
| // 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, WhitespaceFixupAroundUnsplittableMarker) {
|
| + 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().addSuggestionMarker(markerRange, Color::black, false, Color::black, Vector<String>());
|
| +
|
| + // 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, WhitespaceFixupAroundUnsplittableMarker2) {
|
| + 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().addSuggestionMarker(markerRange, Color::black, false, Color::black, Vector<String>());
|
| +
|
| + // 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
|
| + // 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, WhitespaceFixupAroundUnsplittableMarker3) {
|
| + 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().addSuggestionMarker(markerRange, Color::black, false, Color::black, Vector<String>());
|
| +
|
| + // 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, WhitespaceFixupAroundUnsplittableMarker4) {
|
| + 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().addSuggestionMarker(markerRange, Color::black, false, Color::black, Vector<String>());
|
| +
|
| + // 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());
|
| ASSERT_STREQ(
|
| "\xC2\xA0text\xC2\xA0",
|
| getMarkedText(document().markers(), div->firstChild(), 0).utf8().data());
|
| @@ -1738,14 +1843,12 @@ TEST_F(InputMethodControllerTest, Marker_ReplaceEntireMarker) {
|
| TEST_F(InputMethodControllerTest, Marker_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().addTextMatchMarker(
|
| markerRange, TextMatchMarker::MatchStatus::kInactive);
|
|
|
| EXPECT_EQ(1u, document().markers().markers().size());
|
| -
|
| // Replace "Initial text" with "New string"
|
| Vector<CompositionUnderline> emptyUnderlines;
|
| controller().setCompositionFromExistingText(emptyUnderlines, 0, 12);
|
| @@ -1775,124 +1878,138 @@ TEST_F(InputMethodControllerTest, Marker_ReplaceTextWithMarkerAtEnd) {
|
| EXPECT_EQ(0u, document().markers().markers().size());
|
| }
|
|
|
| -TEST_F(InputMethodControllerTest, Marker_Deletions) {
|
| +TEST_F(InputMethodControllerTest, Marker_DeleteStartOfMarker) {
|
| Element* div = insertHTMLElement(
|
| - "<div id='sample' contenteditable>1111122222333334444455555</div>",
|
| - "sample");
|
| -
|
| - EphemeralRange markerRange = PlainTextRange(0, 5).createRange(*div);
|
| - document().markers().addTextMatchMarker(
|
| - markerRange, TextMatchMarker::MatchStatus::kInactive);
|
| + "<div id='sample' contenteditable>Initial text.</div>", "sample");
|
|
|
| - markerRange = PlainTextRange(5, 10).createRange(*div);
|
| - document().markers().addTextMatchMarker(
|
| - markerRange, TextMatchMarker::MatchStatus::kInactive);
|
| + // Add marker to "Initial"
|
| + EphemeralRange markerRange = PlainTextRange(0, 7).createRange(*div);
|
| + document().markers().addTextMatchMarker(markerRange, false);
|
|
|
| - markerRange = PlainTextRange(10, 15).createRange(*div);
|
| - document().markers().addTextMatchMarker(
|
| - markerRange, TextMatchMarker::MatchStatus::kInactive);
|
| + Vector<CompositionUnderline> emptyUnderlines;
|
| + // Set composition to "Ini"
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 0, 3);
|
| + // Delete "Ini"
|
| + controller().commitText(String(""), emptyUnderlines, 0);
|
|
|
| - markerRange = PlainTextRange(15, 20).createRange(*div);
|
| - document().markers().addTextMatchMarker(
|
| - markerRange, TextMatchMarker::MatchStatus::kInactive);
|
| + // 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());
|
| +}
|
|
|
| - markerRange = PlainTextRange(20, 25).createRange(*div);
|
| - document().markers().addTextMatchMarker(
|
| - markerRange, TextMatchMarker::MatchStatus::kInactive);
|
| +TEST_F(InputMethodControllerTest, Marker_DeleteBeforeStartOfMarker) {
|
| + Element* div = insertHTMLElement(
|
| + "<div id='sample' contenteditable>Initial text.</div>", "sample");
|
|
|
| - EXPECT_EQ(5u, document().markers().markers().size());
|
| + // Add marker to "text"
|
| + EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
|
| + document().markers().addTextMatchMarker(markerRange, false);
|
|
|
| - // Delete third marker and portions of second and fourth
|
| Vector<CompositionUnderline> emptyUnderlines;
|
| - controller().setCompositionFromExistingText(emptyUnderlines, 8, 17);
|
| - controller().commitText(String(""), emptyUnderlines, 0);
|
| + // Set composition to "Initial"
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
|
|
|
| - // Verify markers were updated correctly
|
| - EXPECT_EQ(4u, document().markers().markers().size());
|
| + // Delete "Initial"
|
| + controller().commitText(String(""), emptyUnderlines, 0);
|
|
|
| - EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
|
| + // 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,
|
| + Marker_DeleteBeforeAndIncludingStartOfMarker) {
|
| + Element* div = insertHTMLElement(
|
| + "<div id='sample' contenteditable>Initial text.</div>", "sample");
|
|
|
| - EXPECT_EQ(5u, document().markers().markers()[1]->startOffset());
|
| - EXPECT_EQ(8u, document().markers().markers()[1]->endOffset());
|
| + // Add marker to "text"
|
| + EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
|
| + document().markers().addTextMatchMarker(markerRange, false);
|
|
|
| - EXPECT_EQ(8u, document().markers().markers()[2]->startOffset());
|
| - EXPECT_EQ(11u, document().markers().markers()[2]->endOffset());
|
| + Vector<CompositionUnderline> emptyUnderlines;
|
| + // Set composition to "Initial te"
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 0, 10);
|
|
|
| - EXPECT_EQ(11u, document().markers().markers()[3]->startOffset());
|
| - EXPECT_EQ(16u, document().markers().markers()[3]->endOffset());
|
| + // Delete "Initial te"
|
| + controller().commitText(String(""), emptyUnderlines, 0);
|
|
|
| - document().markers().clear();
|
| + // 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());
|
| +}
|
|
|
| - markerRange = PlainTextRange(5, 10).createRange(*div);
|
| - document().markers().addTextMatchMarker(
|
| - markerRange, TextMatchMarker::MatchStatus::kInactive);
|
| +TEST_F(InputMethodControllerTest, Marker_DeleteEndOfMarker) {
|
| + Element* div = insertHTMLElement(
|
| + "<div id='sample' contenteditable>Initial text.</div>", "sample");
|
|
|
| - // Delete exactly on a marker
|
| - controller().setCompositionFromExistingText(emptyUnderlines, 5, 10);
|
| - controller().commitText(String(""), emptyUnderlines, 0);
|
| - EXPECT_EQ(0u, document().markers().markers().size());
|
| + // Add marker to "text"
|
| + EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
|
| + document().markers().addTextMatchMarker(markerRange, false);
|
|
|
| - markerRange = PlainTextRange(5, 10).createRange(*div);
|
| - document().markers().addTextMatchMarker(
|
| - markerRange, TextMatchMarker::MatchStatus::kInactive);
|
| + Vector<CompositionUnderline> emptyUnderlines;
|
| + // Set composition to "xt."
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 10, 13);
|
|
|
| - // Delete middle of marker
|
| - controller().setCompositionFromExistingText(emptyUnderlines, 6, 9);
|
| + // 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(5u, document().markers().markers()[0]->startOffset());
|
| - EXPECT_EQ(7u, document().markers().markers()[0]->endOffset());
|
| + EXPECT_EQ(8u, document().markers().markers()[0]->startOffset());
|
| + EXPECT_EQ(10u, document().markers().markers()[0]->endOffset());
|
| }
|
|
|
| -TEST_F(InputMethodControllerTest, Marker_Insertions) {
|
| +TEST_F(InputMethodControllerTest, Marker_DeleteBeforeEndOfMarker) {
|
| Element* div = insertHTMLElement(
|
| - "<div id='sample' contenteditable>1111122222333334444455555</div>",
|
| - "sample");
|
| + "<div id='sample' contenteditable>Initial text.</div>", "sample");
|
| + // Add marker to "text"
|
| + EphemeralRange markerRange = PlainTextRange(8, 12).createRange(*div);
|
| + document().markers().addTextMatchMarker(markerRange, false);
|
|
|
| - EphemeralRange markerRange = PlainTextRange(0, 5).createRange(*div);
|
| - document().markers().addTextMatchMarker(
|
| - markerRange, TextMatchMarker::MatchStatus::kInactive);
|
| + Vector<CompositionUnderline> emptyUnderlines;
|
| + // Set composition to "Initial"
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 0, 7);
|
|
|
| - markerRange = PlainTextRange(5, 10).createRange(*div);
|
| - document().markers().addTextMatchMarker(
|
| - markerRange, TextMatchMarker::MatchStatus::kInactive);
|
| + // Delete "Initial"
|
| + controller().commitText(String(""), emptyUnderlines, 0);
|
|
|
| - markerRange = PlainTextRange(10, 15).createRange(*div);
|
| - document().markers().addTextMatchMarker(
|
| - markerRange, TextMatchMarker::MatchStatus::kInactive);
|
| + // 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());
|
| +}
|
|
|
| - // insert in middle of second marker
|
| - Vector<CompositionUnderline> emptyUnderlines;
|
| - controller().setComposition("", emptyUnderlines, 7, 7);
|
| - controller().commitText(String("66666"), emptyUnderlines, -7);
|
| +TEST_F(InputMethodControllerTest, Marker_DeleteNestedMarkers) {
|
| + Element* div = insertHTMLElement(
|
| + "<div id='sample' contenteditable>Initial text.</div>", "sample");
|
|
|
| - EXPECT_EQ(3u, document().markers().markers().size());
|
| + EphemeralRange markerRange = PlainTextRange(0, 6).createRange(*div);
|
| + document().markers().addSuggestionMarker(markerRange, Color::black, false, Color::black, Vector<String>());
|
|
|
| - EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
|
| - EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
|
| + markerRange = PlainTextRange(1, 9).createRange(*div);
|
| + document().markers().addSuggestionMarker(markerRange, Color::black, false, Color::black, Vector<String>());
|
|
|
| - EXPECT_EQ(5u, document().markers().markers()[1]->startOffset());
|
| - EXPECT_EQ(15u, document().markers().markers()[1]->endOffset());
|
| + markerRange = PlainTextRange(2, 3).createRange(*div);
|
| + document().markers().addSuggestionMarker(markerRange, Color::black, false, Color::black, Vector<String>());
|
|
|
| - EXPECT_EQ(15u, document().markers().markers()[2]->startOffset());
|
| - EXPECT_EQ(20u, document().markers().markers()[2]->endOffset());
|
| + Vector<CompositionUnderline> emptyUnderlines;
|
| + controller().setCompositionFromExistingText(emptyUnderlines, 5, 7);
|
|
|
| - // insert between first and second markers (cursor is at position 5)
|
| - controller().commitText(String("77777"), emptyUnderlines, 0);
|
| + controller().commitText(String(""), emptyUnderlines, 0);
|
|
|
| EXPECT_EQ(3u, document().markers().markers().size());
|
|
|
| EXPECT_EQ(0u, document().markers().markers()[0]->startOffset());
|
| EXPECT_EQ(5u, document().markers().markers()[0]->endOffset());
|
|
|
| - EXPECT_EQ(10u, document().markers().markers()[1]->startOffset());
|
| - EXPECT_EQ(20u, document().markers().markers()[1]->endOffset());
|
| + EXPECT_EQ(1u, document().markers().markers()[1]->startOffset());
|
| + EXPECT_EQ(7u, document().markers().markers()[1]->endOffset());
|
|
|
| - EXPECT_EQ(20u, document().markers().markers()[2]->startOffset());
|
| - EXPECT_EQ(25u, document().markers().markers()[2]->endOffset());
|
| + EXPECT_EQ(2u, document().markers().markers()[2]->startOffset());
|
| + EXPECT_EQ(3u, document().markers().markers()[2]->endOffset());
|
| }
|
|
|
| } // namespace blink
|
|
|