Commit 6c0b19c6 authored by Ioana Pandele's avatar Ioana Pandele Committed by Commit Bot

[PwdCheckAndroid] Hide password on edit view entry

Bug: 1141018
Change-Id: I44c9516636f5ab8c3610aa272b725329c2fe911c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2489912Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819826}
parent 26798b98
......@@ -40,7 +40,7 @@ public class PasswordCheckEditFragmentView extends PreferenceFragmentCompat {
public static final String EXTRA_COMPROMISED_CREDENTIAL = "extra_compromised_credential";
@VisibleForTesting
static final String EXTRA_NEW_PASSWORD = "extra_new_password";
static final String EXTRA_PASSWORD_MASKED = "extra_password_masked";
static final String EXTRA_PASSWORD_VISIBLE = "extra_password_visible";
private Supplier<PasswordCheck> mPasswordCheckFactory;
private String mNewPassword;
......@@ -78,7 +78,7 @@ public class PasswordCheckEditFragmentView extends PreferenceFragmentCompat {
super.onViewCreated(view, savedInstanceState);
mCredential = getCredentialFromInstanceStateOrLaunchBundle(savedInstanceState);
mNewPassword = getNewPasswordFromInstanceStateOrLaunchBundle(savedInstanceState);
mPasswordVisible = getViewButtonPressedFromInstanceState(savedInstanceState);
mPasswordVisible = getPasswordVisibleFromInstanceState(savedInstanceState);
TextView hintText = view.findViewById(R.id.edit_hint);
hintText.setText(getString(R.string.password_edit_hint, mCredential.getDisplayOrigin()));
......@@ -113,9 +113,9 @@ public class PasswordCheckEditFragmentView extends PreferenceFragmentCompat {
mMaskPasswordButton = view.findViewById(R.id.password_entry_editor_mask_password);
mMaskPasswordButton.setOnClickListener(unusedView -> this.maskPassword());
if (mPasswordVisible) {
maskPassword();
} else {
unmaskPassword();
} else {
maskPassword();
}
}
......@@ -144,7 +144,7 @@ public class PasswordCheckEditFragmentView extends PreferenceFragmentCompat {
super.onSaveInstanceState(outState);
outState.putParcelable(EXTRA_COMPROMISED_CREDENTIAL, mCredential);
outState.putString(EXTRA_NEW_PASSWORD, mNewPassword);
outState.putBoolean(EXTRA_PASSWORD_MASKED, mPasswordVisible);
outState.putBoolean(EXTRA_PASSWORD_VISIBLE, mPasswordVisible);
}
@Override
......@@ -199,9 +199,10 @@ public class PasswordCheckEditFragmentView extends PreferenceFragmentCompat {
: "");
}
private boolean getViewButtonPressedFromInstanceState(Bundle savedInstanceState) {
return (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_PASSWORD_MASKED))
&& savedInstanceState.getBoolean(EXTRA_PASSWORD_MASKED);
private boolean getPasswordVisibleFromInstanceState(Bundle savedInstanceState) {
return (savedInstanceState != null
&& savedInstanceState.containsKey(EXTRA_PASSWORD_VISIBLE))
&& savedInstanceState.getBoolean(EXTRA_PASSWORD_VISIBLE);
}
private void maskPassword() {
......
......@@ -208,22 +208,22 @@ public class PasswordCheckEditViewTest {
assertNotNull(unmaskButton);
assertNotNull(maskButton);
// Unmasked by default since the user just reauthenticated.
assertThat(maskButton.getVisibility(), is(View.VISIBLE));
assertThat(unmaskButton.getVisibility(), is(View.GONE));
assertThat(password, isVisiblePasswordInput(true));
// Clicking the mask button obfuscates the password.
runOnUiThreadBlocking(maskButton::callOnClick);
// Masked by default
assertThat(maskButton.getVisibility(), is(View.GONE));
assertThat(unmaskButton.getVisibility(), is(View.VISIBLE));
assertThat(password, isVisiblePasswordInput(false));
// Clicking the unmask button shows the password again.
// Clicking the unmask button shows the password.
runOnUiThreadBlocking(unmaskButton::callOnClick);
assertThat(maskButton.getVisibility(), is(View.VISIBLE));
assertThat(unmaskButton.getVisibility(), is(View.GONE));
assertThat(password, isVisiblePasswordInput(true));
// Clicking the mask button hides the password again.
runOnUiThreadBlocking(maskButton::callOnClick);
assertThat(maskButton.getVisibility(), is(View.GONE));
assertThat(unmaskButton.getVisibility(), is(View.VISIBLE));
assertThat(password, isVisiblePasswordInput(false));
}
private void setUpUiLaunchedFromSettings() {
......
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