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

Side by Side Diff: sync/internal_api/processor_entity_tracker_unittest.cc

Issue 1918923002: [Sync] USS: Ignore encryption changes during conflict resolution 1/2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/internal_api/public/processor_entity_tracker.h" 5 #include "sync/internal_api/public/processor_entity_tracker.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "sync/internal_api/public/base/model_type.h" 14 #include "sync/internal_api/public/base/model_type.h"
15 #include "sync/internal_api/public/non_blocking_sync_common.h" 15 #include "sync/internal_api/public/non_blocking_sync_common.h"
16 #include "sync/protocol/sync.pb.h" 16 #include "sync/protocol/sync.pb.h"
17 #include "sync/syncable/syncable_util.h" 17 #include "sync/syncable/syncable_util.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 namespace syncer_v2 { 20 namespace syncer_v2 {
21 21
22 namespace {
23
24 const std::string kTag1 = "tag1";
25 const std::string kTag2 = "tag2";
26 const std::string kTag3 = "tag3";
27 const std::string kValue1 = "value1";
28 const std::string kValue2 = "value2";
29 const std::string kValue3 = "value3";
30
31 std::string GenerateTagHash(const std::string& tag) {
32 return syncer::syncable::GenerateSyncableHash(syncer::PREFERENCES, tag);
33 }
34
35 sync_pb::EntitySpecifics GenerateSpecifics(const std::string& tag,
36 const std::string& value) {
37 sync_pb::EntitySpecifics specifics;
38 specifics.mutable_preference()->set_name(tag);
39 specifics.mutable_preference()->set_value(value);
40 return specifics;
41 }
42
43 } // namespace
44
22 // Some simple sanity tests for the ProcessorEntityTracker. 45 // Some simple sanity tests for the ProcessorEntityTracker.
23 // 46 //
24 // A lot of the more complicated sync logic is implemented in the 47 // A lot of the more complicated sync logic is implemented in the
25 // SharedModelTypeProcessor that owns the ProcessorEntityTracker. We can't unit 48 // SharedModelTypeProcessor that owns the ProcessorEntityTracker. We can't unit
26 // test it here. 49 // test it here.
27 // 50 //
28 // Instead, we focus on simple tests to make sure that variables are getting 51 // Instead, we focus on simple tests to make sure that variables are getting
29 // properly intialized and flags properly set. Anything more complicated would 52 // properly intialized and flags properly set. Anything more complicated would
30 // be a redundant and incomplete version of the SharedModelTypeProcessor tests. 53 // be a redundant and incomplete version of the SharedModelTypeProcessor tests.
31 class ProcessorEntityTrackerTest : public ::testing::Test { 54 class ProcessorEntityTrackerTest : public ::testing::Test {
32 public: 55 public:
33 ProcessorEntityTrackerTest() 56 ProcessorEntityTrackerTest()
34 : kServerId("ServerID"), 57 : kServerId("ServerID"),
35 kClientTag("sample.pref.name"), 58 kClientTag("sample.pref.name"),
36 kClientTagHash(GetSyncableHash(kClientTag)), 59 kClientTagHash(GenerateTagHash(kClientTag)),
37 kCtime(base::Time::UnixEpoch() + base::TimeDelta::FromDays(10)), 60 kCtime(base::Time::UnixEpoch() + base::TimeDelta::FromDays(10)),
38 kMtime(base::Time::UnixEpoch() + base::TimeDelta::FromDays(20)) { 61 kMtime(base::Time::UnixEpoch() + base::TimeDelta::FromDays(20)),
39 sync_pb::PreferenceSpecifics* pref_specifics = 62 specifics(GenerateSpecifics(kClientTag, kValue1)) {}
40 specifics.mutable_preference();
41 pref_specifics->set_name(kClientTag);
42 pref_specifics->set_value("pref.value");
43 }
44
45 static std::string GetSyncableHash(const std::string& tag) {
46 return syncer::syncable::GenerateSyncableHash(syncer::PREFERENCES, tag);
47 }
48 63
49 std::unique_ptr<ProcessorEntityTracker> NewLocalItem(const std::string& tag) { 64 std::unique_ptr<ProcessorEntityTracker> NewLocalItem(const std::string& tag) {
50 return std::unique_ptr<ProcessorEntityTracker>( 65 return std::unique_ptr<ProcessorEntityTracker>(
51 ProcessorEntityTracker::CreateNew(tag, GetSyncableHash(tag), "", 66 ProcessorEntityTracker::CreateNew(tag, GenerateTagHash(tag), "",
52 kCtime)); 67 kCtime));
53 } 68 }
54 69
55 std::unique_ptr<ProcessorEntityTracker> NewLocalItem( 70 std::unique_ptr<ProcessorEntityTracker> NewLocalItem(
56 const std::string& tag, 71 const std::string& tag,
57 const sync_pb::EntitySpecifics& specifics) { 72 const sync_pb::EntitySpecifics& specifics) {
58 std::unique_ptr<ProcessorEntityTracker> entity(NewLocalItem(tag)); 73 std::unique_ptr<ProcessorEntityTracker> entity(NewLocalItem(tag));
59 MakeLocalChange(entity.get(), specifics); 74 MakeLocalChange(entity.get(), specifics);
60 return entity; 75 return entity;
61 } 76 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 const std::string kClientTagHash; 133 const std::string kClientTagHash;
119 const base::Time kCtime; 134 const base::Time kCtime;
120 const base::Time kMtime; 135 const base::Time kMtime;
121 sync_pb::EntitySpecifics specifics; 136 sync_pb::EntitySpecifics specifics;
122 }; 137 };
123 138
124 TEST_F(ProcessorEntityTrackerTest, NewItem) { 139 TEST_F(ProcessorEntityTrackerTest, NewItem) {
125 std::unique_ptr<ProcessorEntityTracker> entity(NewLocalItem("asdf")); 140 std::unique_ptr<ProcessorEntityTracker> entity(NewLocalItem("asdf"));
126 141
127 EXPECT_EQ(entity->client_tag(), "asdf"); 142 EXPECT_EQ(entity->client_tag(), "asdf");
128 EXPECT_EQ(entity->metadata().client_tag_hash(), GetSyncableHash("asdf")); 143 EXPECT_EQ(entity->metadata().client_tag_hash(), GenerateTagHash("asdf"));
129 144
130 EXPECT_FALSE(entity->HasCommitData()); 145 EXPECT_FALSE(entity->HasCommitData());
131 EXPECT_FALSE(HasSpecificsHash(entity)); 146 EXPECT_FALSE(HasSpecificsHash(entity));
132 147
133 EXPECT_FALSE(entity->IsUnsynced()); 148 EXPECT_FALSE(entity->IsUnsynced());
134 EXPECT_FALSE(entity->UpdateIsReflection(1)); 149 EXPECT_FALSE(entity->UpdateIsReflection(1));
135 } 150 }
136 151
137 TEST_F(ProcessorEntityTrackerTest, NewLocalItem) { 152 TEST_F(ProcessorEntityTrackerTest, NewLocalItem) {
138 std::unique_ptr<ProcessorEntityTracker> entity( 153 std::unique_ptr<ProcessorEntityTracker> entity(
139 NewLocalItem("asdf", specifics)); 154 NewLocalItem("asdf", specifics));
140 155
141 EXPECT_EQ(1, entity->metadata().sequence_number()); 156 EXPECT_EQ(1, entity->metadata().sequence_number());
142 EXPECT_EQ(0, entity->metadata().acked_sequence_number()); 157 EXPECT_EQ(0, entity->metadata().acked_sequence_number());
143 EXPECT_EQ(kUncommittedVersion, entity->metadata().server_version()); 158 EXPECT_EQ(kUncommittedVersion, entity->metadata().server_version());
144 EXPECT_TRUE(entity->HasCommitData()); 159 EXPECT_TRUE(entity->HasCommitData());
145 EXPECT_TRUE(HasSpecificsHash(entity)); 160 EXPECT_TRUE(HasSpecificsHash(entity));
146 EXPECT_TRUE(entity->IsUnsynced()); 161 EXPECT_TRUE(entity->IsUnsynced());
147 EXPECT_FALSE(entity->UpdateIsReflection(1)); 162 EXPECT_FALSE(entity->UpdateIsReflection(1));
148 163
149 entity->ReceiveCommitResponse("id", 1, 1); 164 CommitResponseData data;
165 data.id = "id";
166 data.client_tag_hash = entity->metadata().client_tag_hash();
167 data.sequence_number = 1;
168 data.response_version = 1;
169 data.specifics_hash = entity->metadata().specifics_hash();
170 entity->ReceiveCommitResponse(data);
150 171
151 EXPECT_EQ(1, entity->metadata().sequence_number()); 172 EXPECT_EQ(1, entity->metadata().sequence_number());
152 EXPECT_EQ(1, entity->metadata().acked_sequence_number()); 173 EXPECT_EQ(1, entity->metadata().acked_sequence_number());
153 EXPECT_EQ(1, entity->metadata().server_version()); 174 EXPECT_EQ(1, entity->metadata().server_version());
154 EXPECT_FALSE(entity->HasCommitData()); 175 EXPECT_FALSE(entity->HasCommitData());
155 EXPECT_TRUE(HasSpecificsHash(entity)); 176 EXPECT_TRUE(HasSpecificsHash(entity));
177 EXPECT_TRUE(entity->metadata().base_specifics_hash().empty());
156 EXPECT_FALSE(entity->IsUnsynced()); 178 EXPECT_FALSE(entity->IsUnsynced());
157 EXPECT_TRUE(entity->UpdateIsReflection(1)); 179 EXPECT_TRUE(entity->UpdateIsReflection(1));
158 } 180 }
159 181
160 TEST_F(ProcessorEntityTrackerTest, FromServerUpdate) { 182 TEST_F(ProcessorEntityTrackerTest, FromServerUpdate) {
161 std::unique_ptr<ProcessorEntityTracker> entity(NewServerItem()); 183 std::unique_ptr<ProcessorEntityTracker> entity(NewServerItem());
162 184
163 EXPECT_EQ(entity->client_tag(), kClientTag); 185 EXPECT_EQ(entity->client_tag(), kClientTag);
164 EXPECT_EQ(entity->metadata().client_tag_hash(), kClientTagHash); 186 EXPECT_EQ(entity->metadata().client_tag_hash(), kClientTagHash);
165 EXPECT_FALSE(HasSpecificsHash(entity)); 187 EXPECT_FALSE(HasSpecificsHash(entity));
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 entity->Delete(); 300 entity->Delete();
279 301
280 entity->InitializeCommitRequestData(&commit_request); 302 entity->InitializeCommitRequestData(&commit_request);
281 const EntityData& data3 = commit_request.entity.value(); 303 const EntityData& data3 = commit_request.entity.value();
282 304
283 EXPECT_EQ(3, commit_request.sequence_number); 305 EXPECT_EQ(3, commit_request.sequence_number);
284 EXPECT_TRUE(data3.is_deleted()); 306 EXPECT_TRUE(data3.is_deleted());
285 } 307 }
286 308
287 } // namespace syncer_v2 309 } // namespace syncer_v2
OLDNEW
« no previous file with comments | « sync/internal_api/processor_entity_tracker.cc ('k') | sync/internal_api/public/non_blocking_sync_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698