diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-20 18:18:57 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-20 18:18:57 +0000 |
commit | 0f0117b24b7b404473ce11ac2fc197297ea7d73c (patch) | |
tree | 4098bc8f91f2d99316cd7140a64a13c12e31f30c /dbus | |
parent | 8b0605cb62b45a053344d86a474e6b49bd9e4ca3 (diff) | |
download | chromium_src-0f0117b24b7b404473ce11ac2fc197297ea7d73c.zip chromium_src-0f0117b24b7b404473ce11ac2fc197297ea7d73c.tar.gz chromium_src-0f0117b24b7b404473ce11ac2fc197297ea7d73c.tar.bz2 |
Fix dbus::PopDataAsValue's behavior when a dictionary's keys including dots
BUG=None
TEST=dbus_unittests --gtest_filter="ValuesUtilTest.PopDictinoaryWithDottedStringKey"
Review URL: http://codereview.chromium.org/9732029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127727 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/values_util.cc | 2 | ||||
-rw-r--r-- | dbus/values_util_unittest.cc | 46 |
2 files changed, 46 insertions, 2 deletions
diff --git a/dbus/values_util.cc b/dbus/values_util.cc index c422374..b78638d 100644 --- a/dbus/values_util.cc +++ b/dbus/values_util.cc @@ -57,7 +57,7 @@ bool PopDictionaryEntries(MessageReader* reader, Value* value = PopDataAsValue(&entry_reader); if (!value) return false; - dictionary_value->Set(key_string, value); + dictionary_value->SetWithoutPathExpansion(key_string, value); } return true; } diff --git a/dbus/values_util_unittest.cc b/dbus/values_util_unittest.cc index 1f97cdc..f97c55a 100644 --- a/dbus/values_util_unittest.cc +++ b/dbus/values_util_unittest.cc @@ -282,6 +282,49 @@ TEST(ValuesUtilTest, PopStringToVariantDictionary) { EXPECT_TRUE(value->Equals(&dictionary_value)); } +TEST(ValuesUtilTest, PopDictionaryWithDottedStringKey) { + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + // Append a dictionary. + dbus::MessageWriter writer(response.get()); + dbus::MessageWriter sub_writer(NULL); + dbus::MessageWriter entry_writer(NULL); + writer.OpenArray("{sv}", &sub_writer); + sub_writer.OpenDictEntry(&entry_writer); + const std::string kKey1 = "www.example.com"; // String including dots. + entry_writer.AppendString(kKey1); + const bool kBoolValue = true; + entry_writer.AppendVariantOfBool(kBoolValue); + sub_writer.CloseContainer(&entry_writer); + sub_writer.OpenDictEntry(&entry_writer); + const std::string kKey2 = ".example"; // String starting with a dot. + entry_writer.AppendString(kKey2); + const int32 kInt32Value = -45; + entry_writer.AppendVariantOfInt32(kInt32Value); + sub_writer.CloseContainer(&entry_writer); + sub_writer.OpenDictEntry(&entry_writer); + const std::string kKey3 = "example."; // String ending with a dot. + entry_writer.AppendString(kKey3); + const double kDoubleValue = 4.9; + entry_writer.AppendVariantOfDouble(kDoubleValue); + sub_writer.CloseContainer(&entry_writer); + writer.CloseContainer(&sub_writer); + + // Create the expected value. + DictionaryValue dictionary_value; + dictionary_value.SetWithoutPathExpansion( + kKey1, Value::CreateBooleanValue(kBoolValue)); + dictionary_value.SetWithoutPathExpansion( + kKey2, Value::CreateIntegerValue(kInt32Value)); + dictionary_value.SetWithoutPathExpansion( + kKey3, Value::CreateDoubleValue(kDoubleValue)); + + // Pop a dictinoary. + dbus::MessageReader reader(response.get()); + scoped_ptr<Value> value(dbus::PopDataAsValue(&reader)); + EXPECT_TRUE(value.get() != NULL); + EXPECT_TRUE(value->Equals(&dictionary_value)); +} + TEST(ValuesUtilTest, PopDoubleToIntDictionary) { // Create test data. const int32 kValues[] = {0, 1, 1, 2, 3, 5, 8, 13, 21}; @@ -310,7 +353,8 @@ TEST(ValuesUtilTest, PopDoubleToIntDictionary) { scoped_ptr<Value> key_value(Value::CreateDoubleValue(keys[i])); std::string key_string; base::JSONWriter::Write(key_value.get(), &key_string); - dictionary_value.SetInteger(key_string, values[i]); + dictionary_value.SetWithoutPathExpansion( + key_string, Value::CreateIntegerValue(values[i])); } // Pop a dictionary. |