#include "chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.h"
#include <stddef.h>
#include <string>
#include <tuple>
#include <utility>
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/metrics/user_action_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/ui/autofill/autofill_bubble_base.h"
#include "chrome/browser/ui/autofill/payments/save_card_ui.h"
#include "chrome/browser/ui/autofill/payments/save_payment_icon_controller.h"
#include "chrome/browser/ui/autofill/test/test_autofill_bubble_handler.h"
#include "chrome/browser/ui/hats/mock_trust_safety_sentiment_service.h"
#include "chrome/browser/ui/hats/trust_safety_sentiment_service_factory.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/metrics/autofill_metrics.h"
#include "components/autofill/core/browser/metrics/payments/credit_card_save_metrics.h"
#include "components/autofill/core/browser/metrics/payments/manage_cards_prompt_metrics.h"
#include "components/autofill/core/browser/payments/payments_autofill_client.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/test_autofill_clock.h"
#include "components/autofill/core/browser/test_personal_data_manager.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/test/mock_navigation_handle.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
Bucket;
ElementsAre;
namespace autofill {
CardSaveType;
SaveCreditCardOptions;
namespace {
const base::Time kArbitraryTime = …;
std::unique_ptr<KeyedService> BuildTestPersonalDataManager(
content::BrowserContext* context) { … }
}
class ObserveHideTestAutofillBubble : public AutofillBubbleBase { … };
class ExposeBubbleAutofillBubbleHandler : public TestAutofillBubbleHandler { … };
class TestBrowserWindowWithAutofillHandler : public TestBrowserWindow { … };
class TestSaveCardBubbleControllerImpl : public SaveCardBubbleControllerImpl { … };
class SaveCardBubbleControllerImplTest : public BrowserWithTestWindowTest { … };
TEST_F(SaveCardBubbleControllerImplTest, LegalMessageLinesEmptyOnLocalSave) { … }
TEST_F(SaveCardBubbleControllerImplTest,
PropagateShouldRequestNameFromUserWhenFalse) { … }
TEST_F(SaveCardBubbleControllerImplTest,
PropagateShouldRequestNameFromUserWhenTrue) { … }
TEST_F(SaveCardBubbleControllerImplTest,
PropagateShouldRequestExpirationDateFromUserWhenFalse) { … }
TEST_F(SaveCardBubbleControllerImplTest,
PropagateShouldRequestExpirationDateFromUserWhenTrue) { … }
SaveCreditCardPromptResultMetricTestData;
class SaveCreditCardPromptResultMetricTest
: public SaveCardBubbleControllerImplTest,
public testing::WithParamInterface<
SaveCreditCardPromptResultMetricTestData> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(SaveCreditCardPromptResultMetricTest,
EmitsSavePromptResultLocalHasNoCards) { … }
TEST_P(SaveCreditCardPromptResultMetricTest,
EmitsSavePromptResultUploadHasNoCards) { … }
TEST_P(SaveCreditCardPromptResultMetricTest,
EmitsSavePromptResultLocalHasSavedCards) { … }
TEST_P(SaveCreditCardPromptResultMetricTest,
EmitsSavePromptResultUploadHasSavedCards) { … }
SaveCardBubbleSingletonTestData;
class SaveCardBubbleSingletonTest
: public SaveCardBubbleControllerImplTest,
public testing::WithParamInterface<SaveCardBubbleSingletonTestData> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(SaveCardBubbleSingletonTest, OnlyOneActiveBubble) { … }
struct SaveCardOptionParam { … };
const SaveCardOptionParam kSaveCardOptionParam[] = …;
SaveCardBubbleLoggingTestData;
class SaveCardBubbleLoggingTest
: public SaveCardBubbleControllerImplTest,
public ::testing::WithParamInterface<SaveCardBubbleLoggingTestData> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(SaveCardBubbleLoggingTest, Metrics_ShowBubble) { … }
TEST_P(SaveCardBubbleLoggingTest, Metrics_ShowIconOnly) { … }
TEST_P(SaveCardBubbleLoggingTest, Metrics_SaveButton) { … }
TEST_P(SaveCardBubbleLoggingTest, Metrics_CancelButton) { … }
TEST_P(SaveCardBubbleLoggingTest, Metrics_Closed) { … }
TEST_P(SaveCardBubbleLoggingTest, Metrics_NotInteracted) { … }
TEST_P(SaveCardBubbleLoggingTest, Metrics_LostFocus) { … }
TEST_P(SaveCardBubbleLoggingTest, Metrics_Unknown) { … }
TEST_P(SaveCardBubbleLoggingTest, Metrics_LegalMessageLinkedClicked) { … }
class SaveCvcBubbleLoggingTest
: public SaveCardBubbleControllerImplTest,
public testing::WithParamInterface<std::tuple<std::string, std::string>> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(SaveCvcBubbleLoggingTest, Metrics_ShowBubble) { … }
TEST_P(SaveCvcBubbleLoggingTest, Metrics_ShowIconOnly) { … }
TEST_P(SaveCvcBubbleLoggingTest, Metrics_SaveButton) { … }
TEST_P(SaveCvcBubbleLoggingTest, Metrics_CancelButton) { … }
TEST_P(SaveCvcBubbleLoggingTest, Metrics_Closed) { … }
TEST_P(SaveCvcBubbleLoggingTest, Metrics_NotInteracted) { … }
TEST_P(SaveCvcBubbleLoggingTest, Metrics_LostFocus) { … }
TEST_P(SaveCvcBubbleLoggingTest, Metrics_Unknown) { … }
TEST_F(SaveCardBubbleControllerImplTest, LocalCvcOnlySaveDialogContent) { … }
TEST_F(SaveCardBubbleControllerImplTest, UploadCardSaveBubbleType) { … }
TEST_F(SaveCardBubbleControllerImplTest, UploadCvcOnlySaveDialogContent) { … }
TEST_F(SaveCardBubbleControllerImplTest,
LocalCard_FirstShow_SaveButton_SigninPromo_Close_Reshow_ManageCards) { … }
TEST_F(SaveCardBubbleControllerImplTest,
LocalCvc_FirstShow_SaveButton_SigninPromo_Close_Reshow_ManageCards) { … }
TEST_F(SaveCardBubbleControllerImplTest,
Metrics_Local_ClickManageCardsDoneButton) { … }
TEST_F(SaveCardBubbleControllerImplTest,
Metrics_Local_ClickManageCardsManageCardsButton) { … }
TEST_F(
SaveCardBubbleControllerImplTest,
Metrics_Local_FirstShow_SaveButton_Close_Reshow_Close_Reshow_ManageCards) { … }
TEST_F(
SaveCardBubbleControllerImplTest,
Metrics_Local_FirstShow_SaveButton_SigninPromo_Close_Reshow_ManageCards) { … }
TEST_F(SaveCardBubbleControllerImplTest,
Upload_FirstShow_SaveButton_NoSigninPromo) { … }
TEST_F(SaveCardBubbleControllerImplTest,
Metrics_Upload_FirstShow_SaveButton_NoSigninPromo) { … }
TEST_F(SaveCardBubbleControllerImplTest, Metrics_Upload_FirstShow_ManageCards) { … }
TEST_F(SaveCardBubbleControllerImplTest, Metrics_Upload_LoadingConfirmation) { … }
class SaveCardBubbleControllerImplTestWithCvCStorageAndFilling
: public SaveCardBubbleControllerImplTest { … };
TEST_F(SaveCardBubbleControllerImplTestWithCvCStorageAndFilling,
LocalCardSaveOnlyDialogContent) { … }
TEST_F(SaveCardBubbleControllerImplTestWithCvCStorageAndFilling,
LocalCardSaveWithCvcDialogContent) { … }
TEST_F(SaveCardBubbleControllerImplTestWithCvCStorageAndFilling,
UploadCardSaveWithCvcDialogContent) { … }
class SaveCardBubbleControllerImplTestWithLoadingAndConfirmation
: public SaveCardBubbleControllerImplTest { … };
TEST_F(SaveCardBubbleControllerImplTestWithLoadingAndConfirmation,
Upload_OnSave_ShowConfirmationBubbleView) { … }
TEST_F(SaveCardBubbleControllerImplTestWithLoadingAndConfirmation,
Upload_OnShowConfirmation_ShowFailureUIModel) { … }
TEST_F(SaveCardBubbleControllerImplTestWithLoadingAndConfirmation,
Upload_OnShowConfirmationBubbleView_ThenShowUploadView) { … }
TEST_F(SaveCardBubbleControllerImplTestWithLoadingAndConfirmation,
Metrics_Upload_AfterSave_OnClose) { … }
TEST_F(SaveCardBubbleControllerImplTestWithLoadingAndConfirmation,
Metrics_Upload_AfterFailedSave_OnClose) { … }
TEST_F(SaveCardBubbleControllerImplTestWithLoadingAndConfirmation,
Metrics_Upload_DuringSave_OnClose) { … }
TEST_F(SaveCardBubbleControllerImplTestWithLoadingAndConfirmation,
Metrics_Local_OnSave) { … }
TEST_F(SaveCardBubbleControllerImplTestWithLoadingAndConfirmation,
VisibilityChange_Upload_HideBubble) { … }
TEST_F(SaveCardBubbleControllerImplTestWithLoadingAndConfirmation,
VisibilityChange_Upload_ReshowAfterLinkClick) { … }
TEST_F(SaveCardBubbleControllerImplTestWithLoadingAndConfirmation,
VisibilityChange_Upload_InProgressState_Retained) { … }
TEST_F(SaveCardBubbleControllerImplTestWithLoadingAndConfirmation,
VisibilityChange_Upload_InProgressStateTransitionIntoCompletedState) { … }
TEST_F(SaveCardBubbleControllerImplTestWithLoadingAndConfirmation,
Metrics_VisibilityChange_Upload_ReshowAfterLinkClick) { … }
TEST_F(SaveCardBubbleControllerImplTestWithLoadingAndConfirmation,
HideSaveCardBubble) { … }
TEST_F(SaveCardBubbleControllerImplTestWithLoadingAndConfirmation,
OnConfirmationPromptClosedByUser_RunCallback) { … }
TEST_F(SaveCardBubbleControllerImplTestWithLoadingAndConfirmation,
OnConfirmationPromptAutoClosed_RunCallback) { … }
UploadCardUpdatedDesktopUiTestData;
class UploadCardUpdatedDesktopUiTest
: public SaveCardBubbleControllerImplTest,
public testing::WithParamInterface<UploadCardUpdatedDesktopUiTestData> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(UploadCardUpdatedDesktopUiTest, ReturnsApplicableWindowTitle) { … }
TEST_P(UploadCardUpdatedDesktopUiTest, ReturnsApplicableExplanatoryMessage) { … }
}