Index: chrome/browser/autofill/auxiliary_profile_impl_unittest.cc |
diff --git a/chrome/browser/autofill/auxiliary_profile_impl_unittest.cc b/chrome/browser/autofill/auxiliary_profile_impl_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..224f9c71d752a45bf7e8f2b0c0b73e61d558ef26 |
--- /dev/null |
+++ b/chrome/browser/autofill/auxiliary_profile_impl_unittest.cc |
@@ -0,0 +1,175 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// 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.
|
+ |
+#include "base/memory/scoped_vector.h" |
+#include "base/string16.h" |
+#include "chrome/browser/autofill/autofill_profile.h" |
+#include "chrome/browser/autofill/auxiliary_profile_loader.h" |
+#include "chrome/browser/autofill/auxiliary_profile_loader_mock.h" |
+#include "chrome/browser/autofill/auxiliary_profiles_android.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace { |
+ |
+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.
|
+ public: |
+ TestContext() : profile_loader_(AuxiliaryProfileLoaderMock()) {} |
+ |
+ AutofillProfile* GetAndLoadProfile() { |
+ AuxiliaryProfilesAndroid impl(&profiles_, |
+ (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.
|
+ impl.GetContactsProfile(); |
+ AutofillProfile* profile = *profiles_.begin(); |
+ return profile; |
+ } |
+ |
+ 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.
|
+ private: |
+ ScopedVector<AutofillProfile> profiles_; |
+}; |
+ |
+} // namespace |
+ |
+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.
|
+ TestContext ctx; |
+ |
+ string16 firstName = ASCIIToUTF16("John"); |
+ string16 middleName = ASCIIToUTF16("H."); |
+ string16 lastName = ASCIIToUTF16("Waston"); |
+ |
+ ctx.profile_loader_.SetFirstName(firstName); |
+ ctx.profile_loader_.SetMiddleName(middleName); |
+ ctx.profile_loader_.SetLastName(lastName); |
+ |
+ AutofillProfile* profile = ctx.GetAndLoadProfile(); |
+ |
+ EXPECT_EQ(profile->GetRawInfo(NAME_FIRST), firstName); |
+ EXPECT_EQ(profile->GetRawInfo(NAME_MIDDLE), middleName); |
+ EXPECT_EQ(profile->GetRawInfo(NAME_LAST), lastName); |
+} |
+ |
+TEST(AuxiliaryProfilesAndroid, SetNameInfoEmpty) { |
+ TestContext ctx; |
+ AutofillProfile * profile = ctx.GetAndLoadProfile(); |
+ |
+ EXPECT_EQ(profile->GetRawInfo(NAME_FIRST), string16()); |
+ EXPECT_EQ(profile->GetRawInfo(NAME_MIDDLE), string16()); |
+ EXPECT_EQ(profile->GetRawInfo(NAME_LAST), string16()); |
+} |
+ |
+TEST(AuxiliaryProfilesAndroid, SetEmailInfo) { |
+ TestContext ctx; |
+ |
+ std::vector<string16> emailAddresses; |
+ emailAddresses.push_back(ASCIIToUTF16("sherlock@holmes.com")); |
+ emailAddresses.push_back(ASCIIToUTF16("watson@holmes.com")); |
+ ctx.profile_loader_.SetEmailAddresses(emailAddresses); |
+ |
+ AutofillProfile * profile = ctx.GetAndLoadProfile(); |
+ std::vector<string16> loadedEmailAddresses; |
+ profile->GetRawMultiInfo(EMAIL_ADDRESS, &loadedEmailAddresses); |
+ EXPECT_EQ(loadedEmailAddresses, emailAddresses); |
+} |
+ |
+TEST(AuxiliaryProfilesAndroid, SetEmailInfoEmpty) { |
+ TestContext ctx; |
+ |
+ std::vector<string16> expectedEmailAddresses; |
+ expectedEmailAddresses.push_back(string16()); |
+ std::vector<string16> loadedEmailAddresses; |
+ AutofillProfile * profile = ctx.GetAndLoadProfile(); |
+ profile->GetRawMultiInfo(EMAIL_ADDRESS, &loadedEmailAddresses); |
+ EXPECT_EQ(loadedEmailAddresses, expectedEmailAddresses); |
+} |
+ |
+TEST(AuxiliaryProfilesAndroid, SetPhoneInfo) { |
+ TestContext ctx; |
+ |
+ std::vector<string16> phoneNumbers; |
+ phoneNumbers.push_back(ASCIIToUTF16("6502530000")); |
+ ctx.profile_loader_.SetPhoneNumbers(phoneNumbers); |
+ |
+ std::vector<string16> loadedPhoneNumbers; |
+ AutofillProfile * profile = ctx.GetAndLoadProfile(); |
+ profile->GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &loadedPhoneNumbers); |
+ EXPECT_EQ(loadedPhoneNumbers, phoneNumbers); |
+} |
+ |
+TEST(AuxiliaryProfilesAndroid, SetPhoneInfoEmpty) { |
+ TestContext ctx; |
+ |
+ std::vector<string16> expectedPhoneNumbers; |
+ expectedPhoneNumbers.push_back(string16()); |
+ |
+ std::vector<string16> loadedPhoneNumbers; |
+ AutofillProfile * profile = ctx.GetAndLoadProfile(); |
+ profile->GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &loadedPhoneNumbers); |
+ EXPECT_EQ(loadedPhoneNumbers, expectedPhoneNumbers); |
+} |
+ |
+TEST(AuxiliaryProfilesAndroid, SetAddressInfo) { |
+ TestContext ctx; |
+ |
+ string16 street = ASCIIToUTF16("221 B Baker Street"); |
+ string16 city = ASCIIToUTF16("London"); |
+ string16 postalCode = ASCIIToUTF16("123456"); |
+ string16 region = ASCIIToUTF16("Georgian Terrace"); |
+ string16 country = ASCIIToUTF16("England"); |
+ |
+ ctx.profile_loader_.SetStreet(street); |
+ ctx.profile_loader_.SetCity(city); |
+ ctx.profile_loader_.SetPostalCode(postalCode); |
+ ctx.profile_loader_.SetRegion(region); |
+ ctx.profile_loader_.SetCountry(country); |
+ |
+ AutofillProfile* profile = ctx.GetAndLoadProfile(); |
+ EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE1), street); |
+ EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_CITY), city); |
+ EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_ZIP), postalCode); |
+ EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_STATE), region); |
+ EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_COUNTRY), country); |
+} |
+ |
+/* |
+ * Android user's profile contact does not prase its address |
+ * into constituent parts. Instead we just Get a long string blob. |
+ * Disable address population tests until we implement a way to parse the |
+ * data. |
+ * |
+string16 pobox = ASCIIToUTF16("222"); |
+string16 neighborhood = ASCIIToUTF16("Doyle"); |
+TEST(AuxiliaryProfilesAndroid, SetAddressInfoCompoundFields1) { |
+ TestContext ctx; |
+ ctx.profile_loader_.SetPobox(pobox); |
+ ctx.profile_loader_.SetNeighborhood(neighborhood); |
+ string16 expectedLine2= ASCIIToUTF16("222, Doyle"); |
+ AutofillProfile* profile = ctx.GetAndLoadProfile(); |
+ EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), expectedLine2); |
+} |
+ |
+TEST(AuxiliaryProfilesAndroid, SetAddressInfoCompoundFields2) { |
+ TestContext ctx; |
+ ctx.profile_loader_.SetPobox(pobox); |
+ AutofillProfile* profile = ctx.GetAndLoadProfile(); |
+ EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), pobox); |
+} |
+ |
+TEST(AuxiliaryProfilesAndroid, SetAddressInfoCompoundFields3) { |
+ TestContext ctx; |
+ ctx.profile_loader_.SetNeighborhood(neighborhood); |
+ AutofillProfile* profile = ctx.GetAndLoadProfile(); |
+ EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), neighborhood); |
+} |
+ |
+TEST(AuxiliaryProfilesAndroid, SetAddressInfoEmpty) { |
+ TestContext ctx; |
+ AutofillProfile* profile = ctx.GetAndLoadProfile(); |
+ EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE1), string16()); |
+ EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), string16()); |
+ EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_CITY), string16()); |
+ EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_ZIP), string16()); |
+ EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_STATE), string16()); |
+ EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_COUNTRY), string16()); |
+} |
+*/ |