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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 | 412 |
413 // Checks the message sent to PasswordAutofillManager to build the suggestion | 413 // Checks the message sent to PasswordAutofillManager to build the suggestion |
414 // list. |username| is the expected username field value, and |show_all| is | 414 // list. |username| is the expected username field value, and |show_all| is |
415 // the expected flag for the PasswordAutofillManager, whether to show all | 415 // the expected flag for the PasswordAutofillManager, whether to show all |
416 // suggestions, or only those starting with |username|. | 416 // suggestions, or only those starting with |username|. |
417 void CheckSuggestions(const std::string& username, bool show_all) { | 417 void CheckSuggestions(const std::string& username, bool show_all) { |
418 const IPC::Message* message = | 418 const IPC::Message* message = |
419 render_thread_->sink().GetFirstMessageMatching( | 419 render_thread_->sink().GetFirstMessageMatching( |
420 AutofillHostMsg_ShowPasswordSuggestions::ID); | 420 AutofillHostMsg_ShowPasswordSuggestions::ID); |
421 EXPECT_TRUE(message); | 421 EXPECT_TRUE(message); |
422 Tuple5<int, base::i18n::TextDirection, base::string16, int, gfx::RectF> | 422 Tuple<int, base::i18n::TextDirection, base::string16, int, gfx::RectF> |
423 args; | 423 args; |
424 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args); | 424 AutofillHostMsg_ShowPasswordSuggestions::Read(message, &args); |
425 EXPECT_EQ(kPasswordFillFormDataId, args.a); | 425 EXPECT_EQ(kPasswordFillFormDataId, get<0>(args)); |
426 EXPECT_EQ(ASCIIToUTF16(username), args.c); | 426 EXPECT_EQ(ASCIIToUTF16(username), get<2>(args)); |
427 EXPECT_EQ(show_all, static_cast<bool>(args.d & autofill::SHOW_ALL)); | 427 EXPECT_EQ(show_all, static_cast<bool>(get<3>(args) & autofill::SHOW_ALL)); |
428 | 428 |
429 render_thread_->sink().ClearMessages(); | 429 render_thread_->sink().ClearMessages(); |
430 } | 430 } |
431 | 431 |
432 void ExpectFormSubmittedWithUsernameAndPasswords( | 432 void ExpectFormSubmittedWithUsernameAndPasswords( |
433 const std::string& username_value, | 433 const std::string& username_value, |
434 const std::string& password_value, | 434 const std::string& password_value, |
435 const std::string& new_password_value) { | 435 const std::string& new_password_value) { |
436 const IPC::Message* message = | 436 const IPC::Message* message = |
437 render_thread_->sink().GetFirstMessageMatching( | 437 render_thread_->sink().GetFirstMessageMatching( |
438 AutofillHostMsg_PasswordFormSubmitted::ID); | 438 AutofillHostMsg_PasswordFormSubmitted::ID); |
439 ASSERT_TRUE(message); | 439 ASSERT_TRUE(message); |
440 Tuple1<autofill::PasswordForm> args; | 440 Tuple<autofill::PasswordForm> args; |
441 AutofillHostMsg_PasswordFormSubmitted::Read(message, &args); | 441 AutofillHostMsg_PasswordFormSubmitted::Read(message, &args); |
442 EXPECT_EQ(ASCIIToUTF16(username_value), args.a.username_value); | 442 EXPECT_EQ(ASCIIToUTF16(username_value), get<0>(args).username_value); |
443 EXPECT_EQ(ASCIIToUTF16(password_value), args.a.password_value); | 443 EXPECT_EQ(ASCIIToUTF16(password_value), get<0>(args).password_value); |
444 EXPECT_EQ(ASCIIToUTF16(new_password_value), args.a.new_password_value); | 444 EXPECT_EQ(ASCIIToUTF16(new_password_value), |
| 445 get<0>(args).new_password_value); |
445 } | 446 } |
446 | 447 |
447 base::string16 username1_; | 448 base::string16 username1_; |
448 base::string16 username2_; | 449 base::string16 username2_; |
449 base::string16 username3_; | 450 base::string16 username3_; |
450 base::string16 password1_; | 451 base::string16 password1_; |
451 base::string16 password2_; | 452 base::string16 password2_; |
452 base::string16 password3_; | 453 base::string16 password3_; |
453 base::string16 alternate_username3_; | 454 base::string16 alternate_username3_; |
454 PasswordFormFillData fill_data_; | 455 PasswordFormFillData fill_data_; |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 ASSERT_EQ(1u, forms3.size()); | 799 ASSERT_EQ(1u, forms3.size()); |
799 EXPECT_FALSE(IsWebNodeVisible(forms3[0])); | 800 EXPECT_FALSE(IsWebNodeVisible(forms3[0])); |
800 } | 801 } |
801 | 802 |
802 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest) { | 803 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest) { |
803 render_thread_->sink().ClearMessages(); | 804 render_thread_->sink().ClearMessages(); |
804 LoadHTML(kVisibleFormWithNoUsernameHTML); | 805 LoadHTML(kVisibleFormWithNoUsernameHTML); |
805 const IPC::Message* message = render_thread_->sink() | 806 const IPC::Message* message = render_thread_->sink() |
806 .GetFirstMessageMatching(AutofillHostMsg_PasswordFormsRendered::ID); | 807 .GetFirstMessageMatching(AutofillHostMsg_PasswordFormsRendered::ID); |
807 EXPECT_TRUE(message); | 808 EXPECT_TRUE(message); |
808 Tuple2<std::vector<autofill::PasswordForm>, bool > param; | 809 Tuple<std::vector<autofill::PasswordForm>, bool> param; |
809 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); | 810 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); |
810 EXPECT_TRUE(param.a.size()); | 811 EXPECT_TRUE(get<0>(param).size()); |
811 | 812 |
812 render_thread_->sink().ClearMessages(); | 813 render_thread_->sink().ClearMessages(); |
813 LoadHTML(kEmptyFormHTML); | 814 LoadHTML(kEmptyFormHTML); |
814 message = render_thread_->sink().GetFirstMessageMatching( | 815 message = render_thread_->sink().GetFirstMessageMatching( |
815 AutofillHostMsg_PasswordFormsRendered::ID); | 816 AutofillHostMsg_PasswordFormsRendered::ID); |
816 EXPECT_TRUE(message); | 817 EXPECT_TRUE(message); |
817 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); | 818 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); |
818 EXPECT_FALSE(param.a.size()); | 819 EXPECT_FALSE(get<0>(param).size()); |
819 | 820 |
820 render_thread_->sink().ClearMessages(); | 821 render_thread_->sink().ClearMessages(); |
821 LoadHTML(kNonVisibleFormHTML); | 822 LoadHTML(kNonVisibleFormHTML); |
822 message = render_thread_->sink().GetFirstMessageMatching( | 823 message = render_thread_->sink().GetFirstMessageMatching( |
823 AutofillHostMsg_PasswordFormsRendered::ID); | 824 AutofillHostMsg_PasswordFormsRendered::ID); |
824 EXPECT_TRUE(message); | 825 EXPECT_TRUE(message); |
825 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); | 826 AutofillHostMsg_PasswordFormsRendered::Read(message, ¶m); |
826 EXPECT_FALSE(param.a.size()); | 827 EXPECT_FALSE(get<0>(param).size()); |
827 } | 828 } |
828 | 829 |
829 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_Redirection) { | 830 TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_Redirection) { |
830 render_thread_->sink().ClearMessages(); | 831 render_thread_->sink().ClearMessages(); |
831 LoadHTML(kEmptyWebpage); | 832 LoadHTML(kEmptyWebpage); |
832 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 833 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
833 AutofillHostMsg_PasswordFormsRendered::ID)); | 834 AutofillHostMsg_PasswordFormsRendered::ID)); |
834 | 835 |
835 render_thread_->sink().ClearMessages(); | 836 render_thread_->sink().ClearMessages(); |
836 LoadHTML(kRedirectionWebpage); | 837 LoadHTML(kRedirectionWebpage); |
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1749 password_element_.setAutofilled(false); | 1750 password_element_.setAutofilled(false); |
1750 | 1751 |
1751 SimulateSuggestionChoiceOfUsernameAndPassword( | 1752 SimulateSuggestionChoiceOfUsernameAndPassword( |
1752 password_element_, base::string16(), ASCIIToUTF16(kAlicePassword)); | 1753 password_element_, base::string16(), ASCIIToUTF16(kAlicePassword)); |
1753 CheckSuggestions(std::string(), false); | 1754 CheckSuggestions(std::string(), false); |
1754 EXPECT_EQ(ASCIIToUTF16(kAlicePassword), password_element_.value()); | 1755 EXPECT_EQ(ASCIIToUTF16(kAlicePassword), password_element_.value()); |
1755 EXPECT_TRUE(password_element_.isAutofilled()); | 1756 EXPECT_TRUE(password_element_.isAutofilled()); |
1756 } | 1757 } |
1757 | 1758 |
1758 } // namespace autofill | 1759 } // namespace autofill |
OLD | NEW |