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

Unified Diff: sync/engine/directory_commit_contribution_unittest.cc

Issue 298503002: sync: Enable typed tombstones commits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add tests for AddDefaultFieldValues Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/engine/commit_util.cc ('k') | sync/protocol/sync.proto » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/engine/directory_commit_contribution_unittest.cc
diff --git a/sync/engine/directory_commit_contribution_unittest.cc b/sync/engine/directory_commit_contribution_unittest.cc
index c38af195fcd7895952120d9a0d9038bfb8183235..475985c2569ba0055dc5771dca0965ec7d484688 100644
--- a/sync/engine/directory_commit_contribution_unittest.cc
+++ b/sync/engine/directory_commit_contribution_unittest.cc
@@ -25,6 +25,7 @@ class DirectoryCommitContributionTest : public ::testing::Test {
syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir());
CreateTypeRoot(&trans, dir(), PREFERENCES);
CreateTypeRoot(&trans, dir(), EXTENSIONS);
+ CreateTypeRoot(&trans, dir(), BOOKMARKS);
}
virtual void TearDown() OVERRIDE {
@@ -49,6 +50,32 @@ class DirectoryCommitContributionTest : public ::testing::Test {
return entry.GetMetahandle();
}
+ int64 CreateSyncedItem(syncable::WriteTransaction* trans,
+ ModelType type,
+ const std::string& tag) {
+ syncable::Entry parent_entry(
+ trans,
+ syncable::GET_BY_SERVER_TAG,
+ ModelTypeToRootTag(type));
+ syncable::MutableEntry entry(
+ trans,
+ syncable::CREATE,
+ type,
+ parent_entry.GetId(),
+ tag);
+
+ entry.PutId(syncable::Id::CreateFromServerId(
+ id_factory_.NewServerId().GetServerId()));
+ entry.PutBaseVersion(10);
+ entry.PutServerVersion(10);
+ entry.PutIsUnappliedUpdate(false);
+ entry.PutIsUnsynced(false);
+ entry.PutIsDel(false);
+ entry.PutServerIsDel(false);
+
+ return entry.GetMetahandle();
+ }
+
void CreateSuccessfulCommitResponse(
const sync_pb::SyncEntity& entity,
sync_pb::CommitResponse::EntryResponse* response) {
@@ -177,6 +204,82 @@ TEST_F(DirectoryCommitContributionTest, PrepareCommit) {
ext_cc->CleanUp();
}
+// Check that deletion requests include a model type.
+// This was not always the case, but was implemented to allow us to loosen some
+// other restrictions in the protocol.
+TEST_F(DirectoryCommitContributionTest, DeletedItemsWithSpecifics) {
+ int64 pref1;
+ {
+ syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir());
+ pref1 = CreateSyncedItem(&trans, PREFERENCES, "pref1");
+ syncable::MutableEntry e1(&trans, syncable::GET_BY_HANDLE, pref1);
+ e1.PutIsDel(true);
+ e1.PutIsUnsynced(true);
+ }
+
+ DirectoryTypeDebugInfoEmitter emitter(PREFERENCES, &type_observers_);
+ scoped_ptr<DirectoryCommitContribution> pref_cc(
+ DirectoryCommitContribution::Build(dir(), PREFERENCES, 25, &emitter));
+ ASSERT_TRUE(pref_cc);
+
+ sync_pb::ClientToServerMessage message;
+ pref_cc->AddToCommitMessage(&message);
+
+ const sync_pb::CommitMessage& commit_message = message.commit();
+ ASSERT_EQ(1, commit_message.entries_size());
+ EXPECT_TRUE(
+ commit_message.entries(0).specifics().has_preference());
+
+ pref_cc->CleanUp();
+}
+
+// As ususal, bookmarks are special. Bookmark deletion is special.
+// Deleted bookmarks include a valid "is folder" bit and their full specifics
+// (especially the meta info, which is what server really wants).
+TEST_F(DirectoryCommitContributionTest, DeletedBookmarksWithSpecifics) {
+ int64 bm1;
+ {
+ syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir());
+ bm1 = CreateSyncedItem(&trans, BOOKMARKS, "bm1");
+ syncable::MutableEntry e1(&trans, syncable::GET_BY_HANDLE, bm1);
+
+ e1.PutIsDir(true);
+ e1.PutServerIsDir(true);
+
+ sync_pb::EntitySpecifics specifics;
+ sync_pb::BookmarkSpecifics* bm_specifics = specifics.mutable_bookmark();
+ bm_specifics->set_url("http://www.chrome.com");
+ bm_specifics->set_title("Chrome");
+ sync_pb::MetaInfo* meta_info = bm_specifics->add_meta_info();
+ meta_info->set_key("K");
+ meta_info->set_value("V");
+ e1.PutSpecifics(specifics);
+
+ e1.PutIsDel(true);
+ e1.PutIsUnsynced(true);
+ }
+
+ DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_);
+ scoped_ptr<DirectoryCommitContribution> bm_cc(
+ DirectoryCommitContribution::Build(dir(), BOOKMARKS, 25, &emitter));
+ ASSERT_TRUE(bm_cc);
+
+ sync_pb::ClientToServerMessage message;
+ bm_cc->AddToCommitMessage(&message);
+
+ const sync_pb::CommitMessage& commit_message = message.commit();
+ ASSERT_EQ(1, commit_message.entries_size());
+
+ const sync_pb::SyncEntity& entity = commit_message.entries(0);
+ EXPECT_TRUE(entity.has_folder());
+ ASSERT_TRUE(entity.specifics().has_bookmark());
+ ASSERT_EQ(1, entity.specifics().bookmark().meta_info_size());
+ EXPECT_EQ("K", entity.specifics().bookmark().meta_info(0).key());
+ EXPECT_EQ("V", entity.specifics().bookmark().meta_info(0).value());
+
+ bm_cc->CleanUp();
+}
+
// Creates some unsynced items, pretends to commit them, and hands back a
// specially crafted response to the syncer in order to test commit response
// processing. The response simulates a succesful commit scenario.
« no previous file with comments | « sync/engine/commit_util.cc ('k') | sync/protocol/sync.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698