Chromium Code Reviews| 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 void VerifySpecifics(DictionaryValue* value, | |
|
akalin
2012/03/19 21:31:38
I think it would be cleaner to have this something
lipalani1
2012/03/20 19:24:41
Done.
| |
| 192 const std::string& path, | |
| 193 bool include_specifics) { | |
| 194 ListValue* entities_list; | |
|
akalin
2012/03/19 21:31:38
initialize to NULL
lipalani1
2012/03/20 19:24:41
Done.
| |
| 195 DictionaryValue* entry_dictionary; | |
| 196 DictionaryValue* specifics_dictionary; | |
| 197 EXPECT_TRUE(value->GetList(path, &entities_list)); | |
|
akalin
2012/03/19 21:31:38
use
if(!...) {
return false;
}
lipalani1
2012/03/20 19:24:41
Done.
| |
| 198 EXPECT_TRUE(entities_list->GetDictionary(0, &entry_dictionary)); | |
| 199 EXPECT_EQ(entry_dictionary->GetDictionary("specifics", | |
| 200 &specifics_dictionary), | |
| 201 include_specifics); | |
| 202 } | |
| 203 } // namespace | |
| 204 | |
| 205 TEST_F(ProtoValueConversionsTest, ClientToServerMessageToValue) { | |
|
akalin
2012/03/19 21:31:38
add test-level comment. Something like
// Create
lipalani1
2012/03/20 19:24:41
Done.
| |
| 206 sync_pb::ClientToServerMessage message; | |
| 207 sync_pb::CommitMessage* commit_message = message.mutable_commit(); | |
| 208 sync_pb::SyncEntity* entity = commit_message->add_entries(); | |
| 209 sync_pb::EntitySpecifics* specifics = entity->mutable_specifics(); | |
| 210 | |
| 211 scoped_ptr<DictionaryValue> value_with_specifics( | |
| 212 ClientToServerMessageToValue(message, true /* include_specifics */)); | |
| 213 EXPECT_FALSE(value_with_specifics->empty()); | |
| 214 VerifySpecifics(value_with_specifics.get(), "commit.entries", true); | |
|
akalin
2012/03/19 21:31:38
true -> true /* include_specifics */
(everywhere
lipalani1
2012/03/20 19:24:41
The param is removed.
On 2012/03/19 21:31:38, akal
| |
| 215 | |
| 216 scoped_ptr<DictionaryValue> value_without_specifics( | |
| 217 ClientToServerMessageToValue(message, false /* include_specifics */)); | |
| 218 EXPECT_FALSE(value_without_specifics->empty()); | |
| 219 VerifySpecifics(value_without_specifics.get(), "commit.entries", false); | |
| 220 } | |
| 221 | |
| 222 TEST_F(ProtoValueConversionsTest, ClientToServerResponseToValue) { | |
|
akalin
2012/03/19 21:31:38
add test-level comment
lipalani1
2012/03/20 19:24:41
Done.
| |
| 223 sync_pb::ClientToServerResponse message; | |
| 224 sync_pb::GetUpdatesResponse* response = message.mutable_get_updates(); | |
| 225 sync_pb::SyncEntity* entity = response->add_entries(); | |
| 226 sync_pb::EntitySpecifics* specifics = entity->mutable_specifics(); | |
| 227 | |
| 228 scoped_ptr<DictionaryValue> value_with_specifics( | |
| 229 ClientToServerResponseToValue(message, true /* include_specifics */)); | |
| 230 EXPECT_FALSE(value_with_specifics->empty()); | |
| 231 VerifySpecifics(value_with_specifics.get(), "get_updates.entries", true); | |
| 232 | |
| 233 | |
| 234 scoped_ptr<DictionaryValue> value_without_specifics( | |
| 235 ClientToServerResponseToValue(message, false /* include_specifics */)); | |
| 236 EXPECT_FALSE(value_without_specifics->empty()); | |
| 237 VerifySpecifics(value_without_specifics.get(), "get_updates.entries", false); | |
| 238 } | |
| 239 | |
| 190 } // namespace | 240 } // namespace |
| 191 } // namespace browser_sync | 241 } // namespace browser_sync |
| OLD | NEW |