Chromium Code Reviews| 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. | |
|
Ilya Sherman
2013/03/01 01:55:04
This file should probably be named "auxiliary_prof
apiccion
2013/03/02 03:37:01
Done.
| |
| 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_loader.h" | |
| 9 #include "chrome/browser/autofill/auxiliary_profile_loader_mock.h" | |
| 10 #include "chrome/browser/autofill/auxiliary_profiles_android.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 class TestContext { | |
|
Yaron
2013/02/28 20:40:43
I think it's more common to instead subclass testi
apiccion
2013/03/01 01:04:34
Done.
| |
| 16 public: | |
| 17 TestContext() : profile_loader_(AuxiliaryProfileLoaderMock()) {} | |
| 18 | |
| 19 AutofillProfile* GetAndLoadProfile() { | |
| 20 AuxiliaryProfilesAndroid impl(&profiles_, | |
| 21 (AuxiliaryProfileLoader*)&profile_loader_); | |
|
Ilya Sherman
2013/03/01 01:55:04
nit: Indentation is off here.
Ilya Sherman
2013/03/01 01:55:04
nit: Always prefer static_cast<> to C-style casts.
apiccion
2013/03/02 03:37:01
Done.
| |
| 22 impl.GetContactsProfile(); | |
| 23 AutofillProfile* profile = *profiles_.begin(); | |
| 24 return profile; | |
| 25 } | |
| 26 | |
| 27 AuxiliaryProfileLoaderMock profile_loader_; | |
|
Ilya Sherman
2013/03/01 01:55:04
Member variables should never be public.
apiccion
2013/03/02 03:37:01
Done.
| |
| 28 private: | |
| 29 ScopedVector<AutofillProfile> profiles_; | |
| 30 }; | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 34 TEST(AuxiliaryProfilesAndroid, SetNameInfo) { | |
|
Yaron
2013/02/28 20:40:43
Is this Android specific code? If so, it needs and
apiccion
2013/03/01 01:04:34
Done.
| |
| 35 TestContext ctx; | |
| 36 | |
| 37 string16 firstName = ASCIIToUTF16("John"); | |
| 38 string16 middleName = ASCIIToUTF16("H."); | |
| 39 string16 lastName = ASCIIToUTF16("Waston"); | |
| 40 | |
| 41 ctx.profile_loader_.SetFirstName(firstName); | |
| 42 ctx.profile_loader_.SetMiddleName(middleName); | |
| 43 ctx.profile_loader_.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(AuxiliaryProfilesAndroid, 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(AuxiliaryProfilesAndroid, 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.profile_loader_.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(AuxiliaryProfilesAndroid, 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(AuxiliaryProfilesAndroid, SetPhoneInfo) { | |
| 87 TestContext ctx; | |
| 88 | |
| 89 std::vector<string16> phoneNumbers; | |
| 90 phoneNumbers.push_back(ASCIIToUTF16("6502530000")); | |
| 91 ctx.profile_loader_.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(AuxiliaryProfilesAndroid, 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(AuxiliaryProfilesAndroid, 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.profile_loader_.SetStreet(street); | |
| 121 ctx.profile_loader_.SetCity(city); | |
| 122 ctx.profile_loader_.SetPostalCode(postalCode); | |
| 123 ctx.profile_loader_.SetRegion(region); | |
| 124 ctx.profile_loader_.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(AuxiliaryProfilesAndroid, SetAddressInfoCompoundFields1) { | |
| 143 TestContext ctx; | |
| 144 ctx.profile_loader_.SetPobox(pobox); | |
| 145 ctx.profile_loader_.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(AuxiliaryProfilesAndroid, SetAddressInfoCompoundFields2) { | |
| 152 TestContext ctx; | |
| 153 ctx.profile_loader_.SetPobox(pobox); | |
| 154 AutofillProfile* profile = ctx.GetAndLoadProfile(); | |
| 155 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), pobox); | |
| 156 } | |
| 157 | |
| 158 TEST(AuxiliaryProfilesAndroid, SetAddressInfoCompoundFields3) { | |
| 159 TestContext ctx; | |
| 160 ctx.profile_loader_.SetNeighborhood(neighborhood); | |
| 161 AutofillProfile* profile = ctx.GetAndLoadProfile(); | |
| 162 EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), neighborhood); | |
| 163 } | |
| 164 | |
| 165 TEST(AuxiliaryProfilesAndroid, 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 |