Index: sync/internal_api/test/test_entry_factory.cc |
diff --git a/sync/internal_api/test/test_entry_factory.cc b/sync/internal_api/test/test_entry_factory.cc |
index f57841253c9ef086a86e2ec2c42cd4ae5a868877..297d0c6115fc7e2b8b248fe7442fde04783ddc3a 100644 |
--- a/sync/internal_api/test/test_entry_factory.cc |
+++ b/sync/internal_api/test/test_entry_factory.cc |
@@ -9,6 +9,7 @@ |
#include "sync/syncable/mutable_entry.h" |
#include "sync/syncable/read_transaction.h" |
#include "sync/syncable/syncable_id.h" |
+#include "sync/syncable/syncable_util.h" |
#include "sync/syncable/write_transaction.h" |
#include "sync/test/engine/test_id_factory.h" |
@@ -45,6 +46,32 @@ int64 TestEntryFactory::CreateUnappliedNewItemWithParent( |
return entry.Get(syncable::META_HANDLE); |
} |
+int64 TestEntryFactory::CreateUnappliedNewBookmarkItemWithParent( |
+ const string& item_id, |
+ const sync_pb::EntitySpecifics& specifics, |
+ const string& parent_id) { |
+ WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
+ MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
+ Id::CreateFromServerId(item_id)); |
+ DCHECK(entry.good()); |
+ entry.Put(syncable::SERVER_VERSION, GetNextRevision()); |
+ entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); |
+ |
+ entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id); |
+ entry.Put(syncable::SERVER_PARENT_ID, Id::CreateFromServerId(parent_id)); |
+ entry.Put(syncable::SERVER_IS_DIR, true); |
+ entry.Put(syncable::SERVER_SPECIFICS, specifics); |
+ |
+ // Not entirely accurate, but at least it's valid and unique. |
+ // (Normally the ID should be a client local ID because this is calculated at |
+ // creation time.) |
+ UniquePosition pos = UniquePosition::InitialPosition( |
+ syncable::GenerateSyncableBookmarkHash( |
+ directory_->cache_guid(), entry.Get(syncable::ID).value())); |
+ entry.Put(syncable::SERVER_UNIQUE_POSITION, pos); |
+ return entry.Get(syncable::META_HANDLE); |
+} |
+ |
int64 TestEntryFactory::CreateUnappliedNewItem( |
const string& item_id, |
const sync_pb::EntitySpecifics& specifics, |
@@ -70,29 +97,25 @@ void TestEntryFactory::CreateUnsyncedItem( |
const Id& item_id, |
const Id& parent_id, |
const string& name, |
- bool is_folder, |
ModelType model_type, |
int64* metahandle_out) { |
WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
- Id predecessor_id; |
- DCHECK( |
- directory_->GetLastChildIdForTest(&trans, parent_id, &predecessor_id)); |
- MutableEntry entry(&trans, syncable::CREATE, parent_id, name); |
+ MutableEntry entry(&trans, syncable::CREATE_UNIQUE, |
+ model_type, parent_id, name); |
DCHECK(entry.good()); |
entry.Put(syncable::ID, item_id); |
entry.Put(syncable::BASE_VERSION, |
item_id.ServerKnows() ? GetNextRevision() : 0); |
entry.Put(syncable::IS_UNSYNCED, true); |
- entry.Put(syncable::IS_DIR, is_folder); |
+ entry.Put(syncable::IS_DIR, false); |
entry.Put(syncable::IS_DEL, false); |
entry.Put(syncable::PARENT_ID, parent_id); |
- CHECK(entry.PutPredecessor(predecessor_id)); |
sync_pb::EntitySpecifics default_specifics; |
AddDefaultFieldValue(model_type, &default_specifics); |
entry.Put(syncable::SPECIFICS, default_specifics); |
if (item_id.ServerKnows()) { |
entry.Put(syncable::SERVER_SPECIFICS, default_specifics); |
- entry.Put(syncable::SERVER_IS_DIR, is_folder); |
+ entry.Put(syncable::SERVER_IS_DIR, false); |
entry.Put(syncable::SERVER_PARENT_ID, parent_id); |
entry.Put(syncable::SERVER_IS_DEL, false); |
} |
@@ -100,13 +123,41 @@ void TestEntryFactory::CreateUnsyncedItem( |
*metahandle_out = entry.Get(syncable::META_HANDLE); |
} |
-int64 TestEntryFactory::CreateUnappliedAndUnsyncedItem( |
+void TestEntryFactory::CreateUnsyncedBookmarkItem( |
+ const Id& item_id, |
+ const Id& parent_id, |
const string& name, |
- ModelType model_type) { |
+ bool is_folder, |
+ int64* metahandle_out) { |
+ WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
+ MutableEntry entry(&trans, syncable::CREATE_BOOKMARK, parent_id, name); |
+ DCHECK(entry.good()); |
+ entry.Put(syncable::ID, item_id); |
+ entry.Put(syncable::BASE_VERSION, |
+ item_id.ServerKnows() ? GetNextRevision() : 0); |
+ entry.Put(syncable::IS_UNSYNCED, true); |
+ entry.Put(syncable::IS_DIR, is_folder); |
+ entry.Put(syncable::IS_DEL, false); |
+ entry.Put(syncable::PARENT_ID, parent_id); |
+ sync_pb::EntitySpecifics default_specifics; |
+ AddDefaultFieldValue(BOOKMARKS, &default_specifics); |
+ entry.Put(syncable::SPECIFICS, default_specifics); |
+ if (item_id.ServerKnows()) { |
+ entry.Put(syncable::SERVER_SPECIFICS, default_specifics); |
+ entry.Put(syncable::SERVER_IS_DIR, is_folder); |
+ entry.Put(syncable::SERVER_PARENT_ID, parent_id); |
+ entry.Put(syncable::SERVER_IS_DEL, false); |
+ } |
+ if (metahandle_out) |
+ *metahandle_out = entry.Get(syncable::META_HANDLE); |
+} |
+ |
+int64 TestEntryFactory::CreateUnappliedAndUnsyncedBookmarkItem( |
+ const string& name) { |
int64 metahandle = 0; |
- CreateUnsyncedItem( |
+ CreateUnsyncedBookmarkItem( |
TestIdFactory::MakeServer(name), TestIdFactory::root(), |
- name, false, model_type, &metahandle); |
+ name, false, &metahandle); |
WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
MutableEntry entry(&trans, syncable::GET_BY_HANDLE, metahandle); |
@@ -123,16 +174,15 @@ int64 TestEntryFactory::CreateUnappliedAndUnsyncedItem( |
int64 TestEntryFactory::CreateSyncedItem( |
const std::string& name, ModelType model_type, bool is_folder) { |
+ DCHECK_NE(BOOKMARKS, model_type); |
WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
syncable::Id parent_id(TestIdFactory::root()); |
syncable::Id item_id(TestIdFactory::MakeServer(name)); |
int64 version = GetNextRevision(); |
- sync_pb::EntitySpecifics default_specifics; |
- AddDefaultFieldValue(model_type, &default_specifics); |
- |
- MutableEntry entry(&trans, syncable::CREATE, parent_id, name); |
+ MutableEntry entry( |
+ &trans, syncable::CREATE_UNIQUE, model_type, parent_id, name); |
if (!entry.good()) { |
NOTREACHED(); |
return syncable::kInvalidMetaHandle; |
@@ -150,16 +200,52 @@ int64 TestEntryFactory::CreateSyncedItem( |
NOTREACHED(); |
return syncable::kInvalidMetaHandle; |
} |
- entry.Put(syncable::SPECIFICS, default_specifics); |
entry.Put(syncable::SERVER_VERSION, GetNextRevision()); |
- entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); |
- entry.Put(syncable::SERVER_NON_UNIQUE_NAME, "X"); |
- entry.Put(syncable::SERVER_PARENT_ID, TestIdFactory::MakeServer("Y")); |
+ entry.Put(syncable::IS_UNAPPLIED_UPDATE, false); |
+ entry.Put(syncable::SERVER_NON_UNIQUE_NAME, name); |
+ entry.Put(syncable::SERVER_PARENT_ID, parent_id); |
entry.Put(syncable::SERVER_IS_DIR, is_folder); |
entry.Put(syncable::SERVER_IS_DEL, false); |
- entry.Put(syncable::SERVER_SPECIFICS, default_specifics); |
+ entry.Put(syncable::SERVER_SPECIFICS, entry.Get(syncable::SPECIFICS)); |
+ |
+ return entry.Get(syncable::META_HANDLE); |
+} |
+ |
+int64 TestEntryFactory::CreateSyncedBookmarkItem( |
+ const std::string& name, bool is_folder) { |
+ WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
+ |
+ syncable::Id parent_id(TestIdFactory::root()); |
+ syncable::Id item_id(TestIdFactory::MakeServer(name)); |
+ int64 version = GetNextRevision(); |
+ |
+ MutableEntry entry(&trans, syncable::CREATE_BOOKMARK, parent_id, name); |
+ if (!entry.good()) { |
+ NOTREACHED(); |
+ return syncable::kInvalidMetaHandle; |
+ } |
+ |
+ entry.Put(syncable::ID, item_id); |
+ entry.Put(syncable::BASE_VERSION, version); |
+ entry.Put(syncable::IS_UNSYNCED, false); |
+ entry.Put(syncable::NON_UNIQUE_NAME, name); |
+ entry.Put(syncable::IS_DIR, is_folder); |
+ entry.Put(syncable::IS_DEL, false); |
+ entry.Put(syncable::PARENT_ID, parent_id); |
+ |
+ if (!entry.PutPredecessor(TestIdFactory::root())) { |
+ NOTREACHED(); |
+ return syncable::kInvalidMetaHandle; |
+ } |
+ |
+ entry.Put(syncable::SERVER_VERSION, GetNextRevision()); |
+ entry.Put(syncable::IS_UNAPPLIED_UPDATE, false); |
+ entry.Put(syncable::SERVER_NON_UNIQUE_NAME, name); |
entry.Put(syncable::SERVER_PARENT_ID, parent_id); |
+ entry.Put(syncable::SERVER_IS_DIR, is_folder); |
+ entry.Put(syncable::SERVER_IS_DEL, false); |
+ entry.Put(syncable::SERVER_SPECIFICS, entry.Get(syncable::SPECIFICS)); |
return entry.Get(syncable::META_HANDLE); |
} |