Commit 2bae5aad authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] add company, email and phone to manual fallback addresses

Bug: 907873
Change-Id: I45f4723dd2e999175c4fc0d5168275a17fb3eaf4
Reviewed-on: https://chromium-review.googlesource.com/c/1348113
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610799}
parent 72e96bdf
......@@ -19,6 +19,9 @@
// The addressee's last name.
@property(nonatomic, readonly) NSString* lastName;
// The company name.
@property(nonatomic, readonly) NSString* company;
// The first line of this address.
@property(nonatomic, readonly) NSString* line1;
......@@ -37,16 +40,26 @@
// The country of the address.
@property(nonatomic, readonly) NSString* country;
// The home phone number.
@property(nonatomic, readonly) NSString* phoneNumber;
// The profile email address.
@property(nonatomic, readonly) NSString* emailAddress;
// Default init.
- (instancetype)initWithFirstName:(NSString*)firstName
middleNameOrInitial:(NSString*)middleNameOrInitial
lastName:(NSString*)lastName
company:(NSString*)company
line1:(NSString*)line1
line2:(NSString*)line2
zip:(NSString*)zip
city:(NSString*)city
state:(NSString*)state
country:(NSString*)country NS_DESIGNATED_INITIALIZER;
country:(NSString*)country
phoneNumber:(NSString*)phoneNumber
emailAddress:(NSString*)emailAddress
NS_DESIGNATED_INITIALIZER;
// Unavailable. Please use |initWithFirstName:middleNameOrInitial:lastName:
// line1:line2:zip:city:state:country:|.
......
......@@ -13,23 +13,29 @@
- (instancetype)initWithFirstName:(NSString*)firstName
middleNameOrInitial:(NSString*)middleNameOrInitial
lastName:(NSString*)lastName
company:(NSString*)company
line1:(NSString*)line1
line2:(NSString*)line2
zip:(NSString*)zip
city:(NSString*)city
state:(NSString*)state
country:(NSString*)country {
country:(NSString*)country
phoneNumber:(NSString*)phoneNumber
emailAddress:(NSString*)emailAddress {
self = [super init];
if (self) {
_firstName = [firstName copy];
_middleNameOrInitial = [middleNameOrInitial copy];
_lastName = [lastName copy];
_company = [company copy];
_line1 = [line1 copy];
_line2 = [line2 copy];
_zip = [zip copy];
_city = [city copy];
_state = [state copy];
_country = [country copy];
_phoneNumber = [phoneNumber copy];
_emailAddress = [emailAddress copy];
}
return self;
}
......@@ -54,6 +60,9 @@
if (![otherObject.lastName isEqual:self.lastName]) {
return NO;
}
if (![otherObject.company isEqual:self.company]) {
return NO;
}
if (![otherObject.line1 isEqual:self.line1]) {
return NO;
}
......@@ -72,25 +81,33 @@
if (![otherObject.country isEqual:self.country]) {
return NO;
}
if (![otherObject.phoneNumber isEqual:self.phoneNumber]) {
return NO;
}
if (![otherObject.emailAddress isEqual:self.emailAddress]) {
return NO;
}
return YES;
}
- (NSUInteger)hash {
return [self.firstName hash] ^ [self.middleNameOrInitial hash] ^
[self.lastName hash] ^ [self.line1 hash] ^ [self.line2 hash] ^
[self.zip hash] ^ [self.city hash] ^ [self.state hash] ^
[self.country hash];
[self.lastName hash] ^ [self.company hash] ^ [self.line1 hash] ^
[self.line2 hash] ^ [self.zip hash] ^ [self.city hash] ^
[self.state hash] ^ [self.country hash] ^ [self.phoneNumber hash] ^
[self.emailAddress hash];
}
- (NSString*)description {
return
[NSString stringWithFormat:
@"<%@ (%p): firstName: %@, middleNameOrInitial: %@, "
@"lastName: %@, line1: %@, "
@"line2: %@, zip: %@, city: %@, state: %@, country: %@>",
NSStringFromClass([self class]), self, self.firstName,
self.middleNameOrInitial, self.lastName, self.line1,
self.line2, self.zip, self.city, self.state, self.country];
return [NSString
stringWithFormat:@"<%@ (%p): firstName: %@, middleNameOrInitial: %@, "
@"lastName: %@, company: %@, line1: %@, "
@"line2: %@, zip: %@, city: %@, state: %@, country: %@, "
@"phoneNumber: %@, emailAddress: %@>",
NSStringFromClass([self class]), self, self.firstName,
self.middleNameOrInitial, self.lastName, self.company,
self.line1, self.line2, self.zip, self.city, self.state,
self.country, self.phoneNumber, self.emailAddress];
}
@end
......@@ -39,6 +39,8 @@ NSString* FieldValueOfTypeOnProfile(const autofill::AutofillProfile& profile,
FieldValueOfTypeOnProfile(profile, autofill::NAME_MIDDLE_INITIAL);
}
NSString* lastName = FieldValueOfTypeOnProfile(profile, autofill::NAME_LAST);
NSString* company =
FieldValueOfTypeOnProfile(profile, autofill::COMPANY_NAME);
NSString* line1 =
FieldValueOfTypeOnProfile(profile, autofill::ADDRESS_HOME_LINE1);
NSString* line2 =
......@@ -51,16 +53,23 @@ NSString* FieldValueOfTypeOnProfile(const autofill::AutofillProfile& profile,
FieldValueOfTypeOnProfile(profile, autofill::ADDRESS_HOME_STATE);
NSString* country =
FieldValueOfTypeOnProfile(profile, autofill::ADDRESS_HOME_COUNTRY);
NSString* phoneNumber =
FieldValueOfTypeOnProfile(profile, autofill::PHONE_HOME_WHOLE_NUMBER);
NSString* emailAddress =
FieldValueOfTypeOnProfile(profile, autofill::EMAIL_ADDRESS);
return [self initWithFirstName:firstName
middleNameOrInitial:middleNameOrInitial
lastName:lastName
company:company
line1:line1
line2:line2
zip:zip
city:city
state:state
country:country];
country:country
phoneNumber:phoneNumber
emailAddress:emailAddress];
}
+ (NSArray<ManualFillAddress*>*)manualFillAddressesFromProfiles:
......
......@@ -37,12 +37,15 @@ TEST_F(ManualFillAddressFormAutofilliOSTest, CreationWithMiddleName) {
NSString* firstName = @"First";
NSString* middleName = @"Middle";
NSString* lastName = @"Last";
NSString* company = @"Google";
NSString* line1 = @"10 Main Street";
NSString* line2 = @"Appt 16";
NSString* zip = @"12345";
NSString* city = @"Springfield";
NSString* state = @"State";
NSString* country = @"US";
NSString* phoneNumber = @"123-456-789";
NSString* emailAddress = @"john@doe";
autofill::CountryNames::SetLocaleString("en-US");
......@@ -50,12 +53,16 @@ TEST_F(ManualFillAddressFormAutofilliOSTest, CreationWithMiddleName) {
SetProfileFieldTypeValue(profile, autofill::NAME_FIRST, firstName);
SetProfileFieldTypeValue(profile, autofill::NAME_MIDDLE, middleName);
SetProfileFieldTypeValue(profile, autofill::NAME_LAST, lastName);
SetProfileFieldTypeValue(profile, autofill::COMPANY_NAME, company);
SetProfileFieldTypeValue(profile, autofill::ADDRESS_HOME_LINE1, line1);
SetProfileFieldTypeValue(profile, autofill::ADDRESS_HOME_LINE2, line2);
SetProfileFieldTypeValue(profile, autofill::ADDRESS_HOME_ZIP, zip);
SetProfileFieldTypeValue(profile, autofill::ADDRESS_HOME_CITY, city);
SetProfileFieldTypeValue(profile, autofill::ADDRESS_HOME_STATE, state);
SetProfileFieldTypeValue(profile, autofill::ADDRESS_HOME_COUNTRY, country);
SetProfileFieldTypeValue(profile, autofill::PHONE_HOME_WHOLE_NUMBER,
phoneNumber);
SetProfileFieldTypeValue(profile, autofill::EMAIL_ADDRESS, emailAddress);
ManualFillAddress* manualFillAddress =
[[ManualFillAddress alloc] initWithProfile:*profile];
......@@ -65,12 +72,15 @@ TEST_F(ManualFillAddressFormAutofilliOSTest, CreationWithMiddleName) {
EXPECT_TRUE(
[middleName isEqualToString:manualFillAddress.middleNameOrInitial]);
EXPECT_TRUE([lastName isEqualToString:manualFillAddress.lastName]);
EXPECT_TRUE([company isEqualToString:manualFillAddress.company]);
EXPECT_TRUE([line1 isEqualToString:manualFillAddress.line1]);
EXPECT_TRUE([line2 isEqualToString:manualFillAddress.line2]);
EXPECT_TRUE([zip isEqualToString:manualFillAddress.zip]);
EXPECT_TRUE([city isEqualToString:manualFillAddress.city]);
EXPECT_TRUE([state isEqualToString:manualFillAddress.state]);
EXPECT_TRUE([@"United States" isEqualToString:manualFillAddress.country]);
EXPECT_TRUE([phoneNumber isEqualToString:manualFillAddress.phoneNumber]);
EXPECT_TRUE([emailAddress isEqualToString:manualFillAddress.emailAddress]);
}
// Tests the creation of an address from an autofill::AutofillProfile.
......@@ -78,12 +88,15 @@ TEST_F(ManualFillAddressFormAutofilliOSTest, CreationWithMiddleInitial) {
NSString* firstName = @"First";
NSString* middleInitial = @"M";
NSString* lastName = @"Last";
NSString* company = @"Google";
NSString* line1 = @"10 Main Street";
NSString* line2 = @"Appt 16";
NSString* zip = @"12345";
NSString* city = @"Springfield";
NSString* state = @"State";
NSString* country = @"US";
NSString* phoneNumber = @"123-456-789";
NSString* emailAddress = @"john@doe";
autofill::CountryNames::SetLocaleString("en-US");
......@@ -92,12 +105,16 @@ TEST_F(ManualFillAddressFormAutofilliOSTest, CreationWithMiddleInitial) {
SetProfileFieldTypeValue(profile, autofill::NAME_MIDDLE_INITIAL,
middleInitial);
SetProfileFieldTypeValue(profile, autofill::NAME_LAST, lastName);
SetProfileFieldTypeValue(profile, autofill::COMPANY_NAME, company);
SetProfileFieldTypeValue(profile, autofill::ADDRESS_HOME_LINE1, line1);
SetProfileFieldTypeValue(profile, autofill::ADDRESS_HOME_LINE2, line2);
SetProfileFieldTypeValue(profile, autofill::ADDRESS_HOME_ZIP, zip);
SetProfileFieldTypeValue(profile, autofill::ADDRESS_HOME_CITY, city);
SetProfileFieldTypeValue(profile, autofill::ADDRESS_HOME_STATE, state);
SetProfileFieldTypeValue(profile, autofill::ADDRESS_HOME_COUNTRY, country);
SetProfileFieldTypeValue(profile, autofill::PHONE_HOME_WHOLE_NUMBER,
phoneNumber);
SetProfileFieldTypeValue(profile, autofill::EMAIL_ADDRESS, emailAddress);
ManualFillAddress* manualFillAddress =
[[ManualFillAddress alloc] initWithProfile:*profile];
......@@ -107,10 +124,13 @@ TEST_F(ManualFillAddressFormAutofilliOSTest, CreationWithMiddleInitial) {
EXPECT_TRUE(
[middleInitial isEqualToString:manualFillAddress.middleNameOrInitial]);
EXPECT_TRUE([lastName isEqualToString:manualFillAddress.lastName]);
EXPECT_TRUE([company isEqualToString:manualFillAddress.company]);
EXPECT_TRUE([line1 isEqualToString:manualFillAddress.line1]);
EXPECT_TRUE([line2 isEqualToString:manualFillAddress.line2]);
EXPECT_TRUE([zip isEqualToString:manualFillAddress.zip]);
EXPECT_TRUE([city isEqualToString:manualFillAddress.city]);
EXPECT_TRUE([state isEqualToString:manualFillAddress.state]);
EXPECT_TRUE([@"United States" isEqualToString:manualFillAddress.country]);
EXPECT_TRUE([phoneNumber isEqualToString:manualFillAddress.phoneNumber]);
EXPECT_TRUE([emailAddress isEqualToString:manualFillAddress.emailAddress]);
}
......@@ -86,6 +86,9 @@ static const CGFloat SideMargins = 16;
// A button showing the address associated last name.
@property(nonatomic, strong) UIButton* lastNameButton;
// A button showing the company name.
@property(nonatomic, strong) UIButton* companyButton;
// A button showing the address line 1.
@property(nonatomic, strong) UIButton* line1Button;
......@@ -110,6 +113,12 @@ static const CGFloat SideMargins = 16;
// A button showing country.
@property(nonatomic, strong) UIButton* countryButton;
// A button showing a phone number.
@property(nonatomic, strong) UIButton* phoneNumberButton;
// A button showing an email address.
@property(nonatomic, strong) UIButton* emailAddressButton;
// The content delegate for this item.
@property(nonatomic, weak) id<ManualFillContentDelegate> delegate;
......@@ -134,13 +143,15 @@ static const CGFloat SideMargins = 16;
[self.firstNameButton setTitle:@"" forState:UIControlStateNormal];
[self.middleNameButton setTitle:@"" forState:UIControlStateNormal];
[self.lastNameButton setTitle:@"" forState:UIControlStateNormal];
[self.companyButton setTitle:@"" forState:UIControlStateNormal];
[self.line1Button setTitle:@"" forState:UIControlStateNormal];
[self.line2Button setTitle:@"" forState:UIControlStateNormal];
[self.zipButton setTitle:@"" forState:UIControlStateNormal];
[self.cityButton setTitle:@"" forState:UIControlStateNormal];
[self.stateButton setTitle:@"" forState:UIControlStateNormal];
[self.countryButton setTitle:@"" forState:UIControlStateNormal];
[self.line2Button setTitle:@"" forState:UIControlStateNormal];
[self.phoneNumberButton setTitle:@"" forState:UIControlStateNormal];
[self.emailAddressButton setTitle:@"" forState:UIControlStateNormal];
self.delegate = nil;
}
......@@ -234,6 +245,15 @@ static const CGFloat SideMargins = 16;
[verticalLeadViews addObject:nameLineViews.firstObject];
}
// Company line.
if (address.company.length) {
[self.companyButton setTitle:address.company forState:UIControlStateNormal];
[verticalLeadViews addObject:self.companyButton];
self.companyButton.hidden = NO;
} else {
self.companyButton.hidden = YES;
}
// Address line 1.
if (address.line1.length) {
[self.line1Button setTitle:address.line1 forState:UIControlStateNormal];
......@@ -318,6 +338,24 @@ static const CGFloat SideMargins = 16;
[verticalLeadViews addObject:stateCountryLineViews.firstObject];
}
if (address.phoneNumber.length) {
[self.phoneNumberButton setTitle:address.phoneNumber
forState:UIControlStateNormal];
[verticalLeadViews addObject:self.phoneNumberButton];
self.phoneNumberButton.hidden = NO;
} else {
self.phoneNumberButton.hidden = YES;
}
if (address.emailAddress.length) {
[self.emailAddressButton setTitle:address.emailAddress
forState:UIControlStateNormal];
[verticalLeadViews addObject:self.emailAddressButton];
self.emailAddressButton.hidden = NO;
} else {
self.emailAddressButton.hidden = YES;
}
self.verticalConstraints = VerticalConstraintsSpacingForViewsInContainer(
verticalLeadViews, self.contentView);
}
......@@ -367,6 +405,12 @@ static const CGFloat SideMargins = 16;
],
self.firstNameButton);
self.companyButton = CreateButtonWithSelectorAndTarget(
@selector(userDidTapAddressInfo:), self);
[self.contentView addSubview:self.companyButton];
HorizontalConstraintsForViewsOnGuideWithShift(@[ self.companyButton ], guide,
0);
self.line1Button = CreateButtonWithSelectorAndTarget(
@selector(userDidTapAddressInfo:), self);
[self.contentView addSubview:self.line1Button];
......@@ -409,6 +453,18 @@ static const CGFloat SideMargins = 16;
SyncBaselinesForViewsOnView(
@[ self.countrySeparatorLabel, self.countryButton ], self.stateButton);
self.phoneNumberButton = CreateButtonWithSelectorAndTarget(
@selector(userDidTapAddressInfo:), self);
[self.contentView addSubview:self.phoneNumberButton];
HorizontalConstraintsForViewsOnGuideWithShift(@[ self.phoneNumberButton ],
guide, 0);
self.emailAddressButton = CreateButtonWithSelectorAndTarget(
@selector(userDidTapAddressInfo:), self);
[self.contentView addSubview:self.emailAddressButton];
HorizontalConstraintsForViewsOnGuideWithShift(@[ self.emailAddressButton ],
guide, 0);
self.nameLineConstraints = @[];
self.zipCityLineConstraints = @[];
self.stateCountryLineConstraints = @[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment