OLD | NEW |
| (Empty) |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/memory/scoped_vector.h" | |
6 #include "base/strings/string16.h" | |
7 #include "base/strings/utf_string_conversions.h" | |
8 #include "components/autofill/browser/android/auxiliary_profile_loader_android.h
" | |
9 #include "components/autofill/browser/android/auxiliary_profiles_android.h" | |
10 #include "components/autofill/browser/android/test_auxiliary_profile_loader_andr
oid.h" | |
11 #include "components/autofill/browser/autofill_profile.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 namespace autofill { | |
15 | |
16 class AuxiliaryProfileAndroidTest : public testing::Test { | |
17 public: | |
18 AuxiliaryProfileAndroidTest() {} | |
19 | |
20 AutofillProfile* GetAndLoadProfile() { | |
21 autofill::AuxiliaryProfilesAndroid impl(profile_loader_, "en-US"); | |
22 profile_ = impl.LoadContactsProfile(); | |
23 return profile_.get(); | |
24 } | |
25 | |
26 TestAuxiliaryProfileLoader& profile_loader() { | |
27 return profile_loader_; | |
28 } | |
29 | |
30 private: | |
31 TestAuxiliaryProfileLoader profile_loader_; | |
32 scoped_ptr<AutofillProfile> profile_; | |
33 }; | |
34 | |
35 TEST_F(AuxiliaryProfileAndroidTest, SetNameInfo) { | |
36 base::string16 first_name = ASCIIToUTF16("John"); | |
37 base::string16 middle_name = ASCIIToUTF16("H."); | |
38 base::string16 last_name = ASCIIToUTF16("Waston"); | |
39 | |
40 profile_loader().SetFirstName(first_name); | |
41 profile_loader().SetMiddleName(middle_name); | |
42 profile_loader().SetLastName(last_name); | |
43 | |
44 AutofillProfile* profile = GetAndLoadProfile(); | |
45 | |
46 EXPECT_EQ(profile->GetRawInfo(NAME_FIRST), first_name); | |
47 EXPECT_EQ(profile->GetRawInfo(NAME_MIDDLE), middle_name); | |
48 EXPECT_EQ(profile->GetRawInfo(NAME_LAST), last_name); | |
49 } | |
50 | |
51 TEST_F(AuxiliaryProfileAndroidTest, SetNameInfoEmpty) { | |
52 AutofillProfile* profile = GetAndLoadProfile(); | |
53 | |
54 EXPECT_EQ(profile->GetRawInfo(NAME_FIRST), base::string16()); | |
55 EXPECT_EQ(profile->GetRawInfo(NAME_MIDDLE), base::string16()); | |
56 EXPECT_EQ(profile->GetRawInfo(NAME_LAST), base::string16()); | |
57 } | |
58 | |
59 TEST_F(AuxiliaryProfileAndroidTest, SetEmailInfo) { | |
60 std::vector<base::string16> email_addresses; | |
61 email_addresses.push_back(ASCIIToUTF16("sherlock@holmes.com")); | |
62 email_addresses.push_back(ASCIIToUTF16("watson@holmes.com")); | |
63 profile_loader().SetEmailAddresses(email_addresses); | |
64 | |
65 AutofillProfile* profile = GetAndLoadProfile(); | |
66 std::vector<base::string16> loaded_email_addresses; | |
67 profile->GetRawMultiInfo(EMAIL_ADDRESS, &loaded_email_addresses); | |
68 EXPECT_EQ(loaded_email_addresses, email_addresses); | |
69 } | |
70 | |
71 TEST_F(AuxiliaryProfileAndroidTest, SetEmailInfoEmpty) { | |
72 std::vector<base::string16> expected_email_addresses; | |
73 expected_email_addresses.push_back(base::string16()); | |
74 std::vector<base::string16> loaded_email_addresses; | |
75 AutofillProfile* profile = GetAndLoadProfile(); | |
76 profile->GetRawMultiInfo(EMAIL_ADDRESS, &loaded_email_addresses); | |
77 EXPECT_EQ(loaded_email_addresses, expected_email_addresses); | |
78 } | |
79 | |
80 TEST_F(AuxiliaryProfileAndroidTest, SetPhoneInfo) { | |
81 std::vector<base::string16> phone_numbers; | |
82 phone_numbers.push_back(ASCIIToUTF16("6502530000")); | |
83 profile_loader().SetPhoneNumbers(phone_numbers); | |
84 | |
85 std::vector<base::string16> loaded_phone_numbers; | |
86 AutofillProfile* profile = GetAndLoadProfile(); | |
87 profile->GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &loaded_phone_numbers); | |
88 EXPECT_EQ(loaded_phone_numbers, phone_numbers); | |
89 } | |
90 | |
91 TEST_F(AuxiliaryProfileAndroidTest, SetPhoneInfoEmpty) { | |
92 std::vector<base::string16> expected_phone_numbers; | |
93 expected_phone_numbers.push_back(base::string16()); | |
94 | |
95 std::vector<base::string16> loaded_phone_numbers; | |
96 AutofillProfile* profile = GetAndLoadProfile(); | |
97 profile->GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &loaded_phone_numbers); | |
98 EXPECT_EQ(loaded_phone_numbers, expected_phone_numbers); | |
99 } | |
100 | |
101 // | |
102 // Android user's profile contact does not parse its address | |
103 // into constituent parts. Instead we just Get a long string blob. | |
104 // Disable address population tests until we implement a way to parse the | |
105 // data. | |
106 // | |
107 | |
108 #if 0 | |
109 TEST_F(AuxiliaryProfileAndroidTest, SetAddressInfo) { | |
110 base::string16 street = ASCIIToUTF16("221 B Baker Street"); | |
111 base::string16 city = ASCIIToUTF16("London"); | |
112 base::string16 postal_code = ASCIIToUTF16("123456"); | |
113 base::string16 region = ASCIIToUTF16("Georgian Terrace"); | |
114 base::string16 country = ASCIIToUTF16("England"); | |
115 | |
116 profile_loader().SetStreet(street); | |
117 profile_loader().SetCity(city); | |
118 profile_loader().SetPostalCode(postal_code); | |
119 profile_loader().SetRegion(region); | |
120 profile_loader().SetCountry(country); | |
121 | |
122 AutofillProfile* profile = GetAndLoadProfile(); | |
123 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE1), street); | |
124 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_CITY), city); | |
125 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_ZIP), postal_code); | |
126 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_STATE), region); | |
127 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_COUNTRY), country); | |
128 } | |
129 | |
130 base::string16 post_office_box= ASCIIToUTF16("222"); | |
131 base::string16 neighborhood = ASCIIToUTF16("Doyle"); | |
132 TEST_F(AuxiliaryProfileAndroidTest, SetAddressInfoCompoundFields1) { | |
133 profile_loader().SetPostOfficeBox(post_office_box); | |
134 profile_loader().SetNeighborhood(neighborhood); | |
135 base::string16 expectedLine2= ASCIIToUTF16("222, Doyle"); | |
136 AutofillProfile* profile = GetAndLoadProfile(); | |
137 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), expectedLine2); | |
138 } | |
139 | |
140 TEST_F(AuxiliaryProfileAndroidTest, SetAddressInfoCompoundFields2) { | |
141 profile_loader().SetPostOfficeBox(post_office_box); | |
142 AutofillProfile* profile = GetAndLoadProfile(); | |
143 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), post_office_box); | |
144 } | |
145 | |
146 TEST_F(AuxiliaryProfileAndroidTest, SetAddressInfoCompoundFields3) { | |
147 profile_loader().SetNeighborhood(neighborhood); | |
148 AutofillProfile* profile = GetAndLoadProfile(); | |
149 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), neighborhood); | |
150 } | |
151 | |
152 TEST_F(AuxiliaryProfileAndroidTest, SetAddressInfoEmpty) { | |
153 AutofillProfile* profile = GetAndLoadProfile(); | |
154 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE1), base::string16()); | |
155 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), base::string16()); | |
156 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_CITY), base::string16()); | |
157 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_ZIP), base::string16()); | |
158 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_STATE), base::string16()); | |
159 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_COUNTRY), base::string16()); | |
160 } | |
161 #endif | |
162 | |
163 } // namespace autofill | |
OLD | NEW |