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

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

Issue 235983016: Add support for setting password value gated on user's gesture in a page (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: OVERRIDE added Created 6 years, 8 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 657f90fd4ad235d65cf08a92b501430f6b162905..e860a1bd9ddf963c2363ef87404885dfa892ce51 100644
--- a/Source/web/tests/WebViewTest.cpp
+++ b/Source/web/tests/WebViewTest.cpp
@@ -1132,7 +1132,8 @@ public:
MockAutofillClient()
: m_ignoreTextChanges(false)
, m_textChangesWhileIgnored(0)
- , m_textChangesWhileNotIgnored(0) { }
+ , m_textChangesWhileNotIgnored(0)
+ , m_userGestureNotificationsCount(0) { }
virtual ~MockAutofillClient() { }
@@ -1144,6 +1145,7 @@ public:
else
++m_textChangesWhileNotIgnored;
}
+ virtual void firstUserGestureObserved() OVERRIDE { ++m_userGestureNotificationsCount; }
void clearChangeCounts()
{
@@ -1153,11 +1155,13 @@ public:
int textChangesWhileIgnored() { return m_textChangesWhileIgnored; }
int textChangesWhileNotIgnored() { return m_textChangesWhileNotIgnored; }
+ int getUserGestureNotificationsCount() { return m_userGestureNotificationsCount; }
private:
bool m_ignoreTextChanges;
int m_textChangesWhileIgnored;
int m_textChangesWhileNotIgnored;
+ int m_userGestureNotificationsCount;
};
@@ -1871,4 +1875,68 @@ TEST_F(WebViewTest, NonUserInputTextUpdate)
EXPECT_FALSE(client.textIsUpdated());
}
+// Check that the WebAutofillClient is correctly notified about first user
+// gestures after load, following various input events.
+TEST_F(WebViewTest, FirstUserGestureObservedKeyEvent)
+{
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("form.html"));
+ MockAutofillClient client;
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form.html", true);
+ webView->setAutofillClient(&client);
+ webView->setInitialFocus(false);
+
+ EXPECT_EQ(0, client.getUserGestureNotificationsCount());
+
+ WebKeyboardEvent keyEvent;
+ keyEvent.windowsKeyCode = WebCore::VKEY_SPACE;
+ keyEvent.type = WebInputEvent::RawKeyDown;
+ keyEvent.setKeyIdentifierFromWindowsKeyCode();
+ webView->handleInputEvent(keyEvent);
+ keyEvent.type = WebInputEvent::KeyUp;
+ webView->handleInputEvent(keyEvent);
+
+ EXPECT_EQ(1, client.getUserGestureNotificationsCount());
+ webView->setAutofillClient(0);
+}
+
+TEST_F(WebViewTest, FirstUserGestureObservedMouseEvent)
+{
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("form.html"));
+ MockAutofillClient client;
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form.html", true);
+ webView->setAutofillClient(&client);
+ webView->setInitialFocus(false);
+
+ EXPECT_EQ(0, client.getUserGestureNotificationsCount());
+
+ WebMouseEvent mouseEvent;
+ mouseEvent.button = WebMouseEvent::ButtonLeft;
+ mouseEvent.x = 1;
+ mouseEvent.y = 1;
+ mouseEvent.clickCount = 1;
+ mouseEvent.type = WebInputEvent::MouseDown;
+ webView->handleInputEvent(mouseEvent);
+ mouseEvent.type = WebInputEvent::MouseUp;
+ webView->handleInputEvent(mouseEvent);
+
+ EXPECT_EQ(1, client.getUserGestureNotificationsCount());
+ webView->setAutofillClient(0);
+}
+
+TEST_F(WebViewTest, FirstUserGestureObservedGestureTap)
+{
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("longpress_selection.html"));
+ MockAutofillClient client;
+ WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "longpress_selection.html", true);
+ webView->setAutofillClient(&client);
+ webView->setInitialFocus(false);
+
+ EXPECT_EQ(0, client.getUserGestureNotificationsCount());
+
+ EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fromUTF8("target")));
+
+ EXPECT_EQ(1, client.getUserGestureNotificationsCount());
+ webView->setAutofillClient(0);
+}
+
} // namespace

Powered by Google App Engine
This is Rietveld 408576698