OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h" | 5 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/common/pref_names.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
14 | 13 |
15 class PrefServiceHashStoreContentsTest : public testing::Test { | 14 class PrefServiceHashStoreContentsTest : public testing::Test { |
16 public: | 15 public: |
17 virtual void SetUp() OVERRIDE { | 16 virtual void SetUp() OVERRIDE { |
18 PrefServiceHashStoreContents::RegisterPrefs(local_state_.registry()); | 17 PrefServiceHashStoreContents::RegisterPrefs(local_state_.registry()); |
19 } | 18 } |
20 | 19 |
21 protected: | 20 protected: |
22 TestingPrefServiceSimple local_state_; | 21 TestingPrefServiceSimple local_state_; |
(...skipping 14 matching lines...) Expand all Loading... |
37 { | 36 { |
38 PrefServiceHashStoreContents contents("store_id", &local_state_); | 37 PrefServiceHashStoreContents contents("store_id", &local_state_); |
39 ASSERT_TRUE(contents.IsInitialized()); | 38 ASSERT_TRUE(contents.IsInitialized()); |
40 PrefServiceHashStoreContents other_contents("other_store_id", | 39 PrefServiceHashStoreContents other_contents("other_store_id", |
41 &local_state_); | 40 &local_state_); |
42 ASSERT_FALSE(other_contents.IsInitialized()); | 41 ASSERT_FALSE(other_contents.IsInitialized()); |
43 } | 42 } |
44 } | 43 } |
45 | 44 |
46 TEST_F(PrefServiceHashStoreContentsTest, Reset) { | 45 TEST_F(PrefServiceHashStoreContentsTest, Reset) { |
47 ASSERT_FALSE(local_state_.GetUserPrefValue(prefs::kProfilePreferenceHashes)); | 46 ASSERT_FALSE(local_state_.GetUserPrefValue( |
| 47 PrefServiceHashStoreContents::kProfilePreferenceHashes)); |
48 | 48 |
49 { | 49 { |
50 PrefServiceHashStoreContents contents("store_id", &local_state_); | 50 PrefServiceHashStoreContents contents("store_id", &local_state_); |
51 ASSERT_FALSE(contents.IsInitialized()); | 51 ASSERT_FALSE(contents.IsInitialized()); |
52 (*contents.GetMutableContents())->Set("foo", new base::StringValue("bar")); | 52 (*contents.GetMutableContents())->Set("foo", new base::StringValue("bar")); |
53 ASSERT_TRUE(contents.IsInitialized()); | 53 ASSERT_TRUE(contents.IsInitialized()); |
54 PrefServiceHashStoreContents other_contents("other_store_id", | 54 PrefServiceHashStoreContents other_contents("other_store_id", |
55 &local_state_); | 55 &local_state_); |
56 (*other_contents.GetMutableContents()) | 56 (*other_contents.GetMutableContents()) |
57 ->Set("foo", new base::StringValue("bar")); | 57 ->Set("foo", new base::StringValue("bar")); |
58 } | 58 } |
59 | 59 |
60 ASSERT_TRUE(local_state_.GetUserPrefValue(prefs::kProfilePreferenceHashes)); | 60 ASSERT_TRUE(local_state_.GetUserPrefValue( |
| 61 PrefServiceHashStoreContents::kProfilePreferenceHashes)); |
61 | 62 |
62 { | 63 { |
63 PrefServiceHashStoreContents contents("store_id", &local_state_); | 64 PrefServiceHashStoreContents contents("store_id", &local_state_); |
64 ASSERT_TRUE(contents.IsInitialized()); | 65 ASSERT_TRUE(contents.IsInitialized()); |
65 contents.Reset(); | 66 contents.Reset(); |
66 ASSERT_FALSE(contents.IsInitialized()); | 67 ASSERT_FALSE(contents.IsInitialized()); |
67 } | 68 } |
68 | 69 |
69 ASSERT_TRUE(local_state_.GetUserPrefValue(prefs::kProfilePreferenceHashes)); | 70 ASSERT_TRUE(local_state_.GetUserPrefValue( |
| 71 PrefServiceHashStoreContents::kProfilePreferenceHashes)); |
70 | 72 |
71 { | 73 { |
72 PrefServiceHashStoreContents contents("store_id", &local_state_); | 74 PrefServiceHashStoreContents contents("store_id", &local_state_); |
73 ASSERT_FALSE(contents.IsInitialized()); | 75 ASSERT_FALSE(contents.IsInitialized()); |
74 PrefServiceHashStoreContents other_contents("other_store_id", | 76 PrefServiceHashStoreContents other_contents("other_store_id", |
75 &local_state_); | 77 &local_state_); |
76 ASSERT_TRUE(other_contents.IsInitialized()); | 78 ASSERT_TRUE(other_contents.IsInitialized()); |
77 } | 79 } |
78 | 80 |
79 { | 81 { |
80 PrefServiceHashStoreContents other_contents("other_store_id", | 82 PrefServiceHashStoreContents other_contents("other_store_id", |
81 &local_state_); | 83 &local_state_); |
82 other_contents.Reset(); | 84 other_contents.Reset(); |
83 } | 85 } |
84 | 86 |
85 ASSERT_FALSE(local_state_.GetUserPrefValue(prefs::kProfilePreferenceHashes)); | 87 ASSERT_FALSE(local_state_.GetUserPrefValue( |
| 88 PrefServiceHashStoreContents::kProfilePreferenceHashes)); |
86 } | 89 } |
87 | 90 |
88 TEST_F(PrefServiceHashStoreContentsTest, GetAndSetContents) { | 91 TEST_F(PrefServiceHashStoreContentsTest, GetAndSetContents) { |
89 { | 92 { |
90 PrefServiceHashStoreContents contents("store_id", &local_state_); | 93 PrefServiceHashStoreContents contents("store_id", &local_state_); |
91 ASSERT_EQ(NULL, contents.GetContents()); | 94 ASSERT_EQ(NULL, contents.GetContents()); |
92 (*contents.GetMutableContents())->Set("foo", new base::StringValue("bar")); | 95 (*contents.GetMutableContents())->Set("foo", new base::StringValue("bar")); |
93 ASSERT_FALSE(contents.GetContents() == NULL); | 96 ASSERT_FALSE(contents.GetContents() == NULL); |
94 std::string actual_value; | 97 std::string actual_value; |
95 ASSERT_TRUE(contents.GetContents()->GetString("foo", &actual_value)); | 98 ASSERT_TRUE(contents.GetContents()->GetString("foo", &actual_value)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 143 |
141 PrefServiceHashStoreContents::ResetAllPrefHashStores(&local_state_); | 144 PrefServiceHashStoreContents::ResetAllPrefHashStores(&local_state_); |
142 | 145 |
143 { | 146 { |
144 PrefServiceHashStoreContents contents_1("store_id_1", &local_state_); | 147 PrefServiceHashStoreContents contents_1("store_id_1", &local_state_); |
145 PrefServiceHashStoreContents contents_2("store_id_2", &local_state_); | 148 PrefServiceHashStoreContents contents_2("store_id_2", &local_state_); |
146 ASSERT_FALSE(contents_1.IsInitialized()); | 149 ASSERT_FALSE(contents_1.IsInitialized()); |
147 ASSERT_FALSE(contents_2.IsInitialized()); | 150 ASSERT_FALSE(contents_2.IsInitialized()); |
148 } | 151 } |
149 } | 152 } |
OLD | NEW |