Commit ad793ba0 authored by Jan Krcal's avatar Jan Krcal Committed by Commit Bot

[AF] Integration tests for changing additional info for wallet metadata

This CL adds more integration tests; it also fixes a bug that
stopped local changes of billing address and local changes of
has_converted to get propagated to sync.

Bug: 894001
Change-Id: Idd91e6799afd3c936b76ac8b1a6851abc67b5ad7
Reviewed-on: https://chromium-review.googlesource.com/c/1333819Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Commit-Queue: Jan Krcal <jkrcal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608003}
parent fd1a4804
...@@ -423,7 +423,8 @@ IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest, ...@@ -423,7 +423,8 @@ IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest,
InitWithDefaultFeatures(); InitWithDefaultFeatures();
GetFakeServer()->SetWalletData( GetFakeServer()->SetWalletData(
{CreateSyncWalletCard(/*name=*/"card-1", /*last_four=*/"0001"), {CreateSyncWalletCard(/*name=*/"card-1", /*last_four=*/"0001",
kDefaultBillingAddressID),
CreateSyncWalletAddress(/*name=*/"address-1", /*company=*/"Company-1"), CreateSyncWalletAddress(/*name=*/"address-1", /*company=*/"Company-1"),
CreateDefaultSyncPaymentsCustomerData()}); CreateDefaultSyncPaymentsCustomerData()});
ASSERT_TRUE(SetupSync()); ASSERT_TRUE(SetupSync());
...@@ -442,7 +443,8 @@ IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest, ...@@ -442,7 +443,8 @@ IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest,
// Put some completely new data in the sync server. // Put some completely new data in the sync server.
GetFakeServer()->SetWalletData( GetFakeServer()->SetWalletData(
{CreateSyncWalletCard(/*name=*/"new-card", /*last_four=*/"0002"), {CreateSyncWalletCard(/*name=*/"new-card", /*last_four=*/"0002",
kDefaultBillingAddressID),
CreateSyncWalletAddress(/*name=*/"new-address", /*company=*/"Company-2"), CreateSyncWalletAddress(/*name=*/"new-address", /*company=*/"Company-2"),
CreateSyncPaymentsCustomerData(/*customer_id=*/"newid")}); CreateSyncPaymentsCustomerData(/*customer_id=*/"newid")});
...@@ -471,7 +473,8 @@ IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest, ...@@ -471,7 +473,8 @@ IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest,
IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest, EmptyUpdatesAreIgnored) { IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest, EmptyUpdatesAreIgnored) {
InitWithDefaultFeatures(); InitWithDefaultFeatures();
GetFakeServer()->SetWalletData( GetFakeServer()->SetWalletData(
{CreateSyncWalletCard(/*name=*/"card-1", /*last_four=*/"0001"), {CreateSyncWalletCard(/*name=*/"card-1", /*last_four=*/"0001",
kDefaultBillingAddressID),
CreateSyncWalletAddress(/*name=*/"address-1", /*company=*/"Company-1"), CreateSyncWalletAddress(/*name=*/"address-1", /*company=*/"Company-1"),
CreateDefaultSyncPaymentsCustomerData()}); CreateDefaultSyncPaymentsCustomerData()});
ASSERT_TRUE(SetupSync()); ASSERT_TRUE(SetupSync());
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "chrome/browser/sync/test/integration/wallet_helper.h" #include "chrome/browser/sync/test/integration/wallet_helper.h"
#include "components/autofill/core/browser/autofill_profile.h" #include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/credit_card.h" #include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/common/autofill_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace { namespace {
...@@ -18,11 +19,20 @@ using wallet_helper::CreateDefaultSyncPaymentsCustomerData; ...@@ -18,11 +19,20 @@ using wallet_helper::CreateDefaultSyncPaymentsCustomerData;
using wallet_helper::CreateSyncWalletAddress; using wallet_helper::CreateSyncWalletAddress;
using wallet_helper::CreateSyncWalletCard; using wallet_helper::CreateSyncWalletCard;
using wallet_helper::GetCreditCard; using wallet_helper::GetCreditCard;
using wallet_helper::GetLocalProfiles;
using wallet_helper::GetServerCreditCards; using wallet_helper::GetServerCreditCards;
using wallet_helper::GetServerProfiles; using wallet_helper::GetServerProfiles;
using wallet_helper::kDefaultBillingAddressID;
using wallet_helper::UpdateServerAddressMetadata; using wallet_helper::UpdateServerAddressMetadata;
using wallet_helper::UpdateServerCardMetadata; using wallet_helper::UpdateServerCardMetadata;
const char kDifferentBillingAddressId[] = "another address entity ID";
constexpr char kLocalBillingAddressId[] =
"local billing address ID has size 36";
static_assert(sizeof(kLocalBillingAddressId) == autofill::kLocalGuidSize + 1,
"|kLocalBillingAddressId| has to have the right length to be "
"considered a local guid");
class TwoClientWalletSyncTest : public UssWalletSwitchToggler, public SyncTest { class TwoClientWalletSyncTest : public UssWalletSwitchToggler, public SyncTest {
public: public:
TwoClientWalletSyncTest() : SyncTest(TWO_CLIENT) {} TwoClientWalletSyncTest() : SyncTest(TWO_CLIENT) {}
...@@ -47,7 +57,8 @@ IN_PROC_BROWSER_TEST_P(TwoClientWalletSyncTest, UpdateCreditCardMetadata) { ...@@ -47,7 +57,8 @@ IN_PROC_BROWSER_TEST_P(TwoClientWalletSyncTest, UpdateCreditCardMetadata) {
InitWithDefaultFeatures(); InitWithDefaultFeatures();
GetFakeServer()->SetWalletData( GetFakeServer()->SetWalletData(
{CreateSyncWalletCard(/*name=*/"card-1", /*last_four=*/"0001"), {CreateSyncWalletCard(/*name=*/"card-1", /*last_four=*/"0001",
kDefaultBillingAddressID),
CreateSyncWalletAddress(/*name=*/"address-1", /*company=*/"Company-1"), CreateSyncWalletAddress(/*name=*/"address-1", /*company=*/"Company-1"),
CreateDefaultSyncPaymentsCustomerData()}); CreateDefaultSyncPaymentsCustomerData()});
ASSERT_TRUE(SetupSync()); ASSERT_TRUE(SetupSync());
...@@ -79,6 +90,199 @@ IN_PROC_BROWSER_TEST_P(TwoClientWalletSyncTest, UpdateCreditCardMetadata) { ...@@ -79,6 +90,199 @@ IN_PROC_BROWSER_TEST_P(TwoClientWalletSyncTest, UpdateCreditCardMetadata) {
EXPECT_EQ(new_use_date, credit_cards[0]->use_date()); EXPECT_EQ(new_use_date, credit_cards[0]->use_date());
} }
IN_PROC_BROWSER_TEST_P(TwoClientWalletSyncTest, UpdateServerAddressMetadata) {
InitWithDefaultFeatures();
GetFakeServer()->SetWalletData(
{CreateSyncWalletCard(/*name=*/"card-1", /*last_four=*/"0001",
kDefaultBillingAddressID),
CreateSyncWalletAddress(/*name=*/"address-1", /*company=*/"Company-1"),
CreateDefaultSyncPaymentsCustomerData()});
ASSERT_TRUE(SetupSync());
// Grab the current address on the first client.
std::vector<AutofillProfile*> server_addresses = GetServerProfiles(0);
ASSERT_EQ(1u, server_addresses.size());
AutofillProfile address = *server_addresses[0];
// Simulate using it -- increase both its use count and use date.
ASSERT_EQ(1u, address.use_count());
address.set_use_count(2);
base::Time new_use_date = base::Time::Now();
ASSERT_NE(new_use_date, address.use_date());
address.set_use_date(new_use_date);
UpdateServerAddressMetadata(0, address);
// Wait for the change to propagate.
EXPECT_TRUE(AutofillWalletChecker(0, 1).Wait());
server_addresses = GetServerProfiles(1);
EXPECT_EQ(1U, server_addresses.size());
EXPECT_EQ(2u, server_addresses[0]->use_count());
EXPECT_EQ(new_use_date, server_addresses[0]->use_date());
server_addresses = GetServerProfiles(0);
EXPECT_EQ(1U, server_addresses.size());
EXPECT_EQ(2u, server_addresses[0]->use_count());
EXPECT_EQ(new_use_date, server_addresses[0]->use_date());
}
IN_PROC_BROWSER_TEST_P(TwoClientWalletSyncTest,
UpdateCreditCardMetadataWithNewBillingAddressId) {
InitWithDefaultFeatures();
GetFakeServer()->SetWalletData(
{CreateSyncWalletCard(/*name=*/"card-1", /*last_four=*/"0001",
/*billing_address_id=*/""),
CreateDefaultSyncPaymentsCustomerData()});
ASSERT_TRUE(SetupSync());
// Grab the current card on the first client.
std::vector<CreditCard*> credit_cards = GetServerCreditCards(0);
ASSERT_EQ(1U, credit_cards.size());
CreditCard card = *credit_cards[0];
ASSERT_TRUE(card.billing_address_id().empty());
// Update the billing address.
card.set_billing_address_id(kDefaultBillingAddressID);
UpdateServerCardMetadata(0, card);
EXPECT_TRUE(AutofillWalletChecker(0, 1).Wait());
// Make sure both clients have the updated billing_address_id.
credit_cards = GetServerCreditCards(1);
EXPECT_EQ(1U, credit_cards.size());
EXPECT_EQ(kDefaultBillingAddressID, credit_cards[0]->billing_address_id());
credit_cards = GetServerCreditCards(0);
EXPECT_EQ(1U, credit_cards.size());
EXPECT_EQ(kDefaultBillingAddressID, credit_cards[0]->billing_address_id());
}
IN_PROC_BROWSER_TEST_P(TwoClientWalletSyncTest,
UpdateCreditCardMetadataWithChangedBillingAddressId) {
InitWithDefaultFeatures();
GetFakeServer()->SetWalletData(
{CreateSyncWalletCard(/*name=*/"card-1", /*last_four=*/"0001",
kDefaultBillingAddressID),
CreateDefaultSyncPaymentsCustomerData()});
ASSERT_TRUE(SetupSync());
// Grab the current card on the first client.
std::vector<CreditCard*> credit_cards = GetServerCreditCards(0);
ASSERT_EQ(1U, credit_cards.size());
CreditCard card = *credit_cards[0];
// Update the billing address.
ASSERT_EQ(kDefaultBillingAddressID, card.billing_address_id());
card.set_billing_address_id(kDifferentBillingAddressId);
UpdateServerCardMetadata(0, card);
EXPECT_TRUE(AutofillWalletChecker(0, 1).Wait());
// Make sure both clients have the updated billing_address_id.
credit_cards = GetServerCreditCards(1);
EXPECT_EQ(1U, credit_cards.size());
EXPECT_EQ(kDifferentBillingAddressId, credit_cards[0]->billing_address_id());
credit_cards = GetServerCreditCards(0);
EXPECT_EQ(1U, credit_cards.size());
EXPECT_EQ(kDifferentBillingAddressId, credit_cards[0]->billing_address_id());
}
IN_PROC_BROWSER_TEST_P(
TwoClientWalletSyncTest,
UpdateCreditCardMetadataWithChangedBillingAddressId_RemoteToLocal) {
InitWithDefaultFeatures();
GetFakeServer()->SetWalletData(
{CreateSyncWalletCard(/*name=*/"card-1", /*last_four=*/"0001",
kDefaultBillingAddressID),
CreateDefaultSyncPaymentsCustomerData()});
ASSERT_TRUE(SetupSync());
// Grab the current card on the first client.
std::vector<CreditCard*> credit_cards = GetServerCreditCards(0);
ASSERT_EQ(1U, credit_cards.size());
CreditCard card = *credit_cards[0];
ASSERT_EQ(kDefaultBillingAddressID, card.billing_address_id());
// Update the billing address (replace a remote profile by a local profile).
card.set_billing_address_id(kLocalBillingAddressId);
UpdateServerCardMetadata(0, card);
EXPECT_TRUE(AutofillWalletChecker(0, 1).Wait());
// Make sure both clients have the updated billing_address_id (local profile
// wins).
credit_cards = GetServerCreditCards(1);
EXPECT_EQ(1U, credit_cards.size());
EXPECT_EQ(kLocalBillingAddressId, credit_cards[0]->billing_address_id());
credit_cards = GetServerCreditCards(0);
EXPECT_EQ(1U, credit_cards.size());
EXPECT_EQ(kLocalBillingAddressId, credit_cards[0]->billing_address_id());
}
IN_PROC_BROWSER_TEST_P(
TwoClientWalletSyncTest,
UpdateCreditCardMetadataWithChangedBillingAddressId_LocalToRemote) {
InitWithDefaultFeatures();
GetFakeServer()->SetWalletData(
{CreateSyncWalletCard(/*name=*/"card-1", /*last_four=*/"0001",
kLocalBillingAddressId),
CreateDefaultSyncPaymentsCustomerData()});
ASSERT_TRUE(SetupSync());
// Grab the current card on the first client.
std::vector<CreditCard*> credit_cards = GetServerCreditCards(0);
ASSERT_EQ(1U, credit_cards.size());
CreditCard card = *credit_cards[0];
// Update the billing address (replace a local profile by a remote profile).
ASSERT_EQ(kLocalBillingAddressId, card.billing_address_id());
card.set_billing_address_id(kDifferentBillingAddressId);
UpdateServerCardMetadata(0, card);
EXPECT_TRUE(AutofillWalletChecker(0, 1).Wait());
// Make sure both clients have the original billing_address_id (local profile
// wins).
credit_cards = GetServerCreditCards(1);
EXPECT_EQ(1U, credit_cards.size());
EXPECT_EQ(kLocalBillingAddressId, credit_cards[0]->billing_address_id());
credit_cards = GetServerCreditCards(0);
EXPECT_EQ(1U, credit_cards.size());
EXPECT_EQ(kLocalBillingAddressId, credit_cards[0]->billing_address_id());
}
IN_PROC_BROWSER_TEST_P(TwoClientWalletSyncTest,
ServerAddressConvertsToSameLocalAddress) {
InitWithDefaultFeatures();
GetFakeServer()->SetWalletData(
{CreateSyncWalletAddress(/*name=*/"address-1", /*company=*/"Company-1"),
CreateDefaultSyncPaymentsCustomerData()});
ASSERT_TRUE(SetupSync());
// Make sure both have has_converted true.
std::vector<AutofillProfile*> server_addresses = GetServerProfiles(0);
EXPECT_EQ(1u, server_addresses.size());
EXPECT_TRUE(server_addresses[0]->has_converted());
server_addresses = GetServerProfiles(1);
EXPECT_EQ(1U, server_addresses.size());
EXPECT_TRUE(server_addresses[0]->has_converted());
// Make sure they have the same local profile.
std::vector<AutofillProfile*> local_addresses = GetLocalProfiles(0);
EXPECT_EQ(1u, local_addresses.size());
const std::string& guid = local_addresses[0]->guid();
local_addresses = GetLocalProfiles(1);
EXPECT_EQ(1u, local_addresses.size());
EXPECT_EQ(guid, local_addresses[0]->guid());
}
INSTANTIATE_TEST_CASE_P(USS, INSTANTIATE_TEST_CASE_P(USS,
TwoClientWalletSyncTest, TwoClientWalletSyncTest,
::testing::Values(false, true)); ::testing::Values(false, true));
......
...@@ -238,11 +238,14 @@ void UpdateServerAddressMetadata(int profile, ...@@ -238,11 +238,14 @@ void UpdateServerAddressMetadata(int profile,
} }
sync_pb::SyncEntity CreateDefaultSyncWalletCard() { sync_pb::SyncEntity CreateDefaultSyncWalletCard() {
return CreateSyncWalletCard(kDefaultCardID, kDefaultCardLastFour); return CreateSyncWalletCard(kDefaultCardID, kDefaultCardLastFour,
kDefaultBillingAddressID);
} }
sync_pb::SyncEntity CreateSyncWalletCard(const std::string& name, sync_pb::SyncEntity CreateSyncWalletCard(
const std::string& last_four) { const std::string& name,
const std::string& last_four,
const std::string& billing_address_id) {
sync_pb::SyncEntity entity; sync_pb::SyncEntity entity;
entity.set_name(name); entity.set_name(name);
entity.set_id_string(name); entity.set_id_string(name);
...@@ -263,7 +266,9 @@ sync_pb::SyncEntity CreateSyncWalletCard(const std::string& name, ...@@ -263,7 +266,9 @@ sync_pb::SyncEntity CreateSyncWalletCard(const std::string& name,
credit_card->set_name_on_card(kDefaultCardName); credit_card->set_name_on_card(kDefaultCardName);
credit_card->set_status(sync_pb::WalletMaskedCreditCard::VALID); credit_card->set_status(sync_pb::WalletMaskedCreditCard::VALID);
credit_card->set_type(kDefaultCardType); credit_card->set_type(kDefaultCardType);
credit_card->set_billing_address_id(kDefaultBillingAddressID); if (!billing_address_id.empty()) {
credit_card->set_billing_address_id(billing_address_id);
}
return entity; return entity;
} }
...@@ -397,6 +402,12 @@ std::vector<AutofillProfile*> GetServerProfiles(int profile) { ...@@ -397,6 +402,12 @@ std::vector<AutofillProfile*> GetServerProfiles(int profile) {
return pdm->GetServerProfiles(); return pdm->GetServerProfiles();
} }
std::vector<AutofillProfile*> GetLocalProfiles(int profile) {
WaitForPDMToRefresh(profile);
PersonalDataManager* pdm = GetPersonalDataManager(profile);
return pdm->GetProfiles();
}
std::vector<CreditCard*> GetServerCreditCards(int profile) { std::vector<CreditCard*> GetServerCreditCards(int profile) {
WaitForPDMToRefresh(profile); WaitForPDMToRefresh(profile);
PersonalDataManager* pdm = GetPersonalDataManager(profile); PersonalDataManager* pdm = GetPersonalDataManager(profile);
......
...@@ -65,7 +65,8 @@ void UpdateServerAddressMetadata( ...@@ -65,7 +65,8 @@ void UpdateServerAddressMetadata(
sync_pb::SyncEntity CreateDefaultSyncWalletCard(); sync_pb::SyncEntity CreateDefaultSyncWalletCard();
sync_pb::SyncEntity CreateSyncWalletCard(const std::string& name, sync_pb::SyncEntity CreateSyncWalletCard(const std::string& name,
const std::string& last_four); const std::string& last_four,
const std::string& billing_address_id);
sync_pb::SyncEntity CreateSyncPaymentsCustomerData( sync_pb::SyncEntity CreateSyncPaymentsCustomerData(
const std::string& customer_id); const std::string& customer_id);
...@@ -92,6 +93,7 @@ void ExpectDefaultProfileValues(const autofill::AutofillProfile& profile); ...@@ -92,6 +93,7 @@ void ExpectDefaultProfileValues(const autofill::AutofillProfile& profile);
// Load current data from the database of profile |profile|. // Load current data from the database of profile |profile|.
std::vector<autofill::AutofillProfile*> GetServerProfiles(int profile); std::vector<autofill::AutofillProfile*> GetServerProfiles(int profile);
std::vector<autofill::AutofillProfile*> GetLocalProfiles(int profile);
std::vector<autofill::CreditCard*> GetServerCreditCards(int profile); std::vector<autofill::CreditCard*> GetServerCreditCards(int profile);
} // namespace wallet_helper } // namespace wallet_helper
......
...@@ -155,6 +155,28 @@ void ApplyChangesToCache(const syncer::SyncChangeList& changes, ...@@ -155,6 +155,28 @@ void ApplyChangesToCache(const syncer::SyncChangeList& changes,
} }
} }
template <class DataType>
bool AreLocalUseStatsUpdated(const sync_pb::WalletMetadataSpecifics& remote,
const DataType& local) {
return base::checked_cast<size_t>(remote.use_count()) < local.use_count() &&
base::Time::FromInternalValue(remote.use_date()) < local.use_date();
}
bool IsLocalBillingAddressUpdated(
const sync_pb::WalletMetadataSpecifics& remote,
const CreditCard& local) {
std::string remote_billing_address_id;
base::Base64Decode(remote.card_billing_address_id(),
&remote_billing_address_id);
return local.billing_address_id() != remote_billing_address_id;
}
bool IsLocalHasConvertedStatusUpdated(
const sync_pb::WalletMetadataSpecifics& remote,
const AutofillProfile& local) {
return remote.address_has_converted() != local.has_converted();
}
// Merges the metadata of the remote and local versions of the data model. // Merges the metadata of the remote and local versions of the data model.
void MergeCommonMetadata( void MergeCommonMetadata(
const sync_pb::WalletMetadataSpecifics& remote_metadata, const sync_pb::WalletMetadataSpecifics& remote_metadata,
...@@ -513,9 +535,20 @@ void AutofillWalletMetadataSyncableService::AutofillProfileChanged( ...@@ -513,9 +535,20 @@ void AutofillWalletMetadataSyncableService::AutofillProfileChanged(
// Implicitly, we filter out ADD (not in cache) and REMOVE (!data_model()). // Implicitly, we filter out ADD (not in cache) and REMOVE (!data_model()).
DCHECK(change.type() == AutofillProfileChange::UPDATE); DCHECK(change.type() == AutofillProfileChange::UPDATE);
AutofillDataModelUpdated( const sync_pb::WalletMetadataSpecifics& remote =
server_id, sync_pb::WalletMetadataSpecifics::ADDRESS, it->GetSpecifics().wallet_metadata();
it->GetSpecifics().wallet_metadata(), *change.data_model()); const AutofillProfile& local = *change.data_model();
if (!AreLocalUseStatsUpdated(remote, local) &&
!IsLocalHasConvertedStatusUpdated(remote, local)) {
return;
}
SendChangesToSyncServer(syncer::SyncChangeList(
1, syncer::SyncChange(
FROM_HERE, syncer::SyncChange::ACTION_UPDATE,
BuildSyncData(sync_pb::WalletMetadataSpecifics::ADDRESS,
server_id, local))));
} }
} }
...@@ -536,9 +569,19 @@ void AutofillWalletMetadataSyncableService::CreditCardChanged( ...@@ -536,9 +569,19 @@ void AutofillWalletMetadataSyncableService::CreditCardChanged(
// Implicitly, we filter out ADD (not in cache) and REMOVE (!data_model()). // Implicitly, we filter out ADD (not in cache) and REMOVE (!data_model()).
DCHECK(change.type() == AutofillProfileChange::UPDATE); DCHECK(change.type() == AutofillProfileChange::UPDATE);
AutofillDataModelUpdated(server_id, sync_pb::WalletMetadataSpecifics::CARD, const sync_pb::WalletMetadataSpecifics& remote =
it->GetSpecifics().wallet_metadata(), it->GetSpecifics().wallet_metadata();
*change.data_model()); const CreditCard& local = *change.data_model();
if (!AreLocalUseStatsUpdated(remote, local) &&
!IsLocalBillingAddressUpdated(remote, local)) {
return;
}
SendChangesToSyncServer(syncer::SyncChangeList(
1,
syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_UPDATE,
BuildSyncData(sync_pb::WalletMetadataSpecifics::CARD,
server_id, local))));
} }
} }
...@@ -718,18 +761,4 @@ syncer::SyncMergeResult AutofillWalletMetadataSyncableService::MergeData( ...@@ -718,18 +761,4 @@ syncer::SyncMergeResult AutofillWalletMetadataSyncableService::MergeData(
return result; return result;
} }
template <class DataType>
void AutofillWalletMetadataSyncableService::AutofillDataModelUpdated(
const std::string& server_id,
const sync_pb::WalletMetadataSpecifics::Type& type,
const sync_pb::WalletMetadataSpecifics& remote,
const DataType& local) {
if (base::checked_cast<size_t>(remote.use_count()) < local.use_count() &&
base::Time::FromInternalValue(remote.use_date()) < local.use_date()) {
SendChangesToSyncServer(syncer::SyncChangeList(
1, syncer::SyncChange(FROM_HERE, syncer::SyncChange::ACTION_UPDATE,
BuildSyncData(remote.type(), server_id, local))));
}
}
} // namespace autofill } // namespace autofill
...@@ -130,15 +130,6 @@ class AutofillWalletMetadataSyncableService ...@@ -130,15 +130,6 @@ class AutofillWalletMetadataSyncableService
// is not present locally. // is not present locally.
syncer::SyncMergeResult MergeData(const syncer::SyncDataList& sync_data); syncer::SyncMergeResult MergeData(const syncer::SyncDataList& sync_data);
// Sends the autofill data model updates to the sync server if the local
// version is more recent. Used for both profiles and credit cards.
template <class DataType>
void AutofillDataModelUpdated(
const std::string& server_id,
const sync_pb::WalletMetadataSpecifics::Type& type,
const sync_pb::WalletMetadataSpecifics& remote,
const DataType& local);
base::ThreadChecker thread_checker_; base::ThreadChecker thread_checker_;
AutofillWebDataBackend* web_data_backend_; // Weak ref. AutofillWebDataBackend* web_data_backend_; // Weak ref.
ScopedObserver<AutofillWebDataBackend, AutofillWalletMetadataSyncableService> ScopedObserver<AutofillWebDataBackend, AutofillWalletMetadataSyncableService>
......
...@@ -476,8 +476,8 @@ TEST_F(AutofillWalletMetadataSyncableServiceTest, ...@@ -476,8 +476,8 @@ TEST_F(AutofillWalletMetadataSyncableServiceTest,
MergeMetadata(&local_, &remote_); MergeMetadata(&local_, &remote_);
} }
// Verify that lower values of metadata are not sent to the sync server when // Verify that lower or equal values of metadata are not sent to the sync server
// local metadata is updated. // when local metadata is updated.
TEST_F(AutofillWalletMetadataSyncableServiceTest, TEST_F(AutofillWalletMetadataSyncableServiceTest,
DontSendLowerValueToServerOnSingleChange) { DontSendLowerValueToServerOnSingleChange) {
local_.UpdateAddressStats(BuildAddress(kAddr1, 1, 2, true)); local_.UpdateAddressStats(BuildAddress(kAddr1, 1, 2, true));
...@@ -485,8 +485,8 @@ TEST_F(AutofillWalletMetadataSyncableServiceTest, ...@@ -485,8 +485,8 @@ TEST_F(AutofillWalletMetadataSyncableServiceTest,
remote_.UpdateAddressStats(BuildAddress(kAddr1, 1, 2, true)); remote_.UpdateAddressStats(BuildAddress(kAddr1, 1, 2, true));
remote_.UpdateCardStats(BuildCard(kCard1, 3, 4, kAddr1)); remote_.UpdateCardStats(BuildCard(kCard1, 3, 4, kAddr1));
MergeMetadata(&local_, &remote_); MergeMetadata(&local_, &remote_);
AutofillProfile address = BuildAddress(kAddr1, 0, 0, false); AutofillProfile address = BuildAddress(kAddr1, 0, 0, true);
CreditCard card = BuildCard(kCard1, 0, 0, kAddr2); CreditCard card = BuildCard(kCard1, 3, 4, kAddr1);
EXPECT_CALL(local_, SendChangesToSyncServer(_)).Times(0); EXPECT_CALL(local_, SendChangesToSyncServer(_)).Times(0);
...@@ -525,6 +525,35 @@ TEST_F(AutofillWalletMetadataSyncableServiceTest, ...@@ -525,6 +525,35 @@ TEST_F(AutofillWalletMetadataSyncableServiceTest,
CreditCardChange(CreditCardChange::UPDATE, card.guid(), &card)); CreditCardChange(CreditCardChange::UPDATE, card.guid(), &card));
} }
// Verify that other changed metadata elements are sent to the sync server when
// local metadata is updated.
TEST_F(AutofillWalletMetadataSyncableServiceTest,
SendChangedMetadataToServerOnLocalSingleChange) {
local_.UpdateAddressStats(BuildAddress(kAddr1, 1, 2, false));
local_.UpdateCardStats(BuildCard(kCard1, 3, 4, kAddr1));
remote_.UpdateAddressStats(BuildAddress(kAddr1, 1, 2, false));
remote_.UpdateCardStats(BuildCard(kCard1, 3, 4, kAddr1));
MergeMetadata(&local_, &remote_);
AutofillProfile address = BuildAddress(kAddr1, 1, 2, true);
CreditCard card = BuildCard(kCard1, 3, 4, kAddr2);
EXPECT_CALL(
local_,
SendChangesToSyncServer(ElementsAre(SyncAddressChangeAndDataMatch(
syncer::SyncChange::ACTION_UPDATE, kAddr1SyncTag,
sync_pb::WalletMetadataSpecifics::ADDRESS, kAddr1Utf8, 1, 2, true))));
EXPECT_CALL(local_,
SendChangesToSyncServer(ElementsAre(SyncCardChangeAndDataMatch(
syncer::SyncChange::ACTION_UPDATE, kCard1SyncTag,
sync_pb::WalletMetadataSpecifics::CARD, kCard1Utf8, 3, 4,
kAddr2Utf8))));
local_.AutofillProfileChanged(AutofillProfileChange(
AutofillProfileChange::UPDATE, address.guid(), &address));
local_.CreditCardChanged(
CreditCardChange(CreditCardChange::UPDATE, card.guid(), &card));
}
// Verify that one-off addition of metadata is not sent to the sync // Verify that one-off addition of metadata is not sent to the sync
// server. Metadata add and delete trigger multiple changes notification // server. Metadata add and delete trigger multiple changes notification
// instead. // instead.
......
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