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/api/sync_data.h" | 5 #include "sync/api/sync_data.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 EXPECT_TRUE(data.IsValid()); | 64 EXPECT_TRUE(data.IsValid()); |
65 EXPECT_TRUE(data.IsLocal()); | 65 EXPECT_TRUE(data.IsLocal()); |
66 EXPECT_EQ(kSyncTag, SyncDataLocal(data).GetTag()); | 66 EXPECT_EQ(kSyncTag, SyncDataLocal(data).GetTag()); |
67 EXPECT_EQ(kDatatype, data.GetDataType()); | 67 EXPECT_EQ(kDatatype, data.GetDataType()); |
68 EXPECT_EQ(kNonUniqueTitle, data.GetTitle()); | 68 EXPECT_EQ(kNonUniqueTitle, data.GetTitle()); |
69 EXPECT_TRUE(data.GetSpecifics().has_preference()); | 69 EXPECT_TRUE(data.GetSpecifics().has_preference()); |
70 } | 70 } |
71 | 71 |
72 TEST_F(SyncDataTest, CreateLocalDataWithAttachments) { | 72 TEST_F(SyncDataTest, CreateLocalDataWithAttachments) { |
73 specifics.mutable_preference(); | 73 specifics.mutable_preference(); |
74 scoped_refptr<base::RefCountedMemory> bytes(new base::RefCountedString); | 74 AttachmentIdList attachment_ids; |
75 AttachmentList attachments; | 75 attachment_ids.push_back(AttachmentId::Create()); |
76 attachments.push_back(Attachment::Create(bytes)); | 76 attachment_ids.push_back(AttachmentId::Create()); |
77 attachments.push_back(Attachment::Create(bytes)); | 77 attachment_ids.push_back(AttachmentId::Create()); |
78 attachments.push_back(Attachment::Create(bytes)); | |
79 | 78 |
80 SyncData data = SyncData::CreateLocalDataWithAttachments( | 79 SyncData data = SyncData::CreateLocalDataWithAttachments( |
81 kSyncTag, kNonUniqueTitle, specifics, attachments); | 80 kSyncTag, kNonUniqueTitle, specifics, attachment_ids); |
82 EXPECT_TRUE(data.IsValid()); | 81 EXPECT_TRUE(data.IsValid()); |
83 EXPECT_TRUE(data.IsLocal()); | 82 EXPECT_TRUE(data.IsLocal()); |
84 EXPECT_EQ(kSyncTag, SyncDataLocal(data).GetTag()); | 83 EXPECT_EQ(kSyncTag, SyncDataLocal(data).GetTag()); |
85 EXPECT_EQ(kDatatype, data.GetDataType()); | 84 EXPECT_EQ(kDatatype, data.GetDataType()); |
86 EXPECT_EQ(kNonUniqueTitle, data.GetTitle()); | 85 EXPECT_EQ(kNonUniqueTitle, data.GetTitle()); |
87 EXPECT_TRUE(data.GetSpecifics().has_preference()); | 86 EXPECT_TRUE(data.GetSpecifics().has_preference()); |
88 AttachmentIdList attachment_ids = data.GetAttachmentIds(); | 87 attachment_ids = data.GetAttachmentIds(); |
89 EXPECT_EQ(3U, attachment_ids.size()); | 88 EXPECT_EQ(3U, attachment_ids.size()); |
90 EXPECT_EQ(3U, SyncDataLocal(data).GetLocalAttachmentsForUpload().size()); | |
91 } | 89 } |
92 | 90 |
93 TEST_F(SyncDataTest, CreateLocalDataWithAttachments_EmptyListOfAttachments) { | 91 TEST_F(SyncDataTest, CreateLocalDataWithAttachments_EmptyListOfAttachments) { |
94 specifics.mutable_preference(); | 92 specifics.mutable_preference(); |
95 AttachmentList attachments; | 93 AttachmentIdList attachment_ids; |
96 SyncData data = SyncData::CreateLocalDataWithAttachments( | 94 SyncData data = SyncData::CreateLocalDataWithAttachments( |
97 kSyncTag, kNonUniqueTitle, specifics, attachments); | 95 kSyncTag, kNonUniqueTitle, specifics, attachment_ids); |
98 EXPECT_TRUE(data.IsValid()); | 96 EXPECT_TRUE(data.IsValid()); |
99 EXPECT_TRUE(data.IsLocal()); | 97 EXPECT_TRUE(data.IsLocal()); |
100 EXPECT_EQ(kSyncTag, SyncDataLocal(data).GetTag()); | 98 EXPECT_EQ(kSyncTag, SyncDataLocal(data).GetTag()); |
101 EXPECT_EQ(kDatatype, data.GetDataType()); | 99 EXPECT_EQ(kDatatype, data.GetDataType()); |
102 EXPECT_EQ(kNonUniqueTitle, data.GetTitle()); | 100 EXPECT_EQ(kNonUniqueTitle, data.GetTitle()); |
103 EXPECT_TRUE(data.GetSpecifics().has_preference()); | 101 EXPECT_TRUE(data.GetSpecifics().has_preference()); |
104 EXPECT_TRUE(data.GetAttachmentIds().empty()); | 102 EXPECT_TRUE(data.GetAttachmentIds().empty()); |
105 EXPECT_TRUE(SyncDataLocal(data).GetLocalAttachmentsForUpload().empty()); | |
106 } | 103 } |
107 | 104 |
108 TEST_F(SyncDataTest, CreateRemoteData) { | 105 TEST_F(SyncDataTest, CreateRemoteData) { |
109 specifics.mutable_preference(); | 106 specifics.mutable_preference(); |
110 SyncData data = SyncData::CreateRemoteData(kId, | 107 SyncData data = SyncData::CreateRemoteData(kId, |
111 specifics, | 108 specifics, |
112 kLastModifiedTime, | 109 kLastModifiedTime, |
113 AttachmentIdList(), | 110 AttachmentIdList(), |
114 attachment_service_proxy); | 111 attachment_service_proxy); |
115 EXPECT_TRUE(data.IsValid()); | 112 EXPECT_TRUE(data.IsValid()); |
116 EXPECT_FALSE(data.IsLocal()); | 113 EXPECT_FALSE(data.IsLocal()); |
117 EXPECT_EQ(kId, SyncDataRemote(data).GetId()); | 114 EXPECT_EQ(kId, SyncDataRemote(data).GetId()); |
118 EXPECT_EQ(kLastModifiedTime, SyncDataRemote(data).GetModifiedTime()); | 115 EXPECT_EQ(kLastModifiedTime, SyncDataRemote(data).GetModifiedTime()); |
119 EXPECT_TRUE(data.GetSpecifics().has_preference()); | 116 EXPECT_TRUE(data.GetSpecifics().has_preference()); |
120 EXPECT_TRUE(data.GetAttachmentIds().empty()); | 117 EXPECT_TRUE(data.GetAttachmentIds().empty()); |
121 } | 118 } |
122 | 119 |
123 // TODO(maniscalco): Add test cases that verify GetLocalAttachmentsForUpload and | 120 // TODO(maniscalco): Add test cases that verify GetLocalAttachmentsForUpload and |
124 // DropAttachments calls are passed through to the underlying AttachmentService. | 121 // DropAttachments calls are passed through to the underlying AttachmentService. |
125 | 122 |
126 } // namespace | 123 } // namespace |
127 | 124 |
128 } // namespace syncer | 125 } // namespace syncer |
OLD | NEW |