1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/autofill/core/browser/payments/autofill_save_card_infobar_delegate_mobile.h"
#include <memory>
#include <optional>
#include <variant>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/test/metrics/histogram_tester.h"
#include "build/branding_buildflags.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/ui/android/autofill/autofill_save_card_delegate_android.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/autofill/core/browser/data_manager/payments/payments_data_manager.h"
#include "components/autofill/core/browser/data_manager/personal_data_manager.h"
#include "components/autofill/core/browser/data_manager/test_personal_data_manager.h"
#include "components/autofill/core/browser/metrics/payments/credit_card_save_metrics.h"
#include "components/autofill/core/browser/payments/payments_autofill_client.h"
#include "components/autofill/core/browser/test_utils/autofill_test_utils.h"
#include "components/browser_ui/device_lock/android/device_lock_bridge.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::_;
namespace autofill {
namespace {
class TestDeviceLockBridge : public DeviceLockBridge {
public:
TestDeviceLockBridge() = default;
TestDeviceLockBridge(const TestDeviceLockBridge&) = delete;
TestDeviceLockBridge& operator=(const TestDeviceLockBridge&) = delete;
bool ShouldShowDeviceLockUi() override { return false; }
};
using CardSaveType = payments::PaymentsAutofillClient::CardSaveType;
using SaveCreditCardOptions =
payments::PaymentsAutofillClient::SaveCreditCardOptions;
class AutofillSaveCardInfoBarDelegateMobileTest
: public ChromeRenderViewHostTestHarness {
public:
struct CreateDelegateOptions {
int logo_icon_id = -1;
std::u16string title_text;
std::u16string confirm_text;
std::u16string cancel_text;
std::u16string description_text;
bool is_google_pay_branding_enabled = false;
};
AutofillSaveCardInfoBarDelegateMobileTest();
AutofillSaveCardInfoBarDelegateMobileTest(
const AutofillSaveCardInfoBarDelegateMobileTest&) = delete;
AutofillSaveCardInfoBarDelegateMobileTest& operator=(
const AutofillSaveCardInfoBarDelegateMobileTest&) = delete;
~AutofillSaveCardInfoBarDelegateMobileTest() override;
void SetUp() override;
void TearDown() override;
protected:
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile> CreateDelegate(
bool is_uploading,
CreditCard credit_card = CreditCard());
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile> CreateDelegate(
CreateDelegateOptions options);
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile>
CreateDelegateWithLegalMessage(
bool is_uploading,
std::string legal_message_string,
CreditCard credit_card = CreditCard());
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile>
CreateDelegateWithOptions(bool is_uploading,
SaveCreditCardOptions options,
CreditCard credit_card = CreditCard());
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile>
CreateDelegateWithLegalMessageAndOptions(
bool is_uploading,
std::string legal_message_string,
SaveCreditCardOptions options,
CreditCard credit_card = CreditCard());
void CheckInfobarAcceptReturnValue(ConfirmInfoBarDelegate* infobar_delegate);
std::unique_ptr<TestPersonalDataManager> personal_data_;
private:
void LocalSaveCardPromptCallback(
payments::PaymentsAutofillClient::SaveCardOfferUserDecision
user_decision) {
personal_data_->test_payments_data_manager().SaveImportedCreditCard(
credit_card_to_save_);
}
void UploadSaveCardPromptCallback(
payments::PaymentsAutofillClient::SaveCardOfferUserDecision user_decision,
const payments::PaymentsAutofillClient::UserProvidedCardDetails&
user_provided_card_details) {
personal_data_->test_payments_data_manager().SaveImportedCreditCard(
credit_card_to_save_);
}
CreditCard credit_card_to_save_;
};
AutofillSaveCardInfoBarDelegateMobileTest::
AutofillSaveCardInfoBarDelegateMobileTest() = default;
AutofillSaveCardInfoBarDelegateMobileTest::
~AutofillSaveCardInfoBarDelegateMobileTest() = default;
void AutofillSaveCardInfoBarDelegateMobileTest::SetUp() {
ChromeRenderViewHostTestHarness::SetUp();
PersonalDataManagerFactory::GetInstance()->SetTestingFactory(
profile(), BrowserContextKeyedServiceFactory::TestingFactory());
personal_data_ = std::make_unique<TestPersonalDataManager>();
personal_data_->SetPrefService(profile()->GetPrefs());
}
void AutofillSaveCardInfoBarDelegateMobileTest::TearDown() {
personal_data_.reset();
ChromeRenderViewHostTestHarness::TearDown();
}
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile>
AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate(
bool is_uploading,
CreditCard credit_card) {
return CreateDelegateWithLegalMessage(is_uploading, "", credit_card);
}
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile>
AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate(
CreateDelegateOptions options) {
AutofillSaveCardUiInfo ui_info;
ui_info.logo_icon_id = options.logo_icon_id;
ui_info.title_text = options.title_text;
ui_info.confirm_text = options.confirm_text;
ui_info.cancel_text = options.cancel_text;
ui_info.description_text = options.description_text;
ui_info.is_google_pay_branding_enabled =
options.is_google_pay_branding_enabled;
#if BUILDFLAG(IS_ANDROID)
auto save_card_delegate = std::make_unique<AutofillSaveCardDelegateAndroid>(
(payments::PaymentsAutofillClient::LocalSaveCardPromptCallback)
base::DoNothing(),
SaveCreditCardOptions(), web_contents());
save_card_delegate->SetDeviceLockBridgeForTesting(
std::make_unique<TestDeviceLockBridge>());
#else
auto save_card_delegate = std::make_unique<AutofillSaveCardDelegate>(
(payments::PaymentsAutofillClient::LocalSaveCardPromptCallback)
base::DoNothing(),
SaveCreditCardOptions());
#endif
return std::make_unique<AutofillSaveCardInfoBarDelegateMobile>(
std::move(ui_info), std::move(save_card_delegate));
}
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile>
AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegateWithOptions(
bool is_uploading,
SaveCreditCardOptions options,
CreditCard credit_card) {
return CreateDelegateWithLegalMessageAndOptions(
is_uploading, /* legal_message_string= */ "", options, credit_card);
}
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile>
AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegateWithLegalMessage(
bool is_uploading,
std::string legal_message_string,
CreditCard credit_card) {
return CreateDelegateWithLegalMessageAndOptions(
is_uploading, legal_message_string, SaveCreditCardOptions(), credit_card);
}
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile>
AutofillSaveCardInfoBarDelegateMobileTest::
CreateDelegateWithLegalMessageAndOptions(bool is_uploading,
std::string legal_message_string,
SaveCreditCardOptions options,
CreditCard credit_card) {
LegalMessageLines legal_message_lines;
if (!legal_message_string.empty()) {
std::optional<base::Value> value =
base::JSONReader::Read(legal_message_string);
EXPECT_TRUE(value);
LegalMessageLine::Parse(value->GetDict(), &legal_message_lines,
/*escape_apostrophes=*/true);
}
credit_card_to_save_ = credit_card;
std::variant<payments::PaymentsAutofillClient::LocalSaveCardPromptCallback,
payments::PaymentsAutofillClient::UploadSaveCardPromptCallback>
save_card_callback;
AutofillSaveCardUiInfo ui_info;
if (is_uploading) {
ui_info = AutofillSaveCardUiInfo::CreateForUploadSave(
options, credit_card, legal_message_lines, AccountInfo());
save_card_callback =
base::BindOnce(&AutofillSaveCardInfoBarDelegateMobileTest::
UploadSaveCardPromptCallback,
base::Unretained(this));
} else {
ui_info = AutofillSaveCardUiInfo::CreateForLocalSave(options, credit_card);
save_card_callback = base::BindOnce(
&AutofillSaveCardInfoBarDelegateMobileTest::LocalSaveCardPromptCallback,
base::Unretained(this));
}
#if BUILDFLAG(IS_ANDROID)
auto save_card_delegate = std::make_unique<AutofillSaveCardDelegateAndroid>(
std::move(save_card_callback), options, web_contents());
save_card_delegate->SetDeviceLockBridgeForTesting(
std::make_unique<TestDeviceLockBridge>());
#else
auto save_card_delegate = std::make_unique<AutofillSaveCardDelegate>(
std::move(save_card_callback), options);
#endif
return std::make_unique<AutofillSaveCardInfoBarDelegateMobile>(
std::move(ui_info), std::move(save_card_delegate));
}
void AutofillSaveCardInfoBarDelegateMobileTest::CheckInfobarAcceptReturnValue(
ConfirmInfoBarDelegate* infobar_delegate) {
#if BUILDFLAG(IS_ANDROID)
EXPECT_FALSE(infobar_delegate->Accept());
#else
EXPECT_TRUE(infobar_delegate->Accept());
#endif
}
// Test that local credit card save infobar metrics are logged correctly.
// TODO(crbug.com/40286922) Split metrics tests into smaller test.
TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Local_Main) {
::testing::InSequence dummy;
// Infobar is shown.
{
base::HistogramTester histogram_tester;
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
/* is_uploading= */ false));
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local",
AutofillMetrics::INFOBAR_SHOWN, 1);
}
// Accept the infobar.
{
personal_data_->test_payments_data_manager().ClearCreditCards();
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
/* is_uploading= */ false));
base::HistogramTester histogram_tester;
CheckInfobarAcceptReturnValue(infobar.get());
ASSERT_EQ(1U,
personal_data_->payments_data_manager().GetCreditCards().size());
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local",
AutofillMetrics::INFOBAR_ACCEPTED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Local",
autofill_metrics::SaveCreditCardPromptResult::kAccepted, 1);
}
// Dismiss the infobar.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
/* is_uploading= */ false));
base::HistogramTester histogram_tester;
infobar->InfoBarDismissed();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local",
AutofillMetrics::INFOBAR_DENIED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Local",
autofill_metrics::SaveCreditCardPromptResult::kDenied, 1);
}
// Ignore the infobar.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
/* is_uploading= */ false));
base::HistogramTester histogram_tester;
infobar.reset();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local",
AutofillMetrics::INFOBAR_IGNORED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Local",
autofill_metrics::SaveCreditCardPromptResult::kIgnored, 1);
}
}
// Test that server credit card save infobar metrics are logged correctly.
// TODO(crbug.com/40286922) Split metrics tests into smaller test.
TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Server_Main) {
::testing::InSequence dummy;
// Infobar is shown.
{
base::HistogramTester histogram_tester;
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
/* is_uploading= */ true));
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_SHOWN, 1);
}
// Infobar is still shown when the legal message is successfully parsed.
{
base::HistogramTester histogram_tester;
std::string good_legal_message =
"{"
" \"line\" : [ {"
" \"template\": \"This is the entire message.\""
" } ]"
"}";
std::unique_ptr<ConfirmInfoBarDelegate> infobar(
CreateDelegateWithLegalMessage(
/* is_uploading= */ true, std::move(good_legal_message)));
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_SHOWN, 1);
}
// Accept the infobar.
{
personal_data_->test_payments_data_manager().ClearCreditCards();
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
/* is_uploading= */ true));
base::HistogramTester histogram_tester;
CheckInfobarAcceptReturnValue(infobar.get());
ASSERT_EQ(1U,
personal_data_->payments_data_manager().GetCreditCards().size());
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_ACCEPTED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
autofill_metrics::SaveCreditCardPromptResult::kAccepted, 1);
}
// Accept the infobar which should request an expiration date.
{
personal_data_->test_payments_data_manager().ClearCreditCards();
std::unique_ptr<ConfirmInfoBarDelegate> infobar(
CreateDelegateWithLegalMessageAndOptions(
/* is_uploading= */ true, /* legal_message_string= */ "",
SaveCreditCardOptions()
.with_should_request_expiration_date_from_user(true)));
base::HistogramTester histogram_tester;
CheckInfobarAcceptReturnValue(infobar.get());
ASSERT_EQ(1U,
personal_data_->payments_data_manager().GetCreditCards().size());
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_ACCEPTED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardInfoBar.Server.RequestingExpirationDate",
AutofillMetrics::INFOBAR_ACCEPTED, 1);
// kAccept of "Autofill.CreditCardSaveFlowResult.Server" should only be
// recorded when all data is collected.
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
autofill_metrics::SaveCreditCardPromptResult::kAccepted, 0);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server.RequestingExpirationDate",
autofill_metrics::SaveCreditCardPromptResult::kAccepted, 0);
}
// Accept the infobar which should request a cardholder name.
{
personal_data_->test_payments_data_manager().ClearCreditCards();
std::unique_ptr<ConfirmInfoBarDelegate> infobar(
CreateDelegateWithLegalMessageAndOptions(
/* is_uploading= */ true, /* legal_message_string= */ "",
SaveCreditCardOptions().with_should_request_name_from_user(true)));
base::HistogramTester histogram_tester;
CheckInfobarAcceptReturnValue(infobar.get());
ASSERT_EQ(1U,
personal_data_->payments_data_manager().GetCreditCards().size());
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_ACCEPTED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardInfoBar.Server.RequestingCardholderName",
AutofillMetrics::INFOBAR_ACCEPTED, 1);
// kAccept of "Autofill.CreditCardSaveFlowResult.Server" should only be
// recorded when all data is collected.
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
autofill_metrics::SaveCreditCardPromptResult::kAccepted, 0);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server.RequestingCardholderName",
autofill_metrics::SaveCreditCardPromptResult::kAccepted, 0);
}
// Dismiss the infobar which doesn't request any data from user.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
/* is_uploading= */ true));
base::HistogramTester histogram_tester;
infobar->InfoBarDismissed();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_DENIED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
autofill_metrics::SaveCreditCardPromptResult::kDenied, 1);
}
// Dismiss the infobar which should request an expiration date.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(
CreateDelegateWithLegalMessageAndOptions(
/* is_uploading= */ true, /* legal_message_string= */ "",
SaveCreditCardOptions()
.with_should_request_expiration_date_from_user(true)));
base::HistogramTester histogram_tester;
infobar->InfoBarDismissed();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_DENIED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardInfoBar.Server.RequestingExpirationDate",
AutofillMetrics::INFOBAR_DENIED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
autofill_metrics::SaveCreditCardPromptResult::kDenied, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server.RequestingExpirationDate",
autofill_metrics::SaveCreditCardPromptResult::kDenied, 1);
}
// Dismiss the infobar which should request a cardholder name.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(
CreateDelegateWithLegalMessageAndOptions(
/* is_uploading= */ true, /* legal_message_string= */ "",
SaveCreditCardOptions().with_should_request_name_from_user(true)));
base::HistogramTester histogram_tester;
infobar->InfoBarDismissed();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_DENIED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardInfoBar.Server.RequestingCardholderName",
AutofillMetrics::INFOBAR_DENIED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
autofill_metrics::SaveCreditCardPromptResult::kDenied, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server.RequestingCardholderName",
autofill_metrics::SaveCreditCardPromptResult::kDenied, 1);
}
// Ignore the infobar which doesn't request any data from user.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(
/* is_uploading= */ true));
base::HistogramTester histogram_tester;
infobar.reset();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_IGNORED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
autofill_metrics::SaveCreditCardPromptResult::kIgnored, 1);
}
// Ignore the infobar which should request an expiration date.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(
CreateDelegateWithLegalMessageAndOptions(
/* is_uploading= */ true, /* legal_message_string= */ "",
SaveCreditCardOptions()
.with_should_request_expiration_date_from_user(true)));
base::HistogramTester histogram_tester;
infobar.reset();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_IGNORED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardInfoBar.Server.RequestingExpirationDate",
AutofillMetrics::INFOBAR_IGNORED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
autofill_metrics::SaveCreditCardPromptResult::kIgnored, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server.RequestingExpirationDate",
autofill_metrics::SaveCreditCardPromptResult::kIgnored, 1);
}
// Ignore the infobar which should request a cardholder name.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(
CreateDelegateWithLegalMessageAndOptions(
/* is_uploading= */ true, /* legal_message_string= */ "",
SaveCreditCardOptions().with_should_request_name_from_user(true)));
base::HistogramTester histogram_tester;
infobar.reset();
histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server",
AutofillMetrics::INFOBAR_IGNORED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardInfoBar.Server.RequestingCardholderName",
AutofillMetrics::INFOBAR_IGNORED, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server",
autofill_metrics::SaveCreditCardPromptResult::kIgnored, 1);
histogram_tester.ExpectUniqueSample(
"Autofill.CreditCardSaveFlowResult.Server.RequestingCardholderName",
autofill_metrics::SaveCreditCardPromptResult::kIgnored, 1);
}
}
// Test that CVC-only local save infobar metrics are logged correctly.
// TODO(crbug.com/40286922) Split metrics tests into smaller test.
TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Cvc_Local_Main) {
::testing::InSequence dummy;
// Infobar is shown.
{
base::HistogramTester histogram_tester;
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegateWithOptions(
/* is_uploading= */ false, SaveCreditCardOptions().with_card_save_type(
CardSaveType::kCvcSaveOnly)));
histogram_tester.ExpectUniqueSample("Autofill.CvcInfoBar.Local",
AutofillMetrics::INFOBAR_SHOWN, 1);
}
// Accept the infobar.
{
personal_data_->test_payments_data_manager().ClearCreditCards();
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegateWithOptions(
/* is_uploading= */ false, SaveCreditCardOptions().with_card_save_type(
CardSaveType::kCvcSaveOnly)));
base::HistogramTester histogram_tester;
CheckInfobarAcceptReturnValue(infobar.get());
ASSERT_EQ(1U,
personal_data_->payments_data_manager().GetCreditCards().size());
histogram_tester.ExpectUniqueSample("Autofill.CvcInfoBar.Local",
AutofillMetrics::INFOBAR_ACCEPTED, 1);
}
// Dismiss the infobar.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegateWithOptions(
/* is_uploading= */ false, SaveCreditCardOptions().with_card_save_type(
CardSaveType::kCvcSaveOnly)));
base::HistogramTester histogram_tester;
infobar->InfoBarDismissed();
histogram_tester.ExpectUniqueSample("Autofill.CvcInfoBar.Local",
AutofillMetrics::INFOBAR_DENIED, 1);
}
// Ignore the infobar.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegateWithOptions(
/* is_uploading= */ false, SaveCreditCardOptions().with_card_save_type(
CardSaveType::kCvcSaveOnly)));
base::HistogramTester histogram_tester;
infobar.reset();
histogram_tester.ExpectUniqueSample("Autofill.CvcInfoBar.Local",
AutofillMetrics::INFOBAR_IGNORED, 1);
}
}
// Test that CVC-only upload save infobar metrics are logged correctly.
// TODO(crbug.com/40286922) Split metrics tests into smaller test.
TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Cvc_Server_Main) {
::testing::InSequence dummy;
// Infobar is shown.
{
base::HistogramTester histogram_tester;
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegateWithOptions(
/* is_uploading= */ true, SaveCreditCardOptions().with_card_save_type(
CardSaveType::kCvcSaveOnly)));
histogram_tester.ExpectUniqueSample("Autofill.CvcInfoBar.Upload",
AutofillMetrics::INFOBAR_SHOWN, 1);
}
// Accept the infobar.
{
personal_data_->test_payments_data_manager().ClearCreditCards();
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegateWithOptions(
/* is_uploading= */ true, SaveCreditCardOptions().with_card_save_type(
CardSaveType::kCvcSaveOnly)));
base::HistogramTester histogram_tester;
CheckInfobarAcceptReturnValue(infobar.get());
ASSERT_EQ(1U,
personal_data_->payments_data_manager().GetCreditCards().size());
histogram_tester.ExpectUniqueSample("Autofill.CvcInfoBar.Upload",
AutofillMetrics::INFOBAR_ACCEPTED, 1);
}
// Dismiss the infobar.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegateWithOptions(
/* is_uploading= */ true, SaveCreditCardOptions().with_card_save_type(
CardSaveType::kCvcSaveOnly)));
base::HistogramTester histogram_tester;
infobar->InfoBarDismissed();
histogram_tester.ExpectUniqueSample("Autofill.CvcInfoBar.Upload",
AutofillMetrics::INFOBAR_DENIED, 1);
}
// Ignore the infobar.
{
std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegateWithOptions(
/* is_uploading= */ true, SaveCreditCardOptions().with_card_save_type(
CardSaveType::kCvcSaveOnly)));
base::HistogramTester histogram_tester;
infobar.reset();
histogram_tester.ExpectUniqueSample("Autofill.CvcInfoBar.Upload",
AutofillMetrics::INFOBAR_IGNORED, 1);
}
}
TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, LocalCardHasNickname) {
CreditCard card = test::GetCreditCard();
card.SetNickname(u"Nickname");
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile> delegate =
CreateDelegate(/*is_uploading=*/true, card);
EXPECT_EQ(delegate->card_label(), card.NicknameAndLastFourDigitsForTesting());
}
TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, LocalCardHasNoNickname) {
CreditCard card = test::GetCreditCard();
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile> delegate =
CreateDelegate(/*is_uploading=*/true, card);
EXPECT_EQ(delegate->card_label(), card.NetworkAndLastFourDigits());
}
TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, IsGooglePayBrandingEnabled) {
for (bool param : {true, false}) {
auto delegate = CreateDelegate({
.is_google_pay_branding_enabled = param,
});
EXPECT_EQ(delegate->IsGooglePayBrandingEnabled(), param);
}
}
TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, GetDescriptionText) {
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile> delegate =
CreateDelegate({
.description_text = u"Mock Description Text",
});
EXPECT_EQ(delegate->GetDescriptionText(), u"Mock Description Text");
}
TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, GetIconId) {
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile> delegate =
CreateDelegate({
.logo_icon_id = 123456,
});
EXPECT_EQ(delegate->GetIconId(), 123456);
}
TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, GetMessageText) {
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile> delegate =
CreateDelegate({
.title_text = u"Mock Title Text",
});
EXPECT_EQ(delegate->GetMessageText(), u"Mock Title Text");
}
TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, GetButtonLabelForOkButton) {
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile> delegate =
CreateDelegate({
.confirm_text = u"Mock Confirm Text",
});
EXPECT_EQ(
delegate->GetButtonLabel(
AutofillSaveCardInfoBarDelegateMobile::InfoBarButton::BUTTON_OK),
u"Mock Confirm Text");
}
TEST_F(AutofillSaveCardInfoBarDelegateMobileTest,
GetButtonLabelForCancelButton) {
std::unique_ptr<AutofillSaveCardInfoBarDelegateMobile> delegate =
CreateDelegate({
.cancel_text = u"Mock Cancel Text",
});
EXPECT_EQ(
delegate->GetButtonLabel(
AutofillSaveCardInfoBarDelegateMobile::InfoBarButton::BUTTON_CANCEL),
u"Mock Cancel Text");
}
} // namespace
} // namespace autofill
|