| 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);
|
|
|