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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 1125
1126 // Just make sure we don't hit any asserts. 1126 // Just make sure we don't hit any asserts.
1127 webViewImpl->handleInputEvent(event); 1127 webViewImpl->handleInputEvent(event);
1128 } 1128 }
1129 1129
1130 class MockAutofillClient : public WebAutofillClient { 1130 class MockAutofillClient : public WebAutofillClient {
1131 public: 1131 public:
1132 MockAutofillClient() 1132 MockAutofillClient()
1133 : m_ignoreTextChanges(false) 1133 : m_ignoreTextChanges(false)
1134 , m_textChangesWhileIgnored(0) 1134 , m_textChangesWhileIgnored(0)
1135 , m_textChangesWhileNotIgnored(0) { } 1135 , m_textChangesWhileNotIgnored(0)
1136 , m_userGestureNotificationsCount(0) { }
1136 1137
1137 virtual ~MockAutofillClient() { } 1138 virtual ~MockAutofillClient() { }
1138 1139
1139 virtual void setIgnoreTextChanges(bool ignore) OVERRIDE { m_ignoreTextChange s = ignore; } 1140 virtual void setIgnoreTextChanges(bool ignore) OVERRIDE { m_ignoreTextChange s = ignore; }
1140 virtual void textFieldDidChange(const WebFormControlElement&) OVERRIDE 1141 virtual void textFieldDidChange(const WebFormControlElement&) OVERRIDE
1141 { 1142 {
1142 if (m_ignoreTextChanges) 1143 if (m_ignoreTextChanges)
1143 ++m_textChangesWhileIgnored; 1144 ++m_textChangesWhileIgnored;
1144 else 1145 else
1145 ++m_textChangesWhileNotIgnored; 1146 ++m_textChangesWhileNotIgnored;
1146 } 1147 }
1148 virtual void firstUserGestureObserved() OVERRIDE { ++m_userGestureNotificati onsCount; }
1147 1149
1148 void clearChangeCounts() 1150 void clearChangeCounts()
1149 { 1151 {
1150 m_textChangesWhileIgnored = 0; 1152 m_textChangesWhileIgnored = 0;
1151 m_textChangesWhileNotIgnored = 0; 1153 m_textChangesWhileNotIgnored = 0;
1152 } 1154 }
1153 1155
1154 int textChangesWhileIgnored() { return m_textChangesWhileIgnored; } 1156 int textChangesWhileIgnored() { return m_textChangesWhileIgnored; }
1155 int textChangesWhileNotIgnored() { return m_textChangesWhileNotIgnored; } 1157 int textChangesWhileNotIgnored() { return m_textChangesWhileNotIgnored; }
1158 int getUserGestureNotificationsCount() { return m_userGestureNotificationsCo unt; }
1156 1159
1157 private: 1160 private:
1158 bool m_ignoreTextChanges; 1161 bool m_ignoreTextChanges;
1159 int m_textChangesWhileIgnored; 1162 int m_textChangesWhileIgnored;
1160 int m_textChangesWhileNotIgnored; 1163 int m_textChangesWhileNotIgnored;
1164 int m_userGestureNotificationsCount;
1161 }; 1165 };
1162 1166
1163 1167
1164 TEST_F(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange) 1168 TEST_F(WebViewTest, LosingFocusDoesNotTriggerAutofillTextChange)
1165 { 1169 {
1166 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html")); 1170 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_populated.html"));
1167 MockAutofillClient client; 1171 MockAutofillClient client;
1168 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html"); 1172 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "input_fiel d_populated.html");
1169 webView->setAutofillClient(&client); 1173 webView->setAutofillClient(&client);
1170 webView->setInitialFocus(false); 1174 webView->setInitialFocus(false);
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
1864 // (B.3) Unfocused and value is changed by script. 1868 // (B.3) Unfocused and value is changed by script.
1865 client.reset(); 1869 client.reset();
1866 EXPECT_FALSE(client.textIsUpdated()); 1870 EXPECT_FALSE(client.textIsUpdated());
1867 document->setFocusedElement(nullptr); 1871 document->setFocusedElement(nullptr);
1868 webViewImpl->setFocus(false); 1872 webViewImpl->setFocus(false);
1869 EXPECT_NE(document->focusedElement(), static_cast<WebCore::Element*>(textAre aElement)); 1873 EXPECT_NE(document->focusedElement(), static_cast<WebCore::Element*>(textAre aElement));
1870 inputElement->setValue("testB3"); 1874 inputElement->setValue("testB3");
1871 EXPECT_FALSE(client.textIsUpdated()); 1875 EXPECT_FALSE(client.textIsUpdated());
1872 } 1876 }
1873 1877
1878 // Check that the WebAutofillClient is correctly notified about first user
1879 // gestures after load, following various input events.
1880 TEST_F(WebViewTest, FirstUserGestureObservedKeyEvent)
1881 {
1882 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("form.html"));
1883 MockAutofillClient client;
1884 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form.html" , true);
1885 webView->setAutofillClient(&client);
1886 webView->setInitialFocus(false);
1887
1888 EXPECT_EQ(0, client.getUserGestureNotificationsCount());
1889
1890 WebKeyboardEvent keyEvent;
1891 keyEvent.windowsKeyCode = WebCore::VKEY_SPACE;
1892 keyEvent.type = WebInputEvent::RawKeyDown;
1893 keyEvent.setKeyIdentifierFromWindowsKeyCode();
1894 webView->handleInputEvent(keyEvent);
1895 keyEvent.type = WebInputEvent::KeyUp;
1896 webView->handleInputEvent(keyEvent);
1897
1898 EXPECT_EQ(1, client.getUserGestureNotificationsCount());
1899 webView->setAutofillClient(0);
1900 }
1901
1902 TEST_F(WebViewTest, FirstUserGestureObservedMouseEvent)
1903 {
1904 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("form.html"));
1905 MockAutofillClient client;
1906 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "form.html" , true);
1907 webView->setAutofillClient(&client);
1908 webView->setInitialFocus(false);
1909
1910 EXPECT_EQ(0, client.getUserGestureNotificationsCount());
1911
1912 WebMouseEvent mouseEvent;
1913 mouseEvent.button = WebMouseEvent::ButtonLeft;
1914 mouseEvent.x = 1;
1915 mouseEvent.y = 1;
1916 mouseEvent.clickCount = 1;
1917 mouseEvent.type = WebInputEvent::MouseDown;
1918 webView->handleInputEvent(mouseEvent);
1919 mouseEvent.type = WebInputEvent::MouseUp;
1920 webView->handleInputEvent(mouseEvent);
1921
1922 EXPECT_EQ(1, client.getUserGestureNotificationsCount());
1923 webView->setAutofillClient(0);
1924 }
1925
1926 TEST_F(WebViewTest, FirstUserGestureObservedGestureTap)
1927 {
1928 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("longpress_selection.html"));
1929 MockAutofillClient client;
1930 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "longpress_ selection.html", true);
1931 webView->setAutofillClient(&client);
1932 webView->setInitialFocus(false);
1933
1934 EXPECT_EQ(0, client.getUserGestureNotificationsCount());
1935
1936 EXPECT_TRUE(tapElementById(webView, WebInputEvent::GestureTap, WebString::fr omUTF8("target")));
1937
1938 EXPECT_EQ(1, client.getUserGestureNotificationsCount());
1939 webView->setAutofillClient(0);
1940 }
1941
1874 } // namespace 1942 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698