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

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

Issue 956133002: [IME] Differentiate s_suppressNextKeypressEvent in WebViewImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add unit tests; breaking fix on purpose for testing. 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 c70283c5ae59f16a0926d1388b1063fc65b5294c..ae1c43a0d980f2c9d2ea1fc826fa1d70814b42db 100644
--- a/Source/web/tests/WebViewTest.cpp
+++ b/Source/web/tests/WebViewTest.cpp
@@ -1282,6 +1282,20 @@ TEST_F(WebViewTest, ClientTapHandling)
m_webViewHelper.reset(); // Explicitly reset to break dependency on locally scoped client.
}
+static void simulateKeyPress(WebView* webView, int windowsKeyCode)
+{
+ WebKeyboardEvent keyEvent;
+ if (windowsKeyCode != VK_UNKNOWN) {
+ keyEvent.windowsKeyCode = windowsKeyCode;
+ keyEvent.setKeyIdentifierFromWindowsKeyCode();
+ }
+ keyEvent.type = WebInputEvent::RawKeyDown;
+ webView->handleInputEvent(keyEvent);
+
+ keyEvent.type = WebInputEvent::KeyUp;
+ webView->handleInputEvent(keyEvent);
+}
+
#if OS(ANDROID)
TEST_F(WebViewTest, LongPressSelection)
{
@@ -1317,11 +1331,7 @@ TEST_F(WebViewTest, BlinkCaretOnTypingAfterLongPress)
EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureLongPress, target));
EXPECT_TRUE(mainFrame->frame()->selection().isCaretBlinkingSuspended());
- WebKeyboardEvent keyEvent;
- keyEvent.type = WebInputEvent::RawKeyDown;
- webView->handleInputEvent(keyEvent);
- keyEvent.type = WebInputEvent::KeyUp;
- webView->handleInputEvent(keyEvent);
+ simulateKeyPress(webView, VK_UNKNOWN);
EXPECT_FALSE(mainFrame->frame()->selection().isCaretBlinkingSuspended());
}
#endif
@@ -1412,6 +1422,18 @@ private:
};
+static void verifySelectionAndComposition(WebView* webView, const char* value, int selectionStart, int selectionEnd, int compositionStart, int compositionEnd, const char* failMessage)
+{
+ WebTextInputInfo info = webView->textInputInfo();
+ if (value) {
+ EXPECT_EQ(std::string(value), std::string(info.value.utf8().data())) << failMessage;
+ }
+ 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, LosingFocusDoesNotTriggerAutofillTextChange)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
@@ -1425,11 +1447,7 @@ TEST_F(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange)
WebVector<WebCompositionUnderline> emptyUnderlines;
frame->setEditableSelectionOffsets(4, 10);
frame->setCompositionFromExistingText(8, 12, emptyUnderlines);
- WebTextInputInfo info = webView->textInputInfo();
- EXPECT_EQ(4, info.selectionStart);
- EXPECT_EQ(10, info.selectionEnd);
- EXPECT_EQ(8, info.compositionStart);
- EXPECT_EQ(12, info.compositionEnd);
+ verifySelectionAndComposition(webView, nullptr, 4, 10, 8, 12, "base case");
// Clear the focus and track that the subsequent composition commit does not trigger a
// text changed notification for autofill.
@@ -1441,6 +1459,35 @@ TEST_F(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange)
frame->setAutofillClient(0);
}
+TEST_F(WebViewTest, CompositionChangeWithKeyEvents)
+{
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("composition_with_key_events.html"));
+ MockAutofillClient client;
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "composition_with_key_events.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(2, 15);
+ frame->setCompositionFromExistingText(6, 11, emptyUnderlines);
+ verifySelectionAndComposition(webView, nullptr, 2, 15, 6, 11, "initial case");
+
+ // Press 'A' and verify that the composition grew.
+ simulateKeyPress(webView, VKEY_A);
+ verifySelectionAndComposition(webView, nullptr, 2, 16, 6, 12, "after pressing 'A'");
+
+ // Press Backspace and verify that the composition shrunk (and is not cancelled).
+ simulateKeyPress(webView, VKEY_BACK);
+ verifySelectionAndComposition(webView, nullptr, 2, 15, 6, 11, "after pressing Backspace");
+
+ webView->advanceFocus(false);
+ }
+}
+
TEST_F(WebViewTest, ConfirmCompositionTriggersAutofillTextChange)
{
URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
@@ -1602,15 +1649,7 @@ TEST_F(WebViewTest, DispatchesDomFocusOutDomFocusInOnViewToggleFocus)
static void openDateTimeChooser(WebView* webView, HTMLInputElement* inputElement)
{
inputElement->focus();
-
- WebKeyboardEvent keyEvent;
- keyEvent.windowsKeyCode = VKEY_SPACE;
- keyEvent.type = WebInputEvent::RawKeyDown;
- keyEvent.setKeyIdentifierFromWindowsKeyCode();
- webView->handleInputEvent(keyEvent);
-
- keyEvent.type = WebInputEvent::KeyUp;
- webView->handleInputEvent(keyEvent);
+ simulateKeyPress(webView, VKEY_SPACE);
}
TEST_F(WebViewTest, ChooseValueFromDateTimeChooser)
@@ -2200,13 +2239,7 @@ TEST_F(WebViewTest, FirstUserGestureObservedKeyEvent)
EXPECT_EQ(0, client.getUserGestureNotificationsCount());
- WebKeyboardEvent keyEvent;
- keyEvent.windowsKeyCode = VKEY_SPACE;
- keyEvent.type = WebInputEvent::RawKeyDown;
- keyEvent.setKeyIdentifierFromWindowsKeyCode();
- webView->handleInputEvent(keyEvent);
- keyEvent.type = WebInputEvent::KeyUp;
- webView->handleInputEvent(keyEvent);
+ simulateKeyPress(webView, VKEY_SPACE);
EXPECT_EQ(1, client.getUserGestureNotificationsCount());
frame->setAutofillClient(0);

Powered by Google App Engine
This is Rietveld 408576698