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

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 review. 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
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..4f9e830a9418fc9bb6f50faf2a3113a9d9124a57 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(DictionaryValue* value,
akalin 2012/03/20 19:38:34 use a const DictionaryValue&
+ 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
+
+TEST_F(ProtoValueConversionsTest, ClientToServerMessageToValue) {
+ // Create a ClientToServerMessage with an EntitySpecifics. Converting it to
akalin 2012/03/20 19:38:34 move comment to above TEST_F
+ // a value should respect the |include_specifics| flag.
+ sync_pb::ClientToServerMessage message;
+ sync_pb::CommitMessage* commit_message = message.mutable_commit();
+ sync_pb::SyncEntity* entity = commit_message->add_entries();
+ sync_pb::EntitySpecifics* specifics = 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"));
+}
+
+TEST_F(ProtoValueConversionsTest, ClientToServerResponseToValue) {
+ // Create a ClientToServerResponse with an EntitySpecifics. Converting it to
akalin 2012/03/20 19:38:34 here, too
+ // a value should respect the |include_specifics| flag.
+ sync_pb::ClientToServerResponse message;
+ sync_pb::GetUpdatesResponse* response = message.mutable_get_updates();
+ sync_pb::SyncEntity* entity = response->add_entries();
+ sync_pb::EntitySpecifics* specifics = 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

Powered by Google App Engine
This is Rietveld 408576698