Commit 31682171 authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[Android][ReEPwdSave] Allow password recovery on username fields

Although username fields are detected and offers the regular fallbacks,
the toggle to recover from "never save" wasn't displayed yet. This CL
allows to enable password saving if the selected field is for usernames.

Screenshot in the bug.

Bug: 1097722
Change-Id: I45c7dde4f591167c934ec840be368915c66b74a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2409990
Commit-Queue: Friedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarIoana Pandele <ioanap@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806985}
parent 1ac5b054
......@@ -32,6 +32,7 @@
#include "components/autofill/core/browser/ui/accessory_sheet_enums.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_util.h"
#include "components/autofill/core/common/mojom/autofill_types.mojom-shared.h"
#include "components/autofill/core/common/password_generation_util.h"
#include "components/password_manager/content/browser/content_password_manager_driver.h"
#include "components/password_manager/content/browser/content_password_manager_driver_factory.h"
......@@ -299,12 +300,7 @@ void PasswordAccessoryControllerImpl::RefreshSuggestionsForField(
autofill::AccessoryTabType::PASSWORDS, GetTitle(has_suggestions, origin),
std::move(info_to_add), std::move(footer_commands_to_add));
if (base::FeatureList::IsEnabled(
password_manager::features::kRecoverFromNeverSaveAndroid) &&
base::FeatureList::IsEnabled(
autofill::features::kAutofillKeyboardAccessory) &&
is_password_field &&
password_client_->IsSavingAndFillingEnabled(origin.GetURL())) {
if (ShouldShowRecoveryToggle(focused_field_type, origin)) {
BlacklistedStatus blacklisted_status =
credential_cache_->GetCredentialStore(origin).GetBlacklistedStatus();
if (blacklisted_status == BlacklistedStatus::kWasBlacklisted ||
......@@ -381,6 +377,23 @@ bool PasswordAccessoryControllerImpl::AppearsInSuggestions(
});
}
bool PasswordAccessoryControllerImpl::ShouldShowRecoveryToggle(
autofill::mojom::FocusedFieldType field_type,
const url::Origin& origin) const {
if (!base::FeatureList::IsEnabled(
password_manager::features::kRecoverFromNeverSaveAndroid)) {
return false;
}
if (!base::FeatureList::IsEnabled(
autofill::features::kAutofillKeyboardAccessory)) {
return false;
}
if (!password_client_->IsSavingAndFillingEnabled(origin.GetURL()))
return false;
return field_type == FocusedFieldType::kFillablePasswordField ||
field_type == FocusedFieldType::kFillableUsernameField;
}
base::WeakPtr<ManualFillingController>
PasswordAccessoryControllerImpl::GetManualFillingController() {
if (!mf_controller_)
......
......@@ -100,6 +100,11 @@ class PasswordAccessoryControllerImpl
bool is_password,
const url::Origin& origin) const;
// Returns true if `field_type` and `origin` of a focused field allow to show
// the option toggle to recover from a "never save" state.
bool ShouldShowRecoveryToggle(autofill::mojom::FocusedFieldType field_type,
const url::Origin& origin) const;
// Lazy-initializes and returns the ManualFillingController for the current
// |web_contents_|. The lazy initialization allows injecting mocks for tests.
base::WeakPtr<ManualFillingController> GetManualFillingController();
......
......@@ -725,6 +725,32 @@ TEST_F(PasswordAccessoryControllerTest, AddsSaveToggleIfWasBlacklisted) {
/*is_manual_generation_available=*/false);
}
TEST_F(PasswordAccessoryControllerTest, AddsSaveToggleOnUsernameIfBlacklisted) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitWithFeatures(
{password_manager::features::kRecoverFromNeverSaveAndroid,
autofill::features::kAutofillKeyboardAccessory},
{});
cache()->SaveCredentialsAndBlacklistedForOrigin(
{}, CredentialCache::IsOriginBlacklisted(true),
url::Origin::Create(GURL(kExampleSite)));
ON_CALL(*password_client(), IsSavingAndFillingEnabled(GURL(kExampleSite)))
.WillByDefault(Return(true));
AccessorySheetData::Builder data_builder(AccessoryTabType::PASSWORDS,
passwords_empty_str(kExampleDomain));
data_builder
.SetOptionToggle(
l10n_util::GetStringUTF16(IDS_PASSWORD_SAVING_STATUS_TOGGLE), false,
autofill::AccessoryAction::TOGGLE_SAVE_PASSWORDS)
.AppendFooterCommand(manage_passwords_str(),
autofill::AccessoryAction::MANAGE_PASSWORDS);
EXPECT_CALL(mock_manual_filling_controller_,
RefreshSuggestions(std::move(data_builder).Build()));
controller()->RefreshSuggestionsForField(
FocusedFieldType::kFillableUsernameField,
/*is_manual_generation_available=*/false);
}
TEST_F(PasswordAccessoryControllerTest,
RecordsAccessoryImpressionsForBlacklisted) {
base::test::ScopedFeatureList scoped_feature_list;
......
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