Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Unified Diff: components/sync/test/engine/mock_model_type_worker.cc

Issue 2222373003: [Sync] Adding storage key concept for ModelTypeServices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing redundant hash value. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/sync/test/engine/mock_model_type_worker.h ('k') | components/sync_driver/device_info_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/sync/test/engine/mock_model_type_worker.cc
diff --git a/components/sync/test/engine/mock_model_type_worker.cc b/components/sync/test/engine/mock_model_type_worker.cc
index af40a239f58a99f1d238843ce7a8900eb7318389..34620a3c10cf3b7e3922a0f501ba5f3424ba932d 100644
--- a/components/sync/test/engine/mock_model_type_worker.cc
+++ b/components/sync/test/engine/mock_model_type_worker.cc
@@ -16,18 +16,6 @@ namespace syncer_v2 {
namespace {
-std::string GenerateTagHash(const std::string& tag) {
- return syncer::syncable::GenerateSyncableHash(syncer::PREFERENCES, tag);
-}
-
-sync_pb::EntitySpecifics GenerateSpecifics(const std::string& tag,
- const std::string& value) {
- sync_pb::EntitySpecifics specifics;
- specifics.mutable_preference()->set_name(tag);
- specifics.mutable_preference()->set_value(value);
- return specifics;
-}
-
} // namespace
MockModelTypeWorker::MockModelTypeWorker(
@@ -50,8 +38,8 @@ CommitRequestDataList MockModelTypeWorker::GetNthPendingCommit(size_t n) const {
return pending_commits_[n];
}
-bool MockModelTypeWorker::HasPendingCommitForTag(const std::string& tag) const {
- const std::string tag_hash = GenerateTagHash(tag);
+bool MockModelTypeWorker::HasPendingCommitForHash(
+ const std::string& tag_hash) const {
for (const CommitRequestDataList& commit : pending_commits_) {
for (const CommitRequestData& data : commit) {
if (data.entity->client_tag_hash == tag_hash) {
@@ -62,9 +50,8 @@ bool MockModelTypeWorker::HasPendingCommitForTag(const std::string& tag) const {
return false;
}
-CommitRequestData MockModelTypeWorker::GetLatestPendingCommitForTag(
- const std::string& tag) const {
- const std::string tag_hash = GenerateTagHash(tag);
+CommitRequestData MockModelTypeWorker::GetLatestPendingCommitForHash(
+ const std::string& tag_hash) const {
// Iterate backward through the sets of commit requests to find the most
// recent one that applies to the specified tag_hash.
for (auto rev_it = pending_commits_.rbegin();
@@ -79,54 +66,58 @@ CommitRequestData MockModelTypeWorker::GetLatestPendingCommitForTag(
return CommitRequestData();
}
-void MockModelTypeWorker::ExpectNthPendingCommit(size_t n,
- const std::string& tag,
- const std::string& value) {
+void MockModelTypeWorker::ExpectNthPendingCommit(
+ size_t n,
+ const std::string& tag_hash,
+ const sync_pb::EntitySpecifics& specifics) {
const CommitRequestDataList& list = GetNthPendingCommit(n);
ASSERT_EQ(1U, list.size());
const EntityData& data = list[0].entity.value();
- EXPECT_EQ(GenerateTagHash(tag), data.client_tag_hash);
- EXPECT_EQ(value, data.specifics.preference().value());
+ EXPECT_EQ(tag_hash, data.client_tag_hash);
+ EXPECT_EQ(specifics.SerializeAsString(), data.specifics.SerializeAsString());
}
void MockModelTypeWorker::ExpectPendingCommits(
- const std::vector<std::string>& tags) {
- EXPECT_EQ(tags.size(), GetNumPendingCommits());
- for (size_t i = 0; i < tags.size(); i++) {
+ const std::vector<std::string>& tag_hashes) {
+ EXPECT_EQ(tag_hashes.size(), GetNumPendingCommits());
+ for (size_t i = 0; i < tag_hashes.size(); i++) {
const CommitRequestDataList& commits = GetNthPendingCommit(i);
EXPECT_EQ(1U, commits.size());
- EXPECT_EQ(GenerateTagHash(tags[i]), commits[0].entity->client_tag_hash)
- << "Hash for tag " << tags[i] << " doesn't match.";
+ EXPECT_EQ(tag_hashes[i], commits[0].entity->client_tag_hash)
+ << "Hash for tag " << tag_hashes[i] << " doesn't match.";
}
}
-void MockModelTypeWorker::UpdateFromServer(const std::string& tag,
- const std::string& value) {
- UpdateFromServer(tag, value, 1);
+void MockModelTypeWorker::UpdateFromServer(
+ const std::string& tag_hash,
+ const sync_pb::EntitySpecifics& specifics) {
+ UpdateFromServer(tag_hash, specifics, 1);
}
-void MockModelTypeWorker::UpdateFromServer(const std::string& tag,
- const std::string& value,
- int64_t version_offset) {
- UpdateFromServer(tag, value, version_offset,
+void MockModelTypeWorker::UpdateFromServer(
+ const std::string& tag_hash,
+ const sync_pb::EntitySpecifics& specifics,
+ int64_t version_offset) {
+ UpdateFromServer(tag_hash, specifics, version_offset,
data_type_state_.encryption_key_name());
}
-void MockModelTypeWorker::UpdateFromServer(const std::string& tag,
- const std::string& value,
- int64_t version_offset,
- const std::string& ekn) {
+void MockModelTypeWorker::UpdateFromServer(
+ const std::string& tag_hash,
+ const sync_pb::EntitySpecifics& specifics,
+ int64_t version_offset,
+ const std::string& ekn) {
UpdateResponseDataList update;
- update.push_back(GenerateUpdateData(tag, value, version_offset, ekn));
+ update.push_back(
+ GenerateUpdateData(tag_hash, specifics, version_offset, ekn));
processor_->OnUpdateReceived(data_type_state_, update);
}
UpdateResponseData MockModelTypeWorker::GenerateUpdateData(
- const std::string& tag,
- const std::string& value,
+ const std::string& tag_hash,
+ const sync_pb::EntitySpecifics& specifics,
int64_t version_offset,
const std::string& ekn) {
- const std::string tag_hash = GenerateTagHash(tag);
// Overwrite the existing server version if this is the new highest version.
int64_t old_version = GetServerVersion(tag_hash);
int64_t version = old_version + version_offset;
@@ -137,7 +128,7 @@ UpdateResponseData MockModelTypeWorker::GenerateUpdateData(
EntityData data;
data.id = GenerateId(tag_hash);
data.client_tag_hash = tag_hash;
- data.specifics = GenerateSpecifics(tag, value);
+ data.specifics = specifics;
// These elements should have no effect on behavior, but we set them anyway
// so we can test they are properly copied around the system if we want to.
data.creation_time = base::Time::UnixEpoch() + base::TimeDelta::FromDays(1);
@@ -153,8 +144,7 @@ UpdateResponseData MockModelTypeWorker::GenerateUpdateData(
return response_data;
}
-void MockModelTypeWorker::TombstoneFromServer(const std::string& tag) {
- const std::string tag_hash = GenerateTagHash(tag);
+void MockModelTypeWorker::TombstoneFromServer(const std::string& tag_hash) {
int64_t old_version = GetServerVersion(tag_hash);
int64_t version = old_version + 1;
SetServerVersion(tag_hash, version);
« no previous file with comments | « components/sync/test/engine/mock_model_type_worker.h ('k') | components/sync_driver/device_info_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698