Commit 1b80aef0 authored by Milica Selakovic's avatar Milica Selakovic Committed by Commit Bot

[Password check] Fix a bug with password check never starts the check

This CL makes sure that:
- flags are reset properly
- `kKnownCredentialsFetched` value is correct if already known
compromised credentials were loaded during scripts refreshment.

Bug: 1127856

Change-Id: Ia63cfd21de34bdb39265de2da81056d3966f7dc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410022
Commit-Queue: Milica Selakovic <selakovic@google.com>
Reviewed-by: default avatarIoana Pandele <ioanap@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806726}
parent 685843db
......@@ -306,7 +306,6 @@ void PasswordCheckManager::RefreshScripts() {
FulfillPrecondition(kScriptsCachePrewarmed);
return;
}
ResetPrecondition(kScriptsCachePrewarmed);
password_script_fetcher_->RefreshScriptsIfNecessary(base::BindOnce(
&PasswordCheckManager::OnScriptsFetched, base::Unretained(this)));
......@@ -318,13 +317,11 @@ void PasswordCheckManager::OnScriptsFetched() {
// Inform the UI about compromised credentials another time because it was
// not allowed to generate UI before the availability of password scripts is
// known.
FulfillPrecondition(kKnownCredentialsFetched);
observer_->OnCompromisedCredentialsChanged(
credentials_count_to_notify_.value());
credentials_count_to_notify_.reset();
}
if (was_start_requested_)
StartCheck();
}
bool PasswordCheckManager::ShouldOfferAutomaticPasswordChange() const {
......@@ -353,5 +350,5 @@ void PasswordCheckManager::FulfillPrecondition(CheckPreconditions condition) {
}
void PasswordCheckManager::ResetPrecondition(CheckPreconditions condition) {
fulfilled_preconditions_ &= !condition;
fulfilled_preconditions_ &= ~condition;
}
......@@ -299,6 +299,39 @@ TEST_F(PasswordCheckManagerTest, RunCheckAfterLastInitialization) {
EXPECT_NE(0.0, manager().GetLastCheckTimestamp().ToDoubleT());
}
TEST_F(PasswordCheckManagerTest,
RunCheckAfterLastInitializationAutomaticChangeOn) {
// Enable password sync
sync_service().SetActiveDataTypes(syncer::ModelTypeSet(syncer::PASSWORDS));
feature_list().InitAndEnableFeature(
password_manager::features::kPasswordChangeInSettings);
EXPECT_CALL(mock_observer(), OnPasswordCheckStatusChanged).Times(AtLeast(1));
EXPECT_CALL(mock_observer(), OnSavedPasswordsFetched(1));
store().AddLogin(MakeSavedPassword(kExampleCom, kUsername1));
InitializeManager();
// Initialization is incomplete, so check shouldn't run.
manager().StartCheck(); // Try to start a check — has no immediate effect.
service()->set_state_and_notify(State::kIdle);
// Since check hasn't started, the last completion time should remain 0.
EXPECT_EQ(0.0, manager().GetLastCheckTimestamp().ToDoubleT());
// Fetch scripts availability.
EXPECT_CALL(fetcher(), RefreshScriptsIfNecessary)
.WillOnce(Invoke(
[](base::OnceClosure callback) { std::move(callback).Run(); }));
manager().RefreshScripts();
// Complete pending initialization. The check should run now.
EXPECT_CALL(mock_observer(), OnCompromisedCredentialsChanged(0))
.Times(AtLeast(1));
RunUntilIdle();
service()->set_state_and_notify(State::kIdle); // Complete check, if any.
// Check should have started and the last completion time be non-zero.
EXPECT_NE(0.0, manager().GetLastCheckTimestamp().ToDoubleT());
}
TEST_F(PasswordCheckManagerTest, CorrectlyCreatesUIStructForSiteCredential) {
InitializeManager();
store().AddLogin(MakeSavedPassword(kExampleCom, kUsername1));
......
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