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 "components/policy/core/common/policy_service_impl.h" | 5 #include "components/policy/core/common/policy_service_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 class ChangePolicyObserver : public PolicyService::Observer { | 67 class ChangePolicyObserver : public PolicyService::Observer { |
68 public: | 68 public: |
69 explicit ChangePolicyObserver(MockConfigurationPolicyProvider* provider) | 69 explicit ChangePolicyObserver(MockConfigurationPolicyProvider* provider) |
70 : provider_(provider), | 70 : provider_(provider), |
71 observer_invoked_(false) {} | 71 observer_invoked_(false) {} |
72 | 72 |
73 virtual void OnPolicyUpdated(const PolicyNamespace&, | 73 virtual void OnPolicyUpdated(const PolicyNamespace&, |
74 const PolicyMap& previous, | 74 const PolicyMap& previous, |
75 const PolicyMap& current) OVERRIDE { | 75 const PolicyMap& current) OVERRIDE { |
76 PolicyMap new_policy; | 76 PolicyMap new_policy; |
77 new_policy.Set("foo", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 77 new_policy.Set("foo", |
78 base::Value::CreateIntegerValue(14), NULL); | 78 POLICY_LEVEL_MANDATORY, |
| 79 POLICY_SCOPE_USER, |
| 80 new base::FundamentalValue(14), |
| 81 NULL); |
79 provider_->UpdateChromePolicy(new_policy); | 82 provider_->UpdateChromePolicy(new_policy); |
80 observer_invoked_ = true; | 83 observer_invoked_ = true; |
81 } | 84 } |
82 | 85 |
83 bool observer_invoked() const { return observer_invoked_; } | 86 bool observer_invoked() const { return observer_invoked_; } |
84 | 87 |
85 private: | 88 private: |
86 MockConfigurationPolicyProvider* provider_; | 89 MockConfigurationPolicyProvider* provider_; |
87 bool observer_invoked_; | 90 bool observer_invoked_; |
88 }; | 91 }; |
89 | 92 |
90 } // namespace | 93 } // namespace |
91 | 94 |
92 class PolicyServiceTest : public testing::Test { | 95 class PolicyServiceTest : public testing::Test { |
93 public: | 96 public: |
94 PolicyServiceTest() {} | 97 PolicyServiceTest() {} |
95 virtual void SetUp() OVERRIDE { | 98 virtual void SetUp() OVERRIDE { |
96 EXPECT_CALL(provider0_, IsInitializationComplete(_)) | 99 EXPECT_CALL(provider0_, IsInitializationComplete(_)) |
97 .WillRepeatedly(Return(true)); | 100 .WillRepeatedly(Return(true)); |
98 EXPECT_CALL(provider1_, IsInitializationComplete(_)) | 101 EXPECT_CALL(provider1_, IsInitializationComplete(_)) |
99 .WillRepeatedly(Return(true)); | 102 .WillRepeatedly(Return(true)); |
100 EXPECT_CALL(provider2_, IsInitializationComplete(_)) | 103 EXPECT_CALL(provider2_, IsInitializationComplete(_)) |
101 .WillRepeatedly(Return(true)); | 104 .WillRepeatedly(Return(true)); |
102 | 105 |
103 provider0_.Init(); | 106 provider0_.Init(); |
104 provider1_.Init(); | 107 provider1_.Init(); |
105 provider2_.Init(); | 108 provider2_.Init(); |
106 | 109 |
107 policy0_.Set("pre", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 110 policy0_.Set("pre", |
108 base::Value::CreateIntegerValue(13), NULL); | 111 POLICY_LEVEL_MANDATORY, |
| 112 POLICY_SCOPE_USER, |
| 113 new base::FundamentalValue(13), |
| 114 NULL); |
109 provider0_.UpdateChromePolicy(policy0_); | 115 provider0_.UpdateChromePolicy(policy0_); |
110 | 116 |
111 PolicyServiceImpl::Providers providers; | 117 PolicyServiceImpl::Providers providers; |
112 providers.push_back(&provider0_); | 118 providers.push_back(&provider0_); |
113 providers.push_back(&provider1_); | 119 providers.push_back(&provider1_); |
114 providers.push_back(&provider2_); | 120 providers.push_back(&provider2_); |
115 policy_service_.reset(new PolicyServiceImpl(providers)); | 121 policy_service_.reset(new PolicyServiceImpl(providers)); |
116 } | 122 } |
117 | 123 |
118 virtual void TearDown() OVERRIDE { | 124 virtual void TearDown() OVERRIDE { |
(...skipping 27 matching lines...) Expand all Loading... |
146 PolicyMap policy1_; | 152 PolicyMap policy1_; |
147 PolicyMap policy2_; | 153 PolicyMap policy2_; |
148 scoped_ptr<PolicyServiceImpl> policy_service_; | 154 scoped_ptr<PolicyServiceImpl> policy_service_; |
149 | 155 |
150 private: | 156 private: |
151 DISALLOW_COPY_AND_ASSIGN(PolicyServiceTest); | 157 DISALLOW_COPY_AND_ASSIGN(PolicyServiceTest); |
152 }; | 158 }; |
153 | 159 |
154 TEST_F(PolicyServiceTest, LoadsPoliciesBeforeProvidersRefresh) { | 160 TEST_F(PolicyServiceTest, LoadsPoliciesBeforeProvidersRefresh) { |
155 PolicyMap expected; | 161 PolicyMap expected; |
156 expected.Set("pre", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 162 expected.Set("pre", |
157 base::Value::CreateIntegerValue(13), NULL); | 163 POLICY_LEVEL_MANDATORY, |
| 164 POLICY_SCOPE_USER, |
| 165 new base::FundamentalValue(13), |
| 166 NULL); |
158 EXPECT_TRUE(VerifyPolicies( | 167 EXPECT_TRUE(VerifyPolicies( |
159 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expected)); | 168 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expected)); |
160 } | 169 } |
161 | 170 |
162 TEST_F(PolicyServiceTest, NotifyObservers) { | 171 TEST_F(PolicyServiceTest, NotifyObservers) { |
163 MockPolicyServiceObserver observer; | 172 MockPolicyServiceObserver observer; |
164 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, &observer); | 173 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, &observer); |
165 | 174 |
166 PolicyMap expectedPrevious; | 175 PolicyMap expectedPrevious; |
167 expectedPrevious.Set("pre", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 176 expectedPrevious.Set("pre", |
168 base::Value::CreateIntegerValue(13), NULL); | 177 POLICY_LEVEL_MANDATORY, |
| 178 POLICY_SCOPE_USER, |
| 179 new base::FundamentalValue(13), |
| 180 NULL); |
169 | 181 |
170 PolicyMap expectedCurrent; | 182 PolicyMap expectedCurrent; |
171 expectedCurrent.CopyFrom(expectedPrevious); | 183 expectedCurrent.CopyFrom(expectedPrevious); |
172 expectedCurrent.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 184 expectedCurrent.Set("aaa", |
173 base::Value::CreateIntegerValue(123), NULL); | 185 POLICY_LEVEL_MANDATORY, |
174 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 186 POLICY_SCOPE_USER, |
175 base::Value::CreateIntegerValue(123), NULL); | 187 new base::FundamentalValue(123), |
| 188 NULL); |
| 189 policy0_.Set("aaa", |
| 190 POLICY_LEVEL_MANDATORY, |
| 191 POLICY_SCOPE_USER, |
| 192 new base::FundamentalValue(123), |
| 193 NULL); |
176 EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, | 194 EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, |
177 std::string()), | 195 std::string()), |
178 PolicyEquals(&expectedPrevious), | 196 PolicyEquals(&expectedPrevious), |
179 PolicyEquals(&expectedCurrent))); | 197 PolicyEquals(&expectedCurrent))); |
180 provider0_.UpdateChromePolicy(policy0_); | 198 provider0_.UpdateChromePolicy(policy0_); |
181 Mock::VerifyAndClearExpectations(&observer); | 199 Mock::VerifyAndClearExpectations(&observer); |
182 | 200 |
183 // No changes. | 201 // No changes. |
184 EXPECT_CALL(observer, OnPolicyUpdated(_, _, _)).Times(0); | 202 EXPECT_CALL(observer, OnPolicyUpdated(_, _, _)).Times(0); |
185 provider0_.UpdateChromePolicy(policy0_); | 203 provider0_.UpdateChromePolicy(policy0_); |
186 Mock::VerifyAndClearExpectations(&observer); | 204 Mock::VerifyAndClearExpectations(&observer); |
187 EXPECT_TRUE(VerifyPolicies( | 205 EXPECT_TRUE(VerifyPolicies( |
188 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expectedCurrent)); | 206 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expectedCurrent)); |
189 | 207 |
190 // New policy. | 208 // New policy. |
191 expectedPrevious.CopyFrom(expectedCurrent); | 209 expectedPrevious.CopyFrom(expectedCurrent); |
192 expectedCurrent.Set("bbb", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 210 expectedCurrent.Set("bbb", |
193 base::Value::CreateIntegerValue(456), NULL); | 211 POLICY_LEVEL_MANDATORY, |
194 policy0_.Set("bbb", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 212 POLICY_SCOPE_USER, |
195 base::Value::CreateIntegerValue(456), NULL); | 213 new base::FundamentalValue(456), |
| 214 NULL); |
| 215 policy0_.Set("bbb", |
| 216 POLICY_LEVEL_MANDATORY, |
| 217 POLICY_SCOPE_USER, |
| 218 new base::FundamentalValue(456), |
| 219 NULL); |
196 EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, | 220 EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, |
197 std::string()), | 221 std::string()), |
198 PolicyEquals(&expectedPrevious), | 222 PolicyEquals(&expectedPrevious), |
199 PolicyEquals(&expectedCurrent))); | 223 PolicyEquals(&expectedCurrent))); |
200 provider0_.UpdateChromePolicy(policy0_); | 224 provider0_.UpdateChromePolicy(policy0_); |
201 Mock::VerifyAndClearExpectations(&observer); | 225 Mock::VerifyAndClearExpectations(&observer); |
202 | 226 |
203 // Removed policy. | 227 // Removed policy. |
204 expectedPrevious.CopyFrom(expectedCurrent); | 228 expectedPrevious.CopyFrom(expectedCurrent); |
205 expectedCurrent.Erase("bbb"); | 229 expectedCurrent.Erase("bbb"); |
206 policy0_.Erase("bbb"); | 230 policy0_.Erase("bbb"); |
207 EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, | 231 EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, |
208 std::string()), | 232 std::string()), |
209 PolicyEquals(&expectedPrevious), | 233 PolicyEquals(&expectedPrevious), |
210 PolicyEquals(&expectedCurrent))); | 234 PolicyEquals(&expectedCurrent))); |
211 provider0_.UpdateChromePolicy(policy0_); | 235 provider0_.UpdateChromePolicy(policy0_); |
212 Mock::VerifyAndClearExpectations(&observer); | 236 Mock::VerifyAndClearExpectations(&observer); |
213 | 237 |
214 // Changed policy. | 238 // Changed policy. |
215 expectedPrevious.CopyFrom(expectedCurrent); | 239 expectedPrevious.CopyFrom(expectedCurrent); |
216 expectedCurrent.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 240 expectedCurrent.Set("aaa", |
217 base::Value::CreateIntegerValue(789), NULL); | 241 POLICY_LEVEL_MANDATORY, |
218 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 242 POLICY_SCOPE_USER, |
219 base::Value::CreateIntegerValue(789), NULL); | 243 new base::FundamentalValue(789), |
| 244 NULL); |
| 245 policy0_.Set("aaa", |
| 246 POLICY_LEVEL_MANDATORY, |
| 247 POLICY_SCOPE_USER, |
| 248 new base::FundamentalValue(789), |
| 249 NULL); |
220 | 250 |
221 EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, | 251 EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, |
222 std::string()), | 252 std::string()), |
223 PolicyEquals(&expectedPrevious), | 253 PolicyEquals(&expectedPrevious), |
224 PolicyEquals(&expectedCurrent))); | 254 PolicyEquals(&expectedCurrent))); |
225 provider0_.UpdateChromePolicy(policy0_); | 255 provider0_.UpdateChromePolicy(policy0_); |
226 Mock::VerifyAndClearExpectations(&observer); | 256 Mock::VerifyAndClearExpectations(&observer); |
227 | 257 |
228 // No changes again. | 258 // No changes again. |
229 EXPECT_CALL(observer, OnPolicyUpdated(_, _, _)).Times(0); | 259 EXPECT_CALL(observer, OnPolicyUpdated(_, _, _)).Times(0); |
230 provider0_.UpdateChromePolicy(policy0_); | 260 provider0_.UpdateChromePolicy(policy0_); |
231 Mock::VerifyAndClearExpectations(&observer); | 261 Mock::VerifyAndClearExpectations(&observer); |
232 EXPECT_TRUE(VerifyPolicies( | 262 EXPECT_TRUE(VerifyPolicies( |
233 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expectedCurrent)); | 263 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expectedCurrent)); |
234 | 264 |
235 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, &observer); | 265 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, &observer); |
236 } | 266 } |
237 | 267 |
238 TEST_F(PolicyServiceTest, NotifyObserversInMultipleNamespaces) { | 268 TEST_F(PolicyServiceTest, NotifyObserversInMultipleNamespaces) { |
239 const std::string kExtension0("extension-0"); | 269 const std::string kExtension0("extension-0"); |
240 const std::string kExtension1("extension-1"); | 270 const std::string kExtension1("extension-1"); |
241 const std::string kExtension2("extension-2"); | 271 const std::string kExtension2("extension-2"); |
242 MockPolicyServiceObserver chrome_observer; | 272 MockPolicyServiceObserver chrome_observer; |
243 MockPolicyServiceObserver extension_observer; | 273 MockPolicyServiceObserver extension_observer; |
244 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, &chrome_observer); | 274 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, &chrome_observer); |
245 policy_service_->AddObserver(POLICY_DOMAIN_EXTENSIONS, &extension_observer); | 275 policy_service_->AddObserver(POLICY_DOMAIN_EXTENSIONS, &extension_observer); |
246 | 276 |
247 PolicyMap previous_policy_map; | 277 PolicyMap previous_policy_map; |
248 previous_policy_map.Set("pre", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 278 previous_policy_map.Set("pre", |
249 base::Value::CreateIntegerValue(13), NULL); | 279 POLICY_LEVEL_MANDATORY, |
| 280 POLICY_SCOPE_USER, |
| 281 new base::FundamentalValue(13), |
| 282 NULL); |
250 PolicyMap policy_map; | 283 PolicyMap policy_map; |
251 policy_map.CopyFrom(previous_policy_map); | 284 policy_map.CopyFrom(previous_policy_map); |
252 policy_map.Set("policy", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 285 policy_map.Set("policy", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
253 base::Value::CreateStringValue("value"), NULL); | 286 base::Value::CreateStringValue("value"), NULL); |
254 | 287 |
255 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); | 288 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
256 // The initial setup includes a policy for chrome that is now changing. | 289 // The initial setup includes a policy for chrome that is now changing. |
257 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 290 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
258 .CopyFrom(policy_map); | 291 .CopyFrom(policy_map); |
259 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension0)) | 292 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension0)) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 Mock::VerifyAndClearExpectations(&extension_observer); | 350 Mock::VerifyAndClearExpectations(&extension_observer); |
318 | 351 |
319 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, &chrome_observer); | 352 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, &chrome_observer); |
320 policy_service_->RemoveObserver(POLICY_DOMAIN_EXTENSIONS, | 353 policy_service_->RemoveObserver(POLICY_DOMAIN_EXTENSIONS, |
321 &extension_observer); | 354 &extension_observer); |
322 } | 355 } |
323 | 356 |
324 TEST_F(PolicyServiceTest, ObserverChangesPolicy) { | 357 TEST_F(PolicyServiceTest, ObserverChangesPolicy) { |
325 ChangePolicyObserver observer(&provider0_); | 358 ChangePolicyObserver observer(&provider0_); |
326 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, &observer); | 359 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, &observer); |
327 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 360 policy0_.Set("aaa", |
328 base::Value::CreateIntegerValue(123), NULL); | 361 POLICY_LEVEL_MANDATORY, |
329 policy0_.Set("bbb", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 362 POLICY_SCOPE_USER, |
330 base::Value::CreateIntegerValue(1234), NULL); | 363 new base::FundamentalValue(123), |
| 364 NULL); |
| 365 policy0_.Set("bbb", |
| 366 POLICY_LEVEL_MANDATORY, |
| 367 POLICY_SCOPE_USER, |
| 368 new base::FundamentalValue(1234), |
| 369 NULL); |
331 // Should not crash. | 370 // Should not crash. |
332 provider0_.UpdateChromePolicy(policy0_); | 371 provider0_.UpdateChromePolicy(policy0_); |
333 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, &observer); | 372 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, &observer); |
334 EXPECT_TRUE(observer.observer_invoked()); | 373 EXPECT_TRUE(observer.observer_invoked()); |
335 } | 374 } |
336 | 375 |
337 TEST_F(PolicyServiceTest, Priorities) { | 376 TEST_F(PolicyServiceTest, Priorities) { |
338 PolicyMap expected; | 377 PolicyMap expected; |
339 expected.Set("pre", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 378 expected.Set("pre", |
340 base::Value::CreateIntegerValue(13), NULL); | 379 POLICY_LEVEL_MANDATORY, |
341 expected.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 380 POLICY_SCOPE_USER, |
342 base::Value::CreateIntegerValue(0), NULL); | 381 new base::FundamentalValue(13), |
343 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 382 NULL); |
344 base::Value::CreateIntegerValue(0), NULL); | 383 expected.Set("aaa", |
345 policy1_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 384 POLICY_LEVEL_MANDATORY, |
346 base::Value::CreateIntegerValue(1), NULL); | 385 POLICY_SCOPE_USER, |
347 policy2_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 386 new base::FundamentalValue(0), |
348 base::Value::CreateIntegerValue(2), NULL); | 387 NULL); |
| 388 policy0_.Set("aaa", |
| 389 POLICY_LEVEL_MANDATORY, |
| 390 POLICY_SCOPE_USER, |
| 391 new base::FundamentalValue(0), |
| 392 NULL); |
| 393 policy1_.Set("aaa", |
| 394 POLICY_LEVEL_MANDATORY, |
| 395 POLICY_SCOPE_USER, |
| 396 new base::FundamentalValue(1), |
| 397 NULL); |
| 398 policy2_.Set("aaa", |
| 399 POLICY_LEVEL_MANDATORY, |
| 400 POLICY_SCOPE_USER, |
| 401 new base::FundamentalValue(2), |
| 402 NULL); |
349 provider0_.UpdateChromePolicy(policy0_); | 403 provider0_.UpdateChromePolicy(policy0_); |
350 provider1_.UpdateChromePolicy(policy1_); | 404 provider1_.UpdateChromePolicy(policy1_); |
351 provider2_.UpdateChromePolicy(policy2_); | 405 provider2_.UpdateChromePolicy(policy2_); |
352 EXPECT_TRUE(VerifyPolicies( | 406 EXPECT_TRUE(VerifyPolicies( |
353 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expected)); | 407 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expected)); |
354 | 408 |
355 expected.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 409 expected.Set("aaa", |
356 base::Value::CreateIntegerValue(1), NULL); | 410 POLICY_LEVEL_MANDATORY, |
| 411 POLICY_SCOPE_USER, |
| 412 new base::FundamentalValue(1), |
| 413 NULL); |
357 policy0_.Erase("aaa"); | 414 policy0_.Erase("aaa"); |
358 provider0_.UpdateChromePolicy(policy0_); | 415 provider0_.UpdateChromePolicy(policy0_); |
359 EXPECT_TRUE(VerifyPolicies( | 416 EXPECT_TRUE(VerifyPolicies( |
360 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expected)); | 417 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expected)); |
361 | 418 |
362 expected.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 419 expected.Set("aaa", |
363 base::Value::CreateIntegerValue(2), NULL); | 420 POLICY_LEVEL_MANDATORY, |
364 policy1_.Set("aaa", POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, | 421 POLICY_SCOPE_USER, |
365 base::Value::CreateIntegerValue(1), NULL); | 422 new base::FundamentalValue(2), |
| 423 NULL); |
| 424 policy1_.Set("aaa", |
| 425 POLICY_LEVEL_RECOMMENDED, |
| 426 POLICY_SCOPE_USER, |
| 427 new base::FundamentalValue(1), |
| 428 NULL); |
366 provider1_.UpdateChromePolicy(policy1_); | 429 provider1_.UpdateChromePolicy(policy1_); |
367 EXPECT_TRUE(VerifyPolicies( | 430 EXPECT_TRUE(VerifyPolicies( |
368 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expected)); | 431 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expected)); |
369 } | 432 } |
370 | 433 |
371 TEST_F(PolicyServiceTest, PolicyChangeRegistrar) { | 434 TEST_F(PolicyServiceTest, PolicyChangeRegistrar) { |
372 scoped_ptr<PolicyChangeRegistrar> registrar(new PolicyChangeRegistrar( | 435 scoped_ptr<PolicyChangeRegistrar> registrar(new PolicyChangeRegistrar( |
373 policy_service_.get(), | 436 policy_service_.get(), |
374 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))); | 437 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))); |
375 | 438 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 } | 667 } |
605 | 668 |
606 TEST_F(PolicyServiceTest, FixDeprecatedPolicies) { | 669 TEST_F(PolicyServiceTest, FixDeprecatedPolicies) { |
607 const PolicyNamespace chrome_namespace(POLICY_DOMAIN_CHROME, std::string()); | 670 const PolicyNamespace chrome_namespace(POLICY_DOMAIN_CHROME, std::string()); |
608 const PolicyNamespace extension_namespace(POLICY_DOMAIN_EXTENSIONS, "xyz"); | 671 const PolicyNamespace extension_namespace(POLICY_DOMAIN_EXTENSIONS, "xyz"); |
609 | 672 |
610 scoped_ptr<PolicyBundle> policy_bundle(new PolicyBundle()); | 673 scoped_ptr<PolicyBundle> policy_bundle(new PolicyBundle()); |
611 PolicyMap& policy_map = policy_bundle->Get(chrome_namespace); | 674 PolicyMap& policy_map = policy_bundle->Get(chrome_namespace); |
612 // Individual proxy policy values in the Chrome namespace should be collected | 675 // Individual proxy policy values in the Chrome namespace should be collected |
613 // into a dictionary. | 676 // into a dictionary. |
614 policy_map.Set(key::kProxyServerMode, POLICY_LEVEL_MANDATORY, | 677 policy_map.Set(key::kProxyServerMode, |
615 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(3), NULL); | 678 POLICY_LEVEL_MANDATORY, |
| 679 POLICY_SCOPE_USER, |
| 680 new base::FundamentalValue(3), |
| 681 NULL); |
616 | 682 |
617 // Both these policies should be ignored, since there's a higher priority | 683 // Both these policies should be ignored, since there's a higher priority |
618 // policy available. | 684 // policy available. |
619 policy_map.Set(key::kProxyMode, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, | 685 policy_map.Set(key::kProxyMode, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, |
620 base::Value::CreateStringValue("pac_script"), NULL); | 686 base::Value::CreateStringValue("pac_script"), NULL); |
621 policy_map.Set(key::kProxyPacUrl, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, | 687 policy_map.Set(key::kProxyPacUrl, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, |
622 base::Value::CreateStringValue("http://example.com/wpad.dat"), | 688 base::Value::CreateStringValue("http://example.com/wpad.dat"), |
623 NULL); | 689 NULL); |
624 | 690 |
625 // Add a value to a non-Chrome namespace. | 691 // Add a value to a non-Chrome namespace. |
626 policy_bundle->Get(extension_namespace) | 692 policy_bundle->Get(extension_namespace).Set(key::kProxyServerMode, |
627 .Set(key::kProxyServerMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 693 POLICY_LEVEL_MANDATORY, |
628 base::Value::CreateIntegerValue(3), NULL); | 694 POLICY_SCOPE_USER, |
| 695 new base::FundamentalValue(3), |
| 696 NULL); |
629 | 697 |
630 // The resulting Chrome namespace map should have the collected policy. | 698 // The resulting Chrome namespace map should have the collected policy. |
631 PolicyMap expected_chrome; | 699 PolicyMap expected_chrome; |
632 scoped_ptr<base::DictionaryValue> expected_value(new base::DictionaryValue); | 700 scoped_ptr<base::DictionaryValue> expected_value(new base::DictionaryValue); |
633 expected_value->SetInteger(key::kProxyServerMode, 3); | 701 expected_value->SetInteger(key::kProxyServerMode, 3); |
634 expected_chrome.Set(key::kProxySettings, POLICY_LEVEL_MANDATORY, | 702 expected_chrome.Set(key::kProxySettings, POLICY_LEVEL_MANDATORY, |
635 POLICY_SCOPE_USER, expected_value.release(), NULL); | 703 POLICY_SCOPE_USER, expected_value.release(), NULL); |
636 | 704 |
637 // The resulting Extensions namespace map shouldn't have been modified. | 705 // The resulting Extensions namespace map shouldn't have been modified. |
638 PolicyMap expected_extension; | 706 PolicyMap expected_extension; |
639 expected_extension.Set(key::kProxyServerMode, POLICY_LEVEL_MANDATORY, | 707 expected_extension.Set(key::kProxyServerMode, |
640 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(3), | 708 POLICY_LEVEL_MANDATORY, |
| 709 POLICY_SCOPE_USER, |
| 710 new base::FundamentalValue(3), |
641 NULL); | 711 NULL); |
642 | 712 |
643 provider0_.UpdatePolicy(policy_bundle.Pass()); | 713 provider0_.UpdatePolicy(policy_bundle.Pass()); |
644 RunUntilIdle(); | 714 RunUntilIdle(); |
645 | 715 |
646 EXPECT_TRUE(VerifyPolicies(chrome_namespace, expected_chrome)); | 716 EXPECT_TRUE(VerifyPolicies(chrome_namespace, expected_chrome)); |
647 EXPECT_TRUE(VerifyPolicies(extension_namespace, expected_extension)); | 717 EXPECT_TRUE(VerifyPolicies(extension_namespace, expected_extension)); |
648 } | 718 } |
649 | 719 |
650 } // namespace policy | 720 } // namespace policy |
OLD | NEW |