Commit 782db57a authored by Viktor Semeniuk's avatar Viktor Semeniuk Committed by Commit Bot

[iOS][Passwords] Showing "signed in with" for federation credential

This change adds "Signed in with" row for federation credential on the
Password Details screen.

Bug: 1137807
Change-Id: Ie9e6d8b78eef253098111904306fbffe4262f897
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2467937
Commit-Queue: Viktor Semeniuk <vsemeniuk@google.com>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821660}
parent 8ae44865
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
// Associated username. // Associated username.
@property(nonatomic, copy) NSString* username; @property(nonatomic, copy) NSString* username;
// The federation providing this credential, if any.
@property(nonatomic, copy, readonly) NSString* federation;
// Associated password. // Associated password.
@property(nonatomic, copy) NSString* password; @property(nonatomic, copy) NSString* password;
......
...@@ -39,7 +39,12 @@ ...@@ -39,7 +39,12 @@
_changePasswordURL = password_manager::CreateChangePasswordUrl(form.url); _changePasswordURL = password_manager::CreateChangePasswordUrl(form.url);
} }
_username = base::SysUTF16ToNSString(form.username_value); _username = base::SysUTF16ToNSString(form.username_value);
_password = base::SysUTF16ToNSString(form.password_value);
if (form.federation_origin.opaque()) {
_password = base::SysUTF16ToNSString(form.password_value);
} else {
_federation = base::SysUTF8ToNSString(form.federation_origin.host());
}
} }
return self; return self;
} }
......
...@@ -58,6 +58,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -58,6 +58,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeWebsite = kItemTypeEnumZero, ItemTypeWebsite = kItemTypeEnumZero,
ItemTypeUsername, ItemTypeUsername,
ItemTypePassword, ItemTypePassword,
ItemTypeFederation,
ItemTypeChangePasswordButton, ItemTypeChangePasswordButton,
ItemTypeChangePasswordRecommendation, ItemTypeChangePasswordRecommendation,
}; };
...@@ -178,6 +179,9 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) { ...@@ -178,6 +179,9 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) {
[model addItem:[self changePasswordRecommendationItem] [model addItem:[self changePasswordRecommendationItem]
toSectionWithIdentifier:SectionIdentifierCompromisedInfo]; toSectionWithIdentifier:SectionIdentifierCompromisedInfo];
} }
} else if ([self.password.federation length]) {
[model addItem:[self federationItem]
toSectionWithIdentifier:SectionIdentifierPassword];
} }
} }
...@@ -243,6 +247,17 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) { ...@@ -243,6 +247,17 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) {
return item; return item;
} }
- (TableViewTextEditItem*)federationItem {
TableViewTextEditItem* item =
[[TableViewTextEditItem alloc] initWithType:ItemTypeFederation];
item.textFieldName =
l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_FEDERATION);
item.textFieldValue = self.password.federation;
item.textFieldEnabled = NO;
item.hideIcon = YES;
return item;
}
- (TableViewTextItem*)changePasswordItem { - (TableViewTextItem*)changePasswordItem {
TableViewTextItem* item = TableViewTextItem* item =
[[TableViewTextItem alloc] initWithType:ItemTypeChangePasswordButton]; [[TableViewTextItem alloc] initWithType:ItemTypeChangePasswordButton];
...@@ -270,6 +285,7 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) { ...@@ -270,6 +285,7 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) {
NSInteger itemType = [model itemTypeForIndexPath:indexPath]; NSInteger itemType = [model itemTypeForIndexPath:indexPath];
switch (itemType) { switch (itemType) {
case ItemTypeWebsite: case ItemTypeWebsite:
case ItemTypeFederation:
[self ensureContextMenuShownForItemType:itemType [self ensureContextMenuShownForItemType:itemType
tableView:tableView tableView:tableView
atIndexPath:indexPath]; atIndexPath:indexPath];
...@@ -388,6 +404,7 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) { ...@@ -388,6 +404,7 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) {
cell.selectionStyle = UITableViewCellSelectionStyleDefault; cell.selectionStyle = UITableViewCellSelectionStyleDefault;
break; break;
case ItemTypeWebsite: case ItemTypeWebsite:
case ItemTypeFederation:
case ItemTypeChangePasswordRecommendation: case ItemTypeChangePasswordRecommendation:
break; break;
} }
...@@ -399,6 +416,7 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) { ...@@ -399,6 +416,7 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) {
NSInteger itemType = [self.tableViewModel itemTypeForIndexPath:indexPath]; NSInteger itemType = [self.tableViewModel itemTypeForIndexPath:indexPath];
switch (itemType) { switch (itemType) {
case ItemTypeWebsite: case ItemTypeWebsite:
case ItemTypeFederation:
return NO; return NO;
case ItemTypeUsername: case ItemTypeUsername:
return base::FeatureList::IsEnabled( return base::FeatureList::IsEnabled(
...@@ -596,6 +614,7 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) { ...@@ -596,6 +614,7 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) {
case ItemTypePassword: case ItemTypePassword:
return YES; return YES;
case ItemTypeWebsite: case ItemTypeWebsite:
case ItemTypeFederation:
case ItemTypeChangePasswordButton: case ItemTypeChangePasswordButton:
case ItemTypeChangePasswordRecommendation: case ItemTypeChangePasswordRecommendation:
return NO; return NO;
...@@ -704,6 +723,9 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) { ...@@ -704,6 +723,9 @@ typedef NS_ENUM(NSInteger, ReauthenticationReason) {
message = message =
l10n_util::GetNSString(IDS_IOS_SETTINGS_USERNAME_WAS_COPIED_MESSAGE); l10n_util::GetNSString(IDS_IOS_SETTINGS_USERNAME_WAS_COPIED_MESSAGE);
break; break;
case ItemTypeFederation:
generalPasteboard.string = self.password.federation;
return;
case ItemTypePassword: case ItemTypePassword:
[self attemptToShowPasswordFor:ReauthenticationReasonCopy]; [self attemptToShowPasswordFor:ReauthenticationReasonCopy];
return; return;
......
...@@ -406,10 +406,11 @@ TEST_F(PasswordDetailsTableViewControllerTest, ...@@ -406,10 +406,11 @@ TEST_F(PasswordDetailsTableViewControllerTest,
TEST_F(PasswordDetailsTableViewControllerTest, TestFederatedCredential) { TEST_F(PasswordDetailsTableViewControllerTest, TestFederatedCredential) {
SetFederatedPassword(); SetFederatedPassword();
EXPECT_EQ(1, NumberOfSections()); EXPECT_EQ(1, NumberOfSections());
EXPECT_EQ(2, NumberOfItemsInSection(0)); EXPECT_EQ(3, NumberOfItemsInSection(0));
CheckEditCellText(@"http://www.example.com/", 0, 0); CheckEditCellText(@"http://www.example.com/", 0, 0);
CheckEditCellText(@"test@egmail.com", 0, 1); CheckEditCellText(@"test@egmail.com", 0, 1);
CheckEditCellText(@"www.example.com", 0, 2);
reauth().expectedResult = ReauthenticationResult::kFailure; reauth().expectedResult = ReauthenticationResult::kFailure;
PasswordDetailsTableViewController* passwordDetails = PasswordDetailsTableViewController* passwordDetails =
......
...@@ -134,21 +134,28 @@ GREYLayoutConstraint* Below() { ...@@ -134,21 +134,28 @@ GREYLayoutConstraint* Below() {
constant:0.0]; constant:0.0];
} }
// Matcher for the Copy site button in Password Details view. // Matcher for the website in Password Details view.
id<GREYMatcher> PasswordDetailWebsite() { id<GREYMatcher> PasswordDetailWebsite() {
return TextFieldForCellWithLabelId(IDS_IOS_SHOW_PASSWORD_VIEW_SITE); return TextFieldForCellWithLabelId(IDS_IOS_SHOW_PASSWORD_VIEW_SITE);
} }
// Matcher for the Copy username button in Password Details view. // Matcher for the username in Password Details view.
id<GREYMatcher> PasswordDetailUsername() { id<GREYMatcher> PasswordDetailUsername() {
return TextFieldForCellWithLabelId(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME); return TextFieldForCellWithLabelId(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME);
} }
// Matcher for the Copy password button in Password Details view. // Matcher for the password in Password Details view.
id<GREYMatcher> PasswordDetailPassword() { id<GREYMatcher> PasswordDetailPassword() {
return TextFieldForCellWithLabelId(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD); return TextFieldForCellWithLabelId(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD);
} }
// Matcher for the federation details in Password Details view.
id<GREYMatcher> PasswordDetailFederation() {
return grey_allOf(grey_accessibilityID(GetTextFieldForID(
IDS_IOS_SHOW_PASSWORD_VIEW_FEDERATION)),
grey_kindOfClassName(@"UITextField"), nil);
}
// Matcher for the Show password button in Password Details view. // Matcher for the Show password button in Password Details view.
id<GREYMatcher> ShowPasswordButton() { id<GREYMatcher> ShowPasswordButton() {
return grey_allOf(ButtonWithAccessibilityLabel(l10n_util::GetNSString( return grey_allOf(ButtonWithAccessibilityLabel(l10n_util::GetNSString(
...@@ -815,6 +822,8 @@ void CopyPasswordDetailWithID(int detail_id) { ...@@ -815,6 +822,8 @@ void CopyPasswordDetailWithID(int detail_id) {
assertWithMatcher:grey_textFieldValue(@"https://example.com/")]; assertWithMatcher:grey_textFieldValue(@"https://example.com/")];
[[EarlGrey selectElementWithMatcher:PasswordDetailUsername()] [[EarlGrey selectElementWithMatcher:PasswordDetailUsername()]
assertWithMatcher:grey_textFieldValue(@"federated username")]; assertWithMatcher:grey_textFieldValue(@"federated username")];
[[EarlGrey selectElementWithMatcher:PasswordDetailFederation()]
assertWithMatcher:grey_textFieldValue(@"famous.provider.net")];
// Check that the password is not present. // Check that the password is not present.
[[EarlGrey selectElementWithMatcher:PasswordDetailPassword()] [[EarlGrey selectElementWithMatcher:PasswordDetailPassword()]
...@@ -855,6 +864,10 @@ void CopyPasswordDetailWithID(int detail_id) { ...@@ -855,6 +864,10 @@ void CopyPasswordDetailWithID(int detail_id) {
[[EarlGrey selectElementWithMatcher:PasswordDetailPassword()] [[EarlGrey selectElementWithMatcher:PasswordDetailPassword()]
assertWithMatcher:grey_textFieldValue(kMaskedPassword)]; assertWithMatcher:grey_textFieldValue(kMaskedPassword)];
// Check that the federation origin is not present.
[[EarlGrey selectElementWithMatcher:PasswordDetailFederation()]
assertWithMatcher:grey_nil()];
[GetInteractionForPasswordDetailItem(PasswordDetailPassword()) [GetInteractionForPasswordDetailItem(PasswordDetailPassword())
assertWithMatcher:grey_layout(@[ Below() ], PasswordDetailUsername())]; assertWithMatcher:grey_layout(@[ Below() ], PasswordDetailUsername())];
[GetInteractionForPasswordDetailItem(PasswordDetailUsername()) [GetInteractionForPasswordDetailItem(PasswordDetailUsername())
...@@ -885,6 +898,8 @@ void CopyPasswordDetailWithID(int detail_id) { ...@@ -885,6 +898,8 @@ void CopyPasswordDetailWithID(int detail_id) {
assertWithMatcher:grey_nil()]; assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:PasswordDetailPassword()] [[EarlGrey selectElementWithMatcher:PasswordDetailPassword()]
assertWithMatcher:grey_nil()]; assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:PasswordDetailFederation()]
assertWithMatcher:grey_nil()];
[[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()] [[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()]
performAction:grey_tap()]; performAction:grey_tap()];
...@@ -912,11 +927,15 @@ void CopyPasswordDetailWithID(int detail_id) { ...@@ -912,11 +927,15 @@ void CopyPasswordDetailWithID(int detail_id) {
assertWithMatcher:grey_textFieldValue(@"https://example.com/")]; assertWithMatcher:grey_textFieldValue(@"https://example.com/")];
[[EarlGrey selectElementWithMatcher:PasswordDetailUsername()] [[EarlGrey selectElementWithMatcher:PasswordDetailUsername()]
assertWithMatcher:grey_textFieldValue(@"federated username")]; assertWithMatcher:grey_textFieldValue(@"federated username")];
[[EarlGrey selectElementWithMatcher:PasswordDetailFederation()]
assertWithMatcher:grey_textFieldValue(@"famous.provider.net")];
[[EarlGrey selectElementWithMatcher:PasswordDetailPassword()] [[EarlGrey selectElementWithMatcher:PasswordDetailPassword()]
assertWithMatcher:grey_nil()]; assertWithMatcher:grey_nil()];
[GetInteractionForPasswordDetailItem(PasswordDetailUsername()) [GetInteractionForPasswordDetailItem(PasswordDetailUsername())
assertWithMatcher:grey_layout(@[ Below() ], PasswordDetailWebsite())]; assertWithMatcher:grey_layout(@[ Below() ], PasswordDetailWebsite())];
[[EarlGrey selectElementWithMatcher:PasswordDetailFederation()]
assertWithMatcher:grey_layout(@[ Below() ], PasswordDetailUsername())];
[[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()] [[EarlGrey selectElementWithMatcher:SettingsMenuBackButton()]
performAction:grey_tap()]; performAction:grey_tap()];
......
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