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

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: Adding C++ unit test Created 4 years, 9 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 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(

Powered by Google App Engine
This is Rietveld 408576698