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 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1555 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1555 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
1556 { | 1556 { |
1557 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 1557 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
1558 | 1558 |
1559 // Create an entry with attachment metadata and see that the attachment id | 1559 // Create an entry with attachment metadata and see that the attachment id |
1560 // is not linked. | 1560 // is not linked. |
1561 MutableEntry entry( | 1561 MutableEntry entry( |
1562 &trans, CREATE, PREFERENCES, trans.root_id(), "some entry"); | 1562 &trans, CREATE, PREFERENCES, trans.root_id(), "some entry"); |
1563 entry.PutId(TestIdFactory::FromNumber(-1)); | 1563 entry.PutId(TestIdFactory::FromNumber(-1)); |
1564 entry.PutIsUnsynced(true); | 1564 entry.PutIsUnsynced(true); |
| 1565 |
| 1566 Directory::Metahandles metahandles; |
1565 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1567 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1568 dir()->GetMetahandlesByAttachmentId( |
| 1569 &trans, attachment_id_proto, &metahandles); |
| 1570 ASSERT_TRUE(metahandles.empty()); |
1566 | 1571 |
1567 // Now add the attachment metadata and see that Directory believes it is | 1572 // Now add the attachment metadata and see that Directory believes it is |
1568 // linked. | 1573 // linked. |
1569 entry.PutAttachmentMetadata(attachment_metadata); | 1574 entry.PutAttachmentMetadata(attachment_metadata); |
1570 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1575 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1576 dir()->GetMetahandlesByAttachmentId( |
| 1577 &trans, attachment_id_proto, &metahandles); |
| 1578 ASSERT_FALSE(metahandles.empty()); |
| 1579 ASSERT_EQ(metahandles[0], entry.GetMetahandle()); |
1571 | 1580 |
1572 // Clear out the attachment metadata and see that it's no longer linked. | 1581 // Clear out the attachment metadata and see that it's no longer linked. |
1573 sync_pb::AttachmentMetadata empty_attachment_metadata; | 1582 sync_pb::AttachmentMetadata empty_attachment_metadata; |
1574 entry.PutAttachmentMetadata(empty_attachment_metadata); | 1583 entry.PutAttachmentMetadata(empty_attachment_metadata); |
1575 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1584 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1585 dir()->GetMetahandlesByAttachmentId( |
| 1586 &trans, attachment_id_proto, &metahandles); |
| 1587 ASSERT_TRUE(metahandles.empty()); |
1576 } | 1588 } |
1577 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1589 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
1578 } | 1590 } |
1579 | 1591 |
| 1592 // Verify that UpdateAttachmentId updates attachment_id and is_on_server flag. |
| 1593 TEST_F(SyncableDirectoryTest, MutableEntry_UpdateAttachmentId) { |
| 1594 sync_pb::AttachmentMetadata attachment_metadata; |
| 1595 sync_pb::AttachmentMetadataRecord* r1 = attachment_metadata.add_record(); |
| 1596 sync_pb::AttachmentMetadataRecord* r2 = attachment_metadata.add_record(); |
| 1597 *r1->mutable_id() = syncer::CreateAttachmentIdProto(); |
| 1598 *r2->mutable_id() = syncer::CreateAttachmentIdProto(); |
| 1599 sync_pb::AttachmentIdProto attachment_id_proto = r1->id(); |
| 1600 |
| 1601 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 1602 |
| 1603 MutableEntry entry( |
| 1604 &trans, CREATE, PREFERENCES, trans.root_id(), "some entry"); |
| 1605 entry.PutId(TestIdFactory::FromNumber(-1)); |
| 1606 entry.PutAttachmentMetadata(attachment_metadata); |
| 1607 |
| 1608 const sync_pb::AttachmentMetadata& entry_metadata = |
| 1609 entry.GetAttachmentMetadata(); |
| 1610 ASSERT_EQ(2, entry_metadata.record_size()); |
| 1611 ASSERT_FALSE(entry_metadata.record(0).is_on_server()); |
| 1612 ASSERT_FALSE(entry_metadata.record(1).is_on_server()); |
| 1613 ASSERT_FALSE(entry.GetIsUnsynced()); |
| 1614 |
| 1615 // TODO(pavely): When we add server info to proto, add test for it here. |
| 1616 entry.UpdateAttachmentIdWithServerInfo(attachment_id_proto); |
| 1617 |
| 1618 ASSERT_TRUE(entry_metadata.record(0).is_on_server()); |
| 1619 ASSERT_FALSE(entry_metadata.record(1).is_on_server()); |
| 1620 ASSERT_TRUE(entry.GetIsUnsynced()); |
| 1621 } |
| 1622 |
1580 // Verify that deleted entries with attachments will retain the attachments. | 1623 // Verify that deleted entries with attachments will retain the attachments. |
1581 TEST_F(SyncableDirectoryTest, Directory_DeleteDoesNotUnlinkAttachments) { | 1624 TEST_F(SyncableDirectoryTest, Directory_DeleteDoesNotUnlinkAttachments) { |
1582 sync_pb::AttachmentMetadata attachment_metadata; | 1625 sync_pb::AttachmentMetadata attachment_metadata; |
1583 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); | 1626 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); |
1584 sync_pb::AttachmentIdProto attachment_id_proto = | 1627 sync_pb::AttachmentIdProto attachment_id_proto = |
1585 syncer::CreateAttachmentIdProto(); | 1628 syncer::CreateAttachmentIdProto(); |
1586 *record->mutable_id() = attachment_id_proto; | 1629 *record->mutable_id() = attachment_id_proto; |
1587 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1630 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
1588 const Id id = TestIdFactory::FromNumber(-1); | 1631 const Id id = TestIdFactory::FromNumber(-1); |
1589 | 1632 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 // Delete the second entry, reload the Directory, see that the attachment is | 1677 // Delete the second entry, reload the Directory, see that the attachment is |
1635 // no loner linked. | 1678 // no loner linked. |
1636 DeleteEntry(id2); | 1679 DeleteEntry(id2); |
1637 SimulateSaveAndReloadDir(); | 1680 SimulateSaveAndReloadDir(); |
1638 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1681 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
1639 } | 1682 } |
1640 | 1683 |
1641 } // namespace syncable | 1684 } // namespace syncable |
1642 | 1685 |
1643 } // namespace syncer | 1686 } // namespace syncer |
OLD | NEW |