summaryrefslogtreecommitdiffstats
path: root/base/values_unittest.cc
diff options
context:
space:
mode:
authortony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-02 00:20:32 +0000
committertony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-02 00:20:32 +0000
commitec330b5c0f38e22470a15460a06309658b18ce14 (patch)
tree5aab1796997ec38122489bd7ed2b722f19f5ac84 /base/values_unittest.cc
parent855b2d52e0a1ba1247eba0c9b79f6f7ba06f19df (diff)
downloadchromium_src-ec330b5c0f38e22470a15460a06309658b18ce14.zip
chromium_src-ec330b5c0f38e22470a15460a06309658b18ce14.tar.gz
chromium_src-ec330b5c0f38e22470a15460a06309658b18ce14.tar.bz2
Remove emtpy lists and empty dictionaries from Preferences and
Local State when writing to disk. BUG=28836 Review URL: http://codereview.chromium.org/449074 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33518 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/values_unittest.cc')
-rw-r--r--base/values_unittest.cc75
1 files changed, 75 insertions, 0 deletions
diff --git a/base/values_unittest.cc b/base/values_unittest.cc
index 5835e2b..912b380 100644
--- a/base/values_unittest.cc
+++ b/base/values_unittest.cc
@@ -478,3 +478,78 @@ TEST(ValuesTest, Equals) {
EXPECT_FALSE(dv.Equals(copy));
delete copy;
}
+
+TEST(ValuesTest, RemoveEmptyChildren) {
+ scoped_ptr<DictionaryValue> root(new DictionaryValue);
+ // Remove empty lists and dictionaries.
+ root->Set(L"empty_dict", new DictionaryValue);
+ root->Set(L"empty_list", new ListValue);
+ root->SetWithoutPathExpansion(L"a.b.c.d.e", new DictionaryValue);
+ root.reset(root->DeepCopyWithoutEmptyChildren());
+ EXPECT_TRUE(root->empty());
+
+ // Make sure we don't prune too much.
+ root->SetBoolean(L"bool", true);
+ root->Set(L"empty_dict", new DictionaryValue);
+ root->SetString(L"empty_string", "");
+ root.reset(root->DeepCopyWithoutEmptyChildren());
+ EXPECT_EQ(2U, root->size());
+
+ // Should do nothing.
+ root.reset(root->DeepCopyWithoutEmptyChildren());
+ EXPECT_EQ(2U, root->size());
+
+ // Nested test cases. These should all reduce back to the bool and string
+ // set above.
+ {
+ root->Set(L"a.b.c.d.e", new DictionaryValue);
+ root.reset(root->DeepCopyWithoutEmptyChildren());
+ EXPECT_EQ(2U, root->size());
+ }
+ {
+ DictionaryValue* inner = new DictionaryValue;
+ root->Set(L"dict_with_emtpy_children", inner);
+ inner->Set(L"empty_dict", new DictionaryValue);
+ inner->Set(L"empty_list", new ListValue);
+ root.reset(root->DeepCopyWithoutEmptyChildren());
+ EXPECT_EQ(2U, root->size());
+ }
+ {
+ ListValue* inner = new ListValue;
+ root->Set(L"list_with_empty_children", inner);
+ inner->Append(new DictionaryValue);
+ inner->Append(new ListValue);
+ root.reset(root->DeepCopyWithoutEmptyChildren());
+ EXPECT_EQ(2U, root->size());
+ }
+
+ // Nested with siblings.
+ {
+ ListValue* inner = new ListValue;
+ root->Set(L"list_with_empty_children", inner);
+ inner->Append(new DictionaryValue);
+ inner->Append(new ListValue);
+ DictionaryValue* inner2 = new DictionaryValue;
+ root->Set(L"dict_with_empty_children", inner2);
+ inner2->Set(L"empty_dict", new DictionaryValue);
+ inner2->Set(L"empty_list", new ListValue);
+ root.reset(root->DeepCopyWithoutEmptyChildren());
+ EXPECT_EQ(2U, root->size());
+ }
+
+ // Make sure nested values don't get pruned.
+ {
+ ListValue* inner = new ListValue;
+ root->Set(L"list_with_empty_children", inner);
+ ListValue* inner2 = new ListValue;
+ inner->Append(new DictionaryValue);
+ inner->Append(inner2);
+ inner2->Append(Value::CreateStringValue("hello"));
+ root.reset(root->DeepCopyWithoutEmptyChildren());
+ EXPECT_EQ(3U, root->size());
+ EXPECT_TRUE(root->GetList(L"list_with_empty_children", &inner));
+ EXPECT_EQ(1U, inner->GetSize()); // Dictionary was pruned.
+ EXPECT_TRUE(inner->GetList(0, &inner2));
+ EXPECT_EQ(1U, inner2->GetSize());
+ }
+}