Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Unified Diff: sync/protocol/proto_value_conversions_unittest.cc

Issue 9663023: Log the sync communication that happens between client and server. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For committing. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/protocol/proto_value_conversions.cc ('k') | sync/sync.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/protocol/proto_value_conversions_unittest.cc
diff --git a/sync/protocol/proto_value_conversions_unittest.cc b/sync/protocol/proto_value_conversions_unittest.cc
index 3d96378722f1684a1c95764f69d7f9b35344dd0b..59eb3a85120a119d33a3a1122c0b5de64193c4de 100644
--- a/sync/protocol/proto_value_conversions_unittest.cc
+++ b/sync/protocol/proto_value_conversions_unittest.cc
@@ -187,5 +187,67 @@ TEST_F(ProtoValueConversionsTest, EntitySpecificsToValue) {
static_cast<int>(value->size()));
}
+namespace {
+// Returns whether the given value has specifics under the entries in the given
+// path.
+bool ValueHasSpecifics(const DictionaryValue& value,
+ const std::string& path) {
+ ListValue* entities_list = NULL;
+ DictionaryValue* entry_dictionary = NULL;
+ DictionaryValue* specifics_dictionary = NULL;
+
+ if (!value.GetList(path, &entities_list))
+ return false;
+
+ if (!entities_list->GetDictionary(0, &entry_dictionary))
+ return false;
+
+ return entry_dictionary->GetDictionary("specifics",
+ &specifics_dictionary);
+}
+} // namespace
+
+// Create a ClientToServerMessage with an EntitySpecifics. Converting it to
+// a value should respect the |include_specifics| flag.
+TEST_F(ProtoValueConversionsTest, ClientToServerMessageToValue) {
+ sync_pb::ClientToServerMessage message;
+ sync_pb::CommitMessage* commit_message = message.mutable_commit();
+ sync_pb::SyncEntity* entity = commit_message->add_entries();
+ entity->mutable_specifics();
+
+ scoped_ptr<DictionaryValue> value_with_specifics(
+ ClientToServerMessageToValue(message, true /* include_specifics */));
+ EXPECT_FALSE(value_with_specifics->empty());
+ EXPECT_TRUE(ValueHasSpecifics(*(value_with_specifics.get()),
+ "commit.entries"));
+
+ scoped_ptr<DictionaryValue> value_without_specifics(
+ ClientToServerMessageToValue(message, false /* include_specifics */));
+ EXPECT_FALSE(value_without_specifics->empty());
+ EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()),
+ "commit.entries"));
+}
+
+// Create a ClientToServerResponse with an EntitySpecifics. Converting it to
+// a value should respect the |include_specifics| flag.
+TEST_F(ProtoValueConversionsTest, ClientToServerResponseToValue) {
+ sync_pb::ClientToServerResponse message;
+ sync_pb::GetUpdatesResponse* response = message.mutable_get_updates();
+ sync_pb::SyncEntity* entity = response->add_entries();
+ entity->mutable_specifics();
+
+ scoped_ptr<DictionaryValue> value_with_specifics(
+ ClientToServerResponseToValue(message, true /* include_specifics */));
+ EXPECT_FALSE(value_with_specifics->empty());
+ EXPECT_TRUE(ValueHasSpecifics(*(value_with_specifics.get()),
+ "get_updates.entries"));
+
+ scoped_ptr<DictionaryValue> value_without_specifics(
+ ClientToServerResponseToValue(message, false /* include_specifics */));
+ EXPECT_FALSE(value_without_specifics->empty());
+ EXPECT_FALSE(ValueHasSpecifics(*(value_without_specifics.get()),
+ "get_updates.entries"));
+}
+
} // namespace
} // namespace browser_sync
« no previous file with comments | « sync/protocol/proto_value_conversions.cc ('k') | sync/sync.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698