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

Unified Diff: Source/web/tests/WebViewTest.cpp

Issue 23848007: Fixing the bounds check in cancelCompositionIfSelectionIsInvalid. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Adding two more test cases Created 7 years, 3 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 | « 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: Source/web/tests/WebViewTest.cpp
diff --git a/Source/web/tests/WebViewTest.cpp b/Source/web/tests/WebViewTest.cpp
index eabc0c1f9cde469ded3300f76a658f3732baf5f8..42df88b64e280a01737ead4376dcd39b0c633883 100644
--- a/Source/web/tests/WebViewTest.cpp
+++ b/Source/web/tests/WebViewTest.cpp
@@ -683,6 +683,68 @@ TEST_F(WebViewTest, SetCompositionFromExistingTextInTextArea)
webView->close();
}
+TEST_F(WebViewTest, SetEditableSelectionOffsetsKeepsComposition)
+{
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
+ WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
+ webView->setInitialFocus(false);
+
+ std::string compositionTextFirst("hello ");
+ std::string compositionTextSecond("world");
+ WebVector<WebCompositionUnderline> emptyUnderlines;
+
+ webView->confirmComposition(WebString::fromUTF8(compositionTextFirst.c_str()));
+ webView->setComposition(WebString::fromUTF8(compositionTextSecond.c_str()), emptyUnderlines, 5, 5);
+
+ WebTextInputInfo info = webView->textInputInfo();
+ EXPECT_EQ("hello world", std::string(info.value.utf8().data()));
+ EXPECT_EQ(11, info.selectionStart);
+ EXPECT_EQ(11, info.selectionEnd);
+ EXPECT_EQ(6, info.compositionStart);
+ EXPECT_EQ(11, info.compositionEnd);
+
+ webView->setEditableSelectionOffsets(6, 6);
+ info = webView->textInputInfo();
+ EXPECT_EQ("hello world", std::string(info.value.utf8().data()));
+ EXPECT_EQ(6, info.selectionStart);
+ EXPECT_EQ(6, info.selectionEnd);
+ EXPECT_EQ(6, info.compositionStart);
+ EXPECT_EQ(11, info.compositionEnd);
+
+ webView->setEditableSelectionOffsets(8, 8);
+ info = webView->textInputInfo();
+ EXPECT_EQ("hello world", std::string(info.value.utf8().data()));
+ EXPECT_EQ(8, info.selectionStart);
+ EXPECT_EQ(8, info.selectionEnd);
+ EXPECT_EQ(6, info.compositionStart);
+ EXPECT_EQ(11, info.compositionEnd);
+
+ webView->setEditableSelectionOffsets(11, 11);
+ info = webView->textInputInfo();
+ EXPECT_EQ("hello world", std::string(info.value.utf8().data()));
+ EXPECT_EQ(11, info.selectionStart);
+ EXPECT_EQ(11, info.selectionEnd);
+ EXPECT_EQ(6, info.compositionStart);
+ EXPECT_EQ(11, info.compositionEnd);
+
+ webView->setEditableSelectionOffsets(6, 11);
+ info = webView->textInputInfo();
+ EXPECT_EQ("hello world", std::string(info.value.utf8().data()));
+ EXPECT_EQ(6, info.selectionStart);
+ EXPECT_EQ(11, info.selectionEnd);
+ EXPECT_EQ(6, info.compositionStart);
+ EXPECT_EQ(11, info.compositionEnd);
+
+ webView->setEditableSelectionOffsets(2, 2);
+ info = webView->textInputInfo();
+ EXPECT_EQ("hello world", std::string(info.value.utf8().data()));
+ EXPECT_EQ(2, info.selectionStart);
+ EXPECT_EQ(2, info.selectionEnd);
+ EXPECT_EQ(-1, info.compositionStart);
+ EXPECT_EQ(-1, info.compositionEnd);
+ webView->close();
+}
+
TEST_F(WebViewTest, IsSelectionAnchorFirst)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
« no previous file with comments | « Source/core/editing/InputMethodController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698