| 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..71240263dc81b75f748c5a690f4ced317e789aff
|
| --- /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.
|
| +
|
| +#include "base/memory/scoped_vector.h"
|
| +#include "base/string16.h"
|
| +#include "chrome/browser/autofill/autofill_profile.h"
|
| +#include "chrome/browser/autofill/auxiliary_profile_impl_android.h"
|
| +#include "chrome/browser/autofill/auxiliary_profile_loader_mock.h"
|
| +#include "chrome/browser/autofill/i_auxiliary_profile_loader.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace {
|
| +
|
| +class TestContext {
|
| + public:
|
| + TestContext() : profileLoader_(AuxiliaryProfileLoaderMock()) {}
|
| +
|
| + AutofillProfile* GetAndLoadProfile() {
|
| + AuxiliaryProfilesImpl impl(&profiles_,
|
| + (IAuxiliaryProfileLoader*)&profileLoader_);
|
| + impl.GetContactsProfile();
|
| + AutofillProfile * profile = *profiles_.begin();
|
| + return profile;
|
| + }
|
| +
|
| + AuxiliaryProfileLoaderMock profileLoader_;
|
| + private:
|
| + ScopedVector<AutofillProfile> profiles_;
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +TEST(AuxiliaryProfileLoaderAndroid, SetNameInfo) {
|
| + TestContext ctx;
|
| +
|
| + string16 firstName = ASCIIToUTF16("John");
|
| + string16 middleName = ASCIIToUTF16("H.");
|
| + string16 lastName = ASCIIToUTF16("Waston");
|
| +
|
| + ctx.profileLoader_.SetFirstName(firstName);
|
| + ctx.profileLoader_.SetMiddleName(middleName);
|
| + ctx.profileLoader_.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(AuxiliaryProfileLoaderAndroid, 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(AuxiliaryProfileLoaderAndroid, SetEmailInfo) {
|
| + TestContext ctx;
|
| +
|
| + std::vector<string16> emailAddresses;
|
| + emailAddresses.push_back(ASCIIToUTF16("sherlock@holmes.com"));
|
| + emailAddresses.push_back(ASCIIToUTF16("watson@holmes.com"));
|
| + ctx.profileLoader_.SetEmailAddresses(emailAddresses);
|
| +
|
| + AutofillProfile * profile = ctx.GetAndLoadProfile();
|
| + std::vector<string16> loadedEmailAddresses;
|
| + profile->GetRawMultiInfo(EMAIL_ADDRESS, &loadedEmailAddresses);
|
| + EXPECT_EQ(loadedEmailAddresses, emailAddresses);
|
| +}
|
| +
|
| +TEST(AuxiliaryProfileLoaderAndroid, 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(AuxiliaryProfileLoaderAndroid, SetPhoneInfo) {
|
| + TestContext ctx;
|
| +
|
| + std::vector<string16> phoneNumbers;
|
| + phoneNumbers.push_back(ASCIIToUTF16("6502530000"));
|
| + ctx.profileLoader_.SetPhoneNumbers(phoneNumbers);
|
| +
|
| + std::vector<string16> loadedPhoneNumbers;
|
| + AutofillProfile * profile = ctx.GetAndLoadProfile();
|
| + profile->GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &loadedPhoneNumbers);
|
| + EXPECT_EQ(loadedPhoneNumbers, phoneNumbers);
|
| +}
|
| +
|
| +TEST(AuxiliaryProfileLoaderAndroid, 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(AuxiliaryProfileLoaderAndroid, 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.profileLoader_.SetStreet(street);
|
| + ctx.profileLoader_.SetCity(city);
|
| + ctx.profileLoader_.SetPostalCode(postalCode);
|
| + ctx.profileLoader_.SetRegion(region);
|
| + ctx.profileLoader_.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(AuxiliaryProfileLoaderAndroid, SetAddressInfoCompoundFields1) {
|
| + TestContext ctx;
|
| + ctx.profileLoader_.SetPobox(pobox);
|
| + ctx.profileLoader_.SetNeighborhood(neighborhood);
|
| + string16 expectedLine2= ASCIIToUTF16("222, Doyle");
|
| + AutofillProfile* profile = ctx.GetAndLoadProfile();
|
| + EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), expectedLine2);
|
| +}
|
| +
|
| +TEST(AuxiliaryProfileLoaderAndroid, SetAddressInfoCompoundFields2) {
|
| + TestContext ctx;
|
| + ctx.profileLoader_.SetPobox(pobox);
|
| + AutofillProfile* profile = ctx.GetAndLoadProfile();
|
| + EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), pobox);
|
| +}
|
| +
|
| +TEST(AuxiliaryProfileLoaderAndroid, SetAddressInfoCompoundFields3) {
|
| + TestContext ctx;
|
| + ctx.profileLoader_.SetNeighborhood(neighborhood);
|
| + AutofillProfile* profile = ctx.GetAndLoadProfile();
|
| + EXPECT_EQ(profile->GetRawInfo(ADDRESS_HOME_LINE2), neighborhood);
|
| +}
|
| +
|
| +TEST(AuxiliaryProfileLoaderAndroid, 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());
|
| +}
|
| +*/
|
|
|