summaryrefslogtreecommitdiffstats
path: root/sync/internal_api/test
diff options
context:
space:
mode:
authorjoaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-11 15:51:40 +0000
committerjoaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-11 15:51:40 +0000
commit88f6351cd9da0846003bd1d79840bf9436d6b886 (patch)
tree497bec530ea31d19b05488a3bf119f1cc533cb59 /sync/internal_api/test
parenta6ee41bcba06dba2212bba3fe1df6fc71a4e8f5f (diff)
downloadchromium_src-88f6351cd9da0846003bd1d79840bf9436d6b886.zip
chromium_src-88f6351cd9da0846003bd1d79840bf9436d6b886.tar.gz
chromium_src-88f6351cd9da0846003bd1d79840bf9436d6b886.tar.bz2
Revert 176340
> sync: Initialize entries with a valid model type > > This change modifies two important sync functions. > > The first is MutableEntry's CREATE constructor. It now requires that > the ModelType of the entry to be specified when the entry is create. > This doesn't quite eliminate the existence of nodes without a valid > model type (the CREATE_NEW_UPDATE_ITEM can still make them), but it > helps. > > This paves the way for the upcoming UniquePosition change. Part of that > change is that bookmarks must be granted a unique tag on creation. To > support this, we must know at creation time the type of a new entry, so > we can take the appropriate bookmark-specific steps if necessary. > > The second function to get a new signature is WriteNode's > InitByCreation(), which has been renamed to > WriteNode::InitBookmarkByCreation(). The function can only be used to > create bookmarks, so the new name describes its function more precisely. > > Updates to the call-sites of MutableEntry's constructor make up the > majority of this change. This change also includes some minor updates > to test functions that create entries to make them compatible with the > stricter assertions or to make them more closely reflect real world > behaviour. > > BUG=145412,126505 > > > Review URL: https://chromiumcodereview.appspot.com/11817010 TBR=rlarocque@chromium.org Review URL: https://codereview.chromium.org/11863011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176352 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/internal_api/test')
-rw-r--r--sync/internal_api/test/test_entry_factory.cc66
1 files changed, 19 insertions, 47 deletions
diff --git a/sync/internal_api/test/test_entry_factory.cc b/sync/internal_api/test/test_entry_factory.cc
index 3753b99..8e6b2b3 100644
--- a/sync/internal_api/test/test_entry_factory.cc
+++ b/sync/internal_api/test/test_entry_factory.cc
@@ -9,7 +9,6 @@
#include "sync/syncable/mutable_entry.h"
#include "sync/syncable/syncable_id.h"
#include "sync/syncable/syncable_read_transaction.h"
-#include "sync/syncable/syncable_util.h"
#include "sync/syncable/syncable_write_transaction.h"
#include "sync/test/engine/test_id_factory.h"
@@ -46,25 +45,6 @@ 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);
-
- return entry.Get(syncable::META_HANDLE);
-}
-
int64 TestEntryFactory::CreateUnappliedNewItem(
const string& item_id,
const sync_pb::EntitySpecifics& specifics,
@@ -93,19 +73,11 @@ void TestEntryFactory::CreateUnsyncedItem(
bool is_folder,
ModelType model_type,
int64* metahandle_out) {
- if (is_folder) {
- DCHECK_EQ(model_type, BOOKMARKS);
- }
-
WriteTransaction trans(FROM_HERE, UNITTEST, directory_);
-
Id predecessor_id;
- if (model_type == BOOKMARKS) {
- DCHECK(directory_->GetLastChildIdForTest(
- &trans, parent_id, &predecessor_id));
- }
-
- MutableEntry entry(&trans, syncable::CREATE, model_type, parent_id, name);
+ DCHECK(
+ directory_->GetLastChildIdForTest(&trans, parent_id, &predecessor_id));
+ MutableEntry entry(&trans, syncable::CREATE, parent_id, name);
DCHECK(entry.good());
entry.Put(syncable::ID, item_id);
entry.Put(syncable::BASE_VERSION,
@@ -114,18 +86,13 @@ void TestEntryFactory::CreateUnsyncedItem(
entry.Put(syncable::IS_DIR, is_folder);
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);
-
- // Bookmarks get inserted at the end of the list.
- if (model_type == BOOKMARKS) {
- DCHECK(entry.PutPredecessor(predecessor_id));
- }
-
if (item_id.ServerKnows()) {
entry.Put(syncable::SERVER_SPECIFICS, default_specifics);
- entry.Put(syncable::SERVER_IS_DIR, false);
+ entry.Put(syncable::SERVER_IS_DIR, is_folder);
entry.Put(syncable::SERVER_PARENT_ID, parent_id);
entry.Put(syncable::SERVER_IS_DEL, false);
}
@@ -133,12 +100,13 @@ void TestEntryFactory::CreateUnsyncedItem(
*metahandle_out = entry.Get(syncable::META_HANDLE);
}
-int64 TestEntryFactory::CreateUnappliedAndUnsyncedBookmarkItem(
- const string& name) {
+int64 TestEntryFactory::CreateUnappliedAndUnsyncedItem(
+ const string& name,
+ ModelType model_type) {
int64 metahandle = 0;
CreateUnsyncedItem(
TestIdFactory::MakeServer(name), TestIdFactory::root(),
- name, false, BOOKMARKS, &metahandle);
+ name, false, model_type, &metahandle);
WriteTransaction trans(FROM_HERE, UNITTEST, directory_);
MutableEntry entry(&trans, syncable::GET_BY_HANDLE, metahandle);
@@ -161,7 +129,10 @@ int64 TestEntryFactory::CreateSyncedItem(
syncable::Id item_id(TestIdFactory::MakeServer(name));
int64 version = GetNextRevision();
- MutableEntry entry(&trans, syncable::CREATE, model_type, parent_id, name);
+ sync_pb::EntitySpecifics default_specifics;
+ AddDefaultFieldValue(model_type, &default_specifics);
+
+ MutableEntry entry(&trans, syncable::CREATE, parent_id, name);
if (!entry.good()) {
NOTREACHED();
return syncable::kInvalidMetaHandle;
@@ -175,19 +146,20 @@ int64 TestEntryFactory::CreateSyncedItem(
entry.Put(syncable::IS_DEL, false);
entry.Put(syncable::PARENT_ID, parent_id);
- // TODO(sync): Place bookmarks at the end of the list?
if (!entry.PutPredecessor(TestIdFactory::root())) {
NOTREACHED();
return syncable::kInvalidMetaHandle;
}
+ entry.Put(syncable::SPECIFICS, default_specifics);
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::IS_UNAPPLIED_UPDATE, true);
+ entry.Put(syncable::SERVER_NON_UNIQUE_NAME, "X");
+ entry.Put(syncable::SERVER_PARENT_ID, TestIdFactory::MakeServer("Y"));
entry.Put(syncable::SERVER_IS_DIR, is_folder);
entry.Put(syncable::SERVER_IS_DEL, false);
- entry.Put(syncable::SERVER_SPECIFICS, entry.Get(syncable::SPECIFICS));
+ entry.Put(syncable::SERVER_SPECIFICS, default_specifics);
+ entry.Put(syncable::SERVER_PARENT_ID, parent_id);
return entry.Get(syncable::META_HANDLE);
}