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 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1397 TEST_F(PasswordAutofillAgentTest, | 1397 TEST_F(PasswordAutofillAgentTest, |
1398 RememberLastNonEmptyPasswordOnSubmit_ScriptCleared) { | 1398 RememberLastNonEmptyPasswordOnSubmit_ScriptCleared) { |
1399 SimulateInputChangeForElement( | 1399 SimulateInputChangeForElement( |
1400 "temp", true, GetMainFrame(), username_element_, true); | 1400 "temp", true, GetMainFrame(), username_element_, true); |
1401 SimulateInputChangeForElement( | 1401 SimulateInputChangeForElement( |
1402 "random", true, GetMainFrame(), password_element_, true); | 1402 "random", true, GetMainFrame(), password_element_, true); |
1403 | 1403 |
1404 // Simulate that the password value was cleared by the site's JavaScript | 1404 // Simulate that the password value was cleared by the site's JavaScript |
1405 // before submit. | 1405 // before submit. |
1406 password_element_.setValue(WebString()); | 1406 password_element_.setValue(WebString()); |
1407 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 1407 static_cast<content::RenderViewObserver*>(&password_autofill_agent_->legacy_) |
1408 ->WillSubmitForm(GetMainFrame(), username_element_.form()); | 1408 ->WillSubmitForm(GetMainFrame(), username_element_.form()); |
1409 | 1409 |
1410 // Observe that the PasswordAutofillAgent still remembered the last non-empty | 1410 // Observe that the PasswordAutofillAgent still remembered the last non-empty |
1411 // password and sent that to the browser. | 1411 // password and sent that to the browser. |
1412 ExpectFormSubmittedWithPasswords("random", ""); | 1412 ExpectFormSubmittedWithPasswords("random", ""); |
1413 } | 1413 } |
1414 | 1414 |
1415 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but this time | 1415 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but this time |
1416 // it's the user who clears the password. This test checks that in that case, | 1416 // it's the user who clears the password. This test checks that in that case, |
1417 // the last non-empty password is not remembered. | 1417 // the last non-empty password is not remembered. |
1418 TEST_F(PasswordAutofillAgentTest, | 1418 TEST_F(PasswordAutofillAgentTest, |
1419 RememberLastNonEmptyPasswordOnSubmit_UserCleared) { | 1419 RememberLastNonEmptyPasswordOnSubmit_UserCleared) { |
1420 SimulateInputChangeForElement( | 1420 SimulateInputChangeForElement( |
1421 "temp", true, GetMainFrame(), username_element_, true); | 1421 "temp", true, GetMainFrame(), username_element_, true); |
1422 SimulateInputChangeForElement( | 1422 SimulateInputChangeForElement( |
1423 "random", true, GetMainFrame(), password_element_, true); | 1423 "random", true, GetMainFrame(), password_element_, true); |
1424 | 1424 |
1425 // Simulate that the user actually cleared the password again. | 1425 // Simulate that the user actually cleared the password again. |
1426 SimulateInputChangeForElement( | 1426 SimulateInputChangeForElement( |
1427 "", true, GetMainFrame(), password_element_, true); | 1427 "", true, GetMainFrame(), password_element_, true); |
1428 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 1428 static_cast<content::RenderViewObserver*>(&password_autofill_agent_->legacy_) |
1429 ->WillSubmitForm(GetMainFrame(), username_element_.form()); | 1429 ->WillSubmitForm(GetMainFrame(), username_element_.form()); |
1430 | 1430 |
1431 // Observe that the PasswordAutofillAgent respects the user having cleared the | 1431 // Observe that the PasswordAutofillAgent respects the user having cleared the |
1432 // password. | 1432 // password. |
1433 ExpectFormSubmittedWithPasswords("", ""); | 1433 ExpectFormSubmittedWithPasswords("", ""); |
1434 } | 1434 } |
1435 | 1435 |
1436 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but uses the | 1436 // Similar to RememberLastNonEmptyPasswordOnSubmit_ScriptCleared, but uses the |
1437 // new password instead of the current password. | 1437 // new password instead of the current password. |
1438 TEST_F(PasswordAutofillAgentTest, | 1438 TEST_F(PasswordAutofillAgentTest, |
1439 RememberLastNonEmptyPasswordOnSubmit_NewPassword) { | 1439 RememberLastNonEmptyPasswordOnSubmit_NewPassword) { |
1440 const char kNewPasswordFormHTML[] = | 1440 const char kNewPasswordFormHTML[] = |
1441 "<FORM name='LoginTestForm'>" | 1441 "<FORM name='LoginTestForm'>" |
1442 " <INPUT type='text' id='username' autocomplete='username'/>" | 1442 " <INPUT type='text' id='username' autocomplete='username'/>" |
1443 " <INPUT type='password' id='password' autocomplete='new-password'/>" | 1443 " <INPUT type='password' id='password' autocomplete='new-password'/>" |
1444 " <INPUT type='submit' value='Login'/>" | 1444 " <INPUT type='submit' value='Login'/>" |
1445 "</FORM>"; | 1445 "</FORM>"; |
1446 LoadHTML(kNewPasswordFormHTML); | 1446 LoadHTML(kNewPasswordFormHTML); |
1447 UpdateUsernameAndPasswordElements(); | 1447 UpdateUsernameAndPasswordElements(); |
1448 | 1448 |
1449 SimulateInputChangeForElement( | 1449 SimulateInputChangeForElement( |
1450 "temp", true, GetMainFrame(), username_element_, true); | 1450 "temp", true, GetMainFrame(), username_element_, true); |
1451 SimulateInputChangeForElement( | 1451 SimulateInputChangeForElement( |
1452 "random", true, GetMainFrame(), password_element_, true); | 1452 "random", true, GetMainFrame(), password_element_, true); |
1453 | 1453 |
1454 // Simulate that the password value was cleared by the site's JavaScript | 1454 // Simulate that the password value was cleared by the site's JavaScript |
1455 // before submit. | 1455 // before submit. |
1456 password_element_.setValue(WebString()); | 1456 password_element_.setValue(WebString()); |
1457 static_cast<content::RenderViewObserver*>(password_autofill_agent_) | 1457 static_cast<content::RenderViewObserver*>(&password_autofill_agent_->legacy_) |
1458 ->WillSubmitForm(GetMainFrame(), username_element_.form()); | 1458 ->WillSubmitForm(GetMainFrame(), username_element_.form()); |
1459 | 1459 |
1460 // Observe that the PasswordAutofillAgent still remembered the last non-empty | 1460 // Observe that the PasswordAutofillAgent still remembered the last non-empty |
1461 // password and sent that to the browser. | 1461 // password and sent that to the browser. |
1462 ExpectFormSubmittedWithPasswords("", "random"); | 1462 ExpectFormSubmittedWithPasswords("", "random"); |
1463 } | 1463 } |
1464 | 1464 |
1465 // The user first accepts a suggestion, but then overwrites the password. This | 1465 // The user first accepts a suggestion, but then overwrites the password. This |
1466 // test checks that the overwritten password is not reverted back if the user | 1466 // test checks that the overwritten password is not reverted back if the user |
1467 // triggers autofill through focusing (but not changing) the username again. | 1467 // triggers autofill through focusing (but not changing) the username again. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 password_element_, | 1514 password_element_, |
1515 /*is_user_input=*/true); | 1515 /*is_user_input=*/true); |
1516 | 1516 |
1517 // Simulate the user typing a stored username. | 1517 // Simulate the user typing a stored username. |
1518 SimulateUsernameChange(kAliceUsername, true); | 1518 SimulateUsernameChange(kAliceUsername, true); |
1519 // The autofileld password should replace the typed one. | 1519 // The autofileld password should replace the typed one. |
1520 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); | 1520 CheckTextFieldsDOMState(kAliceUsername, true, kAlicePassword, true); |
1521 } | 1521 } |
1522 | 1522 |
1523 } // namespace autofill | 1523 } // namespace autofill |
OLD | NEW |