Commit 378bdf9d authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Passwords] Rename PasswordGenerationState to Manager

The name PasswordGenerationState is kinda misleading. The class does
more than keeping the state of the generation. It also modifies the
underlying password store.

Change-Id: If21a78b11268fe7a4a2d2c8adea9c769bb4351f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1882311Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Vasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Auto-Submit: Mohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709835}
parent 1cf04352
...@@ -139,8 +139,8 @@ jumbo_static_library("browser") { ...@@ -139,8 +139,8 @@ jumbo_static_library("browser") {
"password_form_user_action.h", "password_form_user_action.h",
"password_generation_frame_helper.cc", "password_generation_frame_helper.cc",
"password_generation_frame_helper.h", "password_generation_frame_helper.h",
"password_generation_state.cc", "password_generation_manager.cc",
"password_generation_state.h", "password_generation_manager.h",
"password_leak_history_consumer.cc", "password_leak_history_consumer.cc",
"password_leak_history_consumer.h", "password_leak_history_consumer.h",
"password_list_sorter.cc", "password_list_sorter.cc",
...@@ -532,7 +532,7 @@ source_set("unit_tests") { ...@@ -532,7 +532,7 @@ source_set("unit_tests") {
"password_form_manager_unittest.cc", "password_form_manager_unittest.cc",
"password_form_metrics_recorder_unittest.cc", "password_form_metrics_recorder_unittest.cc",
"password_generation_frame_helper_unittest.cc", "password_generation_frame_helper_unittest.cc",
"password_generation_state_unittest.cc", "password_generation_manager_unittest.cc",
"password_hash_data_unittest.cc", "password_hash_data_unittest.cc",
"password_list_sorter_unittest.cc", "password_list_sorter_unittest.cc",
"password_manager_metrics_recorder_unittest.cc", "password_manager_metrics_recorder_unittest.cc",
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "components/password_manager/core/browser/form_fetcher_impl.h" #include "components/password_manager/core/browser/form_fetcher_impl.h"
#include "components/password_manager/core/browser/form_saver.h" #include "components/password_manager/core/browser/form_saver.h"
#include "components/password_manager/core/browser/password_form_filling.h" #include "components/password_manager/core/browser/password_form_filling.h"
#include "components/password_manager/core/browser/password_generation_state.h" #include "components/password_manager/core/browser/password_generation_manager.h"
#include "components/password_manager/core/browser/password_manager_client.h" #include "components/password_manager/core/browser/password_manager_client.h"
#include "components/password_manager/core/browser/password_manager_driver.h" #include "components/password_manager/core/browser/password_manager_driver.h"
#include "components/password_manager/core/browser/password_manager_util.h" #include "components/password_manager/core/browser/password_manager_util.h"
...@@ -487,8 +487,8 @@ void PasswordFormManager::PasswordNoLongerGenerated() { ...@@ -487,8 +487,8 @@ void PasswordFormManager::PasswordNoLongerGenerated() {
if (!HasGeneratedPassword()) if (!HasGeneratedPassword())
return; return;
generation_state_->PasswordNoLongerGenerated(); generation_manager_->PasswordNoLongerGenerated();
generation_state_.reset(); generation_manager_.reset();
votes_uploader_.set_has_generated_password(false); votes_uploader_.set_has_generated_password(false);
votes_uploader_.set_generated_password_changed(false); votes_uploader_.set_generated_password_changed(false);
metrics_recorder_->SetGeneratedPasswordStatus( metrics_recorder_->SetGeneratedPasswordStatus(
...@@ -496,7 +496,7 @@ void PasswordFormManager::PasswordNoLongerGenerated() { ...@@ -496,7 +496,7 @@ void PasswordFormManager::PasswordNoLongerGenerated() {
} }
bool PasswordFormManager::HasGeneratedPassword() const { bool PasswordFormManager::HasGeneratedPassword() const {
return generation_state_ && generation_state_->HasGeneratedPassword(); return generation_manager_ && generation_manager_->HasGeneratedPassword();
} }
void PasswordFormManager::SetGenerationPopupWasShown( void PasswordFormManager::SetGenerationPopupWasShown(
...@@ -558,7 +558,7 @@ bool PasswordFormManager::UpdateGeneratedPasswordOnUserInput( ...@@ -558,7 +558,7 @@ bool PasswordFormManager::UpdateGeneratedPasswordOnUserInput(
break; break;
} }
} }
base::string16 generated_password = generation_state_->generated_password(); base::string16 generated_password = generation_manager_->generated_password();
if (votes_uploader_.get_generation_element() == field_identifier) { if (votes_uploader_.get_generation_element() == field_identifier) {
generated_password = field_value; generated_password = field_value;
form_data_changed = true; form_data_changed = true;
...@@ -586,9 +586,9 @@ std::unique_ptr<PasswordFormManager> PasswordFormManager::Clone() { ...@@ -586,9 +586,9 @@ std::unique_ptr<PasswordFormManager> PasswordFormManager::Clone() {
// owning one needs to happen explicitly. // owning one needs to happen explicitly.
result->owned_form_fetcher_ = std::move(fetcher); result->owned_form_fetcher_ = std::move(fetcher);
if (generation_state_) { if (generation_manager_) {
result->generation_state_ = result->generation_manager_ =
generation_state_->Clone(result->form_saver_.get()); generation_manager_->Clone(result->form_saver_.get());
} }
// These data members all satisfy: // These data members all satisfy:
...@@ -834,10 +834,10 @@ void PasswordFormManager::OnGeneratedPasswordAccepted( ...@@ -834,10 +834,10 @@ void PasswordFormManager::OnGeneratedPasswordAccepted(
parsed_form->signon_realm = GetSignonRealm(form_data.url); parsed_form->signon_realm = GetSignonRealm(form_data.url);
} }
parsed_form->password_value = password; parsed_form->password_value = password;
generation_state_ = generation_manager_ =
std::make_unique<PasswordGenerationState>(form_saver_.get(), client_); std::make_unique<PasswordGenerationManager>(form_saver_.get(), client_);
generation_state_->GeneratedPasswordAccepted(*parsed_form, *form_fetcher_, generation_manager_->GeneratedPasswordAccepted(*parsed_form, *form_fetcher_,
driver_); driver_);
} }
PasswordFormManager::PasswordFormManager( PasswordFormManager::PasswordFormManager(
...@@ -958,7 +958,7 @@ void PasswordFormManager::CreatePendingCredentials() { ...@@ -958,7 +958,7 @@ void PasswordFormManager::CreatePendingCredentials() {
} }
} }
pending_credentials_.password_value = pending_credentials_.password_value =
HasGeneratedPassword() ? generation_state_->generated_password() HasGeneratedPassword() ? generation_manager_->generated_password()
: password_to_save.first; : password_to_save.first;
pending_credentials_.preferred = true; pending_credentials_.preferred = true;
pending_credentials_.date_last_used = base::Time::Now(); pending_credentials_.date_last_used = base::Time::Now();
...@@ -1094,8 +1094,8 @@ void PasswordFormManager::PresaveGeneratedPasswordInternal( ...@@ -1094,8 +1094,8 @@ void PasswordFormManager::PresaveGeneratedPasswordInternal(
} }
if (!HasGeneratedPassword()) { if (!HasGeneratedPassword()) {
generation_state_ = generation_manager_ =
std::make_unique<PasswordGenerationState>(form_saver_.get(), client_); std::make_unique<PasswordGenerationManager>(form_saver_.get(), client_);
votes_uploader_.set_generated_password_changed(false); votes_uploader_.set_generated_password_changed(false);
metrics_recorder_->SetGeneratedPasswordStatus( metrics_recorder_->SetGeneratedPasswordStatus(
PasswordFormMetricsRecorder::GeneratedPasswordStatus:: PasswordFormMetricsRecorder::GeneratedPasswordStatus::
...@@ -1105,7 +1105,7 @@ void PasswordFormManager::PresaveGeneratedPasswordInternal( ...@@ -1105,7 +1105,7 @@ void PasswordFormManager::PresaveGeneratedPasswordInternal(
// from the presaved one, then mark that the generated password was changed. // from the presaved one, then mark that the generated password was changed.
// If a user recovers the original generated password, it will be recorded // If a user recovers the original generated password, it will be recorded
// as a password change. // as a password change.
if (generation_state_->generated_password() != generated_password) { if (generation_manager_->generated_password() != generated_password) {
votes_uploader_.set_generated_password_changed(true); votes_uploader_.set_generated_password_changed(true);
metrics_recorder_->SetGeneratedPasswordStatus( metrics_recorder_->SetGeneratedPasswordStatus(
PasswordFormMetricsRecorder::GeneratedPasswordStatus:: PasswordFormMetricsRecorder::GeneratedPasswordStatus::
...@@ -1118,7 +1118,7 @@ void PasswordFormManager::PresaveGeneratedPasswordInternal( ...@@ -1118,7 +1118,7 @@ void PasswordFormManager::PresaveGeneratedPasswordInternal(
// generated password is saved. // generated password is saved.
parsed_form->password_value = generated_password; parsed_form->password_value = generated_password;
generation_state_->PresaveGeneratedPassword( generation_manager_->PresaveGeneratedPassword(
std::move(*parsed_form), form_fetcher_->GetAllRelevantMatches()); std::move(*parsed_form), form_fetcher_->GetAllRelevantMatches());
} }
...@@ -1155,7 +1155,7 @@ void PasswordFormManager::SavePendingToStore(bool update) { ...@@ -1155,7 +1155,7 @@ void PasswordFormManager::SavePendingToStore(bool update) {
base::string16 old_password = base::string16 old_password =
saved_form ? saved_form->password_value : base::string16(); saved_form ? saved_form->password_value : base::string16();
if (HasGeneratedPassword()) { if (HasGeneratedPassword()) {
generation_state_->CommitGeneratedPassword( generation_manager_->CommitGeneratedPassword(
pending_credentials_, form_fetcher_->GetAllRelevantMatches(), pending_credentials_, form_fetcher_->GetAllRelevantMatches(),
old_password); old_password);
} else if (update) { } else if (update) {
......
...@@ -30,7 +30,7 @@ namespace password_manager { ...@@ -30,7 +30,7 @@ namespace password_manager {
class FormSaver; class FormSaver;
class PasswordFormMetricsRecorder; class PasswordFormMetricsRecorder;
class PasswordGenerationState; class PasswordGenerationManager;
class PasswordManagerClient; class PasswordManagerClient;
class PasswordManagerDriver; class PasswordManagerDriver;
struct PossibleUsernameData; struct PossibleUsernameData;
...@@ -337,7 +337,7 @@ class PasswordFormManager : public PasswordFormManagerForUI, ...@@ -337,7 +337,7 @@ class PasswordFormManager : public PasswordFormManagerForUI,
bool is_new_login_ = true; bool is_new_login_ = true;
// Handles the user flows related to the generation. // Handles the user flows related to the generation.
std::unique_ptr<PasswordGenerationState> generation_state_; std::unique_ptr<PasswordGenerationManager> generation_manager_;
// Whether a saved password was overridden. The flag is true when there is a // Whether a saved password was overridden. The flag is true when there is a
// credential in the store that will get a new password value. // credential in the store that will get a new password value.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "components/password_manager/core/browser/password_generation_state.h" #include "components/password_manager/core/browser/password_generation_manager.h"
#include <map> #include <map>
#include <utility> #include <utility>
...@@ -182,22 +182,23 @@ const PasswordForm* FindUsernameConflict( ...@@ -182,22 +182,23 @@ const PasswordForm* FindUsernameConflict(
} }
} // namespace } // namespace
PasswordGenerationState::PasswordGenerationState(FormSaver* form_saver, PasswordGenerationManager::PasswordGenerationManager(
PasswordManagerClient* client) FormSaver* form_saver,
PasswordManagerClient* client)
: form_saver_(form_saver), : form_saver_(form_saver),
client_(client), client_(client),
clock_(new base::DefaultClock) {} clock_(new base::DefaultClock) {}
PasswordGenerationState::~PasswordGenerationState() = default; PasswordGenerationManager::~PasswordGenerationManager() = default;
std::unique_ptr<PasswordGenerationState> PasswordGenerationState::Clone( std::unique_ptr<PasswordGenerationManager> PasswordGenerationManager::Clone(
FormSaver* form_saver) const { FormSaver* form_saver) const {
auto clone = std::make_unique<PasswordGenerationState>(form_saver, client_); auto clone = std::make_unique<PasswordGenerationManager>(form_saver, client_);
clone->presaved_ = presaved_; clone->presaved_ = presaved_;
return clone; return clone;
} }
void PasswordGenerationState::GeneratedPasswordAccepted( void PasswordGenerationManager::GeneratedPasswordAccepted(
PasswordForm generated, PasswordForm generated,
const FormFetcher& fetcher, const FormFetcher& fetcher,
base::WeakPtr<PasswordManagerDriver> driver) { base::WeakPtr<PasswordManagerDriver> driver) {
...@@ -217,7 +218,7 @@ void PasswordGenerationState::GeneratedPasswordAccepted( ...@@ -217,7 +218,7 @@ void PasswordGenerationState::GeneratedPasswordAccepted(
GenerationPresaveConflict::kConflictWithEmptyUsername); GenerationPresaveConflict::kConflictWithEmptyUsername);
auto bubble_launcher = std::make_unique<PasswordDataForUI>( auto bubble_launcher = std::make_unique<PasswordDataForUI>(
std::move(generated), matches, fetcher.GetFederatedMatches(), std::move(generated), matches, fetcher.GetFederatedMatches(),
base::BindRepeating(&PasswordGenerationState::OnPresaveBubbleResult, base::BindRepeating(&PasswordGenerationManager::OnPresaveBubbleResult,
weak_factory_.GetWeakPtr(), std::move(driver))); weak_factory_.GetWeakPtr(), std::move(driver)));
client_->PromptUserToSaveOrUpdatePassword(std::move(bubble_launcher), client_->PromptUserToSaveOrUpdatePassword(std::move(bubble_launcher),
true); true);
...@@ -233,7 +234,7 @@ void PasswordGenerationState::GeneratedPasswordAccepted( ...@@ -233,7 +234,7 @@ void PasswordGenerationState::GeneratedPasswordAccepted(
driver->GeneratedPasswordAccepted(generated.password_value); driver->GeneratedPasswordAccepted(generated.password_value);
} }
void PasswordGenerationState::PresaveGeneratedPassword( void PasswordGenerationManager::PresaveGeneratedPassword(
PasswordForm generated, PasswordForm generated,
const std::vector<const PasswordForm*>& matches) { const std::vector<const PasswordForm*>& matches) {
DCHECK(!generated.password_value.empty()); DCHECK(!generated.password_value.empty());
...@@ -253,13 +254,13 @@ void PasswordGenerationState::PresaveGeneratedPassword( ...@@ -253,13 +254,13 @@ void PasswordGenerationState::PresaveGeneratedPassword(
presaved_ = std::move(generated); presaved_ = std::move(generated);
} }
void PasswordGenerationState::PasswordNoLongerGenerated() { void PasswordGenerationManager::PasswordNoLongerGenerated() {
DCHECK(presaved_); DCHECK(presaved_);
form_saver_->Remove(*presaved_); form_saver_->Remove(*presaved_);
presaved_.reset(); presaved_.reset();
} }
void PasswordGenerationState::CommitGeneratedPassword( void PasswordGenerationManager::CommitGeneratedPassword(
PasswordForm generated, PasswordForm generated,
const std::vector<const PasswordForm*>& matches, const std::vector<const PasswordForm*>& matches,
const base::string16& old_password) { const base::string16& old_password) {
...@@ -271,7 +272,7 @@ void PasswordGenerationState::CommitGeneratedPassword( ...@@ -271,7 +272,7 @@ void PasswordGenerationState::CommitGeneratedPassword(
presaved_.value() /* old_primary_key */); presaved_.value() /* old_primary_key */);
} }
void PasswordGenerationState::OnPresaveBubbleResult( void PasswordGenerationManager::OnPresaveBubbleResult(
const base::WeakPtr<PasswordManagerDriver>& driver, const base::WeakPtr<PasswordManagerDriver>& driver,
bool accepted, bool accepted,
const PasswordForm& pending) { const PasswordForm& pending) {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_GENERATION_STATE_H_ #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_GENERATION_MANAGER_H_
#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_GENERATION_STATE_H_ #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_GENERATION_MANAGER_H_
#include <map> #include <map>
#include <memory> #include <memory>
...@@ -20,14 +20,16 @@ class FormSaver; ...@@ -20,14 +20,16 @@ class FormSaver;
class PasswordManagerClient; class PasswordManagerClient;
class PasswordManagerDriver; class PasswordManagerDriver;
class PasswordGenerationState { class PasswordGenerationManager {
public: public:
PasswordGenerationState(FormSaver* form_saver, PasswordManagerClient* client); PasswordGenerationManager(FormSaver* form_saver,
~PasswordGenerationState(); PasswordManagerClient* client);
PasswordGenerationState(const PasswordGenerationState& rhs) = delete; ~PasswordGenerationManager();
PasswordGenerationState& operator=(const PasswordGenerationState&) = delete; PasswordGenerationManager(const PasswordGenerationManager& rhs) = delete;
PasswordGenerationManager& operator=(const PasswordGenerationManager&) =
delete;
std::unique_ptr<PasswordGenerationState> Clone(FormSaver* form_saver) const; std::unique_ptr<PasswordGenerationManager> Clone(FormSaver* form_saver) const;
// Returns true iff the generated password was presaved. // Returns true iff the generated password was presaved.
bool HasGeneratedPassword() const { return presaved_.has_value(); } bool HasGeneratedPassword() const { return presaved_.has_value(); }
...@@ -85,9 +87,9 @@ class PasswordGenerationState { ...@@ -85,9 +87,9 @@ class PasswordGenerationState {
// Interface to get current time. // Interface to get current time.
std::unique_ptr<base::Clock> clock_; std::unique_ptr<base::Clock> clock_;
// Used to produce callbacks. // Used to produce callbacks.
base::WeakPtrFactory<PasswordGenerationState> weak_factory_{this}; base::WeakPtrFactory<PasswordGenerationManager> weak_factory_{this};
}; };
} // namespace password_manager } // namespace password_manager
#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_GENERATION_STATE_H_ #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_GENERATION_MANAGER_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "components/password_manager/core/browser/password_generation_state.h" #include "components/password_manager/core/browser/password_generation_manager.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -117,13 +117,13 @@ bool MockPasswordManagerClient::PromptUserToSaveOrUpdatePassword( ...@@ -117,13 +117,13 @@ bool MockPasswordManagerClient::PromptUserToSaveOrUpdatePassword(
return PromptUserToSaveOrUpdatePasswordMock(update_password); return PromptUserToSaveOrUpdatePasswordMock(update_password);
} }
class PasswordGenerationStateTest : public testing::Test { class PasswordGenerationManagerTest : public testing::Test {
public: public:
PasswordGenerationStateTest(); PasswordGenerationManagerTest();
~PasswordGenerationStateTest() override; ~PasswordGenerationManagerTest() override;
MockPasswordStore& store() { return *mock_store_; } MockPasswordStore& store() { return *mock_store_; }
PasswordGenerationState& state() { return generation_state_; } PasswordGenerationManager& manager() { return generation_manager_; }
FormSaverImpl& form_saver() { return form_saver_; } FormSaverImpl& form_saver() { return form_saver_; }
MockPasswordManagerClient& client() { return client_; } MockPasswordManagerClient& client() { return client_; }
...@@ -139,24 +139,24 @@ class PasswordGenerationStateTest : public testing::Test { ...@@ -139,24 +139,24 @@ class PasswordGenerationStateTest : public testing::Test {
// Test with the real form saver for better robustness. // Test with the real form saver for better robustness.
FormSaverImpl form_saver_; FormSaverImpl form_saver_;
MockPasswordManagerClient client_; MockPasswordManagerClient client_;
PasswordGenerationState generation_state_; PasswordGenerationManager generation_manager_;
}; };
PasswordGenerationStateTest::PasswordGenerationStateTest() PasswordGenerationManagerTest::PasswordGenerationManagerTest()
: mock_store_(new testing::StrictMock<MockPasswordStore>()), : mock_store_(new testing::StrictMock<MockPasswordStore>()),
form_saver_(mock_store_.get()), form_saver_(mock_store_.get()),
generation_state_(&form_saver_, &client_) { generation_manager_(&form_saver_, &client_) {
auto clock = std::make_unique<base::SimpleTestClock>(); auto clock = std::make_unique<base::SimpleTestClock>();
clock->SetNow(base::Time::FromTimeT(kTime)); clock->SetNow(base::Time::FromTimeT(kTime));
generation_state_.set_clock(std::move(clock)); generation_manager_.set_clock(std::move(clock));
} }
PasswordGenerationStateTest::~PasswordGenerationStateTest() { PasswordGenerationManagerTest::~PasswordGenerationManagerTest() {
mock_store_->ShutdownOnUIThread(); mock_store_->ShutdownOnUIThread();
} }
std::unique_ptr<PasswordFormManagerForUI> std::unique_ptr<PasswordFormManagerForUI>
PasswordGenerationStateTest::SetUpOverwritingUI( PasswordGenerationManagerTest::SetUpOverwritingUI(
base::WeakPtr<PasswordManagerDriver> driver) { base::WeakPtr<PasswordManagerDriver> driver) {
PasswordForm generated = CreateGenerated(); PasswordForm generated = CreateGenerated();
PasswordForm saved = CreateSaved(); PasswordForm saved = CreateSaved();
...@@ -169,14 +169,14 @@ PasswordGenerationStateTest::SetUpOverwritingUI( ...@@ -169,14 +169,14 @@ PasswordGenerationStateTest::SetUpOverwritingUI(
EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordMock(true)) EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordMock(true))
.WillOnce(testing::Return(true)); .WillOnce(testing::Return(true));
state().GeneratedPasswordAccepted(std::move(generated), fetcher, manager().GeneratedPasswordAccepted(std::move(generated), fetcher,
std::move(driver)); std::move(driver));
return client_.MoveForm(); return client_.MoveForm();
} }
// Check that accepting a generated password simply relays the message to the // Check that accepting a generated password simply relays the message to the
// driver. // driver.
TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_EmptyStore) { TEST_F(PasswordGenerationManagerTest, GeneratedPasswordAccepted_EmptyStore) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
base::test::ScopedFeatureList scoped_feature_list; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kGenerationNoOverwrites); scoped_feature_list.InitAndEnableFeature(features::kGenerationNoOverwrites);
...@@ -185,9 +185,9 @@ TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_EmptyStore) { ...@@ -185,9 +185,9 @@ TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_EmptyStore) {
FakeFormFetcher fetcher; FakeFormFetcher fetcher;
EXPECT_CALL(driver, GeneratedPasswordAccepted(generated.password_value)); EXPECT_CALL(driver, GeneratedPasswordAccepted(generated.password_value));
state().GeneratedPasswordAccepted(std::move(generated), fetcher, manager().GeneratedPasswordAccepted(std::move(generated), fetcher,
driver.AsWeakPtr()); driver.AsWeakPtr());
EXPECT_FALSE(state().HasGeneratedPassword()); EXPECT_FALSE(manager().HasGeneratedPassword());
histogram_tester.ExpectUniqueSample( histogram_tester.ExpectUniqueSample(
"PasswordGeneration.PresaveConflict", "PasswordGeneration.PresaveConflict",
metrics_util::GenerationPresaveConflict::kNoUsernameConflict, 1); metrics_util::GenerationPresaveConflict::kNoUsernameConflict, 1);
...@@ -196,7 +196,7 @@ TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_EmptyStore) { ...@@ -196,7 +196,7 @@ TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_EmptyStore) {
// In case of accepted password conflicts with an existing username the // In case of accepted password conflicts with an existing username the
// credential can be presaved with an empty one. Thus, no conflict happens and // credential can be presaved with an empty one. Thus, no conflict happens and
// the driver should be notified directly. // the driver should be notified directly.
TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_Conflict) { TEST_F(PasswordGenerationManagerTest, GeneratedPasswordAccepted_Conflict) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
base::test::ScopedFeatureList scoped_feature_list; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kGenerationNoOverwrites); scoped_feature_list.InitAndEnableFeature(features::kGenerationNoOverwrites);
...@@ -208,15 +208,15 @@ TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_Conflict) { ...@@ -208,15 +208,15 @@ TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_Conflict) {
fetcher.SetNonFederated({&saved}); fetcher.SetNonFederated({&saved});
EXPECT_CALL(driver, GeneratedPasswordAccepted(generated.password_value)); EXPECT_CALL(driver, GeneratedPasswordAccepted(generated.password_value));
state().GeneratedPasswordAccepted(std::move(generated), fetcher, manager().GeneratedPasswordAccepted(std::move(generated), fetcher,
driver.AsWeakPtr()); driver.AsWeakPtr());
EXPECT_FALSE(state().HasGeneratedPassword()); EXPECT_FALSE(manager().HasGeneratedPassword());
histogram_tester.ExpectUniqueSample( histogram_tester.ExpectUniqueSample(
"PasswordGeneration.PresaveConflict", "PasswordGeneration.PresaveConflict",
metrics_util::GenerationPresaveConflict::kNoConflictWithEmptyUsername, 1); metrics_util::GenerationPresaveConflict::kNoConflictWithEmptyUsername, 1);
} }
TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_UpdateUI) { TEST_F(PasswordGenerationManagerTest, GeneratedPasswordAccepted_UpdateUI) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
base::test::ScopedFeatureList scoped_feature_list; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kGenerationNoOverwrites); scoped_feature_list.InitAndEnableFeature(features::kGenerationNoOverwrites);
...@@ -241,7 +241,7 @@ TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_UpdateUI) { ...@@ -241,7 +241,7 @@ TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_UpdateUI) {
metrics_util::GenerationPresaveConflict::kConflictWithEmptyUsername, 1); metrics_util::GenerationPresaveConflict::kConflictWithEmptyUsername, 1);
} }
TEST_F(PasswordGenerationStateTest, TEST_F(PasswordGenerationManagerTest,
GeneratedPasswordAccepted_UpdateUIDismissed) { GeneratedPasswordAccepted_UpdateUIDismissed) {
base::test::ScopedFeatureList scoped_feature_list; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kGenerationNoOverwrites); scoped_feature_list.InitAndEnableFeature(features::kGenerationNoOverwrites);
...@@ -253,7 +253,7 @@ TEST_F(PasswordGenerationStateTest, ...@@ -253,7 +253,7 @@ TEST_F(PasswordGenerationStateTest,
ui_form->OnNoInteraction(true); ui_form->OnNoInteraction(true);
} }
TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_UpdateUINope) { TEST_F(PasswordGenerationManagerTest, GeneratedPasswordAccepted_UpdateUINope) {
base::test::ScopedFeatureList scoped_feature_list; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kGenerationNoOverwrites); scoped_feature_list.InitAndEnableFeature(features::kGenerationNoOverwrites);
MockPasswordManagerDriver driver; MockPasswordManagerDriver driver;
...@@ -264,7 +264,7 @@ TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_UpdateUINope) { ...@@ -264,7 +264,7 @@ TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_UpdateUINope) {
ui_form->OnNopeUpdateClicked(); ui_form->OnNopeUpdateClicked();
} }
TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_UpdateUINever) { TEST_F(PasswordGenerationManagerTest, GeneratedPasswordAccepted_UpdateUINever) {
base::test::ScopedFeatureList scoped_feature_list; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kGenerationNoOverwrites); scoped_feature_list.InitAndEnableFeature(features::kGenerationNoOverwrites);
MockPasswordManagerDriver driver; MockPasswordManagerDriver driver;
...@@ -275,7 +275,7 @@ TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_UpdateUINever) { ...@@ -275,7 +275,7 @@ TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_UpdateUINever) {
ui_form->OnNeverClicked(); ui_form->OnNeverClicked();
} }
TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_UpdateUISave) { TEST_F(PasswordGenerationManagerTest, GeneratedPasswordAccepted_UpdateUISave) {
base::test::ScopedFeatureList scoped_feature_list; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kGenerationNoOverwrites); scoped_feature_list.InitAndEnableFeature(features::kGenerationNoOverwrites);
MockPasswordManagerDriver driver; MockPasswordManagerDriver driver;
...@@ -288,24 +288,24 @@ TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_UpdateUISave) { ...@@ -288,24 +288,24 @@ TEST_F(PasswordGenerationStateTest, GeneratedPasswordAccepted_UpdateUISave) {
} }
// Check that presaving a password for the first time results in adding it. // Check that presaving a password for the first time results in adding it.
TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_New) { TEST_F(PasswordGenerationManagerTest, PresaveGeneratedPassword_New) {
const PasswordForm generated = CreateGenerated(); const PasswordForm generated = CreateGenerated();
PasswordForm generated_with_date = generated; PasswordForm generated_with_date = generated;
generated_with_date.date_created = base::Time::FromTimeT(kTime); generated_with_date.date_created = base::Time::FromTimeT(kTime);
EXPECT_CALL(store(), AddLogin(generated_with_date)); EXPECT_CALL(store(), AddLogin(generated_with_date));
state().PresaveGeneratedPassword(generated, {}); manager().PresaveGeneratedPassword(generated, {});
EXPECT_TRUE(state().HasGeneratedPassword()); EXPECT_TRUE(manager().HasGeneratedPassword());
} }
// Check that presaving a password for the second time results in updating it. // Check that presaving a password for the second time results in updating it.
TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_Replace) { TEST_F(PasswordGenerationManagerTest, PresaveGeneratedPassword_Replace) {
PasswordForm generated = CreateGenerated(); PasswordForm generated = CreateGenerated();
PasswordForm generated_with_date = generated; PasswordForm generated_with_date = generated;
generated_with_date.date_created = base::Time::FromTimeT(kTime); generated_with_date.date_created = base::Time::FromTimeT(kTime);
EXPECT_CALL(store(), AddLogin(generated_with_date)); EXPECT_CALL(store(), AddLogin(generated_with_date));
state().PresaveGeneratedPassword(generated, {}); manager().PresaveGeneratedPassword(generated, {});
PasswordForm generated_updated = generated; PasswordForm generated_updated = generated;
generated_updated.password_value = ASCIIToUTF16("newgenpwd"); generated_updated.password_value = ASCIIToUTF16("newgenpwd");
...@@ -313,18 +313,18 @@ TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_Replace) { ...@@ -313,18 +313,18 @@ TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_Replace) {
generated_with_date.date_created = base::Time::FromTimeT(kTime); generated_with_date.date_created = base::Time::FromTimeT(kTime);
EXPECT_CALL(store(), UpdateLoginWithPrimaryKey(generated_with_date, EXPECT_CALL(store(), UpdateLoginWithPrimaryKey(generated_with_date,
FormHasUniqueKey(generated))); FormHasUniqueKey(generated)));
state().PresaveGeneratedPassword(generated_updated, {}); manager().PresaveGeneratedPassword(generated_updated, {});
EXPECT_TRUE(state().HasGeneratedPassword()); EXPECT_TRUE(manager().HasGeneratedPassword());
} }
// Check that presaving a password for the third time results in updating it. // Check that presaving a password for the third time results in updating it.
TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_ReplaceTwice) { TEST_F(PasswordGenerationManagerTest, PresaveGeneratedPassword_ReplaceTwice) {
PasswordForm generated = CreateGenerated(); PasswordForm generated = CreateGenerated();
PasswordForm generated_with_date = generated; PasswordForm generated_with_date = generated;
generated_with_date.date_created = base::Time::FromTimeT(kTime); generated_with_date.date_created = base::Time::FromTimeT(kTime);
EXPECT_CALL(store(), AddLogin(generated_with_date)); EXPECT_CALL(store(), AddLogin(generated_with_date));
state().PresaveGeneratedPassword(generated, {}); manager().PresaveGeneratedPassword(generated, {});
PasswordForm generated_updated = generated; PasswordForm generated_updated = generated;
generated_updated.password_value = ASCIIToUTF16("newgenpwd"); generated_updated.password_value = ASCIIToUTF16("newgenpwd");
...@@ -332,7 +332,7 @@ TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_ReplaceTwice) { ...@@ -332,7 +332,7 @@ TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_ReplaceTwice) {
generated_with_date.date_created = base::Time::FromTimeT(kTime); generated_with_date.date_created = base::Time::FromTimeT(kTime);
EXPECT_CALL(store(), UpdateLoginWithPrimaryKey(generated_with_date, EXPECT_CALL(store(), UpdateLoginWithPrimaryKey(generated_with_date,
FormHasUniqueKey(generated))); FormHasUniqueKey(generated)));
state().PresaveGeneratedPassword(generated_updated, {}); manager().PresaveGeneratedPassword(generated_updated, {});
generated = generated_updated; generated = generated_updated;
generated_updated.password_value = ASCIIToUTF16("newgenpwd2"); generated_updated.password_value = ASCIIToUTF16("newgenpwd2");
...@@ -341,13 +341,13 @@ TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_ReplaceTwice) { ...@@ -341,13 +341,13 @@ TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_ReplaceTwice) {
generated_with_date.date_created = base::Time::FromTimeT(kTime); generated_with_date.date_created = base::Time::FromTimeT(kTime);
EXPECT_CALL(store(), UpdateLoginWithPrimaryKey(generated_with_date, EXPECT_CALL(store(), UpdateLoginWithPrimaryKey(generated_with_date,
FormHasUniqueKey(generated))); FormHasUniqueKey(generated)));
state().PresaveGeneratedPassword(generated_updated, {}); manager().PresaveGeneratedPassword(generated_updated, {});
EXPECT_TRUE(state().HasGeneratedPassword()); EXPECT_TRUE(manager().HasGeneratedPassword());
} }
// Check that presaving a password with a known username results in clearing the // Check that presaving a password with a known username results in clearing the
// username. // username.
TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_WithConflict) { TEST_F(PasswordGenerationManagerTest, PresaveGeneratedPassword_WithConflict) {
const PasswordForm generated = CreateGenerated(); const PasswordForm generated = CreateGenerated();
PasswordForm saved = CreateSaved(); PasswordForm saved = CreateSaved();
...@@ -358,30 +358,31 @@ TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_WithConflict) { ...@@ -358,30 +358,31 @@ TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_WithConflict) {
generated_with_date.username_value.clear(); generated_with_date.username_value.clear();
EXPECT_CALL(store(), AddLogin(generated_with_date)); EXPECT_CALL(store(), AddLogin(generated_with_date));
state().PresaveGeneratedPassword(generated, {&saved}); manager().PresaveGeneratedPassword(generated, {&saved});
EXPECT_TRUE(state().HasGeneratedPassword()); EXPECT_TRUE(manager().HasGeneratedPassword());
} }
// Check that presaving a password with an unknown username saves it as is. // Check that presaving a password with an unknown username saves it as is.
TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_WithoutConflict) { TEST_F(PasswordGenerationManagerTest,
PresaveGeneratedPassword_WithoutConflict) {
const PasswordForm generated = CreateGenerated(); const PasswordForm generated = CreateGenerated();
PasswordForm generated_with_date = generated; PasswordForm generated_with_date = generated;
generated_with_date.date_created = base::Time::FromTimeT(kTime); generated_with_date.date_created = base::Time::FromTimeT(kTime);
const PasswordForm saved = CreateSaved(); const PasswordForm saved = CreateSaved();
EXPECT_CALL(store(), AddLogin(generated_with_date)); EXPECT_CALL(store(), AddLogin(generated_with_date));
state().PresaveGeneratedPassword(generated, {&saved}); manager().PresaveGeneratedPassword(generated, {&saved});
EXPECT_TRUE(state().HasGeneratedPassword()); EXPECT_TRUE(manager().HasGeneratedPassword());
} }
// Check that presaving a password followed by a call to save a pending // Check that presaving a password followed by a call to save a pending
// credential (as new) results in replacing the presaved password with the // credential (as new) results in replacing the presaved password with the
// pending one. // pending one.
TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_ThenSaveAsNew) { TEST_F(PasswordGenerationManagerTest, PresaveGeneratedPassword_ThenSaveAsNew) {
const PasswordForm generated = CreateGenerated(); const PasswordForm generated = CreateGenerated();
EXPECT_CALL(store(), AddLogin(_)); EXPECT_CALL(store(), AddLogin(_));
state().PresaveGeneratedPassword(generated, {}); manager().PresaveGeneratedPassword(generated, {});
// User edits after submission. // User edits after submission.
PasswordForm pending = generated; PasswordForm pending = generated;
...@@ -392,15 +393,15 @@ TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_ThenSaveAsNew) { ...@@ -392,15 +393,15 @@ TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_ThenSaveAsNew) {
generated_with_date.date_last_used = base::Time::FromTimeT(kTime); generated_with_date.date_last_used = base::Time::FromTimeT(kTime);
EXPECT_CALL(store(), UpdateLoginWithPrimaryKey(generated_with_date, EXPECT_CALL(store(), UpdateLoginWithPrimaryKey(generated_with_date,
FormHasUniqueKey(generated))); FormHasUniqueKey(generated)));
state().CommitGeneratedPassword(pending, {} /* matches */, manager().CommitGeneratedPassword(pending, {} /* matches */,
base::string16() /* old_password */); base::string16() /* old_password */);
EXPECT_TRUE(state().HasGeneratedPassword()); EXPECT_TRUE(manager().HasGeneratedPassword());
} }
// Check that presaving a password followed by a call to save a pending // Check that presaving a password followed by a call to save a pending
// credential (as update) results in replacing the presaved password with the // credential (as update) results in replacing the presaved password with the
// pending one. // pending one.
TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_ThenUpdate) { TEST_F(PasswordGenerationManagerTest, PresaveGeneratedPassword_ThenUpdate) {
PasswordForm generated = CreateGenerated(); PasswordForm generated = CreateGenerated();
PasswordForm related_password = CreateSaved(); PasswordForm related_password = CreateSaved();
...@@ -426,7 +427,7 @@ TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_ThenUpdate) { ...@@ -426,7 +427,7 @@ TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_ThenUpdate) {
const std::vector<const autofill::PasswordForm*> matches = { const std::vector<const autofill::PasswordForm*> matches = {
&related_password, &related_psl_password, &unrelated_password, &related_password, &related_psl_password, &unrelated_password,
&unrelated_psl_password}; &unrelated_psl_password};
state().PresaveGeneratedPassword(generated, matches); manager().PresaveGeneratedPassword(generated, matches);
generated.username_value = ASCIIToUTF16("username"); generated.username_value = ASCIIToUTF16("username");
PasswordForm generated_with_date = generated; PasswordForm generated_with_date = generated;
...@@ -449,59 +450,60 @@ TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_ThenUpdate) { ...@@ -449,59 +450,60 @@ TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_ThenUpdate) {
unrelated_password_expected.preferred = false; unrelated_password_expected.preferred = false;
EXPECT_CALL(store(), UpdateLogin(unrelated_password_expected)); EXPECT_CALL(store(), UpdateLogin(unrelated_password_expected));
state().CommitGeneratedPassword(generated, matches, manager().CommitGeneratedPassword(generated, matches,
ASCIIToUTF16("old password")); ASCIIToUTF16("old password"));
EXPECT_TRUE(state().HasGeneratedPassword()); EXPECT_TRUE(manager().HasGeneratedPassword());
} }
// Check that removing a presaved password removes the presaved password. // Check that removing a presaved password removes the presaved password.
TEST_F(PasswordGenerationStateTest, PasswordNoLongerGenerated) { TEST_F(PasswordGenerationManagerTest, PasswordNoLongerGenerated) {
PasswordForm generated = CreateGenerated(); PasswordForm generated = CreateGenerated();
EXPECT_CALL(store(), AddLogin(_)); EXPECT_CALL(store(), AddLogin(_));
state().PresaveGeneratedPassword(generated, {}); manager().PresaveGeneratedPassword(generated, {});
generated.date_created = base::Time::FromTimeT(kTime); generated.date_created = base::Time::FromTimeT(kTime);
EXPECT_CALL(store(), RemoveLogin(generated)); EXPECT_CALL(store(), RemoveLogin(generated));
state().PasswordNoLongerGenerated(); manager().PasswordNoLongerGenerated();
EXPECT_FALSE(state().HasGeneratedPassword()); EXPECT_FALSE(manager().HasGeneratedPassword());
} }
// Check that removing the presaved password and then presaving again results in // Check that removing the presaved password and then presaving again results in
// adding the second presaved password as new. // adding the second presaved password as new.
TEST_F(PasswordGenerationStateTest, PasswordNoLongerGenerated_AndPresaveAgain) { TEST_F(PasswordGenerationManagerTest,
PasswordNoLongerGenerated_AndPresaveAgain) {
PasswordForm generated = CreateGenerated(); PasswordForm generated = CreateGenerated();
PasswordForm generated_with_date = generated; PasswordForm generated_with_date = generated;
generated_with_date.date_created = base::Time::FromTimeT(kTime); generated_with_date.date_created = base::Time::FromTimeT(kTime);
EXPECT_CALL(store(), AddLogin(generated_with_date)); EXPECT_CALL(store(), AddLogin(generated_with_date));
state().PresaveGeneratedPassword(generated, {}); manager().PresaveGeneratedPassword(generated, {});
EXPECT_CALL(store(), RemoveLogin(generated_with_date)); EXPECT_CALL(store(), RemoveLogin(generated_with_date));
state().PasswordNoLongerGenerated(); manager().PasswordNoLongerGenerated();
generated.username_value = ASCIIToUTF16("newgenusername"); generated.username_value = ASCIIToUTF16("newgenusername");
generated.password_value = ASCIIToUTF16("newgenpwd"); generated.password_value = ASCIIToUTF16("newgenpwd");
generated_with_date = generated; generated_with_date = generated;
generated_with_date.date_created = base::Time::FromTimeT(kTime); generated_with_date.date_created = base::Time::FromTimeT(kTime);
EXPECT_CALL(store(), AddLogin(generated_with_date)); EXPECT_CALL(store(), AddLogin(generated_with_date));
state().PresaveGeneratedPassword(generated, {}); manager().PresaveGeneratedPassword(generated, {});
EXPECT_TRUE(state().HasGeneratedPassword()); EXPECT_TRUE(manager().HasGeneratedPassword());
} }
// Check that presaving a password once in original and then once in clone // Check that presaving a password once in original and then once in clone
// results in the clone calling update, not a fresh save. // results in the clone calling update, not a fresh save.
TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_CloneUpdates) { TEST_F(PasswordGenerationManagerTest, PresaveGeneratedPassword_CloneUpdates) {
PasswordForm generated = CreateGenerated(); PasswordForm generated = CreateGenerated();
PasswordForm generated_with_date = generated; PasswordForm generated_with_date = generated;
generated_with_date.date_created = base::Time::FromTimeT(kTime); generated_with_date.date_created = base::Time::FromTimeT(kTime);
EXPECT_CALL(store(), AddLogin(generated_with_date)); EXPECT_CALL(store(), AddLogin(generated_with_date));
state().PresaveGeneratedPassword(generated, {}); manager().PresaveGeneratedPassword(generated, {});
std::unique_ptr<FormSaver> cloned_saver = form_saver().Clone(); std::unique_ptr<FormSaver> cloned_saver = form_saver().Clone();
std::unique_ptr<PasswordGenerationState> cloned_state = std::unique_ptr<PasswordGenerationManager> cloned_state =
state().Clone(cloned_saver.get()); manager().Clone(cloned_saver.get());
std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); std::unique_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock);
clock->SetNow(base::Time::FromTimeT(kAnotherTime)); clock->SetNow(base::Time::FromTimeT(kAnotherTime));
cloned_state->set_clock(std::move(clock)); cloned_state->set_clock(std::move(clock));
...@@ -518,16 +520,16 @@ TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_CloneUpdates) { ...@@ -518,16 +520,16 @@ TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_CloneUpdates) {
} }
// Check that a clone can still work after the original is destroyed. // Check that a clone can still work after the original is destroyed.
TEST_F(PasswordGenerationStateTest, PresaveGeneratedPassword_CloneSurvives) { TEST_F(PasswordGenerationManagerTest, PresaveGeneratedPassword_CloneSurvives) {
auto original = auto original =
std::make_unique<PasswordGenerationState>(&form_saver(), &client()); std::make_unique<PasswordGenerationManager>(&form_saver(), &client());
const PasswordForm generated = CreateGenerated(); const PasswordForm generated = CreateGenerated();
EXPECT_CALL(store(), AddLogin(_)); EXPECT_CALL(store(), AddLogin(_));
original->PresaveGeneratedPassword(generated, {}); original->PresaveGeneratedPassword(generated, {});
std::unique_ptr<FormSaver> cloned_saver = form_saver().Clone(); std::unique_ptr<FormSaver> cloned_saver = form_saver().Clone();
std::unique_ptr<PasswordGenerationState> cloned_state = std::unique_ptr<PasswordGenerationManager> cloned_state =
original->Clone(cloned_saver.get()); original->Clone(cloned_saver.get());
original.reset(); original.reset();
EXPECT_CALL(store(), UpdateLoginWithPrimaryKey(_, _)); EXPECT_CALL(store(), UpdateLoginWithPrimaryKey(_, _));
......
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