#include "chrome/browser/ui/passwords/bubble_controllers/save_update_bubble_controller.h"
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/functional/bind.h"
#include "base/metrics/histogram_samples.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/simple_test_clock.h"
#include "chrome/browser/password_manager/profile_password_store_factory.h"
#include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/test_signin_client_builder.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/browser/ui/passwords/passwords_model_delegate_mock.h"
#include "chrome/test/base/testing_profile.h"
#include "components/password_manager/core/browser/features/password_manager_features_util.h"
#include "components/password_manager/core/browser/mock_password_feature_manager.h"
#include "components/password_manager/core/browser/password_form_metrics_recorder.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/password_manager/core/browser/password_manager_test_utils.h"
#include "components/password_manager/core/browser/password_store/interactions_stats.h"
#include "components/password_manager/core/browser/password_store/mock_password_store_interface.h"
#include "components/password_manager/core/browser/password_store/mock_smart_bubble_stats_store.h"
#include "components/password_manager/core/common/credential_manager_types.h"
#include "components/password_manager/core/common/password_manager_ui.h"
#include "components/sync/test/test_sync_service.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/web_contents_tester.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_source.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
_;
Eq;
Return;
ReturnRef;
namespace {
constexpr ukm::SourceId kTestSourceId = …;
constexpr char kSiteOrigin[] = …;
constexpr char16_t kUsername[] = …;
constexpr char16_t kUsernameExisting[] = …;
constexpr char16_t kUsernameNew[] = …;
constexpr char16_t kPassword[] = …;
constexpr char16_t kPasswordEdited[] = …;
constexpr char kUIDismissalReasonGeneralMetric[] = …;
constexpr char kUIDismissalReasonSaveMetric[] = …;
constexpr char kUIDismissalReasonUpdateMetric[] = …;
std::unique_ptr<KeyedService> BuildTestSyncService(
content::BrowserContext* context) { … }
void SetupAccountPasswordStore(syncer::TestSyncService* sync_service,
PrefService* pref_service) { … }
}
class SaveUpdateBubbleControllerTest : public ::testing::Test { … };
void SaveUpdateBubbleControllerTest::SetUpWithState(
password_manager::ui::State state,
PasswordBubbleControllerBase::DisplayReason reason) { … }
void SaveUpdateBubbleControllerTest::PretendPasswordWaiting(
PasswordBubbleControllerBase::DisplayReason reason) { … }
void SaveUpdateBubbleControllerTest::PretendUpdatePasswordWaiting() { … }
void SaveUpdateBubbleControllerTest::
DestroyModelAndVerifyControllerExpectations() { … }
void SaveUpdateBubbleControllerTest::DestroyModelExpectReason(
password_manager::metrics_util::UIDismissalReason dismissal_reason) { … }
password_manager::InteractionsStats
SaveUpdateBubbleControllerTest::GetTestStats() { … }
std::vector<std::unique_ptr<password_manager::PasswordForm>>
SaveUpdateBubbleControllerTest::GetCurrentForms() const { … }
TEST_F(SaveUpdateBubbleControllerTest, CloseWithoutInteraction) { … }
TEST_F(SaveUpdateBubbleControllerTest, ClickSaveInLocalStore) { … }
TEST_F(SaveUpdateBubbleControllerTest, ClickSaveInAccountStoreWhileOptedIn) { … }
TEST_F(SaveUpdateBubbleControllerTest, ClickSaveInAccountStoreWhileNotOptedIn) { … }
TEST_F(SaveUpdateBubbleControllerTest, ClickUpdateWhileNotOptedIn) { … }
TEST_F(SaveUpdateBubbleControllerTest, ClickSaveInUpdateState) { … }
TEST_F(SaveUpdateBubbleControllerTest, ClickNever) { … }
TEST_F(SaveUpdateBubbleControllerTest, ClickUpdate) { … }
TEST_F(SaveUpdateBubbleControllerTest, ClickUpdateInSaveState) { … }
TEST_F(SaveUpdateBubbleControllerTest, GetInitialUsername_MatchedUsername) { … }
TEST_F(SaveUpdateBubbleControllerTest, ClickSaveWhenNoCredentialsExisted) { … }
TEST_F(SaveUpdateBubbleControllerTest, ClickSaveWhenCredentialsExisted) { … }
class SaveUpdateBubbleControllerUKMTest
: public SaveUpdateBubbleControllerTest,
public testing::WithParamInterface<
std::tuple<bool ,
bool ,
password_manager::PasswordFormMetricsRecorder::
BubbleDismissalReason>> { … };
TEST_P(SaveUpdateBubbleControllerUKMTest, RecordUKMs) { … }
INSTANTIATE_TEST_SUITE_P(…);
class SaveUpdateBubbleControllerPasswordRevealingTest
: public SaveUpdateBubbleControllerTest,
public testing::WithParamInterface<
std::tuple<bool ,
bool ,
bool ,
PasswordBubbleControllerBase::DisplayReason>> { … };
TEST_P(SaveUpdateBubbleControllerPasswordRevealingTest,
EyeIcon_ReauthForPasswordsRevealing) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST_F(SaveUpdateBubbleControllerTest, PasswordsRevealedReported) { … }
TEST_F(SaveUpdateBubbleControllerTest,
UpdateAccountStoreAffectsTheAccountStore) { … }
TEST_F(SaveUpdateBubbleControllerTest,
UpdateProfileStoreDoesnotAffectTheAccountStore) { … }
TEST_F(SaveUpdateBubbleControllerTest, UpdateBothStoresAffectsTheAccountStore) { … }
TEST_F(SaveUpdateBubbleControllerTest,
SaveInAccountStoreAffectsTheAccountStore) { … }
TEST_F(SaveUpdateBubbleControllerTest,
SaveInProfileStoreDoesntAffectTheAccountStore) { … }
TEST_F(SaveUpdateBubbleControllerTest, NullDelegate) { … }
TEST_F(SaveUpdateBubbleControllerTest, ShowsUpdateEvenIfNoExistingCredential) { … }