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

Side by Side Diff: sync/protocol/proto_value_conversions_unittest.cc

Issue 10825137: FYI: Control Data + Per-Device Metadata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add PER_USER_METADATA, refactor some encryption code Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Keep this file in sync with the .proto files in this directory. 5 // Keep this file in sync with the .proto files in this directory.
6 6
7 #include "sync/protocol/proto_value_conversions.h" 7 #include "sync/protocol/proto_value_conversions.h"
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "sync/internal_api/public/base/model_type.h" 11 #include "sync/internal_api/public/base/model_type.h"
12 #include "sync/protocol/app_notification_specifics.pb.h" 12 #include "sync/protocol/app_notification_specifics.pb.h"
13 #include "sync/protocol/app_setting_specifics.pb.h" 13 #include "sync/protocol/app_setting_specifics.pb.h"
14 #include "sync/protocol/app_specifics.pb.h" 14 #include "sync/protocol/app_specifics.pb.h"
15 #include "sync/protocol/autofill_specifics.pb.h" 15 #include "sync/protocol/autofill_specifics.pb.h"
16 #include "sync/protocol/bookmark_specifics.pb.h" 16 #include "sync/protocol/bookmark_specifics.pb.h"
17 #include "sync/protocol/encryption.pb.h" 17 #include "sync/protocol/encryption.pb.h"
18 #include "sync/protocol/extension_setting_specifics.pb.h" 18 #include "sync/protocol/extension_setting_specifics.pb.h"
19 #include "sync/protocol/extension_specifics.pb.h" 19 #include "sync/protocol/extension_specifics.pb.h"
20 #include "sync/protocol/nigori_specifics.pb.h" 20 #include "sync/protocol/nigori_specifics.pb.h"
21 #include "sync/protocol/password_specifics.pb.h" 21 #include "sync/protocol/password_specifics.pb.h"
22 #include "sync/protocol/per_device_specifics.pb.h"
23 #include "sync/protocol/per_user_specifics.pb.h"
22 #include "sync/protocol/preference_specifics.pb.h" 24 #include "sync/protocol/preference_specifics.pb.h"
23 #include "sync/protocol/search_engine_specifics.pb.h" 25 #include "sync/protocol/search_engine_specifics.pb.h"
24 #include "sync/protocol/session_specifics.pb.h" 26 #include "sync/protocol/session_specifics.pb.h"
25 #include "sync/protocol/sync.pb.h" 27 #include "sync/protocol/sync.pb.h"
26 #include "sync/protocol/theme_specifics.pb.h" 28 #include "sync/protocol/theme_specifics.pb.h"
27 #include "sync/protocol/typed_url_specifics.pb.h" 29 #include "sync/protocol/typed_url_specifics.pb.h"
28 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
29 31
30 namespace syncer { 32 namespace syncer {
31 namespace { 33 namespace {
32 34
33 class ProtoValueConversionsTest : public testing::Test { 35 class ProtoValueConversionsTest : public testing::Test {
34 protected: 36 protected:
35 template <class T> 37 template <class T>
36 void TestSpecificsToValue( 38 void TestSpecificsToValue(
37 DictionaryValue* (*specifics_to_value)(const T&)) { 39 DictionaryValue* (*specifics_to_value)(const T&)) {
38 const T& specifics(T::default_instance()); 40 const T& specifics(T::default_instance());
39 scoped_ptr<DictionaryValue> value(specifics_to_value(specifics)); 41 scoped_ptr<DictionaryValue> value(specifics_to_value(specifics));
40 // We can't do much but make sure that the returned value has 42 // We can't do much but make sure that the returned value is not null.
41 // something in it. 43 EXPECT_TRUE(value.get());
42 EXPECT_FALSE(value->empty());
43 } 44 }
44 }; 45 };
45 46
46 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) { 47 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) {
47 // If this number changes, that means we added or removed a data 48 // If this number changes, that means we added or removed a data
48 // type. Don't forget to add a unit test for {New 49 // type. Don't forget to add a unit test for {New
49 // type}SpecificsToValue below. 50 // type}SpecificsToValue below.
50 EXPECT_EQ(17, MODEL_TYPE_COUNT); 51 EXPECT_EQ(19, MODEL_TYPE_COUNT);
51 52
52 // We'd also like to check if we changed any field in our messages. 53 // We'd also like to check if we changed any field in our messages.
53 // However, that's hard to do: sizeof could work, but it's 54 // However, that's hard to do: sizeof could work, but it's
54 // platform-dependent. default_instance().ByteSize() won't change 55 // platform-dependent. default_instance().ByteSize() won't change
55 // for most changes, since most of our fields are optional. So we 56 // for most changes, since most of our fields are optional. So we
56 // just settle for comments in the proto files. 57 // just settle for comments in the proto files.
57 } 58 }
58 59
59 TEST_F(ProtoValueConversionsTest, EncryptedDataToValue) { 60 TEST_F(ProtoValueConversionsTest, EncryptedDataToValue) {
60 TestSpecificsToValue(EncryptedDataToValue); 61 TestSpecificsToValue(EncryptedDataToValue);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 130 }
130 131
131 TEST_F(ProtoValueConversionsTest, NigoriSpecificsToValue) { 132 TEST_F(ProtoValueConversionsTest, NigoriSpecificsToValue) {
132 TestSpecificsToValue(NigoriSpecificsToValue); 133 TestSpecificsToValue(NigoriSpecificsToValue);
133 } 134 }
134 135
135 TEST_F(ProtoValueConversionsTest, PasswordSpecificsToValue) { 136 TEST_F(ProtoValueConversionsTest, PasswordSpecificsToValue) {
136 TestSpecificsToValue(PasswordSpecificsToValue); 137 TestSpecificsToValue(PasswordSpecificsToValue);
137 } 138 }
138 139
140 TEST_F(ProtoValueConversionsTest, PerDeviceSpecificsToValue) {
141 TestSpecificsToValue(PerDeviceSpecificsToValue);
142 }
143
144 TEST_F(ProtoValueConversionsTest, PerUserSpecificsToValue) {
145 TestSpecificsToValue(PerUserSpecificsToValue);
146 }
147
139 TEST_F(ProtoValueConversionsTest, PreferenceSpecificsToValue) { 148 TEST_F(ProtoValueConversionsTest, PreferenceSpecificsToValue) {
140 TestSpecificsToValue(PreferenceSpecificsToValue); 149 TestSpecificsToValue(PreferenceSpecificsToValue);
141 } 150 }
142 151
143 TEST_F(ProtoValueConversionsTest, SearchEngineSpecificsToValue) { 152 TEST_F(ProtoValueConversionsTest, SearchEngineSpecificsToValue) {
144 TestSpecificsToValue(SearchEngineSpecificsToValue); 153 TestSpecificsToValue(SearchEngineSpecificsToValue);
145 } 154 }
146 155
147 TEST_F(ProtoValueConversionsTest, SessionSpecificsToValue) { 156 TEST_F(ProtoValueConversionsTest, SessionSpecificsToValue) {
148 TestSpecificsToValue(SessionSpecificsToValue); 157 TestSpecificsToValue(SessionSpecificsToValue);
(...skipping 18 matching lines...) Expand all
167 SET_FIELD(app); 176 SET_FIELD(app);
168 SET_FIELD(app_notification); 177 SET_FIELD(app_notification);
169 SET_FIELD(app_setting); 178 SET_FIELD(app_setting);
170 SET_FIELD(autofill); 179 SET_FIELD(autofill);
171 SET_FIELD(autofill_profile); 180 SET_FIELD(autofill_profile);
172 SET_FIELD(bookmark); 181 SET_FIELD(bookmark);
173 SET_FIELD(extension); 182 SET_FIELD(extension);
174 SET_FIELD(extension_setting); 183 SET_FIELD(extension_setting);
175 SET_FIELD(nigori); 184 SET_FIELD(nigori);
176 SET_FIELD(password); 185 SET_FIELD(password);
186 SET_FIELD(per_device_metadata);
187 SET_FIELD(per_user_metadata);
177 SET_FIELD(preference); 188 SET_FIELD(preference);
178 SET_FIELD(search_engine); 189 SET_FIELD(search_engine);
179 SET_FIELD(session); 190 SET_FIELD(session);
180 SET_FIELD(theme); 191 SET_FIELD(theme);
181 SET_FIELD(typed_url); 192 SET_FIELD(typed_url);
182 193
183 #undef SET_FIELD 194 #undef SET_FIELD
184 195
185 scoped_ptr<DictionaryValue> value(EntitySpecificsToValue(specifics)); 196 scoped_ptr<DictionaryValue> value(EntitySpecificsToValue(specifics));
186 EXPECT_EQ(MODEL_TYPE_COUNT - FIRST_REAL_MODEL_TYPE, 197 EXPECT_EQ(MODEL_TYPE_COUNT - FIRST_REAL_MODEL_TYPE,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 255
245 scoped_ptr<DictionaryValue> value_without_specifics( 256 scoped_ptr<DictionaryValue> value_without_specifics(
246 ClientToServerResponseToValue(message, false /* include_specifics */)); 257 ClientToServerResponseToValue(message, false /* include_specifics */));
247 EXPECT_FALSE(value_without_specifics->empty()); 258 EXPECT_FALSE(value_without_specifics->empty());
248 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), 259 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()),
249 "get_updates.entries")); 260 "get_updates.entries"));
250 } 261 }
251 262
252 } // namespace 263 } // namespace
253 } // namespace syncer 264 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698