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

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

Issue 217063005: Separate SyncData methods into three groups, local, remote, and common. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@syncapi
Patch Set: 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
« sync/api/sync_data.h ('K') | « sync/api/sync_data.cc ('k') | no next file » | 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" 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 TEST_F(SyncDataTest, NoArgCtor) { 47 TEST_F(SyncDataTest, NoArgCtor) {
48 SyncData data; 48 SyncData data;
49 EXPECT_FALSE(data.IsValid()); 49 EXPECT_FALSE(data.IsValid());
50 } 50 }
51 51
52 TEST_F(SyncDataTest, CreateLocalDelete) { 52 TEST_F(SyncDataTest, CreateLocalDelete) {
53 SyncData data = SyncData::CreateLocalDelete(kSyncTag, kDatatype); 53 SyncData data = SyncData::CreateLocalDelete(kSyncTag, kDatatype);
54 EXPECT_TRUE(data.IsValid()); 54 EXPECT_TRUE(data.IsValid());
55 EXPECT_TRUE(data.IsLocal()); 55 EXPECT_TRUE(data.IsLocal());
56 EXPECT_EQ(kSyncTag, data.GetTag()); 56 EXPECT_EQ(kSyncTag, data.local().GetTag());
57 EXPECT_EQ(kDatatype, data.GetDataType()); 57 EXPECT_EQ(kDatatype, data.GetDataType());
58 } 58 }
59 59
60 TEST_F(SyncDataTest, CreateLocalData) { 60 TEST_F(SyncDataTest, CreateLocalData) {
61 specifics.mutable_preference(); 61 specifics.mutable_preference();
62 SyncData data = 62 SyncData data =
63 SyncData::CreateLocalData(kSyncTag, kNonUniqueTitle, specifics); 63 SyncData::CreateLocalData(kSyncTag, kNonUniqueTitle, specifics);
64 EXPECT_TRUE(data.IsValid()); 64 EXPECT_TRUE(data.IsValid());
65 EXPECT_TRUE(data.IsLocal()); 65 EXPECT_TRUE(data.IsLocal());
66 EXPECT_EQ(kSyncTag, data.GetTag()); 66 EXPECT_EQ(kSyncTag, data.local().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 scoped_refptr<base::RefCountedMemory> bytes(new base::RefCountedString);
75 AttachmentList attachments; 75 AttachmentList attachments;
76 attachments.push_back(Attachment::Create(bytes)); 76 attachments.push_back(Attachment::Create(bytes));
77 attachments.push_back(Attachment::Create(bytes)); 77 attachments.push_back(Attachment::Create(bytes));
78 attachments.push_back(Attachment::Create(bytes)); 78 attachments.push_back(Attachment::Create(bytes));
79 79
80 SyncData data = SyncData::CreateLocalDataWithAttachments( 80 SyncData data = SyncData::CreateLocalDataWithAttachments(
81 kSyncTag, kNonUniqueTitle, specifics, attachments); 81 kSyncTag, kNonUniqueTitle, specifics, attachments);
82 EXPECT_TRUE(data.IsValid()); 82 EXPECT_TRUE(data.IsValid());
83 EXPECT_TRUE(data.IsLocal()); 83 EXPECT_TRUE(data.IsLocal());
84 EXPECT_EQ(kSyncTag, data.GetTag()); 84 EXPECT_EQ(kSyncTag, data.local().GetTag());
85 EXPECT_EQ(kDatatype, data.GetDataType()); 85 EXPECT_EQ(kDatatype, data.GetDataType());
86 EXPECT_EQ(kNonUniqueTitle, data.GetTitle()); 86 EXPECT_EQ(kNonUniqueTitle, data.GetTitle());
87 EXPECT_TRUE(data.GetSpecifics().has_preference()); 87 EXPECT_TRUE(data.GetSpecifics().has_preference());
88 AttachmentIdList attachment_ids = data.GetAttachmentIds(); 88 AttachmentIdList attachment_ids = data.GetAttachmentIds();
89 EXPECT_EQ(3U, attachment_ids.size()); 89 EXPECT_EQ(3U, attachment_ids.size());
90 EXPECT_EQ(3U, data.GetLocalAttachmentsForUpload().size()); 90 EXPECT_EQ(3U, data.local().GetLocalAttachmentsForUpload().size());
91 } 91 }
92 92
93 TEST_F(SyncDataTest, CreateLocalDataWithAttachments_EmptyListOfAttachments) { 93 TEST_F(SyncDataTest, CreateLocalDataWithAttachments_EmptyListOfAttachments) {
94 specifics.mutable_preference(); 94 specifics.mutable_preference();
95 AttachmentList attachments; 95 AttachmentList attachments;
96 SyncData data = SyncData::CreateLocalDataWithAttachments( 96 SyncData data = SyncData::CreateLocalDataWithAttachments(
97 kSyncTag, kNonUniqueTitle, specifics, attachments); 97 kSyncTag, kNonUniqueTitle, specifics, attachments);
98 EXPECT_TRUE(data.IsValid()); 98 EXPECT_TRUE(data.IsValid());
99 EXPECT_TRUE(data.IsLocal()); 99 EXPECT_TRUE(data.IsLocal());
100 EXPECT_EQ(kSyncTag, data.GetTag()); 100 EXPECT_EQ(kSyncTag, data.local().GetTag());
101 EXPECT_EQ(kDatatype, data.GetDataType()); 101 EXPECT_EQ(kDatatype, data.GetDataType());
102 EXPECT_EQ(kNonUniqueTitle, data.GetTitle()); 102 EXPECT_EQ(kNonUniqueTitle, data.GetTitle());
103 EXPECT_TRUE(data.GetSpecifics().has_preference()); 103 EXPECT_TRUE(data.GetSpecifics().has_preference());
104 EXPECT_TRUE(data.GetAttachmentIds().empty()); 104 EXPECT_TRUE(data.GetAttachmentIds().empty());
105 EXPECT_TRUE(data.GetLocalAttachmentsForUpload().empty()); 105 EXPECT_TRUE(data.local().GetLocalAttachmentsForUpload().empty());
106 } 106 }
107 107
108 TEST_F(SyncDataTest, CreateRemoteData) { 108 TEST_F(SyncDataTest, CreateRemoteData) {
109 specifics.mutable_preference(); 109 specifics.mutable_preference();
110 SyncData data = SyncData::CreateRemoteData(kId, 110 SyncData data = SyncData::CreateRemoteData(kId,
111 specifics, 111 specifics,
112 kLastModifiedTime, 112 kLastModifiedTime,
113 AttachmentIdList(), 113 AttachmentIdList(),
114 attachment_service_proxy); 114 attachment_service_proxy);
115 EXPECT_TRUE(data.IsValid()); 115 EXPECT_TRUE(data.IsValid());
116 EXPECT_FALSE(data.IsLocal()); 116 EXPECT_FALSE(data.IsLocal());
117 EXPECT_EQ(kId, data.GetRemoteId()); 117 EXPECT_EQ(kId, data.remote().GetRemoteId());
118 EXPECT_EQ(kLastModifiedTime, data.GetRemoteModifiedTime()); 118 EXPECT_EQ(kLastModifiedTime, data.remote().GetRemoteModifiedTime());
119 EXPECT_TRUE(data.GetSpecifics().has_preference()); 119 EXPECT_TRUE(data.GetSpecifics().has_preference());
120 EXPECT_TRUE(data.GetAttachmentIds().empty()); 120 EXPECT_TRUE(data.GetAttachmentIds().empty());
121 } 121 }
122 122
123 TEST_F(SyncDataTest, CreateRemoteData_WithoutAttachmentService) { 123 TEST_F(SyncDataTest, CreateRemoteData_WithoutAttachmentService) {
124 specifics.mutable_preference(); 124 specifics.mutable_preference();
125 SyncData data = SyncData::CreateRemoteData(kId, specifics, kLastModifiedTime); 125 SyncData data = SyncData::CreateRemoteData(kId, specifics, kLastModifiedTime);
126 EXPECT_TRUE(data.IsValid()); 126 EXPECT_TRUE(data.IsValid());
127 EXPECT_FALSE(data.IsLocal()); 127 EXPECT_FALSE(data.IsLocal());
128 EXPECT_EQ(kId, data.GetRemoteId()); 128 EXPECT_EQ(kId, data.remote().GetRemoteId());
129 EXPECT_EQ(kLastModifiedTime, data.GetRemoteModifiedTime()); 129 EXPECT_EQ(kLastModifiedTime, data.remote().GetRemoteModifiedTime());
130 EXPECT_TRUE(data.GetSpecifics().has_preference()); 130 EXPECT_TRUE(data.GetSpecifics().has_preference());
131 } 131 }
132 132
133 // TODO(maniscalco): Add test cases that verify GetLocalAttachmentsForUpload and 133 // TODO(maniscalco): Add test cases that verify GetLocalAttachmentsForUpload and
134 // DropAttachments calls are passed through to the underlying AttachmentService. 134 // DropAttachments calls are passed through to the underlying AttachmentService.
135 135
136 } // namespace 136 } // namespace
137 137
138 } // namespace syncer 138 } // namespace syncer
OLDNEW
« sync/api/sync_data.h ('K') | « sync/api/sync_data.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698