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/test/base/chrome_render_view_test.h" | 7 #include "chrome/test/base/chrome_render_view_test.h" |
8 #include "components/autofill/content/common/autofill_messages.h" | 8 #include "components/autofill/content/common/autofill_messages.h" |
9 #include "components/autofill/content/renderer/autofill_agent.h" | 9 #include "components/autofill/content/renderer/autofill_agent.h" |
10 #include "components/autofill/content/renderer/form_autofill_util.h" | 10 #include "components/autofill/content/renderer/form_autofill_util.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 public: | 171 public: |
172 PasswordAutofillAgentTest() { | 172 PasswordAutofillAgentTest() { |
173 } | 173 } |
174 | 174 |
175 // Simulates the fill password form message being sent to the renderer. | 175 // Simulates the fill password form message being sent to the renderer. |
176 // We use that so we don't have to make RenderView::OnFillPasswordForm() | 176 // We use that so we don't have to make RenderView::OnFillPasswordForm() |
177 // protected. | 177 // protected. |
178 void SimulateOnFillPasswordForm( | 178 void SimulateOnFillPasswordForm( |
179 const PasswordFormFillData& fill_data) { | 179 const PasswordFormFillData& fill_data) { |
180 AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data); | 180 AutofillMsg_FillPasswordForm msg(0, kPasswordFillFormDataId, fill_data); |
181 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 181 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
182 ->OnMessageReceived(msg); | 182 ->OnMessageReceived(msg); |
183 } | 183 } |
184 | 184 |
185 void SendVisiblePasswordForms() { | 185 void SendVisiblePasswordForms() { |
186 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 186 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
187 ->DidFinishLoad(GetMainFrame()); | 187 ->DidFinishLoad(); |
188 } | 188 } |
189 | 189 |
190 void SetUp() override { | 190 void SetUp() override { |
191 ChromeRenderViewTest::SetUp(); | 191 ChromeRenderViewTest::SetUp(); |
192 | 192 |
193 // Add a preferred login and an additional login to the FillData. | 193 // Add a preferred login and an additional login to the FillData. |
194 username1_ = ASCIIToUTF16(kAliceUsername); | 194 username1_ = ASCIIToUTF16(kAliceUsername); |
195 password1_ = ASCIIToUTF16(kAlicePassword); | 195 password1_ = ASCIIToUTF16(kAlicePassword); |
196 username2_ = ASCIIToUTF16(kBobUsername); | 196 username2_ = ASCIIToUTF16(kBobUsername); |
197 password2_ = ASCIIToUTF16(kBobPassword); | 197 password2_ = ASCIIToUTF16(kBobPassword); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 base::string16 username(base::ASCIIToUTF16(kAliceUsername)); | 301 base::string16 username(base::ASCIIToUTF16(kAliceUsername)); |
302 base::string16 password(base::ASCIIToUTF16(kAlicePassword)); | 302 base::string16 password(base::ASCIIToUTF16(kAlicePassword)); |
303 | 303 |
304 // This call is necessary to setup the autofill agent appropriate for the | 304 // This call is necessary to setup the autofill agent appropriate for the |
305 // user selection; simulates the menu actually popping up. | 305 // user selection; simulates the menu actually popping up. |
306 render_thread_->sink().ClearMessages(); | 306 render_thread_->sink().ClearMessages(); |
307 static_cast<autofill::PageClickListener*>(autofill_agent_) | 307 static_cast<autofill::PageClickListener*>(autofill_agent_) |
308 ->FormControlElementClicked(username_input, false); | 308 ->FormControlElementClicked(username_input, false); |
309 | 309 |
310 AutofillMsg_FillPasswordSuggestion msg(0, username, password); | 310 AutofillMsg_FillPasswordSuggestion msg(0, username, password); |
311 static_cast<content::RenderViewObserver*>(autofill_agent_) | 311 static_cast<content::RenderFrameObserver*>(autofill_agent_) |
312 ->OnMessageReceived(msg); | 312 ->OnMessageReceived(msg); |
313 } | 313 } |
314 | 314 |
315 void LayoutMainFrame() { | 315 void LayoutMainFrame() { |
316 GetMainFrame()->view()->layout(); | 316 GetMainFrame()->view()->layout(); |
317 } | 317 } |
318 | 318 |
319 void SimulateUsernameChange(const std::string& username, | 319 void SimulateUsernameChange(const std::string& username, |
320 bool move_caret_to_end, | 320 bool move_caret_to_end, |
321 bool is_user_input = false) { | 321 bool is_user_input = false) { |
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1396 TEST_F(PasswordAutofillAgentTest, | 1396 TEST_F(PasswordAutofillAgentTest, |
1397 RememberLastNonEmptyPasswordOnSubmit_ScriptCleared) { | 1397 RememberLastNonEmptyPasswordOnSubmit_ScriptCleared) { |
1398 SimulateInputChangeForElement( | 1398 SimulateInputChangeForElement( |
1399 "temp", true, GetMainFrame(), username_element_, true); | 1399 "temp", true, GetMainFrame(), username_element_, true); |
1400 SimulateInputChangeForElement( | 1400 SimulateInputChangeForElement( |
1401 "random", true, GetMainFrame(), password_element_, true); | 1401 "random", true, GetMainFrame(), password_element_, true); |
1402 | 1402 |
1403 // Simulate that the password value was cleared by the site's JavaScript | 1403 // Simulate that the password value was cleared by the site's JavaScript |
1404 // before submit. | 1404 // before submit. |
1405 password_element_.setValue(WebString()); | 1405 password_element_.setValue(WebString()); |
1406 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 1406 static_cast<content::RenderViewObserver*>(&password_autofill_agent_->legacy_) |
1407 ->WillSubmitForm(GetMainFrame(), username_element_.form()); | 1407 ->WillSubmitForm(GetMainFrame(), username_element_.form()); |
1408 | 1408 |
1409 // Observe that the PasswordAutofillAgent still remembered the last non-empty | 1409 // Observe that the PasswordAutofillAgent still remembered the last non-empty |
1410 // password and sent that to the browser. | 1410 // password and sent that to the browser. |
1411 ExpectFormSubmittedWithPasswords("random", ""); | 1411 ExpectFormSubmittedWithPasswords("random", ""); |
1412 } | 1412 } |
1413 | 1413 |
1414 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but this time | 1414 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but this time |
1415 // it's the user who clears the password. This test checks that in that case, | 1415 // it's the user who clears the password. This test checks that in that case, |
1416 // the last non-empty password is not remembered. | 1416 // the last non-empty password is not remembered. |
1417 TEST_F(PasswordAutofillAgentTest, | 1417 TEST_F(PasswordAutofillAgentTest, |
1418 RememberLastNonEmptyPasswordOnSubmit_UserCleared) { | 1418 RememberLastNonEmptyPasswordOnSubmit_UserCleared) { |
1419 SimulateInputChangeForElement( | 1419 SimulateInputChangeForElement( |
1420 "temp", true, GetMainFrame(), username_element_, true); | 1420 "temp", true, GetMainFrame(), username_element_, true); |
1421 SimulateInputChangeForElement( | 1421 SimulateInputChangeForElement( |
1422 "random", true, GetMainFrame(), password_element_, true); | 1422 "random", true, GetMainFrame(), password_element_, true); |
1423 | 1423 |
1424 // Simulate that the user actually cleared the password again. | 1424 // Simulate that the user actually cleared the password again. |
1425 SimulateInputChangeForElement( | 1425 SimulateInputChangeForElement( |
1426 "", true, GetMainFrame(), password_element_, true); | 1426 "", true, GetMainFrame(), password_element_, true); |
1427 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 1427 static_cast<content::RenderViewObserver*>(&password_autofill_agent_->legacy_) |
1428 ->WillSubmitForm(GetMainFrame(), username_element_.form()); | 1428 ->WillSubmitForm(GetMainFrame(), username_element_.form()); |
1429 | 1429 |
1430 // Observe that the PasswordAutofillAgent respects the user having cleared the | 1430 // Observe that the PasswordAutofillAgent respects the user having cleared the |
1431 // password. | 1431 // password. |
1432 ExpectFormSubmittedWithPasswords("", ""); | 1432 ExpectFormSubmittedWithPasswords("", ""); |
1433 } | 1433 } |
1434 | 1434 |
1435 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but uses the | 1435 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but uses the |
1436 // new password instead of the current password. | 1436 // new password instead of the current password. |
1437 TEST_F(PasswordAutofillAgentTest, | 1437 TEST_F(PasswordAutofillAgentTest, |
1438 RememberLastNonEmptyPasswordOnSubmit_NewPassword) { | 1438 RememberLastNonEmptyPasswordOnSubmit_NewPassword) { |
1439 const char kNewPasswordFormHTML[] = | 1439 const char kNewPasswordFormHTML[] = |
1440 "<FORM name='LoginTestForm'>" | 1440 "<FORM name='LoginTestForm'>" |
1441 " <INPUT type='text' id='username' autocomplete='username'/>" | 1441 " <INPUT type='text' id='username' autocomplete='username'/>" |
1442 " <INPUT type='password' id='password' autocomplete='new-password'/>" | 1442 " <INPUT type='password' id='password' autocomplete='new-password'/>" |
1443 " <INPUT type='submit' value='Login'/>" | 1443 " <INPUT type='submit' value='Login'/>" |
1444 "</FORM>"; | 1444 "</FORM>"; |
1445 LoadHTML(kNewPasswordFormHTML); | 1445 LoadHTML(kNewPasswordFormHTML); |
1446 UpdateUsernameAndPasswordElements(); | 1446 UpdateUsernameAndPasswordElements(); |
1447 | 1447 |
1448 SimulateInputChangeForElement( | 1448 SimulateInputChangeForElement( |
1449 "temp", true, GetMainFrame(), username_element_, true); | 1449 "temp", true, GetMainFrame(), username_element_, true); |
1450 SimulateInputChangeForElement( | 1450 SimulateInputChangeForElement( |
1451 "random", true, GetMainFrame(), password_element_, true); | 1451 "random", true, GetMainFrame(), password_element_, true); |
1452 | 1452 |
1453 // Simulate that the password value was cleared by the site's JavaScript | 1453 // Simulate that the password value was cleared by the site's JavaScript |
1454 // before submit. | 1454 // before submit. |
1455 password_element_.setValue(WebString()); | 1455 password_element_.setValue(WebString()); |
1456 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 1456 static_cast<content::RenderViewObserver*>(&password_autofill_agent_->legacy_) |
1457 ->WillSubmitForm(GetMainFrame(), username_element_.form()); | 1457 ->WillSubmitForm(GetMainFrame(), username_element_.form()); |
1458 | 1458 |
1459 // Observe that the PasswordAutofillAgent still remembered the last non-empty | 1459 // Observe that the PasswordAutofillAgent still remembered the last non-empty |
1460 // password and sent that to the browser. | 1460 // password and sent that to the browser. |
1461 ExpectFormSubmittedWithPasswords("", "random"); | 1461 ExpectFormSubmittedWithPasswords("", "random"); |
1462 } | 1462 } |
1463 | 1463 |
1464 // The user first accepts a suggestion, but then overwrites the password. This | 1464 // The user first accepts a suggestion, but then overwrites the password. This |
1465 // test checks that the overwritten password is not reverted back if the user | 1465 // test checks that the overwritten password is not reverted back if the user |
1466 // triggers autofill through focusing (but not changing) the username again. | 1466 // triggers autofill through focusing (but not changing) the username again. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1513 password_element_, | 1513 password_element_, |
1514 /*is_user_input=*/true); | 1514 /*is_user_input=*/true); |
1515 | 1515 |
1516 // Simulate the user typing a stored username. | 1516 // Simulate the user typing a stored username. |
1517 SimulateUsernameChange(kAliceUsername, true); | 1517 SimulateUsernameChange(kAliceUsername, true); |
1518 // The autofileld password should replace the typed one. | 1518 // The autofileld password should replace the typed one. |
1519 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); | 1519 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
1520 } | 1520 } |
1521 | 1521 |
1522 } // namespace autofill | 1522 } // namespace autofill |
OLD | NEW |