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

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: Store Position objects as local variables... 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/InputMethodController.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4af9689b59c85a4c5a410e556eda3cdfb60b1237..b355a091de56b4412b60eb9a0e53ad587709e3d1 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
@@ -193,6 +193,161 @@ 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(2u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(2u, controller().getSelectionOffsets().end());
+
+ 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, -100, -100);
+ EXPECT_STREQ("heABllo", input->value().utf8().data());
+ EXPECT_EQ(0u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(0u, controller().getSelectionOffsets().end());
+
+ // The cursor is on left boundary.
+ // "*heABllo".
+ controller().setComposition("AB", underlines, -2, -2);
+ EXPECT_STREQ("heABllo", input->value().utf8().data());
+ EXPECT_EQ(0u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(0u, controller().getSelectionOffsets().end());
+
+ // The cursor is before the composing text.
+ // "he*ABllo".
+ controller().setComposition("AB", underlines, 0, 0);
+ EXPECT_STREQ("heABllo", input->value().utf8().data());
+ EXPECT_EQ(2u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(2u, controller().getSelectionOffsets().end());
+
+ // The cursor is after the composing text.
+ // "heAB*llo".
+ controller().setComposition("AB", underlines, 2, 2);
+ EXPECT_STREQ("heABllo", input->value().utf8().data());
+ EXPECT_EQ(4u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(4u, controller().getSelectionOffsets().end());
+
+ // The cursor is on right boundary.
+ // "heABllo*".
+ controller().setComposition("AB", underlines, 5, 5);
+ EXPECT_STREQ("heABllo", input->value().utf8().data());
+ EXPECT_EQ(7u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(7u, controller().getSelectionOffsets().end());
+
+ // The cursor exceeds right boundary.
+ // "heABllo*".
+ controller().setComposition("AB", underlines, 100, 100);
+ EXPECT_STREQ("heABllo", input->value().utf8().data());
+ EXPECT_EQ(7u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(7u, controller().getSelectionOffsets().end());
+}
+
+TEST_F(InputMethodControllerTest, SetCompositionForContentEditableWithDifferentNewCursorPositions)
+{
+ // 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, 2, Color(255, 0, 0), false, 0));
+
+ // The cursor exceeds left boundary.
+ // "*hello\nworld\n01234AB56789", where * stands for cursor.
+ controller().setComposition("AB", underlines, -100, -100);
+ EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data());
+ EXPECT_EQ(0u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(0u, controller().getSelectionOffsets().end());
+
+ // The cursor is on left boundary.
+ // "*hello\nworld\n01234AB56789".
+ controller().setComposition("AB", underlines, -17, -17);
+ EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data());
+ EXPECT_EQ(0u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(0u, controller().getSelectionOffsets().end());
+
+ // The cursor is in the 1st node.
+ // "he*llo\nworld\n01234AB56789".
+ controller().setComposition("AB", underlines, -15, -15);
+ EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data());
+ EXPECT_EQ(2u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(2u, controller().getSelectionOffsets().end());
+
+ // The cursor is on right boundary of the 1st node.
+ // "hello*\nworld\n01234AB56789".
+ controller().setComposition("AB", underlines, -12, -12);
+ EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data());
+ EXPECT_EQ(5u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(5u, controller().getSelectionOffsets().end());
+
+ // The cursor is on right boundary of the 2nd node.
+ // "hello\n*world\n01234AB56789".
+ controller().setComposition("AB", underlines, -11, -11);
+ EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data());
+ EXPECT_EQ(6u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(6u, controller().getSelectionOffsets().end());
+
+ // The cursor is on right boundary of the 3rd node.
+ // "hello\nworld*\n01234AB56789".
+ controller().setComposition("AB", underlines, -6, -6);
+ EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data());
+ EXPECT_EQ(11u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(11u, controller().getSelectionOffsets().end());
+
+ // The cursor is on right boundary of the 4th node.
+ // "hello\nworld\n*01234AB56789".
+ controller().setComposition("AB", underlines, -5, -5);
+ EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data());
+ EXPECT_EQ(12u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(12u, controller().getSelectionOffsets().end());
+
+ // The cursor is before the composing text.
+ // "hello\nworld\n01234*AB56789".
+ controller().setComposition("AB", underlines, 0, 0);
+ EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data());
+ EXPECT_EQ(17u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(17u, controller().getSelectionOffsets().end());
+
+ // The cursor is after the composing text.
+ // "hello\nworld\n01234AB*56789".
+ controller().setComposition("AB", underlines, 2, 2);
+ EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data());
+ EXPECT_EQ(19u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(19u, controller().getSelectionOffsets().end());
+
+ // The cursor is on right boundary.
+ // "hello\nworld\n01234AB56789*".
+ controller().setComposition("AB", underlines, 7, 7);
+ EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data());
+ EXPECT_EQ(24u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(24u, controller().getSelectionOffsets().end());
+
+ // The cursor exceeds right boundary.
+ // "hello\nworld\n01234AB56789*".
+ controller().setComposition("AB", underlines, 100, 100);
+ EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data());
+ EXPECT_EQ(24u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(24u, controller().getSelectionOffsets().end());
+}
+
TEST_F(InputMethodControllerTest, CompositionFireBeforeInput)
{
document().settings()->setScriptEnabled(true);
« no previous file with comments | « third_party/WebKit/Source/core/editing/InputMethodController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698