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

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

Issue 1847583003: Fix setComposingText when newCursorPosition != 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add some C++ unit tests. Created 4 years, 8 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
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 8378cfd7faeab0d62587fa4938265288c6028f32..3d14005ce069f5ed4c529a362578663cd16cbe06 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
@@ -174,7 +174,10 @@ TEST_F(InputMethodControllerTest, SetCompositionFromExistingTextWithInvalidOffse
underlines.append(CompositionUnderline(7, 8, Color(255, 0, 0), false, 0));
controller().setCompositionFromExistingText(underlines, 7, 8);
- EXPECT_FALSE(controller().compositionRange());
+ // If it exceeds the right boundary, it should stay at the right boundary
+ RawPtr<Range> range = controller().compositionRange();
+ EXPECT_EQ(4, range->startOffset());
+ EXPECT_EQ(4, range->endOffset());
}
TEST_F(InputMethodControllerTest, ConfirmPasswordComposition)
@@ -190,4 +193,135 @@ TEST_F(InputMethodControllerTest, ConfirmPasswordComposition)
EXPECT_STREQ("foo", input->value().utf8().data());
}
+TEST_F(InputMethodControllerTest, SetCompositionForInputWithDifferentNewCursorPositions)
+{
+ HTMLInputElement* input = toHTMLInputElement(
+ insertHTMLElement("<input id='sample'>", "sample"));
+
+ input->setValue("hello");
+ controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
+ EXPECT_STREQ("hello", input->value().utf8().data());
+ EXPECT_EQ(2, frame().selection().start().computeOffsetInContainerNode());
+ EXPECT_EQ(2, frame().selection().end().computeOffsetInContainerNode());
+
+ Vector<CompositionUnderline> underlines;
+ underlines.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0));
+
+ // The cursor exceeds left boundary.
+ // "*heABllo", where * stands for cursor.
+ controller().setComposition("AB", underlines, -10, -10);
+ EXPECT_STREQ("heABllo", input->value().utf8().data());
+ EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode());
+ EXPECT_EQ(0, frame().selection().end().computeOffsetInContainerNode());
+
+ // The cursor is on left boundary.
+ // "*heABllo".
+ controller().setComposition("AB", underlines, -2, -2);
+ EXPECT_STREQ("heABllo", input->value().utf8().data());
+ EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode());
+ EXPECT_EQ(0, frame().selection().end().computeOffsetInContainerNode());
+
+ // The cursor is before the composing text.
+ // "he*ABllo".
+ controller().setComposition("AB", underlines, 0, 0);
+ EXPECT_STREQ("heABllo", input->value().utf8().data());
+ EXPECT_EQ(2, frame().selection().start().computeOffsetInContainerNode());
+ EXPECT_EQ(2, frame().selection().end().computeOffsetInContainerNode());
+
+ // The cursor is after the composing text.
+ // "heAB*llo".
+ controller().setComposition("AB", underlines, 2, 2);
+ EXPECT_STREQ("heABllo", input->value().utf8().data());
+ EXPECT_EQ(4, frame().selection().start().computeOffsetInContainerNode());
+ EXPECT_EQ(4, frame().selection().end().computeOffsetInContainerNode());
+
+ // The cursor is on right boundary.
+ // "heABllo*".
+ controller().setComposition("AB", underlines, 5, 5);
+ EXPECT_STREQ("heABllo", input->value().utf8().data());
+ EXPECT_EQ(7, frame().selection().start().computeOffsetInContainerNode());
+ EXPECT_EQ(7, frame().selection().end().computeOffsetInContainerNode());
+
+ // The cursor exceeds right boundary.
+ // "heABllo*".
+ controller().setComposition("AB", underlines, 10, 10);
+ EXPECT_STREQ("heABllo", input->value().utf8().data());
+ EXPECT_EQ(7, frame().selection().start().computeOffsetInContainerNode());
+ EXPECT_EQ(7, frame().selection().end().computeOffsetInContainerNode());
+}
+
+TEST_F(InputMethodControllerTest, SetCompositionForEditableWithDifferentNewCursorPositions)
+{
+ // There are 3 nodes and 5+1+6 characters: "hello", '\n', "world!".
+ Element* div = insertHTMLElement(
+ "<div id='sample' contenteditable='true'>"
+ "hello"
+ "<p id='sample2' contenteditable='true'>world!</p>"
+ "</div>",
+ "sample");
+
+ controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
+ EXPECT_STREQ("hello\nworld!", div->innerText().utf8().data());
+ EXPECT_EQ(2, frame().selection().start().computeOffsetInContainerNode());
+ EXPECT_EQ(2, frame().selection().end().computeOffsetInContainerNode());
+
+ Vector<CompositionUnderline> underlines;
+ underlines.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0));
+
+ // The cursor exceeds left boundary.
+ // "*heABllo\nworld!", where * stands for cursor.
+ controller().setComposition("AB", underlines, -10, -10);
+ EXPECT_STREQ("heABllo\nworld!", div->innerText().utf8().data());
+ EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode());
+ EXPECT_EQ(0, frame().selection().end().computeOffsetInContainerNode());
+
+ // The cursor is on left boundary.
+ // "*heABllo\nworld!"
+ controller().setComposition("AB", underlines, -2, -2);
+ EXPECT_STREQ("heABllo\nworld!", div->innerText().utf8().data());
+ EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode());
+ EXPECT_EQ(0, frame().selection().end().computeOffsetInContainerNode());
+
+ // The cursor is before the composing text.
+ // "he*ABllo\nworld!"
+ controller().setComposition("AB", underlines, 0, 0);
+ EXPECT_STREQ("heABllo\nworld!", div->innerText().utf8().data());
+ EXPECT_EQ(2, frame().selection().start().computeOffsetInContainerNode());
+ EXPECT_EQ(2, frame().selection().end().computeOffsetInContainerNode());
+
+ // The cursor is after the composing text.
+ // "heAB*llo\nworld!"
+ controller().setComposition("AB", underlines, 2, 2);
+ EXPECT_STREQ("heABllo\nworld!", div->innerText().utf8().data());
+ EXPECT_EQ(4, frame().selection().start().computeOffsetInContainerNode());
+ EXPECT_EQ(4, frame().selection().end().computeOffsetInContainerNode());
+
+ // The cursor is on right boundary of the 1st node.
+ // "heABllo*\nworld!"
+ controller().setComposition("AB", underlines, 5, 5);
+ EXPECT_STREQ("heABllo\nworld!", div->innerText().utf8().data());
+ EXPECT_EQ(7, frame().selection().start().computeOffsetInContainerNode());
+ EXPECT_EQ(7, frame().selection().end().computeOffsetInContainerNode());
+
+ // The cursor is on left boundary of the 3rd node.
+ // "heABllo\n*world!".
+ controller().setComposition("AB", underlines, 6, 6);
+ EXPECT_STREQ("heABllo\nworld!", div->innerText().utf8().data());
+ EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode());
+ EXPECT_EQ(0, frame().selection().end().computeOffsetInContainerNode());
+
+ // The cursor is on right boundary of the 3rd node.
+ // "heABllo\nworld!*"
+ controller().setComposition("AB", underlines, 12, 12);
+ EXPECT_STREQ("heABllo\nworld!", div->innerText().utf8().data());
+ EXPECT_EQ(6, frame().selection().start().computeOffsetInContainerNode());
+ EXPECT_EQ(6, frame().selection().end().computeOffsetInContainerNode());
+
+ // The cursor exceeds right boundary.
+ // "heABllo\nworld!*"
+ controller().setComposition("AB", underlines, 20, 20);
+ EXPECT_STREQ("heABllo\nworld!", div->innerText().utf8().data());
+ EXPECT_EQ(6, frame().selection().start().computeOffsetInContainerNode());
+ EXPECT_EQ(6, frame().selection().end().computeOffsetInContainerNode());
+}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698