| 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(29, MODEL_TYPE_COUNT); | 58 EXPECT_EQ(30, 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } | 178 } |
| 177 | 179 |
| 178 TEST_F(ProtoValueConversionsTest, ManagedUserSettingSpecificsToValue) { | 180 TEST_F(ProtoValueConversionsTest, ManagedUserSettingSpecificsToValue) { |
| 179 TestSpecificsToValue(ManagedUserSettingSpecificsToValue); | 181 TestSpecificsToValue(ManagedUserSettingSpecificsToValue); |
| 180 } | 182 } |
| 181 | 183 |
| 182 TEST_F(ProtoValueConversionsTest, ManagedUserSpecificsToValue) { | 184 TEST_F(ProtoValueConversionsTest, ManagedUserSpecificsToValue) { |
| 183 TestSpecificsToValue(ManagedUserSpecificsToValue); | 185 TestSpecificsToValue(ManagedUserSpecificsToValue); |
| 184 } | 186 } |
| 185 | 187 |
| 188 TEST_F(ProtoValueConversionsTest, ManagedUserSharedSettingSpecificsToValue) { |
| 189 TestSpecificsToValue(ManagedUserSharedSettingSpecificsToValue); |
| 190 } |
| 191 |
| 186 TEST_F(ProtoValueConversionsTest, NigoriSpecificsToValue) { | 192 TEST_F(ProtoValueConversionsTest, NigoriSpecificsToValue) { |
| 187 TestSpecificsToValue(NigoriSpecificsToValue); | 193 TestSpecificsToValue(NigoriSpecificsToValue); |
| 188 } | 194 } |
| 189 | 195 |
| 190 TEST_F(ProtoValueConversionsTest, PasswordSpecificsToValue) { | 196 TEST_F(ProtoValueConversionsTest, PasswordSpecificsToValue) { |
| 191 TestSpecificsToValue(PasswordSpecificsToValue); | 197 TestSpecificsToValue(PasswordSpecificsToValue); |
| 192 } | 198 } |
| 193 | 199 |
| 194 TEST_F(ProtoValueConversionsTest, PreferenceSpecificsToValue) { | 200 TEST_F(ProtoValueConversionsTest, PreferenceSpecificsToValue) { |
| 195 TestSpecificsToValue(PreferenceSpecificsToValue); | 201 TestSpecificsToValue(PreferenceSpecificsToValue); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 SET_FIELD(bookmark); | 246 SET_FIELD(bookmark); |
| 241 SET_FIELD(device_info); | 247 SET_FIELD(device_info); |
| 242 SET_FIELD(dictionary); | 248 SET_FIELD(dictionary); |
| 243 SET_FIELD(experiments); | 249 SET_FIELD(experiments); |
| 244 SET_FIELD(extension); | 250 SET_FIELD(extension); |
| 245 SET_FIELD(extension_setting); | 251 SET_FIELD(extension_setting); |
| 246 SET_FIELD(favicon_image); | 252 SET_FIELD(favicon_image); |
| 247 SET_FIELD(favicon_tracking); | 253 SET_FIELD(favicon_tracking); |
| 248 SET_FIELD(history_delete_directive); | 254 SET_FIELD(history_delete_directive); |
| 249 SET_FIELD(managed_user_setting); | 255 SET_FIELD(managed_user_setting); |
| 256 SET_FIELD(managed_user_shared_setting); |
| 250 SET_FIELD(managed_user); | 257 SET_FIELD(managed_user); |
| 251 SET_FIELD(nigori); | 258 SET_FIELD(nigori); |
| 252 SET_FIELD(password); | 259 SET_FIELD(password); |
| 253 SET_FIELD(preference); | 260 SET_FIELD(preference); |
| 254 SET_FIELD(priority_preference); | 261 SET_FIELD(priority_preference); |
| 255 SET_FIELD(search_engine); | 262 SET_FIELD(search_engine); |
| 256 SET_FIELD(session); | 263 SET_FIELD(session); |
| 257 SET_FIELD(synced_notification); | 264 SET_FIELD(synced_notification); |
| 258 SET_FIELD(theme); | 265 SET_FIELD(theme); |
| 259 SET_FIELD(typed_url); | 266 SET_FIELD(typed_url); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 | 330 |
| 324 scoped_ptr<base::DictionaryValue> value_without_specifics( | 331 scoped_ptr<base::DictionaryValue> value_without_specifics( |
| 325 ClientToServerResponseToValue(message, false /* include_specifics */)); | 332 ClientToServerResponseToValue(message, false /* include_specifics */)); |
| 326 EXPECT_FALSE(value_without_specifics->empty()); | 333 EXPECT_FALSE(value_without_specifics->empty()); |
| 327 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), | 334 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), |
| 328 "get_updates.entries")); | 335 "get_updates.entries")); |
| 329 } | 336 } |
| 330 | 337 |
| 331 } // namespace | 338 } // namespace |
| 332 } // namespace syncer | 339 } // namespace syncer |
| OLD | NEW |