OLD | NEW |
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 Loading... |
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 Loading... |
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_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_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 |
1866 } // namespace autofill | 1916 } // namespace autofill |
OLD | NEW |