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

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

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

Powered by Google App Engine
This is Rietveld 408576698