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

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

Issue 970743002: [IME] Fix s_suppressNextKeypressEvent logic in WebViewImpl::setComposition(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 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: Source/web/tests/WebViewTest.cpp
diff --git a/Source/web/tests/WebViewTest.cpp b/Source/web/tests/WebViewTest.cpp
index 5819e60bb94178009a99062ed75be376ff8b67b6..273ab35a58bf3481ae6dd04c0a648378d0e03dde 100644
--- a/Source/web/tests/WebViewTest.cpp
+++ b/Source/web/tests/WebViewTest.cpp
@@ -1432,6 +1432,55 @@ TEST_F(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange)
frame->setAutofillClient(0);
}
+static void verifySelectionAndComposition(WebView* webView, int selectionStart, int selectionEnd, int compositionStart, int compositionEnd, const char* failMessage)
+{
+ WebTextInputInfo info = webView->textInputInfo();
+ EXPECT_EQ(selectionStart, info.selectionStart) << failMessage;
+ EXPECT_EQ(selectionEnd, info.selectionEnd) << failMessage;
+ EXPECT_EQ(compositionStart, info.compositionStart) << failMessage;
+ EXPECT_EQ(compositionEnd, info.compositionEnd) << failMessage;
+}
+
+TEST_F(WebViewTest, CompositionNotCancelledByBackspace)
+{
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("composition_not_cancelled_by_backspace.html"));
+ MockAutofillClient client;
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "composition_not_cancelled_by_backspace.html");
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame());
+ frame->setAutofillClient(&client);
+ webView->setInitialFocus(false);
+
+ // Test both input elements.
+ for (int i = 0; i < 2; ++i) {
+ // Select composition and do sanity check.
+ WebVector<WebCompositionUnderline> emptyUnderlines;
+ frame->setEditableSelectionOffsets(6, 6);
+ EXPECT_TRUE(webView->setComposition("fghij", emptyUnderlines, 0, 5));
+ frame->setEditableSelectionOffsets(11, 11);
+ verifySelectionAndComposition(webView, 11, 11, 6, 11, "initial case");
+
+ // Press Backspace and verify composition didn't get cancelled. This is to verify the fix
+ // for crbug.com/429916.
+ WebKeyboardEvent keyEvent;
+ keyEvent.windowsKeyCode = VKEY_BACK;
+ keyEvent.setKeyIdentifierFromWindowsKeyCode();
+ keyEvent.type = WebInputEvent::RawKeyDown;
+ webView->handleInputEvent(keyEvent);
+
+ frame->setEditableSelectionOffsets(6, 6);
+ EXPECT_TRUE(webView->setComposition("fghi", emptyUnderlines, 0, 4));
+ frame->setEditableSelectionOffsets(10, 10);
+ verifySelectionAndComposition(webView, 10, 10, 6, 10, "after pressing Backspace");
+
+ keyEvent.type = WebInputEvent::KeyUp;
+ webView->handleInputEvent(keyEvent);
+
+ webView->advanceFocus(false);
+ }
+
+ frame->setAutofillClient(0);
+}
+
TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));

Powered by Google App Engine
This is Rietveld 408576698