OLD | NEW |
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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 TEST_F(DirectoryCommitContributionTest, GatherByTypes) { | 122 TEST_F(DirectoryCommitContributionTest, GatherByTypes) { |
123 int64_t pref1; | 123 int64_t pref1; |
124 { | 124 { |
125 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); | 125 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); |
126 pref1 = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); | 126 pref1 = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); |
127 CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); | 127 CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); |
128 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); | 128 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); |
129 } | 129 } |
130 | 130 |
131 DirectoryTypeDebugInfoEmitter emitter(PREFERENCES, &type_observers_); | 131 DirectoryTypeDebugInfoEmitter emitter(PREFERENCES, &type_observers_); |
132 scoped_ptr<DirectoryCommitContribution> cc( | 132 std::unique_ptr<DirectoryCommitContribution> cc( |
133 DirectoryCommitContribution::Build(dir(), PREFERENCES, 5, &emitter)); | 133 DirectoryCommitContribution::Build(dir(), PREFERENCES, 5, &emitter)); |
134 ASSERT_EQ(2U, cc->GetNumEntries()); | 134 ASSERT_EQ(2U, cc->GetNumEntries()); |
135 | 135 |
136 const std::vector<int64_t>& metahandles = cc->metahandles_; | 136 const std::vector<int64_t>& metahandles = cc->metahandles_; |
137 EXPECT_TRUE(std::find(metahandles.begin(), metahandles.end(), pref1) != | 137 EXPECT_TRUE(std::find(metahandles.begin(), metahandles.end(), pref1) != |
138 metahandles.end()); | 138 metahandles.end()); |
139 EXPECT_TRUE(std::find(metahandles.begin(), metahandles.end(), pref1) != | 139 EXPECT_TRUE(std::find(metahandles.begin(), metahandles.end(), pref1) != |
140 metahandles.end()); | 140 metahandles.end()); |
141 | 141 |
142 cc->CleanUp(); | 142 cc->CleanUp(); |
143 } | 143 } |
144 | 144 |
145 // Verify that the DirectoryCommitContributionTest builder function | 145 // Verify that the DirectoryCommitContributionTest builder function |
146 // truncates if necessary. | 146 // truncates if necessary. |
147 TEST_F(DirectoryCommitContributionTest, GatherAndTruncate) { | 147 TEST_F(DirectoryCommitContributionTest, GatherAndTruncate) { |
148 int64_t pref1; | 148 int64_t pref1; |
149 int64_t pref2; | 149 int64_t pref2; |
150 { | 150 { |
151 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); | 151 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); |
152 pref1 = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); | 152 pref1 = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); |
153 pref2 = CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); | 153 pref2 = CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); |
154 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); | 154 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); |
155 } | 155 } |
156 | 156 |
157 DirectoryTypeDebugInfoEmitter emitter(PREFERENCES, &type_observers_); | 157 DirectoryTypeDebugInfoEmitter emitter(PREFERENCES, &type_observers_); |
158 scoped_ptr<DirectoryCommitContribution> cc( | 158 std::unique_ptr<DirectoryCommitContribution> cc( |
159 DirectoryCommitContribution::Build(dir(), PREFERENCES, 1, &emitter)); | 159 DirectoryCommitContribution::Build(dir(), PREFERENCES, 1, &emitter)); |
160 ASSERT_EQ(1U, cc->GetNumEntries()); | 160 ASSERT_EQ(1U, cc->GetNumEntries()); |
161 | 161 |
162 int64_t only_metahandle = cc->metahandles_[0]; | 162 int64_t only_metahandle = cc->metahandles_[0]; |
163 EXPECT_TRUE(only_metahandle == pref1 || only_metahandle == pref2); | 163 EXPECT_TRUE(only_metahandle == pref1 || only_metahandle == pref2); |
164 | 164 |
165 cc->CleanUp(); | 165 cc->CleanUp(); |
166 } | 166 } |
167 | 167 |
168 // Sanity check for building commits from DirectoryCommitContributions. | 168 // Sanity check for building commits from DirectoryCommitContributions. |
169 // This test makes two CommitContribution objects of different types and uses | 169 // This test makes two CommitContribution objects of different types and uses |
170 // them to initialize a commit message. Then it checks that the contents of the | 170 // them to initialize a commit message. Then it checks that the contents of the |
171 // commit message match those of the directory they came from. | 171 // commit message match those of the directory they came from. |
172 TEST_F(DirectoryCommitContributionTest, PrepareCommit) { | 172 TEST_F(DirectoryCommitContributionTest, PrepareCommit) { |
173 { | 173 { |
174 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); | 174 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); |
175 CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); | 175 CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); |
176 CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); | 176 CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); |
177 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); | 177 CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); |
178 } | 178 } |
179 | 179 |
180 DirectoryTypeDebugInfoEmitter emitter1(PREFERENCES, &type_observers_); | 180 DirectoryTypeDebugInfoEmitter emitter1(PREFERENCES, &type_observers_); |
181 DirectoryTypeDebugInfoEmitter emitter2(EXTENSIONS, &type_observers_); | 181 DirectoryTypeDebugInfoEmitter emitter2(EXTENSIONS, &type_observers_); |
182 scoped_ptr<DirectoryCommitContribution> pref_cc( | 182 std::unique_ptr<DirectoryCommitContribution> pref_cc( |
183 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25, &emitter1)); | 183 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25, &emitter1)); |
184 scoped_ptr<DirectoryCommitContribution> ext_cc( | 184 std::unique_ptr<DirectoryCommitContribution> ext_cc( |
185 DirectoryCommitContribution::Build(dir(), EXTENSIONS, 25, &emitter2)); | 185 DirectoryCommitContribution::Build(dir(), EXTENSIONS, 25, &emitter2)); |
186 | 186 |
187 sync_pb::ClientToServerMessage message; | 187 sync_pb::ClientToServerMessage message; |
188 pref_cc->AddToCommitMessage(&message); | 188 pref_cc->AddToCommitMessage(&message); |
189 ext_cc->AddToCommitMessage(&message); | 189 ext_cc->AddToCommitMessage(&message); |
190 | 190 |
191 const sync_pb::CommitMessage& commit_message = message.commit(); | 191 const sync_pb::CommitMessage& commit_message = message.commit(); |
192 | 192 |
193 std::set<syncable::Id> ids_for_commit; | 193 std::set<syncable::Id> ids_for_commit; |
194 ASSERT_EQ(3, commit_message.entries_size()); | 194 ASSERT_EQ(3, commit_message.entries_size()); |
(...skipping 30 matching lines...) Expand all Loading... |
225 int64_t pref1; | 225 int64_t pref1; |
226 { | 226 { |
227 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); | 227 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); |
228 pref1 = CreateSyncedItem(&trans, PREFERENCES, "pref1"); | 228 pref1 = CreateSyncedItem(&trans, PREFERENCES, "pref1"); |
229 syncable::MutableEntry e1(&trans, syncable::GET_BY_HANDLE, pref1); | 229 syncable::MutableEntry e1(&trans, syncable::GET_BY_HANDLE, pref1); |
230 e1.PutIsDel(true); | 230 e1.PutIsDel(true); |
231 e1.PutIsUnsynced(true); | 231 e1.PutIsUnsynced(true); |
232 } | 232 } |
233 | 233 |
234 DirectoryTypeDebugInfoEmitter emitter(PREFERENCES, &type_observers_); | 234 DirectoryTypeDebugInfoEmitter emitter(PREFERENCES, &type_observers_); |
235 scoped_ptr<DirectoryCommitContribution> pref_cc( | 235 std::unique_ptr<DirectoryCommitContribution> pref_cc( |
236 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25, &emitter)); | 236 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25, &emitter)); |
237 ASSERT_TRUE(pref_cc); | 237 ASSERT_TRUE(pref_cc); |
238 | 238 |
239 sync_pb::ClientToServerMessage message; | 239 sync_pb::ClientToServerMessage message; |
240 pref_cc->AddToCommitMessage(&message); | 240 pref_cc->AddToCommitMessage(&message); |
241 | 241 |
242 const sync_pb::CommitMessage& commit_message = message.commit(); | 242 const sync_pb::CommitMessage& commit_message = message.commit(); |
243 ASSERT_EQ(1, commit_message.entries_size()); | 243 ASSERT_EQ(1, commit_message.entries_size()); |
244 EXPECT_TRUE( | 244 EXPECT_TRUE( |
245 commit_message.entries(0).specifics().has_preference()); | 245 commit_message.entries(0).specifics().has_preference()); |
(...skipping 21 matching lines...) Expand all Loading... |
267 sync_pb::MetaInfo* meta_info = bm_specifics->add_meta_info(); | 267 sync_pb::MetaInfo* meta_info = bm_specifics->add_meta_info(); |
268 meta_info->set_key("K"); | 268 meta_info->set_key("K"); |
269 meta_info->set_value("V"); | 269 meta_info->set_value("V"); |
270 e1.PutSpecifics(specifics); | 270 e1.PutSpecifics(specifics); |
271 | 271 |
272 e1.PutIsDel(true); | 272 e1.PutIsDel(true); |
273 e1.PutIsUnsynced(true); | 273 e1.PutIsUnsynced(true); |
274 } | 274 } |
275 | 275 |
276 DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_); | 276 DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_); |
277 scoped_ptr<DirectoryCommitContribution> bm_cc( | 277 std::unique_ptr<DirectoryCommitContribution> bm_cc( |
278 DirectoryCommitContribution::Build(dir(), BOOKMARKS, 25, &emitter)); | 278 DirectoryCommitContribution::Build(dir(), BOOKMARKS, 25, &emitter)); |
279 ASSERT_TRUE(bm_cc); | 279 ASSERT_TRUE(bm_cc); |
280 | 280 |
281 sync_pb::ClientToServerMessage message; | 281 sync_pb::ClientToServerMessage message; |
282 bm_cc->AddToCommitMessage(&message); | 282 bm_cc->AddToCommitMessage(&message); |
283 | 283 |
284 const sync_pb::CommitMessage& commit_message = message.commit(); | 284 const sync_pb::CommitMessage& commit_message = message.commit(); |
285 ASSERT_EQ(1, commit_message.entries_size()); | 285 ASSERT_EQ(1, commit_message.entries_size()); |
286 | 286 |
287 const sync_pb::SyncEntity& entity = commit_message.entries(0); | 287 const sync_pb::SyncEntity& entity = commit_message.entries(0); |
(...skipping 21 matching lines...) Expand all Loading... |
309 bm_specifics->set_title("Chrome"); | 309 bm_specifics->set_title("Chrome"); |
310 e.PutSpecifics(specifics); | 310 e.PutSpecifics(specifics); |
311 | 311 |
312 e.PutIsDel(false); | 312 e.PutIsDel(false); |
313 e.PutIsUnsynced(true); | 313 e.PutIsUnsynced(true); |
314 | 314 |
315 EXPECT_TRUE(e.ShouldMaintainHierarchy()); | 315 EXPECT_TRUE(e.ShouldMaintainHierarchy()); |
316 } | 316 } |
317 | 317 |
318 DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_); | 318 DirectoryTypeDebugInfoEmitter emitter(BOOKMARKS, &type_observers_); |
319 scoped_ptr<DirectoryCommitContribution> bm_cc( | 319 std::unique_ptr<DirectoryCommitContribution> bm_cc( |
320 DirectoryCommitContribution::Build(dir(), BOOKMARKS, 25, &emitter)); | 320 DirectoryCommitContribution::Build(dir(), BOOKMARKS, 25, &emitter)); |
321 | 321 |
322 sync_pb::ClientToServerMessage message; | 322 sync_pb::ClientToServerMessage message; |
323 bm_cc->AddToCommitMessage(&message); | 323 bm_cc->AddToCommitMessage(&message); |
324 const sync_pb::CommitMessage& commit_message = message.commit(); | 324 const sync_pb::CommitMessage& commit_message = message.commit(); |
325 bm_cc->CleanUp(); | 325 bm_cc->CleanUp(); |
326 | 326 |
327 ASSERT_EQ(1, commit_message.entries_size()); | 327 ASSERT_EQ(1, commit_message.entries_size()); |
328 EXPECT_TRUE(commit_message.entries(0).has_parent_id_string()); | 328 EXPECT_TRUE(commit_message.entries(0).has_parent_id_string()); |
329 EXPECT_FALSE(commit_message.entries(0).parent_id_string().empty()); | 329 EXPECT_FALSE(commit_message.entries(0).parent_id_string().empty()); |
330 } | 330 } |
331 | 331 |
332 // Test that preferences do not support hierarchy. | 332 // Test that preferences do not support hierarchy. |
333 TEST_F(DirectoryCommitContributionTest, HierarchySupport_Preferences) { | 333 TEST_F(DirectoryCommitContributionTest, HierarchySupport_Preferences) { |
334 // Create a normal-looking prefs item. | 334 // Create a normal-looking prefs item. |
335 int64_t pref1; | 335 int64_t pref1; |
336 { | 336 { |
337 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); | 337 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); |
338 pref1 = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); | 338 pref1 = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); |
339 syncable::MutableEntry e(&trans, syncable::GET_BY_HANDLE, pref1); | 339 syncable::MutableEntry e(&trans, syncable::GET_BY_HANDLE, pref1); |
340 | 340 |
341 EXPECT_FALSE(e.ShouldMaintainHierarchy()); | 341 EXPECT_FALSE(e.ShouldMaintainHierarchy()); |
342 } | 342 } |
343 | 343 |
344 DirectoryTypeDebugInfoEmitter emitter(PREFERENCES, &type_observers_); | 344 DirectoryTypeDebugInfoEmitter emitter(PREFERENCES, &type_observers_); |
345 scoped_ptr<DirectoryCommitContribution> pref_cc( | 345 std::unique_ptr<DirectoryCommitContribution> pref_cc( |
346 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25, &emitter)); | 346 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25, &emitter)); |
347 | 347 |
348 sync_pb::ClientToServerMessage message; | 348 sync_pb::ClientToServerMessage message; |
349 pref_cc->AddToCommitMessage(&message); | 349 pref_cc->AddToCommitMessage(&message); |
350 const sync_pb::CommitMessage& commit_message = message.commit(); | 350 const sync_pb::CommitMessage& commit_message = message.commit(); |
351 pref_cc->CleanUp(); | 351 pref_cc->CleanUp(); |
352 | 352 |
353 ASSERT_EQ(1, commit_message.entries_size()); | 353 ASSERT_EQ(1, commit_message.entries_size()); |
354 EXPECT_FALSE(commit_message.entries(0).has_parent_id_string()); | 354 EXPECT_FALSE(commit_message.entries(0).has_parent_id_string()); |
355 EXPECT_TRUE(commit_message.entries(0).parent_id_string().empty()); | 355 EXPECT_TRUE(commit_message.entries(0).parent_id_string().empty()); |
(...skipping 15 matching lines...) Expand all Loading... |
371 int64_t ext1_handle; | 371 int64_t ext1_handle; |
372 { | 372 { |
373 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); | 373 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, dir()); |
374 pref1_handle = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); | 374 pref1_handle = CreateUnsyncedItem(&trans, PREFERENCES, "pref1"); |
375 pref2_handle = CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); | 375 pref2_handle = CreateUnsyncedItem(&trans, PREFERENCES, "pref2"); |
376 ext1_handle = CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); | 376 ext1_handle = CreateUnsyncedItem(&trans, EXTENSIONS, "extension1"); |
377 } | 377 } |
378 | 378 |
379 DirectoryTypeDebugInfoEmitter emitter1(PREFERENCES, &type_observers_); | 379 DirectoryTypeDebugInfoEmitter emitter1(PREFERENCES, &type_observers_); |
380 DirectoryTypeDebugInfoEmitter emitter2(EXTENSIONS, &type_observers_); | 380 DirectoryTypeDebugInfoEmitter emitter2(EXTENSIONS, &type_observers_); |
381 scoped_ptr<DirectoryCommitContribution> pref_cc( | 381 std::unique_ptr<DirectoryCommitContribution> pref_cc( |
382 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25, &emitter1)); | 382 DirectoryCommitContribution::Build(dir(), PREFERENCES, 25, &emitter1)); |
383 scoped_ptr<DirectoryCommitContribution> ext_cc( | 383 std::unique_ptr<DirectoryCommitContribution> ext_cc( |
384 DirectoryCommitContribution::Build(dir(), EXTENSIONS, 25, &emitter2)); | 384 DirectoryCommitContribution::Build(dir(), EXTENSIONS, 25, &emitter2)); |
385 | 385 |
386 sync_pb::ClientToServerMessage message; | 386 sync_pb::ClientToServerMessage message; |
387 pref_cc->AddToCommitMessage(&message); | 387 pref_cc->AddToCommitMessage(&message); |
388 ext_cc->AddToCommitMessage(&message); | 388 ext_cc->AddToCommitMessage(&message); |
389 | 389 |
390 const sync_pb::CommitMessage& commit_message = message.commit(); | 390 const sync_pb::CommitMessage& commit_message = message.commit(); |
391 ASSERT_EQ(3, commit_message.entries_size()); | 391 ASSERT_EQ(3, commit_message.entries_size()); |
392 | 392 |
393 sync_pb::ClientToServerResponse response; | 393 sync_pb::ClientToServerResponse response; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 // art3 has two attachments, neither of which have been uploaded to the | 458 // art3 has two attachments, neither of which have been uploaded to the |
459 // server. art2 is not eligible to be committed. | 459 // server. art2 is not eligible to be committed. |
460 sync_pb::AttachmentMetadata art3_attachments; | 460 sync_pb::AttachmentMetadata art3_attachments; |
461 AddAttachment(&art3_attachments, false /* is_on_server */); | 461 AddAttachment(&art3_attachments, false /* is_on_server */); |
462 AddAttachment(&art3_attachments, false /* is_on_server */); | 462 AddAttachment(&art3_attachments, false /* is_on_server */); |
463 art3_handle = CreateUnsyncedItemWithAttachments( | 463 art3_handle = CreateUnsyncedItemWithAttachments( |
464 &trans, ARTICLES, "art3", art3_attachments); | 464 &trans, ARTICLES, "art3", art3_attachments); |
465 } | 465 } |
466 | 466 |
467 DirectoryTypeDebugInfoEmitter emitter(ARTICLES, &type_observers_); | 467 DirectoryTypeDebugInfoEmitter emitter(ARTICLES, &type_observers_); |
468 scoped_ptr<DirectoryCommitContribution> art_cc( | 468 std::unique_ptr<DirectoryCommitContribution> art_cc( |
469 DirectoryCommitContribution::Build(dir(), ARTICLES, 25, &emitter)); | 469 DirectoryCommitContribution::Build(dir(), ARTICLES, 25, &emitter)); |
470 | 470 |
471 // Only art1 is ready. | 471 // Only art1 is ready. |
472 EXPECT_EQ(1U, art_cc->GetNumEntries()); | 472 EXPECT_EQ(1U, art_cc->GetNumEntries()); |
473 | 473 |
474 sync_pb::ClientToServerMessage message; | 474 sync_pb::ClientToServerMessage message; |
475 art_cc->AddToCommitMessage(&message); | 475 art_cc->AddToCommitMessage(&message); |
476 | 476 |
477 const sync_pb::CommitMessage& commit_message = message.commit(); | 477 const sync_pb::CommitMessage& commit_message = message.commit(); |
478 ASSERT_EQ(1, commit_message.entries_size()); | 478 ASSERT_EQ(1, commit_message.entries_size()); |
(...skipping 27 matching lines...) Expand all Loading... |
506 EXPECT_FALSE(a3.GetId().ServerKnows()); | 506 EXPECT_FALSE(a3.GetId().ServerKnows()); |
507 EXPECT_FALSE(a3.GetSyncing()); | 507 EXPECT_FALSE(a3.GetSyncing()); |
508 EXPECT_FALSE(a3.GetDirtySync()); | 508 EXPECT_FALSE(a3.GetDirtySync()); |
509 EXPECT_EQ(0, a3.GetServerVersion()); | 509 EXPECT_EQ(0, a3.GetServerVersion()); |
510 } | 510 } |
511 | 511 |
512 art_cc->CleanUp(); | 512 art_cc->CleanUp(); |
513 } | 513 } |
514 | 514 |
515 } // namespace syncer | 515 } // namespace syncer |
OLD | NEW |