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

Side by Side Diff: base/values_unittest.cc

Issue 2027010: Preference provider implementation backed by JSON files in a directory. (Closed)
Patch Set: A few more fixes. Created 10 years, 7 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 unified diff | Download patch
« no previous file with comments | « base/values.cc ('k') | chrome/browser/config_dir_policy_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 inner->Append(inner2); 585 inner->Append(inner2);
586 inner2->Append(Value::CreateStringValue("hello")); 586 inner2->Append(Value::CreateStringValue("hello"));
587 root.reset(root->DeepCopyWithoutEmptyChildren()); 587 root.reset(root->DeepCopyWithoutEmptyChildren());
588 EXPECT_EQ(3U, root->size()); 588 EXPECT_EQ(3U, root->size());
589 EXPECT_TRUE(root->GetList(L"list_with_empty_children", &inner)); 589 EXPECT_TRUE(root->GetList(L"list_with_empty_children", &inner));
590 EXPECT_EQ(1U, inner->GetSize()); // Dictionary was pruned. 590 EXPECT_EQ(1U, inner->GetSize()); // Dictionary was pruned.
591 EXPECT_TRUE(inner->GetList(0, &inner2)); 591 EXPECT_TRUE(inner->GetList(0, &inner2));
592 EXPECT_EQ(1U, inner2->GetSize()); 592 EXPECT_EQ(1U, inner2->GetSize());
593 } 593 }
594 } 594 }
595
596 TEST(ValuesTest, MergeDictionary) {
597 scoped_ptr<DictionaryValue> base(new DictionaryValue);
598 base->SetString(L"base_key", "base_key_value_base");
599 base->SetString(L"collide_key", "collide_key_value_base");
600 DictionaryValue* base_sub_dict = new DictionaryValue;
601 base_sub_dict->SetString(L"sub_base_key", "sub_base_key_value_base");
602 base_sub_dict->SetString(L"sub_collide_key", "sub_collide_key_value_base");
603 base->Set(L"sub_dict_key", base_sub_dict);
604
605 scoped_ptr<DictionaryValue> merge(new DictionaryValue);
606 merge->SetString(L"merge_key", "merge_key_value_merge");
607 merge->SetString(L"collide_key", "collide_key_value_merge");
608 DictionaryValue* merge_sub_dict = new DictionaryValue;
609 merge_sub_dict->SetString(L"sub_merge_key", "sub_merge_key_value_merge");
610 merge_sub_dict->SetString(L"sub_collide_key", "sub_collide_key_value_merge");
611 merge->Set(L"sub_dict_key", merge_sub_dict);
612
613 base->MergeDictionary(merge.get());
614
615 EXPECT_EQ(4U, base->size());
616 std::string base_key_value;
617 EXPECT_TRUE(base->GetString(L"base_key", &base_key_value));
618 EXPECT_EQ("base_key_value_base", base_key_value); // Base value preserved.
619 std::string collide_key_value;
620 EXPECT_TRUE(base->GetString(L"collide_key", &collide_key_value));
621 EXPECT_EQ("collide_key_value_merge", collide_key_value); // Replaced.
622 std::string merge_key_value;
623 EXPECT_TRUE(base->GetString(L"merge_key", &merge_key_value));
624 EXPECT_EQ("merge_key_value_merge", merge_key_value); // Merged in.
625
626 DictionaryValue* res_sub_dict;
627 EXPECT_TRUE(base->GetDictionary(L"sub_dict_key", &res_sub_dict));
628 EXPECT_EQ(3U, res_sub_dict->size());
629 std::string sub_base_key_value;
630 EXPECT_TRUE(res_sub_dict->GetString(L"sub_base_key", &sub_base_key_value));
631 EXPECT_EQ("sub_base_key_value_base", sub_base_key_value); // Preserved.
632 std::string sub_collide_key_value;
633 EXPECT_TRUE(res_sub_dict->GetString(L"sub_collide_key",
634 &sub_collide_key_value));
635 EXPECT_EQ("sub_collide_key_value_merge", sub_collide_key_value); // Replaced.
636 std::string sub_merge_key_value;
637 EXPECT_TRUE(res_sub_dict->GetString(L"sub_merge_key", &sub_merge_key_value));
638 EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in.
639 }
OLDNEW
« no previous file with comments | « base/values.cc ('k') | chrome/browser/config_dir_policy_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698