| 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 <tuple> |
| 6 |
| 5 #include "base/macros.h" | 7 #include "base/macros.h" |
| 6 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/renderer/autofill/password_generation_test_utils.h" | 10 #include "chrome/renderer/autofill/password_generation_test_utils.h" |
| 9 #include "chrome/test/base/chrome_render_view_test.h" | 11 #include "chrome/test/base/chrome_render_view_test.h" |
| 10 #include "components/autofill/content/common/autofill_messages.h" | 12 #include "components/autofill/content/common/autofill_messages.h" |
| 11 #include "components/autofill/content/renderer/autofill_agent.h" | 13 #include "components/autofill/content/renderer/autofill_agent.h" |
| 12 #include "components/autofill/content/renderer/form_autofill_util.h" | 14 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 13 #include "components/autofill/content/renderer/password_autofill_agent.h" | 15 #include "components/autofill/content/renderer/password_autofill_agent.h" |
| 14 #include "components/autofill/content/renderer/test_password_autofill_agent.h" | 16 #include "components/autofill/content/renderer/test_password_autofill_agent.h" |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 435 |
| 434 // Checks the message sent to PasswordAutofillManager to build the suggestion | 436 // Checks the message sent to PasswordAutofillManager to build the suggestion |
| 435 // list. |username| is the expected username field value, and |show_all| is | 437 // list. |username| is the expected username field value, and |show_all| is |
| 436 // the expected flag for the PasswordAutofillManager, whether to show all | 438 // the expected flag for the PasswordAutofillManager, whether to show all |
| 437 // suggestions, or only those starting with |username|. | 439 // suggestions, or only those starting with |username|. |
| 438 void CheckSuggestions(const std::string& username, bool show_all) { | 440 void CheckSuggestions(const std::string& username, bool show_all) { |
| 439 const IPC::Message* message = | 441 const IPC::Message* message = |
| 440 render_thread_->sink().GetFirstMessageMatching( | 442 render_thread_->sink().GetFirstMessageMatching( |
| 441 AutofillHostMsg_ShowPasswordSuggestions::ID); | 443 AutofillHostMsg_ShowPasswordSuggestions::ID); |
| 442 ASSERT_TRUE(message); | 444 ASSERT_TRUE(message); |
| 443 base::Tuple<int, base::i18n::TextDirection, base::string16, int, gfx::RectF> | 445 std::tuple<int, base::i18n::TextDirection, base::string16, int, gfx::RectF> |
| 444 args; | 446 args; |
| 445 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args); | 447 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args); |
| 446 EXPECT_EQ(kPasswordFillFormDataId, base::get<0>(args)); | 448 EXPECT_EQ(kPasswordFillFormDataId, std::get<0>(args)); |
| 447 EXPECT_EQ(ASCIIToUTF16(username), base::get<2>(args)); | 449 EXPECT_EQ(ASCIIToUTF16(username), std::get<2>(args)); |
| 448 EXPECT_EQ(show_all, | 450 EXPECT_EQ(show_all, |
| 449 static_cast<bool>(base::get<3>(args) & autofill::SHOW_ALL)); | 451 static_cast<bool>(std::get<3>(args) & autofill::SHOW_ALL)); |
| 450 | 452 |
| 451 render_thread_->sink().ClearMessages(); | 453 render_thread_->sink().ClearMessages(); |
| 452 } | 454 } |
| 453 | 455 |
| 454 void ExpectFormSubmittedWithUsernameAndPasswords( | 456 void ExpectFormSubmittedWithUsernameAndPasswords( |
| 455 const std::string& username_value, | 457 const std::string& username_value, |
| 456 const std::string& password_value, | 458 const std::string& password_value, |
| 457 const std::string& new_password_value) { | 459 const std::string& new_password_value) { |
| 458 const IPC::Message* message = | 460 const IPC::Message* message = |
| 459 render_thread_->sink().GetFirstMessageMatching( | 461 render_thread_->sink().GetFirstMessageMatching( |
| 460 AutofillHostMsg_PasswordFormSubmitted::ID); | 462 AutofillHostMsg_PasswordFormSubmitted::ID); |
| 461 ASSERT_TRUE(message); | 463 ASSERT_TRUE(message); |
| 462 base::Tuple<autofill::PasswordForm> args; | 464 std::tuple<autofill::PasswordForm> args; |
| 463 AutofillHostMsg_PasswordFormSubmitted::Read(message, &args); | 465 AutofillHostMsg_PasswordFormSubmitted::Read(message, &args); |
| 464 EXPECT_EQ(ASCIIToUTF16(username_value), base::get<0>(args).username_value); | 466 EXPECT_EQ(ASCIIToUTF16(username_value), std::get<0>(args).username_value); |
| 465 EXPECT_EQ(ASCIIToUTF16(password_value), base::get<0>(args).password_value); | 467 EXPECT_EQ(ASCIIToUTF16(password_value), std::get<0>(args).password_value); |
| 466 EXPECT_EQ(ASCIIToUTF16(new_password_value), | 468 EXPECT_EQ(ASCIIToUTF16(new_password_value), |
| 467 base::get<0>(args).new_password_value); | 469 std::get<0>(args).new_password_value); |
| 468 } | 470 } |
| 469 | 471 |
| 470 void ExpectInPageNavigationWithUsernameAndPasswords( | 472 void ExpectInPageNavigationWithUsernameAndPasswords( |
| 471 const std::string& username_value, | 473 const std::string& username_value, |
| 472 const std::string& password_value, | 474 const std::string& password_value, |
| 473 const std::string& new_password_value) { | 475 const std::string& new_password_value) { |
| 474 const IPC::Message* message = | 476 const IPC::Message* message = |
| 475 render_thread_->sink().GetFirstMessageMatching( | 477 render_thread_->sink().GetFirstMessageMatching( |
| 476 AutofillHostMsg_InPageNavigation::ID); | 478 AutofillHostMsg_InPageNavigation::ID); |
| 477 ASSERT_TRUE(message); | 479 ASSERT_TRUE(message); |
| 478 base::Tuple<autofill::PasswordForm> args; | 480 std::tuple<autofill::PasswordForm> args; |
| 479 AutofillHostMsg_InPageNavigation::Read(message, &args); | 481 AutofillHostMsg_InPageNavigation::Read(message, &args); |
| 480 EXPECT_EQ(ASCIIToUTF16(username_value), base::get<0>(args).username_value); | 482 EXPECT_EQ(ASCIIToUTF16(username_value), std::get<0>(args).username_value); |
| 481 EXPECT_EQ(ASCIIToUTF16(password_value), base::get<0>(args).password_value); | 483 EXPECT_EQ(ASCIIToUTF16(password_value), std::get<0>(args).password_value); |
| 482 EXPECT_EQ(ASCIIToUTF16(new_password_value), | 484 EXPECT_EQ(ASCIIToUTF16(new_password_value), |
| 483 base::get<0>(args).new_password_value); | 485 std::get<0>(args).new_password_value); |
| 484 } | 486 } |
| 485 | 487 |
| 486 base::string16 username1_; | 488 base::string16 username1_; |
| 487 base::string16 username2_; | 489 base::string16 username2_; |
| 488 base::string16 username3_; | 490 base::string16 username3_; |
| 489 base::string16 password1_; | 491 base::string16 password1_; |
| 490 base::string16 password2_; | 492 base::string16 password2_; |
| 491 base::string16 password3_; | 493 base::string16 password3_; |
| 492 base::string16 alternate_username3_; | 494 base::string16 alternate_username3_; |
| 493 PasswordFormFillData fill_data_; | 495 PasswordFormFillData fill_data_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 508 * returns false. May be we should mock URL loading to cirmcuvent this? | 510 * returns false. May be we should mock URL loading to cirmcuvent this? |
| 509 TODO(jcivelli): find a way to make the security origin not deny access to the | 511 TODO(jcivelli): find a way to make the security origin not deny access to the |
| 510 password manager and then reenable this code. | 512 password manager and then reenable this code. |
| 511 | 513 |
| 512 // The form has been loaded, we should have sent the browser a message about | 514 // The form has been loaded, we should have sent the browser a message about |
| 513 // the form. | 515 // the form. |
| 514 const IPC::Message* msg = render_thread_.sink().GetFirstMessageMatching( | 516 const IPC::Message* msg = render_thread_.sink().GetFirstMessageMatching( |
| 515 AutofillHostMsg_PasswordFormsParsed::ID); | 517 AutofillHostMsg_PasswordFormsParsed::ID); |
| 516 ASSERT_TRUE(msg != NULL); | 518 ASSERT_TRUE(msg != NULL); |
| 517 | 519 |
| 518 base::Tuple1<std::vector<PasswordForm> > forms; | 520 std::tuple<std::vector<PasswordForm> > forms; |
| 519 AutofillHostMsg_PasswordFormsParsed::Read(msg, &forms); | 521 AutofillHostMsg_PasswordFormsParsed::Read(msg, &forms); |
| 520 ASSERT_EQ(1U, forms.a.size()); | 522 ASSERT_EQ(1U, forms.a.size()); |
| 521 PasswordForm password_form = forms.a[0]; | 523 PasswordForm password_form = forms.a[0]; |
| 522 EXPECT_EQ(PasswordForm::SCHEME_HTML, password_form.scheme); | 524 EXPECT_EQ(PasswordForm::SCHEME_HTML, password_form.scheme); |
| 523 EXPECT_EQ(ASCIIToUTF16(kUsernameName), password_form.username_element); | 525 EXPECT_EQ(ASCIIToUTF16(kUsernameName), password_form.username_element); |
| 524 EXPECT_EQ(ASCIIToUTF16(kPasswordName), password_form.password_element); | 526 EXPECT_EQ(ASCIIToUTF16(kPasswordName), password_form.password_element); |
| 525 */ | 527 */ |
| 526 | 528 |
| 527 // Simulate the browser sending back the login info, it triggers the | 529 // Simulate the browser sending back the login info, it triggers the |
| 528 // autocomplete. | 530 // autocomplete. |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 ASSERT_EQ(1u, forms3.size()); | 775 ASSERT_EQ(1u, forms3.size()); |
| 774 EXPECT_FALSE(form_util::IsWebNodeVisible(forms3[0])); | 776 EXPECT_FALSE(form_util::IsWebNodeVisible(forms3[0])); |
| 775 } | 777 } |
| 776 | 778 |
| 777 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest) { | 779 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest) { |
| 778 render_thread_->sink().ClearMessages(); | 780 render_thread_->sink().ClearMessages(); |
| 779 LoadHTML(kVisibleFormWithNoUsernameHTML); | 781 LoadHTML(kVisibleFormWithNoUsernameHTML); |
| 780 const IPC::Message* message = render_thread_->sink() | 782 const IPC::Message* message = render_thread_->sink() |
| 781 .GetFirstMessageMatching(AutofillHostMsg_PasswordFormsRendered::ID); | 783 .GetFirstMessageMatching(AutofillHostMsg_PasswordFormsRendered::ID); |
| 782 EXPECT_TRUE(message); | 784 EXPECT_TRUE(message); |
| 783 base::Tuple<std::vector<autofill::PasswordForm>, bool> param; | 785 std::tuple<std::vector<autofill::PasswordForm>, bool> param; |
| 784 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); | 786 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); |
| 785 EXPECT_TRUE(base::get<0>(param).size()); | 787 EXPECT_TRUE(std::get<0>(param).size()); |
| 786 | 788 |
| 787 render_thread_->sink().ClearMessages(); | 789 render_thread_->sink().ClearMessages(); |
| 788 LoadHTML(kEmptyFormHTML); | 790 LoadHTML(kEmptyFormHTML); |
| 789 message = render_thread_->sink().GetFirstMessageMatching( | 791 message = render_thread_->sink().GetFirstMessageMatching( |
| 790 AutofillHostMsg_PasswordFormsRendered::ID); | 792 AutofillHostMsg_PasswordFormsRendered::ID); |
| 791 EXPECT_TRUE(message); | 793 EXPECT_TRUE(message); |
| 792 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); | 794 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); |
| 793 EXPECT_FALSE(base::get<0>(param).size()); | 795 EXPECT_FALSE(std::get<0>(param).size()); |
| 794 | 796 |
| 795 render_thread_->sink().ClearMessages(); | 797 render_thread_->sink().ClearMessages(); |
| 796 LoadHTML(kNonVisibleFormHTML); | 798 LoadHTML(kNonVisibleFormHTML); |
| 797 message = render_thread_->sink().GetFirstMessageMatching( | 799 message = render_thread_->sink().GetFirstMessageMatching( |
| 798 AutofillHostMsg_PasswordFormsRendered::ID); | 800 AutofillHostMsg_PasswordFormsRendered::ID); |
| 799 EXPECT_TRUE(message); | 801 EXPECT_TRUE(message); |
| 800 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); | 802 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); |
| 801 EXPECT_FALSE(base::get<0>(param).size()); | 803 EXPECT_FALSE(std::get<0>(param).size()); |
| 802 } | 804 } |
| 803 | 805 |
| 804 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_Redirection) { | 806 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_Redirection) { |
| 805 render_thread_->sink().ClearMessages(); | 807 render_thread_->sink().ClearMessages(); |
| 806 LoadHTML(kEmptyWebpage); | 808 LoadHTML(kEmptyWebpage); |
| 807 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 809 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
| 808 AutofillHostMsg_PasswordFormsRendered::ID)); | 810 AutofillHostMsg_PasswordFormsRendered::ID)); |
| 809 | 811 |
| 810 render_thread_->sink().ClearMessages(); | 812 render_thread_->sink().ClearMessages(); |
| 811 LoadHTML(kRedirectionWebpage); | 813 LoadHTML(kRedirectionWebpage); |
| (...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2319 | 2321 |
| 2320 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2322 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 2321 ->WillSendSubmitEvent(username_element_.form()); | 2323 ->WillSendSubmitEvent(username_element_.form()); |
| 2322 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) | 2324 static_cast<content::RenderFrameObserver*>(password_autofill_agent_) |
| 2323 ->WillSubmitForm(username_element_.form()); | 2325 ->WillSubmitForm(username_element_.form()); |
| 2324 | 2326 |
| 2325 ExpectFormSubmittedWithUsernameAndPasswords("Alice", "mypassword", ""); | 2327 ExpectFormSubmittedWithUsernameAndPasswords("Alice", "mypassword", ""); |
| 2326 } | 2328 } |
| 2327 | 2329 |
| 2328 } // namespace autofill | 2330 } // namespace autofill |
| OLD | NEW |