Commit 5a0ccdd2 authored by Vadym Doroshenko's avatar Vadym Doroshenko Committed by Commit Bot

Implementation of PermanentlyBlacklist in NewPasswordFormManager.

It's basically the same as in PasswordFormManager.

Bug: 831123
Change-Id: Iee8fda80eb46e3be1245e2f28d5a9b08980f527e
Reviewed-on: https://chromium-review.googlesource.com/1213156
Commit-Queue: Vadym Doroshenko <dvadym@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589946}
parent 6e232c81
...@@ -293,9 +293,26 @@ void NewPasswordFormManager::UpdatePasswordValue( ...@@ -293,9 +293,26 @@ void NewPasswordFormManager::UpdatePasswordValue(
// TODO(https://crbug.com/831123): Implement all methods from // TODO(https://crbug.com/831123): Implement all methods from
// PasswordFormManagerForUI. // PasswordFormManagerForUI.
void NewPasswordFormManager::OnNopeUpdateClicked() {} void NewPasswordFormManager::OnNopeUpdateClicked() {}
void NewPasswordFormManager::OnNeverClicked() {}
void NewPasswordFormManager::OnNeverClicked() {
PermanentlyBlacklist();
}
void NewPasswordFormManager::OnNoInteraction(bool is_update) {} void NewPasswordFormManager::OnNoInteraction(bool is_update) {}
void NewPasswordFormManager::PermanentlyBlacklist() {}
void NewPasswordFormManager::PermanentlyBlacklist() {
DCHECK(!client_->IsIncognito());
if (!new_blacklisted_) {
new_blacklisted_ = std::make_unique<PasswordForm>();
new_blacklisted_->origin = observed_form_.origin;
// The following method of finding |signon_realm| is correct for HTML forms.
new_blacklisted_->signon_realm = observed_form_.origin.GetOrigin().spec();
blacklisted_matches_.push_back(new_blacklisted_.get());
}
form_saver_->PermanentlyBlacklist(new_blacklisted_.get());
}
void NewPasswordFormManager::OnPasswordsRevealed() {} void NewPasswordFormManager::OnPasswordsRevealed() {}
bool NewPasswordFormManager::IsNewLogin() const { bool NewPasswordFormManager::IsNewLogin() const {
...@@ -335,6 +352,7 @@ void NewPasswordFormManager::ProcessMatches( ...@@ -335,6 +352,7 @@ void NewPasswordFormManager::ProcessMatches(
// Copy out blacklisted matches. // Copy out blacklisted matches.
blacklisted_matches_.clear(); blacklisted_matches_.clear();
new_blacklisted_.reset();
std::copy_if( std::copy_if(
non_federated.begin(), non_federated.end(), non_federated.begin(), non_federated.end(),
std::back_inserter(blacklisted_matches_), [](const PasswordForm* form) { std::back_inserter(blacklisted_matches_), [](const PasswordForm* form) {
......
...@@ -211,6 +211,15 @@ class NewPasswordFormManager : public PasswordFormManagerInterface, ...@@ -211,6 +211,15 @@ class NewPasswordFormManager : public PasswordFormManagerInterface,
// form. They are owned by |form_fetcher_|. // form. They are owned by |form_fetcher_|.
std::vector<const autofill::PasswordForm*> blacklisted_matches_; std::vector<const autofill::PasswordForm*> blacklisted_matches_;
// If the observed form gets blacklisted through |this|, the blacklist entry
// gets stored in |new_blacklisted_| until data is potentially refreshed by
// reading from PasswordStore again. |blacklisted_matches_| will contain
// |new_blacklisted_.get()| in that case. The PasswordForm will usually get
// accessed via |blacklisted_matches_|, this unique_ptr is only used to store
// it (unlike the rest of forms being pointed to in |blacklisted_matches_|,
// which are owned by |form_fetcher_|).
std::unique_ptr<autofill::PasswordForm> new_blacklisted_;
// Convenience pointer to entry in best_matches_ that is marked // Convenience pointer to entry in best_matches_ that is marked
// as preferred. This is only allowed to be null if there are no best matches // as preferred. This is only allowed to be null if there are no best matches
// at all, since there will always be one preferred login when there are // at all, since there will always be one preferred login when there are
......
...@@ -811,4 +811,21 @@ TEST_F(NewPasswordFormManagerTest, UpdatePasswordToAlreadyExisting) { ...@@ -811,4 +811,21 @@ TEST_F(NewPasswordFormManagerTest, UpdatePasswordToAlreadyExisting) {
EXPECT_FALSE(form_manager_->IsPasswordOverridden()); EXPECT_FALSE(form_manager_->IsPasswordOverridden());
} }
TEST_F(NewPasswordFormManagerTest, PermanentlyBlacklist) {
TestMockTimeTaskRunner::ScopedContext scoped_context(task_runner_.get());
fetcher_->SetNonFederated({}, 0u);
MockFormSaver& form_saver = MockFormSaver::Get(form_manager_.get());
PasswordForm* new_blacklisted_form = nullptr;
EXPECT_CALL(form_saver, PermanentlyBlacklist(_))
.WillOnce(SaveArg<0>(&new_blacklisted_form));
form_manager_->PermanentlyBlacklist();
ASSERT_TRUE(new_blacklisted_form);
EXPECT_EQ(observed_form_.origin, new_blacklisted_form->origin);
EXPECT_EQ(GetSignonRealm(observed_form_.origin),
new_blacklisted_form->signon_realm);
}
} // namespace password_manager } // namespace password_manager
...@@ -331,7 +331,7 @@ class PasswordFormManager : public PasswordFormManagerInterface, ...@@ -331,7 +331,7 @@ class PasswordFormManager : public PasswordFormManagerInterface,
// |new_blacklisted_.get()| in that case. The PasswordForm will usually get // |new_blacklisted_.get()| in that case. The PasswordForm will usually get
// accessed via |blacklisted_matches_|, this unique_ptr is only used to store // accessed via |blacklisted_matches_|, this unique_ptr is only used to store
// it (unlike the rest of forms being pointed to in |blacklisted_matches_|, // it (unlike the rest of forms being pointed to in |blacklisted_matches_|,
// which are owned by |form_fetcher_|. // which are owned by |form_fetcher_|).
std::unique_ptr<autofill::PasswordForm> new_blacklisted_; std::unique_ptr<autofill::PasswordForm> new_blacklisted_;
// The PasswordForm from the page or dialog managed by |this|. // The PasswordForm from the page or dialog managed by |this|.
......
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