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

Side by Side Diff: sync/syncable/directory_unittest.cc

Issue 982883002: [Sync] Add size and crc32c to AttachmentId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with master. Created 5 years, 9 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
« no previous file with comments | « sync/protocol/attachments.proto ('k') | no next file » | 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/syncable/directory_unittest.h" 5 #include "sync/syncable/directory_unittest.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/test/values_test_util.h" 8 #include "base/test/values_test_util.h"
9 #include "sync/internal_api/public/base/attachment_id_proto.h" 9 #include "sync/internal_api/public/base/attachment_id_proto.h"
10 #include "sync/syncable/syncable_proto_util.h" 10 #include "sync/syncable/syncable_proto_util.h"
(...skipping 1621 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 base::PlatformThread::Join(threads[i]); 1632 base::PlatformThread::Join(threads[i]);
1633 } 1633 }
1634 } 1634 }
1635 1635
1636 // Verify that Directory is notifed when a MutableEntry's AttachmentMetadata 1636 // Verify that Directory is notifed when a MutableEntry's AttachmentMetadata
1637 // changes. 1637 // changes.
1638 TEST_F(SyncableDirectoryTest, MutableEntry_PutAttachmentMetadata) { 1638 TEST_F(SyncableDirectoryTest, MutableEntry_PutAttachmentMetadata) {
1639 sync_pb::AttachmentMetadata attachment_metadata; 1639 sync_pb::AttachmentMetadata attachment_metadata;
1640 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); 1640 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record();
1641 sync_pb::AttachmentIdProto attachment_id_proto = 1641 sync_pb::AttachmentIdProto attachment_id_proto =
1642 syncer::CreateAttachmentIdProto(); 1642 syncer::CreateAttachmentIdProto(0, 0);
1643 *record->mutable_id() = attachment_id_proto; 1643 *record->mutable_id() = attachment_id_proto;
1644 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); 1644 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto));
1645 { 1645 {
1646 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); 1646 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get());
1647 1647
1648 // Create an entry with attachment metadata and see that the attachment id 1648 // Create an entry with attachment metadata and see that the attachment id
1649 // is not linked. 1649 // is not linked.
1650 MutableEntry entry( 1650 MutableEntry entry(
1651 &trans, CREATE, PREFERENCES, trans.root_id(), "some entry"); 1651 &trans, CREATE, PREFERENCES, trans.root_id(), "some entry");
1652 entry.PutId(TestIdFactory::FromNumber(-1)); 1652 entry.PutId(TestIdFactory::FromNumber(-1));
(...skipping 23 matching lines...) Expand all
1676 ASSERT_TRUE(metahandles.empty()); 1676 ASSERT_TRUE(metahandles.empty());
1677 } 1677 }
1678 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); 1678 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto));
1679 } 1679 }
1680 1680
1681 // Verify that UpdateAttachmentId updates attachment_id and is_on_server flag. 1681 // Verify that UpdateAttachmentId updates attachment_id and is_on_server flag.
1682 TEST_F(SyncableDirectoryTest, MutableEntry_UpdateAttachmentId) { 1682 TEST_F(SyncableDirectoryTest, MutableEntry_UpdateAttachmentId) {
1683 sync_pb::AttachmentMetadata attachment_metadata; 1683 sync_pb::AttachmentMetadata attachment_metadata;
1684 sync_pb::AttachmentMetadataRecord* r1 = attachment_metadata.add_record(); 1684 sync_pb::AttachmentMetadataRecord* r1 = attachment_metadata.add_record();
1685 sync_pb::AttachmentMetadataRecord* r2 = attachment_metadata.add_record(); 1685 sync_pb::AttachmentMetadataRecord* r2 = attachment_metadata.add_record();
1686 *r1->mutable_id() = syncer::CreateAttachmentIdProto(); 1686 *r1->mutable_id() = syncer::CreateAttachmentIdProto(0, 0);
1687 *r2->mutable_id() = syncer::CreateAttachmentIdProto(); 1687 *r2->mutable_id() = syncer::CreateAttachmentIdProto(0, 0);
1688 sync_pb::AttachmentIdProto attachment_id_proto = r1->id(); 1688 sync_pb::AttachmentIdProto attachment_id_proto = r1->id();
1689 1689
1690 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); 1690 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get());
1691 1691
1692 MutableEntry entry( 1692 MutableEntry entry(
1693 &trans, CREATE, PREFERENCES, trans.root_id(), "some entry"); 1693 &trans, CREATE, PREFERENCES, trans.root_id(), "some entry");
1694 entry.PutId(TestIdFactory::FromNumber(-1)); 1694 entry.PutId(TestIdFactory::FromNumber(-1));
1695 entry.PutAttachmentMetadata(attachment_metadata); 1695 entry.PutAttachmentMetadata(attachment_metadata);
1696 1696
1697 const sync_pb::AttachmentMetadata& entry_metadata = 1697 const sync_pb::AttachmentMetadata& entry_metadata =
1698 entry.GetAttachmentMetadata(); 1698 entry.GetAttachmentMetadata();
1699 ASSERT_EQ(2, entry_metadata.record_size()); 1699 ASSERT_EQ(2, entry_metadata.record_size());
1700 ASSERT_FALSE(entry_metadata.record(0).is_on_server()); 1700 ASSERT_FALSE(entry_metadata.record(0).is_on_server());
1701 ASSERT_FALSE(entry_metadata.record(1).is_on_server()); 1701 ASSERT_FALSE(entry_metadata.record(1).is_on_server());
1702 ASSERT_FALSE(entry.GetIsUnsynced()); 1702 ASSERT_FALSE(entry.GetIsUnsynced());
1703 1703
1704 entry.MarkAttachmentAsOnServer(attachment_id_proto); 1704 entry.MarkAttachmentAsOnServer(attachment_id_proto);
1705 1705
1706 ASSERT_TRUE(entry_metadata.record(0).is_on_server()); 1706 ASSERT_TRUE(entry_metadata.record(0).is_on_server());
1707 ASSERT_FALSE(entry_metadata.record(1).is_on_server()); 1707 ASSERT_FALSE(entry_metadata.record(1).is_on_server());
1708 ASSERT_TRUE(entry.GetIsUnsynced()); 1708 ASSERT_TRUE(entry.GetIsUnsynced());
1709 } 1709 }
1710 1710
1711 // Verify that deleted entries with attachments will retain the attachments. 1711 // Verify that deleted entries with attachments will retain the attachments.
1712 TEST_F(SyncableDirectoryTest, Directory_DeleteDoesNotUnlinkAttachments) { 1712 TEST_F(SyncableDirectoryTest, Directory_DeleteDoesNotUnlinkAttachments) {
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(); 1716 syncer::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 const Id id = TestIdFactory::FromNumber(-1); 1719 const Id id = TestIdFactory::FromNumber(-1);
1720 1720
1721 // Create an entry with attachment metadata and see that the attachment id 1721 // Create an entry with attachment metadata and see that the attachment id
1722 // is linked. 1722 // is linked.
1723 CreateEntryWithAttachmentMetadata( 1723 CreateEntryWithAttachmentMetadata(
1724 PREFERENCES, "some entry", id, attachment_metadata); 1724 PREFERENCES, "some entry", id, attachment_metadata);
1725 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); 1725 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto));
1726 1726
1727 // Delete the entry and see that it's still linked because the entry hasn't 1727 // Delete the entry and see that it's still linked because the entry hasn't
1728 // yet been purged. 1728 // yet been purged.
1729 DeleteEntry(id); 1729 DeleteEntry(id);
1730 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); 1730 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto));
1731 1731
1732 // Reload the Directory, purging the deleted entry, and see that the 1732 // Reload the Directory, purging the deleted entry, and see that the
1733 // attachment is no longer linked. 1733 // attachment is no longer linked.
1734 SimulateSaveAndReloadDir(); 1734 SimulateSaveAndReloadDir();
1735 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); 1735 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto));
1736 } 1736 }
1737 1737
1738 // Verify that a given attachment can be referenced by multiple entries and that 1738 // Verify that a given attachment can be referenced by multiple entries and that
1739 // any one of the references is sufficient to ensure it remains linked. 1739 // any one of the references is sufficient to ensure it remains linked.
1740 TEST_F(SyncableDirectoryTest, Directory_LastReferenceUnlinksAttachments) { 1740 TEST_F(SyncableDirectoryTest, Directory_LastReferenceUnlinksAttachments) {
1741 // Create one attachment. 1741 // Create one attachment.
1742 sync_pb::AttachmentMetadata attachment_metadata; 1742 sync_pb::AttachmentMetadata attachment_metadata;
1743 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); 1743 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record();
1744 sync_pb::AttachmentIdProto attachment_id_proto = 1744 sync_pb::AttachmentIdProto attachment_id_proto =
1745 syncer::CreateAttachmentIdProto(); 1745 syncer::CreateAttachmentIdProto(0, 0);
1746 *record->mutable_id() = attachment_id_proto; 1746 *record->mutable_id() = attachment_id_proto;
1747 1747
1748 // Create two entries, each referencing the attachment. 1748 // Create two entries, each referencing the attachment.
1749 const Id id1 = TestIdFactory::FromNumber(-1); 1749 const Id id1 = TestIdFactory::FromNumber(-1);
1750 const Id id2 = TestIdFactory::FromNumber(-2); 1750 const Id id2 = TestIdFactory::FromNumber(-2);
1751 CreateEntryWithAttachmentMetadata( 1751 CreateEntryWithAttachmentMetadata(
1752 PREFERENCES, "some entry", id1, attachment_metadata); 1752 PREFERENCES, "some entry", id1, attachment_metadata);
1753 CreateEntryWithAttachmentMetadata( 1753 CreateEntryWithAttachmentMetadata(
1754 PREFERENCES, "some other entry", id2, attachment_metadata); 1754 PREFERENCES, "some other entry", id2, attachment_metadata);
1755 1755
1756 // See that the attachment is considered linked. 1756 // See that the attachment is considered linked.
1757 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); 1757 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto));
1758 1758
1759 // Delete the first entry, reload the Directory, see that the attachment is 1759 // Delete the first entry, reload the Directory, see that the attachment is
1760 // still linked. 1760 // still linked.
1761 DeleteEntry(id1); 1761 DeleteEntry(id1);
1762 SimulateSaveAndReloadDir(); 1762 SimulateSaveAndReloadDir();
1763 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); 1763 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto));
1764 1764
1765 // Delete the second entry, reload the Directory, see that the attachment is 1765 // Delete the second entry, reload the Directory, see that the attachment is
1766 // no loner linked. 1766 // no loner linked.
1767 DeleteEntry(id2); 1767 DeleteEntry(id2);
1768 SimulateSaveAndReloadDir(); 1768 SimulateSaveAndReloadDir();
1769 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); 1769 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto));
1770 } 1770 }
1771 1771
1772 TEST_F(SyncableDirectoryTest, Directory_GetAttachmentIdsToUpload) { 1772 TEST_F(SyncableDirectoryTest, Directory_GetAttachmentIdsToUpload) {
1773 // Create one attachment, referenced by two entries. 1773 // Create one attachment, referenced by two entries.
1774 AttachmentId attachment_id = AttachmentId::Create(); 1774 AttachmentId attachment_id = AttachmentId::Create(0, 0);
1775 sync_pb::AttachmentIdProto attachment_id_proto = attachment_id.GetProto(); 1775 sync_pb::AttachmentIdProto attachment_id_proto = attachment_id.GetProto();
1776 sync_pb::AttachmentMetadata attachment_metadata; 1776 sync_pb::AttachmentMetadata attachment_metadata;
1777 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); 1777 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record();
1778 *record->mutable_id() = attachment_id_proto; 1778 *record->mutable_id() = attachment_id_proto;
1779 const Id id1 = TestIdFactory::FromNumber(-1); 1779 const Id id1 = TestIdFactory::FromNumber(-1);
1780 const Id id2 = TestIdFactory::FromNumber(-2); 1780 const Id id2 = TestIdFactory::FromNumber(-2);
1781 CreateEntryWithAttachmentMetadata( 1781 CreateEntryWithAttachmentMetadata(
1782 PREFERENCES, "some entry", id1, attachment_metadata); 1782 PREFERENCES, "some entry", id1, attachment_metadata);
1783 CreateEntryWithAttachmentMetadata( 1783 CreateEntryWithAttachmentMetadata(
1784 PREFERENCES, "some other entry", id2, attachment_metadata); 1784 PREFERENCES, "some other entry", id2, attachment_metadata);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1876 ASSERT_EQ(1, p_root.GetTotalNodeCount() - 1); 1876 ASSERT_EQ(1, p_root.GetTotalNodeCount() - 1);
1877 Entry a_root(&trans, GET_BY_ID, a_root_id); 1877 Entry a_root(&trans, GET_BY_ID, a_root_id);
1878 ASSERT_EQ(item2_id, a_root.GetFirstChildId()); 1878 ASSERT_EQ(item2_id, a_root.GetFirstChildId());
1879 ASSERT_EQ(1, a_root.GetTotalNodeCount() - 1); 1879 ASSERT_EQ(1, a_root.GetTotalNodeCount() - 1);
1880 } 1880 }
1881 } 1881 }
1882 1882
1883 } // namespace syncable 1883 } // namespace syncable
1884 1884
1885 } // namespace syncer 1885 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/protocol/attachments.proto ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698