Commit 4cde6da1 authored by Jan Krcal's avatar Jan Krcal Committed by Commit Bot

[AF] Add integration tests for wallet metadata

This CL creates the first integration tests for the autofill wallet
metadata model type.

Bug: 894001
Change-Id: Ie756264fe6b22d863a6965456ec0d7b627774c23
Reviewed-on: https://chromium-review.googlesource.com/c/1306357
Commit-Queue: Jan Krcal <jkrcal@chromium.org>
Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607282}
parent c1de4473
......@@ -22,7 +22,6 @@
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/browser/payments/payments_customer_data.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/webdata/autofill_entry.h"
#include "components/autofill/core/browser/webdata/autofill_table.h"
......@@ -60,6 +59,11 @@ class MockWebDataServiceObserver
void(const AutofillChangeList& changes));
};
scoped_refptr<AutofillWebDataService> GetWebDataService(int index) {
return WebDataServiceFactory::GetAutofillWebDataForProfile(
test()->GetProfile(index), ServiceAccessType::EXPLICIT_ACCESS);
}
void WaitForCurrentTasksToComplete(base::SequencedTaskRunner* task_runner) {
base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
......@@ -76,8 +80,7 @@ void RemoveKeyDontBlockForSync(int profile, const AutofillKey& key) {
EXPECT_CALL(mock_observer, AutofillEntriesChanged(_))
.WillOnce(SignalEvent(&done_event));
scoped_refptr<AutofillWebDataService> wds =
autofill_helper::GetProfileWebDataService(profile);
scoped_refptr<AutofillWebDataService> wds = GetWebDataService(profile);
void (AutofillWebDataService::*add_observer_func)(
AutofillWebDataServiceObserverOnDBSequence*) =
......@@ -111,30 +114,6 @@ std::vector<AutofillEntry> GetAllAutofillEntries(AutofillWebDataService* wds) {
return entries;
}
void SetServerCardsOnDBSequence(
AutofillWebDataService* wds,
const std::vector<autofill::CreditCard>& credit_cards) {
DCHECK(wds->GetDBTaskRunner()->RunsTasksInCurrentSequence());
AutofillTable::FromWebDatabase(wds->GetDatabase())
->SetServerCreditCards(credit_cards);
}
void SetServerProfilesOnDBSequence(
AutofillWebDataService* wds,
const std::vector<autofill::AutofillProfile>& profiles) {
DCHECK(wds->GetDBTaskRunner()->RunsTasksInCurrentSequence());
AutofillTable::FromWebDatabase(wds->GetDatabase())
->SetServerProfiles(profiles);
}
void SetPaymentsCustomerDataOnDBSequence(
AutofillWebDataService* wds,
const autofill::PaymentsCustomerData& customer_data) {
DCHECK(wds->GetDBTaskRunner()->RunsTasksInCurrentSequence());
AutofillTable::FromWebDatabase(wds->GetDatabase())
->SetPaymentsCustomerData(&customer_data);
}
bool ProfilesMatchImpl(
int profile_a,
const std::vector<AutofillProfile*>& autofill_profiles_a,
......@@ -227,16 +206,6 @@ AutofillProfile CreateUniqueAutofillProfile() {
return profile;
}
scoped_refptr<AutofillWebDataService> GetProfileWebDataService(int index) {
return WebDataServiceFactory::GetAutofillWebDataForProfile(
test()->GetProfile(index), ServiceAccessType::EXPLICIT_ACCESS);
}
scoped_refptr<AutofillWebDataService> GetAccountWebDataService(int index) {
return WebDataServiceFactory::GetAutofillWebDataForAccount(
test()->GetProfile(index), ServiceAccessType::EXPLICIT_ACCESS);
}
PersonalDataManager* GetPersonalDataManager(int index) {
return autofill::PersonalDataManagerFactory::GetForProfile(
test()->GetProfile(index));
......@@ -257,7 +226,7 @@ void AddKeys(int profile, const std::set<AutofillKey>& keys) {
EXPECT_CALL(mock_observer, AutofillEntriesChanged(_))
.WillOnce(SignalEvent(&done_event));
scoped_refptr<AutofillWebDataService> wds = GetProfileWebDataService(profile);
scoped_refptr<AutofillWebDataService> wds = GetWebDataService(profile);
void (AutofillWebDataService::*add_observer_func)(
AutofillWebDataServiceObserverOnDBSequence*) =
......@@ -278,8 +247,7 @@ void AddKeys(int profile, const std::set<AutofillKey>& keys) {
void RemoveKey(int profile, const AutofillKey& key) {
RemoveKeyDontBlockForSync(profile, key);
WaitForCurrentTasksToComplete(
autofill_helper::GetProfileWebDataService(profile)->GetDBTaskRunner());
WaitForCurrentTasksToComplete(GetWebDataService(profile)->GetDBTaskRunner());
}
void RemoveKeys(int profile) {
......@@ -287,12 +255,11 @@ void RemoveKeys(int profile) {
for (const AutofillEntry& entry : keys) {
RemoveKeyDontBlockForSync(profile, entry.key());
}
WaitForCurrentTasksToComplete(
autofill_helper::GetProfileWebDataService(profile)->GetDBTaskRunner());
WaitForCurrentTasksToComplete(GetWebDataService(profile)->GetDBTaskRunner());
}
std::set<AutofillEntry> GetAllKeys(int profile) {
scoped_refptr<AutofillWebDataService> wds = GetProfileWebDataService(profile);
scoped_refptr<AutofillWebDataService> wds = GetWebDataService(profile);
std::vector<AutofillEntry> all_entries = GetAllAutofillEntries(wds.get());
return std::set<AutofillEntry>(all_entries.begin(), all_entries.end());
}
......@@ -309,35 +276,6 @@ void SetCreditCards(int profile, std::vector<CreditCard>* credit_cards) {
GetPersonalDataManager(profile)->SetCreditCards(credit_cards);
}
void SetServerCreditCards(
int profile,
const std::vector<autofill::CreditCard>& credit_cards) {
scoped_refptr<AutofillWebDataService> wds = GetProfileWebDataService(profile);
wds->GetDBTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&SetServerCardsOnDBSequence,
base::Unretained(wds.get()), credit_cards));
WaitForCurrentTasksToComplete(wds->GetDBTaskRunner());
}
void SetServerProfiles(int profile,
const std::vector<autofill::AutofillProfile>& profiles) {
scoped_refptr<AutofillWebDataService> wds = GetProfileWebDataService(profile);
wds->GetDBTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&SetServerProfilesOnDBSequence,
base::Unretained(wds.get()), profiles));
WaitForCurrentTasksToComplete(wds->GetDBTaskRunner());
}
void SetPaymentsCustomerData(
int profile,
const autofill::PaymentsCustomerData& customer_data) {
scoped_refptr<AutofillWebDataService> wds = GetProfileWebDataService(profile);
wds->GetDBTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&SetPaymentsCustomerDataOnDBSequence,
base::Unretained(wds.get()), customer_data));
WaitForCurrentTasksToComplete(wds->GetDBTaskRunner());
}
void AddProfile(int profile, const AutofillProfile& autofill_profile) {
std::vector<AutofillProfile> autofill_profiles;
for (AutofillProfile* profile : GetAllAutoFillProfiles(profile)) {
......@@ -389,8 +327,7 @@ std::vector<AutofillProfile*> GetAllAutoFillProfiles(int profile) {
// data, but this shouldn't cause problems. While PersonalDataManager will
// cancel outstanding queries, this is only instigated on the UI sequence,
// which we are about to block, which means we are safe.
WaitForCurrentTasksToComplete(
autofill_helper::GetProfileWebDataService(profile)->GetDBTaskRunner());
WaitForCurrentTasksToComplete(GetWebDataService(profile)->GetDBTaskRunner());
return pdm->GetProfiles();
}
......@@ -446,9 +383,9 @@ bool AutofillProfileChecker::Wait() {
// before any locally instigated async writes. This is run exactly one time
// before the first IsExitConditionSatisfied() is called.
WaitForCurrentTasksToComplete(
autofill_helper::GetProfileWebDataService(profile_a_)->GetDBTaskRunner());
GetWebDataService(profile_a_)->GetDBTaskRunner());
WaitForCurrentTasksToComplete(
autofill_helper::GetProfileWebDataService(profile_b_)->GetDBTaskRunner());
GetWebDataService(profile_b_)->GetDBTaskRunner());
return StatusChangeChecker::Wait();
}
......
......@@ -20,9 +20,7 @@ class AutofillEntry;
class AutofillKey;
class AutofillProfile;
class AutofillType;
class AutofillWebDataService;
class CreditCard;
struct PaymentsCustomerData;
class PersonalDataManager;
} // namespace autofill
......@@ -35,15 +33,6 @@ enum ProfileType {
PROFILE_NULL
};
// Used to access the web data service within a particular sync profile.
scoped_refptr<autofill::AutofillWebDataService> GetProfileWebDataService(
int index) WARN_UNUSED_RESULT;
// Used to access the account-scoped web data service within a particular sync
// profile.
scoped_refptr<autofill::AutofillWebDataService> GetAccountWebDataService(
int index) WARN_UNUSED_RESULT;
// Used to access the personal data manager within a particular sync profile.
autofill::PersonalDataManager* GetPersonalDataManager(
int index) WARN_UNUSED_RESULT;
......@@ -76,17 +65,6 @@ void SetProfiles(int profile,
void SetCreditCards(int profile,
std::vector<autofill::CreditCard>* credit_cards);
void SetServerCreditCards(
int profile,
const std::vector<autofill::CreditCard>& credit_cards);
void SetServerProfiles(int profile,
const std::vector<autofill::AutofillProfile>& profiles);
void SetPaymentsCustomerData(
int profile,
const autofill::PaymentsCustomerData& customer_data);
// Adds the autofill profile |autofill_profile| to sync profile |profile|.
void AddProfile(int profile, const autofill::AutofillProfile& autofill_profile);
......
......@@ -7,12 +7,12 @@
#include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/sync/test/integration/autofill_helper.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
#include "chrome/browser/sync/test/integration/secondary_account_helper.h"
#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
#include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/sync/test/integration/wallet_helper.h"
#include "chrome/browser/web_data_service_factory.h"
#include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/credit_card.h"
......@@ -34,10 +34,22 @@
using autofill::AutofillProfile;
using autofill::CreditCard;
using autofill::data_util::TruncateUTF8;
using autofill_helper::GetAccountWebDataService;
using autofill_helper::GetPersonalDataManager;
using autofill_helper::GetProfileWebDataService;
using base::ASCIIToUTF16;
using wallet_helper::CreateDefaultSyncPaymentsCustomerData;
using wallet_helper::CreateDefaultSyncWalletAddress;
using wallet_helper::CreateDefaultSyncWalletCard;
using wallet_helper::CreateSyncWalletCard;
using wallet_helper::CreateSyncWalletAddress;
using wallet_helper::CreateSyncPaymentsCustomerData;
using wallet_helper::ExpectDefaultCreditCardValues;
using wallet_helper::ExpectDefaultProfileValues;
using wallet_helper::GetAccountWebDataService;
using wallet_helper::GetDefaultCreditCard;
using wallet_helper::GetPersonalDataManager;
using wallet_helper::GetProfileWebDataService;
using wallet_helper::kDefaultBillingAddressID;
using wallet_helper::kDefaultCardID;
using wallet_helper::kDefaultCustomerID;
namespace {
......@@ -45,33 +57,6 @@ ACTION_P(QuitMessageLoop, loop) {
loop->Quit();
}
// Constants for the credit card.
const char kDefaultCardID[] = "wallet card ID";
const int kDefaultCardExpMonth = 8;
const int kDefaultCardExpYear = 2087;
const char kDefaultCardLastFour[] = "1234";
const char kDefaultCardName[] = "Patrick Valenzuela";
const char kDefaultBillingAddressId[] = "billing address entity ID";
const sync_pb::WalletMaskedCreditCard_WalletCardType kDefaultCardType =
sync_pb::WalletMaskedCreditCard::AMEX;
// Constants for the address.
const char kDefaultAddressID[] = "wallet address ID";
const char kDefaultAddressName[] = "John S. Doe";
const char kDefaultCompanyName[] = "The Company";
const char kDefaultStreetAddress[] = "1234 Fake Street\nApp 2";
const char kDefaultCity[] = "Cityville";
const char kDefaultState[] = "Stateful";
const char kDefaultCountry[] = "US";
const char kDefaultZip[] = "90011";
const char kDefaultPhone[] = "1.800.555.1234";
const char kDefaultSortingCode[] = "CEDEX";
const char kDefaultDependentLocality[] = "DepLoc";
const char kDefaultLanguageCode[] = "en";
// Constants for PaymentsCustomerData.
const char kDefaultCustomerID[] = "deadbeef";
const char kLocalGuidA[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44A";
const char kDifferentBillingAddressId[] = "another address entity ID";
......@@ -193,199 +178,10 @@ std::unique_ptr<autofill::PaymentsCustomerData> GetPaymentsCustomerData(
}
#endif
sync_pb::SyncEntity CreateDefaultSyncWalletCard() {
sync_pb::SyncEntity entity;
entity.set_name(kDefaultCardID);
entity.set_id_string(kDefaultCardID);
entity.set_version(0); // Will be overridden by the fake server.
entity.set_ctime(12345);
entity.set_mtime(12345);
sync_pb::AutofillWalletSpecifics* wallet_specifics =
entity.mutable_specifics()->mutable_autofill_wallet();
wallet_specifics->set_type(
sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD);
sync_pb::WalletMaskedCreditCard* credit_card =
wallet_specifics->mutable_masked_card();
credit_card->set_id(kDefaultCardID);
credit_card->set_exp_month(kDefaultCardExpMonth);
credit_card->set_exp_year(kDefaultCardExpYear);
credit_card->set_last_four(kDefaultCardLastFour);
credit_card->set_name_on_card(kDefaultCardName);
credit_card->set_status(sync_pb::WalletMaskedCreditCard::VALID);
credit_card->set_type(kDefaultCardType);
credit_card->set_billing_address_id(kDefaultBillingAddressId);
return entity;
}
sync_pb::SyncEntity CreateSyncWalletCard(const std::string& name,
const std::string& last_four) {
sync_pb::SyncEntity result = CreateDefaultSyncWalletCard();
result.set_name(name);
result.set_id_string(name);
sync_pb::WalletMaskedCreditCard* credit_card = result.mutable_specifics()
->mutable_autofill_wallet()
->mutable_masked_card();
credit_card->set_last_four(last_four);
credit_card->set_id(name);
return result;
}
sync_pb::SyncEntity CreateSyncPaymentsCustomerData(
const std::string& customer_id) {
sync_pb::SyncEntity entity;
entity.set_name(customer_id);
entity.set_id_string(customer_id);
entity.set_version(0); // Will be overridden by the fake server.
entity.set_ctime(12345);
entity.set_mtime(12345);
sync_pb::AutofillWalletSpecifics* wallet_specifics =
entity.mutable_specifics()->mutable_autofill_wallet();
wallet_specifics->set_type(sync_pb::AutofillWalletSpecifics::CUSTOMER_DATA);
sync_pb::PaymentsCustomerData* customer_data =
wallet_specifics->mutable_customer_data();
customer_data->set_id(customer_id);
return entity;
}
sync_pb::SyncEntity CreateDefaultSyncPaymentsCustomerData() {
return CreateSyncPaymentsCustomerData(kDefaultCustomerID);
}
CreditCard GetDefaultCreditCard() {
CreditCard card(CreditCard::MASKED_SERVER_CARD, kDefaultCardID);
card.SetExpirationMonth(kDefaultCardExpMonth);
card.SetExpirationYear(kDefaultCardExpYear);
card.SetNumber(base::UTF8ToUTF16(kDefaultCardLastFour));
card.SetRawInfo(autofill::CREDIT_CARD_NAME_FULL,
base::UTF8ToUTF16(kDefaultCardName));
card.SetServerStatus(CreditCard::OK);
card.SetNetworkForMaskedCard(autofill::kAmericanExpressCard);
card.set_card_type(CreditCard::CARD_TYPE_CREDIT);
card.set_billing_address_id(kDefaultBillingAddressId);
return card;
}
sync_pb::SyncEntity CreateDefaultSyncWalletAddress() {
sync_pb::SyncEntity entity;
entity.set_name(kDefaultAddressID);
entity.set_id_string(kDefaultAddressID);
entity.set_version(0); // Will be overridden by the fake server.
entity.set_ctime(12345);
entity.set_mtime(12345);
sync_pb::AutofillWalletSpecifics* wallet_specifics =
entity.mutable_specifics()->mutable_autofill_wallet();
wallet_specifics->set_type(sync_pb::AutofillWalletSpecifics::POSTAL_ADDRESS);
sync_pb::WalletPostalAddress* wallet_address =
wallet_specifics->mutable_address();
wallet_address->set_id(kDefaultAddressID);
wallet_address->set_recipient_name(kDefaultAddressName);
wallet_address->set_company_name(kDefaultCompanyName);
wallet_address->add_street_address(kDefaultStreetAddress);
wallet_address->set_address_1(kDefaultState);
wallet_address->set_address_2(kDefaultCity);
wallet_address->set_address_3(kDefaultDependentLocality);
wallet_address->set_postal_code(kDefaultZip);
wallet_address->set_country_code(kDefaultCountry);
wallet_address->set_phone_number(kDefaultPhone);
wallet_address->set_sorting_code(kDefaultSortingCode);
wallet_address->set_language_code(kDefaultLanguageCode);
return entity;
}
sync_pb::SyncEntity CreateSyncWalletAddress(const std::string& name,
const std::string& company) {
sync_pb::SyncEntity result = CreateDefaultSyncWalletAddress();
result.set_name(name);
result.set_id_string(name);
sync_pb::WalletPostalAddress* wallet_address =
result.mutable_specifics()->mutable_autofill_wallet()->mutable_address();
wallet_address->set_id(name);
wallet_address->set_company_name(company);
return result;
}
// TODO(sebsg): Instead add a function to create a card, and one to inject in
// the server. Then compare the cards directly.
void ExpectDefaultCreditCardValues(const CreditCard& card) {
EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, card.record_type());
EXPECT_EQ(kDefaultCardID, card.server_id());
EXPECT_EQ(base::UTF8ToUTF16(kDefaultCardLastFour), card.LastFourDigits());
EXPECT_EQ(autofill::kAmericanExpressCard, card.network());
EXPECT_EQ(kDefaultCardExpMonth, card.expiration_month());
EXPECT_EQ(kDefaultCardExpYear, card.expiration_year());
EXPECT_EQ(base::UTF8ToUTF16(kDefaultCardName),
card.GetRawInfo(autofill::ServerFieldType::CREDIT_CARD_NAME_FULL));
EXPECT_EQ(kDefaultBillingAddressId, card.billing_address_id());
}
// TODO(sebsg): Instead add a function to create a profile, and one to inject in
// the server. Then compare the profiles directly.
void ExpectDefaultProfileValues(const AutofillProfile& profile) {
EXPECT_EQ(kDefaultLanguageCode, profile.language_code());
EXPECT_EQ(
kDefaultAddressName,
TruncateUTF8(base::UTF16ToUTF8(profile.GetRawInfo(autofill::NAME_FULL))));
EXPECT_EQ(kDefaultCompanyName,
TruncateUTF8(
base::UTF16ToUTF8(profile.GetRawInfo(autofill::COMPANY_NAME))));
EXPECT_EQ(kDefaultStreetAddress,
TruncateUTF8(base::UTF16ToUTF8(
profile.GetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS))));
EXPECT_EQ(kDefaultCity, TruncateUTF8(base::UTF16ToUTF8(profile.GetRawInfo(
autofill::ADDRESS_HOME_CITY))));
EXPECT_EQ(kDefaultState, TruncateUTF8(base::UTF16ToUTF8(profile.GetRawInfo(
autofill::ADDRESS_HOME_STATE))));
EXPECT_EQ(kDefaultZip, TruncateUTF8(base::UTF16ToUTF8(
profile.GetRawInfo(autofill::ADDRESS_HOME_ZIP))));
EXPECT_EQ(kDefaultCountry, TruncateUTF8(base::UTF16ToUTF8(profile.GetRawInfo(
autofill::ADDRESS_HOME_COUNTRY))));
EXPECT_EQ(kDefaultPhone, TruncateUTF8(base::UTF16ToUTF8(profile.GetRawInfo(
autofill::PHONE_HOME_WHOLE_NUMBER))));
EXPECT_EQ(kDefaultSortingCode,
TruncateUTF8(base::UTF16ToUTF8(
profile.GetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE))));
EXPECT_EQ(kDefaultDependentLocality,
TruncateUTF8(base::UTF16ToUTF8(profile.GetRawInfo(
autofill::ADDRESS_HOME_DEPENDENT_LOCALITY))));
}
// Class that enables or disables USS based on test parameter. Must be the first
// base class of the test fixture.
// TODO(jkrcal): When the new implementation fully launches, remove this class,
// convert all tests from *_P back to *_F and remove the instance at the end.
class UssSwitchToggler : public testing::WithParamInterface<bool> {
public:
UssSwitchToggler() {}
// Sets up feature overrides, based on the parameter of the test.
void InitWithDefaultFeatures() { InitWithFeatures({}, {}); }
// Sets up feature overrides, adds the toggled feature on top of specified
// |enabled_features| and |disabled_features|. Vectors are passed by value
// because we need to alter them anyway.
void InitWithFeatures(std::vector<base::Feature> enabled_features,
std::vector<base::Feature> disabled_features) {
if (GetParam()) {
enabled_features.push_back(switches::kSyncUSSAutofillWalletData);
} else {
disabled_features.push_back(switches::kSyncUSSAutofillWalletData);
}
override_features_.InitWithFeatures(enabled_features, disabled_features);
}
private:
base::test::ScopedFeatureList override_features_;
};
} // namespace
class SingleClientWalletSyncTest : public UssSwitchToggler, public SyncTest {
class SingleClientWalletSyncTest : public UssWalletSwitchToggler,
public SyncTest {
public:
SingleClientWalletSyncTest() : SyncTest(SINGLE_CLIENT) {}
~SingleClientWalletSyncTest() override {}
......@@ -774,16 +570,16 @@ IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest,
// Add a server credit card on the client.
CreditCard credit_card(CreditCard::MASKED_SERVER_CARD, "a123");
std::vector<CreditCard> credit_cards = {credit_card};
autofill_helper::SetServerCreditCards(0, credit_cards);
wallet_helper::SetServerCreditCards(0, credit_cards);
// Add a server profile on the client.
AutofillProfile profile(AutofillProfile::SERVER_PROFILE, "a123");
profile.SetRawInfo(autofill::COMPANY_NAME, ASCIIToUTF16("JustATest"));
std::vector<AutofillProfile> client_profiles = {profile};
autofill_helper::SetServerProfiles(0, client_profiles);
wallet_helper::SetServerProfiles(0, client_profiles);
// Add PaymentsCustomerData on the client.
autofill_helper::SetPaymentsCustomerData(
wallet_helper::SetPaymentsCustomerData(
0, autofill::PaymentsCustomerData(/*customer_id=*/kDefaultCustomerID));
// Refresh the pdm so that it gets data from autofill table.
......@@ -834,15 +630,15 @@ IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest,
AutofillProfile profile(AutofillProfile::SERVER_PROFILE, "a123");
profile.SetRawInfo(autofill::COMPANY_NAME, ASCIIToUTF16("JustATest"));
std::vector<AutofillProfile> client_profiles = {profile};
autofill_helper::SetServerProfiles(0, client_profiles);
wallet_helper::SetServerProfiles(0, client_profiles);
// Add a server credit card on the client.
CreditCard credit_card(CreditCard::MASKED_SERVER_CARD, "a123");
std::vector<CreditCard> credit_cards = {credit_card};
autofill_helper::SetServerCreditCards(0, credit_cards);
wallet_helper::SetServerCreditCards(0, credit_cards);
// Add PaymentsCustomerData on the client.
autofill_helper::SetPaymentsCustomerData(
wallet_helper::SetPaymentsCustomerData(
0, autofill::PaymentsCustomerData(/*customer_id=*/kDefaultCustomerID));
// Refresh the pdm so that it gets cards from autofill table.
......@@ -871,9 +667,8 @@ IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest,
// The only profile present on the client should be the one from the server.
profiles = pdm->GetServerProfiles();
EXPECT_EQ(1uL, profiles.size());
EXPECT_EQ(kDefaultCompanyName,
TruncateUTF8(base::UTF16ToUTF8(
profiles[0]->GetRawInfo(autofill::COMPANY_NAME))));
EXPECT_NE("JustATest", TruncateUTF8(base::UTF16ToUTF8(
profiles[0]->GetRawInfo(autofill::COMPANY_NAME))));
// There should be no cards present.
cards = pdm->GetCreditCards();
......@@ -897,7 +692,7 @@ IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest,
CreditCard credit_card = GetDefaultCreditCard();
credit_card.set_billing_address_id(kLocalGuidA);
std::vector<CreditCard> credit_cards = {credit_card};
autofill_helper::SetServerCreditCards(0, credit_cards);
wallet_helper::SetServerCreditCards(0, credit_cards);
// Refresh the pdm so that it gets cards from autofill table.
RefreshAndWaitForOnPersonalDataChanged(pdm);
......@@ -933,7 +728,7 @@ IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest,
CreditCard credit_card = GetDefaultCreditCard();
credit_card.set_billing_address_id(kDifferentBillingAddressId);
std::vector<CreditCard> credit_cards = {credit_card};
autofill_helper::SetServerCreditCards(0, credit_cards);
wallet_helper::SetServerCreditCards(0, credit_cards);
// Refresh the pdm so that it gets cards from autofill table.
RefreshAndWaitForOnPersonalDataChanged(pdm);
......@@ -952,7 +747,7 @@ IN_PROC_BROWSER_TEST_P(SingleClientWalletSyncTest,
cards = pdm->GetCreditCards();
ASSERT_EQ(1uL, cards.size());
EXPECT_EQ(kDefaultCardID, cards[0]->server_id());
EXPECT_EQ(kDefaultBillingAddressId, cards[0]->billing_address_id());
EXPECT_EQ(kDefaultBillingAddressID, cards[0]->billing_address_id());
}
class SingleClientWalletSecondaryAccountSyncTest
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/macros.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/sync/test/integration/wallet_helper.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/credit_card.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
using autofill::AutofillProfile;
using autofill::CreditCard;
using autofill::PersonalDataManager;
using wallet_helper::CreateDefaultSyncPaymentsCustomerData;
using wallet_helper::CreateSyncWalletAddress;
using wallet_helper::CreateSyncWalletCard;
using wallet_helper::GetCreditCard;
using wallet_helper::GetServerCreditCards;
using wallet_helper::GetServerProfiles;
using wallet_helper::UpdateServerAddressMetadata;
using wallet_helper::UpdateServerCardMetadata;
class TwoClientWalletSyncTest : public UssWalletSwitchToggler, public SyncTest {
public:
TwoClientWalletSyncTest() : SyncTest(TWO_CLIENT) {}
~TwoClientWalletSyncTest() override {}
bool TestUsesSelfNotifications() override { return false; }
private:
DISALLOW_COPY_AND_ASSIGN(TwoClientWalletSyncTest);
};
IN_PROC_BROWSER_TEST_P(TwoClientWalletSyncTest, UpdateCreditCardMetadata) {
InitWithDefaultFeatures();
GetFakeServer()->SetWalletData(
{CreateSyncWalletCard(/*name=*/"card-1", /*last_four=*/"0001"),
CreateSyncWalletAddress(/*name=*/"address-1", /*company=*/"Company-1"),
CreateDefaultSyncPaymentsCustomerData()});
ASSERT_TRUE(SetupSync());
// Increase use count on the first client.
CreditCard card = GetCreditCard(/*name=*/"card-1", /*last_four=*/"0001");
card.set_use_count(5);
UpdateServerCardMetadata(0, card);
EXPECT_TRUE(AutofillWalletChecker(0, 1).Wait());
// Make sure both clients have use_count=5.
std::vector<CreditCard*> credit_cards = GetServerCreditCards(1);
EXPECT_EQ(1U, credit_cards.size());
EXPECT_EQ(5u, credit_cards[0]->use_count());
credit_cards = GetServerCreditCards(0);
EXPECT_EQ(1U, credit_cards.size());
EXPECT_EQ(5u, credit_cards[0]->use_count());
}
INSTANTIATE_TEST_CASE_P(USS,
TwoClientWalletSyncTest,
::testing::Values(false, true));
} // namespace
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/sync/test/integration/wallet_helper.h"
#include <stddef.h>
#include <map>
#include <utility>
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/sync/profile_sync_test_util.h"
#include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/web_data_service_factory.h"
#include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/payments/payments_customer_data.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/webdata/autofill_table.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/sync/driver/sync_driver_switches.h"
using autofill::AutofillProfile;
using autofill::AutofillTable;
using autofill::AutofillWebDataService;
using autofill::CreditCard;
using autofill::PaymentsCustomerData;
using autofill::PersonalDataManager;
using autofill::data_util::TruncateUTF8;
using sync_datatype_helper::test;
namespace {
// Constants for the credit card.
const int kDefaultCardExpMonth = 8;
const int kDefaultCardExpYear = 2087;
const char kDefaultCardLastFour[] = "1234";
const char kDefaultCardName[] = "Patrick Valenzuela";
const sync_pb::WalletMaskedCreditCard_WalletCardType kDefaultCardType =
sync_pb::WalletMaskedCreditCard::AMEX;
// Constants for the address.
const char kDefaultAddressName[] = "John S. Doe";
const char kDefaultCompanyName[] = "The Company";
const char kDefaultStreetAddress[] = "1234 Fake Street\nApp 2";
const char kDefaultCity[] = "Cityville";
const char kDefaultState[] = "Stateful";
const char kDefaultCountry[] = "US";
const char kDefaultZip[] = "90011";
const char kDefaultPhone[] = "1.800.555.1234";
const char kDefaultSortingCode[] = "CEDEX";
const char kDefaultDependentLocality[] = "DepLoc";
const char kDefaultLanguageCode[] = "en";
template <class Item>
bool ListsMatch(int profile_a,
const std::vector<Item*>& list_a,
int profile_b,
const std::vector<Item*>& list_b) {
std::map<std::string, Item> list_a_map;
for (Item* item : list_a) {
list_a_map[item->server_id()] = *item;
}
// This seems to be a transient state that will eventually be rectified by
// model type logic. We don't need to check b for duplicates directly because
// after the first is erased from |autofill_profiles_a_map| the second will
// not be found.
if (list_a.size() != list_a_map.size()) {
DVLOG(1) << "Profile " << profile_a << " contains duplicate server_ids.";
return false;
}
for (Item* item : list_b) {
if (!list_a_map.count(item->server_id())) {
DVLOG(1) << "GUID " << item->server_id() << " not found in profile "
<< profile_b << ".";
return false;
}
Item* expected_item = &list_a_map[item->server_id()];
if (expected_item->Compare(*item) != 0 ||
expected_item->use_count() != item->use_count()) {
DVLOG(1) << "Mismatch in profile with server_id " << item->server_id()
<< ".";
return false;
}
list_a_map.erase(item->server_id());
}
if (list_a_map.size()) {
DVLOG(1) << "Entries present in profile " << profile_a
<< " but not in profile" << profile_b << ".";
return false;
}
return true;
}
template <class Item>
void LogLists(const std::vector<Item*>& list_a,
const std::vector<Item*>& list_b) {
int x = 0;
for (Item* item : list_a) {
DVLOG(1) << "A#" << x++ << " " << *item;
}
x = 0;
for (Item* item : list_b) {
DVLOG(1) << "B#" << x++ << " " << *item;
}
}
bool WalletDataAndMetadataMatchImpl(
int profile_a,
const std::vector<CreditCard*>& server_cards_a,
const std::vector<AutofillProfile*>& server_profiles_a,
int profile_b,
const std::vector<CreditCard*>& server_cards_b,
const std::vector<AutofillProfile*>& server_profiles_b) {
if (!ListsMatch(profile_a, server_cards_a, profile_b, server_cards_b)) {
LogLists(server_cards_a, server_cards_b);
return false;
}
if (!ListsMatch(profile_a, server_profiles_a, profile_b, server_profiles_b)) {
LogLists(server_profiles_a, server_profiles_b);
return false;
}
return true;
}
void WaitForCurrentTasksToComplete(base::SequencedTaskRunner* task_runner) {
base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
task_runner->PostTask(FROM_HERE, base::BindOnce(&base::WaitableEvent::Signal,
base::Unretained(&event)));
event.Wait();
}
void SetServerCardsOnDBSequence(AutofillWebDataService* wds,
const std::vector<CreditCard>& credit_cards) {
DCHECK(wds->GetDBTaskRunner()->RunsTasksInCurrentSequence());
AutofillTable::FromWebDatabase(wds->GetDatabase())
->SetServerCreditCards(credit_cards);
}
void SetServerProfilesOnDBSequence(
AutofillWebDataService* wds,
const std::vector<AutofillProfile>& profiles) {
DCHECK(wds->GetDBTaskRunner()->RunsTasksInCurrentSequence());
AutofillTable::FromWebDatabase(wds->GetDatabase())
->SetServerProfiles(profiles);
}
void SetPaymentsCustomerDataOnDBSequence(
AutofillWebDataService* wds,
const PaymentsCustomerData& customer_data) {
DCHECK(wds->GetDBTaskRunner()->RunsTasksInCurrentSequence());
AutofillTable::FromWebDatabase(wds->GetDatabase())
->SetPaymentsCustomerData(&customer_data);
}
} // namespace
namespace wallet_helper {
const char kDefaultCardID[] = "wallet card ID";
const char kDefaultAddressID[] = "wallet address ID";
const char kDefaultCustomerID[] = "deadbeef";
const char kDefaultBillingAddressID[] = "billing address entity ID";
PersonalDataManager* GetPersonalDataManager(int index) {
return autofill::PersonalDataManagerFactory::GetForProfile(
test()->GetProfile(index));
}
scoped_refptr<AutofillWebDataService> GetProfileWebDataService(int index) {
return WebDataServiceFactory::GetAutofillWebDataForProfile(
test()->GetProfile(index), ServiceAccessType::EXPLICIT_ACCESS);
}
scoped_refptr<AutofillWebDataService> GetAccountWebDataService(int index) {
return WebDataServiceFactory::GetAutofillWebDataForAccount(
test()->GetProfile(index), ServiceAccessType::EXPLICIT_ACCESS);
}
void SetServerCreditCards(
int profile,
const std::vector<autofill::CreditCard>& credit_cards) {
scoped_refptr<AutofillWebDataService> wds = GetProfileWebDataService(profile);
wds->GetDBTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&SetServerCardsOnDBSequence,
base::Unretained(wds.get()), credit_cards));
WaitForCurrentTasksToComplete(wds->GetDBTaskRunner());
}
void SetServerProfiles(int profile,
const std::vector<autofill::AutofillProfile>& profiles) {
scoped_refptr<AutofillWebDataService> wds = GetProfileWebDataService(profile);
wds->GetDBTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&SetServerProfilesOnDBSequence,
base::Unretained(wds.get()), profiles));
WaitForCurrentTasksToComplete(wds->GetDBTaskRunner());
}
void SetPaymentsCustomerData(
int profile,
const autofill::PaymentsCustomerData& customer_data) {
scoped_refptr<AutofillWebDataService> wds = GetProfileWebDataService(profile);
wds->GetDBTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&SetPaymentsCustomerDataOnDBSequence,
base::Unretained(wds.get()), customer_data));
WaitForCurrentTasksToComplete(wds->GetDBTaskRunner());
}
void UpdateServerCardMetadata(int profile, const CreditCard& credit_card) {
scoped_refptr<AutofillWebDataService> wds = GetProfileWebDataService(profile);
wds->UpdateServerCardMetadata(credit_card);
WaitForCurrentTasksToComplete(wds->GetDBTaskRunner());
}
void UpdateServerAddressMetadata(int profile,
const AutofillProfile& server_address) {
scoped_refptr<AutofillWebDataService> wds = GetProfileWebDataService(profile);
wds->UpdateServerAddressMetadata(server_address);
WaitForCurrentTasksToComplete(wds->GetDBTaskRunner());
}
sync_pb::SyncEntity CreateDefaultSyncWalletCard() {
return CreateSyncWalletCard(kDefaultCardID, kDefaultCardLastFour);
}
sync_pb::SyncEntity CreateSyncWalletCard(const std::string& name,
const std::string& last_four) {
sync_pb::SyncEntity entity;
entity.set_name(name);
entity.set_id_string(name);
entity.set_version(0); // Will be overridden by the fake server.
entity.set_ctime(12345);
entity.set_mtime(12345);
sync_pb::AutofillWalletSpecifics* wallet_specifics =
entity.mutable_specifics()->mutable_autofill_wallet();
wallet_specifics->set_type(
sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD);
sync_pb::WalletMaskedCreditCard* credit_card =
wallet_specifics->mutable_masked_card();
credit_card->set_id(name);
credit_card->set_exp_month(kDefaultCardExpMonth);
credit_card->set_exp_year(kDefaultCardExpYear);
credit_card->set_last_four(last_four);
credit_card->set_name_on_card(kDefaultCardName);
credit_card->set_status(sync_pb::WalletMaskedCreditCard::VALID);
credit_card->set_type(kDefaultCardType);
credit_card->set_billing_address_id(kDefaultBillingAddressID);
return entity;
}
sync_pb::SyncEntity CreateSyncPaymentsCustomerData(
const std::string& customer_id) {
sync_pb::SyncEntity entity;
entity.set_name(customer_id);
entity.set_id_string(customer_id);
entity.set_version(0); // Will be overridden by the fake server.
entity.set_ctime(12345);
entity.set_mtime(12345);
sync_pb::AutofillWalletSpecifics* wallet_specifics =
entity.mutable_specifics()->mutable_autofill_wallet();
wallet_specifics->set_type(sync_pb::AutofillWalletSpecifics::CUSTOMER_DATA);
sync_pb::PaymentsCustomerData* customer_data =
wallet_specifics->mutable_customer_data();
customer_data->set_id(customer_id);
return entity;
}
sync_pb::SyncEntity CreateDefaultSyncPaymentsCustomerData() {
return CreateSyncPaymentsCustomerData(kDefaultCustomerID);
}
CreditCard GetDefaultCreditCard() {
return GetCreditCard(kDefaultCardID, kDefaultCardLastFour);
}
autofill::CreditCard GetCreditCard(const std::string& name,
const std::string& last_four) {
CreditCard card(CreditCard::MASKED_SERVER_CARD, name);
card.SetExpirationMonth(kDefaultCardExpMonth);
card.SetExpirationYear(kDefaultCardExpYear);
card.SetNumber(base::UTF8ToUTF16(last_four));
card.SetRawInfo(autofill::CREDIT_CARD_NAME_FULL,
base::UTF8ToUTF16(kDefaultCardName));
card.SetServerStatus(CreditCard::OK);
card.SetNetworkForMaskedCard(autofill::kAmericanExpressCard);
card.set_card_type(CreditCard::CARD_TYPE_CREDIT);
card.set_billing_address_id(kDefaultBillingAddressID);
return card;
}
sync_pb::SyncEntity CreateDefaultSyncWalletAddress() {
sync_pb::SyncEntity entity;
entity.set_name(kDefaultAddressID);
entity.set_id_string(kDefaultAddressID);
entity.set_version(0); // Will be overridden by the fake server.
entity.set_ctime(12345);
entity.set_mtime(12345);
sync_pb::AutofillWalletSpecifics* wallet_specifics =
entity.mutable_specifics()->mutable_autofill_wallet();
wallet_specifics->set_type(sync_pb::AutofillWalletSpecifics::POSTAL_ADDRESS);
sync_pb::WalletPostalAddress* wallet_address =
wallet_specifics->mutable_address();
wallet_address->set_id(kDefaultAddressID);
wallet_address->set_recipient_name(kDefaultAddressName);
wallet_address->set_company_name(kDefaultCompanyName);
wallet_address->add_street_address(kDefaultStreetAddress);
wallet_address->set_address_1(kDefaultState);
wallet_address->set_address_2(kDefaultCity);
wallet_address->set_address_3(kDefaultDependentLocality);
wallet_address->set_postal_code(kDefaultZip);
wallet_address->set_country_code(kDefaultCountry);
wallet_address->set_phone_number(kDefaultPhone);
wallet_address->set_sorting_code(kDefaultSortingCode);
wallet_address->set_language_code(kDefaultLanguageCode);
return entity;
}
sync_pb::SyncEntity CreateSyncWalletAddress(const std::string& name,
const std::string& company) {
sync_pb::SyncEntity result = CreateDefaultSyncWalletAddress();
result.set_name(name);
result.set_id_string(name);
sync_pb::WalletPostalAddress* wallet_address =
result.mutable_specifics()->mutable_autofill_wallet()->mutable_address();
wallet_address->set_id(name);
wallet_address->set_company_name(company);
return result;
}
void ExpectDefaultCreditCardValues(const CreditCard& card) {
EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, card.record_type());
EXPECT_EQ(kDefaultCardID, card.server_id());
EXPECT_EQ(base::UTF8ToUTF16(kDefaultCardLastFour), card.LastFourDigits());
EXPECT_EQ(autofill::kAmericanExpressCard, card.network());
EXPECT_EQ(kDefaultCardExpMonth, card.expiration_month());
EXPECT_EQ(kDefaultCardExpYear, card.expiration_year());
EXPECT_EQ(base::UTF8ToUTF16(kDefaultCardName),
card.GetRawInfo(autofill::ServerFieldType::CREDIT_CARD_NAME_FULL));
EXPECT_EQ(kDefaultBillingAddressID, card.billing_address_id());
}
void ExpectDefaultProfileValues(const AutofillProfile& profile) {
EXPECT_EQ(kDefaultLanguageCode, profile.language_code());
EXPECT_EQ(
kDefaultAddressName,
TruncateUTF8(base::UTF16ToUTF8(profile.GetRawInfo(autofill::NAME_FULL))));
EXPECT_EQ(kDefaultCompanyName,
TruncateUTF8(
base::UTF16ToUTF8(profile.GetRawInfo(autofill::COMPANY_NAME))));
EXPECT_EQ(kDefaultStreetAddress,
TruncateUTF8(base::UTF16ToUTF8(
profile.GetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS))));
EXPECT_EQ(kDefaultCity, TruncateUTF8(base::UTF16ToUTF8(profile.GetRawInfo(
autofill::ADDRESS_HOME_CITY))));
EXPECT_EQ(kDefaultState, TruncateUTF8(base::UTF16ToUTF8(profile.GetRawInfo(
autofill::ADDRESS_HOME_STATE))));
EXPECT_EQ(kDefaultZip, TruncateUTF8(base::UTF16ToUTF8(
profile.GetRawInfo(autofill::ADDRESS_HOME_ZIP))));
EXPECT_EQ(kDefaultCountry, TruncateUTF8(base::UTF16ToUTF8(profile.GetRawInfo(
autofill::ADDRESS_HOME_COUNTRY))));
EXPECT_EQ(kDefaultPhone, TruncateUTF8(base::UTF16ToUTF8(profile.GetRawInfo(
autofill::PHONE_HOME_WHOLE_NUMBER))));
EXPECT_EQ(kDefaultSortingCode,
TruncateUTF8(base::UTF16ToUTF8(
profile.GetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE))));
EXPECT_EQ(kDefaultDependentLocality,
TruncateUTF8(base::UTF16ToUTF8(profile.GetRawInfo(
autofill::ADDRESS_HOME_DEPENDENT_LOCALITY))));
}
std::vector<AutofillProfile*> GetServerProfiles(int profile) {
PersonalDataManager* pdm = GetPersonalDataManager(profile);
// Get the latest values from the DB and wait for it to finish.
pdm->Refresh();
WaitForCurrentTasksToComplete(
GetProfileWebDataService(profile)->GetDBTaskRunner());
return pdm->GetServerProfiles();
}
std::vector<CreditCard*> GetServerCreditCards(int profile) {
PersonalDataManager* pdm = GetPersonalDataManager(profile);
// Get the latest values from the DB and wait for it to finish.
pdm->Refresh();
WaitForCurrentTasksToComplete(
GetProfileWebDataService(profile)->GetDBTaskRunner());
return pdm->GetServerCreditCards();
}
} // namespace wallet_helper
AutofillWalletChecker::AutofillWalletChecker(int profile_a, int profile_b)
: profile_a_(profile_a), profile_b_(profile_b) {
wallet_helper::GetPersonalDataManager(profile_a_)->AddObserver(this);
wallet_helper::GetPersonalDataManager(profile_b_)->AddObserver(this);
}
AutofillWalletChecker::~AutofillWalletChecker() {
wallet_helper::GetPersonalDataManager(profile_a_)->RemoveObserver(this);
wallet_helper::GetPersonalDataManager(profile_b_)->RemoveObserver(this);
}
bool AutofillWalletChecker::Wait() {
wallet_helper::GetPersonalDataManager(profile_a_)->Refresh();
wallet_helper::GetPersonalDataManager(profile_b_)->Refresh();
// Similar to GetAllAutoFillProfiles() we need to make sure we are not reading
// before any locally instigated async writes. This is run exactly one time
// before the first IsExitConditionSatisfied() is called.
WaitForCurrentTasksToComplete(
wallet_helper::GetProfileWebDataService(profile_a_)->GetDBTaskRunner());
WaitForCurrentTasksToComplete(
wallet_helper::GetProfileWebDataService(profile_b_)->GetDBTaskRunner());
return StatusChangeChecker::Wait();
}
bool AutofillWalletChecker::IsExitConditionSatisfied() {
autofill::PersonalDataManager* pdm_a =
wallet_helper::GetPersonalDataManager(profile_a_);
autofill::PersonalDataManager* pdm_b =
wallet_helper::GetPersonalDataManager(profile_b_);
return WalletDataAndMetadataMatchImpl(
profile_a_, pdm_a->GetServerCreditCards(), pdm_a->GetServerProfiles(),
profile_b_, pdm_b->GetServerCreditCards(), pdm_b->GetServerProfiles());
}
std::string AutofillWalletChecker::GetDebugMessage() const {
return "Waiting for matching autofill wallet cards and addresses";
}
void AutofillWalletChecker::OnPersonalDataChanged() {
CheckExitCondition();
}
UssWalletSwitchToggler::UssWalletSwitchToggler() {}
void UssWalletSwitchToggler::InitWithDefaultFeatures() {
InitWithFeatures({}, {});
}
void UssWalletSwitchToggler::InitWithFeatures(
std::vector<base::Feature> enabled_features,
std::vector<base::Feature> disabled_features) {
if (GetParam()) {
enabled_features.push_back(switches::kSyncUSSAutofillWalletData);
} else {
disabled_features.push_back(switches::kSyncUSSAutofillWalletData);
}
override_features_.InitWithFeatures(enabled_features, disabled_features);
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_WALLET_HELPER_H_
#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_WALLET_HELPER_H_
#include <vector>
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/sync/test/integration/multi_client_status_change_checker.h"
#include "components/autofill/core/browser/personal_data_manager_observer.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace autofill {
class AutofillProfile;
class AutofillWebDataService;
class CreditCard;
class PersonalDataManager;
struct PaymentsCustomerData;
} // namespace autofill
namespace sync_pb {
class SyncEntity;
}
namespace wallet_helper {
extern const char kDefaultCardID[];
extern const char kDefaultAddressID[];
extern const char kDefaultCustomerID[];
extern const char kDefaultBillingAddressID[];
// Used to access the personal data manager within a particular sync profile.
autofill::PersonalDataManager* GetPersonalDataManager(int index)
WARN_UNUSED_RESULT;
// Used to access the web data service within a particular sync profile.
scoped_refptr<autofill::AutofillWebDataService> GetProfileWebDataService(
int index) WARN_UNUSED_RESULT;
// Used to access the account-scoped web data service within a particular sync
// profile.
scoped_refptr<autofill::AutofillWebDataService> GetAccountWebDataService(
int index) WARN_UNUSED_RESULT;
void SetServerCreditCards(
int profile,
const std::vector<autofill::CreditCard>& credit_cards);
void SetServerProfiles(int profile,
const std::vector<autofill::AutofillProfile>& profiles);
void SetPaymentsCustomerData(
int profile,
const autofill::PaymentsCustomerData& customer_data);
void UpdateServerCardMetadata(int profile,
const autofill::CreditCard& credit_card);
void UpdateServerAddressMetadata(
int profile,
const autofill::AutofillProfile& server_address);
sync_pb::SyncEntity CreateDefaultSyncWalletCard();
sync_pb::SyncEntity CreateSyncWalletCard(const std::string& name,
const std::string& last_four);
sync_pb::SyncEntity CreateSyncPaymentsCustomerData(
const std::string& customer_id);
sync_pb::SyncEntity CreateDefaultSyncPaymentsCustomerData();
autofill::CreditCard GetDefaultCreditCard();
autofill::CreditCard GetCreditCard(const std::string& name,
const std::string& last_four);
sync_pb::SyncEntity CreateDefaultSyncWalletAddress();
sync_pb::SyncEntity CreateSyncWalletAddress(const std::string& name,
const std::string& company);
// TODO(sebsg): Instead add a function to create a card, and one to inject in
// the server. Then compare the cards directly.
void ExpectDefaultCreditCardValues(const autofill::CreditCard& card);
// TODO(sebsg): Instead add a function to create a profile, and one to inject in
// the server. Then compare the profiles directly.
void ExpectDefaultProfileValues(const autofill::AutofillProfile& profile);
// Load current data from the database of profile |profile|.
std::vector<autofill::AutofillProfile*> GetServerProfiles(int profile);
std::vector<autofill::CreditCard*> GetServerCreditCards(int profile);
} // namespace wallet_helper
// Checker to block until autofill wallet & server profiles match on both
// profiles.
class AutofillWalletChecker : public StatusChangeChecker,
public autofill::PersonalDataManagerObserver {
public:
AutofillWalletChecker(int profile_a, int profile_b);
~AutofillWalletChecker() override;
// StatusChangeChecker implementation.
bool Wait() override;
bool IsExitConditionSatisfied() override;
std::string GetDebugMessage() const override;
// autofill::PersonalDataManager implementation.
void OnPersonalDataChanged() override;
private:
const int profile_a_;
const int profile_b_;
};
// Class that enables or disables USS based on test parameter. Must be the first
// base class of the test fixture.
// TODO(jkrcal): When the new implementation fully launches, remove this class,
// convert all tests from *_P back to *_F and remove the instance at the end.
class UssWalletSwitchToggler : public testing::WithParamInterface<bool> {
public:
UssWalletSwitchToggler();
// Sets up feature overrides, based on the parameter of the test.
void InitWithDefaultFeatures();
// Sets up feature overrides, adds the toggled feature on top of specified
// |enabled_features| and |disabled_features|. Vectors are passed by value
// because we need to alter them anyway.
void InitWithFeatures(std::vector<base::Feature> enabled_features,
std::vector<base::Feature> disabled_features);
private:
base::test::ScopedFeatureList override_features_;
};
#endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_WALLET_HELPER_H_
......@@ -5271,6 +5271,8 @@ if (!is_android && !is_fuchsia) {
"../browser/sync/test/integration/typed_urls_helper.h",
"../browser/sync/test/integration/updated_progress_marker_checker.cc",
"../browser/sync/test/integration/updated_progress_marker_checker.h",
"../browser/sync/test/integration/wallet_helper.cc",
"../browser/sync/test/integration/wallet_helper.h",
"../browser/sync/test/integration/wifi_credentials_helper.cc",
"../browser/sync/test/integration/wifi_credentials_helper.h",
"../browser/sync/test/integration/wifi_credentials_helper_chromeos.cc",
......@@ -5377,6 +5379,7 @@ if (!is_android && !is_fuchsia) {
"../browser/sync/test/integration/two_client_themes_sync_test.cc",
"../browser/sync/test/integration/two_client_typed_urls_sync_test.cc",
"../browser/sync/test/integration/two_client_uss_sync_test.cc",
"../browser/sync/test/integration/two_client_wallet_sync_test.cc",
"data/resource.rc",
]
......
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