OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 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/string16.h" | |
7 #include "chrome/browser/autofill/autofill_profile.h" | |
8 #include "chrome/browser/autofill/auxiliary_profile_impl_android.h" | |
9 #include "chrome/browser/autofill/auxiliary_profile_loader_mock.h" | |
10 #include "chrome/browser/autofill/i_auxiliary_profile_loader.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 namespace { | |
14 | |
15 class TestContext { | |
16 public: | |
17 TestContext() : profileLoader_(AuxiliaryProfileLoaderMock()) {} | |
18 | |
19 AutofillProfile* GetAndLoadProfile() { | |
20 AuxiliaryProfilesImpl impl(&profiles_, | |
21 (IAuxiliaryProfileLoader*)&profileLoader_); | |
22 impl.GetContactsProfile(); | |
23 AutofillProfile * profile = *profiles_.begin(); | |
David Trainor- moved to gerrit
2013/02/27 07:49:28
No space between AutofillProfile and *.
| |
24 return profile; | |
25 } | |
26 | |
27 AuxiliaryProfileLoaderMock profileLoader_; | |
28 private: | |
29 ScopedVector<AutofillProfile> profiles_; | |
30 }; | |
31 | |
32 } // namespace | |
33 | |
34 TEST(AuxiliaryProfileLoaderAndroid, SetNameInfo) { | |
35 TestContext ctx; | |
36 | |
37 string16 firstName = ASCIIToUTF16("John"); | |
38 string16 middleName = ASCIIToUTF16("H."); | |
39 string16 lastName = ASCIIToUTF16("Waston"); | |
40 | |
41 ctx.profileLoader_.SetFirstName(firstName); | |
42 ctx.profileLoader_.SetMiddleName(middleName); | |
43 ctx.profileLoader_.SetLastName(lastName); | |
44 | |
45 AutofillProfile* profile = ctx.GetAndLoadProfile(); | |
46 | |
47 EXPECT_EQ(profile->GetRawInfo(NAME_FIRST), firstName); | |
48 EXPECT_EQ(profile->GetRawInfo(NAME_MIDDLE), middleName); | |
49 EXPECT_EQ(profile->GetRawInfo(NAME_LAST), lastName); | |
50 } | |
51 | |
52 TEST(AuxiliaryProfileLoaderAndroid, SetNameInfoEmpty) { | |
53 TestContext ctx; | |
54 AutofillProfile * profile = ctx.GetAndLoadProfile(); | |
55 | |
56 EXPECT_EQ(profile->GetRawInfo(NAME_FIRST), string16()); | |
57 EXPECT_EQ(profile->GetRawInfo(NAME_MIDDLE), string16()); | |
58 EXPECT_EQ(profile->GetRawInfo(NAME_LAST), string16()); | |
59 } | |
60 | |
61 TEST(AuxiliaryProfileLoaderAndroid, SetEmailInfo) { | |
62 TestContext ctx; | |
63 | |
64 std::vector<string16> emailAddresses; | |
65 emailAddresses.push_back(ASCIIToUTF16("sherlock@holmes.com")); | |
66 emailAddresses.push_back(ASCIIToUTF16("watson@holmes.com")); | |
67 ctx.profileLoader_.SetEmailAddresses(emailAddresses); | |
68 | |
69 AutofillProfile * profile = ctx.GetAndLoadProfile(); | |
70 std::vector<string16> loadedEmailAddresses; | |
71 profile->GetRawMultiInfo(EMAIL_ADDRESS, &loadedEmailAddresses); | |
72 EXPECT_EQ(loadedEmailAddresses, emailAddresses); | |
73 } | |
74 | |
75 TEST(AuxiliaryProfileLoaderAndroid, SetEmailInfoEmpty) { | |
76 TestContext ctx; | |
77 | |
78 std::vector<string16> expectedEmailAddresses; | |
79 expectedEmailAddresses.push_back(string16()); | |
80 std::vector<string16> loadedEmailAddresses; | |
81 AutofillProfile * profile = ctx.GetAndLoadProfile(); | |
82 profile->GetRawMultiInfo(EMAIL_ADDRESS, &loadedEmailAddresses); | |
83 EXPECT_EQ(loadedEmailAddresses, expectedEmailAddresses); | |
84 } | |
85 | |
86 TEST(AuxiliaryProfileLoaderAndroid, SetPhoneInfo) { | |
87 TestContext ctx; | |
88 | |
89 std::vector<string16> phoneNumbers; | |
90 phoneNumbers.push_back(ASCIIToUTF16("6502530000")); | |
91 ctx.profileLoader_.SetPhoneNumbers(phoneNumbers); | |
92 | |
93 std::vector<string16> loadedPhoneNumbers; | |
94 AutofillProfile * profile = ctx.GetAndLoadProfile(); | |
95 profile->GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &loadedPhoneNumbers); | |
96 EXPECT_EQ(loadedPhoneNumbers, phoneNumbers); | |
97 } | |
98 | |
99 TEST(AuxiliaryProfileLoaderAndroid, SetPhoneInfoEmpty) { | |
100 TestContext ctx; | |
101 | |
102 std::vector<string16> expectedPhoneNumbers; | |
103 expectedPhoneNumbers.push_back(string16()); | |
104 | |
105 std::vector<string16> loadedPhoneNumbers; | |
106 AutofillProfile * profile = ctx.GetAndLoadProfile(); | |
107 profile->GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &loadedPhoneNumbers); | |
108 EXPECT_EQ(loadedPhoneNumbers, expectedPhoneNumbers); | |
109 } | |
110 | |
111 TEST(AuxiliaryProfileLoaderAndroid, SetAddressInfo) { | |
112 TestContext ctx; | |
113 | |
114 string16 street = ASCIIToUTF16("221 B Baker Street"); | |
115 string16 city = ASCIIToUTF16("London"); | |
116 string16 postalCode = ASCIIToUTF16("123456"); | |
117 string16 region = ASCIIToUTF16("Georgian Terrace"); | |
118 string16 country = ASCIIToUTF16("England"); | |
119 | |
120 ctx.profileLoader_.SetStreet(street); | |
121 ctx.profileLoader_.SetCity(city); | |
122 ctx.profileLoader_.SetPostalCode(postalCode); | |
123 ctx.profileLoader_.SetRegion(region); | |
124 ctx.profileLoader_.SetCountry(country); | |
125 | |
126 AutofillProfile* profile = ctx.GetAndLoadProfile(); | |
127 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE1), street); | |
128 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_CITY), city); | |
129 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_ZIP), postalCode); | |
130 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_STATE), region); | |
131 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_COUNTRY), country); | |
132 } | |
133 | |
134 /* | |
135 * Android user's profile contact does not prase its address | |
136 * into constituent parts. Instead we just Get a long string blob. | |
137 * Disable address population tests until we implement a way to parse the | |
138 * data. | |
139 * | |
140 string16 pobox = ASCIIToUTF16("222"); | |
141 string16 neighborhood = ASCIIToUTF16("Doyle"); | |
142 TEST(AuxiliaryProfileLoaderAndroid, SetAddressInfoCompoundFields1) { | |
143 TestContext ctx; | |
144 ctx.profileLoader_.SetPobox(pobox); | |
145 ctx.profileLoader_.SetNeighborhood(neighborhood); | |
146 string16 expectedLine2= ASCIIToUTF16("222, Doyle"); | |
147 AutofillProfile* profile = ctx.GetAndLoadProfile(); | |
148 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), expectedLine2); | |
149 } | |
150 | |
151 TEST(AuxiliaryProfileLoaderAndroid, SetAddressInfoCompoundFields2) { | |
152 TestContext ctx; | |
153 ctx.profileLoader_.SetPobox(pobox); | |
154 AutofillProfile* profile = ctx.GetAndLoadProfile(); | |
155 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), pobox); | |
156 } | |
157 | |
158 TEST(AuxiliaryProfileLoaderAndroid, SetAddressInfoCompoundFields3) { | |
159 TestContext ctx; | |
160 ctx.profileLoader_.SetNeighborhood(neighborhood); | |
161 AutofillProfile* profile = ctx.GetAndLoadProfile(); | |
162 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), neighborhood); | |
163 } | |
164 | |
165 TEST(AuxiliaryProfileLoaderAndroid, SetAddressInfoEmpty) { | |
166 TestContext ctx; | |
167 AutofillProfile* profile = ctx.GetAndLoadProfile(); | |
168 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE1), string16()); | |
169 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), string16()); | |
170 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_CITY), string16()); | |
171 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_ZIP), string16()); | |
172 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_STATE), string16()); | |
173 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_COUNTRY), string16()); | |
174 } | |
175 */ | |
OLD | NEW |