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

Side by Side Diff: chrome/renderer/autofill/password_autofill_agent_browsertest.cc

Issue 1161023008: Suggest to fill password change forms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tiny fix Created 5 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/string_util.h" 5 #include "base/strings/string_util.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/renderer/autofill/password_generation_test_utils.h" 7 #include "chrome/renderer/autofill/password_generation_test_utils.h"
8 #include "chrome/test/base/chrome_render_view_test.h" 8 #include "chrome/test/base/chrome_render_view_test.h"
9 #include "components/autofill/content/common/autofill_messages.h" 9 #include "components/autofill/content/common/autofill_messages.h"
10 #include "components/autofill/content/renderer/autofill_agent.h" 10 #include "components/autofill/content/renderer/autofill_agent.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 168
169 const char kFormHTMLWithTwoTextFields[] = 169 const char kFormHTMLWithTwoTextFields[] =
170 "<FORM name='LoginTestForm' id='LoginTestForm' " 170 "<FORM name='LoginTestForm' id='LoginTestForm' "
171 "action='http://www.bidule.com'>" 171 "action='http://www.bidule.com'>"
172 " <INPUT type='text' id='username'/>" 172 " <INPUT type='text' id='username'/>"
173 " <INPUT type='text' id='email'/>" 173 " <INPUT type='text' id='email'/>"
174 " <INPUT type='password' id='password'/>" 174 " <INPUT type='password' id='password'/>"
175 " <INPUT type='submit' value='Login'/>" 175 " <INPUT type='submit' value='Login'/>"
176 "</FORM>"; 176 "</FORM>";
177 177
178 const char kPasswordChangeFormHTML[] =
179 "<FORM name='ChangeWithUsernameForm' action='http://www.bidule.com'>"
180 " <INPUT type='text' id='username'/>"
181 " <INPUT type='password' id='password'/>"
182 " <INPUT type='password' id='newpassword'/>"
183 " <INPUT type='password' id='confirmpassword'/>"
184 " <INPUT type='submit' value='Login'/>"
185 "</FORM>";
186
178 // Sets the "readonly" attribute of |element| to the value given by |read_only|. 187 // Sets the "readonly" attribute of |element| to the value given by |read_only|.
179 void SetElementReadOnly(WebInputElement& element, bool read_only) { 188 void SetElementReadOnly(WebInputElement& element, bool read_only) {
180 element.setAttribute(WebString::fromUTF8("readonly"), 189 element.setAttribute(WebString::fromUTF8("readonly"),
181 read_only ? WebString::fromUTF8("true") : WebString()); 190 read_only ? WebString::fromUTF8("true") : WebString());
182 } 191 }
183 192
184 } // namespace 193 } // namespace
185 194
186 namespace autofill { 195 namespace autofill {
187 196
(...skipping 1668 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 password_generation_->OnMessageReceived(msg); 1865 password_generation_->OnMessageReceived(msg);
1857 1866
1858 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1867 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1859 ->WillSendSubmitEvent(username_element_.form()); 1868 ->WillSendSubmitEvent(username_element_.form());
1860 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) 1869 static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
1861 ->WillSubmitForm(username_element_.form()); 1870 ->WillSubmitForm(username_element_.form());
1862 1871
1863 ExpectFormSubmittedWithUsernameAndPasswords(kAliceUsername, "NewPass22", ""); 1872 ExpectFormSubmittedWithUsernameAndPasswords(kAliceUsername, "NewPass22", "");
1864 } 1873 }
1865 1874
1875 // Tests that a password change form is properly filled with the username and
1876 // password.
1877 TEST_F(PasswordAutofillAgentTest, FillSuggestionPasswordChangeForms) {
1878 LoadHTML(kPasswordChangeFormHTML);
1879 UpdateOriginForHTML(kPasswordChangeFormHTML);
1880 UpdateUsernameAndPasswordElements();
1881 // Simulate the browser sending the login info, but set |wait_for_username|
1882 // to prevent the form from being immediately filled.
1883 fill_data_.wait_for_username = true;
1884 fill_data_.is_possible_change_password_form = true;
1885 SimulateOnFillPasswordForm(fill_data_);
1886
1887 // Neither field should have been autocompleted.
1888 CheckTextFieldsDOMState(std::string(), false, std::string(), false);
1889
1890 EXPECT_TRUE(password_autofill_agent_->FillSuggestion(
1891 username_element_, kAliceUsername, kAlicePassword));
1892 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true);
1893 }
1894
1895 // Tests that a password change form is properly filled with the password when
1896 // the user click on the password field.
1897 TEST_F(PasswordAutofillAgentTest,
1898 FillSuggestionPasswordChangeFormsOnlyPassword) {
1899 LoadHTML(kPasswordChangeFormHTML);
1900 UpdateOriginForHTML(kPasswordChangeFormHTML);
1901 UpdateUsernameAndPasswordElements();
1902 // Simulate the browser sending the login info, but set |wait_for_username|
1903 // to prevent the form from being immediately filled.
1904 fill_data_.wait_for_username = true;
1905 fill_data_.is_possible_change_password_form = true;
1906 SimulateOnFillPasswordForm(fill_data_);
1907
1908 // Neither field should have been autocompleted.
1909 CheckTextFieldsDOMState(std::string(), false, std::string(), false);
1910
1911 EXPECT_TRUE(password_autofill_agent_->FillSuggestion(
1912 password_element_, kAliceUsername, kAlicePassword));
1913 CheckTextFieldsDOMState("", false, kAlicePassword, true);
1914 }
1915
1916 // Tests that one user click on a username field is sufficient to bring up a
1917 // credential suggestion popup on a change password form.
1918 TEST_F(PasswordAutofillAgentTest,
1919 SuggestionsOnUsernameFieldOfChangePasswordForm) {
1920 LoadHTML(kPasswordChangeFormHTML);
1921 UpdateOriginForHTML(kPasswordChangeFormHTML);
1922 UpdateUsernameAndPasswordElements();
1923
1924 ClearUsernameAndPasswordFields();
1925 fill_data_.wait_for_username = true;
1926 fill_data_.is_possible_change_password_form = true;
1927 SimulateOnFillPasswordForm(fill_data_);
1928 // Simulate a user clicking on the username element. This should produce a
1929 // message.
1930 render_thread_->sink().ClearMessages();
1931 static_cast<PageClickListener*>(autofill_agent_)
1932 ->FormControlElementClicked(username_element_, true);
1933 CheckSuggestions("", true);
1934 }
1935
1936 // Tests that one user click on a password field is sufficient to bring up a
1937 // credential suggestion popup on a change password form.
1938 TEST_F(PasswordAutofillAgentTest,
1939 SuggestionsOnPasswordFieldOfChangePasswordForm) {
1940 LoadHTML(kPasswordChangeFormHTML);
1941 UpdateOriginForHTML(kPasswordChangeFormHTML);
1942 UpdateUsernameAndPasswordElements();
1943
1944 ClearUsernameAndPasswordFields();
1945 fill_data_.wait_for_username = true;
1946 fill_data_.is_possible_change_password_form = true;
1947 SimulateOnFillPasswordForm(fill_data_);
1948 // Simulate a user clicking on the password element. This should produce a
1949 // message.
1950 render_thread_->sink().ClearMessages();
1951 static_cast<PageClickListener*>(autofill_agent_)
1952 ->FormControlElementClicked(password_element_, true);
1953 CheckSuggestions("", false);
1954 }
1955
1956 // Tests that there are no autosuggestions from the password manager when the
1957 // user clicks on the password field of change password form after the user
1958 // typed in the username field.
1959 TEST_F(PasswordAutofillAgentTest,
1960 NoSuggestionsOnPasswordFieldOfChangePasswordFormAfterUsernameTyping) {
1961 LoadHTML(kPasswordChangeFormHTML);
1962 UpdateOriginForHTML(kPasswordChangeFormHTML);
1963 UpdateUsernameAndPasswordElements();
1964
1965 ClearUsernameAndPasswordFields();
1966 fill_data_.wait_for_username = true;
1967 fill_data_.is_possible_change_password_form = true;
1968 SimulateOnFillPasswordForm(fill_data_);
1969
1970 // Clear the text fields to start fresh.
1971 SimulateUsernameChange("temp");
1972
1973 // Simulate a user clicking on the password element. This should produce no
1974 // message.
1975 render_thread_->sink().ClearMessages();
1976 static_cast<PageClickListener*>(autofill_agent_)
1977 ->FormControlElementClicked(password_element_, false);
1978 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
1979 AutofillHostMsg_ShowPasswordSuggestions::ID));
1980 }
1981
1866 } // namespace autofill 1982 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698