Content settings: remove some plugin-related code/resources when... there are no...
[chromium-blink-merge.git] / components / user_prefs / tracked / pref_service_hash_store_contents_unittest.cc
blob09003d9ecdd0b06ac4905b9994c0809afb3789cf
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
3 // found in the LICENSE file.
5 #include "components/user_prefs/tracked/pref_service_hash_store_contents.h"
7 #include <string>
9 #include "base/prefs/pref_service.h"
10 #include "base/prefs/testing_pref_service.h"
11 #include "base/values.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 class PrefServiceHashStoreContentsTest : public testing::Test {
15 public:
16 void SetUp() override {
17 PrefServiceHashStoreContents::RegisterPrefs(local_state_.registry());
20 protected:
21 TestingPrefServiceSimple local_state_;
24 TEST_F(PrefServiceHashStoreContentsTest, hash_store_id) {
25 PrefServiceHashStoreContents contents("store_id", &local_state_);
26 ASSERT_EQ("store_id", contents.hash_store_id());
29 TEST_F(PrefServiceHashStoreContentsTest, IsInitialized) {
31 PrefServiceHashStoreContents contents("store_id", &local_state_);
32 ASSERT_FALSE(contents.IsInitialized());
33 (*contents.GetMutableContents())->Set("foo", new base::StringValue("bar"));
34 ASSERT_TRUE(contents.IsInitialized());
37 PrefServiceHashStoreContents contents("store_id", &local_state_);
38 ASSERT_TRUE(contents.IsInitialized());
39 PrefServiceHashStoreContents other_contents("other_store_id",
40 &local_state_);
41 ASSERT_FALSE(other_contents.IsInitialized());
45 TEST_F(PrefServiceHashStoreContentsTest, Reset) {
46 ASSERT_FALSE(local_state_.GetUserPrefValue(
47 PrefServiceHashStoreContents::kProfilePreferenceHashes));
50 PrefServiceHashStoreContents contents("store_id", &local_state_);
51 ASSERT_FALSE(contents.IsInitialized());
52 (*contents.GetMutableContents())->Set("foo", new base::StringValue("bar"));
53 ASSERT_TRUE(contents.IsInitialized());
54 PrefServiceHashStoreContents other_contents("other_store_id",
55 &local_state_);
56 (*other_contents.GetMutableContents())
57 ->Set("foo", new base::StringValue("bar"));
60 ASSERT_TRUE(local_state_.GetUserPrefValue(
61 PrefServiceHashStoreContents::kProfilePreferenceHashes));
64 PrefServiceHashStoreContents contents("store_id", &local_state_);
65 ASSERT_TRUE(contents.IsInitialized());
66 contents.Reset();
67 ASSERT_FALSE(contents.IsInitialized());
70 ASSERT_TRUE(local_state_.GetUserPrefValue(
71 PrefServiceHashStoreContents::kProfilePreferenceHashes));
74 PrefServiceHashStoreContents contents("store_id", &local_state_);
75 ASSERT_FALSE(contents.IsInitialized());
76 PrefServiceHashStoreContents other_contents("other_store_id",
77 &local_state_);
78 ASSERT_TRUE(other_contents.IsInitialized());
82 PrefServiceHashStoreContents other_contents("other_store_id",
83 &local_state_);
84 other_contents.Reset();
87 ASSERT_FALSE(local_state_.GetUserPrefValue(
88 PrefServiceHashStoreContents::kProfilePreferenceHashes));
91 TEST_F(PrefServiceHashStoreContentsTest, GetAndSetContents) {
93 PrefServiceHashStoreContents contents("store_id", &local_state_);
94 ASSERT_EQ(NULL, contents.GetContents());
95 (*contents.GetMutableContents())->Set("foo", new base::StringValue("bar"));
96 ASSERT_FALSE(contents.GetContents() == NULL);
97 std::string actual_value;
98 ASSERT_TRUE(contents.GetContents()->GetString("foo", &actual_value));
99 ASSERT_EQ("bar", actual_value);
100 PrefServiceHashStoreContents other_contents("other_store_id",
101 &local_state_);
102 ASSERT_EQ(NULL, other_contents.GetContents());
105 PrefServiceHashStoreContents contents("store_id", &local_state_);
106 ASSERT_FALSE(contents.GetContents() == NULL);
110 TEST_F(PrefServiceHashStoreContentsTest, GetAndSetSuperMac) {
112 PrefServiceHashStoreContents contents("store_id", &local_state_);
113 ASSERT_TRUE(contents.GetSuperMac().empty());
114 (*contents.GetMutableContents())->Set("foo", new base::StringValue("bar"));
115 ASSERT_TRUE(contents.GetSuperMac().empty());
116 contents.SetSuperMac("0123456789");
117 ASSERT_EQ("0123456789", contents.GetSuperMac());
120 PrefServiceHashStoreContents contents("store_id", &local_state_);
121 ASSERT_EQ("0123456789", contents.GetSuperMac());
122 PrefServiceHashStoreContents other_contents("other_store_id",
123 &local_state_);
124 ASSERT_TRUE(other_contents.GetSuperMac().empty());
128 TEST_F(PrefServiceHashStoreContentsTest, ResetAllPrefHashStores) {
130 PrefServiceHashStoreContents contents_1("store_id_1", &local_state_);
131 PrefServiceHashStoreContents contents_2("store_id_2", &local_state_);
132 (*contents_1.GetMutableContents())
133 ->Set("foo", new base::StringValue("bar"));
134 (*contents_2.GetMutableContents())
135 ->Set("foo", new base::StringValue("bar"));
138 PrefServiceHashStoreContents contents_1("store_id_1", &local_state_);
139 PrefServiceHashStoreContents contents_2("store_id_2", &local_state_);
140 ASSERT_TRUE(contents_1.IsInitialized());
141 ASSERT_TRUE(contents_2.IsInitialized());
144 PrefServiceHashStoreContents::ResetAllPrefHashStores(&local_state_);
147 PrefServiceHashStoreContents contents_1("store_id_1", &local_state_);
148 PrefServiceHashStoreContents contents_2("store_id_2", &local_state_);
149 ASSERT_FALSE(contents_1.IsInitialized());
150 ASSERT_FALSE(contents_2.IsInitialized());