OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/ref_counted.h" | 7 #include "base/ref_counted.h" |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
9 #include "base/scoped_vector.h" | 9 #include "base/scoped_vector.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "chrome/common/ipc_test_sink.h" | 21 #include "chrome/common/ipc_test_sink.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "chrome/common/render_messages.h" | 23 #include "chrome/common/render_messages.h" |
24 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "webkit/glue/form_data.h" | 26 #include "webkit/glue/form_data.h" |
27 #include "webkit/glue/form_field.h" | 27 #include "webkit/glue/form_field.h" |
28 | 28 |
29 using webkit_glue::FormData; | 29 using webkit_glue::FormData; |
30 | 30 |
31 namespace { | |
32 | |
33 typedef Tuple4<int, | 31 typedef Tuple4<int, |
34 std::vector<string16>, | 32 std::vector<string16>, |
35 std::vector<string16>, | 33 std::vector<string16>, |
36 std::vector<int> > AutoFillParam; | 34 std::vector<int> > AutoFillParam; |
37 | 35 |
38 class TestPersonalDataManager : public PersonalDataManager { | 36 class TestPersonalDataManager : public PersonalDataManager { |
39 public: | 37 public: |
40 TestPersonalDataManager() { | 38 TestPersonalDataManager() { |
41 CreateTestAutoFillProfiles(&web_profiles_); | 39 CreateTestAutoFillProfiles(&web_profiles_); |
42 CreateTestCreditCards(&credit_cards_); | 40 CreateTestCreditCards(&credit_cards_); |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 autofill_manager_->FormsSeen(forms); | 722 autofill_manager_->FormsSeen(forms); |
725 | 723 |
726 // The page ID sent to the AutoFillManager from the RenderView, used to send | 724 // The page ID sent to the AutoFillManager from the RenderView, used to send |
727 // an IPC message back to the renderer. | 725 // an IPC message back to the renderer. |
728 const int kPageID = 1; | 726 const int kPageID = 1; |
729 EXPECT_TRUE( | 727 EXPECT_TRUE( |
730 autofill_manager_->FillAutoFillFormData(kPageID, | 728 autofill_manager_->FillAutoFillFormData(kPageID, |
731 form, | 729 form, |
732 string16(), | 730 string16(), |
733 ASCIIToUTF16("Home; *3456"), | 731 ASCIIToUTF16("Home; *3456"), |
734 1)); | 732 AutoFillManager::PackIDs(4, 1))); |
735 | 733 |
736 int page_id = 0; | 734 int page_id = 0; |
737 FormData results; | 735 FormData results; |
738 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | 736 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
739 EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name); | 737 EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name); |
740 EXPECT_EQ(ASCIIToUTF16("POST"), results.method); | 738 EXPECT_EQ(ASCIIToUTF16("POST"), results.method); |
741 EXPECT_EQ(GURL("https://myform.com/form.html"), results.origin); | 739 EXPECT_EQ(GURL("https://myform.com/form.html"), results.origin); |
742 EXPECT_EQ(GURL("https://myform.com/submit.html"), results.action); | 740 EXPECT_EQ(GURL("https://myform.com/submit.html"), results.action); |
743 ASSERT_EQ(15U, results.fields.size()); | 741 ASSERT_EQ(15U, results.fields.size()); |
744 | 742 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 } | 790 } |
793 | 791 |
794 TEST_F(AutoFillManagerTest, FillNonBillingFormSemicolon) { | 792 TEST_F(AutoFillManagerTest, FillNonBillingFormSemicolon) { |
795 // |profile| will be owned by the mock PersonalDataManager. | 793 // |profile| will be owned by the mock PersonalDataManager. |
796 AutoFillProfile* profile = new AutoFillProfile; | 794 AutoFillProfile* profile = new AutoFillProfile; |
797 autofill_unittest::SetProfileInfo(profile, "Home; 8765", "Joe", "", "Ely", | 795 autofill_unittest::SetProfileInfo(profile, "Home; 8765", "Joe", "", "Ely", |
798 "flatlander@gmail.com", "MCA", | 796 "flatlander@gmail.com", "MCA", |
799 "916 16th St.", "Apt. 6", "Lubbock", | 797 "916 16th St.", "Apt. 6", "Lubbock", |
800 "Texas", "79401", "USA", | 798 "Texas", "79401", "USA", |
801 "12345678901", ""); | 799 "12345678901", ""); |
802 profile->set_unique_id(6); | 800 profile->set_unique_id(7); |
803 autofill_manager_->AddProfile(profile); | 801 autofill_manager_->AddProfile(profile); |
804 | 802 |
805 FormData form; | 803 FormData form; |
806 CreateTestFormData(&form); | 804 CreateTestFormData(&form); |
807 | 805 |
808 // Set up our FormStructures. | 806 // Set up our FormStructures. |
809 std::vector<FormData> forms; | 807 std::vector<FormData> forms; |
810 forms.push_back(form); | 808 forms.push_back(form); |
811 autofill_manager_->FormsSeen(forms); | 809 autofill_manager_->FormsSeen(forms); |
812 | 810 |
813 // The page ID sent to the AutoFillManager from the RenderView, used to send | 811 // The page ID sent to the AutoFillManager from the RenderView, used to send |
814 // an IPC message back to the renderer. | 812 // an IPC message back to the renderer. |
815 const int kPageID = 1; | 813 const int kPageID = 1; |
816 EXPECT_TRUE( | 814 EXPECT_TRUE( |
817 autofill_manager_->FillAutoFillFormData(kPageID, | 815 autofill_manager_->FillAutoFillFormData(kPageID, |
818 form, | 816 form, |
819 string16(), | 817 string16(), |
820 ASCIIToUTF16("Home; 8765"), | 818 ASCIIToUTF16("Home; 8765"), |
821 6)); | 819 AutoFillManager::PackIDs(4, 7))); |
822 | 820 |
823 int page_id = 0; | 821 int page_id = 0; |
824 FormData results; | 822 FormData results; |
825 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | 823 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
826 EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name); | 824 EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name); |
827 EXPECT_EQ(ASCIIToUTF16("POST"), results.method); | 825 EXPECT_EQ(ASCIIToUTF16("POST"), results.method); |
828 EXPECT_EQ(GURL("http://myform.com/form.html"), results.origin); | 826 EXPECT_EQ(GURL("http://myform.com/form.html"), results.origin); |
829 EXPECT_EQ(GURL("http://myform.com/submit.html"), results.action); | 827 EXPECT_EQ(GURL("http://myform.com/submit.html"), results.action); |
830 ASSERT_EQ(11U, results.fields.size()); | 828 ASSERT_EQ(11U, results.fields.size()); |
831 | 829 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 } | 864 } |
867 | 865 |
868 TEST_F(AutoFillManagerTest, FillBillFormSemicolon) { | 866 TEST_F(AutoFillManagerTest, FillBillFormSemicolon) { |
869 // |profile| will be owned by the mock PersonalDataManager. | 867 // |profile| will be owned by the mock PersonalDataManager. |
870 AutoFillProfile* profile = new AutoFillProfile; | 868 AutoFillProfile* profile = new AutoFillProfile; |
871 autofill_unittest::SetProfileInfo(profile, "Home; 8765", "Joe", "", "Ely", | 869 autofill_unittest::SetProfileInfo(profile, "Home; 8765", "Joe", "", "Ely", |
872 "flatlander@gmail.com", "MCA", | 870 "flatlander@gmail.com", "MCA", |
873 "916 16th St.", "Apt. 6", "Lubbock", | 871 "916 16th St.", "Apt. 6", "Lubbock", |
874 "Texas", "79401", "USA", | 872 "Texas", "79401", "USA", |
875 "12345678901", ""); | 873 "12345678901", ""); |
876 profile->set_unique_id(6); | 874 profile->set_unique_id(7); |
877 autofill_manager_->AddProfile(profile); | 875 autofill_manager_->AddProfile(profile); |
878 | 876 |
879 FormData form; | 877 FormData form; |
880 CreateTestFormDataBilling(&form); | 878 CreateTestFormDataBilling(&form); |
881 | 879 |
882 // Set up our FormStructures. | 880 // Set up our FormStructures. |
883 std::vector<FormData> forms; | 881 std::vector<FormData> forms; |
884 forms.push_back(form); | 882 forms.push_back(form); |
885 autofill_manager_->FormsSeen(forms); | 883 autofill_manager_->FormsSeen(forms); |
886 | 884 |
887 // The page ID sent to the AutoFillManager from the RenderView, used to send | 885 // The page ID sent to the AutoFillManager from the RenderView, used to send |
888 // an IPC message back to the renderer. | 886 // an IPC message back to the renderer. |
889 const int kPageID = 1; | 887 const int kPageID = 1; |
890 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( | 888 EXPECT_TRUE(autofill_manager_->FillAutoFillFormData( |
891 kPageID, form, string16(), ASCIIToUTF16("Home; 8765; *3456"), 6)); | 889 kPageID, form, string16(), ASCIIToUTF16("Home; 8765; *3456"), |
| 890 AutoFillManager::PackIDs(4, 7))); |
892 | 891 |
893 int page_id = 0; | 892 int page_id = 0; |
894 FormData results; | 893 FormData results; |
895 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); | 894 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); |
896 EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name); | 895 EXPECT_EQ(ASCIIToUTF16("MyForm"), results.name); |
897 EXPECT_EQ(ASCIIToUTF16("POST"), results.method); | 896 EXPECT_EQ(ASCIIToUTF16("POST"), results.method); |
898 EXPECT_EQ(GURL("https://myform.com/form.html"), results.origin); | 897 EXPECT_EQ(GURL("https://myform.com/form.html"), results.origin); |
899 EXPECT_EQ(GURL("https://myform.com/submit.html"), results.action); | 898 EXPECT_EQ(GURL("https://myform.com/submit.html"), results.action); |
900 ASSERT_EQ(15U, results.fields.size()); | 899 ASSERT_EQ(15U, results.fields.size()); |
901 | 900 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 #else | 1204 #else |
1206 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 1205 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
1207 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 1206 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
1208 profile()->GetPrefs()->SetBoolean( | 1207 profile()->GetPrefs()->SetBoolean( |
1209 prefs::kAutoFillAuxiliaryProfilesEnabled, true); | 1208 prefs::kAutoFillAuxiliaryProfilesEnabled, true); |
1210 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); | 1209 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); |
1211 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( | 1210 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( |
1212 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 1211 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
1213 #endif | 1212 #endif |
1214 } | 1213 } |
1215 | |
1216 } // namespace | |
OLD | NEW |