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 "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 1766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
1785 | 1785 |
1786 // See that Directory reports that this attachment is not on the server. | 1786 // See that Directory reports that this attachment is not on the server. |
1787 AttachmentIdSet id_set; | 1787 AttachmentIdList ids; |
1788 { | 1788 { |
1789 ReadTransaction trans(FROM_HERE, dir().get()); | 1789 ReadTransaction trans(FROM_HERE, dir().get()); |
1790 dir()->GetAttachmentIdsToUpload(&trans, PREFERENCES, &id_set); | 1790 dir()->GetAttachmentIdsToUpload(&trans, PREFERENCES, &ids); |
1791 } | 1791 } |
1792 ASSERT_EQ(1U, id_set.size()); | 1792 ASSERT_EQ(1U, ids.size()); |
1793 ASSERT_EQ(attachment_id, *id_set.begin()); | 1793 ASSERT_EQ(attachment_id, *ids.begin()); |
1794 | 1794 |
1795 // Call again, but this time with a ModelType for which there are no entries. | 1795 // Call again, but this time with a ModelType for which there are no entries. |
1796 // See that Directory correctly reports that there are none. | 1796 // See that Directory correctly reports that there are none. |
1797 { | 1797 { |
1798 ReadTransaction trans(FROM_HERE, dir().get()); | 1798 ReadTransaction trans(FROM_HERE, dir().get()); |
1799 dir()->GetAttachmentIdsToUpload(&trans, PASSWORDS, &id_set); | 1799 dir()->GetAttachmentIdsToUpload(&trans, PASSWORDS, &ids); |
1800 } | 1800 } |
1801 ASSERT_TRUE(id_set.empty()); | 1801 ASSERT_TRUE(ids.empty()); |
1802 | 1802 |
1803 // Now, mark the attachment as "on the server" via entry_1. | 1803 // Now, mark the attachment as "on the server" via entry_1. |
1804 { | 1804 { |
1805 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 1805 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
1806 MutableEntry entry_1(&trans, GET_BY_ID, id1); | 1806 MutableEntry entry_1(&trans, GET_BY_ID, id1); |
1807 entry_1.MarkAttachmentAsOnServer(attachment_id_proto); | 1807 entry_1.MarkAttachmentAsOnServer(attachment_id_proto); |
1808 } | 1808 } |
1809 | 1809 |
1810 // See that Directory no longer reports that this attachment is not on the | 1810 // See that Directory no longer reports that this attachment is not on the |
1811 // server. | 1811 // server. |
1812 { | 1812 { |
1813 ReadTransaction trans(FROM_HERE, dir().get()); | 1813 ReadTransaction trans(FROM_HERE, dir().get()); |
1814 dir()->GetAttachmentIdsToUpload(&trans, PREFERENCES, &id_set); | 1814 dir()->GetAttachmentIdsToUpload(&trans, PREFERENCES, &ids); |
1815 } | 1815 } |
1816 ASSERT_TRUE(id_set.empty()); | 1816 ASSERT_TRUE(ids.empty()); |
1817 } | 1817 } |
1818 | 1818 |
1819 // Verify that the directory accepts entries with unset parent ID. | 1819 // Verify that the directory accepts entries with unset parent ID. |
1820 TEST_F(SyncableDirectoryTest, MutableEntry_ImplicitParentId) { | 1820 TEST_F(SyncableDirectoryTest, MutableEntry_ImplicitParentId) { |
1821 TestIdFactory id_factory; | 1821 TestIdFactory id_factory; |
1822 const Id root_id = TestIdFactory::root(); | 1822 const Id root_id = TestIdFactory::root(); |
1823 const Id p_root_id = id_factory.NewServerId(); | 1823 const Id p_root_id = id_factory.NewServerId(); |
1824 const Id a_root_id = id_factory.NewServerId(); | 1824 const Id a_root_id = id_factory.NewServerId(); |
1825 const Id item1_id = id_factory.NewServerId(); | 1825 const Id item1_id = id_factory.NewServerId(); |
1826 const Id item2_id = id_factory.NewServerId(); | 1826 const Id item2_id = id_factory.NewServerId(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |