Commit e945ccef authored by Ioana Pandele's avatar Ioana Pandele Committed by Commit Bot

[Android] Update leak check switch

- Add a description
- Change string
- Change order
- Only display for signed in users

Bug: 986322
Change-Id: I47e7320f66caad5587348c4e63d0e565c54bf68e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1776541
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692265}
parent ebd771be
......@@ -34,6 +34,7 @@ import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.preferences.SearchUtils;
import org.chromium.chrome.browser.preferences.TextMessagePreference;
import org.chromium.components.signin.ChromeSigninController;
import org.chromium.ui.text.SpanApplier;
import java.util.Locale;
......@@ -72,8 +73,8 @@ public class SavePasswordsPreferences
private static final String PREF_KEY_SAVED_PASSWORDS_NO_TEXT = "saved_passwords_no_text";
private static final int ORDER_SWITCH = 0;
private static final int ORDER_AUTO_SIGNIN_CHECKBOX = 1;
private static final int ORDER_AUTO_LEAK_DETECTION_SWITCH = 2;
private static final int ORDER_AUTO_LEAK_DETECTION_SWITCH = 1;
private static final int ORDER_AUTO_SIGNIN_CHECKBOX = 2;
private static final int ORDER_MANAGE_ACCOUNT_LINK = 3;
private static final int ORDER_SAVED_PASSWORDS = 4;
private static final int ORDER_EXCEPTIONS = 5;
......@@ -209,8 +210,13 @@ public class SavePasswordsPreferences
getPreferenceScreen().removeAll();
if (mSearchQuery == null) {
createSavePasswordsSwitch();
ChromeSigninController signInController = ChromeSigninController.get();
if (signInController != null && signInController.isSignedIn()) {
createAutoLeakDetectionSwitch();
}
createAutoSignInCheckbox();
createAutoLeakDetectionSwitch();
}
PasswordManagerHandlerProvider.getInstance()
.getPasswordManagerHandler()
......@@ -440,9 +446,9 @@ public class SavePasswordsPreferences
mAutoLeakDetectionSwitch = new ChromeSwitchPreference(getStyledContext(), null);
mAutoLeakDetectionSwitch.setKey(PREF_LEAK_DETECTION_SWITCH);
// TODO(crbug.com/986317): Add description and update title.
mAutoLeakDetectionSwitch.setTitle(R.string.passwords_leak_detection_switch_title);
mAutoLeakDetectionSwitch.setOrder(ORDER_AUTO_LEAK_DETECTION_SWITCH);
mAutoLeakDetectionSwitch.setSummary(R.string.passwords_leak_detection_switch_description);
mAutoLeakDetectionSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
PrefServiceBridge.getInstance().setPasswordLeakDetectionEnabled((boolean) newValue);
return true;
......
......@@ -556,9 +556,12 @@ CHAR-LIMIT guidelines:
<message name="IDS_PASSWORDS_AUTO_SIGNIN_DESCRIPTION" desc="Text under 'Auto sign-in' checkbox">
Automatically sign in to websites using stored credentials. When the feature is off, you’ll be asked for verification every time before signing in to a website.
</message>
<message name="IDS_PASSWORDS_LEAK_DETECTION_SWITCH_TITLE" desc="Title for the switch togglingwhether Chrome should check that entered credentials have been part of a leak.">
<message name="IDS_PASSWORDS_LEAK_DETECTION_SWITCH_TITLE" desc="Title for the switch toggling whether Chrome should check that entered credentials have been part of a leak.">
Check password safety
</message>
<message name="IDS_PASSWORDS_LEAK_DETECTION_SWITCH_DESCRIPTION" desc="Description for the switch toggling whether Chrome should check that entered credentials have been part of a leak.">
Warns you if a password you use was part of a data breach
</message>
<message name="IDS_SECTION_SAVED_PASSWORDS_EXCEPTIONS" desc="Header for the list of websites for which user selected to never save passwords. [CHAR-LIMIT=32]">
Never saved
</message>
......
feb1d516f50af8ba55ff6753762220dca3ab18ab
\ No newline at end of file
4ce3fc0c7ec4f132ea462f09e7f2986266c05000
\ No newline at end of file
......@@ -540,6 +540,9 @@ public class SavePasswordsPreferencesTest {
@Feature({"Preferences"})
@Features.EnableFeatures({SavePasswordsPreferences.PASSWORD_LEAK_DETECTION_FEATURE})
public void testLeakDetectionSwitchEnabled() throws Exception {
// The switch is only displayed for signed in users.
ChromeSigninController.get().setSignedInAccountName("Test Account");
TestThreadUtils.runOnUiThreadBlocking(
() -> { PrefServiceBridge.getInstance().setPasswordLeakDetectionEnabled(true); });
......@@ -566,6 +569,9 @@ public class SavePasswordsPreferencesTest {
@Feature({"Preferences"})
@Features.EnableFeatures({SavePasswordsPreferences.PASSWORD_LEAK_DETECTION_FEATURE})
public void testLeakDetectionSwitchDisabled() throws Exception {
// The switch is only displayed for signed in users.
ChromeSigninController.get().setSignedInAccountName("Test Account");
TestThreadUtils.runOnUiThreadBlocking(
() -> { PrefServiceBridge.getInstance().setPasswordLeakDetectionEnabled(false); });
final Preferences preferences =
......@@ -579,6 +585,21 @@ public class SavePasswordsPreferencesTest {
Assert.assertFalse(onOffSwitch.isChecked());
}
@Test
@SmallTest
@Feature({"Preferences"})
@Features.EnableFeatures({SavePasswordsPreferences.PASSWORD_LEAK_DETECTION_FEATURE})
public void testLeakDetectionNonSignedIn() throws Exception {
final Preferences preferences =
PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(),
SavePasswordsPreferences.class.getName());
SavePasswordsPreferences savedPasswordPrefs =
(SavePasswordsPreferences) preferences.getMainFragment();
// The switch shouldn't be displayed for non signed-in users.
Assert.assertNull(savedPasswordPrefs.findPreference(
SavePasswordsPreferences.PREF_LEAK_DETECTION_SWITCH));
}
/**
* Tests that the link pointing to managing passwords in the user's account is not displayed
* for non signed in users.
......
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