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