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