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

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

Issue 2020973002: Reland: Fix setComposingText with empty text when newCursorPosition != 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 b176244dce8033ea84b758f52b67d042185fbfce..ba9009782aec812462ee3b9f5542878a06143bcb 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
@@ -348,6 +348,128 @@ TEST_F(InputMethodControllerTest, SetCompositionForContentEditableWithDifferentN
EXPECT_EQ(24u, controller().getSelectionOffsets().end());
}
+TEST_F(InputMethodControllerTest, SetCompositionWithEmptyTextForDifferentNewCursorPositions)
+{
+ // There are 7 nodes and 5+1+5+1+3+4+3 characters: "hello", '\n', "world", "\n", "012", "3456", "789".
+ Element* div = insertHTMLElement(
+ "<div id='sample' contenteditable='true'>"
+ "hello"
+ "<div id='sample2' contenteditable='true'>world"
+ "<p>012<b>3456</b><i>789</i></p>"
+ "</div>"
+ "</div>",
+ "sample");
+
+ controller().setEditableSelectionOffsets(PlainTextRange(17, 17));
+ EXPECT_STREQ("hello\nworld\n0123456789", div->innerText().utf8().data());
+ EXPECT_EQ(17u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(17u, controller().getSelectionOffsets().end());
+
+ Vector<CompositionUnderline> underlines;
+ underlines.append(CompositionUnderline(0, 0, Color(255, 0, 0), false, 0));
+
+ // The cursor exceeds left boundary.
+ // "*hello\nworld\n0123456789", where * stands for cursor.
+ controller().setComposition("", underlines, -100, -100);
+ EXPECT_STREQ("hello\nworld\n0123456789", div->innerText().utf8().data());
+ EXPECT_EQ(0u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(0u, controller().getSelectionOffsets().end());
+
+ // The cursor exceeds right boundary.
+ // "hello\nworld\n0123456789*".
+ controller().setComposition("", underlines, 100, 100);
+ EXPECT_STREQ("hello\nworld\n0123456789", div->innerText().utf8().data());
+ EXPECT_EQ(22u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(22u, controller().getSelectionOffsets().end());
+
+ // The cursor is on left boundary.
+ // "*hello\nworld\n0123456789".
+ controller().setComposition("", underlines, -22, -22);
+ EXPECT_STREQ("hello\nworld\n0123456789", div->innerText().utf8().data());
+ EXPECT_EQ(0u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(0u, controller().getSelectionOffsets().end());
+
+ // The cursor is on right boundary.
+ // "hello\nworld\n0123456789*".
+ controller().setComposition("", underlines, 22, 22);
+ EXPECT_STREQ("hello\nworld\n0123456789", div->innerText().utf8().data());
+ EXPECT_EQ(22u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(22u, controller().getSelectionOffsets().end());
+
+ // The cursor is in the 1st node.
+ // "he*llo\nworld\n0123456789".
+ controller().setComposition("", underlines, -20, -20);
+ EXPECT_STREQ("hello\nworld\n0123456789", div->innerText().utf8().data());
+ EXPECT_EQ(2u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(2u, controller().getSelectionOffsets().end());
+
+ // The cursor is on the left boundary of the 5th node.
+ // "hello\nworld\n*01234AB56789".
+ controller().setComposition("", underlines, 10, 10);
+ EXPECT_STREQ("hello\nworld\n0123456789", div->innerText().utf8().data());
+ EXPECT_EQ(12u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(12u, controller().getSelectionOffsets().end());
+
+ // The cursor stays.
+ // "hello\nworld\n*01234AB56789".
+ controller().setComposition("", underlines, 0, 0);
+ EXPECT_STREQ("hello\nworld\n0123456789", div->innerText().utf8().data());
+ EXPECT_EQ(12u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(12u, controller().getSelectionOffsets().end());
+}
+
+TEST_F(InputMethodControllerTest, SetCompositionWithEmptyTextAndPreviousCompositionForDifferentNewCursorPositions)
+{
+ Element* div = insertHTMLElement(
+ "<div id='sample' contenteditable='true'>hello</div>",
+ "sample");
+
+ controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
+ EXPECT_STREQ("hello", div->innerText().utf8().data());
+ EXPECT_EQ(2u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(2u, controller().getSelectionOffsets().end());
+
+ Vector<CompositionUnderline> underlines0;
+ underlines0.append(CompositionUnderline(0, 0, Color(255, 0, 0), false, 0));
+ Vector<CompositionUnderline> underlines2;
+ underlines2.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0));
+
+ controller().setComposition("AB", underlines2, 2, 2);
+ // The cursor exceeds left boundary.
+ controller().setComposition("", underlines0, -100, -100);
+ EXPECT_STREQ("hello", div->innerText().utf8().data());
+ EXPECT_EQ(0u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(0u, controller().getSelectionOffsets().end());
+
+ controller().setComposition("AB", underlines2, 2, 2);
+ // The cursor exceeds right boundary.
+ controller().setComposition("", underlines0, 100, 100);
+ EXPECT_STREQ("hello", div->innerText().utf8().data());
+ EXPECT_EQ(5u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(5u, controller().getSelectionOffsets().end());
+
+ controller().setComposition("AB", underlines2, 2, 2);
+ // The cursor is on left boundary.
+ controller().setComposition("", underlines0, -5, -5);
+ EXPECT_STREQ("hello", div->innerText().utf8().data());
+ EXPECT_EQ(0u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(0u, controller().getSelectionOffsets().end());
+
+ controller().setComposition("AB", underlines2, 2, 2);
+ // The cursor is on right boundary.
+ controller().setComposition("", underlines0, 5, 5);
+ EXPECT_STREQ("hello", div->innerText().utf8().data());
+ EXPECT_EQ(5u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(5u, controller().getSelectionOffsets().end());
+
+ controller().setComposition("AB", underlines2, 2, 2);
+ // The cursor stays.
+ controller().setComposition("", underlines0, 0, 0);
+ EXPECT_STREQ("hello", div->innerText().utf8().data());
+ EXPECT_EQ(5u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(5u, controller().getSelectionOffsets().end());
+}
+
TEST_F(InputMethodControllerTest, CompositionFireBeforeInput)
{
document().settings()->setScriptEnabled(true);

Powered by Google App Engine
This is Rietveld 408576698