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

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: Add AttachmentServiceBase allowing us to drop AsWeakPtr and RefCountedThreadSafe from AttachmentServiceProxy. Created 6 years, 8 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
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(attachment_service->AsWeakPtr()),
37 attachment_service_proxy(base::MessageLoopProxy::current(),
38 attachment_service->AsWeakPtr()) {}
39 base::MessageLoop loop;
40 sync_pb::EntitySpecifics specifics;
41 scoped_ptr<AttachmentServiceBase> attachment_service;
42 base::WeakPtr<AttachmentService> attachment_service_weak_ptr;
43 AttachmentServiceProxy attachment_service_proxy;
44 };
26 45
27 TEST_F(SyncDataTest, NoArgCtor) { 46 TEST_F(SyncDataTest, NoArgCtor) {
28 SyncData data; 47 SyncData data;
29 EXPECT_FALSE(data.IsValid()); 48 EXPECT_FALSE(data.IsValid());
30 } 49 }
31 50
32 TEST_F(SyncDataTest, CreateLocalDelete) { 51 TEST_F(SyncDataTest, CreateLocalDelete) {
33 SyncData data = SyncData::CreateLocalDelete(kSyncTag, kDatatype); 52 SyncData data = SyncData::CreateLocalDelete(kSyncTag, kDatatype);
34 EXPECT_TRUE(data.IsValid()); 53 EXPECT_TRUE(data.IsValid());
35 EXPECT_TRUE(data.IsLocal()); 54 EXPECT_TRUE(data.IsLocal());
36 EXPECT_EQ(kSyncTag, data.GetTag()); 55 EXPECT_EQ(kSyncTag, data.GetTag());
37 EXPECT_EQ(kDatatype, data.GetDataType()); 56 EXPECT_EQ(kDatatype, data.GetDataType());
38 } 57 }
39 58
40 TEST_F(SyncDataTest, CreateLocalData) { 59 TEST_F(SyncDataTest, CreateLocalData) {
41 sync_pb::EntitySpecifics specifics;
42 specifics.mutable_preference(); 60 specifics.mutable_preference();
43 SyncData data = 61 SyncData data =
44 SyncData::CreateLocalData(kSyncTag, kNonUniqueTitle, specifics); 62 SyncData::CreateLocalData(kSyncTag, kNonUniqueTitle, specifics);
45 EXPECT_TRUE(data.IsValid()); 63 EXPECT_TRUE(data.IsValid());
46 EXPECT_TRUE(data.IsLocal()); 64 EXPECT_TRUE(data.IsLocal());
47 EXPECT_EQ(kSyncTag, data.GetTag()); 65 EXPECT_EQ(kSyncTag, data.GetTag());
48 EXPECT_EQ(kDatatype, data.GetDataType()); 66 EXPECT_EQ(kDatatype, data.GetDataType());
49 EXPECT_EQ(kNonUniqueTitle, data.GetTitle()); 67 EXPECT_EQ(kNonUniqueTitle, data.GetTitle());
50 EXPECT_TRUE(data.GetSpecifics().has_preference()); 68 EXPECT_TRUE(data.GetSpecifics().has_preference());
51 } 69 }
52 70
71 TEST_F(SyncDataTest, CreateLocalDataWithAttachments) {
72 specifics.mutable_preference();
73 scoped_refptr<base::RefCountedMemory> bytes(new base::RefCountedString);
74 AttachmentList attachments;
75 attachments.push_back(Attachment::Create(bytes));
76 attachments.push_back(Attachment::Create(bytes));
77 attachments.push_back(Attachment::Create(bytes));
78
79 SyncData data = SyncData::CreateLocalDataWithAttachments(
80 kSyncTag, kNonUniqueTitle, specifics, attachments);
81 EXPECT_TRUE(data.IsValid());
82 EXPECT_TRUE(data.IsLocal());
83 EXPECT_EQ(kSyncTag, data.GetTag());
84 EXPECT_EQ(kDatatype, data.GetDataType());
85 EXPECT_EQ(kNonUniqueTitle, data.GetTitle());
86 EXPECT_TRUE(data.GetSpecifics().has_preference());
87 AttachmentIdList attachment_ids = data.GetAttachmentIds();
88 EXPECT_EQ(3U, attachment_ids.size());
89 }
90
91 TEST_F(SyncDataTest, CreateLocalDataWithAttachments_EmptyListOfAttachments) {
92 specifics.mutable_preference();
93 AttachmentList attachments;
94 SyncData data = SyncData::CreateLocalDataWithAttachments(
95 kSyncTag, kNonUniqueTitle, specifics, attachments);
96 EXPECT_TRUE(data.IsValid());
97 EXPECT_TRUE(data.IsLocal());
98 EXPECT_EQ(kSyncTag, data.GetTag());
99 EXPECT_EQ(kDatatype, data.GetDataType());
100 EXPECT_EQ(kNonUniqueTitle, data.GetTitle());
101 EXPECT_TRUE(data.GetSpecifics().has_preference());
102 EXPECT_TRUE(data.GetAttachmentIds().empty());
103 }
104
53 TEST_F(SyncDataTest, CreateRemoteData) { 105 TEST_F(SyncDataTest, CreateRemoteData) {
54 sync_pb::EntitySpecifics specifics; 106 specifics.mutable_preference();
107 SyncData data = SyncData::CreateRemoteData(kId,
108 specifics,
109 kLastModifiedTime,
110 AttachmentIdList(),
111 attachment_service_proxy);
112 EXPECT_TRUE(data.IsValid());
113 EXPECT_FALSE(data.IsLocal());
114 EXPECT_EQ(kId, data.GetRemoteId());
115 EXPECT_EQ(kLastModifiedTime, data.GetRemoteModifiedTime());
116 EXPECT_TRUE(data.GetSpecifics().has_preference());
117 EXPECT_TRUE(data.GetAttachmentIds().empty());
118 }
119
120 TEST_F(SyncDataTest, CreateRemoteData_WithoutAttachmentService) {
55 specifics.mutable_preference(); 121 specifics.mutable_preference();
56 SyncData data = SyncData::CreateRemoteData(kId, specifics, kLastModifiedTime); 122 SyncData data = SyncData::CreateRemoteData(kId, specifics, kLastModifiedTime);
57 EXPECT_TRUE(data.IsValid()); 123 EXPECT_TRUE(data.IsValid());
58 EXPECT_FALSE(data.IsLocal()); 124 EXPECT_FALSE(data.IsLocal());
59 EXPECT_EQ(kId, data.GetRemoteId()); 125 EXPECT_EQ(kId, data.GetRemoteId());
60 EXPECT_EQ(kLastModifiedTime, data.GetRemoteModifiedTime()); 126 EXPECT_EQ(kLastModifiedTime, data.GetRemoteModifiedTime());
61 EXPECT_TRUE(data.GetSpecifics().has_preference()); 127 EXPECT_TRUE(data.GetSpecifics().has_preference());
62 } 128 }
63 129
130 // TODO(maniscalco): Add test cases that verify GetAttachments and
131 // DropAttachments calls are passed through to the underlying AttachmentService.
132
64 } // namespace 133 } // namespace
65 134
66 } // namespace syncer 135 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698