Commit 83f2f67e authored by Eleonora Rocchi's avatar Eleonora Rocchi Committed by Commit Bot

[PwdCheckAndroid] Add menu entry to view compromised credential

This CL adds a view entry to the more menu of a compromised credential.
It also adds a test to verify the menu is correctly shown.

IDS_PASSWORD_CHECK_CREDENTIAL_MENU_ITEM_VIEW_BUTTON_CAPTION.png
https://storage.cloud.google.com/chromium-translation-screenshots/2531deee57820ab74470f0ebbb23616862e03840

Bug: 1117502, 1092444
Change-Id: I6600c78848bb4dadf343c4c9ff60c6a5ba594941
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2362910Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarIoana Pandele <ioanap@chromium.org>
Commit-Queue: Eleonora Rocchi <erocchi@google.com>
Cr-Commit-Position: refs/heads/master@{#799515}
parent 4838b76a
......@@ -42,6 +42,12 @@ class PasswordCheckCoordinator implements PasswordCheckComponentUi, LifecycleObs
*/
void onRemove(CompromisedCredential credential);
/**
* View the given Credential.
* @param credential A {@link CompromisedCredential} to be viewed.
*/
void onView(CompromisedCredential credential);
/**
* Opens a password change form or home page of |credential|'s origin or an app.
* @param credential A {@link CompromisedCredential} to be changed.
......
......@@ -171,6 +171,21 @@ class PasswordCheckMediator
});
}
@Override
public void onView(CompromisedCredential credential) {
if (!mReauthenticationHelper.canReauthenticate()) {
mReauthenticationHelper.showScreenLockToast();
return;
}
mReauthenticationHelper.reauthenticate(ReauthReason.VIEW_PASSWORD,
reauthSucceeded
-> {
// TODO(crbug.com/1117502) Add implementation to view the compromised
// credential
});
}
@Override
public void onChangePasswordButtonClick(CompromisedCredential credential) {
mChangePasswordDelegate.launchAppOrCctWithChangePasswordUrl(credential);
......
......@@ -450,13 +450,17 @@ class PasswordCheckViewBinder {
private static ListMenu createCredentialMenu(Context context, CompromisedCredential credential,
PasswordCheckCoordinator.CredentialEventHandler credentialHandler) {
MVCListAdapter.ModelList menuItems = new MVCListAdapter.ModelList();
menuItems.add(BasicListMenu.buildMenuListItem(
R.string.password_check_credential_menu_item_view_button_caption, 0, 0, true));
menuItems.add(BasicListMenu.buildMenuListItem(
R.string.password_check_credential_menu_item_edit_button_caption, 0, 0, true));
menuItems.add(
BasicListMenu.buildMenuListItem(org.chromium.chrome.R.string.remove, 0, 0, true));
ListMenu.Delegate delegate = (listModel) -> {
int textId = listModel.get(ListMenuItemProperties.TITLE_ID);
if (textId == R.string.password_check_credential_menu_item_edit_button_caption) {
if (textId == R.string.password_check_credential_menu_item_view_button_caption) {
credentialHandler.onView(credential);
} else if (textId == R.string.password_check_credential_menu_item_edit_button_caption) {
credentialHandler.onEdit(credential);
} else if (textId == org.chromium.chrome.R.string.remove) {
credentialHandler.onRemove(credential);
......
......@@ -253,6 +253,9 @@
<message name="IDS_PASSWORD_CHECK_CREDENTIAL_MENU_ITEM_EDIT_BUTTON_CAPTION" desc="Caption for the menu button allowing to edit a compromised credential.">
Edit password
</message>
<message name="IDS_PASSWORD_CHECK_CREDENTIAL_MENU_ITEM_VIEW_BUTTON_CAPTION" desc="Caption for the menu button allowing to view a compromised credential.">
View password
</message>
<!-- Password Check Toast strings -->
<message name="IDS_PASSWORD_CHECK_SET_SCREEN_LOCK_TEXT" desc="Text prompting user to set a screen lock in order to view or edit their compromised passwords.">
......
......@@ -527,6 +527,22 @@ public class PasswordCheckViewTest {
verify(mMockHandler).onRemove(eq(ANA));
}
@Test
@MediumTest
public void testClickingViewInMoreMenuTriggersHandler() {
runOnUiThreadBlocking(() -> mModel.get(ITEMS).add(buildCredentialItem(ANA)));
waitForListViewToHaveLength(1);
TouchCommon.singleClickView(getCredentialMoreButtonAt(0));
onView(withText(R.string.password_check_credential_menu_item_view_button_caption))
.inRoot(withDecorView(
not(is(mPasswordCheckView.getActivity().getWindow().getDecorView()))))
.perform(click());
verify(mMockHandler).onView(eq(ANA));
}
@Test
@SmallTest
public void testGetTimestampStrings() {
......
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