diff options
-rw-r--r-- | chrome/browser/sync/glue/bookmark_change_processor.cc | 4 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service_autofill_unittest.cc | 3 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service_bookmark_unittest.cc | 7 | ||||
-rw-r--r-- | sync/engine/apply_updates_and_resolve_conflicts_command_unittest.cc | 29 | ||||
-rw-r--r-- | sync/engine/process_commit_response_command_unittest.cc | 183 | ||||
-rw-r--r-- | sync/engine/syncer_unittest.cc | 173 | ||||
-rw-r--r-- | sync/internal_api/public/test/test_entry_factory.h | 27 | ||||
-rw-r--r-- | sync/internal_api/public/write_node.h | 14 | ||||
-rw-r--r-- | sync/internal_api/sync_encryption_handler_impl_unittest.cc | 1 | ||||
-rw-r--r-- | sync/internal_api/sync_manager_impl_unittest.cc | 93 | ||||
-rw-r--r-- | sync/internal_api/test/test_entry_factory.cc | 66 | ||||
-rw-r--r-- | sync/internal_api/write_node.cc | 34 | ||||
-rw-r--r-- | sync/syncable/mutable_entry.cc | 35 | ||||
-rw-r--r-- | sync/syncable/mutable_entry.h | 9 | ||||
-rw-r--r-- | sync/syncable/syncable_unittest.cc | 129 | ||||
-rw-r--r-- | sync/test/engine/test_syncable_utils.cc | 1 |
16 files changed, 408 insertions, 400 deletions
diff --git a/chrome/browser/sync/glue/bookmark_change_processor.cc b/chrome/browser/sync/glue/bookmark_change_processor.cc index 344f5a9..b55d279 100644 --- a/chrome/browser/sync/glue/bookmark_change_processor.cc +++ b/chrome/browser/sync/glue/bookmark_change_processor.cc @@ -404,7 +404,7 @@ bool BookmarkChangeProcessor::PlaceSyncNode(MoveOrCreate operation, if (index == 0) { // Insert into first position. success = (operation == CREATE) ? - dst->InitBookmarkByCreation(sync_parent, NULL) : + dst->InitByCreation(syncer::BOOKMARKS, sync_parent, NULL) : dst->SetPosition(sync_parent, NULL); if (success) { DCHECK_EQ(dst->GetParentId(), sync_parent.GetId()); @@ -420,7 +420,7 @@ bool BookmarkChangeProcessor::PlaceSyncNode(MoveOrCreate operation, return false; } success = (operation == CREATE) ? - dst->InitBookmarkByCreation(sync_parent, &sync_prev) : + dst->InitByCreation(syncer::BOOKMARKS, sync_parent, &sync_prev) : dst->SetPosition(sync_parent, &sync_prev); if (success) { DCHECK_EQ(dst->GetParentId(), sync_parent.GetId()); diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc index 2e8ac94..c952eab 100644 --- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc @@ -741,8 +741,7 @@ class FakeServerUpdater : public base::RefCountedThreadSafe<FakeServerUpdater> { // Simulates effects of UpdateLocalDataFromServerData MutableEntry parent(&trans, GET_BY_SERVER_TAG, syncer::ModelTypeToRootTag(syncer::AUTOFILL)); - MutableEntry item(&trans, CREATE, syncer::AUTOFILL, - parent.Get(syncer::syncable::ID), tag); + MutableEntry item(&trans, CREATE, parent.Get(syncer::syncable::ID), tag); ASSERT_TRUE(item.good()); item.Put(SPECIFICS, entity_specifics); item.Put(SERVER_SPECIFICS, entity_specifics); diff --git a/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc b/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc index 2b72b22..618b4ee 100644 --- a/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_bookmark_unittest.cc @@ -81,12 +81,13 @@ class FakeServerChange { EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); syncer::WriteNode node(trans_); if (predecessor_id == 0) { - EXPECT_TRUE(node.InitBookmarkByCreation(parent, NULL)); + EXPECT_TRUE(node.InitByCreation(syncer::BOOKMARKS, parent, NULL)); } else { syncer::ReadNode predecessor(trans_); EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id)); EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); - EXPECT_TRUE(node.InitBookmarkByCreation(parent, &predecessor)); + EXPECT_TRUE(node.InitByCreation(syncer::BOOKMARKS, parent, + &predecessor)); } EXPECT_EQ(node.GetPredecessorId(), predecessor_id); EXPECT_EQ(node.GetParentId(), parent_id); @@ -360,7 +361,7 @@ class ProfileSyncServiceBookmarkTest : public testing::Test { predecessor = &predecessor_node; } syncer::WriteNode node(&trans); - if (!node.InitBookmarkByCreation(root, predecessor)) + if (!node.InitByCreation(type, root, predecessor)) return false; node.SetIsFolder(true); node.GetMutableEntryForTest()->Put( diff --git a/sync/engine/apply_updates_and_resolve_conflicts_command_unittest.cc b/sync/engine/apply_updates_and_resolve_conflicts_command_unittest.cc index c341e8f..97d4c33 100644 --- a/sync/engine/apply_updates_and_resolve_conflicts_command_unittest.cc +++ b/sync/engine/apply_updates_and_resolve_conflicts_command_unittest.cc @@ -71,10 +71,12 @@ class ApplyUpdatesAndResolveConflictsCommandTest : public SyncerCommandTest { TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, Simple) { string root_server_id = syncable::GetNullId().GetServerId(); - entry_factory_->CreateUnappliedNewBookmarkItemWithParent( - "parent", DefaultBookmarkSpecifics(), root_server_id); - entry_factory_->CreateUnappliedNewBookmarkItemWithParent( - "child", DefaultBookmarkSpecifics(), "parent"); + entry_factory_->CreateUnappliedNewItemWithParent("parent", + DefaultBookmarkSpecifics(), + root_server_id); + entry_factory_->CreateUnappliedNewItemWithParent("child", + DefaultBookmarkSpecifics(), + "parent"); ExpectGroupToChange(apply_updates_command_, GROUP_UI); apply_updates_command_.ExecuteImpl(session()); @@ -93,15 +95,15 @@ TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, // Set a bunch of updates which are difficult to apply in the order // they're received due to dependencies on other unseen items. string root_server_id = syncable::GetNullId().GetServerId(); - entry_factory_->CreateUnappliedNewBookmarkItemWithParent( + entry_factory_->CreateUnappliedNewItemWithParent( "a_child_created_first", DefaultBookmarkSpecifics(), "parent"); - entry_factory_->CreateUnappliedNewBookmarkItemWithParent( + entry_factory_->CreateUnappliedNewItemWithParent( "x_child_created_first", DefaultBookmarkSpecifics(), "parent"); - entry_factory_->CreateUnappliedNewBookmarkItemWithParent( + entry_factory_->CreateUnappliedNewItemWithParent( "parent", DefaultBookmarkSpecifics(), root_server_id); - entry_factory_->CreateUnappliedNewBookmarkItemWithParent( + entry_factory_->CreateUnappliedNewItemWithParent( "a_child_created_second", DefaultBookmarkSpecifics(), "parent"); - entry_factory_->CreateUnappliedNewBookmarkItemWithParent( + entry_factory_->CreateUnappliedNewItemWithParent( "x_child_created_second", DefaultBookmarkSpecifics(), "parent"); ExpectGroupToChange(apply_updates_command_, GROUP_UI); @@ -117,7 +119,7 @@ TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, // expect the command to detect that this update can't be applied because it is // in a CONFLICT state. TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, SimpleConflict) { - entry_factory_->CreateUnappliedAndUnsyncedBookmarkItem("item"); + entry_factory_->CreateUnappliedAndUnsyncedItem("item", BOOKMARKS); ExpectGroupToChange(apply_updates_command_, GROUP_UI); apply_updates_command_.ExecuteImpl(session()); @@ -137,8 +139,8 @@ TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, SimpleConflict) { // CONFLICT_HIERARCHY state. TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, HierarchyAndSimpleConflict) { // Create a simply-conflicting item. It will start with valid parent ids. - int64 handle = entry_factory_->CreateUnappliedAndUnsyncedBookmarkItem( - "orphaned_by_server"); + int64 handle = entry_factory_->CreateUnappliedAndUnsyncedItem( + "orphaned_by_server", BOOKMARKS); { // Manually set the SERVER_PARENT_ID to bad value. // A bad parent indicates a hierarchy conflict. @@ -240,7 +242,8 @@ TEST_F(ApplyUpdatesAndResolveConflictsCommandTest, // Create a server-deleted directory. { // Create it as a child of root node. - int64 handle = entry_factory_->CreateSyncedItem("parent", BOOKMARKS, true); + int64 handle = + entry_factory_->CreateSyncedItem("parent", BOOKMARKS, true); WriteTransaction trans(FROM_HERE, UNITTEST, directory()); MutableEntry entry(&trans, syncable::GET_BY_HANDLE, handle); diff --git a/sync/engine/process_commit_response_command_unittest.cc b/sync/engine/process_commit_response_command_unittest.cc index 40bd61b..f96ea5e 100644 --- a/sync/engine/process_commit_response_command_unittest.cc +++ b/sync/engine/process_commit_response_command_unittest.cc @@ -8,7 +8,6 @@ #include "base/location.h" #include "base/stringprintf.h" -#include "sync/internal_api/public/test/test_entry_factory.h" #include "sync/protocol/bookmark_specifics.pb.h" #include "sync/protocol/sync.pb.h" #include "sync/sessions/sync_session.h" @@ -56,14 +55,13 @@ class ProcessCommitResponseCommandTest : public SyncerCommandTest { (*mutable_routing_info())[AUTOFILL] = GROUP_DB; SyncerCommandTest::SetUp(); - - test_entry_factory_.reset(new TestEntryFactory(directory())); } protected: ProcessCommitResponseCommandTest() - : next_new_revision_(4000), + : next_old_revision_(1), + next_new_revision_(4000), next_server_position_(10000) { } @@ -77,22 +75,59 @@ class ProcessCommitResponseCommandTest : public SyncerCommandTest { << "Item should have a valid (positive) server base revision"; } - // Create a new unsynced item in the database, and synthesize a commit record - // and a commit response for it in the syncer session. If item_id is a local - // ID, the item will be a create operation. Otherwise, it will be an edit. - // Returns the metahandle of the newly created item. - int CreateUnprocessedCommitResult( + // Create an unsynced item in the database. If item_id is a local ID, it + // will be treated as a create-new. Otherwise, if it's a server ID, we'll + // fake the server data so that it looks like it exists on the server. + // Returns the methandle of the created item in |metahandle_out| if not NULL. + void 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; + ASSERT_TRUE( + directory()->GetLastChildIdForTest(&trans, parent_id, &predecessor_id)); + MutableEntry entry(&trans, syncable::CREATE, parent_id, name); + ASSERT_TRUE(entry.good()); + entry.Put(syncable::ID, item_id); + entry.Put(syncable::BASE_VERSION, + item_id.ServerKnows() ? next_old_revision_++ : 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); + 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_PARENT_ID, parent_id); + entry.Put(syncable::SERVER_IS_DEL, false); + } + if (metahandle_out) + *metahandle_out = entry.Get(syncable::META_HANDLE); + } + + // Create a new unsynced item in the database, and synthesize a commit + // record and a commit response for it in the syncer session. If item_id + // is a local ID, the item will be a create operation. Otherwise, it + // will be an edit. + void CreateUnprocessedCommitResult( const Id& item_id, const Id& parent_id, const string& name, - bool is_folder, ModelType model_type, sessions::OrderedCommitSet *commit_set, sync_pb::ClientToServerMessage *commit, sync_pb::ClientToServerResponse *response) { + bool is_folder = true; int64 metahandle = 0; - test_entry_factory_->CreateUnsyncedItem(item_id, parent_id, name, - is_folder, model_type, &metahandle); + CreateUnsyncedItem(item_id, parent_id, name, is_folder, model_type, + &metahandle); // ProcessCommitResponseCommand consumes commit_ids from the session // state, so we need to update that. O(n^2) because it's a test. @@ -100,26 +135,19 @@ class ProcessCommitResponseCommandTest : public SyncerCommandTest { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); MutableEntry entry(&trans, syncable::GET_BY_ID, item_id); - EXPECT_TRUE(entry.good()); + ASSERT_TRUE(entry.good()); entry.Put(syncable::SYNCING, true); // Add to the commit message. - // TODO(sync): Use the real commit-building code to construct this. commit->set_message_contents(ClientToServerMessage::COMMIT); sync_pb::SyncEntity* entity = commit->mutable_commit()->add_entries(); - entity->set_non_unique_name(entry.Get(syncable::NON_UNIQUE_NAME)); - entity->set_folder(entry.Get(syncable::IS_DIR)); - entity->set_parent_id_string( - SyncableIdToProto(entry.Get(syncable::PARENT_ID))); + entity->set_non_unique_name(name); + entity->set_folder(is_folder); + entity->set_parent_id_string(SyncableIdToProto(parent_id)); entity->set_version(entry.Get(syncable::BASE_VERSION)); entity->mutable_specifics()->CopyFrom(entry.Get(syncable::SPECIFICS)); entity->set_id_string(SyncableIdToProto(item_id)); - if (!entry.Get(syncable::UNIQUE_CLIENT_TAG).empty()) { - entity->set_client_defined_unique_tag( - entry.Get(syncable::UNIQUE_CLIENT_TAG)); - } - // Add to the response message. response->set_error_code(sync_pb::SyncEnums::SUCCESS); sync_pb::CommitResponse_EntryResponse* entry_response = @@ -145,8 +173,6 @@ class ProcessCommitResponseCommandTest : public SyncerCommandTest { response->commit().entryresponse(i).id_string()); } } - - return metahandle; } void SetLastErrorCode(sync_pb::CommitResponse::ResponseType error_code, @@ -158,8 +184,8 @@ class ProcessCommitResponseCommandTest : public SyncerCommandTest { } TestIdFactory id_factory_; - scoped_ptr<TestEntryFactory> test_entry_factory_; private: + int64 next_old_revision_; int64 next_new_revision_; int64 next_server_position_; DISALLOW_COPY_AND_ASSIGN(ProcessCommitResponseCommandTest); @@ -171,63 +197,69 @@ TEST_F(ProcessCommitResponseCommandTest, MultipleCommitIdProjections) { sync_pb::ClientToServerResponse response; Id bookmark_folder_id = id_factory_.NewLocalId(); - int bookmark_folder_handle = CreateUnprocessedCommitResult( - bookmark_folder_id, id_factory_.root(), "A bookmark folder", true, - BOOKMARKS, &commit_set, &request, &response); - int bookmark1_handle = CreateUnprocessedCommitResult( - id_factory_.NewLocalId(), bookmark_folder_id, "bookmark 1", false, - BOOKMARKS, &commit_set, &request, &response); - int bookmark2_handle = CreateUnprocessedCommitResult( - id_factory_.NewLocalId(), bookmark_folder_id, "bookmark 2", false, - BOOKMARKS, &commit_set, &request, &response); - int pref1_handle = CreateUnprocessedCommitResult( - id_factory_.NewLocalId(), id_factory_.root(), "Pref 1", false, - PREFERENCES, &commit_set, &request, &response); - int pref2_handle = CreateUnprocessedCommitResult( - id_factory_.NewLocalId(), id_factory_.root(), "Pref 2", false, - PREFERENCES, &commit_set, &request, &response); - int autofill1_handle = CreateUnprocessedCommitResult( - id_factory_.NewLocalId(), id_factory_.root(), "Autofill 1", false, - AUTOFILL, &commit_set, &request, &response); - int autofill2_handle = CreateUnprocessedCommitResult( - id_factory_.NewLocalId(), id_factory_.root(), "Autofill 2", false, - AUTOFILL, &commit_set, &request, &response); + Id bookmark_id1 = id_factory_.NewLocalId(); + Id bookmark_id2 = id_factory_.NewLocalId(); + Id pref_id1 = id_factory_.NewLocalId(), pref_id2 = id_factory_.NewLocalId(); + Id autofill_id1 = id_factory_.NewLocalId(); + Id autofill_id2 = id_factory_.NewLocalId(); + CreateUnprocessedCommitResult(bookmark_folder_id, id_factory_.root(), + "A bookmark folder", BOOKMARKS, + &commit_set, &request, &response); + CreateUnprocessedCommitResult(bookmark_id1, bookmark_folder_id, + "bookmark 1", BOOKMARKS, + &commit_set, &request, &response); + CreateUnprocessedCommitResult(bookmark_id2, bookmark_folder_id, + "bookmark 2", BOOKMARKS, + &commit_set, &request, &response); + CreateUnprocessedCommitResult(pref_id1, id_factory_.root(), + "Pref 1", PREFERENCES, + &commit_set, &request, &response); + CreateUnprocessedCommitResult(pref_id2, id_factory_.root(), + "Pref 2", PREFERENCES, + &commit_set, &request, &response); + CreateUnprocessedCommitResult(autofill_id1, id_factory_.root(), + "Autofill 1", AUTOFILL, + &commit_set, &request, &response); + CreateUnprocessedCommitResult(autofill_id2, id_factory_.root(), + "Autofill 2", AUTOFILL, + &commit_set, &request, &response); ProcessCommitResponseCommand command(commit_set, request, response); ExpectGroupsToChange(command, GROUP_UI, GROUP_DB); command.ExecuteImpl(session()); syncable::ReadTransaction trans(FROM_HERE, directory()); - - Entry b_folder(&trans, syncable::GET_BY_HANDLE, bookmark_folder_handle); - ASSERT_TRUE(b_folder.good()); - - Id new_fid = b_folder.Get(syncable::ID); + Id new_fid; + ASSERT_TRUE(directory()->GetFirstChildId( + &trans, id_factory_.root(), &new_fid)); ASSERT_FALSE(new_fid.IsRoot()); EXPECT_TRUE(new_fid.ServerKnows()); EXPECT_FALSE(bookmark_folder_id.ServerKnows()); EXPECT_FALSE(new_fid == bookmark_folder_id); - + Entry b_folder(&trans, syncable::GET_BY_ID, new_fid); + ASSERT_TRUE(b_folder.good()); ASSERT_EQ("A bookmark folder", b_folder.Get(NON_UNIQUE_NAME)) << "Name of bookmark folder should not change."; ASSERT_LT(0, b_folder.Get(BASE_VERSION)) << "Bookmark folder should have a valid (positive) server base revision"; // Look at the two bookmarks in bookmark_folder. - Entry b1(&trans, syncable::GET_BY_HANDLE, bookmark1_handle); - Entry b2(&trans, syncable::GET_BY_HANDLE, bookmark2_handle); + Id cid; + ASSERT_TRUE(directory()->GetFirstChildId(&trans, new_fid, &cid)); + Entry b1(&trans, syncable::GET_BY_ID, cid); + Entry b2(&trans, syncable::GET_BY_ID, b1.GetSuccessorId()); CheckEntry(&b1, "bookmark 1", BOOKMARKS, new_fid); CheckEntry(&b2, "bookmark 2", BOOKMARKS, new_fid); ASSERT_TRUE(b2.GetSuccessorId().IsRoot()); // Look at the prefs and autofill items. - Entry p1(&trans, syncable::GET_BY_HANDLE, pref1_handle); - Entry p2(&trans, syncable::GET_BY_HANDLE, pref2_handle); + Entry p1(&trans, syncable::GET_BY_ID, b_folder.GetSuccessorId()); + Entry p2(&trans, syncable::GET_BY_ID, p1.GetSuccessorId()); CheckEntry(&p1, "Pref 1", PREFERENCES, id_factory_.root()); CheckEntry(&p2, "Pref 2", PREFERENCES, id_factory_.root()); - Entry a1(&trans, syncable::GET_BY_HANDLE, autofill1_handle); - Entry a2(&trans, syncable::GET_BY_HANDLE, autofill2_handle); + Entry a1(&trans, syncable::GET_BY_ID, p2.GetSuccessorId()); + Entry a2(&trans, syncable::GET_BY_ID, a1.GetSuccessorId()); CheckEntry(&a1, "Autofill 1", AUTOFILL, id_factory_.root()); CheckEntry(&a2, "Autofill 2", AUTOFILL, id_factory_.root()); ASSERT_TRUE(a2.GetSuccessorId().IsRoot()); @@ -250,18 +282,16 @@ TEST_F(ProcessCommitResponseCommandTest, NewFolderCommitKeepsChildOrder) { // Create the parent folder, a new item whose ID will change on commit. Id folder_id = id_factory_.NewLocalId(); - CreateUnprocessedCommitResult(folder_id, id_factory_.root(), - "A", true, BOOKMARKS, + CreateUnprocessedCommitResult(folder_id, id_factory_.root(), "A", + BOOKMARKS, &commit_set, &request, &response); // Verify that the item is reachable. { - Id child_id; syncable::ReadTransaction trans(FROM_HERE, directory()); - syncable::Entry root(&trans, syncable::GET_BY_ID, id_factory_.root()); - ASSERT_TRUE(root.good()); + Id child_id; ASSERT_TRUE(directory()->GetFirstChildId( - &trans, id_factory_.root(), &child_id)); + &trans, id_factory_.root(), &child_id)); ASSERT_EQ(folder_id, child_id); } @@ -273,8 +303,8 @@ TEST_F(ProcessCommitResponseCommandTest, NewFolderCommitKeepsChildOrder) { // Alternate between new and old child items, just for kicks. Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); CreateUnprocessedCommitResult( - id, folder_id, base::StringPrintf("Item %d", i), false, - BOOKMARKS, &commit_set, &request, &response); + id, folder_id, base::StringPrintf("Item %d", i), BOOKMARKS, + &commit_set, &request, &response); } // The second 25 children will be unsynced items but NOT part of the commit // batch. When the ID of the parent folder changes during the commit, @@ -283,9 +313,8 @@ TEST_F(ProcessCommitResponseCommandTest, NewFolderCommitKeepsChildOrder) { for (; i < 2*batch_size; ++i) { // Alternate between new and old child items, just for kicks. Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); - test_entry_factory_->CreateUnsyncedItem( - id, folder_id, base::StringPrintf("Item %d", i), - false, BOOKMARKS, NULL); + CreateUnsyncedItem(id, folder_id, base::StringPrintf("Item %d", i), + false, BOOKMARKS, NULL); } // Process the commit response for the parent folder and the first @@ -384,17 +413,15 @@ TEST_P(MixedResult, ExtensionActivity) { << "To not be lame, this test requires more than one active group."; // Bookmark item setup. - CreateUnprocessedCommitResult( - id_factory_.NewServerId(), - id_factory_.root(), "Some bookmark", false, - BOOKMARKS, &commit_set, &request, &response); + CreateUnprocessedCommitResult(id_factory_.NewServerId(), + id_factory_.root(), "Some bookmark", BOOKMARKS, + &commit_set, &request, &response); if (ShouldFailBookmarkCommit()) SetLastErrorCode(CommitResponse::TRANSIENT_ERROR, &response); // Autofill item setup. - CreateUnprocessedCommitResult( - id_factory_.NewServerId(), - id_factory_.root(), "Some autofill", false, - AUTOFILL, &commit_set, &request, &response); + CreateUnprocessedCommitResult(id_factory_.NewServerId(), + id_factory_.root(), "Some autofill", AUTOFILL, + &commit_set, &request, &response); if (ShouldFailAutofillCommit()) SetLastErrorCode(CommitResponse::TRANSIENT_ERROR, &response); diff --git a/sync/engine/syncer_unittest.cc b/sync/engine/syncer_unittest.cc index 669bda2..7fef4f4 100644 --- a/sync/engine/syncer_unittest.cc +++ b/sync/engine/syncer_unittest.cc @@ -355,7 +355,7 @@ class SyncerTest : public testing::Test, } string utf8_name = test->id.GetServerId(); string name(utf8_name.begin(), utf8_name.end()); - MutableEntry entry(&trans, CREATE, BOOKMARKS, test->parent_id, name); + MutableEntry entry(&trans, CREATE, test->parent_id, name); entry.Put(syncable::ID, test->id); if (test->id.ServerKnows()) { @@ -458,8 +458,8 @@ class SyncerTest : public testing::Test, int64 CreateUnsyncedDirectory(const string& entry_name, const syncable::Id& id) { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry entry( - &wtrans, CREATE, BOOKMARKS, wtrans.root_id(), entry_name); + MutableEntry entry(&wtrans, syncable::CREATE, wtrans.root_id(), + entry_name); EXPECT_TRUE(entry.good()); entry.Put(syncable::IS_UNSYNCED, true); entry.Put(syncable::IS_DIR, true); @@ -987,14 +987,15 @@ TEST_F(SyncerTest, EncryptionAwareConflicts) { TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete"); + MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), + "Pete"); ASSERT_TRUE(parent.good()); parent.Put(syncable::IS_UNSYNCED, true); parent.Put(syncable::IS_DIR, true); parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); parent.Put(syncable::BASE_VERSION, 1); parent.Put(syncable::ID, parent_id_); - MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent_id_, "Pete"); + MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete"); ASSERT_TRUE(child.good()); child.Put(syncable::ID, child_id_); child.Put(syncable::BASE_VERSION, 1); @@ -1019,20 +1020,20 @@ TEST_F(SyncerTest, TestPurgeWhileUnsynced) { syncable::Id pref_node_id = TestIdFactory::MakeServer("Tim"); { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete"); + MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete"); ASSERT_TRUE(parent.good()); parent.Put(syncable::IS_UNSYNCED, true); parent.Put(syncable::IS_DIR, true); parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); parent.Put(syncable::BASE_VERSION, 1); parent.Put(syncable::ID, parent_id_); - MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent_id_, "Pete"); + MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete"); ASSERT_TRUE(child.good()); child.Put(syncable::ID, child_id_); child.Put(syncable::BASE_VERSION, 1); WriteTestDataToEntry(&wtrans, &child); - MutableEntry parent2(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Tim"); + MutableEntry parent2(&wtrans, syncable::CREATE, wtrans.root_id(), "Tim"); ASSERT_TRUE(parent2.good()); parent2.Put(syncable::IS_UNSYNCED, true); parent2.Put(syncable::IS_DIR, true); @@ -1066,7 +1067,7 @@ TEST_F(SyncerTest, TestPurgeWhileUnapplied) { // Similar to above, but for unapplied items. Bug 49278. { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete"); + MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete"); ASSERT_TRUE(parent.good()); parent.Put(syncable::IS_UNAPPLIED_UPDATE, true); parent.Put(syncable::IS_DIR, true); @@ -1221,23 +1222,24 @@ TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); { - MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Bob"); + MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), + "Bob"); ASSERT_TRUE(parent.good()); parent.Put(syncable::IS_UNSYNCED, true); parent.Put(syncable::IS_DIR, true); parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); parent.Put(syncable::ID, ids_.FromNumber(100)); parent.Put(syncable::BASE_VERSION, 1); - MutableEntry child( - &wtrans, CREATE, BOOKMARKS, ids_.FromNumber(100), "Bob"); + MutableEntry child(&wtrans, syncable::CREATE, ids_.FromNumber(100), + "Bob"); ASSERT_TRUE(child.good()); child.Put(syncable::IS_UNSYNCED, true); child.Put(syncable::IS_DIR, true); child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); child.Put(syncable::ID, ids_.FromNumber(101)); child.Put(syncable::BASE_VERSION, 1); - MutableEntry grandchild( - &wtrans, CREATE, BOOKMARKS, ids_.FromNumber(101), "Bob"); + MutableEntry grandchild(&wtrans, syncable::CREATE, ids_.FromNumber(101), + "Bob"); ASSERT_TRUE(grandchild.good()); grandchild.Put(syncable::ID, ids_.FromNumber(102)); grandchild.Put(syncable::IS_UNSYNCED, true); @@ -1247,7 +1249,8 @@ TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { { // Create three deleted items which deletions we expect to be sent to the // server. - MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete"); + MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), + "Pete"); ASSERT_TRUE(parent.good()); parent.Put(syncable::ID, ids_.FromNumber(103)); parent.Put(syncable::IS_UNSYNCED, true); @@ -1256,8 +1259,8 @@ TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { parent.Put(syncable::IS_DEL, true); parent.Put(syncable::BASE_VERSION, 1); parent.Put(syncable::MTIME, now_minus_2h); - MutableEntry child( - &wtrans, CREATE, BOOKMARKS, ids_.FromNumber(103), "Pete"); + MutableEntry child(&wtrans, syncable::CREATE, ids_.FromNumber(103), + "Pete"); ASSERT_TRUE(child.good()); child.Put(syncable::ID, ids_.FromNumber(104)); child.Put(syncable::IS_UNSYNCED, true); @@ -1266,8 +1269,8 @@ TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { child.Put(syncable::IS_DEL, true); child.Put(syncable::BASE_VERSION, 1); child.Put(syncable::MTIME, now_minus_2h); - MutableEntry grandchild( - &wtrans, CREATE, BOOKMARKS, ids_.FromNumber(104), "Pete"); + MutableEntry grandchild(&wtrans, syncable::CREATE, ids_.FromNumber(104), + "Pete"); ASSERT_TRUE(grandchild.good()); grandchild.Put(syncable::ID, ids_.FromNumber(105)); grandchild.Put(syncable::IS_UNSYNCED, true); @@ -1296,35 +1299,32 @@ TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { } TEST_F(SyncerTest, TestCommitListOrderingWithNewItems) { - syncable::Id parent1_id = ids_.MakeServer("p1"); - syncable::Id parent2_id = ids_.MakeServer("p2"); - { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "1"); + MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "1"); ASSERT_TRUE(parent.good()); parent.Put(syncable::IS_UNSYNCED, true); parent.Put(syncable::IS_DIR, true); parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); - parent.Put(syncable::ID, parent1_id); - MutableEntry child(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "2"); + parent.Put(syncable::ID, parent_id_); + MutableEntry child(&wtrans, syncable::CREATE, wtrans.root_id(), "2"); ASSERT_TRUE(child.good()); child.Put(syncable::IS_UNSYNCED, true); child.Put(syncable::IS_DIR, true); child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); - child.Put(syncable::ID, parent2_id); + child.Put(syncable::ID, child_id_); parent.Put(syncable::BASE_VERSION, 1); child.Put(syncable::BASE_VERSION, 1); } { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry parent(&wtrans, CREATE, BOOKMARKS, parent1_id, "A"); + MutableEntry parent(&wtrans, syncable::CREATE, parent_id_, "A"); ASSERT_TRUE(parent.good()); parent.Put(syncable::IS_UNSYNCED, true); parent.Put(syncable::IS_DIR, true); parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); parent.Put(syncable::ID, ids_.FromNumber(102)); - MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent1_id, "B"); + MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "B"); ASSERT_TRUE(child.good()); child.Put(syncable::IS_UNSYNCED, true); child.Put(syncable::IS_DIR, true); @@ -1334,13 +1334,13 @@ TEST_F(SyncerTest, TestCommitListOrderingWithNewItems) { } { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry parent(&wtrans, CREATE, BOOKMARKS, parent2_id, "A"); + MutableEntry parent(&wtrans, syncable::CREATE, child_id_, "A"); ASSERT_TRUE(parent.good()); parent.Put(syncable::IS_UNSYNCED, true); parent.Put(syncable::IS_DIR, true); parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); parent.Put(syncable::ID, ids_.FromNumber(-104)); - MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent2_id, "B"); + MutableEntry child(&wtrans, syncable::CREATE, child_id_, "B"); ASSERT_TRUE(child.good()); child.Put(syncable::IS_UNSYNCED, true); child.Put(syncable::IS_DIR, true); @@ -1352,8 +1352,8 @@ TEST_F(SyncerTest, TestCommitListOrderingWithNewItems) { SyncShareNudge(); ASSERT_EQ(6u, mock_server_->committed_ids().size()); // If this test starts failing, be aware other sort orders could be valid. - EXPECT_TRUE(parent1_id == mock_server_->committed_ids()[0]); - EXPECT_TRUE(parent2_id == mock_server_->committed_ids()[1]); + EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); + EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); EXPECT_TRUE(ids_.FromNumber(102) == mock_server_->committed_ids()[2]); EXPECT_TRUE(ids_.FromNumber(-103) == mock_server_->committed_ids()[3]); EXPECT_TRUE(ids_.FromNumber(-104) == mock_server_->committed_ids()[4]); @@ -1365,18 +1365,18 @@ TEST_F(SyncerTest, TestCommitListOrderingCounterexample) { { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "P"); + MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "P"); ASSERT_TRUE(parent.good()); parent.Put(syncable::IS_UNSYNCED, true); parent.Put(syncable::IS_DIR, true); parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); parent.Put(syncable::ID, parent_id_); - MutableEntry child1(&wtrans, CREATE, BOOKMARKS, parent_id_, "1"); + MutableEntry child1(&wtrans, syncable::CREATE, parent_id_, "1"); ASSERT_TRUE(child1.good()); child1.Put(syncable::IS_UNSYNCED, true); child1.Put(syncable::ID, child_id_); child1.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); - MutableEntry child2(&wtrans, CREATE, BOOKMARKS, parent_id_, "2"); + MutableEntry child2(&wtrans, syncable::CREATE, parent_id_, "2"); ASSERT_TRUE(child2.good()); child2.Put(syncable::IS_UNSYNCED, true); child2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); @@ -1402,7 +1402,7 @@ TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) { { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), + MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), parent1_name); ASSERT_TRUE(parent.good()); parent.Put(syncable::IS_UNSYNCED, true); @@ -1416,16 +1416,14 @@ TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) { syncable::Id child_id = ids_.NewServerId(); { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry parent2( - &wtrans, CREATE, BOOKMARKS, parent_id_, parent2_name); + MutableEntry parent2(&wtrans, syncable::CREATE, parent_id_, parent2_name); ASSERT_TRUE(parent2.good()); parent2.Put(syncable::IS_UNSYNCED, true); parent2.Put(syncable::IS_DIR, true); parent2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); parent2.Put(syncable::ID, parent2_id); - MutableEntry child( - &wtrans, CREATE, BOOKMARKS, parent2_id, child_name); + MutableEntry child(&wtrans, syncable::CREATE, parent2_id, child_name); ASSERT_TRUE(child.good()); child.Put(syncable::IS_UNSYNCED, true); child.Put(syncable::IS_DIR, true); @@ -1472,7 +1470,7 @@ TEST_F(SyncerTest, TestCommitListOrderingAndNewParentAndChild) { { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); MutableEntry parent(&wtrans, - CREATE, BOOKMARKS, + syncable::CREATE, wtrans.root_id(), parent_name); ASSERT_TRUE(parent.good()); @@ -1488,15 +1486,14 @@ TEST_F(SyncerTest, TestCommitListOrderingAndNewParentAndChild) { const Id child_local_id = ids_.NewLocalId(); { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry parent2(&wtrans, CREATE, BOOKMARKS, parent_id_, parent2_name); + MutableEntry parent2(&wtrans, syncable::CREATE, parent_id_, parent2_name); ASSERT_TRUE(parent2.good()); parent2.Put(syncable::IS_UNSYNCED, true); parent2.Put(syncable::IS_DIR, true); parent2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); parent2.Put(syncable::ID, parent2_local_id); - MutableEntry child( - &wtrans, CREATE, BOOKMARKS, parent2_local_id, child_name); + MutableEntry child(&wtrans, syncable::CREATE, parent2_local_id, child_name); ASSERT_TRUE(child.good()); child.Put(syncable::IS_UNSYNCED, true); child.Put(syncable::IS_DIR, true); @@ -1714,14 +1711,14 @@ TEST_F(SyncerTest, CommitTimeRename) { // Create a folder and an entry. { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry parent(&trans, CREATE, BOOKMARKS, root_id_, "Folder"); + MutableEntry parent(&trans, CREATE, root_id_, "Folder"); ASSERT_TRUE(parent.good()); parent.Put(IS_DIR, true); parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); parent.Put(IS_UNSYNCED, true); metahandle_folder = parent.Get(META_HANDLE); - MutableEntry entry(&trans, CREATE, BOOKMARKS, parent.Get(ID), "new_entry"); + MutableEntry entry(&trans, CREATE, parent.Get(ID), "new_entry"); ASSERT_TRUE(entry.good()); metahandle_new_entry = entry.Get(META_HANDLE); WriteTestDataToEntry(&trans, &entry); @@ -1762,7 +1759,7 @@ TEST_F(SyncerTest, CommitTimeRenameI18N) { // Create a folder, expect a commit time rename. { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry parent(&trans, CREATE, BOOKMARKS, root_id_, "Folder"); + MutableEntry parent(&trans, CREATE, root_id_, "Folder"); ASSERT_TRUE(parent.good()); parent.Put(IS_DIR, true); parent.Put(SPECIFICS, DefaultBookmarkSpecifics()); @@ -1793,8 +1790,7 @@ TEST_F(SyncerTest, CommitReuniteUpdateAdjustsChildren) { int64 metahandle_folder; { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry entry( - &trans, CREATE, BOOKMARKS, trans.root_id(), "new_folder"); + MutableEntry entry(&trans, CREATE, trans.root_id(), "new_folder"); ASSERT_TRUE(entry.good()); entry.Put(IS_DIR, true); entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); @@ -1816,7 +1812,7 @@ TEST_F(SyncerTest, CommitReuniteUpdateAdjustsChildren) { // Create an entry in the newly created folder. { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry entry(&trans, CREATE, BOOKMARKS, folder_id, "new_entry"); + MutableEntry entry(&trans, CREATE, folder_id, "new_entry"); ASSERT_TRUE(entry.good()); metahandle_entry = entry.Get(META_HANDLE); WriteTestDataToEntry(&trans, &entry); @@ -1885,7 +1881,7 @@ TEST_F(SyncerTest, CommitReuniteUpdate) { int64 entry_metahandle; { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "new_entry"); + MutableEntry entry(&trans, CREATE, trans.root_id(), "new_entry"); ASSERT_TRUE(entry.good()); entry_metahandle = entry.Get(META_HANDLE); WriteTestDataToEntry(&trans, &entry); @@ -1939,7 +1935,7 @@ TEST_F(SyncerTest, CommitReuniteUpdateDoesNotChokeOnDeletedLocalEntry) { int64 entry_metahandle; { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "new_entry"); + MutableEntry entry(&trans, CREATE, trans.root_id(), "new_entry"); ASSERT_TRUE(entry.good()); entry_metahandle = entry.Get(META_HANDLE); WriteTestDataToEntry(&trans, &entry); @@ -2103,8 +2099,8 @@ class EntryCreatedInNewFolderTest : public SyncerTest { "bob")); CHECK(bob.good()); - MutableEntry entry2( - &trans, CREATE, BOOKMARKS, bob.Get(syncable::ID), "bob"); + MutableEntry entry2(&trans, syncable::CREATE, bob.Get(syncable::ID), + "bob"); CHECK(entry2.good()); entry2.Put(syncable::IS_DIR, true); entry2.Put(syncable::IS_UNSYNCED, true); @@ -2115,7 +2111,8 @@ class EntryCreatedInNewFolderTest : public SyncerTest { TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) { { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob"); + MutableEntry entry(&trans, syncable::CREATE, trans.root_id(), + "bob"); ASSERT_TRUE(entry.good()); entry.Put(syncable::IS_DIR, true); entry.Put(syncable::IS_UNSYNCED, true); @@ -2153,7 +2150,7 @@ TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) { { // Create an item. WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry fred_match(&trans, CREATE, BOOKMARKS, trans.root_id(), + MutableEntry fred_match(&trans, CREATE, trans.root_id(), "fred_match"); ASSERT_TRUE(fred_match.good()); metahandle_fred = fred_match.Get(META_HANDLE); @@ -2189,13 +2186,13 @@ TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) { TEST_F(SyncerTest, DoublyChangedWithResolver) { { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "Folder"); + MutableEntry parent(&wtrans, syncable::CREATE, root_id_, "Folder"); ASSERT_TRUE(parent.good()); parent.Put(syncable::IS_DIR, true); parent.Put(syncable::ID, parent_id_); parent.Put(syncable::BASE_VERSION, 5); parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); - MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent_id_, "Pete.htm"); + MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete.htm"); ASSERT_TRUE(child.good()); child.Put(syncable::ID, child_id_); child.Put(syncable::BASE_VERSION, 10); @@ -2230,7 +2227,7 @@ TEST_F(SyncerTest, CommitsUpdateDoesntAlterEntry) { int64 entry_metahandle; { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry entry(&wtrans, CREATE, BOOKMARKS, root_id_, "Pete"); + MutableEntry entry(&wtrans, syncable::CREATE, root_id_, "Pete"); ASSERT_TRUE(entry.good()); EXPECT_FALSE(entry.Get(ID).ServerKnows()); entry.Put(syncable::IS_DIR, true); @@ -2276,7 +2273,7 @@ TEST_F(SyncerTest, ParentAndChildBothMatch) { { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "Folder"); + MutableEntry parent(&wtrans, CREATE, root_id_, "Folder"); ASSERT_TRUE(parent.good()); parent.Put(IS_DIR, true); parent.Put(IS_UNSYNCED, true); @@ -2284,7 +2281,7 @@ TEST_F(SyncerTest, ParentAndChildBothMatch) { parent.Put(BASE_VERSION, 1); parent.Put(SPECIFICS, DefaultBookmarkSpecifics()); - MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent.Get(ID), "test.htm"); + MutableEntry child(&wtrans, CREATE, parent.Get(ID), "test.htm"); ASSERT_TRUE(child.good()); child.Put(ID, child_id); child.Put(BASE_VERSION, 1); @@ -2317,7 +2314,7 @@ TEST_F(SyncerTest, ParentAndChildBothMatch) { TEST_F(SyncerTest, CommittingNewDeleted) { { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob"); + MutableEntry entry(&trans, CREATE, trans.root_id(), "bob"); entry.Put(IS_UNSYNCED, true); entry.Put(IS_DEL, true); } @@ -2338,7 +2335,7 @@ TEST_F(SyncerTest, UnappliedUpdateDuringCommit) { // This test is a little fake. { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob"); + MutableEntry entry(&trans, CREATE, trans.root_id(), "bob"); entry.Put(ID, ids_.FromNumber(20)); entry.Put(BASE_VERSION, 1); entry.Put(SERVER_VERSION, 1); @@ -2370,7 +2367,7 @@ TEST_F(SyncerTest, DeletingEntryInFolder) { int64 existing_metahandle; { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "existing"); + MutableEntry entry(&trans, CREATE, trans.root_id(), "existing"); ASSERT_TRUE(entry.good()); entry.Put(IS_DIR, true); entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); @@ -2380,7 +2377,7 @@ TEST_F(SyncerTest, DeletingEntryInFolder) { syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry newfolder(&trans, CREATE, BOOKMARKS, trans.root_id(), "new"); + MutableEntry newfolder(&trans, CREATE, trans.root_id(), "new"); ASSERT_TRUE(newfolder.good()); newfolder.Put(IS_DIR, true); newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics()); @@ -2406,8 +2403,7 @@ TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { SyncShareNudge(); { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry newfolder( - &trans, CREATE, BOOKMARKS, ids_.FromNumber(1), "local"); + MutableEntry newfolder(&trans, CREATE, ids_.FromNumber(1), "local"); ASSERT_TRUE(newfolder.good()); newfolder.Put(IS_UNSYNCED, true); newfolder.Put(IS_DIR, true); @@ -2498,7 +2494,7 @@ TEST_F(SyncerTest, CommitManyItemsInOneGo_Success) { for (uint32 i = 0; i < items_to_commit; i++) { string nameutf8 = base::StringPrintf("%d", i); string name(nameutf8.begin(), nameutf8.end()); - MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name); + MutableEntry e(&trans, CREATE, trans.root_id(), name); e.Put(IS_UNSYNCED, true); e.Put(IS_DIR, true); e.Put(SPECIFICS, DefaultBookmarkSpecifics()); @@ -2521,7 +2517,7 @@ TEST_F(SyncerTest, CommitManyItemsInOneGo_PostBufferFail) { for (uint32 i = 0; i < items_to_commit; i++) { string nameutf8 = base::StringPrintf("%d", i); string name(nameutf8.begin(), nameutf8.end()); - MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name); + MutableEntry e(&trans, CREATE, trans.root_id(), name); e.Put(IS_UNSYNCED, true); e.Put(IS_DIR, true); e.Put(SPECIFICS, DefaultBookmarkSpecifics()); @@ -2551,7 +2547,7 @@ TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) { for (uint32 i = 0; i < items_to_commit; i++) { string nameutf8 = base::StringPrintf("%d", i); string name(nameutf8.begin(), nameutf8.end()); - MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name); + MutableEntry e(&trans, CREATE, trans.root_id(), name); e.Put(IS_UNSYNCED, true); e.Put(IS_DIR, true); e.Put(SPECIFICS, DefaultBookmarkSpecifics()); @@ -2649,8 +2645,7 @@ TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) { syncable::Id local_folder_id; { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry new_entry( - &wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Bar.htm"); + MutableEntry new_entry(&wtrans, CREATE, wtrans.root_id(), "Bar.htm"); ASSERT_TRUE(new_entry.good()); local_folder_id = new_entry.Get(ID); local_folder_handle = new_entry.Get(META_HANDLE); @@ -2716,8 +2711,7 @@ TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) { syncable::Id local_folder_id; { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry new_entry( - &wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Bar.htm"); + MutableEntry new_entry(&wtrans, CREATE, wtrans.root_id(), "Bar.htm"); ASSERT_TRUE(new_entry.good()); local_folder_id = new_entry.Get(ID); local_folder_handle = new_entry.Get(META_HANDLE); @@ -2889,12 +2883,12 @@ TEST_F(SyncerTest, ResolveWeWroteTheyDeleted) { TEST_F(SyncerTest, DuplicateIDReturn) { { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry folder(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob"); + MutableEntry folder(&trans, CREATE, trans.root_id(), "bob"); ASSERT_TRUE(folder.good()); folder.Put(IS_UNSYNCED, true); folder.Put(IS_DIR, true); folder.Put(SPECIFICS, DefaultBookmarkSpecifics()); - MutableEntry folder2(&trans, CREATE, BOOKMARKS, trans.root_id(), "fred"); + MutableEntry folder2(&trans, CREATE, trans.root_id(), "fred"); ASSERT_TRUE(folder2.good()); folder2.Put(IS_UNSYNCED, false); folder2.Put(IS_DIR, true); @@ -2933,8 +2927,7 @@ TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) { { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry local_deleted( - &trans, CREATE, BOOKMARKS, trans.root_id(), "name"); + MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name"); local_deleted.Put(ID, ids_.FromNumber(1)); local_deleted.Put(BASE_VERSION, 1); local_deleted.Put(IS_DEL, true); @@ -2967,8 +2960,7 @@ TEST_F(SyncerTest, UpdateFlipsTheFolderBit) { { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry local_deleted( - &trans, CREATE, BOOKMARKS, trans.root_id(), "name"); + MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name"); local_deleted.Put(ID, ids_.FromNumber(1)); local_deleted.Put(BASE_VERSION, 1); local_deleted.Put(IS_DEL, true); @@ -3006,8 +2998,7 @@ TEST_F(SyncerTest, MergingExistingItems) { SyncShareNudge(); { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry entry( - &trans, CREATE, BOOKMARKS, trans.root_id(), "Copy of base"); + MutableEntry entry(&trans, CREATE, trans.root_id(), "Copy of base"); WriteTestDataToEntry(&trans, &entry); } mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50); @@ -3197,7 +3188,7 @@ TEST_F(SyncerTest, DirectoryCommitTest) { { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "foo"); + MutableEntry parent(&wtrans, syncable::CREATE, root_id_, "foo"); ASSERT_TRUE(parent.good()); parent.Put(syncable::IS_UNSYNCED, true); parent.Put(syncable::IS_DIR, true); @@ -3205,7 +3196,7 @@ TEST_F(SyncerTest, DirectoryCommitTest) { in_root_id = parent.Get(syncable::ID); foo_metahandle = parent.Get(META_HANDLE); - MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent.Get(ID), "bar"); + MutableEntry child(&wtrans, syncable::CREATE, parent.Get(ID), "bar"); ASSERT_TRUE(child.good()); child.Put(syncable::IS_UNSYNCED, true); child.Put(syncable::IS_DIR, true); @@ -3317,8 +3308,7 @@ TEST_F(SyncerTest, EnsureWeSendUpOldParent) { entry.Put(PARENT_ID, folder_two_id); entry.Put(IS_UNSYNCED, true); // A new entry should send no "old parent." - MutableEntry create( - &trans, CREATE, BOOKMARKS, trans.root_id(), "new_folder"); + MutableEntry create(&trans, CREATE, trans.root_id(), "new_folder"); create.Put(IS_UNSYNCED, true); create.Put(SPECIFICS, DefaultBookmarkSpecifics()); } @@ -3338,7 +3328,7 @@ TEST_F(SyncerTest, Test64BitVersionSupport) { // Try writing max int64 to the version fields of a meta entry. { WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); - MutableEntry entry(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), name); + MutableEntry entry(&wtrans, syncable::CREATE, wtrans.root_id(), name); ASSERT_TRUE(entry.good()); entry.Put(syncable::BASE_VERSION, really_big_int); entry.Put(syncable::SERVER_VERSION, really_big_int); @@ -3549,8 +3539,7 @@ TEST_F(SyncerTest, ClientTagUncommittedTagMatchesUpdate) { { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry perm_folder( - &trans, CREATE, BOOKMARKS, ids_.root(), "clientname"); + MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname"); ASSERT_TRUE(perm_folder.good()); perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm"); perm_folder.Put(SPECIFICS, local_bookmark); @@ -3615,8 +3604,7 @@ TEST_F(SyncerTest, ClientTagConflictWithDeletedLocalEntry) { { // Create a deleted local entry with a unique client tag. WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry perm_folder( - &trans, CREATE, BOOKMARKS, ids_.root(), "clientname"); + MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname"); ASSERT_TRUE(perm_folder.good()); ASSERT_FALSE(perm_folder.Get(ID).ServerKnows()); perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm"); @@ -4078,8 +4066,7 @@ class SyncerUndeletionTest : public SyncerTest { void Create() { WriteTransaction trans(FROM_HERE, UNITTEST, directory()); - MutableEntry perm_folder( - &trans, CREATE, BOOKMARKS, ids_.root(), "clientname"); + MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname"); ASSERT_TRUE(perm_folder.good()); perm_folder.Put(UNIQUE_CLIENT_TAG, client_tag_); perm_folder.Put(IS_UNSYNCED, true); diff --git a/sync/internal_api/public/test/test_entry_factory.h b/sync/internal_api/public/test/test_entry_factory.h index 7ca79e6..071a501 100644 --- a/sync/internal_api/public/test/test_entry_factory.h +++ b/sync/internal_api/public/test/test_entry_factory.h @@ -29,21 +29,15 @@ class TestEntryFactory { const sync_pb::EntitySpecifics& specifics, const std::string& parent_id); - int64 CreateUnappliedNewBookmarkItemWithParent( - const std::string& item_id, - const sync_pb::EntitySpecifics& specifics, - const std::string& parent_id); - // Create a new unapplied update without a parent. int64 CreateUnappliedNewItem(const std::string& item_id, const sync_pb::EntitySpecifics& specifics, bool is_unique); - // Create an unsynced unique_client_tag item in the database. If item_id is a - // local ID, it will be treated as a create-new. Otherwise, if it's a server - // ID, we'll fake the server data so that it looks like it exists on the - // server. Returns the methandle of the created item in |metahandle_out| if - // not NULL. + // Create an unsynced item in the database. If item_id is a local ID, it will + // be treated as a create-new. Otherwise, if it's a server ID, we'll fake the + // server data so that it looks like it exists on the server. Returns the + // methandle of the created item in |metahandle_out| if not NULL. void CreateUnsyncedItem(const syncable::Id& item_id, const syncable::Id& parent_id, const std::string& name, @@ -51,13 +45,14 @@ class TestEntryFactory { ModelType model_type, int64* metahandle_out); - // Creates a bookmark that is both unsynced an an unapplied update. Returns - // the metahandle of the created item. - int64 CreateUnappliedAndUnsyncedBookmarkItem(const std::string& name); + // Creates an item that is both unsynced an an unapplied update. Returns the + // metahandle of the created item. + int64 CreateUnappliedAndUnsyncedItem(const std::string& name, + ModelType model_type); - // Creates a unique_client_tag item that has neither IS_UNSYNED or - // IS_UNAPPLIED_UPDATE. The item is known to both the server and client. - // Returns the metahandle of the created item. + // Creates an item that has neither IS_UNSYNED or IS_UNAPPLIED_UPDATE. The + // item is known to both the server and client. Returns the metahandle of + // the created item. int64 CreateSyncedItem(const std::string& name, ModelType model_type, bool is_folder); diff --git a/sync/internal_api/public/write_node.h b/sync/internal_api/public/write_node.h index 990f040..73baa6f 100644 --- a/sync/internal_api/public/write_node.h +++ b/sync/internal_api/public/write_node.h @@ -67,12 +67,15 @@ class SYNC_EXPORT WriteNode : public BaseNode { ModelType model_type, const std::string& tag) OVERRIDE; - // Create a new bookmark node with the specified parent and predecessor. Use - // a NULL |predecessor| to indicate that this is to be the first child. + // Create a new node with the specified parent and predecessor. |model_type| + // dictates the type of the item, and controls which EntitySpecifics proto + // extension can be used with this item. Use a NULL |predecessor| + // to indicate that this is to be the first child. // |predecessor| must be a child of |new_parent| or NULL. Returns false on // failure. - bool InitBookmarkByCreation(const BaseNode& parent, - const BaseNode* predecessor); + bool InitByCreation(ModelType model_type, + const BaseNode& parent, + const BaseNode* predecessor); // Create nodes using this function if they're unique items that // you want to fetch using client_tag. Note that the behavior of these @@ -180,6 +183,9 @@ class SYNC_EXPORT WriteNode : public BaseNode { void* operator new(size_t size); // Node is meant for stack use only. + // Helper to set model type. This will clear any specifics data. + void PutModelType(ModelType model_type); + // Helper to set the previous node. bool PutPredecessor(const BaseNode* predecessor) WARN_UNUSED_RESULT; diff --git a/sync/internal_api/sync_encryption_handler_impl_unittest.cc b/sync/internal_api/sync_encryption_handler_impl_unittest.cc index a650c14..6e0b757 100644 --- a/sync/internal_api/sync_encryption_handler_impl_unittest.cc +++ b/sync/internal_api/sync_encryption_handler_impl_unittest.cc @@ -103,7 +103,6 @@ class SyncEncryptionHandlerImplTest : public ::testing::Test { syncable::WriteTransaction wtrans(FROM_HERE, syncable::UNITTEST, directory); syncable::MutableEntry node(&wtrans, syncable::CREATE, - model_type, wtrans.root_id(), tag_name); node.Put(syncable::UNIQUE_SERVER_TAG, tag_name); diff --git a/sync/internal_api/sync_manager_impl_unittest.cc b/sync/internal_api/sync_manager_impl_unittest.cc index c06aa28..fd981f1 100644 --- a/sync/internal_api/sync_manager_impl_unittest.cc +++ b/sync/internal_api/sync_manager_impl_unittest.cc @@ -130,29 +130,35 @@ int64 MakeNode(UserShare* share, return node.GetId(); } -// Makes a folder child of a non-root node. Returns the id of the +// Makes a non-folder child of a non-root node. Returns the id of the // newly-created node. -int64 MakeFolderWithParent(UserShare* share, - ModelType model_type, - int64 parent_id, - BaseNode* predecessor) { +int64 MakeNodeWithParent(UserShare* share, + ModelType model_type, + const std::string& client_tag, + int64 parent_id) { WriteTransaction trans(FROM_HERE, share); ReadNode parent_node(&trans); - DCHECK_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); + EXPECT_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); WriteNode node(&trans); - DCHECK(node.InitBookmarkByCreation(parent_node, predecessor)); - node.SetIsFolder(true); + WriteNode::InitUniqueByCreationResult result = + node.InitUniqueByCreation(model_type, parent_node, client_tag); + EXPECT_EQ(WriteNode::INIT_SUCCESS, result); + node.SetIsFolder(false); return node.GetId(); } -int64 MakeBookmarkWithParent(UserShare* share, - int64 parent_id, - BaseNode* predecessor) { +// Makes a folder child of a non-root node. Returns the id of the +// newly-created node. +int64 MakeFolderWithParent(UserShare* share, + ModelType model_type, + int64 parent_id, + BaseNode* predecessor) { WriteTransaction trans(FROM_HERE, share); ReadNode parent_node(&trans); - DCHECK_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); + EXPECT_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); WriteNode node(&trans); - DCHECK(node.InitBookmarkByCreation(parent_node, predecessor)); + EXPECT_TRUE(node.InitByCreation(model_type, parent_node, predecessor)); + node.SetIsFolder(true); return node.GetId(); } @@ -344,7 +350,8 @@ TEST_F(SyncApiTest, TestDeleteBehavior) { // we'll use this spare folder later WriteNode folder_node(&trans); - EXPECT_TRUE(folder_node.InitBookmarkByCreation(root_node, NULL)); + EXPECT_TRUE(folder_node.InitByCreation(BOOKMARKS, + root_node, NULL)); folder_id = folder_node.GetId(); WriteNode wnode(&trans); @@ -453,21 +460,22 @@ TEST_F(SyncApiTest, WriteEncryptedTitle) { trans.GetCryptographer()->AddKey(params); } test_user_share_.encryption_handler()->EnableEncryptEverything(); - int bookmark_id; { WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); ReadNode root_node(&trans); root_node.InitByRootLookup(); WriteNode bookmark_node(&trans); - ASSERT_TRUE(bookmark_node.InitBookmarkByCreation(root_node, NULL)); - bookmark_id = bookmark_node.GetId(); + WriteNode::InitUniqueByCreationResult result = + bookmark_node.InitUniqueByCreation(BOOKMARKS, + root_node, "foo"); + EXPECT_EQ(WriteNode::INIT_SUCCESS, result); bookmark_node.SetTitle(UTF8ToWide("foo")); WriteNode pref_node(&trans); - WriteNode::InitUniqueByCreationResult result = + result = pref_node.InitUniqueByCreation(PREFERENCES, root_node, "bar"); - ASSERT_EQ(WriteNode::INIT_SUCCESS, result); + EXPECT_EQ(WriteNode::INIT_SUCCESS, result); pref_node.SetTitle(UTF8ToWide("bar")); } { @@ -476,13 +484,15 @@ TEST_F(SyncApiTest, WriteEncryptedTitle) { root_node.InitByRootLookup(); ReadNode bookmark_node(&trans); - ASSERT_EQ(BaseNode::INIT_OK, bookmark_node.InitByIdLookup(bookmark_id)); + EXPECT_EQ(BaseNode::INIT_OK, + bookmark_node.InitByClientTagLookup(BOOKMARKS, + "foo")); EXPECT_EQ("foo", bookmark_node.GetTitle()); EXPECT_EQ(kEncryptedString, bookmark_node.GetEntry()->Get(syncable::NON_UNIQUE_NAME)); ReadNode pref_node(&trans); - ASSERT_EQ(BaseNode::INIT_OK, + EXPECT_EQ(BaseNode::INIT_OK, pref_node.InitByClientTagLookup(PREFERENCES, "bar")); EXPECT_EQ(kEncryptedString, pref_node.GetTitle()); @@ -662,14 +672,16 @@ TEST_F(SyncApiTest, GetTotalNodeCountMultipleChildren) { BOOKMARKS, parent, NULL); - ignore_result(MakeBookmarkWithParent( + ignore_result(MakeNodeWithParent( test_user_share_.user_share(), - parent, - NULL)); - ignore_result(MakeBookmarkWithParent( + BOOKMARKS, + "c2", + parent)); + ignore_result(MakeNodeWithParent( test_user_share_.user_share(), - child1, - NULL)); + BOOKMARKS, + "c1c1", + child1)); { ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); @@ -1528,17 +1540,20 @@ TEST_F(SyncManagerTest, EncryptDataTypesWithData) { // First batch_size nodes are children of folder. size_t i; for (i = 0; i < batch_size; ++i) { - MakeBookmarkWithParent(sync_manager_.GetUserShare(), folder, NULL); + MakeNodeWithParent(sync_manager_.GetUserShare(), BOOKMARKS, + base::StringPrintf("%"PRIuS"", i), folder); } // Next batch_size nodes are a different type and on their own. for (; i < 2*batch_size; ++i) { - MakeNode(sync_manager_.GetUserShare(), SESSIONS, - base::StringPrintf("%"PRIuS"", i)); + MakeNodeWithParent(sync_manager_.GetUserShare(), SESSIONS, + base::StringPrintf("%"PRIuS"", i), + GetIdForDataType(SESSIONS)); } // Last batch_size nodes are a third type that will not need encryption. for (; i < 3*batch_size; ++i) { - MakeNode(sync_manager_.GetUserShare(), THEMES, - base::StringPrintf("%"PRIuS"", i)); + MakeNodeWithParent(sync_manager_.GetUserShare(), THEMES, + base::StringPrintf("%"PRIuS"", i), + GetIdForDataType(THEMES)); } { @@ -2135,11 +2150,10 @@ TEST_F(SyncManagerTest, CreateLocalBookmark) { std::string url = "url"; { WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); - ReadNode bookmark_root(&trans); - ASSERT_EQ(BaseNode::INIT_OK, - bookmark_root.InitByTagLookup(ModelTypeToRootTag(BOOKMARKS))); + ReadNode root_node(&trans); + root_node.InitByRootLookup(); WriteNode node(&trans); - ASSERT_TRUE(node.InitBookmarkByCreation(bookmark_root, NULL)); + ASSERT_TRUE(node.InitByCreation(BOOKMARKS, root_node, NULL)); node.SetIsFolder(false); node.SetTitle(UTF8ToWide(title)); @@ -2149,10 +2163,9 @@ TEST_F(SyncManagerTest, CreateLocalBookmark) { } { ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); - ReadNode bookmark_root(&trans); - ASSERT_EQ(BaseNode::INIT_OK, - bookmark_root.InitByTagLookup(ModelTypeToRootTag(BOOKMARKS))); - int64 child_id = bookmark_root.GetFirstChildId(); + ReadNode root_node(&trans); + root_node.InitByRootLookup(); + int64 child_id = root_node.GetFirstChildId(); ReadNode node(&trans); ASSERT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); 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); } diff --git a/sync/internal_api/write_node.cc b/sync/internal_api/write_node.cc index 43d6e50..5628571 100644 --- a/sync/internal_api/write_node.cc +++ b/sync/internal_api/write_node.cc @@ -212,7 +212,12 @@ void WriteNode::SetEntitySpecifics( DCHECK_NE(new_specifics_type, UNSPECIFIED); DVLOG(1) << "Writing entity specifics of type " << ModelTypeToString(new_specifics_type); - DCHECK_EQ(new_specifics_type, GetModelType()); + // GetModelType() can be unspecified if this is the first time this + // node is being initialized (see PutModelType()). Otherwise, it + // should match |new_specifics_type|. + if (GetModelType() != UNSPECIFIED) { + DCHECK_EQ(new_specifics_type, GetModelType()); + } // Preserve unknown fields. const sync_pb::EntitySpecifics& old_specifics = entry_->Get(SPECIFICS); @@ -322,10 +327,22 @@ BaseNode::InitByLookupResult WriteNode::InitByTagLookup( return INIT_OK; } +void WriteNode::PutModelType(ModelType model_type) { + // Set an empty specifics of the appropriate datatype. The presence + // of the specific field will identify the model type. + DCHECK(GetModelType() == model_type || + GetModelType() == UNSPECIFIED); // Immutable once set. + + sync_pb::EntitySpecifics specifics; + AddDefaultFieldValue(model_type, &specifics); + SetEntitySpecifics(specifics); +} + // Create a new node with default properties, and bind this WriteNode to it. // Return true on success. -bool WriteNode::InitBookmarkByCreation(const BaseNode& parent, - const BaseNode* predecessor) { +bool WriteNode::InitByCreation(ModelType model_type, + const BaseNode& parent, + const BaseNode* predecessor) { DCHECK(!entry_) << "Init called twice"; // |predecessor| must be a child of |parent| or NULL. if (predecessor && predecessor->GetParentId() != parent.GetId()) { @@ -340,8 +357,7 @@ bool WriteNode::InitBookmarkByCreation(const BaseNode& parent, string dummy(kDefaultNameForNewNodes); entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), - syncable::CREATE, BOOKMARKS, - parent_id, dummy); + syncable::CREATE, parent_id, dummy); if (!entry_->good()) return false; @@ -349,6 +365,8 @@ bool WriteNode::InitBookmarkByCreation(const BaseNode& parent, // Entries are untitled folders by default. entry_->Put(syncable::IS_DIR, true); + PutModelType(model_type); + // Now set the predecessor, which sets IS_UNSYNCED as necessary. return PutPredecessor(predecessor); } @@ -416,8 +434,7 @@ WriteNode::InitUniqueByCreationResult WriteNode::InitUniqueByCreation( } } else { entry_ = new syncable::MutableEntry(transaction_->GetWrappedWriteTrans(), - syncable::CREATE, - model_type, parent_id, dummy); + syncable::CREATE, parent_id, dummy); if (!entry_->good()) return INIT_FAILED_COULD_NOT_CREATE_ENTRY; @@ -428,6 +445,9 @@ WriteNode::InitUniqueByCreationResult WriteNode::InitUniqueByCreation( // We don't support directory and tag combinations. entry_->Put(syncable::IS_DIR, false); + // Will clear specifics data. + PutModelType(model_type); + // Now set the predecessor, which sets IS_UNSYNCED as necessary. bool success = PutPredecessor(NULL); if (!success) diff --git a/sync/syncable/mutable_entry.cc b/sync/syncable/mutable_entry.cc index 816e951..64a23ce 100644 --- a/sync/syncable/mutable_entry.cc +++ b/sync/syncable/mutable_entry.cc @@ -19,9 +19,15 @@ using std::string; namespace syncer { namespace syncable { -void MutableEntry::Init(WriteTransaction* trans, - ModelType model_type, - const Id& parent_id, +MutableEntry::MutableEntry(WriteTransaction* trans, Create, + const Id& parent_id, const string& name) + : Entry(trans), + write_transaction_(trans) { + Init(trans, parent_id, name); +} + + +void MutableEntry::Init(WriteTransaction* trans, const Id& parent_id, const string& name) { scoped_ptr<EntryKernel> kernel(new EntryKernel); kernel_ = NULL; @@ -37,15 +43,9 @@ void MutableEntry::Init(WriteTransaction* trans, // We match the database defaults here kernel->put(BASE_VERSION, CHANGES_VERSION); kernel->put(SERVER_ORDINAL_IN_PARENT, NodeOrdinal::CreateInitialOrdinal()); - - // Normally the SPECIFICS setting code is wrapped in logic to deal with - // unknown fields and encryption. Since all we want to do here is ensure that - // GetModelType() returns a correct value from the very beginning, these - // few lines are sufficient. - sync_pb::EntitySpecifics specifics; - AddDefaultFieldValue(model_type, &specifics); - kernel->put(SPECIFICS, specifics); - + if (!trans->directory()->InsertEntry(trans, kernel.get())) { + return; // We failed inserting, nothing more to do. + } // Because this entry is new, it was originally deleted. kernel->put(IS_DEL, true); trans->SaveOriginal(kernel.get()); @@ -55,17 +55,6 @@ void MutableEntry::Init(WriteTransaction* trans, kernel_ = kernel.release(); } -MutableEntry::MutableEntry(WriteTransaction* trans, - Create, - ModelType model_type, - const Id& parent_id, - const string& name) - : Entry(trans), - write_transaction_(trans) { - Init(trans, model_type, parent_id, name); - DCHECK(trans->directory()->InsertEntry(trans, kernel_)); -} - MutableEntry::MutableEntry(WriteTransaction* trans, CreateNewUpdateItem, const Id& id) : Entry(trans), write_transaction_(trans) { diff --git a/sync/syncable/mutable_entry.h b/sync/syncable/mutable_entry.h index 51cd794..cf7768a 100644 --- a/sync/syncable/mutable_entry.h +++ b/sync/syncable/mutable_entry.h @@ -6,7 +6,6 @@ #define SYNC_SYNCABLE_MUTABLE_ENTRY_H_ #include "sync/base/sync_export.h" -#include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/base/node_ordinal.h" #include "sync/syncable/entry.h" #include "sync/syncable/metahandle_set.h" @@ -29,12 +28,12 @@ enum CreateNewUpdateItem { // A mutable meta entry. Changes get committed to the database when the // WriteTransaction is destroyed. class SYNC_EXPORT_PRIVATE MutableEntry : public Entry { - void Init(WriteTransaction* trans, ModelType model_type, - const Id& parent_id, const std::string& name); + void Init(WriteTransaction* trans, const Id& parent_id, + const std::string& name); public: - MutableEntry(WriteTransaction* trans, Create, ModelType model_type, - const Id& parent_id, const std::string& name); + MutableEntry(WriteTransaction* trans, Create, const Id& parent_id, + const std::string& name); MutableEntry(WriteTransaction* trans, CreateNewUpdateItem, const Id& id); MutableEntry(WriteTransaction* trans, GetByHandle, int64); MutableEntry(WriteTransaction* trans, GetById, const Id&); diff --git a/sync/syncable/syncable_unittest.cc b/sync/syncable/syncable_unittest.cc index 444e9e3..7c72ed4b 100644 --- a/sync/syncable/syncable_unittest.cc +++ b/sync/syncable/syncable_unittest.cc @@ -146,7 +146,7 @@ TEST_F(SyncableGeneralTest, General) { // Test creating a new meta entry. { WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); - MutableEntry me(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), name); + MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name); ASSERT_TRUE(me.good()); me.Put(ID, id); me.Put(BASE_VERSION, 1); @@ -238,7 +238,7 @@ TEST_F(SyncableGeneralTest, ChildrenOps) { { WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); - MutableEntry me(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), name); + MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name); ASSERT_TRUE(me.good()); me.Put(ID, id); me.Put(BASE_VERSION, 1); @@ -300,7 +300,7 @@ TEST_F(SyncableGeneralTest, ClientIndexRebuildsProperly) { NullTransactionObserver())); { WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); - MutableEntry me(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), name); + MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name); ASSERT_TRUE(me.good()); me.Put(ID, id); me.Put(BASE_VERSION, 1); @@ -346,7 +346,7 @@ TEST_F(SyncableGeneralTest, ClientIndexRebuildsDeletedProperly) { NullTransactionObserver())); { WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); - MutableEntry me(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "deleted"); + MutableEntry me(&wtrans, CREATE, wtrans.root_id(), "deleted"); ASSERT_TRUE(me.good()); me.Put(ID, id); me.Put(BASE_VERSION, 1); @@ -401,7 +401,7 @@ TEST_F(SyncableGeneralTest, ToValue) { // Test creating a new meta entry. { WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); - MutableEntry me(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "new"); + MutableEntry me(&wtrans, CREATE, wtrans.root_id(), "new"); ASSERT_TRUE(me.good()); me.Put(ID, id); me.Put(BASE_VERSION, 1); @@ -409,7 +409,7 @@ TEST_F(SyncableGeneralTest, ToValue) { scoped_ptr<DictionaryValue> value(me.ToValue(NULL)); ExpectDictBooleanValue(true, *value, "good"); EXPECT_TRUE(value->HasKey("kernel")); - ExpectDictStringValue("Bookmarks", *value, "modelType"); + ExpectDictStringValue("Unspecified", *value, "modelType"); ExpectDictBooleanValue(true, *value, "existsOnClientBecauseNameIsNonEmpty"); ExpectDictBooleanValue(false, *value, "isRoot"); } @@ -504,7 +504,7 @@ class SyncableDirectoryTest : public testing::Test { } void CreateEntry(const std::string& entryname, Id id) { WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); - MutableEntry me(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), entryname); + MutableEntry me(&wtrans, CREATE, wtrans.root_id(), entryname); ASSERT_TRUE(me.good()); me.Put(ID, id); me.Put(IS_UNSYNCED, true); @@ -544,7 +544,7 @@ TEST_F(SyncableDirectoryTest, TakeSnapshotGetsMetahandlesToPurge) { { WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); for (int i = 0; i < metas_to_create; i++) { - MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), "foo"); + MutableEntry e(&trans, CREATE, trans.root_id(), "foo"); e.Put(IS_UNSYNCED, true); sync_pb::EntitySpecifics specs; if (i % 2 == 0) { @@ -585,7 +585,7 @@ TEST_F(SyncableDirectoryTest, TakeSnapshotGetsAllDirtyHandlesTest) { { WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); for (int i = 0; i < metahandles_to_create; i++) { - MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), "foo"); + MutableEntry e(&trans, CREATE, trans.root_id(), "foo"); expected_dirty_metahandles.push_back(e.Get(META_HANDLE)); e.Put(IS_UNSYNCED, true); } @@ -616,7 +616,7 @@ TEST_F(SyncableDirectoryTest, TakeSnapshotGetsAllDirtyHandlesTest) { e1.Put(IS_DIR, true); e1.Put(IS_UNSYNCED, true); // Add new entries - MutableEntry e2(&trans, CREATE, BOOKMARKS, trans.root_id(), "bar"); + MutableEntry e2(&trans, CREATE, trans.root_id(), "bar"); e2.Put(IS_UNSYNCED, true); new_dirty_metahandles.push_back(e2.Get(META_HANDLE)); } @@ -648,7 +648,7 @@ TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) { { WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); for (int i = 0; i < metahandles_to_create; i++) { - MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), "foo"); + MutableEntry e(&trans, CREATE, trans.root_id(), "foo"); expected_dirty_metahandles.push_back(e.Get(META_HANDLE)); e.Put(IS_UNSYNCED, true); } @@ -667,7 +667,7 @@ TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) { e1.Put(IS_DIR, true); e1.Put(IS_UNSYNCED, true); // Add new entries - MutableEntry e2(&trans, CREATE, BOOKMARKS, trans.root_id(), "bar"); + MutableEntry e2(&trans, CREATE, trans.root_id(), "bar"); e2.Put(IS_UNSYNCED, true); new_dirty_metahandles.push_back(e2.Get(META_HANDLE)); } @@ -871,13 +871,13 @@ TEST_F(SyncableDirectoryTest, TestBasicLookupValidID) { TEST_F(SyncableDirectoryTest, TestDelete) { std::string name = "peanut butter jelly time"; WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); - MutableEntry e1(&trans, CREATE, BOOKMARKS, trans.root_id(), name); + MutableEntry e1(&trans, CREATE, trans.root_id(), name); ASSERT_TRUE(e1.good()); ASSERT_TRUE(e1.Put(IS_DEL, true)); - MutableEntry e2(&trans, CREATE, BOOKMARKS, trans.root_id(), name); + MutableEntry e2(&trans, CREATE, trans.root_id(), name); ASSERT_TRUE(e2.good()); ASSERT_TRUE(e2.Put(IS_DEL, true)); - MutableEntry e3(&trans, CREATE, BOOKMARKS, trans.root_id(), name); + MutableEntry e3(&trans, CREATE, trans.root_id(), name); ASSERT_TRUE(e3.good()); ASSERT_TRUE(e3.Put(IS_DEL, true)); @@ -899,14 +899,14 @@ TEST_F(SyncableDirectoryTest, TestGetUnsynced) { dir_->GetUnsyncedMetaHandles(&trans, &handles); ASSERT_TRUE(0 == handles.size()); - MutableEntry e1(&trans, CREATE, BOOKMARKS, trans.root_id(), "abba"); + MutableEntry e1(&trans, CREATE, trans.root_id(), "abba"); ASSERT_TRUE(e1.good()); handle1 = e1.Get(META_HANDLE); e1.Put(BASE_VERSION, 1); e1.Put(IS_DIR, true); e1.Put(ID, TestIdFactory::FromNumber(101)); - MutableEntry e2(&trans, CREATE, BOOKMARKS, e1.Get(ID), "bread"); + MutableEntry e2(&trans, CREATE, e1.Get(ID), "bread"); ASSERT_TRUE(e2.good()); handle2 = e2.Get(META_HANDLE); e2.Put(BASE_VERSION, 1); @@ -971,7 +971,7 @@ TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) { dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles); ASSERT_TRUE(0 == handles.size()); - MutableEntry e1(&trans, CREATE, BOOKMARKS, trans.root_id(), "abba"); + MutableEntry e1(&trans, CREATE, trans.root_id(), "abba"); ASSERT_TRUE(e1.good()); handle1 = e1.Get(META_HANDLE); e1.Put(IS_UNAPPLIED_UPDATE, false); @@ -979,7 +979,7 @@ TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) { e1.Put(ID, TestIdFactory::FromNumber(101)); e1.Put(IS_DIR, true); - MutableEntry e2(&trans, CREATE, BOOKMARKS, e1.Get(ID), "bread"); + MutableEntry e2(&trans, CREATE, e1.Get(ID), "bread"); ASSERT_TRUE(e2.good()); handle2 = e2.Get(META_HANDLE); e2.Put(IS_UNAPPLIED_UPDATE, false); @@ -1040,22 +1040,22 @@ TEST_F(SyncableDirectoryTest, DeleteBug_531383) { int64 grandchild_handle; { WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); - MutableEntry parent(&wtrans, CREATE, BOOKMARKS, id_factory.root(), "Bob"); + MutableEntry parent(&wtrans, CREATE, id_factory.root(), "Bob"); ASSERT_TRUE(parent.good()); parent.Put(IS_DIR, true); parent.Put(ID, id_factory.NewServerId()); parent.Put(BASE_VERSION, 1); - MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent.Get(ID), "Bob"); + MutableEntry child(&wtrans, CREATE, parent.Get(ID), "Bob"); ASSERT_TRUE(child.good()); child.Put(IS_DIR, true); child.Put(ID, id_factory.NewServerId()); child.Put(BASE_VERSION, 1); - MutableEntry grandchild(&wtrans, CREATE, BOOKMARKS, child.Get(ID), "Bob"); + MutableEntry grandchild(&wtrans, CREATE, child.Get(ID), "Bob"); ASSERT_TRUE(grandchild.good()); grandchild.Put(ID, id_factory.NewServerId()); grandchild.Put(BASE_VERSION, 1); ASSERT_TRUE(grandchild.Put(IS_DEL, true)); - MutableEntry twin(&wtrans, CREATE, BOOKMARKS, child.Get(ID), "Bob"); + MutableEntry twin(&wtrans, CREATE, child.Get(ID), "Bob"); ASSERT_TRUE(twin.good()); ASSERT_TRUE(twin.Put(IS_DEL, true)); ASSERT_TRUE(grandchild.Put(IS_DEL, false)); @@ -1079,32 +1079,32 @@ TEST_F(SyncableDirectoryTest, TestIsLegalNewParent) { WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); Entry root(&wtrans, GET_BY_ID, id_factory.root()); ASSERT_TRUE(root.good()); - MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root.Get(ID), "Bob"); + MutableEntry parent(&wtrans, CREATE, root.Get(ID), "Bob"); ASSERT_TRUE(parent.good()); parent.Put(IS_DIR, true); parent.Put(ID, id_factory.NewServerId()); parent.Put(BASE_VERSION, 1); - MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent.Get(ID), "Bob"); + MutableEntry child(&wtrans, CREATE, parent.Get(ID), "Bob"); ASSERT_TRUE(child.good()); child.Put(IS_DIR, true); child.Put(ID, id_factory.NewServerId()); child.Put(BASE_VERSION, 1); - MutableEntry grandchild(&wtrans, CREATE, BOOKMARKS, child.Get(ID), "Bob"); + MutableEntry grandchild(&wtrans, CREATE, child.Get(ID), "Bob"); ASSERT_TRUE(grandchild.good()); grandchild.Put(ID, id_factory.NewServerId()); grandchild.Put(BASE_VERSION, 1); - MutableEntry parent2(&wtrans, CREATE, BOOKMARKS, root.Get(ID), "Pete"); + MutableEntry parent2(&wtrans, CREATE, root.Get(ID), "Pete"); ASSERT_TRUE(parent2.good()); parent2.Put(IS_DIR, true); parent2.Put(ID, id_factory.NewServerId()); parent2.Put(BASE_VERSION, 1); - MutableEntry child2(&wtrans, CREATE, BOOKMARKS, parent2.Get(ID), "Pete"); + MutableEntry child2(&wtrans, CREATE, parent2.Get(ID), "Pete"); ASSERT_TRUE(child2.good()); child2.Put(IS_DIR, true); child2.Put(ID, id_factory.NewServerId()); child2.Put(BASE_VERSION, 1); - MutableEntry grandchild2(&wtrans, CREATE, BOOKMARKS, child2.Get(ID), "Pete"); + MutableEntry grandchild2(&wtrans, CREATE, child2.Get(ID), "Pete"); ASSERT_TRUE(grandchild2.good()); grandchild2.Put(ID, id_factory.NewServerId()); grandchild2.Put(BASE_VERSION, 1); @@ -1136,13 +1136,13 @@ TEST_F(SyncableDirectoryTest, TestEntryIsInFolder) { { WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); - MutableEntry folder(&trans, CREATE, BOOKMARKS, trans.root_id(), "folder"); + MutableEntry folder(&trans, CREATE, trans.root_id(), "folder"); ASSERT_TRUE(folder.good()); EXPECT_TRUE(folder.Put(IS_DIR, true)); EXPECT_TRUE(folder.Put(IS_UNSYNCED, true)); folder_id = folder.Get(ID); - MutableEntry entry(&trans, CREATE, BOOKMARKS, folder.Get(ID), entry_name); + MutableEntry entry(&trans, CREATE, folder.Get(ID), entry_name); ASSERT_TRUE(entry.good()); entry_handle = entry.Get(META_HANDLE); entry.Put(IS_UNSYNCED, true); @@ -1167,15 +1167,15 @@ TEST_F(SyncableDirectoryTest, TestParentIdIndexUpdate) { std::string child_name = "child"; WriteTransaction wt(FROM_HERE, UNITTEST, dir_.get()); - MutableEntry parent_folder(&wt, CREATE, BOOKMARKS, wt.root_id(), "folder1"); + MutableEntry parent_folder(&wt, CREATE, wt.root_id(), "folder1"); parent_folder.Put(IS_UNSYNCED, true); EXPECT_TRUE(parent_folder.Put(IS_DIR, true)); - MutableEntry parent_folder2(&wt, CREATE, BOOKMARKS, wt.root_id(), "folder2"); + MutableEntry parent_folder2(&wt, CREATE, wt.root_id(), "folder2"); parent_folder2.Put(IS_UNSYNCED, true); EXPECT_TRUE(parent_folder2.Put(IS_DIR, true)); - MutableEntry child(&wt, CREATE, BOOKMARKS, parent_folder.Get(ID), child_name); + MutableEntry child(&wt, CREATE, parent_folder.Get(ID), child_name); EXPECT_TRUE(child.Put(IS_DIR, true)); child.Put(IS_UNSYNCED, true); @@ -1196,7 +1196,7 @@ TEST_F(SyncableDirectoryTest, TestNoReindexDeletedItems) { std::string new_name = "new_name"; WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); - MutableEntry folder(&trans, CREATE, BOOKMARKS, trans.root_id(), folder_name); + MutableEntry folder(&trans, CREATE, trans.root_id(), folder_name); ASSERT_TRUE(folder.good()); ASSERT_TRUE(folder.Put(IS_DIR, true)); ASSERT_TRUE(folder.Put(IS_DEL, true)); @@ -1214,7 +1214,7 @@ TEST_F(SyncableDirectoryTest, TestNoReindexDeletedItems) { TEST_F(SyncableDirectoryTest, TestCaseChangeRename) { WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); - MutableEntry folder(&trans, CREATE, BOOKMARKS, trans.root_id(), "CaseChange"); + MutableEntry folder(&trans, CREATE, trans.root_id(), "CaseChange"); ASSERT_TRUE(folder.good()); EXPECT_TRUE(folder.Put(PARENT_ID, trans.root_id())); EXPECT_TRUE(folder.Put(NON_UNIQUE_NAME, "CASECHANGE")); @@ -1240,7 +1240,7 @@ TEST_F(SyncableDirectoryTest, GetModelType) { WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); - MutableEntry folder(&trans, CREATE, BOOKMARKS, trans.root_id(), "Folder"); + MutableEntry folder(&trans, CREATE, trans.root_id(), "Folder"); ASSERT_TRUE(folder.good()); folder.Put(ID, id_factory.NewServerId()); folder.Put(SPECIFICS, specifics); @@ -1249,7 +1249,7 @@ TEST_F(SyncableDirectoryTest, GetModelType) { folder.Put(IS_DEL, false); ASSERT_EQ(datatype, folder.GetModelType()); - MutableEntry item(&trans, CREATE, BOOKMARKS, trans.root_id(), "Item"); + MutableEntry item(&trans, CREATE, trans.root_id(), "Item"); ASSERT_TRUE(item.good()); item.Put(ID, id_factory.NewServerId()); item.Put(SPECIFICS, specifics); @@ -1260,8 +1260,7 @@ TEST_F(SyncableDirectoryTest, GetModelType) { // It's critical that deletion records retain their datatype, so that // they can be dispatched to the appropriate change processor. - MutableEntry deleted_item( - &trans, CREATE, BOOKMARKS, trans.root_id(), "Deleted Item"); + MutableEntry deleted_item(&trans, CREATE, trans.root_id(), "Deleted Item"); ASSERT_TRUE(item.good()); deleted_item.Put(ID, id_factory.NewServerId()); deleted_item.Put(SPECIFICS, specifics); @@ -1316,11 +1315,11 @@ TEST_F(SyncableDirectoryTest, ChangeEntryIDAndUpdateChildren_ParentAndChild) { // Create two client-side items, a parent and child. WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); - MutableEntry parent(&trans, CREATE, BOOKMARKS, id_factory.root(), "parent"); + MutableEntry parent(&trans, CREATE, id_factory.root(), "parent"); parent.Put(IS_DIR, true); parent.Put(IS_UNSYNCED, true); - MutableEntry child(&trans, CREATE, BOOKMARKS, parent.Get(ID), "child"); + MutableEntry child(&trans, CREATE, parent.Get(ID), "child"); child.Put(IS_UNSYNCED, true); orig_parent_id = parent.Get(ID); @@ -1364,11 +1363,11 @@ TEST_F(SyncableDirectoryTest, // Create two client-side items, a parent and child. WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); - MutableEntry parent(&trans, CREATE, BOOKMARKS, id_factory.root(), "parent"); + MutableEntry parent(&trans, CREATE, id_factory.root(), "parent"); parent.Put(IS_DIR, true); parent.Put(IS_UNSYNCED, true); - MutableEntry child(&trans, CREATE, BOOKMARKS, parent.Get(ID), "child"); + MutableEntry child(&trans, CREATE, parent.Get(ID), "child"); child.Put(IS_UNSYNCED, true); orig_parent_id = parent.Get(ID); @@ -1447,7 +1446,7 @@ TEST_F(SyncableDirectoryTest, OldClientLeftUnsyncedDeletedLocalItem) { WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); // Create an uncommitted tombstone entry. - MutableEntry server_knows(&trans, CREATE, BOOKMARKS, id_factory.root(), + MutableEntry server_knows(&trans, CREATE, id_factory.root(), "server_knows"); server_knows.Put(ID, server_knows_id); server_knows.Put(IS_UNSYNCED, true); @@ -1456,8 +1455,7 @@ TEST_F(SyncableDirectoryTest, OldClientLeftUnsyncedDeletedLocalItem) { server_knows.Put(SERVER_VERSION, 4); // Create a valid update entry. - MutableEntry not_is_del( - &trans, CREATE, BOOKMARKS, id_factory.root(), "not_is_del"); + MutableEntry not_is_del(&trans, CREATE, id_factory.root(), "not_is_del"); not_is_del.Put(ID, not_is_del_id); not_is_del.Put(IS_DEL, false); not_is_del.Put(IS_UNSYNCED, true); @@ -1468,7 +1466,7 @@ TEST_F(SyncableDirectoryTest, OldClientLeftUnsyncedDeletedLocalItem) { // New clients should never put entries into this state. We work around // this by setting IS_DEL before setting IS_UNSYNCED, something which the // client should never do in practice. - MutableEntry zombie(&trans, CREATE, BOOKMARKS, id_factory.root(), "zombie"); + MutableEntry zombie(&trans, CREATE, id_factory.root(), "zombie"); zombie.Put(ID, zombie_id); zombie.Put(IS_DEL, true); zombie.Put(IS_UNSYNCED, true); @@ -1504,11 +1502,11 @@ TEST_F(SyncableDirectoryTest, OrdinalWithNullSurvivesSaveAndReload) { { WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); - MutableEntry parent(&trans, CREATE, BOOKMARKS, id_factory.root(), "parent"); + MutableEntry parent(&trans, CREATE, id_factory.root(), "parent"); parent.Put(IS_DIR, true); parent.Put(IS_UNSYNCED, true); - MutableEntry child(&trans, CREATE, BOOKMARKS, parent.Get(ID), "child"); + MutableEntry child(&trans, CREATE, parent.Get(ID), "child"); child.Put(IS_UNSYNCED, true); child.Put(SERVER_ORDINAL_IN_PARENT, null_ord); @@ -1692,8 +1690,9 @@ TEST_F(OnDiskSyncableDirectoryTest, TestPurgeEntriesWithTypeIn) { // Add more nodes for this type. Technically, they should be placed under // the proper type root nodes but the assertions in this test won't notice // if their parent isn't quite right. - MutableEntry item1(&trans, CREATE, BOOKMARKS, trans.root_id(), "Item"); + MutableEntry item1(&trans, CREATE, trans.root_id(), "Item"); ASSERT_TRUE(item1.good()); + item1.Put(SPECIFICS, bookmark_specs); item1.Put(SERVER_SPECIFICS, bookmark_specs); item1.Put(IS_UNSYNCED, true); @@ -1703,8 +1702,7 @@ TEST_F(OnDiskSyncableDirectoryTest, TestPurgeEntriesWithTypeIn) { item2.Put(SERVER_SPECIFICS, bookmark_specs); item2.Put(IS_UNAPPLIED_UPDATE, true); - MutableEntry item3(&trans, CREATE, PREFERENCES, - trans.root_id(), "Item"); + MutableEntry item3(&trans, CREATE, trans.root_id(), "Item"); ASSERT_TRUE(item3.good()); item3.Put(SPECIFICS, preference_specs); item3.Put(SERVER_SPECIFICS, preference_specs); @@ -1716,8 +1714,7 @@ TEST_F(OnDiskSyncableDirectoryTest, TestPurgeEntriesWithTypeIn) { item4.Put(SERVER_SPECIFICS, preference_specs); item4.Put(IS_UNAPPLIED_UPDATE, true); - MutableEntry item5(&trans, CREATE, AUTOFILL, - trans.root_id(), "Item"); + MutableEntry item5(&trans, CREATE, trans.root_id(), "Item"); ASSERT_TRUE(item5.good()); item5.Put(SPECIFICS, autofill_specs); item5.Put(SERVER_SPECIFICS, autofill_specs); @@ -1794,8 +1791,7 @@ TEST_F(OnDiskSyncableDirectoryTest, { WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); - MutableEntry create( - &trans, CREATE, BOOKMARKS, trans.root_id(), create_name); + MutableEntry create(&trans, CREATE, trans.root_id(), create_name); MutableEntry update(&trans, CREATE_NEW_UPDATE_ITEM, update_id); create.Put(IS_UNSYNCED, true); update.Put(IS_UNAPPLIED_UPDATE, true); @@ -1895,7 +1891,7 @@ TEST_F(OnDiskSyncableDirectoryTest, TestSaveChangesFailure) { { WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); - MutableEntry e1(&trans, CREATE, BOOKMARKS, trans.root_id(), "aguilera"); + MutableEntry e1(&trans, CREATE, trans.root_id(), "aguilera"); ASSERT_TRUE(e1.good()); EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); handle1 = e1.Get(META_HANDLE); @@ -1941,8 +1937,7 @@ TEST_F(OnDiskSyncableDirectoryTest, TestSaveChangesFailure) { EXPECT_TRUE(IsInDirtyMetahandles(handle1)); // New item. - MutableEntry kids_on_block( - &trans, CREATE, BOOKMARKS, trans.root_id(), "kids"); + MutableEntry kids_on_block(&trans, CREATE, trans.root_id(), "kids"); ASSERT_TRUE(kids_on_block.good()); handle2 = kids_on_block.Get(META_HANDLE); kids_on_block.Put(BASE_VERSION, 1); @@ -1977,7 +1972,7 @@ TEST_F(OnDiskSyncableDirectoryTest, TestSaveChangesFailureWithPurge) { { WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); - MutableEntry e1(&trans, CREATE, BOOKMARKS, trans.root_id(), "aguilera"); + MutableEntry e1(&trans, CREATE, trans.root_id(), "aguilera"); ASSERT_TRUE(e1.good()); EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); handle1 = e1.Get(META_HANDLE); @@ -2121,7 +2116,7 @@ class StressTransactionsDelegate : public base::PlatformThread::Delegate { base::StringPrintf("%d.%d", thread_number_, entry_count++); path_name.assign(unique_name.begin(), unique_name.end()); WriteTransaction trans(FROM_HERE, UNITTEST, dir_); - MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), path_name); + MutableEntry e(&trans, CREATE, trans.root_id(), path_name); CHECK(e.good()); base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( rand() % 20)); @@ -2178,9 +2173,13 @@ class SyncableClientTagTest : public SyncableDirectoryTest { SyncableClientTagTest() : test_name_("test_name"), test_tag_("dietcoke") {} bool CreateWithDefaultTag(Id id, bool deleted) { + return CreateWithTag(test_tag_, id, deleted); + } + + // Attempt to create an entry with a default tag. + bool CreateWithTag(const char* tag, Id id, bool deleted) { WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); - MutableEntry me(&wtrans, CREATE, PREFERENCES, - wtrans.root_id(), test_name_); + MutableEntry me(&wtrans, CREATE, wtrans.root_id(), test_name_); CHECK(me.good()); me.Put(ID, id); if (id.ServerKnows()) { @@ -2189,7 +2188,7 @@ class SyncableClientTagTest : public SyncableDirectoryTest { me.Put(IS_UNSYNCED, true); me.Put(IS_DEL, deleted); me.Put(IS_DIR, false); - return me.Put(UNIQUE_CLIENT_TAG, test_tag_); + return me.Put(UNIQUE_CLIENT_TAG, tag); } // Verify an entry exists with the default tag. diff --git a/sync/test/engine/test_syncable_utils.cc b/sync/test/engine/test_syncable_utils.cc index 389a16a..77be4c3 100644 --- a/sync/test/engine/test_syncable_utils.cc +++ b/sync/test/engine/test_syncable_utils.cc @@ -71,7 +71,6 @@ void CreateTypeRoot(WriteTransaction* trans, std::string tag_name = syncer::ModelTypeToRootTag(type); syncable::MutableEntry node(trans, syncable::CREATE, - type, TestIdFactory::root(), tag_name); DCHECK(node.good()); |