| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 all_handles.insert(e.Get(META_HANDLE)); | 541 all_handles.insert(e.Get(META_HANDLE)); |
| 542 } else { | 542 } else { |
| 543 AddDefaultFieldValue(PREFERENCES, &specs); | 543 AddDefaultFieldValue(PREFERENCES, &specs); |
| 544 all_handles.insert(e.Get(META_HANDLE)); | 544 all_handles.insert(e.Get(META_HANDLE)); |
| 545 } | 545 } |
| 546 e.Put(SPECIFICS, specs); | 546 e.Put(SPECIFICS, specs); |
| 547 e.Put(SERVER_SPECIFICS, specs); | 547 e.Put(SERVER_SPECIFICS, specs); |
| 548 } | 548 } |
| 549 } | 549 } |
| 550 | 550 |
| 551 syncable::ModelTypeSet to_purge(BOOKMARKS); | 551 syncer::ModelTypeSet to_purge(BOOKMARKS); |
| 552 dir_->PurgeEntriesWithTypeIn(to_purge); | 552 dir_->PurgeEntriesWithTypeIn(to_purge); |
| 553 | 553 |
| 554 Directory::SaveChangesSnapshot snapshot1; | 554 Directory::SaveChangesSnapshot snapshot1; |
| 555 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex); | 555 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex); |
| 556 dir_->TakeSnapshotForSaveChanges(&snapshot1); | 556 dir_->TakeSnapshotForSaveChanges(&snapshot1); |
| 557 EXPECT_TRUE(expected_purges == snapshot1.metahandles_to_purge); | 557 EXPECT_TRUE(expected_purges == snapshot1.metahandles_to_purge); |
| 558 | 558 |
| 559 to_purge.Clear(); | 559 to_purge.Clear(); |
| 560 to_purge.Put(PREFERENCES); | 560 to_purge.Put(PREFERENCES); |
| 561 dir_->PurgeEntriesWithTypeIn(to_purge); | 561 dir_->PurgeEntriesWithTypeIn(to_purge); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 822 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
| 823 dir_->GetUnsyncedMetaHandles(&trans, &handles); | 823 dir_->GetUnsyncedMetaHandles(&trans, &handles); |
| 824 ASSERT_TRUE(1 == handles.size()); | 824 ASSERT_TRUE(1 == handles.size()); |
| 825 ASSERT_TRUE(handle2 == handles[0]); | 825 ASSERT_TRUE(handle2 == handles[0]); |
| 826 } | 826 } |
| 827 } | 827 } |
| 828 | 828 |
| 829 TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) { | 829 TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) { |
| 830 std::vector<int64> handles; | 830 std::vector<int64> handles; |
| 831 int64 handle1, handle2; | 831 int64 handle1, handle2; |
| 832 const syncable::FullModelTypeSet all_types = | 832 const syncer::FullModelTypeSet all_types = syncer::FullModelTypeSet::All(); |
| 833 syncable::FullModelTypeSet::All(); | |
| 834 { | 833 { |
| 835 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 834 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
| 836 | 835 |
| 837 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles); | 836 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles); |
| 838 ASSERT_TRUE(0 == handles.size()); | 837 ASSERT_TRUE(0 == handles.size()); |
| 839 | 838 |
| 840 MutableEntry e1(&trans, CREATE, trans.root_id(), "abba"); | 839 MutableEntry e1(&trans, CREATE, trans.root_id(), "abba"); |
| 841 ASSERT_TRUE(e1.good()); | 840 ASSERT_TRUE(e1.good()); |
| 842 handle1 = e1.Get(META_HANDLE); | 841 handle1 = e1.Get(META_HANDLE); |
| 843 e1.Put(IS_UNAPPLIED_UPDATE, false); | 842 e1.Put(IS_UNAPPLIED_UPDATE, false); |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1389 sync_pb::EntitySpecifics bookmark_specs; | 1388 sync_pb::EntitySpecifics bookmark_specs; |
| 1390 sync_pb::EntitySpecifics autofill_specs; | 1389 sync_pb::EntitySpecifics autofill_specs; |
| 1391 sync_pb::EntitySpecifics preference_specs; | 1390 sync_pb::EntitySpecifics preference_specs; |
| 1392 AddDefaultFieldValue(BOOKMARKS, &bookmark_specs); | 1391 AddDefaultFieldValue(BOOKMARKS, &bookmark_specs); |
| 1393 AddDefaultFieldValue(PREFERENCES, &preference_specs); | 1392 AddDefaultFieldValue(PREFERENCES, &preference_specs); |
| 1394 AddDefaultFieldValue(AUTOFILL, &autofill_specs); | 1393 AddDefaultFieldValue(AUTOFILL, &autofill_specs); |
| 1395 dir_->set_initial_sync_ended_for_type(BOOKMARKS, true); | 1394 dir_->set_initial_sync_ended_for_type(BOOKMARKS, true); |
| 1396 dir_->set_initial_sync_ended_for_type(PREFERENCES, true); | 1395 dir_->set_initial_sync_ended_for_type(PREFERENCES, true); |
| 1397 dir_->set_initial_sync_ended_for_type(AUTOFILL, true); | 1396 dir_->set_initial_sync_ended_for_type(AUTOFILL, true); |
| 1398 | 1397 |
| 1399 syncable::ModelTypeSet types_to_purge(PREFERENCES, AUTOFILL); | 1398 syncer::ModelTypeSet types_to_purge(PREFERENCES, AUTOFILL); |
| 1400 | 1399 |
| 1401 TestIdFactory id_factory; | 1400 TestIdFactory id_factory; |
| 1402 // Create some items for each type. | 1401 // Create some items for each type. |
| 1403 { | 1402 { |
| 1404 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); | 1403 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); |
| 1405 MutableEntry item1(&trans, CREATE, trans.root_id(), "Item"); | 1404 MutableEntry item1(&trans, CREATE, trans.root_id(), "Item"); |
| 1406 ASSERT_TRUE(item1.good()); | 1405 ASSERT_TRUE(item1.good()); |
| 1407 item1.Put(SPECIFICS, bookmark_specs); | 1406 item1.Put(SPECIFICS, bookmark_specs); |
| 1408 item1.Put(SERVER_SPECIFICS, bookmark_specs); | 1407 item1.Put(SERVER_SPECIFICS, bookmark_specs); |
| 1409 item1.Put(IS_UNSYNCED, true); | 1408 item1.Put(IS_UNSYNCED, true); |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1681 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); | 1680 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); |
| 1682 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); | 1681 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); |
| 1683 } | 1682 } |
| 1684 ASSERT_TRUE(dir_->SaveChanges()); | 1683 ASSERT_TRUE(dir_->SaveChanges()); |
| 1685 | 1684 |
| 1686 // Now do some operations using a directory for which SaveChanges will | 1685 // Now do some operations using a directory for which SaveChanges will |
| 1687 // always fail. | 1686 // always fail. |
| 1688 SwapInUnsaveableDirectory(); | 1687 SwapInUnsaveableDirectory(); |
| 1689 ASSERT_TRUE(dir_->good()); | 1688 ASSERT_TRUE(dir_->good()); |
| 1690 | 1689 |
| 1691 syncable::ModelTypeSet set(BOOKMARKS); | 1690 syncer::ModelTypeSet set(BOOKMARKS); |
| 1692 dir_->PurgeEntriesWithTypeIn(set); | 1691 dir_->PurgeEntriesWithTypeIn(set); |
| 1693 EXPECT_TRUE(IsInMetahandlesToPurge(handle1)); | 1692 EXPECT_TRUE(IsInMetahandlesToPurge(handle1)); |
| 1694 ASSERT_FALSE(dir_->SaveChanges()); | 1693 ASSERT_FALSE(dir_->SaveChanges()); |
| 1695 EXPECT_TRUE(IsInMetahandlesToPurge(handle1)); | 1694 EXPECT_TRUE(IsInMetahandlesToPurge(handle1)); |
| 1696 } | 1695 } |
| 1697 | 1696 |
| 1698 } // namespace | 1697 } // namespace |
| 1699 | 1698 |
| 1700 void SyncableDirectoryTest::ValidateEntry(BaseTransaction* trans, | 1699 void SyncableDirectoryTest::ValidateEntry(BaseTransaction* trans, |
| 1701 int64 id, | 1700 int64 id, |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1932 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 1931 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
| 1933 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 1932 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
| 1934 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); | 1933 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); |
| 1935 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); | 1934 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); |
| 1936 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); | 1935 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); |
| 1937 } | 1936 } |
| 1938 | 1937 |
| 1939 } // namespace | 1938 } // namespace |
| 1940 } // namespace syncable | 1939 } // namespace syncable |
| 1941 } // namespace syncer | 1940 } // namespace syncer |
| OLD | NEW |