| 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 1581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1592 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1592 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1593 { | 1593 { |
| 1594 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 1594 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 1595 | 1595 |
| 1596 // Create an entry with attachment metadata and see that the attachment id | 1596 // Create an entry with attachment metadata and see that the attachment id |
| 1597 // is not linked. | 1597 // is not linked. |
| 1598 MutableEntry entry( | 1598 MutableEntry entry( |
| 1599 &trans, CREATE, PREFERENCES, trans.root_id(), "some entry"); | 1599 &trans, CREATE, PREFERENCES, trans.root_id(), "some entry"); |
| 1600 entry.PutId(TestIdFactory::FromNumber(-1)); | 1600 entry.PutId(TestIdFactory::FromNumber(-1)); |
| 1601 entry.PutIsUnsynced(true); | 1601 entry.PutIsUnsynced(true); |
| 1602 |
| 1603 Directory::Metahandles metahandles; |
| 1602 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1604 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1605 dir()->GetMetahandlesByAttachmentId( |
| 1606 &trans, attachment_id_proto, &metahandles); |
| 1607 ASSERT_TRUE(metahandles.empty()); |
| 1603 | 1608 |
| 1604 // Now add the attachment metadata and see that Directory believes it is | 1609 // Now add the attachment metadata and see that Directory believes it is |
| 1605 // linked. | 1610 // linked. |
| 1606 entry.PutAttachmentMetadata(attachment_metadata); | 1611 entry.PutAttachmentMetadata(attachment_metadata); |
| 1607 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1612 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1613 dir()->GetMetahandlesByAttachmentId( |
| 1614 &trans, attachment_id_proto, &metahandles); |
| 1615 ASSERT_FALSE(metahandles.empty()); |
| 1616 ASSERT_EQ(metahandles[0], entry.GetMetahandle()); |
| 1608 | 1617 |
| 1609 // Clear out the attachment metadata and see that it's no longer linked. | 1618 // Clear out the attachment metadata and see that it's no longer linked. |
| 1610 sync_pb::AttachmentMetadata empty_attachment_metadata; | 1619 sync_pb::AttachmentMetadata empty_attachment_metadata; |
| 1611 entry.PutAttachmentMetadata(empty_attachment_metadata); | 1620 entry.PutAttachmentMetadata(empty_attachment_metadata); |
| 1612 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1621 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1622 dir()->GetMetahandlesByAttachmentId( |
| 1623 &trans, attachment_id_proto, &metahandles); |
| 1624 ASSERT_TRUE(metahandles.empty()); |
| 1613 } | 1625 } |
| 1614 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1626 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1615 } | 1627 } |
| 1616 | 1628 |
| 1629 // Verify that UpdateAttachmentId updates attachment_id and is_on_server flag. |
| 1630 TEST_F(SyncableDirectoryTest, MutableEntry_UpdateAttachmentId) { |
| 1631 sync_pb::AttachmentMetadata attachment_metadata; |
| 1632 sync_pb::AttachmentMetadataRecord* r1 = attachment_metadata.add_record(); |
| 1633 sync_pb::AttachmentMetadataRecord* r2 = attachment_metadata.add_record(); |
| 1634 *r1->mutable_id() = syncer::CreateAttachmentIdProto(); |
| 1635 *r2->mutable_id() = syncer::CreateAttachmentIdProto(); |
| 1636 sync_pb::AttachmentIdProto attachment_id_proto = r1->id(); |
| 1637 |
| 1638 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 1639 |
| 1640 MutableEntry entry( |
| 1641 &trans, CREATE, PREFERENCES, trans.root_id(), "some entry"); |
| 1642 entry.PutId(TestIdFactory::FromNumber(-1)); |
| 1643 entry.PutAttachmentMetadata(attachment_metadata); |
| 1644 |
| 1645 const sync_pb::AttachmentMetadata& entry_metadata = |
| 1646 entry.GetAttachmentMetadata(); |
| 1647 ASSERT_EQ(2, entry_metadata.record_size()); |
| 1648 ASSERT_FALSE(entry_metadata.record(0).is_on_server()); |
| 1649 ASSERT_FALSE(entry_metadata.record(1).is_on_server()); |
| 1650 ASSERT_FALSE(entry.GetIsUnsynced()); |
| 1651 |
| 1652 // TODO(pavely): When we add server info to proto, add test for it here. |
| 1653 entry.UpdateAttachmentIdWithServerInfo(attachment_id_proto); |
| 1654 |
| 1655 ASSERT_TRUE(entry_metadata.record(0).is_on_server()); |
| 1656 ASSERT_FALSE(entry_metadata.record(1).is_on_server()); |
| 1657 ASSERT_TRUE(entry.GetIsUnsynced()); |
| 1658 } |
| 1659 |
| 1617 // Verify that deleted entries with attachments will retain the attachments. | 1660 // Verify that deleted entries with attachments will retain the attachments. |
| 1618 TEST_F(SyncableDirectoryTest, Directory_DeleteDoesNotUnlinkAttachments) { | 1661 TEST_F(SyncableDirectoryTest, Directory_DeleteDoesNotUnlinkAttachments) { |
| 1619 sync_pb::AttachmentMetadata attachment_metadata; | 1662 sync_pb::AttachmentMetadata attachment_metadata; |
| 1620 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); | 1663 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); |
| 1621 sync_pb::AttachmentIdProto attachment_id_proto = | 1664 sync_pb::AttachmentIdProto attachment_id_proto = |
| 1622 syncer::CreateAttachmentIdProto(); | 1665 syncer::CreateAttachmentIdProto(); |
| 1623 *record->mutable_id() = attachment_id_proto; | 1666 *record->mutable_id() = attachment_id_proto; |
| 1624 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1667 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1625 const Id id = TestIdFactory::FromNumber(-1); | 1668 const Id id = TestIdFactory::FromNumber(-1); |
| 1626 | 1669 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1671 // Delete the second entry, reload the Directory, see that the attachment is | 1714 // Delete the second entry, reload the Directory, see that the attachment is |
| 1672 // no loner linked. | 1715 // no loner linked. |
| 1673 DeleteEntry(id2); | 1716 DeleteEntry(id2); |
| 1674 SimulateSaveAndReloadDir(); | 1717 SimulateSaveAndReloadDir(); |
| 1675 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1718 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1676 } | 1719 } |
| 1677 | 1720 |
| 1678 } // namespace syncable | 1721 } // namespace syncable |
| 1679 | 1722 |
| 1680 } // namespace syncer | 1723 } // namespace syncer |
| OLD | NEW |