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

Unified Diff: components/sync/engine_impl/test_entry_factory.cc

Issue 2442583003: [Sync] Start implementation of migration for USS. (Closed)
Patch Set: Fix other tests. Created 4 years, 2 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
Index: components/sync/engine_impl/test_entry_factory.cc
diff --git a/components/sync/engine_impl/test_entry_factory.cc b/components/sync/engine_impl/test_entry_factory.cc
index cf0dfde82c234611e56fca55ffda08afb9247d27..0bca5981b8cf061a1881d2d108b6692e9301cebf 100644
--- a/components/sync/engine_impl/test_entry_factory.cc
+++ b/components/sync/engine_impl/test_entry_factory.cc
@@ -4,10 +4,13 @@
#include "components/sync/engine_impl/test_entry_factory.h"
+#include "components/sync/base/model_type.h"
#include "components/sync/syncable/directory.h"
#include "components/sync/syncable/entry.h"
+#include "components/sync/syncable/model_neutral_mutable_entry.h"
#include "components/sync/syncable/mutable_entry.h"
#include "components/sync/syncable/syncable_id.h"
+#include "components/sync/syncable/syncable_model_neutral_write_transaction.h"
#include "components/sync/syncable/syncable_read_transaction.h"
#include "components/sync/syncable/syncable_util.h"
#include "components/sync/syncable/syncable_write_transaction.h"
@@ -141,12 +144,30 @@ int64_t TestEntryFactory::CreateUnappliedAndUnsyncedBookmarkItem(
int64_t TestEntryFactory::CreateSyncedItem(const std::string& name,
ModelType model_type,
bool is_folder) {
- WriteTransaction trans(FROM_HERE, UNITTEST, directory_);
+ return CreateSyncedItem(name, model_type, is_folder,
+ sync_pb::EntitySpecifics());
+}
- syncable::Id parent_id(TestIdFactory::root());
- syncable::Id item_id(TestIdFactory::MakeServer(name));
+int64_t TestEntryFactory::CreateSyncedItem(
+ const std::string& name,
+ ModelType model_type,
+ bool is_folder,
+ const sync_pb::EntitySpecifics& specifics) {
int64_t version = GetNextRevision();
+ 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.
+ syncable::Id item_id(TestIdFactory::MakeServer(name));
+ syncable::Id parent_id;
+ {
+ 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
+ syncable::Entry root(&trans, syncable::GET_TYPE_ROOT, model_type);
+ if (root.good()) {
+ parent_id = root.GetId();
+ } else {
+ parent_id = TestIdFactory::root();
+ }
+ }
+ WriteTransaction trans(FROM_HERE, UNITTEST, directory_);
MutableEntry entry(&trans, syncable::CREATE, model_type, parent_id, name);
if (!entry.good()) {
NOTREACHED();
@@ -154,6 +175,9 @@ int64_t TestEntryFactory::CreateSyncedItem(const std::string& name,
}
entry.PutId(item_id);
+ entry.PutCtime(now);
+ entry.PutMtime(now);
+ entry.PutUniqueClientTag(syncable::GenerateSyncableHash(model_type, name));
entry.PutBaseVersion(version);
entry.PutIsUnsynced(false);
entry.PutNonUniqueName(name);
@@ -161,14 +185,37 @@ int64_t TestEntryFactory::CreateSyncedItem(const std::string& name,
entry.PutIsDel(false);
entry.PutParentId(parent_id);
- entry.PutServerVersion(GetNextRevision());
+ entry.PutServerCtime(now);
+ entry.PutServerMtime(now);
+ entry.PutServerVersion(version);
entry.PutIsUnappliedUpdate(false);
entry.PutServerNonUniqueName(name);
entry.PutServerParentId(parent_id);
entry.PutServerIsDir(is_folder);
entry.PutServerIsDel(false);
- entry.PutServerSpecifics(entry.GetSpecifics());
+ // Only rewrite the default specifics (which have the model type marker
+ // already) if the new ones have data in them.
+ 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.
+ entry.PutSpecifics(specifics);
+ entry.PutServerSpecifics(specifics);
+ } else {
+ entry.PutServerSpecifics(entry.GetSpecifics());
+ }
+
+ return entry.GetMetahandle();
+}
+
+int64_t TestEntryFactory::CreateTypeRootNode(ModelType model_type) {
+ syncable::ModelNeutralWriteTransaction trans(FROM_HERE, syncable::UNITTEST,
+ directory_);
+ sync_pb::EntitySpecifics specifics;
+ AddDefaultFieldValue(model_type, &specifics);
+ syncable::ModelNeutralMutableEntry entry(
+ &trans, syncable::CREATE_NEW_TYPE_ROOT, model_type);
+ DCHECK(entry.good());
+ entry.PutServerIsDir(true);
+ entry.PutUniqueServerTag(ModelTypeToRootTag(model_type));
return entry.GetMetahandle();
}

Powered by Google App Engine
This is Rietveld 408576698