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

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: Fixed a unit test. 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..c7c29e0cedc4a06843d7bec3fa6d43f5b053784f 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
@@ -55,37 +55,37 @@ TEST_F(InputMethodControllerTest, BackspaceFromEndOfInput)
insertHTMLElement("<input id='sample'>", "sample"));
input->setValue("fooX");
- controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
+ controller().setEditableSelectionOffsets(4, 4);
EXPECT_STREQ("fooX", input->value().utf8().data());
controller().extendSelectionAndDelete(0, 0);
EXPECT_STREQ("fooX", input->value().utf8().data());
input->setValue("fooX");
- controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
+ controller().setEditableSelectionOffsets(4, 4);
EXPECT_STREQ("fooX", input->value().utf8().data());
controller().extendSelectionAndDelete(1, 0);
EXPECT_STREQ("foo", input->value().utf8().data());
input->setValue(String::fromUTF8("foo\xE2\x98\x85")); // U+2605 == "black star"
- controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
+ controller().setEditableSelectionOffsets(4, 4);
EXPECT_STREQ("foo\xE2\x98\x85", input->value().utf8().data());
controller().extendSelectionAndDelete(1, 0);
EXPECT_STREQ("foo", input->value().utf8().data());
input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86")); // U+1F3C6 == "trophy"
- controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
+ controller().setEditableSelectionOffsets(4, 4);
EXPECT_STREQ("foo\xF0\x9F\x8F\x86", input->value().utf8().data());
controller().extendSelectionAndDelete(1, 0);
EXPECT_STREQ("foo", input->value().utf8().data());
input->setValue(String::fromUTF8("foo\xE0\xB8\x81\xE0\xB9\x89")); // composed U+0E01 "ka kai" + U+0E49 "mai tho"
- controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
+ controller().setEditableSelectionOffsets(4, 4);
EXPECT_STREQ("foo\xE0\xB8\x81\xE0\xB9\x89", input->value().utf8().data());
controller().extendSelectionAndDelete(1, 0);
EXPECT_STREQ("foo", input->value().utf8().data());
input->setValue("fooX");
- controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
+ controller().setEditableSelectionOffsets(4, 4);
EXPECT_STREQ("fooX", input->value().utf8().data());
controller().extendSelectionAndDelete(0, 1);
EXPECT_STREQ("fooX", input->value().utf8().data());
@@ -129,13 +129,13 @@ TEST_F(InputMethodControllerTest, DeleteBySettingEmptyComposition)
insertHTMLElement("<input id='sample'>", "sample"));
input->setValue("foo ");
- controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
+ controller().setEditableSelectionOffsets(4, 4);
EXPECT_STREQ("foo ", input->value().utf8().data());
controller().extendSelectionAndDelete(0, 0);
EXPECT_STREQ("foo ", input->value().utf8().data());
input->setValue("foo ");
- controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
+ controller().setEditableSelectionOffsets(4, 4);
EXPECT_STREQ("foo ", input->value().utf8().data());
controller().extendSelectionAndDelete(1, 0);
EXPECT_STREQ("foo", input->value().utf8().data());
@@ -199,7 +199,7 @@ TEST_F(InputMethodControllerTest, SetCompositionForInputWithDifferentNewCursorPo
insertHTMLElement("<input id='sample'>", "sample"));
input->setValue("hello");
- controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
+ controller().setEditableSelectionOffsets(2, 2);
EXPECT_STREQ("hello", input->value().utf8().data());
EXPECT_EQ(2u, controller().getSelectionOffsets().start());
EXPECT_EQ(2u, controller().getSelectionOffsets().end());
@@ -262,7 +262,7 @@ TEST_F(InputMethodControllerTest, SetCompositionForContentEditableWithDifferentN
"</div>",
"sample");
- controller().setEditableSelectionOffsets(PlainTextRange(17, 17));
+ controller().setEditableSelectionOffsets(17, 17);
EXPECT_STREQ("hello\nworld\n0123456789", div->innerText().utf8().data());
EXPECT_EQ(17u, controller().getSelectionOffsets().start());
EXPECT_EQ(17u, controller().getSelectionOffsets().end());
@@ -348,6 +348,36 @@ TEST_F(InputMethodControllerTest, SetCompositionForContentEditableWithDifferentN
EXPECT_EQ(24u, controller().getSelectionOffsets().end());
}
+TEST_F(InputMethodControllerTest, SetCompositionWithEmptyText)
+{
+ Element* div = insertHTMLElement(
+ "<div id='sample' contenteditable='true'>hello</div>",
+ "sample");
+
+ controller().setEditableSelectionOffsets(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);
+ // With previous composition.
+ controller().setComposition("", underlines0, 2, 2);
+ EXPECT_STREQ("hello", div->innerText().utf8().data());
+ EXPECT_EQ(4u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(4u, controller().getSelectionOffsets().end());
+
+ // Without previous composition.
+ controller().setComposition("", underlines0, -1, -1);
+ EXPECT_STREQ("hello", div->innerText().utf8().data());
+ EXPECT_EQ(3u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(3u, controller().getSelectionOffsets().end());
+}
+
TEST_F(InputMethodControllerTest, CompositionFireBeforeInput)
{
document().settings()->setScriptEnabled(true);

Powered by Google App Engine
This is Rietveld 408576698