Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "components/sync/engine_impl/test_entry_factory.h" | 5 #include "components/sync/engine_impl/test_entry_factory.h" |
| 6 | 6 |
| 7 #include "components/sync/base/model_type.h" | |
| 7 #include "components/sync/syncable/directory.h" | 8 #include "components/sync/syncable/directory.h" |
| 8 #include "components/sync/syncable/entry.h" | 9 #include "components/sync/syncable/entry.h" |
| 10 #include "components/sync/syncable/model_neutral_mutable_entry.h" | |
| 9 #include "components/sync/syncable/mutable_entry.h" | 11 #include "components/sync/syncable/mutable_entry.h" |
| 10 #include "components/sync/syncable/syncable_id.h" | 12 #include "components/sync/syncable/syncable_id.h" |
| 13 #include "components/sync/syncable/syncable_model_neutral_write_transaction.h" | |
| 11 #include "components/sync/syncable/syncable_read_transaction.h" | 14 #include "components/sync/syncable/syncable_read_transaction.h" |
| 12 #include "components/sync/syncable/syncable_util.h" | 15 #include "components/sync/syncable/syncable_util.h" |
| 13 #include "components/sync/syncable/syncable_write_transaction.h" | 16 #include "components/sync/syncable/syncable_write_transaction.h" |
| 14 #include "components/sync/test/engine/test_id_factory.h" | 17 #include "components/sync/test/engine/test_id_factory.h" |
| 15 | 18 |
| 16 using std::string; | 19 using std::string; |
| 17 | 20 |
| 18 namespace syncer { | 21 namespace syncer { |
| 19 | 22 |
| 20 using syncable::Id; | 23 using syncable::Id; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 | 137 |
| 135 entry.PutIsUnappliedUpdate(true); | 138 entry.PutIsUnappliedUpdate(true); |
| 136 entry.PutServerVersion(GetNextRevision()); | 139 entry.PutServerVersion(GetNextRevision()); |
| 137 | 140 |
| 138 return metahandle; | 141 return metahandle; |
| 139 } | 142 } |
| 140 | 143 |
| 141 int64_t TestEntryFactory::CreateSyncedItem(const std::string& name, | 144 int64_t TestEntryFactory::CreateSyncedItem(const std::string& name, |
| 142 ModelType model_type, | 145 ModelType model_type, |
| 143 bool is_folder) { | 146 bool is_folder) { |
| 147 return CreateSyncedItem(name, model_type, is_folder, | |
| 148 sync_pb::EntitySpecifics()); | |
| 149 } | |
| 150 | |
| 151 int64_t TestEntryFactory::CreateSyncedItem( | |
| 152 const std::string& name, | |
| 153 ModelType model_type, | |
| 154 bool is_folder, | |
| 155 const sync_pb::EntitySpecifics& specifics) { | |
| 156 int64_t version = GetNextRevision(); | |
| 157 base::Time now = base::Time::Now(); | |
|
skym
2016/10/21 15:34:20
Time::Now() is difficult to test.
maxbogue
2016/10/24 19:02:18
Testing that it's not null seems fine. You'd rathe
skym
2016/10/25 15:48:12
Yes, I think I have another comment about wanting
maxbogue
2016/10/26 23:26:15
Acknowledged.
| |
| 158 syncable::Id item_id(TestIdFactory::MakeServer(name)); | |
| 159 syncable::Id parent_id; | |
| 160 { | |
| 161 syncable::ReadTransaction trans(FROM_HERE, directory_); | |
|
skym
2016/10/21 15:34:20
Why not move the WriteTransaction up higher and re
maxbogue
2016/10/24 19:02:18
Didn't occur to me that you could use a WriteTrans
| |
| 162 syncable::Entry root(&trans, syncable::GET_TYPE_ROOT, model_type); | |
| 163 if (root.good()) { | |
| 164 parent_id = root.GetId(); | |
| 165 } else { | |
| 166 parent_id = TestIdFactory::root(); | |
| 167 } | |
| 168 } | |
| 169 | |
| 144 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); | 170 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
| 145 | |
| 146 syncable::Id parent_id(TestIdFactory::root()); | |
| 147 syncable::Id item_id(TestIdFactory::MakeServer(name)); | |
| 148 int64_t version = GetNextRevision(); | |
| 149 | |
| 150 MutableEntry entry(&trans, syncable::CREATE, model_type, parent_id, name); | 171 MutableEntry entry(&trans, syncable::CREATE, model_type, parent_id, name); |
| 151 if (!entry.good()) { | 172 if (!entry.good()) { |
| 152 NOTREACHED(); | 173 NOTREACHED(); |
| 153 return syncable::kInvalidMetaHandle; | 174 return syncable::kInvalidMetaHandle; |
| 154 } | 175 } |
| 155 | 176 |
| 156 entry.PutId(item_id); | 177 entry.PutId(item_id); |
| 178 entry.PutCtime(now); | |
| 179 entry.PutMtime(now); | |
| 180 entry.PutUniqueClientTag(syncable::GenerateSyncableHash(model_type, name)); | |
| 157 entry.PutBaseVersion(version); | 181 entry.PutBaseVersion(version); |
| 158 entry.PutIsUnsynced(false); | 182 entry.PutIsUnsynced(false); |
| 159 entry.PutNonUniqueName(name); | 183 entry.PutNonUniqueName(name); |
| 160 entry.PutIsDir(is_folder); | 184 entry.PutIsDir(is_folder); |
| 161 entry.PutIsDel(false); | 185 entry.PutIsDel(false); |
| 162 entry.PutParentId(parent_id); | 186 entry.PutParentId(parent_id); |
| 163 | 187 |
| 164 entry.PutServerVersion(GetNextRevision()); | 188 entry.PutServerCtime(now); |
| 189 entry.PutServerMtime(now); | |
| 190 entry.PutServerVersion(version); | |
| 165 entry.PutIsUnappliedUpdate(false); | 191 entry.PutIsUnappliedUpdate(false); |
| 166 entry.PutServerNonUniqueName(name); | 192 entry.PutServerNonUniqueName(name); |
| 167 entry.PutServerParentId(parent_id); | 193 entry.PutServerParentId(parent_id); |
| 168 entry.PutServerIsDir(is_folder); | 194 entry.PutServerIsDir(is_folder); |
| 169 entry.PutServerIsDel(false); | 195 entry.PutServerIsDel(false); |
| 170 entry.PutServerSpecifics(entry.GetSpecifics()); | 196 |
| 197 // Only rewrite the default specifics (which have the model type marker | |
| 198 // already) if the new ones have data in them. | |
| 199 if (specifics.ByteSize() > 0) { | |
|
skym
2016/10/21 15:34:20
How can specifics have the model type marker and y
maxbogue
2016/10/24 19:02:18
The default specifics already in the entry have th
skym
2016/10/25 15:48:11
Gotcha. Can you update this comment to mention whe
maxbogue
2016/10/26 23:26:15
Done.
| |
| 200 entry.PutSpecifics(specifics); | |
| 201 entry.PutServerSpecifics(specifics); | |
| 202 } else { | |
| 203 entry.PutServerSpecifics(entry.GetSpecifics()); | |
| 204 } | |
| 171 | 205 |
| 172 return entry.GetMetahandle(); | 206 return entry.GetMetahandle(); |
| 173 } | 207 } |
| 174 | 208 |
| 209 int64_t TestEntryFactory::CreateTypeRootNode(ModelType model_type) { | |
| 210 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, syncable::UNITTEST, | |
| 211 directory_); | |
| 212 sync_pb::EntitySpecifics specifics; | |
| 213 AddDefaultFieldValue(model_type, &specifics); | |
| 214 syncable::ModelNeutralMutableEntry entry( | |
| 215 &trans, syncable::CREATE_NEW_TYPE_ROOT, model_type); | |
| 216 DCHECK(entry.good()); | |
| 217 entry.PutServerIsDir(true); | |
| 218 entry.PutUniqueServerTag(ModelTypeToRootTag(model_type)); | |
| 219 return entry.GetMetahandle(); | |
| 220 } | |
| 221 | |
| 175 int64_t TestEntryFactory::CreateUnappliedRootNode(ModelType model_type) { | 222 int64_t TestEntryFactory::CreateUnappliedRootNode(ModelType model_type) { |
| 176 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory_); | 223 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory_); |
| 177 sync_pb::EntitySpecifics specifics; | 224 sync_pb::EntitySpecifics specifics; |
| 178 AddDefaultFieldValue(model_type, &specifics); | 225 AddDefaultFieldValue(model_type, &specifics); |
| 179 syncable::Id node_id = TestIdFactory::MakeServer("xyz"); | 226 syncable::Id node_id = TestIdFactory::MakeServer("xyz"); |
| 180 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, | 227 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
| 181 node_id); | 228 node_id); |
| 182 DCHECK(entry.good()); | 229 DCHECK(entry.good()); |
| 183 // Make it look like sort of like a pending creation from the server. | 230 // Make it look like sort of like a pending creation from the server. |
| 184 // The SERVER_PARENT_ID and UNIQUE_CLIENT_TAG aren't quite right, but | 231 // The SERVER_PARENT_ID and UNIQUE_CLIENT_TAG aren't quite right, but |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 return false; | 343 return false; |
| 297 } | 344 } |
| 298 return entry.GetIsUnappliedUpdate(); | 345 return entry.GetIsUnappliedUpdate(); |
| 299 } | 346 } |
| 300 | 347 |
| 301 int64_t TestEntryFactory::GetNextRevision() { | 348 int64_t TestEntryFactory::GetNextRevision() { |
| 302 return next_revision_++; | 349 return next_revision_++; |
| 303 } | 350 } |
| 304 | 351 |
| 305 } // namespace syncer | 352 } // namespace syncer |
| OLD | NEW |