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

Side by Side Diff: sync/api/sync_data_unittest.cc

Issue 187303006: Update sync API to support attachments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@attachmentapi
Patch Set: Rename GetAttachments to GetLocalAttachmentsForUpload. Created 6 years, 9 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 | « sync/api/sync_data.cc ('k') | sync/internal_api/base_node.cc » ('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 "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"
10 #include "base/message_loop/message_loop.h"
11 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "sync/api/attachments/attachment_id.h"
14 #include "sync/api/attachments/attachment_service.h"
15 #include "sync/api/attachments/attachment_service_proxy.h"
16 #include "sync/api/attachments/fake_attachment_service.h"
10 #include "sync/protocol/sync.pb.h" 17 #include "sync/protocol/sync.pb.h"
11 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
12 19
13 using std::string; 20 using std::string;
14 21
15 namespace syncer { 22 namespace syncer {
16 23
17 namespace { 24 namespace {
18 25
19 const string kSyncTag = "3984729834"; 26 const string kSyncTag = "3984729834";
20 const ModelType kDatatype = syncer::PREFERENCES; 27 const ModelType kDatatype = syncer::PREFERENCES;
21 const string kNonUniqueTitle = "my preference"; 28 const string kNonUniqueTitle = "my preference";
22 const int64 kId = 439829; 29 const int64 kId = 439829;
23 const base::Time kLastModifiedTime = base::Time(); 30 const base::Time kLastModifiedTime = base::Time();
24 31
25 typedef testing::Test SyncDataTest; 32 class SyncDataTest : public testing::Test {
33 protected:
34 SyncDataTest()
35 : attachment_service(FakeAttachmentService::CreateForTest()),
36 attachment_service_weak_ptr_factory(attachment_service.get()),
37 attachment_service_proxy(
38 base::MessageLoopProxy::current(),
39 attachment_service_weak_ptr_factory.GetWeakPtr()) {}
40 base::MessageLoop loop;
41 sync_pb::EntitySpecifics specifics;
42 scoped_ptr<AttachmentService> attachment_service;
43 base::WeakPtrFactory<AttachmentService> attachment_service_weak_ptr_factory;
44 AttachmentServiceProxy attachment_service_proxy;
45 };
26 46
27 TEST_F(SyncDataTest, NoArgCtor) { 47 TEST_F(SyncDataTest, NoArgCtor) {
28 SyncData data; 48 SyncData data;
29 EXPECT_FALSE(data.IsValid()); 49 EXPECT_FALSE(data.IsValid());
30 } 50 }
31 51
32 TEST_F(SyncDataTest, CreateLocalDelete) { 52 TEST_F(SyncDataTest, CreateLocalDelete) {
33 SyncData data = SyncData::CreateLocalDelete(kSyncTag, kDatatype); 53 SyncData data = SyncData::CreateLocalDelete(kSyncTag, kDatatype);
34 EXPECT_TRUE(data.IsValid()); 54 EXPECT_TRUE(data.IsValid());
35 EXPECT_TRUE(data.IsLocal()); 55 EXPECT_TRUE(data.IsLocal());
36 EXPECT_EQ(kSyncTag, data.GetTag()); 56 EXPECT_EQ(kSyncTag, data.GetTag());
37 EXPECT_EQ(kDatatype, data.GetDataType()); 57 EXPECT_EQ(kDatatype, data.GetDataType());
38 } 58 }
39 59
40 TEST_F(SyncDataTest, CreateLocalData) { 60 TEST_F(SyncDataTest, CreateLocalData) {
41 sync_pb::EntitySpecifics specifics;
42 specifics.mutable_preference(); 61 specifics.mutable_preference();
43 SyncData data = 62 SyncData data =
44 SyncData::CreateLocalData(kSyncTag, kNonUniqueTitle, specifics); 63 SyncData::CreateLocalData(kSyncTag, kNonUniqueTitle, specifics);
45 EXPECT_TRUE(data.IsValid()); 64 EXPECT_TRUE(data.IsValid());
46 EXPECT_TRUE(data.IsLocal()); 65 EXPECT_TRUE(data.IsLocal());
47 EXPECT_EQ(kSyncTag, data.GetTag()); 66 EXPECT_EQ(kSyncTag, data.GetTag());
48 EXPECT_EQ(kDatatype, data.GetDataType()); 67 EXPECT_EQ(kDatatype, data.GetDataType());
49 EXPECT_EQ(kNonUniqueTitle, data.GetTitle()); 68 EXPECT_EQ(kNonUniqueTitle, data.GetTitle());
50 EXPECT_TRUE(data.GetSpecifics().has_preference()); 69 EXPECT_TRUE(data.GetSpecifics().has_preference());
51 } 70 }
52 71
72 TEST_F(SyncDataTest, CreateLocalDataWithAttachments) {
73 specifics.mutable_preference();
74 scoped_refptr<base::RefCountedMemory> bytes(new base::RefCountedString);
75 AttachmentList attachments;
76 attachments.push_back(Attachment::Create(bytes));
77 attachments.push_back(Attachment::Create(bytes));
78 attachments.push_back(Attachment::Create(bytes));
79
80 SyncData data = SyncData::CreateLocalDataWithAttachments(
81 kSyncTag, kNonUniqueTitle, specifics, attachments);
82 EXPECT_TRUE(data.IsValid());
83 EXPECT_TRUE(data.IsLocal());
84 EXPECT_EQ(kSyncTag, data.GetTag());
85 EXPECT_EQ(kDatatype, data.GetDataType());
86 EXPECT_EQ(kNonUniqueTitle, data.GetTitle());
87 EXPECT_TRUE(data.GetSpecifics().has_preference());
88 AttachmentIdList attachment_ids = data.GetAttachmentIds();
89 EXPECT_EQ(3U, attachment_ids.size());
90 EXPECT_EQ(3U, data.GetLocalAttachmentsForUpload().size());
91 }
92
93 TEST_F(SyncDataTest, CreateLocalDataWithAttachments_EmptyListOfAttachments) {
94 specifics.mutable_preference();
95 AttachmentList attachments;
96 SyncData data = SyncData::CreateLocalDataWithAttachments(
97 kSyncTag, kNonUniqueTitle, specifics, attachments);
98 EXPECT_TRUE(data.IsValid());
99 EXPECT_TRUE(data.IsLocal());
100 EXPECT_EQ(kSyncTag, data.GetTag());
101 EXPECT_EQ(kDatatype, data.GetDataType());
102 EXPECT_EQ(kNonUniqueTitle, data.GetTitle());
103 EXPECT_TRUE(data.GetSpecifics().has_preference());
104 EXPECT_TRUE(data.GetAttachmentIds().empty());
105 EXPECT_TRUE(data.GetLocalAttachmentsForUpload().empty());
106 }
107
53 TEST_F(SyncDataTest, CreateRemoteData) { 108 TEST_F(SyncDataTest, CreateRemoteData) {
54 sync_pb::EntitySpecifics specifics; 109 specifics.mutable_preference();
110 SyncData data = SyncData::CreateRemoteData(kId,
111 specifics,
112 kLastModifiedTime,
113 AttachmentIdList(),
114 attachment_service_proxy);
115 EXPECT_TRUE(data.IsValid());
116 EXPECT_FALSE(data.IsLocal());
117 EXPECT_EQ(kId, data.GetRemoteId());
118 EXPECT_EQ(kLastModifiedTime, data.GetRemoteModifiedTime());
119 EXPECT_TRUE(data.GetSpecifics().has_preference());
120 EXPECT_TRUE(data.GetAttachmentIds().empty());
121 }
122
123 TEST_F(SyncDataTest, CreateRemoteData_WithoutAttachmentService) {
55 specifics.mutable_preference(); 124 specifics.mutable_preference();
56 SyncData data = SyncData::CreateRemoteData(kId, specifics, kLastModifiedTime); 125 SyncData data = SyncData::CreateRemoteData(kId, specifics, kLastModifiedTime);
57 EXPECT_TRUE(data.IsValid()); 126 EXPECT_TRUE(data.IsValid());
58 EXPECT_FALSE(data.IsLocal()); 127 EXPECT_FALSE(data.IsLocal());
59 EXPECT_EQ(kId, data.GetRemoteId()); 128 EXPECT_EQ(kId, data.GetRemoteId());
60 EXPECT_EQ(kLastModifiedTime, data.GetRemoteModifiedTime()); 129 EXPECT_EQ(kLastModifiedTime, data.GetRemoteModifiedTime());
61 EXPECT_TRUE(data.GetSpecifics().has_preference()); 130 EXPECT_TRUE(data.GetSpecifics().has_preference());
62 } 131 }
63 132
133 // TODO(maniscalco): Add test cases that verify GetLocalAttachmentsForUpload and
134 // DropAttachments calls are passed through to the underlying AttachmentService.
135
64 } // namespace 136 } // namespace
65 137
66 } // namespace syncer 138 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/api/sync_data.cc ('k') | sync/internal_api/base_node.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698