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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/engine/commit_util.cc ('k') | sync/protocol/sync.proto » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/engine/directory_commit_contribution.h" 5 #include "sync/engine/directory_commit_contribution.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "sync/sessions/status_controller.h" 8 #include "sync/sessions/status_controller.h"
9 #include "sync/syncable/entry.h" 9 #include "sync/syncable/entry.h"
10 #include "sync/syncable/mutable_entry.h" 10 #include "sync/syncable/mutable_entry.h"
11 #include "sync/syncable/syncable_read_transaction.h" 11 #include "sync/syncable/syncable_read_transaction.h"
12 #include "sync/syncable/syncable_write_transaction.h" 12 #include "sync/syncable/syncable_write_transaction.h"
13 #include "sync/test/engine/test_directory_setter_upper.h" 13 #include "sync/test/engine/test_directory_setter_upper.h"
14 #include "sync/test/engine/test_id_factory.h" 14 #include "sync/test/engine/test_id_factory.h"
15 #include "sync/test/engine/test_syncable_utils.h" 15 #include "sync/test/engine/test_syncable_utils.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace syncer { 18 namespace syncer {
19 19
20 class DirectoryCommitContributionTest : public ::testing::Test { 20 class DirectoryCommitContributionTest : public ::testing::Test {
21 public: 21 public:
22 virtual void SetUp() OVERRIDE { 22 virtual void SetUp() OVERRIDE {
23 dir_maker_.SetUp(); 23 dir_maker_.SetUp();
24 24
25 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); 25 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir());
26 CreateTypeRoot(&trans, dir(), PREFERENCES); 26 CreateTypeRoot(&trans, dir(), PREFERENCES);
27 CreateTypeRoot(&trans, dir(), EXTENSIONS); 27 CreateTypeRoot(&trans, dir(), EXTENSIONS);
28 CreateTypeRoot(&trans, dir(), BOOKMARKS);
28 } 29 }
29 30
30 virtual void TearDown() OVERRIDE { 31 virtual void TearDown() OVERRIDE {
31 dir_maker_.TearDown(); 32 dir_maker_.TearDown();
32 } 33 }
33 34
34 protected: 35 protected:
35 int64 CreateUnsyncedItem(syncable::WriteTransaction* trans, 36 int64 CreateUnsyncedItem(syncable::WriteTransaction* trans,
36 ModelType type, 37 ModelType type,
37 const std::string& tag) { 38 const std::string& tag) {
38 syncable::Entry parent_entry( 39 syncable::Entry parent_entry(
39 trans, 40 trans,
40 syncable::GET_BY_SERVER_TAG, 41 syncable::GET_BY_SERVER_TAG,
41 ModelTypeToRootTag(type)); 42 ModelTypeToRootTag(type));
42 syncable::MutableEntry entry( 43 syncable::MutableEntry entry(
43 trans, 44 trans,
44 syncable::CREATE, 45 syncable::CREATE,
45 type, 46 type,
46 parent_entry.GetId(), 47 parent_entry.GetId(),
47 tag); 48 tag);
48 entry.PutIsUnsynced(true); 49 entry.PutIsUnsynced(true);
49 return entry.GetMetahandle(); 50 return entry.GetMetahandle();
50 } 51 }
51 52
53 int64 CreateSyncedItem(syncable::WriteTransaction* trans,
54 ModelType type,
55 const std::string& tag) {
56 syncable::Entry parent_entry(
57 trans,
58 syncable::GET_BY_SERVER_TAG,
59 ModelTypeToRootTag(type));
60 syncable::MutableEntry entry(
61 trans,
62 syncable::CREATE,
63 type,
64 parent_entry.GetId(),
65 tag);
66
67 entry.PutId(syncable::Id::CreateFromServerId(
68 id_factory_.NewServerId().GetServerId()));
69 entry.PutBaseVersion(10);
70 entry.PutServerVersion(10);
71 entry.PutIsUnappliedUpdate(false);
72 entry.PutIsUnsynced(false);
73 entry.PutIsDel(false);
74 entry.PutServerIsDel(false);
75
76 return entry.GetMetahandle();
77 }
78
52 void CreateSuccessfulCommitResponse( 79 void CreateSuccessfulCommitResponse(
53 const sync_pb::SyncEntity& entity, 80 const sync_pb::SyncEntity& entity,
54 sync_pb::CommitResponse::EntryResponse* response) { 81 sync_pb::CommitResponse::EntryResponse* response) {
55 response->set_response_type(sync_pb::CommitResponse::SUCCESS); 82 response->set_response_type(sync_pb::CommitResponse::SUCCESS);
56 response->set_non_unique_name(entity.name()); 83 response->set_non_unique_name(entity.name());
57 response->set_version(entity.version() + 1); 84 response->set_version(entity.version() + 1);
58 response->set_parent_id_string(entity.parent_id_string()); 85 response->set_parent_id_string(entity.parent_id_string());
59 86
60 if (entity.id_string()[0] == '-') // Look for the - in 'c-1234' style IDs. 87 if (entity.id_string()[0] == '-') // Look for the - in 'c-1234' style IDs.
61 response->set_id_string(id_factory_.NewServerId().GetServerId()); 88 response->set_id_string(id_factory_.NewServerId().GetServerId());
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 syncable::Entry entry(&trans, syncable::GET_BY_ID, *it); 197 syncable::Entry entry(&trans, syncable::GET_BY_ID, *it);
171 ASSERT_TRUE(entry.good()); 198 ASSERT_TRUE(entry.good());
172 EXPECT_TRUE(entry.GetSyncing()); 199 EXPECT_TRUE(entry.GetSyncing());
173 } 200 }
174 } 201 }
175 202
176 pref_cc->CleanUp(); 203 pref_cc->CleanUp();
177 ext_cc->CleanUp(); 204 ext_cc->CleanUp();
178 } 205 }
179 206
207 // Check that deletion requests include a model type.
208 // This was not always the case, but was implemented to allow us to loosen some
209 // other restrictions in the protocol.
210 TEST_F(DirectoryCommitContributionTest, DeletedItemsWithSpecifics) {
211 int64 pref1;
212 {
213 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir());
214 pref1 = CreateSyncedItem(&trans, PREFERENCES, "pref1");
215 syncable::MutableEntry e1(&trans, syncable::GET_BY_HANDLE, pref1);
216 e1.PutIsDel(true);
217 e1.PutIsUnsynced(true);
218 }
219
220 DirectoryTypeDebugInfoEmitter emitter(PREFERENCES, &type_observers_);
221 scoped_ptr<DirectoryCommitContribution> pref_cc(
222 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25, &emitter));
223 ASSERT_TRUE(pref_cc);
224
225 sync_pb::ClientToServerMessage message;
226 pref_cc->AddToCommitMessage(&message);
227
228 const sync_pb::CommitMessage& commit_message = message.commit();
229 ASSERT_EQ(1, commit_message.entries_size());
230 EXPECT_TRUE(
231 commit_message.entries(0).specifics().has_preference());
232
233 pref_cc->CleanUp();
234 }
235
236 // As ususal, bookmarks are special. Bookmark deletion is special.
237 // Deleted bookmarks include a valid "is folder" bit and their full specifics
238 // (especially the meta info, which is what server really wants).
239 TEST_F(DirectoryCommitContributionTest, DeletedBookmarksWithSpecifics) {
240 int64 bm1;
241 {
242 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir());
243 bm1 = CreateSyncedItem(&trans, BOOKMARKS, "bm1");
244 syncable::MutableEntry e1(&trans, syncable::GET_BY_HANDLE, bm1);
245
246 e1.PutIsDir(true);
247 e1.PutServerIsDir(true);
248
249 sync_pb::EntitySpecifics specifics;
250 sync_pb::BookmarkSpecifics* bm_specifics = specifics.mutable_bookmark();
251 bm_specifics->set_url("http://www.chrome.com");
252 bm_specifics->set_title("Chrome");
253 sync_pb::MetaInfo* meta_info = bm_specifics->add_meta_info();
254 meta_info->set_key("K");
255 meta_info->set_value("V");
256 e1.PutSpecifics(specifics);
257
258 e1.PutIsDel(true);
259 e1.PutIsUnsynced(true);
260 }
261
262 DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_);
263 scoped_ptr<DirectoryCommitContribution> bm_cc(
264 DirectoryCommitContribution::Build(dir(), BOOKMARKS, 25, &emitter));
265 ASSERT_TRUE(bm_cc);
266
267 sync_pb::ClientToServerMessage message;
268 bm_cc->AddToCommitMessage(&message);
269
270 const sync_pb::CommitMessage& commit_message = message.commit();
271 ASSERT_EQ(1, commit_message.entries_size());
272
273 const sync_pb::SyncEntity& entity = commit_message.entries(0);
274 EXPECT_TRUE(entity.has_folder());
275 ASSERT_TRUE(entity.specifics().has_bookmark());
276 ASSERT_EQ(1, entity.specifics().bookmark().meta_info_size());
277 EXPECT_EQ("K", entity.specifics().bookmark().meta_info(0).key());
278 EXPECT_EQ("V", entity.specifics().bookmark().meta_info(0).value());
279
280 bm_cc->CleanUp();
281 }
282
180 // Creates some unsynced items, pretends to commit them, and hands back a 283 // Creates some unsynced items, pretends to commit them, and hands back a
181 // specially crafted response to the syncer in order to test commit response 284 // specially crafted response to the syncer in order to test commit response
182 // processing. The response simulates a succesful commit scenario. 285 // processing. The response simulates a succesful commit scenario.
183 TEST_F(DirectoryCommitContributionTest, ProcessCommitResponse) { 286 TEST_F(DirectoryCommitContributionTest, ProcessCommitResponse) {
184 int64 pref1_handle; 287 int64 pref1_handle;
185 int64 pref2_handle; 288 int64 pref2_handle;
186 int64 ext1_handle; 289 int64 ext1_handle;
187 { 290 {
188 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); 291 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir());
189 pref1_handle = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); 292 pref1_handle = CreateUnsyncedItem(&trans, PREFERENCES, "pref1");
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 EXPECT_TRUE(e1.GetId().ServerKnows()); 338 EXPECT_TRUE(e1.GetId().ServerKnows());
236 EXPECT_FALSE(e1.GetSyncing()); 339 EXPECT_FALSE(e1.GetSyncing());
237 EXPECT_LT(0, e1.GetServerVersion()); 340 EXPECT_LT(0, e1.GetServerVersion());
238 } 341 }
239 342
240 pref_cc->CleanUp(); 343 pref_cc->CleanUp();
241 ext_cc->CleanUp(); 344 ext_cc->CleanUp();
242 } 345 }
243 346
244 } // namespace syncer 347 } // namespace syncer
OLDNEW
« 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