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" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 SET_FIELD(theme); | 180 SET_FIELD(theme); |
181 SET_FIELD(typed_url); | 181 SET_FIELD(typed_url); |
182 | 182 |
183 #undef SET_FIELD | 183 #undef SET_FIELD |
184 | 184 |
185 scoped_ptr<DictionaryValue> value(EntitySpecificsToValue(specifics)); | 185 scoped_ptr<DictionaryValue> value(EntitySpecificsToValue(specifics)); |
186 EXPECT_EQ(syncable::MODEL_TYPE_COUNT - syncable::FIRST_REAL_MODEL_TYPE, | 186 EXPECT_EQ(syncable::MODEL_TYPE_COUNT - syncable::FIRST_REAL_MODEL_TYPE, |
187 static_cast<int>(value->size())); | 187 static_cast<int>(value->size())); |
188 } | 188 } |
189 | 189 |
190 namespace { | |
191 // Returns whether the given value has specifics under the entries in the given | |
192 // path. | |
193 bool ValueHasSpecifics(DictionaryValue* value, | |
akalin
2012/03/20 19:38:34
use a const DictionaryValue&
| |
194 const std::string& path) { | |
195 ListValue* entities_list = NULL; | |
196 DictionaryValue* entry_dictionary = NULL; | |
197 DictionaryValue* specifics_dictionary = NULL; | |
198 | |
199 if (!value->GetList(path, &entities_list)) | |
200 return false; | |
201 | |
202 if (!entities_list->GetDictionary(0, &entry_dictionary)) | |
203 return false; | |
204 | |
205 return entry_dictionary->GetDictionary("specifics", | |
206 &specifics_dictionary); | |
207 } | |
208 } // namespace | |
209 | |
210 TEST_F(ProtoValueConversionsTest, ClientToServerMessageToValue) { | |
211 // Create a ClientToServerMessage with an EntitySpecifics. Converting it to | |
akalin
2012/03/20 19:38:34
move comment to above TEST_F
| |
212 // a value should respect the |include_specifics| flag. | |
213 sync_pb::ClientToServerMessage message; | |
214 sync_pb::CommitMessage* commit_message = message.mutable_commit(); | |
215 sync_pb::SyncEntity* entity = commit_message->add_entries(); | |
216 sync_pb::EntitySpecifics* specifics = entity->mutable_specifics(); | |
217 | |
218 scoped_ptr<DictionaryValue> value_with_specifics( | |
219 ClientToServerMessageToValue(message, true /* include_specifics */)); | |
220 EXPECT_FALSE(value_with_specifics->empty()); | |
221 EXPECT_TRUE(ValueHasSpecifics(value_with_specifics.get(), "commit.entries")); | |
222 | |
223 scoped_ptr<DictionaryValue> value_without_specifics( | |
224 ClientToServerMessageToValue(message, false /* include_specifics */)); | |
225 EXPECT_FALSE(value_without_specifics->empty()); | |
226 EXPECT_FALSE(ValueHasSpecifics(value_without_specifics.get(), | |
227 "commit.entries")); | |
228 } | |
229 | |
230 TEST_F(ProtoValueConversionsTest, ClientToServerResponseToValue) { | |
231 // Create a ClientToServerResponse with an EntitySpecifics. Converting it to | |
akalin
2012/03/20 19:38:34
here, too
| |
232 // a value should respect the |include_specifics| flag. | |
233 sync_pb::ClientToServerResponse message; | |
234 sync_pb::GetUpdatesResponse* response = message.mutable_get_updates(); | |
235 sync_pb::SyncEntity* entity = response->add_entries(); | |
236 sync_pb::EntitySpecifics* specifics = entity->mutable_specifics(); | |
237 | |
238 scoped_ptr<DictionaryValue> value_with_specifics( | |
239 ClientToServerResponseToValue(message, true /* include_specifics */)); | |
240 EXPECT_FALSE(value_with_specifics->empty()); | |
241 EXPECT_TRUE(ValueHasSpecifics(value_with_specifics.get(), | |
242 "get_updates.entries")); | |
243 | |
244 | |
245 scoped_ptr<DictionaryValue> value_without_specifics( | |
246 ClientToServerResponseToValue(message, false /* include_specifics */)); | |
247 EXPECT_FALSE(value_without_specifics->empty()); | |
248 EXPECT_FALSE(ValueHasSpecifics(value_without_specifics.get(), | |
249 "get_updates.entries")); | |
250 } | |
251 | |
190 } // namespace | 252 } // namespace |
191 } // namespace browser_sync | 253 } // namespace browser_sync |
OLD | NEW |