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 "components/policy/core/browser/configuration_policy_pref_store.h" | 5 #include "components/policy/core/browser/configuration_policy_pref_store.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 }; | 80 }; |
81 | 81 |
82 TEST_F(ConfigurationPolicyPrefStoreStringTest, GetDefault) { | 82 TEST_F(ConfigurationPolicyPrefStoreStringTest, GetDefault) { |
83 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); | 83 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); |
84 } | 84 } |
85 | 85 |
86 TEST_F(ConfigurationPolicyPrefStoreStringTest, SetValue) { | 86 TEST_F(ConfigurationPolicyPrefStoreStringTest, SetValue) { |
87 PolicyMap policy; | 87 PolicyMap policy; |
88 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 88 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
89 POLICY_SOURCE_CLOUD, | 89 POLICY_SOURCE_CLOUD, |
90 base::MakeUnique<base::StringValue>("http://chromium.org"), | 90 base::MakeUnique<base::Value>("http://chromium.org"), nullptr); |
91 nullptr); | |
92 UpdateProviderPolicy(policy); | 91 UpdateProviderPolicy(policy); |
93 const base::Value* value = NULL; | 92 const base::Value* value = NULL; |
94 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); | 93 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); |
95 ASSERT_TRUE(value); | 94 ASSERT_TRUE(value); |
96 EXPECT_TRUE(base::StringValue("http://chromium.org").Equals(value)); | 95 EXPECT_TRUE(base::Value("http://chromium.org").Equals(value)); |
97 } | 96 } |
98 | 97 |
99 // Test cases for boolean-valued policy settings. | 98 // Test cases for boolean-valued policy settings. |
100 class ConfigurationPolicyPrefStoreBooleanTest | 99 class ConfigurationPolicyPrefStoreBooleanTest |
101 : public ConfigurationPolicyPrefStoreTest { | 100 : public ConfigurationPolicyPrefStoreTest { |
102 void SetUp() override { | 101 void SetUp() override { |
103 handler_list_.AddHandler( | 102 handler_list_.AddHandler( |
104 base::WrapUnique<ConfigurationPolicyHandler>(new SimplePolicyHandler( | 103 base::WrapUnique<ConfigurationPolicyHandler>(new SimplePolicyHandler( |
105 kTestPolicy, kTestPref, base::Value::Type::BOOLEAN))); | 104 kTestPolicy, kTestPref, base::Value::Type::BOOLEAN))); |
106 } | 105 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 PrefStoreObserverMock observer_; | 178 PrefStoreObserverMock observer_; |
180 }; | 179 }; |
181 | 180 |
182 TEST_F(ConfigurationPolicyPrefStoreRefreshTest, Refresh) { | 181 TEST_F(ConfigurationPolicyPrefStoreRefreshTest, Refresh) { |
183 const base::Value* value = NULL; | 182 const base::Value* value = NULL; |
184 EXPECT_FALSE(store_->GetValue(kTestPolicy, NULL)); | 183 EXPECT_FALSE(store_->GetValue(kTestPolicy, NULL)); |
185 | 184 |
186 PolicyMap policy; | 185 PolicyMap policy; |
187 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 186 policy.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
188 POLICY_SOURCE_CLOUD, | 187 POLICY_SOURCE_CLOUD, |
189 base::MakeUnique<base::StringValue>("http://www.chromium.org"), | 188 base::MakeUnique<base::Value>("http://www.chromium.org"), nullptr); |
190 nullptr); | |
191 UpdateProviderPolicy(policy); | 189 UpdateProviderPolicy(policy); |
192 observer_.VerifyAndResetChangedKey(kTestPref); | 190 observer_.VerifyAndResetChangedKey(kTestPref); |
193 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); | 191 EXPECT_TRUE(store_->GetValue(kTestPref, &value)); |
194 EXPECT_TRUE(base::StringValue("http://www.chromium.org").Equals(value)); | 192 EXPECT_TRUE(base::Value("http://www.chromium.org").Equals(value)); |
195 | 193 |
196 UpdateProviderPolicy(policy); | 194 UpdateProviderPolicy(policy); |
197 EXPECT_TRUE(observer_.changed_keys.empty()); | 195 EXPECT_TRUE(observer_.changed_keys.empty()); |
198 | 196 |
199 policy.Erase(kTestPolicy); | 197 policy.Erase(kTestPolicy); |
200 UpdateProviderPolicy(policy); | 198 UpdateProviderPolicy(policy); |
201 observer_.VerifyAndResetChangedKey(kTestPref); | 199 observer_.VerifyAndResetChangedKey(kTestPref); |
202 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); | 200 EXPECT_FALSE(store_->GetValue(kTestPref, NULL)); |
203 } | 201 } |
204 | 202 |
205 TEST_F(ConfigurationPolicyPrefStoreRefreshTest, Initialization) { | 203 TEST_F(ConfigurationPolicyPrefStoreRefreshTest, Initialization) { |
206 EXPECT_FALSE(store_->IsInitializationComplete()); | 204 EXPECT_FALSE(store_->IsInitializationComplete()); |
207 EXPECT_CALL(provider_, IsInitializationComplete(POLICY_DOMAIN_CHROME)) | 205 EXPECT_CALL(provider_, IsInitializationComplete(POLICY_DOMAIN_CHROME)) |
208 .WillRepeatedly(Return(true)); | 206 .WillRepeatedly(Return(true)); |
209 PolicyMap policy; | 207 PolicyMap policy; |
210 UpdateProviderPolicy(policy); | 208 UpdateProviderPolicy(policy); |
211 EXPECT_TRUE(observer_.initialized); | 209 EXPECT_TRUE(observer_.initialized); |
212 EXPECT_TRUE(observer_.initialization_success); | 210 EXPECT_TRUE(observer_.initialization_success); |
213 Mock::VerifyAndClearExpectations(&observer_); | 211 Mock::VerifyAndClearExpectations(&observer_); |
214 EXPECT_TRUE(store_->IsInitializationComplete()); | 212 EXPECT_TRUE(store_->IsInitializationComplete()); |
215 } | 213 } |
216 | 214 |
217 } // namespace policy | 215 } // namespace policy |
OLD | NEW |