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 "components/sync/syncable/directory_unittest.h" | 5 #include "components/sync/syncable/directory_unittest.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <cstdlib> | 10 #include <cstdlib> |
(...skipping 1695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 base::PlatformThread::Join(threads[i]); | 1706 base::PlatformThread::Join(threads[i]); |
1707 } | 1707 } |
1708 } | 1708 } |
1709 | 1709 |
1710 // Verify that Directory is notifed when a MutableEntry's AttachmentMetadata | 1710 // Verify that Directory is notifed when a MutableEntry's AttachmentMetadata |
1711 // changes. | 1711 // changes. |
1712 TEST_F(SyncableDirectoryTest, MutableEntry_PutAttachmentMetadata) { | 1712 TEST_F(SyncableDirectoryTest, MutableEntry_PutAttachmentMetadata) { |
1713 sync_pb::AttachmentMetadata attachment_metadata; | 1713 sync_pb::AttachmentMetadata attachment_metadata; |
1714 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); | 1714 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); |
1715 sync_pb::AttachmentIdProto attachment_id_proto = | 1715 sync_pb::AttachmentIdProto attachment_id_proto = |
1716 syncer::CreateAttachmentIdProto(0, 0); | 1716 CreateAttachmentIdProto(0, 0); |
1717 *record->mutable_id() = attachment_id_proto; | 1717 *record->mutable_id() = attachment_id_proto; |
1718 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1718 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
1719 { | 1719 { |
1720 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 1720 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
1721 | 1721 |
1722 // Create an entry with attachment metadata and see that the attachment id | 1722 // Create an entry with attachment metadata and see that the attachment id |
1723 // is not linked. | 1723 // is not linked. |
1724 MutableEntry entry(&trans, CREATE, PREFERENCES, trans.root_id(), | 1724 MutableEntry entry(&trans, CREATE, PREFERENCES, trans.root_id(), |
1725 "some entry"); | 1725 "some entry"); |
1726 entry.PutId(TestIdFactory::FromNumber(-1)); | 1726 entry.PutId(TestIdFactory::FromNumber(-1)); |
(...skipping 23 matching lines...) Expand all Loading... |
1750 ASSERT_TRUE(metahandles.empty()); | 1750 ASSERT_TRUE(metahandles.empty()); |
1751 } | 1751 } |
1752 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1752 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
1753 } | 1753 } |
1754 | 1754 |
1755 // Verify that UpdateAttachmentId updates attachment_id and is_on_server flag. | 1755 // Verify that UpdateAttachmentId updates attachment_id and is_on_server flag. |
1756 TEST_F(SyncableDirectoryTest, MutableEntry_UpdateAttachmentId) { | 1756 TEST_F(SyncableDirectoryTest, MutableEntry_UpdateAttachmentId) { |
1757 sync_pb::AttachmentMetadata attachment_metadata; | 1757 sync_pb::AttachmentMetadata attachment_metadata; |
1758 sync_pb::AttachmentMetadataRecord* r1 = attachment_metadata.add_record(); | 1758 sync_pb::AttachmentMetadataRecord* r1 = attachment_metadata.add_record(); |
1759 sync_pb::AttachmentMetadataRecord* r2 = attachment_metadata.add_record(); | 1759 sync_pb::AttachmentMetadataRecord* r2 = attachment_metadata.add_record(); |
1760 *r1->mutable_id() = syncer::CreateAttachmentIdProto(0, 0); | 1760 *r1->mutable_id() = CreateAttachmentIdProto(0, 0); |
1761 *r2->mutable_id() = syncer::CreateAttachmentIdProto(0, 0); | 1761 *r2->mutable_id() = CreateAttachmentIdProto(0, 0); |
1762 sync_pb::AttachmentIdProto attachment_id_proto = r1->id(); | 1762 sync_pb::AttachmentIdProto attachment_id_proto = r1->id(); |
1763 | 1763 |
1764 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 1764 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
1765 | 1765 |
1766 MutableEntry entry(&trans, CREATE, PREFERENCES, trans.root_id(), | 1766 MutableEntry entry(&trans, CREATE, PREFERENCES, trans.root_id(), |
1767 "some entry"); | 1767 "some entry"); |
1768 entry.PutId(TestIdFactory::FromNumber(-1)); | 1768 entry.PutId(TestIdFactory::FromNumber(-1)); |
1769 entry.PutAttachmentMetadata(attachment_metadata); | 1769 entry.PutAttachmentMetadata(attachment_metadata); |
1770 | 1770 |
1771 { | 1771 { |
(...skipping 17 matching lines...) Expand all Loading... |
1789 ASSERT_FALSE(entry_metadata.record(1).is_on_server()); | 1789 ASSERT_FALSE(entry_metadata.record(1).is_on_server()); |
1790 ASSERT_TRUE(entry.GetIsUnsynced()); | 1790 ASSERT_TRUE(entry.GetIsUnsynced()); |
1791 } | 1791 } |
1792 } | 1792 } |
1793 | 1793 |
1794 // Verify that deleted entries with attachments will retain the attachments. | 1794 // Verify that deleted entries with attachments will retain the attachments. |
1795 TEST_F(SyncableDirectoryTest, Directory_DeleteDoesNotUnlinkAttachments) { | 1795 TEST_F(SyncableDirectoryTest, Directory_DeleteDoesNotUnlinkAttachments) { |
1796 sync_pb::AttachmentMetadata attachment_metadata; | 1796 sync_pb::AttachmentMetadata attachment_metadata; |
1797 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); | 1797 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); |
1798 sync_pb::AttachmentIdProto attachment_id_proto = | 1798 sync_pb::AttachmentIdProto attachment_id_proto = |
1799 syncer::CreateAttachmentIdProto(0, 0); | 1799 CreateAttachmentIdProto(0, 0); |
1800 *record->mutable_id() = attachment_id_proto; | 1800 *record->mutable_id() = attachment_id_proto; |
1801 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1801 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
1802 const Id id = TestIdFactory::FromNumber(-1); | 1802 const Id id = TestIdFactory::FromNumber(-1); |
1803 | 1803 |
1804 // Create an entry with attachment metadata and see that the attachment id | 1804 // Create an entry with attachment metadata and see that the attachment id |
1805 // is linked. | 1805 // is linked. |
1806 CreateEntryWithAttachmentMetadata(PREFERENCES, "some entry", id, | 1806 CreateEntryWithAttachmentMetadata(PREFERENCES, "some entry", id, |
1807 attachment_metadata); | 1807 attachment_metadata); |
1808 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1808 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); |
1809 | 1809 |
1810 // Delete the entry and see that it's still linked because the entry hasn't | 1810 // Delete the entry and see that it's still linked because the entry hasn't |
1811 // yet been purged. | 1811 // yet been purged. |
1812 DeleteEntry(id); | 1812 DeleteEntry(id); |
1813 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1813 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); |
1814 | 1814 |
1815 // Reload the Directory, purging the deleted entry, and see that the | 1815 // Reload the Directory, purging the deleted entry, and see that the |
1816 // attachment is no longer linked. | 1816 // attachment is no longer linked. |
1817 SimulateSaveAndReloadDir(); | 1817 SimulateSaveAndReloadDir(); |
1818 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1818 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
1819 } | 1819 } |
1820 | 1820 |
1821 // Verify that a given attachment can be referenced by multiple entries and that | 1821 // Verify that a given attachment can be referenced by multiple entries and that |
1822 // any one of the references is sufficient to ensure it remains linked. | 1822 // any one of the references is sufficient to ensure it remains linked. |
1823 TEST_F(SyncableDirectoryTest, Directory_LastReferenceUnlinksAttachments) { | 1823 TEST_F(SyncableDirectoryTest, Directory_LastReferenceUnlinksAttachments) { |
1824 // Create one attachment. | 1824 // Create one attachment. |
1825 sync_pb::AttachmentMetadata attachment_metadata; | 1825 sync_pb::AttachmentMetadata attachment_metadata; |
1826 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); | 1826 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); |
1827 sync_pb::AttachmentIdProto attachment_id_proto = | 1827 sync_pb::AttachmentIdProto attachment_id_proto = |
1828 syncer::CreateAttachmentIdProto(0, 0); | 1828 CreateAttachmentIdProto(0, 0); |
1829 *record->mutable_id() = attachment_id_proto; | 1829 *record->mutable_id() = attachment_id_proto; |
1830 | 1830 |
1831 // Create two entries, each referencing the attachment. | 1831 // Create two entries, each referencing the attachment. |
1832 const Id id1 = TestIdFactory::FromNumber(-1); | 1832 const Id id1 = TestIdFactory::FromNumber(-1); |
1833 const Id id2 = TestIdFactory::FromNumber(-2); | 1833 const Id id2 = TestIdFactory::FromNumber(-2); |
1834 CreateEntryWithAttachmentMetadata(PREFERENCES, "some entry", id1, | 1834 CreateEntryWithAttachmentMetadata(PREFERENCES, "some entry", id1, |
1835 attachment_metadata); | 1835 attachment_metadata); |
1836 CreateEntryWithAttachmentMetadata(PREFERENCES, "some other entry", id2, | 1836 CreateEntryWithAttachmentMetadata(PREFERENCES, "some other entry", id2, |
1837 attachment_metadata); | 1837 attachment_metadata); |
1838 | 1838 |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2139 | 2139 |
2140 const base::DictionaryValue* first_result; | 2140 const base::DictionaryValue* first_result; |
2141 ASSERT_TRUE(nodes->GetDictionary(0, &first_result)); | 2141 ASSERT_TRUE(nodes->GetDictionary(0, &first_result)); |
2142 EXPECT_TRUE(first_result->HasKey("ID")); | 2142 EXPECT_TRUE(first_result->HasKey("ID")); |
2143 EXPECT_TRUE(first_result->HasKey("NON_UNIQUE_NAME")); | 2143 EXPECT_TRUE(first_result->HasKey("NON_UNIQUE_NAME")); |
2144 } | 2144 } |
2145 | 2145 |
2146 } // namespace syncable | 2146 } // namespace syncable |
2147 | 2147 |
2148 } // namespace syncer | 2148 } // namespace syncer |
OLD | NEW |