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 ; | |
brettw
2015/05/22 20:59:32
Did you screw up search and replace for these plac
Evan Stade
2015/05/22 21:28:57
must have done
| |
683 EXPECT_EQ(2U, root->size()); | 684 EXPECT_EQ(2U, root->size()); |
684 | 685 |
685 // Should do nothing. | 686 // Should do nothing. |
686 root.reset(root->DeepCopyWithoutEmptyChildren()); | 687 root = root->DeepCopyWithoutEmptyChildren(); |
688 ; | |
687 EXPECT_EQ(2U, root->size()); | 689 EXPECT_EQ(2U, root->size()); |
688 | 690 |
689 // Nested test cases. These should all reduce back to the bool and string | 691 // Nested test cases. These should all reduce back to the bool and string |
690 // set above. | 692 // set above. |
691 { | 693 { |
692 root->Set("a.b.c.d.e", make_scoped_ptr(new DictionaryValue)); | 694 root->Set("a.b.c.d.e", make_scoped_ptr(new DictionaryValue)); |
693 root.reset(root->DeepCopyWithoutEmptyChildren()); | 695 root = root->DeepCopyWithoutEmptyChildren(); |
696 ; | |
694 EXPECT_EQ(2U, root->size()); | 697 EXPECT_EQ(2U, root->size()); |
695 } | 698 } |
696 { | 699 { |
697 scoped_ptr<DictionaryValue> inner(new DictionaryValue); | 700 scoped_ptr<DictionaryValue> inner(new DictionaryValue); |
698 inner->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); | 701 inner->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); |
699 inner->Set("empty_list", make_scoped_ptr(new ListValue)); | 702 inner->Set("empty_list", make_scoped_ptr(new ListValue)); |
700 root->Set("dict_with_empty_children", inner.Pass()); | 703 root->Set("dict_with_empty_children", inner.Pass()); |
701 root.reset(root->DeepCopyWithoutEmptyChildren()); | 704 root = root->DeepCopyWithoutEmptyChildren(); |
705 ; | |
702 EXPECT_EQ(2U, root->size()); | 706 EXPECT_EQ(2U, root->size()); |
703 } | 707 } |
704 { | 708 { |
705 scoped_ptr<ListValue> inner(new ListValue); | 709 scoped_ptr<ListValue> inner(new ListValue); |
706 inner->Append(make_scoped_ptr(new DictionaryValue)); | 710 inner->Append(make_scoped_ptr(new DictionaryValue)); |
707 inner->Append(make_scoped_ptr(new ListValue)); | 711 inner->Append(make_scoped_ptr(new ListValue)); |
708 root->Set("list_with_empty_children", inner.Pass()); | 712 root->Set("list_with_empty_children", inner.Pass()); |
709 root.reset(root->DeepCopyWithoutEmptyChildren()); | 713 root = root->DeepCopyWithoutEmptyChildren(); |
714 ; | |
710 EXPECT_EQ(2U, root->size()); | 715 EXPECT_EQ(2U, root->size()); |
711 } | 716 } |
712 | 717 |
713 // Nested with siblings. | 718 // Nested with siblings. |
714 { | 719 { |
715 scoped_ptr<ListValue> inner(new ListValue()); | 720 scoped_ptr<ListValue> inner(new ListValue()); |
716 inner->Append(make_scoped_ptr(new DictionaryValue)); | 721 inner->Append(make_scoped_ptr(new DictionaryValue)); |
717 inner->Append(make_scoped_ptr(new ListValue)); | 722 inner->Append(make_scoped_ptr(new ListValue)); |
718 root->Set("list_with_empty_children", inner.Pass()); | 723 root->Set("list_with_empty_children", inner.Pass()); |
719 scoped_ptr<DictionaryValue> inner2(new DictionaryValue); | 724 scoped_ptr<DictionaryValue> inner2(new DictionaryValue); |
720 inner2->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); | 725 inner2->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); |
721 inner2->Set("empty_list", make_scoped_ptr(new ListValue)); | 726 inner2->Set("empty_list", make_scoped_ptr(new ListValue)); |
722 root->Set("dict_with_empty_children", inner2.Pass()); | 727 root->Set("dict_with_empty_children", inner2.Pass()); |
723 root.reset(root->DeepCopyWithoutEmptyChildren()); | 728 root = root->DeepCopyWithoutEmptyChildren(); |
729 ; | |
724 EXPECT_EQ(2U, root->size()); | 730 EXPECT_EQ(2U, root->size()); |
725 } | 731 } |
726 | 732 |
727 // Make sure nested values don't get pruned. | 733 // Make sure nested values don't get pruned. |
728 { | 734 { |
729 scoped_ptr<ListValue> inner(new ListValue); | 735 scoped_ptr<ListValue> inner(new ListValue); |
730 scoped_ptr<ListValue> inner2(new ListValue); | 736 scoped_ptr<ListValue> inner2(new ListValue); |
731 inner2->Append(make_scoped_ptr(new StringValue("hello"))); | 737 inner2->Append(make_scoped_ptr(new StringValue("hello"))); |
732 inner->Append(make_scoped_ptr(new DictionaryValue)); | 738 inner->Append(make_scoped_ptr(new DictionaryValue)); |
733 inner->Append(inner2.Pass()); | 739 inner->Append(inner2.Pass()); |
734 root->Set("list_with_empty_children", inner.Pass()); | 740 root->Set("list_with_empty_children", inner.Pass()); |
735 root.reset(root->DeepCopyWithoutEmptyChildren()); | 741 root = root->DeepCopyWithoutEmptyChildren(); |
742 ; | |
736 EXPECT_EQ(3U, root->size()); | 743 EXPECT_EQ(3U, root->size()); |
737 | 744 |
738 ListValue* inner_value, *inner_value2; | 745 ListValue* inner_value, *inner_value2; |
739 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner_value)); | 746 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner_value)); |
740 EXPECT_EQ(1U, inner_value->GetSize()); // Dictionary was pruned. | 747 EXPECT_EQ(1U, inner_value->GetSize()); // Dictionary was pruned. |
741 EXPECT_TRUE(inner_value->GetList(0, &inner_value2)); | 748 EXPECT_TRUE(inner_value->GetList(0, &inner_value2)); |
742 EXPECT_EQ(1U, inner_value2->GetSize()); | 749 EXPECT_EQ(1U, inner_value2->GetSize()); |
743 } | 750 } |
744 } | 751 } |
745 | 752 |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1136 EXPECT_FALSE(main_list.GetList(1, NULL)); | 1143 EXPECT_FALSE(main_list.GetList(1, NULL)); |
1137 EXPECT_FALSE(main_list.GetList(2, NULL)); | 1144 EXPECT_FALSE(main_list.GetList(2, NULL)); |
1138 EXPECT_FALSE(main_list.GetList(3, NULL)); | 1145 EXPECT_FALSE(main_list.GetList(3, NULL)); |
1139 EXPECT_FALSE(main_list.GetList(4, NULL)); | 1146 EXPECT_FALSE(main_list.GetList(4, NULL)); |
1140 EXPECT_FALSE(main_list.GetList(5, NULL)); | 1147 EXPECT_FALSE(main_list.GetList(5, NULL)); |
1141 EXPECT_TRUE(main_list.GetList(6, NULL)); | 1148 EXPECT_TRUE(main_list.GetList(6, NULL)); |
1142 EXPECT_FALSE(main_list.GetList(7, NULL)); | 1149 EXPECT_FALSE(main_list.GetList(7, NULL)); |
1143 } | 1150 } |
1144 | 1151 |
1145 } // namespace base | 1152 } // namespace base |
OLD | NEW |