Chromium Code Reviews| 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 20ad741e29ee338811f10d097b8fd032d3a5451a..19a1a021f91068a15df1a0670e319e85199115b0 100644 |
| --- a/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp |
| +++ b/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp |
| @@ -46,6 +46,88 @@ Element* InputMethodControllerTest::insertHTMLElement( |
| return element; |
| } |
| +TEST_F(InputMethodControllerTest, CreateDifferentRanges) |
| +{ |
| + HTMLInputElement* input = toHTMLInputElement( |
| + insertHTMLElement("<input id='sample'>", "sample")); |
| + |
| + input->setValue("hello"); |
| + Element* rootEditableElement = frame().selection().rootEditableElement(); |
| + EXPECT_TRUE(rootEditableElement); |
| + |
| + // In InputMethodController::setComposition, we are sure that End >= Start >= 0. Our tests can base on this fact. |
| + // Start and End are on the left boundary |
| + EphemeralRange range = PlainTextRange(0, 0).createRange(*rootEditableElement); |
| + EXPECT_EQ(0u, range.startPosition().computeOffsetInContainerNode()); |
| + EXPECT_EQ(0u, range.endPosition().computeOffsetInContainerNode()); |
| + |
| + // Start is on the left boundary, and End is on the right boundary |
|
Changwan Ryu
2016/04/04 06:23:13
The below code seems to belong to PlainTextRange t
yabinh
2016/04/04 08:31:51
OK. I'll create a new file to put the test.
|
| + range = PlainTextRange(0, 5).createRange(*rootEditableElement); |
| + EXPECT_EQ(0u, range.startPosition().computeOffsetInContainerNode()); |
| + EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); |
| + |
| + // Start is on the left boundary, and End exceeds right boundary |
| + range = PlainTextRange(0, 10).createRange(*rootEditableElement); |
| + EXPECT_EQ(0u, range.startPosition().computeOffsetInContainerNode()); |
| + EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); |
| + |
| + // Start and End are on the right boundary |
| + range = PlainTextRange(5, 5).createRange(*rootEditableElement); |
| + EXPECT_EQ(5u, range.startPosition().computeOffsetInContainerNode()); |
| + EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); |
| + |
| + // Start is on the right boundary, and End exceeds right boundary |
| + range = PlainTextRange(5, 10).createRange(*rootEditableElement); |
| + EXPECT_EQ(5u, range.startPosition().computeOffsetInContainerNode()); |
| + EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); |
| + |
| + // Start and End exceed the right boundary |
| + range = PlainTextRange(10, 10).createRange(*rootEditableElement); |
| + EXPECT_EQ(5u, range.startPosition().computeOffsetInContainerNode()); |
| + EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); |
| +} |
| + |
| +TEST_F(InputMethodControllerTest, CreateDifferentRangesForSelection) |
| +{ |
| + HTMLInputElement* input = toHTMLInputElement( |
| + insertHTMLElement("<input id='sample'>", "sample")); |
| + |
| + input->setValue("hello"); |
| + Element* rootEditableElement = frame().selection().rootEditableElement(); |
| + EXPECT_TRUE(rootEditableElement); |
| + |
| + // In InputMethodController::setComposition, we are sure that End >= Start >= 0. Our tests can base on this fact. |
| + // Start and End are on the left boundary |
| + EphemeralRange range = PlainTextRange(0, 0).createRangeForSelection(*rootEditableElement); |
| + EXPECT_EQ(0u, range.startPosition().computeOffsetInContainerNode()); |
| + EXPECT_EQ(0u, range.endPosition().computeOffsetInContainerNode()); |
| + |
| + // Start is on the left boundary, and End is on the right boundary |
| + range = PlainTextRange(0, 5).createRangeForSelection(*rootEditableElement); |
| + EXPECT_EQ(0u, range.startPosition().computeOffsetInContainerNode()); |
| + EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); |
| + |
| + // Start is on the left boundary, and End exceeds right boundary |
| + range = PlainTextRange(0, 10).createRangeForSelection(*rootEditableElement); |
| + EXPECT_EQ(0u, range.startPosition().computeOffsetInContainerNode()); |
| + EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); |
| + |
| + // Start and End are on the right boundary |
| + range = PlainTextRange(5, 5).createRangeForSelection(*rootEditableElement); |
| + EXPECT_EQ(5u, range.startPosition().computeOffsetInContainerNode()); |
| + EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); |
| + |
| + // Start is on the right boundary, and End exceeds right boundary |
| + range = PlainTextRange(5, 10).createRangeForSelection(*rootEditableElement); |
| + EXPECT_EQ(5u, range.startPosition().computeOffsetInContainerNode()); |
| + EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); |
| + |
| + // Start and End exceed the right boundary |
| + range = PlainTextRange(10, 10).createRangeForSelection(*rootEditableElement); |
| + EXPECT_EQ(5u, range.startPosition().computeOffsetInContainerNode()); |
| + EXPECT_EQ(5u, range.endPosition().computeOffsetInContainerNode()); |
| +} |
| + |
| TEST_F(InputMethodControllerTest, BackspaceFromEndOfInput) |
| { |
| HTMLInputElement* input = toHTMLInputElement( |