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

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: Fix integration tests 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
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/control_preference_specifics.pb.h"
19 #include "sync/protocol/device_info_specifics.pb.h" 20 #include "sync/protocol/device_info_specifics.pb.h"
20 #include "sync/protocol/encryption.pb.h" 21 #include "sync/protocol/encryption.pb.h"
21 #include "sync/protocol/experiments_specifics.pb.h" 22 #include "sync/protocol/experiments_specifics.pb.h"
22 #include "sync/protocol/extension_setting_specifics.pb.h" 23 #include "sync/protocol/extension_setting_specifics.pb.h"
23 #include "sync/protocol/extension_specifics.pb.h" 24 #include "sync/protocol/extension_specifics.pb.h"
24 #include "sync/protocol/nigori_specifics.pb.h" 25 #include "sync/protocol/nigori_specifics.pb.h"
25 #include "sync/protocol/password_specifics.pb.h" 26 #include "sync/protocol/password_specifics.pb.h"
26 #include "sync/protocol/preference_specifics.pb.h" 27 #include "sync/protocol/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"
(...skipping 13 matching lines...) Expand all
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(20, MODEL_TYPE_COUNT); 53 EXPECT_EQ(21, 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, ControlPreferenceSpecificsToValue) {
143 TestSpecificsToValue(ControlPreferenceSpecificsToValue);
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // Touch the extensions to make sure it shows up in the generated 198 // Touch the extensions to make sure it shows up in the generated
194 // value. 199 // value.
195 #define SET_FIELD(key) (void)specifics.mutable_##key() 200 #define SET_FIELD(key) (void)specifics.mutable_##key()
196 201
197 SET_FIELD(app); 202 SET_FIELD(app);
198 SET_FIELD(app_notification); 203 SET_FIELD(app_notification);
199 SET_FIELD(app_setting); 204 SET_FIELD(app_setting);
200 SET_FIELD(autofill); 205 SET_FIELD(autofill);
201 SET_FIELD(autofill_profile); 206 SET_FIELD(autofill_profile);
202 SET_FIELD(bookmark); 207 SET_FIELD(bookmark);
208 SET_FIELD(control_preference);
203 SET_FIELD(experiments); 209 SET_FIELD(experiments);
204 SET_FIELD(extension); 210 SET_FIELD(extension);
205 SET_FIELD(extension_setting); 211 SET_FIELD(extension_setting);
206 SET_FIELD(history_delete_directive); 212 SET_FIELD(history_delete_directive);
207 SET_FIELD(nigori); 213 SET_FIELD(nigori);
208 SET_FIELD(password); 214 SET_FIELD(password);
209 SET_FIELD(device_info); 215 SET_FIELD(device_info);
210 SET_FIELD(preference); 216 SET_FIELD(preference);
211 SET_FIELD(search_engine); 217 SET_FIELD(search_engine);
212 SET_FIELD(session); 218 SET_FIELD(session);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 283
278 scoped_ptr<DictionaryValue> value_without_specifics( 284 scoped_ptr<DictionaryValue> value_without_specifics(
279 ClientToServerResponseToValue(message, false /* include_specifics */)); 285 ClientToServerResponseToValue(message, false /* include_specifics */));
280 EXPECT_FALSE(value_without_specifics->empty()); 286 EXPECT_FALSE(value_without_specifics->empty());
281 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), 287 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()),
282 "get_updates.entries")); 288 "get_updates.entries"));
283 } 289 }
284 290
285 } // namespace 291 } // namespace
286 } // namespace syncer 292 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698