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

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

Issue 11734009: sync: Add ControlPreference protobuf and supporting code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Daily rebase Created 7 years, 11 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
« no previous file with comments | « sync/protocol/proto_value_conversions.cc ('k') | sync/protocol/sync.proto » ('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 (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/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "sync/internal_api/public/base/model_type.h" 13 #include "sync/internal_api/public/base/model_type.h"
14 #include "sync/protocol/app_notification_specifics.pb.h" 14 #include "sync/protocol/app_notification_specifics.pb.h"
15 #include "sync/protocol/app_setting_specifics.pb.h" 15 #include "sync/protocol/app_setting_specifics.pb.h"
16 #include "sync/protocol/app_specifics.pb.h" 16 #include "sync/protocol/app_specifics.pb.h"
17 #include "sync/protocol/autofill_specifics.pb.h" 17 #include "sync/protocol/autofill_specifics.pb.h"
18 #include "sync/protocol/bookmark_specifics.pb.h" 18 #include "sync/protocol/bookmark_specifics.pb.h"
19 #include "sync/protocol/device_info_specifics.pb.h" 19 #include "sync/protocol/device_info_specifics.pb.h"
20 #include "sync/protocol/encryption.pb.h" 20 #include "sync/protocol/encryption.pb.h"
21 #include "sync/protocol/experiments_specifics.pb.h" 21 #include "sync/protocol/experiments_specifics.pb.h"
22 #include "sync/protocol/extension_setting_specifics.pb.h" 22 #include "sync/protocol/extension_setting_specifics.pb.h"
23 #include "sync/protocol/extension_specifics.pb.h" 23 #include "sync/protocol/extension_specifics.pb.h"
24 #include "sync/protocol/nigori_specifics.pb.h" 24 #include "sync/protocol/nigori_specifics.pb.h"
25 #include "sync/protocol/password_specifics.pb.h" 25 #include "sync/protocol/password_specifics.pb.h"
26 #include "sync/protocol/preference_specifics.pb.h" 26 #include "sync/protocol/preference_specifics.pb.h"
27 #include "sync/protocol/priority_preference_specifics.pb.h"
27 #include "sync/protocol/search_engine_specifics.pb.h" 28 #include "sync/protocol/search_engine_specifics.pb.h"
28 #include "sync/protocol/session_specifics.pb.h" 29 #include "sync/protocol/session_specifics.pb.h"
29 #include "sync/protocol/sync.pb.h" 30 #include "sync/protocol/sync.pb.h"
30 #include "sync/protocol/theme_specifics.pb.h" 31 #include "sync/protocol/theme_specifics.pb.h"
31 #include "sync/protocol/typed_url_specifics.pb.h" 32 #include "sync/protocol/typed_url_specifics.pb.h"
32 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
33 34
34 namespace syncer { 35 namespace syncer {
35 namespace { 36 namespace {
36 37
37 class ProtoValueConversionsTest : public testing::Test { 38 class ProtoValueConversionsTest : public testing::Test {
38 protected: 39 protected:
39 template <class T> 40 template <class T>
40 void TestSpecificsToValue( 41 void TestSpecificsToValue(
41 DictionaryValue* (*specifics_to_value)(const T&)) { 42 DictionaryValue* (*specifics_to_value)(const T&)) {
42 const T& specifics(T::default_instance()); 43 const T& specifics(T::default_instance());
43 scoped_ptr<DictionaryValue> value(specifics_to_value(specifics)); 44 scoped_ptr<DictionaryValue> value(specifics_to_value(specifics));
44 // We can't do much but make sure that this doesn't crash. 45 // We can't do much but make sure that this doesn't crash.
45 } 46 }
46 }; 47 };
47 48
48 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) { 49 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) {
49 // If this number changes, that means we added or removed a data 50 // If this number changes, that means we added or removed a data
50 // type. Don't forget to add a unit test for {New 51 // type. Don't forget to add a unit test for {New
51 // type}SpecificsToValue below. 52 // type}SpecificsToValue below.
52 EXPECT_EQ(21, MODEL_TYPE_COUNT); 53 EXPECT_EQ(22, MODEL_TYPE_COUNT);
53 54
54 // We'd also like to check if we changed any field in our messages. 55 // We'd also like to check if we changed any field in our messages.
55 // However, that's hard to do: sizeof could work, but it's 56 // However, that's hard to do: sizeof could work, but it's
56 // platform-dependent. default_instance().ByteSize() won't change 57 // platform-dependent. default_instance().ByteSize() won't change
57 // for most changes, since most of our fields are optional. So we 58 // for most changes, since most of our fields are optional. So we
58 // just settle for comments in the proto files. 59 // just settle for comments in the proto files.
59 } 60 }
60 61
61 TEST_F(ProtoValueConversionsTest, EncryptedDataToValue) { 62 TEST_F(ProtoValueConversionsTest, EncryptedDataToValue) {
62 TestSpecificsToValue(EncryptedDataToValue); 63 TestSpecificsToValue(EncryptedDataToValue);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 scoped_ptr<DictionaryValue> value(BookmarkSpecificsToValue(specifics)); 132 scoped_ptr<DictionaryValue> value(BookmarkSpecificsToValue(specifics));
132 EXPECT_FALSE(value->empty()); 133 EXPECT_FALSE(value->empty());
133 std::string encoded_time; 134 std::string encoded_time;
134 EXPECT_TRUE(value->GetString("creation_time_us", &encoded_time)); 135 EXPECT_TRUE(value->GetString("creation_time_us", &encoded_time));
135 EXPECT_EQ(base::Int64ToString(creation_time.ToInternalValue()), encoded_time); 136 EXPECT_EQ(base::Int64ToString(creation_time.ToInternalValue()), encoded_time);
136 std::string encoded_icon_url; 137 std::string encoded_icon_url;
137 EXPECT_TRUE(value->GetString("icon_url", &encoded_icon_url)); 138 EXPECT_TRUE(value->GetString("icon_url", &encoded_icon_url));
138 EXPECT_EQ(icon_url, encoded_icon_url); 139 EXPECT_EQ(icon_url, encoded_icon_url);
139 } 140 }
140 141
142 TEST_F(ProtoValueConversionsTest, PriorityPreferenceSpecificsToValue) {
143 TestSpecificsToValue(PriorityPreferenceSpecificsToValue);
144 }
145
141 TEST_F(ProtoValueConversionsTest, DeviceInfoSpecificsToValue) { 146 TEST_F(ProtoValueConversionsTest, DeviceInfoSpecificsToValue) {
142 TestSpecificsToValue(DeviceInfoSpecificsToValue); 147 TestSpecificsToValue(DeviceInfoSpecificsToValue);
143 } 148 }
144 149
145 TEST_F(ProtoValueConversionsTest, ExperimentsSpecificsToValue) { 150 TEST_F(ProtoValueConversionsTest, ExperimentsSpecificsToValue) {
146 TestSpecificsToValue(ExperimentsSpecificsToValue); 151 TestSpecificsToValue(ExperimentsSpecificsToValue);
147 } 152 }
148 153
149 TEST_F(ProtoValueConversionsTest, ExtensionSettingSpecificsToValue) { 154 TEST_F(ProtoValueConversionsTest, ExtensionSettingSpecificsToValue) {
150 TestSpecificsToValue(ExtensionSettingSpecificsToValue); 155 TestSpecificsToValue(ExtensionSettingSpecificsToValue);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 SET_FIELD(autofill_profile); 210 SET_FIELD(autofill_profile);
206 SET_FIELD(bookmark); 211 SET_FIELD(bookmark);
207 SET_FIELD(experiments); 212 SET_FIELD(experiments);
208 SET_FIELD(extension); 213 SET_FIELD(extension);
209 SET_FIELD(extension_setting); 214 SET_FIELD(extension_setting);
210 SET_FIELD(history_delete_directive); 215 SET_FIELD(history_delete_directive);
211 SET_FIELD(nigori); 216 SET_FIELD(nigori);
212 SET_FIELD(password); 217 SET_FIELD(password);
213 SET_FIELD(device_info); 218 SET_FIELD(device_info);
214 SET_FIELD(preference); 219 SET_FIELD(preference);
220 SET_FIELD(priority_preference);
215 SET_FIELD(search_engine); 221 SET_FIELD(search_engine);
216 SET_FIELD(session); 222 SET_FIELD(session);
217 SET_FIELD(synced_notification); 223 SET_FIELD(synced_notification);
218 SET_FIELD(theme); 224 SET_FIELD(theme);
219 SET_FIELD(typed_url); 225 SET_FIELD(typed_url);
220 226
221 #undef SET_FIELD 227 #undef SET_FIELD
222 228
223 scoped_ptr<DictionaryValue> value(EntitySpecificsToValue(specifics)); 229 scoped_ptr<DictionaryValue> value(EntitySpecificsToValue(specifics));
224 EXPECT_EQ(MODEL_TYPE_COUNT - FIRST_REAL_MODEL_TYPE, 230 EXPECT_EQ(MODEL_TYPE_COUNT - FIRST_REAL_MODEL_TYPE,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 288
283 scoped_ptr<DictionaryValue> value_without_specifics( 289 scoped_ptr<DictionaryValue> value_without_specifics(
284 ClientToServerResponseToValue(message, false /* include_specifics */)); 290 ClientToServerResponseToValue(message, false /* include_specifics */));
285 EXPECT_FALSE(value_without_specifics->empty()); 291 EXPECT_FALSE(value_without_specifics->empty());
286 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), 292 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()),
287 "get_updates.entries")); 293 "get_updates.entries"));
288 } 294 }
289 295
290 } // namespace 296 } // namespace
291 } // namespace syncer 297 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/protocol/proto_value_conversions.cc ('k') | sync/protocol/sync.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698