| 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 #include <limits> | 5 #include <limits> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 EXPECT_TRUE(original_list->Equals(copy_list.get())); | 665 EXPECT_TRUE(original_list->Equals(copy_list.get())); |
| 666 } | 666 } |
| 667 | 667 |
| 668 TEST(ValuesTest, RemoveEmptyChildren) { | 668 TEST(ValuesTest, RemoveEmptyChildren) { |
| 669 scoped_ptr<DictionaryValue> root(new DictionaryValue); | 669 scoped_ptr<DictionaryValue> root(new DictionaryValue); |
| 670 // Remove empty lists and dictionaries. | 670 // Remove empty lists and dictionaries. |
| 671 root->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); | 671 root->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); |
| 672 root->Set("empty_list", make_scoped_ptr(new ListValue)); | 672 root->Set("empty_list", make_scoped_ptr(new ListValue)); |
| 673 root->SetWithoutPathExpansion("a.b.c.d.e", | 673 root->SetWithoutPathExpansion("a.b.c.d.e", |
| 674 make_scoped_ptr(new DictionaryValue)); | 674 make_scoped_ptr(new DictionaryValue)); |
| 675 root.reset(root->DeepCopyWithoutEmptyChildren()); | 675 root = root->DeepCopyWithoutEmptyChildren(); |
| 676 EXPECT_TRUE(root->empty()); | 676 EXPECT_TRUE(root->empty()); |
| 677 | 677 |
| 678 // Make sure we don't prune too much. | 678 // Make sure we don't prune too much. |
| 679 root->SetBoolean("bool", true); | 679 root->SetBoolean("bool", true); |
| 680 root->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); | 680 root->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); |
| 681 root->SetString("empty_string", std::string()); | 681 root->SetString("empty_string", std::string()); |
| 682 root.reset(root->DeepCopyWithoutEmptyChildren()); | 682 root = root->DeepCopyWithoutEmptyChildren(); |
| 683 EXPECT_EQ(2U, root->size()); | 683 EXPECT_EQ(2U, root->size()); |
| 684 | 684 |
| 685 // Should do nothing. | 685 // Should do nothing. |
| 686 root.reset(root->DeepCopyWithoutEmptyChildren()); | 686 root = root->DeepCopyWithoutEmptyChildren(); |
| 687 EXPECT_EQ(2U, root->size()); | 687 EXPECT_EQ(2U, root->size()); |
| 688 | 688 |
| 689 // Nested test cases. These should all reduce back to the bool and string | 689 // Nested test cases. These should all reduce back to the bool and string |
| 690 // set above. | 690 // set above. |
| 691 { | 691 { |
| 692 root->Set("a.b.c.d.e", make_scoped_ptr(new DictionaryValue)); | 692 root->Set("a.b.c.d.e", make_scoped_ptr(new DictionaryValue)); |
| 693 root.reset(root->DeepCopyWithoutEmptyChildren()); | 693 root = root->DeepCopyWithoutEmptyChildren(); |
| 694 EXPECT_EQ(2U, root->size()); | 694 EXPECT_EQ(2U, root->size()); |
| 695 } | 695 } |
| 696 { | 696 { |
| 697 scoped_ptr<DictionaryValue> inner(new DictionaryValue); | 697 scoped_ptr<DictionaryValue> inner(new DictionaryValue); |
| 698 inner->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); | 698 inner->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); |
| 699 inner->Set("empty_list", make_scoped_ptr(new ListValue)); | 699 inner->Set("empty_list", make_scoped_ptr(new ListValue)); |
| 700 root->Set("dict_with_empty_children", inner.Pass()); | 700 root->Set("dict_with_empty_children", inner.Pass()); |
| 701 root.reset(root->DeepCopyWithoutEmptyChildren()); | 701 root = root->DeepCopyWithoutEmptyChildren(); |
| 702 EXPECT_EQ(2U, root->size()); | 702 EXPECT_EQ(2U, root->size()); |
| 703 } | 703 } |
| 704 { | 704 { |
| 705 scoped_ptr<ListValue> inner(new ListValue); | 705 scoped_ptr<ListValue> inner(new ListValue); |
| 706 inner->Append(make_scoped_ptr(new DictionaryValue)); | 706 inner->Append(make_scoped_ptr(new DictionaryValue)); |
| 707 inner->Append(make_scoped_ptr(new ListValue)); | 707 inner->Append(make_scoped_ptr(new ListValue)); |
| 708 root->Set("list_with_empty_children", inner.Pass()); | 708 root->Set("list_with_empty_children", inner.Pass()); |
| 709 root.reset(root->DeepCopyWithoutEmptyChildren()); | 709 root = root->DeepCopyWithoutEmptyChildren(); |
| 710 EXPECT_EQ(2U, root->size()); | 710 EXPECT_EQ(2U, root->size()); |
| 711 } | 711 } |
| 712 | 712 |
| 713 // Nested with siblings. | 713 // Nested with siblings. |
| 714 { | 714 { |
| 715 scoped_ptr<ListValue> inner(new ListValue()); | 715 scoped_ptr<ListValue> inner(new ListValue()); |
| 716 inner->Append(make_scoped_ptr(new DictionaryValue)); | 716 inner->Append(make_scoped_ptr(new DictionaryValue)); |
| 717 inner->Append(make_scoped_ptr(new ListValue)); | 717 inner->Append(make_scoped_ptr(new ListValue)); |
| 718 root->Set("list_with_empty_children", inner.Pass()); | 718 root->Set("list_with_empty_children", inner.Pass()); |
| 719 scoped_ptr<DictionaryValue> inner2(new DictionaryValue); | 719 scoped_ptr<DictionaryValue> inner2(new DictionaryValue); |
| 720 inner2->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); | 720 inner2->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); |
| 721 inner2->Set("empty_list", make_scoped_ptr(new ListValue)); | 721 inner2->Set("empty_list", make_scoped_ptr(new ListValue)); |
| 722 root->Set("dict_with_empty_children", inner2.Pass()); | 722 root->Set("dict_with_empty_children", inner2.Pass()); |
| 723 root.reset(root->DeepCopyWithoutEmptyChildren()); | 723 root = root->DeepCopyWithoutEmptyChildren(); |
| 724 EXPECT_EQ(2U, root->size()); | 724 EXPECT_EQ(2U, root->size()); |
| 725 } | 725 } |
| 726 | 726 |
| 727 // Make sure nested values don't get pruned. | 727 // Make sure nested values don't get pruned. |
| 728 { | 728 { |
| 729 scoped_ptr<ListValue> inner(new ListValue); | 729 scoped_ptr<ListValue> inner(new ListValue); |
| 730 scoped_ptr<ListValue> inner2(new ListValue); | 730 scoped_ptr<ListValue> inner2(new ListValue); |
| 731 inner2->Append(make_scoped_ptr(new StringValue("hello"))); | 731 inner2->Append(make_scoped_ptr(new StringValue("hello"))); |
| 732 inner->Append(make_scoped_ptr(new DictionaryValue)); | 732 inner->Append(make_scoped_ptr(new DictionaryValue)); |
| 733 inner->Append(inner2.Pass()); | 733 inner->Append(inner2.Pass()); |
| 734 root->Set("list_with_empty_children", inner.Pass()); | 734 root->Set("list_with_empty_children", inner.Pass()); |
| 735 root.reset(root->DeepCopyWithoutEmptyChildren()); | 735 root = root->DeepCopyWithoutEmptyChildren(); |
| 736 EXPECT_EQ(3U, root->size()); | 736 EXPECT_EQ(3U, root->size()); |
| 737 | 737 |
| 738 ListValue* inner_value, *inner_value2; | 738 ListValue* inner_value, *inner_value2; |
| 739 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner_value)); | 739 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner_value)); |
| 740 EXPECT_EQ(1U, inner_value->GetSize()); // Dictionary was pruned. | 740 EXPECT_EQ(1U, inner_value->GetSize()); // Dictionary was pruned. |
| 741 EXPECT_TRUE(inner_value->GetList(0, &inner_value2)); | 741 EXPECT_TRUE(inner_value->GetList(0, &inner_value2)); |
| 742 EXPECT_EQ(1U, inner_value2->GetSize()); | 742 EXPECT_EQ(1U, inner_value2->GetSize()); |
| 743 } | 743 } |
| 744 } | 744 } |
| 745 | 745 |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 EXPECT_FALSE(main_list.GetList(1, NULL)); | 1136 EXPECT_FALSE(main_list.GetList(1, NULL)); |
| 1137 EXPECT_FALSE(main_list.GetList(2, NULL)); | 1137 EXPECT_FALSE(main_list.GetList(2, NULL)); |
| 1138 EXPECT_FALSE(main_list.GetList(3, NULL)); | 1138 EXPECT_FALSE(main_list.GetList(3, NULL)); |
| 1139 EXPECT_FALSE(main_list.GetList(4, NULL)); | 1139 EXPECT_FALSE(main_list.GetList(4, NULL)); |
| 1140 EXPECT_FALSE(main_list.GetList(5, NULL)); | 1140 EXPECT_FALSE(main_list.GetList(5, NULL)); |
| 1141 EXPECT_TRUE(main_list.GetList(6, NULL)); | 1141 EXPECT_TRUE(main_list.GetList(6, NULL)); |
| 1142 EXPECT_FALSE(main_list.GetList(7, NULL)); | 1142 EXPECT_FALSE(main_list.GetList(7, NULL)); |
| 1143 } | 1143 } |
| 1144 | 1144 |
| 1145 } // namespace base | 1145 } // namespace base |
| OLD | NEW |