Commit bdd9ecc4 authored by Eleonora Rocchi's avatar Eleonora Rocchi Committed by Commit Bot

[PwdCheckAndroid] Close the view dialog if the reauth time expired

This CL adds the logic to close the view dialog of a compromised
credential if the reauth time expired. It also adds a test to verify
the dialog is correctly dismissed.


Bug: 1119796, 1092444
Change-Id: Icbab80bcb312a2d9ac81edacab1f6eb56e3eda23
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2377810Reviewed-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@{#801806}
parent b6953033
......@@ -13,6 +13,8 @@ import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import org.chromium.chrome.browser.password_check.internal.R;
import org.chromium.chrome.browser.password_manager.settings.ReauthenticationManager;
import org.chromium.chrome.browser.password_manager.settings.ReauthenticationManager.ReauthScope;
/**
* Shows the dialog that allows the user to see the compromised credential.
......@@ -44,4 +46,14 @@ public class PasswordCheckViewDialogFragment extends PasswordCheckDialogFragment
.create();
return viewDialog;
}
@Override
public void onResume() {
super.onResume();
if (!ReauthenticationManager.authenticationStillValid(ReauthScope.ONE_AT_A_TIME)) {
// If the page was idle (e.g. screenlocked for a few minutes), close the dialog to
// ensure the user goes through reauth again.
dismiss();
}
}
}
......@@ -42,6 +42,7 @@ import static org.chromium.chrome.browser.password_check.PasswordCheckUIStatus.E
import static org.chromium.chrome.browser.password_check.PasswordCheckUIStatus.ERROR_UNKNOWN;
import static org.chromium.chrome.browser.password_check.PasswordCheckUIStatus.IDLE;
import static org.chromium.chrome.browser.password_check.PasswordCheckUIStatus.RUNNING;
import static org.chromium.chrome.browser.password_manager.settings.ReauthenticationManager.VALID_REAUTHENTICATION_TIME_INTERVAL_MILLIS;
import static org.chromium.content_public.browser.test.util.CriteriaHelper.pollUiThread;
import static org.chromium.content_public.browser.test.util.TestThreadUtils.runOnUiThreadBlocking;
......@@ -76,6 +77,8 @@ import org.chromium.base.test.util.ScalableTimeout;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.password_check.PasswordCheckProperties.HeaderProperties;
import org.chromium.chrome.browser.password_check.internal.R;
import org.chromium.chrome.browser.password_manager.settings.ReauthenticationManager;
import org.chromium.chrome.browser.password_manager.settings.ReauthenticationManager.ReauthScope;
import org.chromium.chrome.browser.settings.SettingsActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.components.browser_ui.widget.listmenu.ListMenuButton;
......@@ -614,6 +617,9 @@ public class PasswordCheckViewTest {
recordedClosure.incrementAndGet();
}
};
ReauthenticationManager.recordLastReauth(
System.currentTimeMillis(), ReauthScope.ONE_AT_A_TIME);
mModel.set(VIEW_CREDENTIAL, ANA);
runOnUiThreadBlocking(() -> mModel.set(VIEW_DIALOG_HANDLER, fakeHandler));
......@@ -625,6 +631,35 @@ public class PasswordCheckViewTest {
assertThat(recordedClosure.get(), is(1));
}
@Test
@MediumTest
public void testOnResumeViewDialogReauthenticationNeeded() {
final AtomicInteger recordedDismiss = new AtomicInteger(0);
PasswordCheckDeletionDialogFragment.Handler fakeHandler =
new PasswordCheckDeletionDialogFragment.Handler() {
@Override
public void onDismiss() {
recordedDismiss.incrementAndGet();
}
@Override
public void onClick(DialogInterface dialogInterface, int i) {}
};
ReauthenticationManager.recordLastReauth(
System.currentTimeMillis(), ReauthScope.ONE_AT_A_TIME);
mModel.set(VIEW_CREDENTIAL, ANA);
runOnUiThreadBlocking(() -> mModel.set(VIEW_DIALOG_HANDLER, fakeHandler));
ReauthenticationManager.recordLastReauth(
System.currentTimeMillis() - VALID_REAUTHENTICATION_TIME_INTERVAL_MILLIS,
ReauthScope.ONE_AT_A_TIME);
mTestRule.getFragment().onStop();
mTestRule.getFragment().onResume();
CriteriaHelper.pollInstrumentationThread(() -> recordedDismiss.get() == 1);
}
private MVCListAdapter.ListItem buildHeader(@PasswordCheckUIStatus int status,
Integer compromisedCredentialsCount, Long checkTimestamp) {
return buildHeader(status, compromisedCredentialsCount, checkTimestamp, null);
......
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