Commit fe5c3752 authored by Andrey Zaytsev's avatar Andrey Zaytsev Committed by Commit Bot

Safety check: fixed the password check observer to handle multiple callbacks with the same state

Bug: 1015841
Change-Id: I06627da332ec630cdb5fc6f83544613ea9df7ee8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2115477
Auto-Submit: Andrey Zaytsev <andzaytsev@google.com>
Commit-Queue: Esmael Elmoslimany <aee@chromium.org>
Reviewed-by: default avatarEsmael Elmoslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#752538}
parent ddb7665a
...@@ -512,8 +512,9 @@ void SafetyCheckHandler::OnStateChanged( ...@@ -512,8 +512,9 @@ void SafetyCheckHandler::OnStateChanged(
break; break;
} }
// Stop observing the leak service in all terminal states. // Stop observing the leak service in all terminal states, if it's still being
observed_leak_check_.Remove(leak_service_); // observed.
observed_leak_check_.RemoveAll();
} }
void SafetyCheckHandler::OnCredentialDone( void SafetyCheckHandler::OnCredentialDone(
......
...@@ -575,6 +575,25 @@ TEST_F(SafetyCheckHandlerTest, CheckPasswords_StartedTwice) { ...@@ -575,6 +575,25 @@ TEST_F(SafetyCheckHandlerTest, CheckPasswords_StartedTwice) {
"internet connection."); "internet connection.");
} }
TEST_F(SafetyCheckHandlerTest, CheckPasswords_ObserverNotifiedTwice) {
safety_check_->PerformSafetyCheck();
EXPECT_TRUE(test_passwords_delegate_.StartPasswordCheckTriggered());
static_cast<password_manager::BulkLeakCheckService::Observer*>(
safety_check_.get())
->OnStateChanged(
password_manager::BulkLeakCheckService::State::kServiceError);
// Another notification about the same state change.
static_cast<password_manager::BulkLeakCheckService::Observer*>(
safety_check_.get())
->OnStateChanged(
password_manager::BulkLeakCheckService::State::kServiceError);
const base::DictionaryValue* event =
GetSafetyCheckStatusChangedWithDataIfExists(
kPasswords,
static_cast<int>(SafetyCheckHandler::PasswordsStatus::kError));
ASSERT_TRUE(event);
}
TEST_F(SafetyCheckHandlerTest, CheckPasswords_Safe) { TEST_F(SafetyCheckHandlerTest, CheckPasswords_Safe) {
safety_check_->PerformSafetyCheck(); safety_check_->PerformSafetyCheck();
// First, a "running" change of state. // First, a "running" change of state.
......
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