Commit 6472cb97 authored by Eleonora Rocchi's avatar Eleonora Rocchi Committed by Commit Bot

[PwdCheckAndroid] Check passwords preference in the Passwords settings menu.

This CL adds the Check passwords preference button in the Passwords settings menu, the button will be only shown if the corresponding feature flag is enabled. It adds tests to check whether the button is correctly shown.

Bug:1092444

Change-Id: I35221b8f4af66f3a4e3a3b5fbbbef42650c7324f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2246590
Commit-Queue: Eleonora Rocchi <erocchi@google.com>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarIoana Pandele <ioanap@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779790}
parent 437824ed
......@@ -67,6 +67,7 @@ public class PasswordSettings
public static final String PREF_SAVE_PASSWORDS_SWITCH = "save_passwords_switch";
public static final String PREF_AUTOSIGNIN_SWITCH = "autosignin_switch";
public static final String PREF_CHECK_PASSWORDS = "check_passwords";
public static final String PREF_KEY_MANAGE_ACCOUNT_LINK = "manage_account_link";
public static final String PREF_KEY_SECURITY_KEY_LINK = "security_key_link";
......@@ -81,11 +82,12 @@ public class PasswordSettings
private static final int ORDER_SWITCH = 0;
private static final int ORDER_AUTO_SIGNIN_CHECKBOX = 1;
private static final int ORDER_MANAGE_ACCOUNT_LINK = 2;
private static final int ORDER_SECURITY_KEY = 3;
private static final int ORDER_SAVED_PASSWORDS = 4;
private static final int ORDER_EXCEPTIONS = 5;
private static final int ORDER_SAVED_PASSWORDS_NO_TEXT = 6;
private static final int ORDER_CHECK_PASSWORDS = 2;
private static final int ORDER_MANAGE_ACCOUNT_LINK = 3;
private static final int ORDER_SECURITY_KEY = 4;
private static final int ORDER_SAVED_PASSWORDS = 5;
private static final int ORDER_EXCEPTIONS = 6;
private static final int ORDER_SAVED_PASSWORDS_NO_TEXT = 7;
private boolean mNoPasswords;
private boolean mNoPasswordExceptions;
......@@ -98,6 +100,7 @@ public class PasswordSettings
private Preference mSecurityKey;
private ChromeSwitchPreference mSavePasswordsSwitch;
private ChromeBaseCheckBoxPreference mAutoSignInSwitch;
private ChromeBasePreference mCheckPasswords;
private TextMessagePreference mEmptyView;
private boolean mSearchRecorded;
private Menu mMenu;
......@@ -234,6 +237,9 @@ public class PasswordSettings
if (mSearchQuery == null) {
createSavePasswordsSwitch();
createAutoSignInCheckbox();
if (ChromeFeatureList.isEnabled(ChromeFeatureList.PASSWORD_CHECK)) {
createCheckPasswords();
}
}
PasswordManagerHandlerProvider.getInstance()
.getPasswordManagerHandler()
......@@ -464,6 +470,17 @@ public class PasswordSettings
getPrefService().getBoolean(Pref.CREDENTIALS_ENABLE_AUTOSIGNIN));
}
private void createCheckPasswords() {
mCheckPasswords = new ChromeBasePreference(getStyledContext(), null);
mCheckPasswords.setKey(PREF_CHECK_PASSWORDS);
mCheckPasswords.setTitle(R.string.passwords_check_title);
mCheckPasswords.setOrder(ORDER_CHECK_PASSWORDS);
mCheckPasswords.setSummary(R.string.passwords_check_description);
// Add a stub listener which returns true to notify the click was handled
mCheckPasswords.setOnPreferenceClickListener(preference -> true);
getPreferenceScreen().addPreference(mCheckPasswords);
}
private void displayManageAccountLink() {
if (!PasswordManagerLauncher.isSyncingPasswordsWithoutCustomPassphrase()) {
return;
......
......@@ -104,6 +104,8 @@ import org.chromium.chrome.browser.settings.SettingsLauncherImpl;
import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.chrome.test.ChromeBrowserTestRule;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.Features.DisableFeatures;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.components.browser_ui.settings.ChromeBaseCheckBoxPreference;
import org.chromium.components.browser_ui.settings.ChromeSwitchPreference;
import org.chromium.components.sync.ModelType;
......@@ -718,6 +720,40 @@ public class PasswordSettingsTest {
});
}
/**
* Check that the check passwords preference is shown when the corresponding feature is enabled.
*/
@Test
@SmallTest
@Feature({"Preferences"})
@EnableFeatures(ChromeFeatureList.PASSWORD_CHECK)
public void testCheckPasswordsEnabled() {
final SettingsActivity settingsActivity = mSettingsActivityTestRule.startSettingsActivity();
TestThreadUtils.runOnUiThreadBlocking(() -> {
PasswordSettings passwordPrefs = mSettingsActivityTestRule.getFragment();
Assert.assertNotNull(
passwordPrefs.findPreference(PasswordSettings.PREF_CHECK_PASSWORDS));
});
}
/**
* Check that the check passwords preference is not shown when the corresponding feature is
* disabled.
*/
@Test
@SmallTest
@Feature({"Preferences"})
@DisableFeatures(ChromeFeatureList.PASSWORD_CHECK)
public void testCheckPasswordsDisabled() {
final SettingsActivity settingsActivity = mSettingsActivityTestRule.startSettingsActivity();
TestThreadUtils.runOnUiThreadBlocking(() -> {
PasswordSettings passwordPrefs = mSettingsActivityTestRule.getFragment();
Assert.assertNull(passwordPrefs.findPreference(PasswordSettings.PREF_CHECK_PASSWORDS));
});
}
/**
* Check that {@link #showPasswordEntryEditingView()} was called with the index matching the one
* of the password that was clicked.
......@@ -725,7 +761,7 @@ public class PasswordSettingsTest {
@Test
@SmallTest
@Feature({"Preferences"})
@Features.EnableFeatures(ChromeFeatureList.PASSWORD_EDITING_ANDROID)
@EnableFeatures(ChromeFeatureList.PASSWORD_EDITING_ANDROID)
public void testSelectedStoredPasswordIndexIsSameAsInShowPasswordEntryEditingView() {
PasswordEditingDelegateProvider.getInstance().setPasswordEditingDelegate(
mMockPasswordEditingDelegate);
......@@ -749,7 +785,7 @@ public class PasswordSettingsTest {
@Test
@SmallTest
@Feature({"Preferences"})
@Features.EnableFeatures(ChromeFeatureList.PASSWORD_EDITING_ANDROID)
@EnableFeatures(ChromeFeatureList.PASSWORD_EDITING_ANDROID)
public void testPasswordDataDisplayedInEditingActivity() {
PasswordEditingDelegateProvider.getInstance().setPasswordEditingDelegate(
mMockPasswordEditingDelegate);
......@@ -771,7 +807,7 @@ public class PasswordSettingsTest {
@Test
@SmallTest
@Feature({"Preferences"})
@Features.EnableFeatures(ChromeFeatureList.PASSWORD_EDITING_ANDROID)
@EnableFeatures(ChromeFeatureList.PASSWORD_EDITING_ANDROID)
public void testPasswordEditingMethodWasCalled() throws Exception {
PasswordEditingDelegateProvider.getInstance().setPasswordEditingDelegate(
mMockPasswordEditingDelegate);
......@@ -800,7 +836,7 @@ public class PasswordSettingsTest {
@Test
@SmallTest
@Feature({"Preferences"})
@Features.EnableFeatures(ChromeFeatureList.PASSWORD_EDITING_ANDROID)
@EnableFeatures(ChromeFeatureList.PASSWORD_EDITING_ANDROID)
public void testChangeOfStoredPasswordDataIsPropagated() throws Exception {
PasswordEditingDelegateProvider.getInstance().setPasswordEditingDelegate(
mMockPasswordEditingDelegate);
......@@ -833,7 +869,7 @@ public class PasswordSettingsTest {
@Test
@SmallTest
@Feature({"Preferences"})
@Features.EnableFeatures(ChromeFeatureList.PASSWORD_EDITING_ANDROID)
@EnableFeatures(ChromeFeatureList.PASSWORD_EDITING_ANDROID)
public void testStoredPasswordCanBeUnmaskedAndMaskedAgain() {
PasswordEditingDelegateProvider.getInstance().setPasswordEditingDelegate(
mMockPasswordEditingDelegate);
......@@ -1694,7 +1730,7 @@ public class PasswordSettingsTest {
@Test
@SmallTest
@Feature({"Preferences"})
@Features.EnableFeatures(ChromeFeatureList.PASSWORD_EDITING_ANDROID)
@EnableFeatures(ChromeFeatureList.PASSWORD_EDITING_ANDROID)
public void testEditSavedPasswordIconVisibleInActionBarWithFeature() {
setPasswordSource( // Initialize preferences
new SavedPasswordEntry("https://example.com", "test user", "test password"));
......
......@@ -242,6 +242,7 @@ const base::Feature* kFeaturesExposedToJava[] = {
&omnibox::kOmniboxSuggestionsRecyclerView,
&omnibox::kOmniboxSuggestionsWrapAround,
&password_manager::features::kGooglePasswordManager,
&password_manager::features::kPasswordCheck,
&password_manager::features::kPasswordEditingAndroid,
&password_manager::features::kPasswordManagerOnboardingAndroid,
&password_manager::features::kRecoverFromNeverSaveAndroid,
......
......@@ -350,6 +350,7 @@ public abstract class ChromeFeatureList {
public static final String PAINT_PREVIEW_CAPTURE_EXPERIMENT = "PaintPreviewCaptureExperiment";
public static final String PAINT_PREVIEW_DEMO = "PaintPreviewDemo";
public static final String PAINT_PREVIEW_SHOW_ON_STARTUP = "PaintPreviewShowOnStartup";
public static final String PASSWORD_CHECK = "PasswordCheck";
public static final String PASSWORD_EDITING_ANDROID = "PasswordEditingAndroid";
public static final String PASSWORD_MANAGER_ONBOARDING_ANDROID =
"PasswordManagerOnboardingAndroid";
......
......@@ -491,6 +491,12 @@ CHAR-LIMIT guidelines:
<message name="IDS_PASSWORDS_LEAK_DETECTION_SWITCH_SIGNED_OUT_ENABLE_DESCRIPTION" desc="Description for the switch toggling whether Chrome should check that entered credentials have been part of a leak. Displayed for users who are not signed in and syncing.">
When you sign in to your Google Account, this feature is turned on
</message>
<message name="IDS_PASSWORDS_CHECK_TITLE" desc="Title for the check passwords button which allows to check whether the user's passwords have been compromised.">
Check passwords
</message>
<message name="IDS_PASSWORDS_CHECK_DESCRIPTION" desc="Text explaining the benefits of checking the passwords, to be displayed under the Check Passwords button title.">
Keep your passwords safe from data breaches and other security issues
</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>
......
dde9e67e02af87bf8b25a1dff9de112432fff9cc
\ No newline at end of file
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