| OLD | NEW |
| 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/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/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/favicon_image_specifics.pb.h" | 24 #include "sync/protocol/favicon_image_specifics.pb.h" |
| 25 #include "sync/protocol/favicon_tracking_specifics.pb.h" | 25 #include "sync/protocol/favicon_tracking_specifics.pb.h" |
| 26 #include "sync/protocol/managed_user_setting_specifics.pb.h" | 26 #include "sync/protocol/managed_user_setting_specifics.pb.h" |
| 27 #include "sync/protocol/managed_user_shared_setting_specifics.pb.h" |
| 28 #include "sync/protocol/managed_user_specifics.pb.h" |
| 27 #include "sync/protocol/nigori_specifics.pb.h" | 29 #include "sync/protocol/nigori_specifics.pb.h" |
| 28 #include "sync/protocol/password_specifics.pb.h" | 30 #include "sync/protocol/password_specifics.pb.h" |
| 29 #include "sync/protocol/preference_specifics.pb.h" | 31 #include "sync/protocol/preference_specifics.pb.h" |
| 30 #include "sync/protocol/priority_preference_specifics.pb.h" | 32 #include "sync/protocol/priority_preference_specifics.pb.h" |
| 31 #include "sync/protocol/search_engine_specifics.pb.h" | 33 #include "sync/protocol/search_engine_specifics.pb.h" |
| 32 #include "sync/protocol/session_specifics.pb.h" | 34 #include "sync/protocol/session_specifics.pb.h" |
| 33 #include "sync/protocol/sync.pb.h" | 35 #include "sync/protocol/sync.pb.h" |
| 34 #include "sync/protocol/theme_specifics.pb.h" | 36 #include "sync/protocol/theme_specifics.pb.h" |
| 35 #include "sync/protocol/typed_url_specifics.pb.h" | 37 #include "sync/protocol/typed_url_specifics.pb.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 37 | 39 |
| 38 namespace syncer { | 40 namespace syncer { |
| 39 namespace { | 41 namespace { |
| 40 | 42 |
| 41 class ProtoValueConversionsTest : public testing::Test { | 43 class ProtoValueConversionsTest : public testing::Test { |
| 42 protected: | 44 protected: |
| 43 template <class T> | 45 template <class T> |
| 44 void TestSpecificsToValue( | 46 void TestSpecificsToValue( |
| 45 base::DictionaryValue* (*specifics_to_value)(const T&)) { | 47 base::DictionaryValue* (*specifics_to_value)(const T&)) { |
| 46 const T& specifics(T::default_instance()); | 48 const T& specifics(T::default_instance()); |
| 47 scoped_ptr<base::DictionaryValue> value(specifics_to_value(specifics)); | 49 scoped_ptr<base::DictionaryValue> value(specifics_to_value(specifics)); |
| 48 // We can't do much but make sure that this doesn't crash. | 50 // We can't do much but make sure that this doesn't crash. |
| 49 } | 51 } |
| 50 }; | 52 }; |
| 51 | 53 |
| 52 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) { | 54 TEST_F(ProtoValueConversionsTest, ProtoChangeCheck) { |
| 53 // If this number changes, that means we added or removed a data | 55 // If this number changes, that means we added or removed a data |
| 54 // type. Don't forget to add a unit test for {New | 56 // type. Don't forget to add a unit test for {New |
| 55 // type}SpecificsToValue below. | 57 // type}SpecificsToValue below. |
| 56 EXPECT_EQ(30, MODEL_TYPE_COUNT); | 58 EXPECT_EQ(31, MODEL_TYPE_COUNT); |
| 57 | 59 |
| 58 // We'd also like to check if we changed any field in our messages. | 60 // We'd also like to check if we changed any field in our messages. |
| 59 // However, that's hard to do: sizeof could work, but it's | 61 // However, that's hard to do: sizeof could work, but it's |
| 60 // platform-dependent. default_instance().ByteSize() won't change | 62 // platform-dependent. default_instance().ByteSize() won't change |
| 61 // for most changes, since most of our fields are optional. So we | 63 // for most changes, since most of our fields are optional. So we |
| 62 // just settle for comments in the proto files. | 64 // just settle for comments in the proto files. |
| 63 } | 65 } |
| 64 | 66 |
| 65 TEST_F(ProtoValueConversionsTest, EncryptedDataToValue) { | 67 TEST_F(ProtoValueConversionsTest, EncryptedDataToValue) { |
| 66 TestSpecificsToValue(EncryptedDataToValue); | 68 TestSpecificsToValue(EncryptedDataToValue); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 205 } |
| 204 | 206 |
| 205 TEST_F(ProtoValueConversionsTest, ManagedUserSettingSpecificsToValue) { | 207 TEST_F(ProtoValueConversionsTest, ManagedUserSettingSpecificsToValue) { |
| 206 TestSpecificsToValue(ManagedUserSettingSpecificsToValue); | 208 TestSpecificsToValue(ManagedUserSettingSpecificsToValue); |
| 207 } | 209 } |
| 208 | 210 |
| 209 TEST_F(ProtoValueConversionsTest, ManagedUserSpecificsToValue) { | 211 TEST_F(ProtoValueConversionsTest, ManagedUserSpecificsToValue) { |
| 210 TestSpecificsToValue(ManagedUserSpecificsToValue); | 212 TestSpecificsToValue(ManagedUserSpecificsToValue); |
| 211 } | 213 } |
| 212 | 214 |
| 215 TEST_F(ProtoValueConversionsTest, ManagedUserSharedSettingSpecificsToValue) { |
| 216 TestSpecificsToValue(ManagedUserSharedSettingSpecificsToValue); |
| 217 } |
| 218 |
| 213 TEST_F(ProtoValueConversionsTest, NigoriSpecificsToValue) { | 219 TEST_F(ProtoValueConversionsTest, NigoriSpecificsToValue) { |
| 214 TestSpecificsToValue(NigoriSpecificsToValue); | 220 TestSpecificsToValue(NigoriSpecificsToValue); |
| 215 } | 221 } |
| 216 | 222 |
| 217 TEST_F(ProtoValueConversionsTest, PasswordSpecificsToValue) { | 223 TEST_F(ProtoValueConversionsTest, PasswordSpecificsToValue) { |
| 218 TestSpecificsToValue(PasswordSpecificsToValue); | 224 TestSpecificsToValue(PasswordSpecificsToValue); |
| 219 } | 225 } |
| 220 | 226 |
| 221 TEST_F(ProtoValueConversionsTest, PreferenceSpecificsToValue) { | 227 TEST_F(ProtoValueConversionsTest, PreferenceSpecificsToValue) { |
| 222 TestSpecificsToValue(PreferenceSpecificsToValue); | 228 TestSpecificsToValue(PreferenceSpecificsToValue); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 SET_FIELD(bookmark); | 274 SET_FIELD(bookmark); |
| 269 SET_FIELD(device_info); | 275 SET_FIELD(device_info); |
| 270 SET_FIELD(dictionary); | 276 SET_FIELD(dictionary); |
| 271 SET_FIELD(experiments); | 277 SET_FIELD(experiments); |
| 272 SET_FIELD(extension); | 278 SET_FIELD(extension); |
| 273 SET_FIELD(extension_setting); | 279 SET_FIELD(extension_setting); |
| 274 SET_FIELD(favicon_image); | 280 SET_FIELD(favicon_image); |
| 275 SET_FIELD(favicon_tracking); | 281 SET_FIELD(favicon_tracking); |
| 276 SET_FIELD(history_delete_directive); | 282 SET_FIELD(history_delete_directive); |
| 277 SET_FIELD(managed_user_setting); | 283 SET_FIELD(managed_user_setting); |
| 284 SET_FIELD(managed_user_shared_setting); |
| 278 SET_FIELD(managed_user); | 285 SET_FIELD(managed_user); |
| 279 SET_FIELD(nigori); | 286 SET_FIELD(nigori); |
| 280 SET_FIELD(password); | 287 SET_FIELD(password); |
| 281 SET_FIELD(preference); | 288 SET_FIELD(preference); |
| 282 SET_FIELD(priority_preference); | 289 SET_FIELD(priority_preference); |
| 283 SET_FIELD(search_engine); | 290 SET_FIELD(search_engine); |
| 284 SET_FIELD(session); | 291 SET_FIELD(session); |
| 285 SET_FIELD(synced_notification); | 292 SET_FIELD(synced_notification); |
| 286 SET_FIELD(theme); | 293 SET_FIELD(theme); |
| 287 SET_FIELD(typed_url); | 294 SET_FIELD(typed_url); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 | 358 |
| 352 scoped_ptr<base::DictionaryValue> value_without_specifics( | 359 scoped_ptr<base::DictionaryValue> value_without_specifics( |
| 353 ClientToServerResponseToValue(message, false /* include_specifics */)); | 360 ClientToServerResponseToValue(message, false /* include_specifics */)); |
| 354 EXPECT_FALSE(value_without_specifics->empty()); | 361 EXPECT_FALSE(value_without_specifics->empty()); |
| 355 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), | 362 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), |
| 356 "get_updates.entries")); | 363 "get_updates.entries")); |
| 357 } | 364 } |
| 358 | 365 |
| 359 } // namespace | 366 } // namespace |
| 360 } // namespace syncer | 367 } // namespace syncer |
| OLD | NEW |