Commit 1ee2fec2 authored by Siyu An's avatar Siyu An Committed by Commit Bot

[Autofill Offer] Implement client tag and storage key

Introduced the autofill_offer_data which will be shared by
chrome client codebase.

Also added tests.

Bug: 1112095
Change-Id: If335e20074b580f5caa613b7360e24f884da8081
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2391906
Commit-Queue: Siyu An <siyua@chromium.org>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805150}
parent 2ac3dbed
...@@ -83,6 +83,8 @@ static_library("browser") { ...@@ -83,6 +83,8 @@ static_library("browser") {
"data_model/autofill_data_model.h", "data_model/autofill_data_model.h",
"data_model/autofill_metadata.cc", "data_model/autofill_metadata.cc",
"data_model/autofill_metadata.h", "data_model/autofill_metadata.h",
"data_model/autofill_offer_data.cc",
"data_model/autofill_offer_data.h",
"data_model/autofill_profile.cc", "data_model/autofill_profile.cc",
"data_model/autofill_profile.h", "data_model/autofill_profile.h",
"data_model/autofill_profile_comparator.cc", "data_model/autofill_profile_comparator.cc",
...@@ -636,6 +638,7 @@ source_set("unit_tests") { ...@@ -636,6 +638,7 @@ source_set("unit_tests") {
"webdata/autofill_sync_bridge_util_unittest.cc", "webdata/autofill_sync_bridge_util_unittest.cc",
"webdata/autofill_table_unittest.cc", "webdata/autofill_table_unittest.cc",
"webdata/autofill_wallet_metadata_sync_bridge_unittest.cc", "webdata/autofill_wallet_metadata_sync_bridge_unittest.cc",
"webdata/autofill_wallet_offer_sync_bridge_unittest.cc",
"webdata/autofill_wallet_sync_bridge_unittest.cc", "webdata/autofill_wallet_sync_bridge_unittest.cc",
"webdata/web_data_service_unittest.cc", "webdata/web_data_service_unittest.cc",
] ]
......
...@@ -580,6 +580,20 @@ CreditCardCloudTokenData GetCreditCardCloudTokenData2() { ...@@ -580,6 +580,20 @@ CreditCardCloudTokenData GetCreditCardCloudTokenData2() {
return data; return data;
} }
AutofillOfferData GetCardLinkedOfferData() {
AutofillOfferData data;
data.offer_id = 111;
data.offer_reward_amount = "5%";
// Sets the expiry to be 45 days later.
data.expiry = AutofillClock::Now() + base::TimeDelta::FromDays(45);
data.offer_details_url = GURL("http://www.example.com");
data.merchant_domain = std::vector<GURL>();
data.merchant_domain.emplace_back(GURL("http://www.example.com"));
data.eligible_instrument_id = std::vector<int64_t>();
data.eligible_instrument_id.emplace_back(111111);
return data;
}
void SetProfileInfo(AutofillProfile* profile, void SetProfileInfo(AutofillProfile* profile,
const char* first_name, const char* first_name,
const char* middle_name, const char* middle_name,
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <vector> #include <vector>
#include "components/autofill/core/browser/autofill_field.h" #include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/data_model/autofill_offer_data.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h" #include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/data_model/credit_card.h" #include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/data_model/credit_card_cloud_token_data.h" #include "components/autofill/core/browser/data_model/credit_card_cloud_token_data.h"
...@@ -182,6 +183,9 @@ CreditCardCloudTokenData GetCreditCardCloudTokenData1(); ...@@ -182,6 +183,9 @@ CreditCardCloudTokenData GetCreditCardCloudTokenData1();
// one above. // one above.
CreditCardCloudTokenData GetCreditCardCloudTokenData2(); CreditCardCloudTokenData GetCreditCardCloudTokenData2();
// Returns an autofill card linked offer data full of dummy info.
AutofillOfferData GetCardLinkedOfferData();
// A unit testing utility that is common to a number of the Autofill unit // A unit testing utility that is common to a number of the Autofill unit
// tests. |SetProfileInfo| provides a quick way to populate a profile with // tests. |SetProfileInfo| provides a quick way to populate a profile with
// c-strings. // c-strings.
......
// Copyright 2020 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 "components/autofill/core/browser/data_model/autofill_offer_data.h"
namespace autofill {
AutofillOfferData::AutofillOfferData() = default;
AutofillOfferData::~AutofillOfferData() = default;
AutofillOfferData::AutofillOfferData(const AutofillOfferData&) = default;
AutofillOfferData& AutofillOfferData::operator=(const AutofillOfferData&) =
default;
} // namespace autofill
\ No newline at end of file
// Copyright 2020 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 COMPONENTS_AUTOFILL_CORE_BROWSER_DATA_MODEL_AUTOFILL_OFFER_DATA_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_DATA_MODEL_AUTOFILL_OFFER_DATA_H_
#include <string>
#include <vector>
#include "base/time/time.h"
#include "url/gurl.h"
namespace autofill {
// Represents an offer for certain merchants redeemable with certain cards.
// Merchants are determined by |merchant_domain| and the unique ids of cards are
// stored in |eligible_instrument_id|.
struct AutofillOfferData {
public:
AutofillOfferData();
~AutofillOfferData();
AutofillOfferData(const AutofillOfferData&);
AutofillOfferData& operator=(const AutofillOfferData&);
// The unique server ID for this offer data.
int64_t offer_id;
// The string including the reward details of the offer. Could be either
// percentage off (XXX%) or fixed amount off ($XXX).
std::string offer_reward_amount;
// The timestamp when the offer will expire. Expired offers will not be shown
// in the frontend.
base::Time expiry;
// The URL that contains the offer details.
GURL offer_details_url;
// The merchant URLs where this offer can be redeemed.
std::vector<GURL> merchant_domain;
// The ids of the cards this offer can be applied to.
std::vector<int64_t> eligible_instrument_id;
};
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_DATA_MODEL_AUTOFILL_OFFER_DATA_H_
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_data_util.h" #include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/data_model/autofill_offer_data.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h" #include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/data_model/credit_card.h" #include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/data_model/credit_card_cloud_token_data.h" #include "components/autofill/core/browser/data_model/credit_card_cloud_token_data.h"
...@@ -285,6 +286,29 @@ void SetAutofillWalletSpecificsFromCreditCardCloudTokenData( ...@@ -285,6 +286,29 @@ void SetAutofillWalletSpecificsFromCreditCardCloudTokenData(
cloud_token_data.instrument_token); cloud_token_data.instrument_token);
} }
void SetAutofillOfferSpecificsFromOfferData(
const AutofillOfferData& offer_data,
sync_pb::AutofillOfferSpecifics* offer_specifics) {
offer_specifics->set_id(offer_data.offer_id);
offer_specifics->set_offer_details_url(offer_data.offer_details_url.spec());
for (const GURL& domain : offer_data.merchant_domain) {
offer_specifics->add_merchant_domain(domain.spec());
}
offer_specifics->set_offer_expiry_date(
(offer_data.expiry - base::Time::UnixEpoch()).InSeconds());
for (int64_t instrument_id : offer_data.eligible_instrument_id) {
offer_specifics->mutable_card_linked_offer_data()->add_instrument_id(
instrument_id);
}
if (offer_data.offer_reward_amount.find("%") != std::string::npos) {
offer_specifics->mutable_percentage_reward()->set_percentage(
offer_data.offer_reward_amount);
} else {
offer_specifics->mutable_fixed_amount_reward()->set_amount(
offer_data.offer_reward_amount);
}
}
AutofillProfile ProfileFromSpecifics( AutofillProfile ProfileFromSpecifics(
const sync_pb::WalletPostalAddress& address) { const sync_pb::WalletPostalAddress& address) {
AutofillProfile profile(AutofillProfile::SERVER_PROFILE, std::string()); AutofillProfile profile(AutofillProfile::SERVER_PROFILE, std::string());
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
namespace autofill { namespace autofill {
struct AutofillOfferData;
class AutofillProfile; class AutofillProfile;
class AutofillTable; class AutofillTable;
class CreditCard; class CreditCard;
...@@ -56,6 +57,11 @@ void SetAutofillWalletSpecificsFromCreditCardCloudTokenData( ...@@ -56,6 +57,11 @@ void SetAutofillWalletSpecificsFromCreditCardCloudTokenData(
sync_pb::AutofillWalletSpecifics* wallet_specifics, sync_pb::AutofillWalletSpecifics* wallet_specifics,
bool enforce_utf8 = false); bool enforce_utf8 = false);
// Sets the fields of the |offer_specifics| based on the specified |offer_data|.
void SetAutofillOfferSpecificsFromOfferData(
const AutofillOfferData& offer_data,
sync_pb::AutofillOfferSpecifics* offer_specifics);
// Creates an AutofillProfile from the specified |address| specifics. // Creates an AutofillProfile from the specified |address| specifics.
AutofillProfile ProfileFromSpecifics( AutofillProfile ProfileFromSpecifics(
const sync_pb::WalletPostalAddress& address); const sync_pb::WalletPostalAddress& address);
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <vector> #include <vector>
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/data_model/autofill_offer_data.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h" #include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/data_model/credit_card.h" #include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/data_model/credit_card_cloud_token_data.h" #include "components/autofill/core/browser/data_model/credit_card_cloud_token_data.h"
...@@ -237,5 +239,36 @@ TEST_F(AutofillSyncBridgeUtilTest, ...@@ -237,5 +239,36 @@ TEST_F(AutofillSyncBridgeUtilTest,
EXPECT_EQ(disk_time, wallet_cards.back().use_date()); EXPECT_EQ(disk_time, wallet_cards.back().use_date());
} }
// Test to ensure the an AutofillOfferData is correctly converted to an
// AutofillOfferSpecifics.
TEST_F(AutofillSyncBridgeUtilTest, OfferSpecificsFromOfferData) {
sync_pb::AutofillOfferSpecifics offer_specifics;
AutofillOfferData offer_data = test::GetCardLinkedOfferData();
SetAutofillOfferSpecificsFromOfferData(offer_data, &offer_specifics);
EXPECT_EQ(offer_specifics.id(), offer_data.offer_id);
EXPECT_EQ(offer_specifics.offer_details_url(), offer_data.offer_details_url);
EXPECT_EQ(offer_specifics.offer_expiry_date(),
(offer_data.expiry - base::Time::UnixEpoch()).InSeconds());
EXPECT_TRUE(offer_specifics.percentage_reward().percentage() ==
offer_data.offer_reward_amount ||
offer_specifics.fixed_amount_reward().amount() ==
offer_data.offer_reward_amount);
EXPECT_EQ(offer_specifics.merchant_domain().size(),
(int)offer_data.merchant_domain.size());
for (int i = 0; i < offer_specifics.merchant_domain().size(); i++) {
EXPECT_EQ(offer_specifics.merchant_domain(i),
offer_data.merchant_domain[i].spec());
}
EXPECT_EQ(offer_specifics.card_linked_offer_data().instrument_id().size(),
(int)offer_data.eligible_instrument_id.size());
for (int i = 0;
i < offer_specifics.card_linked_offer_data().instrument_id().size();
i++) {
EXPECT_EQ(offer_specifics.card_linked_offer_data().instrument_id(i),
offer_data.eligible_instrument_id[i]);
}
}
} // namespace } // namespace
} // namespace autofill } // namespace autofill
...@@ -3135,7 +3135,8 @@ bool AutofillTable::SupportsMetadataForModelType( ...@@ -3135,7 +3135,8 @@ bool AutofillTable::SupportsMetadataForModelType(
return (model_type == syncer::AUTOFILL || return (model_type == syncer::AUTOFILL ||
model_type == syncer::AUTOFILL_PROFILE || model_type == syncer::AUTOFILL_PROFILE ||
model_type == syncer::AUTOFILL_WALLET_DATA || model_type == syncer::AUTOFILL_WALLET_DATA ||
model_type == syncer::AUTOFILL_WALLET_METADATA); model_type == syncer::AUTOFILL_WALLET_METADATA ||
model_type == syncer::AUTOFILL_WALLET_OFFER);
} }
int AutofillTable::GetKeyValueForModelType(syncer::ModelType model_type) const { int AutofillTable::GetKeyValueForModelType(syncer::ModelType model_type) const {
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <utility> #include <utility>
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "components/autofill/core/browser/data_model/autofill_offer_data.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h" #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/sync/model_impl/client_tag_based_model_type_processor.h" #include "components/sync/model_impl/client_tag_based_model_type_processor.h"
...@@ -17,6 +19,17 @@ namespace { ...@@ -17,6 +19,17 @@ namespace {
// Address to this variable used as the user data key. // Address to this variable used as the user data key.
static int kAutofillWalletOfferSyncBridgeUserDataKey = 0; static int kAutofillWalletOfferSyncBridgeUserDataKey = 0;
std::string GetClientTagFromSpecifics(
const sync_pb::AutofillOfferSpecifics& specifics) {
return base::NumberToString(specifics.id());
}
std::string GetStorageKeyFromSpecifics(
const sync_pb::AutofillOfferSpecifics& specifics) {
// Use client tag as the storage key.
return GetClientTagFromSpecifics(specifics);
}
} // namespace } // namespace
// static // static
...@@ -28,7 +41,8 @@ void AutofillWalletOfferSyncBridge::CreateForWebDataServiceAndBackend( ...@@ -28,7 +41,8 @@ void AutofillWalletOfferSyncBridge::CreateForWebDataServiceAndBackend(
std::make_unique<AutofillWalletOfferSyncBridge>( std::make_unique<AutofillWalletOfferSyncBridge>(
std::make_unique<syncer::ClientTagBasedModelTypeProcessor>( std::make_unique<syncer::ClientTagBasedModelTypeProcessor>(
syncer::AUTOFILL_WALLET_OFFER, syncer::AUTOFILL_WALLET_OFFER,
/*dump_stack=*/base::RepeatingClosure()))); /*dump_stack=*/base::RepeatingClosure()),
web_data_backend));
} }
// static // static
...@@ -40,8 +54,11 @@ syncer::ModelTypeSyncBridge* AutofillWalletOfferSyncBridge::FromWebDataService( ...@@ -40,8 +54,11 @@ syncer::ModelTypeSyncBridge* AutofillWalletOfferSyncBridge::FromWebDataService(
} }
AutofillWalletOfferSyncBridge::AutofillWalletOfferSyncBridge( AutofillWalletOfferSyncBridge::AutofillWalletOfferSyncBridge(
std::unique_ptr<syncer::ModelTypeChangeProcessor> change_processor) std::unique_ptr<syncer::ModelTypeChangeProcessor> change_processor,
: ModelTypeSyncBridge(std::move(change_processor)) {} AutofillWebDataBackend* web_data_backend)
: ModelTypeSyncBridge(std::move(change_processor)) {
DCHECK(web_data_backend);
}
AutofillWalletOfferSyncBridge::~AutofillWalletOfferSyncBridge() = default; AutofillWalletOfferSyncBridge::~AutofillWalletOfferSyncBridge() = default;
...@@ -78,14 +95,16 @@ void AutofillWalletOfferSyncBridge::GetAllDataForDebugging( ...@@ -78,14 +95,16 @@ void AutofillWalletOfferSyncBridge::GetAllDataForDebugging(
std::string AutofillWalletOfferSyncBridge::GetClientTag( std::string AutofillWalletOfferSyncBridge::GetClientTag(
const syncer::EntityData& entity_data) { const syncer::EntityData& entity_data) {
NOTIMPLEMENTED(); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return ""; DCHECK(entity_data.specifics.has_autofill_offer());
return GetClientTagFromSpecifics(entity_data.specifics.autofill_offer());
} }
std::string AutofillWalletOfferSyncBridge::GetStorageKey( std::string AutofillWalletOfferSyncBridge::GetStorageKey(
const syncer::EntityData& entity_data) { const syncer::EntityData& entity_data) {
NOTIMPLEMENTED(); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return ""; DCHECK(entity_data.specifics.has_autofill_offer());
return GetStorageKeyFromSpecifics(entity_data.specifics.autofill_offer());
} }
bool AutofillWalletOfferSyncBridge::SupportsIncrementalUpdates() const { bool AutofillWalletOfferSyncBridge::SupportsIncrementalUpdates() const {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "base/sequence_checker.h"
#include "base/supports_user_data.h" #include "base/supports_user_data.h"
#include "components/sync/model/metadata_change_list.h" #include "components/sync/model/metadata_change_list.h"
#include "components/sync/model/model_error.h" #include "components/sync/model/model_error.h"
...@@ -35,7 +36,8 @@ class AutofillWalletOfferSyncBridge : public base::SupportsUserData::Data, ...@@ -35,7 +36,8 @@ class AutofillWalletOfferSyncBridge : public base::SupportsUserData::Data,
AutofillWebDataService* web_data_service); AutofillWebDataService* web_data_service);
explicit AutofillWalletOfferSyncBridge( explicit AutofillWalletOfferSyncBridge(
std::unique_ptr<syncer::ModelTypeChangeProcessor> change_processor); std::unique_ptr<syncer::ModelTypeChangeProcessor> change_processor,
AutofillWebDataBackend* web_data_backend);
~AutofillWalletOfferSyncBridge() override; ~AutofillWalletOfferSyncBridge() override;
AutofillWalletOfferSyncBridge(const AutofillWalletOfferSyncBridge&) = delete; AutofillWalletOfferSyncBridge(const AutofillWalletOfferSyncBridge&) = delete;
...@@ -58,6 +60,10 @@ class AutofillWalletOfferSyncBridge : public base::SupportsUserData::Data, ...@@ -58,6 +60,10 @@ class AutofillWalletOfferSyncBridge : public base::SupportsUserData::Data,
bool SupportsIncrementalUpdates() const override; bool SupportsIncrementalUpdates() const override;
void ApplyStopSyncChanges(std::unique_ptr<syncer::MetadataChangeList> void ApplyStopSyncChanges(std::unique_ptr<syncer::MetadataChangeList>
delete_metadata_change_list) override; delete_metadata_change_list) override;
private:
// The bridge should be used on the same sequence where it is constructed.
SEQUENCE_CHECKER(sequence_checker_);
}; };
} // namespace autofill } // namespace autofill
......
// Copyright 2020 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 "components/autofill/core/browser/webdata/autofill_wallet_offer_sync_bridge.h"
#include <stddef.h>
#include <memory>
#include <utility>
#include "base/files/scoped_temp_dir.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/geo/country_names.h"
#include "components/autofill/core/browser/test_autofill_clock.h"
#include "components/autofill/core/browser/webdata/autofill_sync_bridge_util.h"
#include "components/autofill/core/browser/webdata/autofill_table.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_backend.h"
#include "components/autofill/core/browser/webdata/mock_autofill_webdata_backend.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/sync/base/hash_util.h"
#include "components/sync/model/entity_data.h"
#include "components/sync/model/mock_model_type_change_processor.h"
#include "components/sync/model/sync_data.h"
#include "components/sync/model_impl/client_tag_based_model_type_processor.h"
#include "components/sync/protocol/autofill_specifics.pb.h"
#include "components/sync/protocol/sync.pb.h"
#include "components/webdata/common/web_database.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace autofill {
namespace {
using base::ScopedTempDir;
using sync_pb::AutofillOfferSpecifics;
using sync_pb::ModelTypeState;
using syncer::EntityData;
using syncer::MockModelTypeChangeProcessor;
using testing::NiceMock;
using testing::Return;
const char kLocaleString[] = "en-US";
const char kDefaultCacheGuid[] = "CacheGuid";
} // namespace
class AutofillWalletOfferSyncBridgeTest : public testing::Test {
public:
AutofillWalletOfferSyncBridgeTest() = default;
~AutofillWalletOfferSyncBridgeTest() override = default;
AutofillWalletOfferSyncBridgeTest(const AutofillWalletOfferSyncBridgeTest&) =
delete;
AutofillWalletOfferSyncBridgeTest& operator=(
const AutofillWalletOfferSyncBridgeTest&) = delete;
void SetUp() override {
CountryNames::SetLocaleString(kLocaleString);
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
db_.AddTable(&table_);
db_.Init(temp_dir_.GetPath().AppendASCII("SyncTestWebDatabase"));
ON_CALL(backend_, GetDatabase()).WillByDefault(Return(&db_));
ResetProcessor();
// Fake that initial sync has been done (so that the bridge immediately
// records metrics).
ResetBridge(/*initial_sync_done=*/true);
}
void ResetProcessor() {
real_processor_ =
std::make_unique<syncer::ClientTagBasedModelTypeProcessor>(
syncer::AUTOFILL_WALLET_OFFER, /*dump_stack=*/base::DoNothing(),
/*commit_only=*/false);
mock_processor_.DelegateCallsByDefaultTo(real_processor_.get());
}
void ResetBridge(bool initial_sync_done) {
ModelTypeState model_type_state;
model_type_state.set_initial_sync_done(initial_sync_done);
model_type_state.mutable_progress_marker()->set_data_type_id(
GetSpecificsFieldNumberFromModelType(syncer::AUTOFILL_WALLET_OFFER));
model_type_state.set_cache_guid(kDefaultCacheGuid);
EXPECT_TRUE(table()->UpdateModelTypeState(syncer::AUTOFILL_WALLET_OFFER,
model_type_state));
bridge_ = std::make_unique<AutofillWalletOfferSyncBridge>(
mock_processor_.CreateForwardingProcessor(), &backend_);
}
EntityData SpecificsToEntity(const AutofillOfferSpecifics& specifics) {
EntityData data;
*data.specifics.mutable_autofill_offer() = specifics;
data.client_tag_hash = syncer::ClientTagHash::FromUnhashed(
syncer::AUTOFILL_WALLET_OFFER, bridge()->GetClientTag(data));
return data;
}
AutofillTable* table() { return &table_; }
AutofillWalletOfferSyncBridge* bridge() { return bridge_.get(); }
private:
ScopedTempDir temp_dir_;
base::test::SingleThreadTaskEnvironment task_environment_;
NiceMock<MockAutofillWebDataBackend> backend_;
AutofillTable table_;
WebDatabase db_;
NiceMock<MockModelTypeChangeProcessor> mock_processor_;
std::unique_ptr<syncer::ClientTagBasedModelTypeProcessor> real_processor_;
std::unique_ptr<AutofillWalletOfferSyncBridge> bridge_;
};
TEST_F(AutofillWalletOfferSyncBridgeTest, VerifyGetClientTag) {
AutofillOfferSpecifics specifics;
AutofillOfferData data = test::GetCardLinkedOfferData();
SetAutofillOfferSpecificsFromOfferData(data, &specifics);
EXPECT_EQ(bridge()->GetClientTag(SpecificsToEntity(specifics)),
base::NumberToString(data.offer_id));
}
TEST_F(AutofillWalletOfferSyncBridgeTest, VerifyGetStorageKey) {
AutofillOfferSpecifics specifics;
AutofillOfferData data = test::GetCardLinkedOfferData();
SetAutofillOfferSpecificsFromOfferData(data, &specifics);
EXPECT_EQ(bridge()->GetStorageKey(SpecificsToEntity(specifics)),
base::NumberToString(data.offer_id));
}
} // namespace autofill
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