#include "chrome/browser/ui/views/autofill/payments/save_card_bubble_views.h"
#include <memory>
#include <string>
#include "base/callback_list.h"
#include "base/command_line.h"
#include "base/functional/bind.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 "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/autofill/autofill_uitest_util.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/browser/sync/test/integration/secondary_account_helper.h"
#include "chrome/browser/sync/test/integration/sync_service_impl_harness.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/ui/autofill/chrome_autofill_client.h"
#include "chrome/browser/ui/autofill/payments/payments_ui_constants.h"
#include "chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/autofill/payments/dialog_view_ids.h"
#include "chrome/browser/ui/views/autofill/payments/save_payment_icon_view.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_container.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_controller.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_loading_indicator_view.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_view_observer.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/autofill/content/browser/content_autofill_driver.h"
#include "components/autofill/content/browser/test_autofill_manager_injector.h"
#include "components/autofill/core/browser/address_data_manager.h"
#include "components/autofill/core/browser/autofill_experiments.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/browser_autofill_manager.h"
#include "components/autofill/core/browser/form_data_importer.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/credit_card_save_manager.h"
#include "components/autofill/core/browser/payments/payments_network_interface.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/strike_databases/payments/credit_card_save_strike_database.h"
#include "components/autofill/core/browser/test_autofill_clock.h"
#include "components/autofill/core/browser/test_autofill_manager_waiter.h"
#include "components/autofill/core/browser/test_event_waiter.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "components/signin/public/base/signin_buildflags.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/identity_test_utils.h"
#include "components/sync/base/features.h"
#include "components/sync/service/sync_service_impl.h"
#include "components/sync/test/fake_server.h"
#include "components/sync/test/fake_server_network_resources.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/device/public/cpp/test/scoped_geolocation_overrider.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/events/base_event_utils.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/combobox/combobox.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/controls/throbber.h"
#include "ui/views/layout/animating_layout_manager.h"
#include "ui/views/layout/animating_layout_manager_test_util.h"
#include "ui/views/test/ax_event_counter.h"
#include "ui/views/test/button_test_api.h"
#include "ui/views/test/test_widget_observer.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/widget/any_widget_observer.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/non_client_view.h"
#include "url/url_constants.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ui/settings_window_manager_chromeos.h"
#include "chromeos/ash/services/multidevice_setup/public/cpp/prefs.h"
#endif
Bucket;
ElementsAre;
WithParamInterface;
namespace {
const char kCreditCardAndAddressUploadForm[] = …;
const char kCreditCardUploadForm[] = …;
const char kURLGetUploadDetailsRequest[] = …;
const char kResponseGetUploadDetailsSuccess[] = …;
const char kURLUploadCardRequest[] = …;
const char kResponsePaymentsSuccess[] = …;
const char kResponsePaymentsFailure[] = …;
const double kFakeGeolocationLatitude = …;
const double kFakeGeolocationLongitude = …;
}
namespace autofill {
class SaveCardBubbleViewsFullFormBrowserTest
: public SyncTest,
public CreditCardSaveManager::ObserverForTest,
public PageActionIconViewObserver { … };
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Local_ClickingNoThanksClosesBubble) { … }
class SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream
: public SaveCardBubbleViewsFullFormBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
AlertAccessibleEvent) { … }
class SaveCardBubbleViewsFullFormBrowserTestSettings
: public SaveCardBubbleViewsFullFormBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTestSettings,
Local_ManageCardsButtonRedirects) { … }
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Local_SynchronousCloseAfterAsynchronousClose) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
DISABLED_Upload_ClickingSaveClosesBubble) { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
class SaveCardBubbleViewsSyncTransportFullFormBrowserTest
: public SaveCardBubbleViewsFullFormBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsSyncTransportFullFormBrowserTest,
Upload_TransportMode_InfoTextIconExists) { … }
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsSyncTransportFullFormBrowserTest,
Local_TransportMode_InfoTextIconDoesNotExist) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsSyncTransportFullFormBrowserTest,
Upload_TransportMode_RequestedCardholderNameTextfieldIsPrefilledWithFocusName) { … }
class SaveCardBubbleViewsSyncTransportFullFormBrowserTestParameterized
: public SaveCardBubbleViewsSyncTransportFullFormBrowserTest,
public WithParamInterface<bool> { … };
IN_PROC_BROWSER_TEST_P(
SaveCardBubbleViewsSyncTransportFullFormBrowserTestParameterized,
Upload_TransportMode_ClickingSaveAcceptsBubble) { … }
INSTANTIATE_TEST_SUITE_P(…);
#endif
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_NotTransportMode_InfoTextIconDoesNotExist) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_ClickingNoThanksClosesBubble) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_ClickingCloseClosesBubble) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_ShouldNotRequestCardholderNameInHappyPath) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_SubmittingFormWithMissingNamesRequestsCardholderNameIfExpOn) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
DISABLED_Upload_SubmittingFormWithConflictingNamesRequestsCardholderNameIfExpOn) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_SaveButtonIsDisabledIfNoCardholderNameAndCardholderNameRequested) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_RequestedCardholderNameTextfieldIsPrefilledWithFocusName) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_RequestedCardholderNameTextfieldIsNotPrefilledWithFocusNameIfMissing) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Logic_ShouldOfferLocalSaveIfPaymentsDeclines) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Logic_ShouldOfferLocalSaveIfPaymentsFails) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Logic_CanOfferToSaveEvenIfNothingFoundIfPaymentsAccepts) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Logic_CanOfferToSaveDynamicForm) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Logic_ShouldNotOfferToSaveIfNothingFoundAndPaymentsDeclines) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Logic_ShouldAttemptToOfferToSaveIfCvcNotFound) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Logic_ShouldAttemptToOfferToSaveIfInvalidCvcFound) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
DISABLED_Logic_ShouldAttemptToOfferToSaveIfNameNotFound) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Logic_ShouldAttemptToOfferToSaveIfNamesConflict) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Logic_ShouldAttemptToOfferToSaveIfAddressNotFound) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Logic_ShouldAttemptToOfferToSaveIfPostalCodesConflict) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_DecliningUploadDoesNotLogUserAcceptedCardOriginUMA) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_SubmittingFormWithMissingExpirationDateRequestsExpirationDate) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_SubmittingFormWithExpiredExpirationDateRequestsExpirationDate) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_ShouldNotRequestExpirationDateInHappyPath) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_SaveButtonStatusResetBetweenExpirationDateSelectionChanges) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_SaveButtonIsDisabledIfExpiredExpirationDateAndExpirationDateRequested) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
DISABLED_Upload_SubmittingFormWithMissingExpirationDateMonthAndWithValidYear) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
DISABLED_Upload_SubmittingFormWithMissingExpirationDateYearAndWithMonth) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_SubmittingFormWithExpirationDateMonthAndWithYearIsOutOfRange) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_SubmittingFormWithExpirationDateMonthAndYearExpired) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
Upload_SubmittingFormWithExpirationDateMonthAndCurrentYear) { … }
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
StrikeDatabase_Local_AddStrikeIfBubbleDeclined) { … }
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
StrikeDatabase_Local_AddStrikeIfBubbleIgnored) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
StrikeDatabase_Upload_AddStrikeIfBubbleDeclined) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
StrikeDatabase_Upload_AddStrikeIfBubbleIgnored) { … }
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
StrikeDatabase_Local_FullFlowTest) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
StrikeDatabase_Upload_FullFlowTest) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
LocalCardHasNickname) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
LocalCardHasNoNickname) { … }
class SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstreamParameterized
: public SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
public WithParamInterface<bool> { … };
IN_PROC_BROWSER_TEST_P(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstreamParameterized,
Upload_CardholderNameRequested_SubmittingChangedValueLogsEditedMetric) { … }
IN_PROC_BROWSER_TEST_P(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstreamParameterized,
Upload_CardholderNameRequested_SubmittingPrefilledValueLogsUneditedMetric) { … }
IN_PROC_BROWSER_TEST_P(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstreamParameterized,
Upload_EnteringCardholderNameAndClickingSaveAcceptsBubbleIfCardholderNameRequested) { … }
INSTANTIATE_TEST_SUITE_P(…);
class SaveCardBubbleViewsFullFormBrowserTestWithLoadingAndConfirmation
: public SaveCardBubbleViewsFullFormBrowserTest { … };
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithLoadingAndConfirmation,
Upload_ClickingSave_ShowsLoadingView) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithLoadingAndConfirmation,
Local_ClickingSave_ClosesBubble) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithLoadingAndConfirmation,
Upload_InProgress_ShowsLoadingView) { … }
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Local_ClickingSaveClosesBubble) { … }
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Local_ClickingIconShowsManageCards) { … }
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Local_ManageCardsDoneButtonClosesBubble) { … }
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
IconViewAccessibleName) { … }
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTestWithAutofillUpstream,
UploadBubble_CheckForAccountChipFooter) { … }
}