| 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/syncable/directory_unittest.h" | 5 #include "sync/syncable/directory_unittest.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
| 7 #include <cstdlib> | 10 #include <cstdlib> |
| 8 | 11 |
| 12 #include "base/macros.h" |
| 9 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 10 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 11 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 12 #include "base/test/values_test_util.h" | 16 #include "base/test/values_test_util.h" |
| 13 #include "sync/internal_api/public/base/attachment_id_proto.h" | 17 #include "sync/internal_api/public/base/attachment_id_proto.h" |
| 14 #include "sync/syncable/syncable_proto_util.h" | 18 #include "sync/syncable/syncable_proto_util.h" |
| 15 #include "sync/syncable/syncable_util.h" | 19 #include "sync/syncable/syncable_util.h" |
| 16 #include "sync/syncable/syncable_write_transaction.h" | 20 #include "sync/syncable/syncable_write_transaction.h" |
| 17 #include "sync/test/engine/test_syncable_utils.h" | 21 #include "sync/test/engine/test_syncable_utils.h" |
| 18 #include "sync/test/test_directory_backing_store.h" | 22 #include "sync/test/test_directory_backing_store.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 185 |
| 182 ReadTransaction trans(FROM_HERE, dir_.get()); | 186 ReadTransaction trans(FROM_HERE, dir_.get()); |
| 183 sync_pb::DataTypeContext context; | 187 sync_pb::DataTypeContext context; |
| 184 dir_->GetDataTypeContext(&trans, it.Get(), &context); | 188 dir_->GetDataTypeContext(&trans, it.Get(), &context); |
| 185 EXPECT_TRUE(context.SerializeAsString().empty()); | 189 EXPECT_TRUE(context.SerializeAsString().empty()); |
| 186 } | 190 } |
| 187 EXPECT_FALSE(types_to_purge.Has(BOOKMARKS)); | 191 EXPECT_FALSE(types_to_purge.Has(BOOKMARKS)); |
| 188 EXPECT_TRUE(dir_->InitialSyncEndedForType(BOOKMARKS)); | 192 EXPECT_TRUE(dir_->InitialSyncEndedForType(BOOKMARKS)); |
| 189 } | 193 } |
| 190 | 194 |
| 191 bool SyncableDirectoryTest::IsInDirtyMetahandles(int64 metahandle) { | 195 bool SyncableDirectoryTest::IsInDirtyMetahandles(int64_t metahandle) { |
| 192 return 1 == dir_->kernel()->dirty_metahandles.count(metahandle); | 196 return 1 == dir_->kernel()->dirty_metahandles.count(metahandle); |
| 193 } | 197 } |
| 194 | 198 |
| 195 bool SyncableDirectoryTest::IsInMetahandlesToPurge(int64 metahandle) { | 199 bool SyncableDirectoryTest::IsInMetahandlesToPurge(int64_t metahandle) { |
| 196 return 1 == dir_->kernel()->metahandles_to_purge.count(metahandle); | 200 return 1 == dir_->kernel()->metahandles_to_purge.count(metahandle); |
| 197 } | 201 } |
| 198 | 202 |
| 199 scoped_ptr<Directory>& SyncableDirectoryTest::dir() { | 203 scoped_ptr<Directory>& SyncableDirectoryTest::dir() { |
| 200 return dir_; | 204 return dir_; |
| 201 } | 205 } |
| 202 | 206 |
| 203 DirectoryChangeDelegate* SyncableDirectoryTest::directory_change_delegate() { | 207 DirectoryChangeDelegate* SyncableDirectoryTest::directory_change_delegate() { |
| 204 return &delegate_; | 208 return &delegate_; |
| 205 } | 209 } |
| 206 | 210 |
| 207 Encryptor* SyncableDirectoryTest::encryptor() { | 211 Encryptor* SyncableDirectoryTest::encryptor() { |
| 208 return &encryptor_; | 212 return &encryptor_; |
| 209 } | 213 } |
| 210 | 214 |
| 211 | 215 |
| 212 TestUnrecoverableErrorHandler* | 216 TestUnrecoverableErrorHandler* |
| 213 SyncableDirectoryTest::unrecoverable_error_handler() { | 217 SyncableDirectoryTest::unrecoverable_error_handler() { |
| 214 return &handler_; | 218 return &handler_; |
| 215 } | 219 } |
| 216 | 220 |
| 217 void SyncableDirectoryTest::ValidateEntry(BaseTransaction* trans, | 221 void SyncableDirectoryTest::ValidateEntry(BaseTransaction* trans, |
| 218 int64 id, | 222 int64_t id, |
| 219 bool check_name, | 223 bool check_name, |
| 220 const std::string& name, | 224 const std::string& name, |
| 221 int64 base_version, | 225 int64_t base_version, |
| 222 int64 server_version, | 226 int64_t server_version, |
| 223 bool is_del) { | 227 bool is_del) { |
| 224 Entry e(trans, GET_BY_ID, TestIdFactory::FromNumber(id)); | 228 Entry e(trans, GET_BY_ID, TestIdFactory::FromNumber(id)); |
| 225 ASSERT_TRUE(e.good()); | 229 ASSERT_TRUE(e.good()); |
| 226 if (check_name) | 230 if (check_name) |
| 227 ASSERT_TRUE(name == e.GetNonUniqueName()); | 231 ASSERT_TRUE(name == e.GetNonUniqueName()); |
| 228 ASSERT_TRUE(base_version == e.GetBaseVersion()); | 232 ASSERT_TRUE(base_version == e.GetBaseVersion()); |
| 229 ASSERT_TRUE(server_version == e.GetServerVersion()); | 233 ASSERT_TRUE(server_version == e.GetServerVersion()); |
| 230 ASSERT_TRUE(is_del == e.GetIsDel()); | 234 ASSERT_TRUE(is_del == e.GetIsDel()); |
| 231 } | 235 } |
| 232 | 236 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 273 |
| 270 dir()->HandleSaveChangesFailure(snapshot1); | 274 dir()->HandleSaveChangesFailure(snapshot1); |
| 271 | 275 |
| 272 Directory::SaveChangesSnapshot snapshot2; | 276 Directory::SaveChangesSnapshot snapshot2; |
| 273 dir()->TakeSnapshotForSaveChanges(&snapshot2); | 277 dir()->TakeSnapshotForSaveChanges(&snapshot2); |
| 274 EXPECT_TRUE(all_handles == snapshot2.metahandles_to_purge); | 278 EXPECT_TRUE(all_handles == snapshot2.metahandles_to_purge); |
| 275 } | 279 } |
| 276 | 280 |
| 277 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsAllDirtyHandlesTest) { | 281 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsAllDirtyHandlesTest) { |
| 278 const int metahandles_to_create = 100; | 282 const int metahandles_to_create = 100; |
| 279 std::vector<int64> expected_dirty_metahandles; | 283 std::vector<int64_t> expected_dirty_metahandles; |
| 280 { | 284 { |
| 281 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 285 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 282 for (int i = 0; i < metahandles_to_create; i++) { | 286 for (int i = 0; i < metahandles_to_create; i++) { |
| 283 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), "foo"); | 287 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), "foo"); |
| 284 expected_dirty_metahandles.push_back(e.GetMetahandle()); | 288 expected_dirty_metahandles.push_back(e.GetMetahandle()); |
| 285 e.PutIsUnsynced(true); | 289 e.PutIsUnsynced(true); |
| 286 } | 290 } |
| 287 } | 291 } |
| 288 // Fake SaveChanges() and make sure we got what we expected. | 292 // Fake SaveChanges() and make sure we got what we expected. |
| 289 { | 293 { |
| 290 Directory::SaveChangesSnapshot snapshot; | 294 Directory::SaveChangesSnapshot snapshot; |
| 291 base::AutoLock scoped_lock(dir()->kernel()->save_changes_mutex); | 295 base::AutoLock scoped_lock(dir()->kernel()->save_changes_mutex); |
| 292 dir()->TakeSnapshotForSaveChanges(&snapshot); | 296 dir()->TakeSnapshotForSaveChanges(&snapshot); |
| 293 // Make sure there's an entry for each new metahandle. Make sure all | 297 // Make sure there's an entry for each new metahandle. Make sure all |
| 294 // entries are marked dirty. | 298 // entries are marked dirty. |
| 295 ASSERT_EQ(expected_dirty_metahandles.size(), snapshot.dirty_metas.size()); | 299 ASSERT_EQ(expected_dirty_metahandles.size(), snapshot.dirty_metas.size()); |
| 296 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); | 300 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); |
| 297 i != snapshot.dirty_metas.end(); | 301 i != snapshot.dirty_metas.end(); |
| 298 ++i) { | 302 ++i) { |
| 299 ASSERT_TRUE((*i)->is_dirty()); | 303 ASSERT_TRUE((*i)->is_dirty()); |
| 300 } | 304 } |
| 301 dir()->VacuumAfterSaveChanges(snapshot); | 305 dir()->VacuumAfterSaveChanges(snapshot); |
| 302 } | 306 } |
| 303 // Put a new value with existing transactions as well as adding new ones. | 307 // Put a new value with existing transactions as well as adding new ones. |
| 304 { | 308 { |
| 305 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 309 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 306 std::vector<int64> new_dirty_metahandles; | 310 std::vector<int64_t> new_dirty_metahandles; |
| 307 for (std::vector<int64>::const_iterator i = | 311 for (std::vector<int64_t>::const_iterator i = |
| 308 expected_dirty_metahandles.begin(); | 312 expected_dirty_metahandles.begin(); |
| 309 i != expected_dirty_metahandles.end(); | 313 i != expected_dirty_metahandles.end(); ++i) { |
| 310 ++i) { | |
| 311 // Change existing entries to directories to dirty them. | 314 // Change existing entries to directories to dirty them. |
| 312 MutableEntry e1(&trans, GET_BY_HANDLE, *i); | 315 MutableEntry e1(&trans, GET_BY_HANDLE, *i); |
| 313 e1.PutIsDir(true); | 316 e1.PutIsDir(true); |
| 314 e1.PutIsUnsynced(true); | 317 e1.PutIsUnsynced(true); |
| 315 // Add new entries | 318 // Add new entries |
| 316 MutableEntry e2(&trans, CREATE, BOOKMARKS, trans.root_id(), "bar"); | 319 MutableEntry e2(&trans, CREATE, BOOKMARKS, trans.root_id(), "bar"); |
| 317 e2.PutIsUnsynced(true); | 320 e2.PutIsUnsynced(true); |
| 318 new_dirty_metahandles.push_back(e2.GetMetahandle()); | 321 new_dirty_metahandles.push_back(e2.GetMetahandle()); |
| 319 } | 322 } |
| 320 expected_dirty_metahandles.insert(expected_dirty_metahandles.end(), | 323 expected_dirty_metahandles.insert(expected_dirty_metahandles.end(), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 336 } | 339 } |
| 337 dir()->VacuumAfterSaveChanges(snapshot); | 340 dir()->VacuumAfterSaveChanges(snapshot); |
| 338 } | 341 } |
| 339 } | 342 } |
| 340 | 343 |
| 341 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) { | 344 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) { |
| 342 const int metahandles_to_create = 100; | 345 const int metahandles_to_create = 100; |
| 343 | 346 |
| 344 // half of 2 * metahandles_to_create | 347 // half of 2 * metahandles_to_create |
| 345 const unsigned int number_changed = 100u; | 348 const unsigned int number_changed = 100u; |
| 346 std::vector<int64> expected_dirty_metahandles; | 349 std::vector<int64_t> expected_dirty_metahandles; |
| 347 { | 350 { |
| 348 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 351 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 349 for (int i = 0; i < metahandles_to_create; i++) { | 352 for (int i = 0; i < metahandles_to_create; i++) { |
| 350 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), "foo"); | 353 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), "foo"); |
| 351 expected_dirty_metahandles.push_back(e.GetMetahandle()); | 354 expected_dirty_metahandles.push_back(e.GetMetahandle()); |
| 352 e.PutIsUnsynced(true); | 355 e.PutIsUnsynced(true); |
| 353 } | 356 } |
| 354 } | 357 } |
| 355 dir()->SaveChanges(); | 358 dir()->SaveChanges(); |
| 356 // Put a new value with existing transactions as well as adding new ones. | 359 // Put a new value with existing transactions as well as adding new ones. |
| 357 { | 360 { |
| 358 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 361 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 359 std::vector<int64> new_dirty_metahandles; | 362 std::vector<int64_t> new_dirty_metahandles; |
| 360 for (std::vector<int64>::const_iterator i = | 363 for (std::vector<int64_t>::const_iterator i = |
| 361 expected_dirty_metahandles.begin(); | 364 expected_dirty_metahandles.begin(); |
| 362 i != expected_dirty_metahandles.end(); | 365 i != expected_dirty_metahandles.end(); ++i) { |
| 363 ++i) { | |
| 364 // Change existing entries to directories to dirty them. | 366 // Change existing entries to directories to dirty them. |
| 365 MutableEntry e1(&trans, GET_BY_HANDLE, *i); | 367 MutableEntry e1(&trans, GET_BY_HANDLE, *i); |
| 366 ASSERT_TRUE(e1.good()); | 368 ASSERT_TRUE(e1.good()); |
| 367 e1.PutIsDir(true); | 369 e1.PutIsDir(true); |
| 368 e1.PutIsUnsynced(true); | 370 e1.PutIsUnsynced(true); |
| 369 // Add new entries | 371 // Add new entries |
| 370 MutableEntry e2(&trans, CREATE, BOOKMARKS, trans.root_id(), "bar"); | 372 MutableEntry e2(&trans, CREATE, BOOKMARKS, trans.root_id(), "bar"); |
| 371 e2.PutIsUnsynced(true); | 373 e2.PutIsUnsynced(true); |
| 372 new_dirty_metahandles.push_back(e2.GetMetahandle()); | 374 new_dirty_metahandles.push_back(e2.GetMetahandle()); |
| 373 } | 375 } |
| 374 expected_dirty_metahandles.insert(expected_dirty_metahandles.end(), | 376 expected_dirty_metahandles.insert(expected_dirty_metahandles.end(), |
| 375 new_dirty_metahandles.begin(), | 377 new_dirty_metahandles.begin(), |
| 376 new_dirty_metahandles.end()); | 378 new_dirty_metahandles.end()); |
| 377 } | 379 } |
| 378 dir()->SaveChanges(); | 380 dir()->SaveChanges(); |
| 379 // Don't make any changes whatsoever and ensure nothing comes back. | 381 // Don't make any changes whatsoever and ensure nothing comes back. |
| 380 { | 382 { |
| 381 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 383 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 382 for (std::vector<int64>::const_iterator i = | 384 for (std::vector<int64_t>::const_iterator i = |
| 383 expected_dirty_metahandles.begin(); | 385 expected_dirty_metahandles.begin(); |
| 384 i != expected_dirty_metahandles.end(); | 386 i != expected_dirty_metahandles.end(); ++i) { |
| 385 ++i) { | |
| 386 MutableEntry e(&trans, GET_BY_HANDLE, *i); | 387 MutableEntry e(&trans, GET_BY_HANDLE, *i); |
| 387 ASSERT_TRUE(e.good()); | 388 ASSERT_TRUE(e.good()); |
| 388 // We aren't doing anything to dirty these entries. | 389 // We aren't doing anything to dirty these entries. |
| 389 } | 390 } |
| 390 } | 391 } |
| 391 // Fake SaveChanges() and make sure we got what we expected. | 392 // Fake SaveChanges() and make sure we got what we expected. |
| 392 { | 393 { |
| 393 Directory::SaveChangesSnapshot snapshot; | 394 Directory::SaveChangesSnapshot snapshot; |
| 394 base::AutoLock scoped_lock(dir()->kernel()->save_changes_mutex); | 395 base::AutoLock scoped_lock(dir()->kernel()->save_changes_mutex); |
| 395 dir()->TakeSnapshotForSaveChanges(&snapshot); | 396 dir()->TakeSnapshotForSaveChanges(&snapshot); |
| 396 // Make sure there are no dirty_metahandles. | 397 // Make sure there are no dirty_metahandles. |
| 397 EXPECT_EQ(0u, snapshot.dirty_metas.size()); | 398 EXPECT_EQ(0u, snapshot.dirty_metas.size()); |
| 398 dir()->VacuumAfterSaveChanges(snapshot); | 399 dir()->VacuumAfterSaveChanges(snapshot); |
| 399 } | 400 } |
| 400 { | 401 { |
| 401 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 402 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 402 bool should_change = false; | 403 bool should_change = false; |
| 403 for (std::vector<int64>::const_iterator i = | 404 for (std::vector<int64_t>::const_iterator i = |
| 404 expected_dirty_metahandles.begin(); | 405 expected_dirty_metahandles.begin(); |
| 405 i != expected_dirty_metahandles.end(); | 406 i != expected_dirty_metahandles.end(); ++i) { |
| 406 ++i) { | |
| 407 // Maybe change entries by flipping IS_DIR. | 407 // Maybe change entries by flipping IS_DIR. |
| 408 MutableEntry e(&trans, GET_BY_HANDLE, *i); | 408 MutableEntry e(&trans, GET_BY_HANDLE, *i); |
| 409 ASSERT_TRUE(e.good()); | 409 ASSERT_TRUE(e.good()); |
| 410 should_change = !should_change; | 410 should_change = !should_change; |
| 411 if (should_change) { | 411 if (should_change) { |
| 412 bool not_dir = !e.GetIsDir(); | 412 bool not_dir = !e.GetIsDir(); |
| 413 e.PutIsDir(not_dir); | 413 e.PutIsDir(not_dir); |
| 414 e.PutIsUnsynced(true); | 414 e.PutIsUnsynced(true); |
| 415 } | 415 } |
| 416 } | 416 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 436 TEST_F(SyncableDirectoryTest, ManageDeleteJournals) { | 436 TEST_F(SyncableDirectoryTest, ManageDeleteJournals) { |
| 437 sync_pb::EntitySpecifics bookmark_specifics; | 437 sync_pb::EntitySpecifics bookmark_specifics; |
| 438 AddDefaultFieldValue(BOOKMARKS, &bookmark_specifics); | 438 AddDefaultFieldValue(BOOKMARKS, &bookmark_specifics); |
| 439 bookmark_specifics.mutable_bookmark()->set_url("url"); | 439 bookmark_specifics.mutable_bookmark()->set_url("url"); |
| 440 | 440 |
| 441 // The first two IDs are server IDs. | 441 // The first two IDs are server IDs. |
| 442 Id id1 = TestIdFactory::FromNumber(1); | 442 Id id1 = TestIdFactory::FromNumber(1); |
| 443 Id id2 = TestIdFactory::FromNumber(2); | 443 Id id2 = TestIdFactory::FromNumber(2); |
| 444 // The third one is a client ID. | 444 // The third one is a client ID. |
| 445 Id id3 = TestIdFactory::FromNumber(-3); | 445 Id id3 = TestIdFactory::FromNumber(-3); |
| 446 int64 handle1 = 0; | 446 int64_t handle1 = 0; |
| 447 int64 handle2 = 0; | 447 int64_t handle2 = 0; |
| 448 int64 handle3 = 0; | 448 int64_t handle3 = 0; |
| 449 { | 449 { |
| 450 // Create 3 bookmark entries and save in database. | 450 // Create 3 bookmark entries and save in database. |
| 451 { | 451 { |
| 452 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 452 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 453 | 453 |
| 454 MutableEntry item1(&trans, CREATE, BOOKMARKS, trans.root_id(), "item1"); | 454 MutableEntry item1(&trans, CREATE, BOOKMARKS, trans.root_id(), "item1"); |
| 455 item1.PutId(id1); | 455 item1.PutId(id1); |
| 456 item1.PutSpecifics(bookmark_specifics); | 456 item1.PutSpecifics(bookmark_specifics); |
| 457 item1.PutServerSpecifics(bookmark_specifics); | 457 item1.PutServerSpecifics(bookmark_specifics); |
| 458 item1.PutIsUnappliedUpdate(true); | 458 item1.PutIsUnappliedUpdate(true); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 } | 580 } |
| 581 } | 581 } |
| 582 | 582 |
| 583 TEST_F(SyncableDirectoryTest, TestPurgeDeletedEntriesOnReload) { | 583 TEST_F(SyncableDirectoryTest, TestPurgeDeletedEntriesOnReload) { |
| 584 sync_pb::EntitySpecifics specifics; | 584 sync_pb::EntitySpecifics specifics; |
| 585 AddDefaultFieldValue(PREFERENCES, &specifics); | 585 AddDefaultFieldValue(PREFERENCES, &specifics); |
| 586 | 586 |
| 587 const int kClientCount = 2; | 587 const int kClientCount = 2; |
| 588 const int kServerCount = 5; | 588 const int kServerCount = 5; |
| 589 const int kTestCount = kClientCount + kServerCount; | 589 const int kTestCount = kClientCount + kServerCount; |
| 590 int64 handles[kTestCount]; | 590 int64_t handles[kTestCount]; |
| 591 | 591 |
| 592 // The idea is to recreate various combinations of IDs, IS_DEL, | 592 // The idea is to recreate various combinations of IDs, IS_DEL, |
| 593 // IS_UNSYNCED, and IS_UNAPPLIED_UPDATE flags to test all combinations | 593 // IS_UNSYNCED, and IS_UNAPPLIED_UPDATE flags to test all combinations |
| 594 // for DirectoryBackingStore::SafeToPurgeOnLoading. | 594 // for DirectoryBackingStore::SafeToPurgeOnLoading. |
| 595 // 0: client ID, IS_DEL, IS_UNSYNCED | 595 // 0: client ID, IS_DEL, IS_UNSYNCED |
| 596 // 1: client ID, IS_UNSYNCED | 596 // 1: client ID, IS_UNSYNCED |
| 597 // 2: server ID, IS_DEL, IS_UNSYNCED, IS_UNAPPLIED_UPDATE | 597 // 2: server ID, IS_DEL, IS_UNSYNCED, IS_UNAPPLIED_UPDATE |
| 598 // 3: server ID, IS_DEL, IS_UNSYNCED | 598 // 3: server ID, IS_DEL, IS_UNSYNCED |
| 599 // 4: server ID, IS_DEL, IS_UNAPPLIED_UPDATE | 599 // 4: server ID, IS_DEL, IS_UNAPPLIED_UPDATE |
| 600 // 5: server ID, IS_DEL | 600 // 5: server ID, IS_DEL |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 item.PutIsUnappliedUpdate(true); | 636 item.PutIsUnappliedUpdate(true); |
| 637 } | 637 } |
| 638 } | 638 } |
| 639 ASSERT_EQ(OPENED, SimulateSaveAndReloadDir()); | 639 ASSERT_EQ(OPENED, SimulateSaveAndReloadDir()); |
| 640 | 640 |
| 641 // Expect items 0 and 5 to be purged according to | 641 // Expect items 0 and 5 to be purged according to |
| 642 // DirectoryBackingStore::SafeToPurgeOnLoading: | 642 // DirectoryBackingStore::SafeToPurgeOnLoading: |
| 643 // - Item 0 is an item with IS_DEL flag and client ID. | 643 // - Item 0 is an item with IS_DEL flag and client ID. |
| 644 // - Item 5 is an item with IS_DEL flag which has both | 644 // - Item 5 is an item with IS_DEL flag which has both |
| 645 // IS_UNSYNCED and IS_UNAPPLIED_UPDATE unset. | 645 // IS_UNSYNCED and IS_UNAPPLIED_UPDATE unset. |
| 646 std::vector<int64> expected_purged; | 646 std::vector<int64_t> expected_purged; |
| 647 expected_purged.push_back(0); | 647 expected_purged.push_back(0); |
| 648 expected_purged.push_back(5); | 648 expected_purged.push_back(5); |
| 649 | 649 |
| 650 std::vector<int64> actually_purged; | 650 std::vector<int64_t> actually_purged; |
| 651 { | 651 { |
| 652 ReadTransaction trans(FROM_HERE, dir().get()); | 652 ReadTransaction trans(FROM_HERE, dir().get()); |
| 653 for (int i = 0; i < kTestCount; i++) { | 653 for (int i = 0; i < kTestCount; i++) { |
| 654 Entry item(&trans, GET_BY_HANDLE, handles[i]); | 654 Entry item(&trans, GET_BY_HANDLE, handles[i]); |
| 655 if (!item.good()) { | 655 if (!item.good()) { |
| 656 actually_purged.push_back(i); | 656 actually_purged.push_back(i); |
| 657 } | 657 } |
| 658 } | 658 } |
| 659 } | 659 } |
| 660 | 660 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 691 e2.PutIsDel(false); | 691 e2.PutIsDel(false); |
| 692 e3.PutIsDel(false); | 692 e3.PutIsDel(false); |
| 693 | 693 |
| 694 e1.PutIsDel(true); | 694 e1.PutIsDel(true); |
| 695 e2.PutIsDel(true); | 695 e2.PutIsDel(true); |
| 696 e3.PutIsDel(true); | 696 e3.PutIsDel(true); |
| 697 } | 697 } |
| 698 | 698 |
| 699 TEST_F(SyncableDirectoryTest, TestGetUnsynced) { | 699 TEST_F(SyncableDirectoryTest, TestGetUnsynced) { |
| 700 Directory::Metahandles handles; | 700 Directory::Metahandles handles; |
| 701 int64 handle1, handle2; | 701 int64_t handle1, handle2; |
| 702 { | 702 { |
| 703 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 703 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 704 | 704 |
| 705 dir()->GetUnsyncedMetaHandles(&trans, &handles); | 705 dir()->GetUnsyncedMetaHandles(&trans, &handles); |
| 706 ASSERT_EQ(0u, handles.size()); | 706 ASSERT_EQ(0u, handles.size()); |
| 707 | 707 |
| 708 MutableEntry e1(&trans, CREATE, BOOKMARKS, trans.root_id(), "abba"); | 708 MutableEntry e1(&trans, CREATE, BOOKMARKS, trans.root_id(), "abba"); |
| 709 ASSERT_TRUE(e1.good()); | 709 ASSERT_TRUE(e1.good()); |
| 710 handle1 = e1.GetMetahandle(); | 710 handle1 = e1.GetMetahandle(); |
| 711 e1.PutBaseVersion(1); | 711 e1.PutBaseVersion(1); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 dir()->SaveChanges(); | 761 dir()->SaveChanges(); |
| 762 { | 762 { |
| 763 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 763 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 764 dir()->GetUnsyncedMetaHandles(&trans, &handles); | 764 dir()->GetUnsyncedMetaHandles(&trans, &handles); |
| 765 ASSERT_EQ(1u, handles.size()); | 765 ASSERT_EQ(1u, handles.size()); |
| 766 ASSERT_TRUE(handle2 == handles[0]); | 766 ASSERT_TRUE(handle2 == handles[0]); |
| 767 } | 767 } |
| 768 } | 768 } |
| 769 | 769 |
| 770 TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) { | 770 TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) { |
| 771 std::vector<int64> handles; | 771 std::vector<int64_t> handles; |
| 772 int64 handle1, handle2; | 772 int64_t handle1, handle2; |
| 773 const FullModelTypeSet all_types = FullModelTypeSet::All(); | 773 const FullModelTypeSet all_types = FullModelTypeSet::All(); |
| 774 { | 774 { |
| 775 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 775 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 776 | 776 |
| 777 dir()->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles); | 777 dir()->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles); |
| 778 ASSERT_EQ(0u, handles.size()); | 778 ASSERT_EQ(0u, handles.size()); |
| 779 | 779 |
| 780 MutableEntry e1(&trans, CREATE, BOOKMARKS, trans.root_id(), "abba"); | 780 MutableEntry e1(&trans, CREATE, BOOKMARKS, trans.root_id(), "abba"); |
| 781 ASSERT_TRUE(e1.good()); | 781 ASSERT_TRUE(e1.good()); |
| 782 handle1 = e1.GetMetahandle(); | 782 handle1 = e1.GetMetahandle(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 835 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 836 dir()->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles); | 836 dir()->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles); |
| 837 ASSERT_EQ(1u, handles.size()); | 837 ASSERT_EQ(1u, handles.size()); |
| 838 ASSERT_TRUE(handle2 == handles[0]); | 838 ASSERT_TRUE(handle2 == handles[0]); |
| 839 } | 839 } |
| 840 } | 840 } |
| 841 | 841 |
| 842 TEST_F(SyncableDirectoryTest, DeleteBug_531383) { | 842 TEST_F(SyncableDirectoryTest, DeleteBug_531383) { |
| 843 // Try to evoke a check failure... | 843 // Try to evoke a check failure... |
| 844 TestIdFactory id_factory; | 844 TestIdFactory id_factory; |
| 845 int64 grandchild_handle; | 845 int64_t grandchild_handle; |
| 846 { | 846 { |
| 847 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir().get()); | 847 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir().get()); |
| 848 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, id_factory.root(), "Bob"); | 848 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, id_factory.root(), "Bob"); |
| 849 ASSERT_TRUE(parent.good()); | 849 ASSERT_TRUE(parent.good()); |
| 850 parent.PutIsDir(true); | 850 parent.PutIsDir(true); |
| 851 parent.PutId(id_factory.NewServerId()); | 851 parent.PutId(id_factory.NewServerId()); |
| 852 parent.PutBaseVersion(1); | 852 parent.PutBaseVersion(1); |
| 853 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent.GetId(), "Bob"); | 853 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent.GetId(), "Bob"); |
| 854 ASSERT_TRUE(child.good()); | 854 ASSERT_TRUE(child.good()); |
| 855 child.PutIsDir(true); | 855 child.PutIsDir(true); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 ASSERT_FALSE(IsLegalNewParent(child, grandchild)); | 923 ASSERT_FALSE(IsLegalNewParent(child, grandchild)); |
| 924 ASSERT_TRUE(IsLegalNewParent(child, parent2)); | 924 ASSERT_TRUE(IsLegalNewParent(child, parent2)); |
| 925 ASSERT_TRUE(IsLegalNewParent(child, grandchild2)); | 925 ASSERT_TRUE(IsLegalNewParent(child, grandchild2)); |
| 926 ASSERT_FALSE(IsLegalNewParent(parent, grandchild)); | 926 ASSERT_FALSE(IsLegalNewParent(parent, grandchild)); |
| 927 ASSERT_FALSE(IsLegalNewParent(root, grandchild)); | 927 ASSERT_FALSE(IsLegalNewParent(root, grandchild)); |
| 928 ASSERT_FALSE(IsLegalNewParent(parent, grandchild)); | 928 ASSERT_FALSE(IsLegalNewParent(parent, grandchild)); |
| 929 } | 929 } |
| 930 | 930 |
| 931 TEST_F(SyncableDirectoryTest, TestEntryIsInFolder) { | 931 TEST_F(SyncableDirectoryTest, TestEntryIsInFolder) { |
| 932 // Create a subdir and an entry. | 932 // Create a subdir and an entry. |
| 933 int64 entry_handle; | 933 int64_t entry_handle; |
| 934 syncable::Id folder_id; | 934 syncable::Id folder_id; |
| 935 syncable::Id entry_id; | 935 syncable::Id entry_id; |
| 936 std::string entry_name = "entry"; | 936 std::string entry_name = "entry"; |
| 937 | 937 |
| 938 { | 938 { |
| 939 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 939 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 940 MutableEntry folder(&trans, CREATE, BOOKMARKS, trans.root_id(), "folder"); | 940 MutableEntry folder(&trans, CREATE, BOOKMARKS, trans.root_id(), "folder"); |
| 941 ASSERT_TRUE(folder.good()); | 941 ASSERT_TRUE(folder.good()); |
| 942 folder.PutIsDir(true); | 942 folder.PutIsDir(true); |
| 943 EXPECT_TRUE(folder.PutIsUnsynced(true)); | 943 EXPECT_TRUE(folder.PutIsUnsynced(true)); |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 child.PutSpecifics(specifics); | 1413 child.PutSpecifics(specifics); |
| 1414 | 1414 |
| 1415 EXPECT_TRUE(child.ShouldMaintainPosition()); | 1415 EXPECT_TRUE(child.ShouldMaintainPosition()); |
| 1416 EXPECT_TRUE(!child.GetUniquePosition().IsValid()); | 1416 EXPECT_TRUE(!child.GetUniquePosition().IsValid()); |
| 1417 } | 1417 } |
| 1418 | 1418 |
| 1419 EXPECT_EQ(FAILED_DATABASE_CORRUPT, SimulateSaveAndReloadDir()); | 1419 EXPECT_EQ(FAILED_DATABASE_CORRUPT, SimulateSaveAndReloadDir()); |
| 1420 } | 1420 } |
| 1421 | 1421 |
| 1422 TEST_F(SyncableDirectoryTest, General) { | 1422 TEST_F(SyncableDirectoryTest, General) { |
| 1423 int64 written_metahandle; | 1423 int64_t written_metahandle; |
| 1424 const Id id = TestIdFactory::FromNumber(99); | 1424 const Id id = TestIdFactory::FromNumber(99); |
| 1425 std::string name = "Jeff"; | 1425 std::string name = "Jeff"; |
| 1426 // Test simple read operations on an empty DB. | 1426 // Test simple read operations on an empty DB. |
| 1427 { | 1427 { |
| 1428 ReadTransaction rtrans(FROM_HERE, dir().get()); | 1428 ReadTransaction rtrans(FROM_HERE, dir().get()); |
| 1429 Entry e(&rtrans, GET_BY_ID, id); | 1429 Entry e(&rtrans, GET_BY_ID, id); |
| 1430 ASSERT_FALSE(e.good()); // Hasn't been written yet. | 1430 ASSERT_FALSE(e.good()); // Hasn't been written yet. |
| 1431 | 1431 |
| 1432 Directory::Metahandles child_handles; | 1432 Directory::Metahandles child_handles; |
| 1433 dir()->GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles); | 1433 dir()->GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle); | 1490 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle); |
| 1491 e.PutIsDel(true); | 1491 e.PutIsDel(true); |
| 1492 | 1492 |
| 1493 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), name)); | 1493 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), name)); |
| 1494 } | 1494 } |
| 1495 | 1495 |
| 1496 dir()->SaveChanges(); | 1496 dir()->SaveChanges(); |
| 1497 } | 1497 } |
| 1498 | 1498 |
| 1499 TEST_F(SyncableDirectoryTest, ChildrenOps) { | 1499 TEST_F(SyncableDirectoryTest, ChildrenOps) { |
| 1500 int64 written_metahandle; | 1500 int64_t written_metahandle; |
| 1501 const Id id = TestIdFactory::FromNumber(99); | 1501 const Id id = TestIdFactory::FromNumber(99); |
| 1502 std::string name = "Jeff"; | 1502 std::string name = "Jeff"; |
| 1503 { | 1503 { |
| 1504 ReadTransaction rtrans(FROM_HERE, dir().get()); | 1504 ReadTransaction rtrans(FROM_HERE, dir().get()); |
| 1505 Entry e(&rtrans, GET_BY_ID, id); | 1505 Entry e(&rtrans, GET_BY_ID, id); |
| 1506 ASSERT_FALSE(e.good()); // Hasn't been written yet. | 1506 ASSERT_FALSE(e.good()); // Hasn't been written yet. |
| 1507 | 1507 |
| 1508 Entry root(&rtrans, GET_BY_ID, rtrans.root_id()); | 1508 Entry root(&rtrans, GET_BY_ID, rtrans.root_id()); |
| 1509 ASSERT_TRUE(root.good()); | 1509 ASSERT_TRUE(root.good()); |
| 1510 EXPECT_FALSE(dir()->HasChildren(&rtrans, rtrans.root_id())); | 1510 EXPECT_FALSE(dir()->HasChildren(&rtrans, rtrans.root_id())); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1551 Entry root(&rtrans, GET_BY_ID, rtrans.root_id()); | 1551 Entry root(&rtrans, GET_BY_ID, rtrans.root_id()); |
| 1552 ASSERT_TRUE(root.good()); | 1552 ASSERT_TRUE(root.good()); |
| 1553 EXPECT_FALSE(dir()->HasChildren(&rtrans, rtrans.root_id())); | 1553 EXPECT_FALSE(dir()->HasChildren(&rtrans, rtrans.root_id())); |
| 1554 EXPECT_TRUE(root.GetFirstChildId().IsNull()); | 1554 EXPECT_TRUE(root.GetFirstChildId().IsNull()); |
| 1555 } | 1555 } |
| 1556 | 1556 |
| 1557 dir()->SaveChanges(); | 1557 dir()->SaveChanges(); |
| 1558 } | 1558 } |
| 1559 | 1559 |
| 1560 TEST_F(SyncableDirectoryTest, ClientIndexRebuildsProperly) { | 1560 TEST_F(SyncableDirectoryTest, ClientIndexRebuildsProperly) { |
| 1561 int64 written_metahandle; | 1561 int64_t written_metahandle; |
| 1562 TestIdFactory factory; | 1562 TestIdFactory factory; |
| 1563 const Id id = factory.NewServerId(); | 1563 const Id id = factory.NewServerId(); |
| 1564 std::string name = "cheesepuffs"; | 1564 std::string name = "cheesepuffs"; |
| 1565 std::string tag = "dietcoke"; | 1565 std::string tag = "dietcoke"; |
| 1566 | 1566 |
| 1567 // Test creating a new meta entry. | 1567 // Test creating a new meta entry. |
| 1568 { | 1568 { |
| 1569 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir().get()); | 1569 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir().get()); |
| 1570 MutableEntry me(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), name); | 1570 MutableEntry me(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), name); |
| 1571 ASSERT_TRUE(me.good()); | 1571 ASSERT_TRUE(me.good()); |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2131 EXPECT_FALSE(dir()->InitialSyncEndedForType(&trans, PREFERENCES)); | 2131 EXPECT_FALSE(dir()->InitialSyncEndedForType(&trans, PREFERENCES)); |
| 2132 | 2132 |
| 2133 // Mark as complete and verify. | 2133 // Mark as complete and verify. |
| 2134 dir()->MarkInitialSyncEndedForType(&trans, PREFERENCES); | 2134 dir()->MarkInitialSyncEndedForType(&trans, PREFERENCES); |
| 2135 EXPECT_TRUE(dir()->InitialSyncEndedForType(&trans, PREFERENCES)); | 2135 EXPECT_TRUE(dir()->InitialSyncEndedForType(&trans, PREFERENCES)); |
| 2136 } | 2136 } |
| 2137 | 2137 |
| 2138 } // namespace syncable | 2138 } // namespace syncable |
| 2139 | 2139 |
| 2140 } // namespace syncer | 2140 } // namespace syncer |
| OLD | NEW |