Commit 7fc4aad6 authored by siashah's avatar siashah Committed by Commit Bot

Set the card issuer for the credit card from sync response

The card issuer was added to CreditCard class in crrev.com/c/2145970.

Please refer to the bug for the design doc.

Bug: 1063426
Change-Id: Ifec43187879f3be9f0a5196bdbada0db5fd8f786
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2166133Reviewed-by: default avatarJan Krcal <jkrcal@chromium.org>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Commit-Queue: Siddharth Shah <siashah@chromium.org>
Cr-Commit-Position: refs/heads/master@{#763501}
parent d10e962b
......@@ -98,6 +98,8 @@ CreditCard CardFromSpecifics(const sync_pb::WalletMaskedCreditCard& card) {
result.SetExpirationMonth(card.exp_month());
result.SetExpirationYear(card.exp_year());
result.set_billing_address_id(card.billing_address_id());
result.set_card_issuer(
static_cast<CreditCard::Issuer>(card.card_issuer().issuer()));
if (!card.nickname().empty())
result.SetNickname(base::UTF8ToUTF16(card.nickname()));
return result;
......@@ -242,6 +244,8 @@ void SetAutofillWalletSpecificsFromServerCard(
wallet_card->set_exp_year(card.expiration_year());
if (!card.nickname().empty())
wallet_card->set_nickname(base::UTF16ToUTF8(card.nickname()));
wallet_card->mutable_card_issuer()->set_issuer(
static_cast<sync_pb::CardIssuer::Issuer>(card.card_issuer()));
}
void SetAutofillWalletSpecificsFromPaymentsCustomerData(
......
......@@ -73,27 +73,38 @@ TEST_F(AutofillSyncBridgeUtilTest, PopulateWalletTypesFromSyncData) {
address_id,
SpecificsToEntity(CreateAutofillWalletSpecificsForAddress(address_id),
/*client_tag=*/"address-address1")));
// Add two credit cards.
std::string credit_card_id_1 = "credit_card_1";
std::string credit_card_id_2 = "credit_card_2";
// Add the first card that has its billing address id set to the address's id.
// No nickname is set.
entity_data.push_back(EntityChange::CreateAdd(
"card_with_billing_address_id",
SpecificsToEntity(CreateAutofillWalletSpecificsForCard(
/*id=*/"card_with_billing_address_id",
/*billing_address_id=*/address_id),
/*client_tag=*/"card-card1")));
sync_pb::AutofillWalletSpecifics wallet_specifics_card1 =
CreateAutofillWalletSpecificsForCard(
/*id=*/credit_card_id_1,
/*billing_address_id=*/address_id);
// Add the second card that has nickname.
std::string nickname("Grocery card");
sync_pb::AutofillWalletSpecifics wallet_specifics_card2 =
CreateAutofillWalletSpecificsForCard(
/*id=*/credit_card_id_2,
/*billing_address_id=*/"", /*nickname=*/nickname);
// Set the second card's issuer to GOOGLE.
wallet_specifics_card2.mutable_masked_card()
->mutable_card_issuer()
->set_issuer(sync_pb::CardIssuer::GOOGLE);
entity_data.push_back(EntityChange::CreateAdd(
credit_card_id_1,
SpecificsToEntity(wallet_specifics_card1, /*client_tag=*/"card-card1")));
entity_data.push_back(EntityChange::CreateAdd(
"card_with_nickname",
SpecificsToEntity(CreateAutofillWalletSpecificsForCard(
/*id=*/"card_with_nickname",
/*billing_address_id=*/"", /*nickname=*/nickname),
/*client_tag=*/"card-card2")));
credit_card_id_2,
SpecificsToEntity(wallet_specifics_card2, /*client_tag=*/"card-card2")));
// Add payments customer data.
entity_data.push_back(EntityChange::CreateAdd(
"deadbeef",
SpecificsToEntity(CreateAutofillWalletSpecificsForPaymentsCustomerData(
/*specifics_id=*/"deadbeef"),
/*client_tag=*/"customer-deadbeef")));
// Add cloud token data.
entity_data.push_back(EntityChange::CreateAdd(
"data1", SpecificsToEntity(
CreateAutofillWalletSpecificsForCreditCardCloudTokenData(
......@@ -123,6 +134,10 @@ TEST_F(AutofillSyncBridgeUtilTest, PopulateWalletTypesFromSyncData) {
// Make sure the second card's nickname is correctly populated from sync data.
EXPECT_EQ(base::UTF8ToUTF16(nickname), wallet_cards.back().nickname());
// Verify that the card_issuer is set correctly.
EXPECT_EQ(wallet_cards.front().card_issuer(), CreditCard::ISSUER_UNKNOWN);
EXPECT_EQ(wallet_cards.back().card_issuer(), CreditCard::GOOGLE);
}
// Verify that the billing address id from the card saved on disk is kept if it
......
......@@ -403,6 +403,8 @@ TEST_F(AutofillWalletSyncBridgeTest,
AutofillProfile address2 = test::GetServerProfile2();
table()->SetServerProfiles({address1, address2});
CreditCard card1 = test::GetMaskedServerCard();
// Set the card issuer to Google.
card1.set_card_issuer(CreditCard::Issuer::GOOGLE);
CreditCard card2 = test::GetMaskedServerCardAmex();
CreditCard card_with_nickname = test::GetMaskedServerCardWithNickname();
table()->SetServerCreditCards({card1, card2, card_with_nickname});
......@@ -437,6 +439,10 @@ TEST_F(AutofillWalletSyncBridgeTest,
// correctly before we compare with local table.
EXPECT_FALSE(card_specifics_with_nickname.masked_card().nickname().empty());
EXPECT_TRUE(card_specifics2.masked_card().nickname().empty());
EXPECT_EQ(sync_pb::CardIssuer::GOOGLE,
card_specifics1.masked_card().card_issuer().issuer());
EXPECT_EQ(sync_pb::CardIssuer::ISSUER_UNKNOWN,
card_specifics2.masked_card().card_issuer().issuer());
// Read local Wallet Data from Autofill table, and compare with expected
// wallet specifics.
EXPECT_THAT(
......@@ -847,6 +853,8 @@ TEST_F(AutofillWalletSyncBridgeTest, MergeSyncData_SetsAllWalletCardData) {
// Create a card to be synced from the server.
CreditCard card = test::GetMaskedServerCard();
card.SetNickname(base::ASCIIToUTF16("Grocery card"));
// Set the card issuer to Google.
card.set_card_issuer(CreditCard::Issuer::GOOGLE);
AutofillWalletSpecifics card_specifics;
SetAutofillWalletSpecificsFromServerCard(card, &card_specifics);
......@@ -871,6 +879,7 @@ TEST_F(AutofillWalletSyncBridgeTest, MergeSyncData_SetsAllWalletCardData) {
EXPECT_EQ(card.expiration_year(), cards[0]->expiration_year());
EXPECT_EQ(card.billing_address_id(), cards[0]->billing_address_id());
EXPECT_EQ(card.nickname(), cards[0]->nickname());
EXPECT_EQ(card.card_issuer(), cards[0]->card_issuer());
// Also make sure that those types are not empty, to exercice all the code
// paths.
......
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