| 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/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/device_info_specifics.pb.h" |
| 17 #include "sync/protocol/encryption.pb.h" | 18 #include "sync/protocol/encryption.pb.h" |
| 18 #include "sync/protocol/extension_setting_specifics.pb.h" | 19 #include "sync/protocol/extension_setting_specifics.pb.h" |
| 19 #include "sync/protocol/extension_specifics.pb.h" | 20 #include "sync/protocol/extension_specifics.pb.h" |
| 20 #include "sync/protocol/nigori_specifics.pb.h" | 21 #include "sync/protocol/nigori_specifics.pb.h" |
| 21 #include "sync/protocol/password_specifics.pb.h" | 22 #include "sync/protocol/password_specifics.pb.h" |
| 22 #include "sync/protocol/preference_specifics.pb.h" | 23 #include "sync/protocol/preference_specifics.pb.h" |
| 23 #include "sync/protocol/search_engine_specifics.pb.h" | 24 #include "sync/protocol/search_engine_specifics.pb.h" |
| 24 #include "sync/protocol/session_specifics.pb.h" | 25 #include "sync/protocol/session_specifics.pb.h" |
| 25 #include "sync/protocol/sync.pb.h" | 26 #include "sync/protocol/sync.pb.h" |
| 26 #include "sync/protocol/theme_specifics.pb.h" | 27 #include "sync/protocol/theme_specifics.pb.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 40 // We can't do much but make sure that the returned value has | 41 // We can't do much but make sure that the returned value has |
| 41 // something in it. | 42 // something in it. |
| 42 EXPECT_FALSE(value->empty()); | 43 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(18, 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 Loading... |
| 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, DeviceInfoSpecificsToValue) { |
| 141 TestSpecificsToValue(DeviceInfoSpecificsToValue); |
| 142 } |
| 143 |
| 139 TEST_F(ProtoValueConversionsTest, PreferenceSpecificsToValue) { | 144 TEST_F(ProtoValueConversionsTest, PreferenceSpecificsToValue) { |
| 140 TestSpecificsToValue(PreferenceSpecificsToValue); | 145 TestSpecificsToValue(PreferenceSpecificsToValue); |
| 141 } | 146 } |
| 142 | 147 |
| 143 TEST_F(ProtoValueConversionsTest, SearchEngineSpecificsToValue) { | 148 TEST_F(ProtoValueConversionsTest, SearchEngineSpecificsToValue) { |
| 144 TestSpecificsToValue(SearchEngineSpecificsToValue); | 149 TestSpecificsToValue(SearchEngineSpecificsToValue); |
| 145 } | 150 } |
| 146 | 151 |
| 147 TEST_F(ProtoValueConversionsTest, SessionSpecificsToValue) { | 152 TEST_F(ProtoValueConversionsTest, SessionSpecificsToValue) { |
| 148 TestSpecificsToValue(SessionSpecificsToValue); | 153 TestSpecificsToValue(SessionSpecificsToValue); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 167 SET_FIELD(app); | 172 SET_FIELD(app); |
| 168 SET_FIELD(app_notification); | 173 SET_FIELD(app_notification); |
| 169 SET_FIELD(app_setting); | 174 SET_FIELD(app_setting); |
| 170 SET_FIELD(autofill); | 175 SET_FIELD(autofill); |
| 171 SET_FIELD(autofill_profile); | 176 SET_FIELD(autofill_profile); |
| 172 SET_FIELD(bookmark); | 177 SET_FIELD(bookmark); |
| 173 SET_FIELD(extension); | 178 SET_FIELD(extension); |
| 174 SET_FIELD(extension_setting); | 179 SET_FIELD(extension_setting); |
| 175 SET_FIELD(nigori); | 180 SET_FIELD(nigori); |
| 176 SET_FIELD(password); | 181 SET_FIELD(password); |
| 182 SET_FIELD(device_info); |
| 177 SET_FIELD(preference); | 183 SET_FIELD(preference); |
| 178 SET_FIELD(search_engine); | 184 SET_FIELD(search_engine); |
| 179 SET_FIELD(session); | 185 SET_FIELD(session); |
| 180 SET_FIELD(theme); | 186 SET_FIELD(theme); |
| 181 SET_FIELD(typed_url); | 187 SET_FIELD(typed_url); |
| 182 | 188 |
| 183 #undef SET_FIELD | 189 #undef SET_FIELD |
| 184 | 190 |
| 185 scoped_ptr<DictionaryValue> value(EntitySpecificsToValue(specifics)); | 191 scoped_ptr<DictionaryValue> value(EntitySpecificsToValue(specifics)); |
| 186 EXPECT_EQ(MODEL_TYPE_COUNT - FIRST_REAL_MODEL_TYPE, | 192 EXPECT_EQ(MODEL_TYPE_COUNT - FIRST_REAL_MODEL_TYPE, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 250 |
| 245 scoped_ptr<DictionaryValue> value_without_specifics( | 251 scoped_ptr<DictionaryValue> value_without_specifics( |
| 246 ClientToServerResponseToValue(message, false /* include_specifics */)); | 252 ClientToServerResponseToValue(message, false /* include_specifics */)); |
| 247 EXPECT_FALSE(value_without_specifics->empty()); | 253 EXPECT_FALSE(value_without_specifics->empty()); |
| 248 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), | 254 EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()), |
| 249 "get_updates.entries")); | 255 "get_updates.entries")); |
| 250 } | 256 } |
| 251 | 257 |
| 252 } // namespace | 258 } // namespace |
| 253 } // namespace syncer | 259 } // namespace syncer |
| OLD | NEW |