| 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..6b49b18321e3262aec2698102ffd8a9bbc55731f 100644
|
| --- a/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
|
| +++ b/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
|
| @@ -193,6 +193,138 @@ 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, -100, -100);
|
| + 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, 100, 100);
|
| + 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, -100, -100);
|
| + 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, 100, 100);
|
| + EXPECT_STREQ("heABllo\nworld!", div->innerText().utf8().data());
|
| + EXPECT_EQ(6, frame().selection().start().computeOffsetInContainerNode());
|
| + EXPECT_EQ(6, frame().selection().end().computeOffsetInContainerNode());
|
| +}
|
| +
|
| TEST_F(InputMethodControllerTest, CompositionFireBeforeInput)
|
| {
|
| document().settings()->setScriptEnabled(true);
|
|
|