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" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "components/policy/core/common/external_data_fetcher.h" | 13 #include "components/policy/core/common/external_data_fetcher.h" |
14 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 14 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
15 #include "components/policy/core/common/mock_policy_service.h" | 15 #include "components/policy/core/common/mock_policy_service.h" |
16 #include "components/policy/core/common/policy_types.h" | |
17 #include "policy/policy_constants.h" | 16 #include "policy/policy_constants.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
20 | 19 |
21 using ::testing::AnyNumber; | 20 using ::testing::AnyNumber; |
22 using ::testing::Mock; | 21 using ::testing::Mock; |
23 using ::testing::Return; | 22 using ::testing::Return; |
24 using ::testing::_; | 23 using ::testing::_; |
25 | 24 |
26 namespace policy { | 25 namespace policy { |
(...skipping 19 matching lines...) Expand all Loading... |
46 // Helper that fills |bundle| with test policies. | 45 // Helper that fills |bundle| with test policies. |
47 void AddTestPolicies(PolicyBundle* bundle, | 46 void AddTestPolicies(PolicyBundle* bundle, |
48 const char* value, | 47 const char* value, |
49 PolicyLevel level, | 48 PolicyLevel level, |
50 PolicyScope scope) { | 49 PolicyScope scope) { |
51 PolicyMap* policy_map = | 50 PolicyMap* policy_map = |
52 &bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 51 &bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
53 policy_map->Set(kSameLevelPolicy, | 52 policy_map->Set(kSameLevelPolicy, |
54 POLICY_LEVEL_MANDATORY, | 53 POLICY_LEVEL_MANDATORY, |
55 POLICY_SCOPE_USER, | 54 POLICY_SCOPE_USER, |
56 POLICY_SOURCE_ENTERPRISE_DEFAULT, | |
57 new base::StringValue(value), | 55 new base::StringValue(value), |
58 NULL); | 56 NULL); |
59 policy_map->Set( | 57 policy_map->Set( |
60 kDiffLevelPolicy, level, scope, POLICY_SOURCE_PLATFORM, | 58 kDiffLevelPolicy, level, scope, new base::StringValue(value), NULL); |
61 new base::StringValue(value), nullptr); | |
62 policy_map = | 59 policy_map = |
63 &bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension)); | 60 &bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension)); |
64 policy_map->Set(kSameLevelPolicy, | 61 policy_map->Set(kSameLevelPolicy, |
65 POLICY_LEVEL_MANDATORY, | 62 POLICY_LEVEL_MANDATORY, |
66 POLICY_SCOPE_USER, | 63 POLICY_SCOPE_USER, |
67 POLICY_SOURCE_ENTERPRISE_DEFAULT, | |
68 new base::StringValue(value), | 64 new base::StringValue(value), |
69 NULL); | 65 NULL); |
70 policy_map->Set( | 66 policy_map->Set( |
71 kDiffLevelPolicy, level, scope, POLICY_SOURCE_PLATFORM, | 67 kDiffLevelPolicy, level, scope, new base::StringValue(value), NULL); |
72 new base::StringValue(value), nullptr); | |
73 } | 68 } |
74 | 69 |
75 // Observer class that changes the policy in the passed provider when the | 70 // Observer class that changes the policy in the passed provider when the |
76 // callback is invoked. | 71 // callback is invoked. |
77 class ChangePolicyObserver : public PolicyService::Observer { | 72 class ChangePolicyObserver : public PolicyService::Observer { |
78 public: | 73 public: |
79 explicit ChangePolicyObserver(MockConfigurationPolicyProvider* provider) | 74 explicit ChangePolicyObserver(MockConfigurationPolicyProvider* provider) |
80 : provider_(provider), | 75 : provider_(provider), |
81 observer_invoked_(false) {} | 76 observer_invoked_(false) {} |
82 | 77 |
83 void OnPolicyUpdated(const PolicyNamespace&, | 78 void OnPolicyUpdated(const PolicyNamespace&, |
84 const PolicyMap& previous, | 79 const PolicyMap& previous, |
85 const PolicyMap& current) override { | 80 const PolicyMap& current) override { |
86 PolicyMap new_policy; | 81 PolicyMap new_policy; |
87 new_policy.Set("foo", | 82 new_policy.Set("foo", |
88 POLICY_LEVEL_MANDATORY, | 83 POLICY_LEVEL_MANDATORY, |
89 POLICY_SCOPE_USER, | 84 POLICY_SCOPE_USER, |
90 POLICY_SOURCE_CLOUD, | |
91 new base::FundamentalValue(14), | 85 new base::FundamentalValue(14), |
92 NULL); | 86 NULL); |
93 provider_->UpdateChromePolicy(new_policy); | 87 provider_->UpdateChromePolicy(new_policy); |
94 observer_invoked_ = true; | 88 observer_invoked_ = true; |
95 } | 89 } |
96 | 90 |
97 bool observer_invoked() const { return observer_invoked_; } | 91 bool observer_invoked() const { return observer_invoked_; } |
98 | 92 |
99 private: | 93 private: |
100 MockConfigurationPolicyProvider* provider_; | 94 MockConfigurationPolicyProvider* provider_; |
(...skipping 13 matching lines...) Expand all Loading... |
114 EXPECT_CALL(provider2_, IsInitializationComplete(_)) | 108 EXPECT_CALL(provider2_, IsInitializationComplete(_)) |
115 .WillRepeatedly(Return(true)); | 109 .WillRepeatedly(Return(true)); |
116 | 110 |
117 provider0_.Init(); | 111 provider0_.Init(); |
118 provider1_.Init(); | 112 provider1_.Init(); |
119 provider2_.Init(); | 113 provider2_.Init(); |
120 | 114 |
121 policy0_.Set("pre", | 115 policy0_.Set("pre", |
122 POLICY_LEVEL_MANDATORY, | 116 POLICY_LEVEL_MANDATORY, |
123 POLICY_SCOPE_USER, | 117 POLICY_SCOPE_USER, |
124 POLICY_SOURCE_ENTERPRISE_DEFAULT, | |
125 new base::FundamentalValue(13), | 118 new base::FundamentalValue(13), |
126 NULL); | 119 NULL); |
127 provider0_.UpdateChromePolicy(policy0_); | 120 provider0_.UpdateChromePolicy(policy0_); |
128 | 121 |
129 PolicyServiceImpl::Providers providers; | 122 PolicyServiceImpl::Providers providers; |
130 providers.push_back(&provider0_); | 123 providers.push_back(&provider0_); |
131 providers.push_back(&provider1_); | 124 providers.push_back(&provider1_); |
132 providers.push_back(&provider2_); | 125 providers.push_back(&provider2_); |
133 policy_service_.reset(new PolicyServiceImpl(providers)); | 126 policy_service_.reset(new PolicyServiceImpl(providers)); |
134 } | 127 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 160 |
168 private: | 161 private: |
169 DISALLOW_COPY_AND_ASSIGN(PolicyServiceTest); | 162 DISALLOW_COPY_AND_ASSIGN(PolicyServiceTest); |
170 }; | 163 }; |
171 | 164 |
172 TEST_F(PolicyServiceTest, LoadsPoliciesBeforeProvidersRefresh) { | 165 TEST_F(PolicyServiceTest, LoadsPoliciesBeforeProvidersRefresh) { |
173 PolicyMap expected; | 166 PolicyMap expected; |
174 expected.Set("pre", | 167 expected.Set("pre", |
175 POLICY_LEVEL_MANDATORY, | 168 POLICY_LEVEL_MANDATORY, |
176 POLICY_SCOPE_USER, | 169 POLICY_SCOPE_USER, |
177 POLICY_SOURCE_ENTERPRISE_DEFAULT, | |
178 new base::FundamentalValue(13), | 170 new base::FundamentalValue(13), |
179 NULL); | 171 NULL); |
180 EXPECT_TRUE(VerifyPolicies( | 172 EXPECT_TRUE(VerifyPolicies( |
181 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expected)); | 173 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expected)); |
182 } | 174 } |
183 | 175 |
184 TEST_F(PolicyServiceTest, NotifyObservers) { | 176 TEST_F(PolicyServiceTest, NotifyObservers) { |
185 MockPolicyServiceObserver observer; | 177 MockPolicyServiceObserver observer; |
186 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, &observer); | 178 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, &observer); |
187 | 179 |
188 PolicyMap expectedPrevious; | 180 PolicyMap expectedPrevious; |
189 expectedPrevious.Set("pre", | 181 expectedPrevious.Set("pre", |
190 POLICY_LEVEL_MANDATORY, | 182 POLICY_LEVEL_MANDATORY, |
191 POLICY_SCOPE_USER, | 183 POLICY_SCOPE_USER, |
192 POLICY_SOURCE_ENTERPRISE_DEFAULT, | |
193 new base::FundamentalValue(13), | 184 new base::FundamentalValue(13), |
194 NULL); | 185 NULL); |
195 | 186 |
196 PolicyMap expectedCurrent; | 187 PolicyMap expectedCurrent; |
197 expectedCurrent.CopyFrom(expectedPrevious); | 188 expectedCurrent.CopyFrom(expectedPrevious); |
198 expectedCurrent.Set("aaa", | 189 expectedCurrent.Set("aaa", |
199 POLICY_LEVEL_MANDATORY, | 190 POLICY_LEVEL_MANDATORY, |
200 POLICY_SCOPE_USER, | 191 POLICY_SCOPE_USER, |
201 POLICY_SOURCE_CLOUD, | |
202 new base::FundamentalValue(123), | 192 new base::FundamentalValue(123), |
203 NULL); | 193 NULL); |
204 policy0_.Set("aaa", | 194 policy0_.Set("aaa", |
205 POLICY_LEVEL_MANDATORY, | 195 POLICY_LEVEL_MANDATORY, |
206 POLICY_SCOPE_USER, | 196 POLICY_SCOPE_USER, |
207 POLICY_SOURCE_CLOUD, | |
208 new base::FundamentalValue(123), | 197 new base::FundamentalValue(123), |
209 NULL); | 198 NULL); |
210 EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, | 199 EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, |
211 std::string()), | 200 std::string()), |
212 PolicyEquals(&expectedPrevious), | 201 PolicyEquals(&expectedPrevious), |
213 PolicyEquals(&expectedCurrent))); | 202 PolicyEquals(&expectedCurrent))); |
214 provider0_.UpdateChromePolicy(policy0_); | 203 provider0_.UpdateChromePolicy(policy0_); |
215 Mock::VerifyAndClearExpectations(&observer); | 204 Mock::VerifyAndClearExpectations(&observer); |
216 | 205 |
217 // No changes. | 206 // No changes. |
218 EXPECT_CALL(observer, OnPolicyUpdated(_, _, _)).Times(0); | 207 EXPECT_CALL(observer, OnPolicyUpdated(_, _, _)).Times(0); |
219 provider0_.UpdateChromePolicy(policy0_); | 208 provider0_.UpdateChromePolicy(policy0_); |
220 Mock::VerifyAndClearExpectations(&observer); | 209 Mock::VerifyAndClearExpectations(&observer); |
221 EXPECT_TRUE(VerifyPolicies( | 210 EXPECT_TRUE(VerifyPolicies( |
222 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expectedCurrent)); | 211 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expectedCurrent)); |
223 | 212 |
224 // New policy. | 213 // New policy. |
225 expectedPrevious.CopyFrom(expectedCurrent); | 214 expectedPrevious.CopyFrom(expectedCurrent); |
226 expectedCurrent.Set("bbb", | 215 expectedCurrent.Set("bbb", |
227 POLICY_LEVEL_MANDATORY, | 216 POLICY_LEVEL_MANDATORY, |
228 POLICY_SCOPE_USER, | 217 POLICY_SCOPE_USER, |
229 POLICY_SOURCE_CLOUD, | |
230 new base::FundamentalValue(456), | 218 new base::FundamentalValue(456), |
231 NULL); | 219 NULL); |
232 policy0_.Set("bbb", | 220 policy0_.Set("bbb", |
233 POLICY_LEVEL_MANDATORY, | 221 POLICY_LEVEL_MANDATORY, |
234 POLICY_SCOPE_USER, | 222 POLICY_SCOPE_USER, |
235 POLICY_SOURCE_CLOUD, | |
236 new base::FundamentalValue(456), | 223 new base::FundamentalValue(456), |
237 NULL); | 224 NULL); |
238 EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, | 225 EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, |
239 std::string()), | 226 std::string()), |
240 PolicyEquals(&expectedPrevious), | 227 PolicyEquals(&expectedPrevious), |
241 PolicyEquals(&expectedCurrent))); | 228 PolicyEquals(&expectedCurrent))); |
242 provider0_.UpdateChromePolicy(policy0_); | 229 provider0_.UpdateChromePolicy(policy0_); |
243 Mock::VerifyAndClearExpectations(&observer); | 230 Mock::VerifyAndClearExpectations(&observer); |
244 | 231 |
245 // Removed policy. | 232 // Removed policy. |
246 expectedPrevious.CopyFrom(expectedCurrent); | 233 expectedPrevious.CopyFrom(expectedCurrent); |
247 expectedCurrent.Erase("bbb"); | 234 expectedCurrent.Erase("bbb"); |
248 policy0_.Erase("bbb"); | 235 policy0_.Erase("bbb"); |
249 EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, | 236 EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, |
250 std::string()), | 237 std::string()), |
251 PolicyEquals(&expectedPrevious), | 238 PolicyEquals(&expectedPrevious), |
252 PolicyEquals(&expectedCurrent))); | 239 PolicyEquals(&expectedCurrent))); |
253 provider0_.UpdateChromePolicy(policy0_); | 240 provider0_.UpdateChromePolicy(policy0_); |
254 Mock::VerifyAndClearExpectations(&observer); | 241 Mock::VerifyAndClearExpectations(&observer); |
255 | 242 |
256 // Changed policy. | 243 // Changed policy. |
257 expectedPrevious.CopyFrom(expectedCurrent); | 244 expectedPrevious.CopyFrom(expectedCurrent); |
258 expectedCurrent.Set("aaa", | 245 expectedCurrent.Set("aaa", |
259 POLICY_LEVEL_MANDATORY, | 246 POLICY_LEVEL_MANDATORY, |
260 POLICY_SCOPE_USER, | 247 POLICY_SCOPE_USER, |
261 POLICY_SOURCE_CLOUD, | |
262 new base::FundamentalValue(789), | 248 new base::FundamentalValue(789), |
263 NULL); | 249 NULL); |
264 policy0_.Set("aaa", | 250 policy0_.Set("aaa", |
265 POLICY_LEVEL_MANDATORY, | 251 POLICY_LEVEL_MANDATORY, |
266 POLICY_SCOPE_USER, | 252 POLICY_SCOPE_USER, |
267 POLICY_SOURCE_CLOUD, | |
268 new base::FundamentalValue(789), | 253 new base::FundamentalValue(789), |
269 NULL); | 254 NULL); |
270 | 255 |
271 EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, | 256 EXPECT_CALL(observer, OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_CHROME, |
272 std::string()), | 257 std::string()), |
273 PolicyEquals(&expectedPrevious), | 258 PolicyEquals(&expectedPrevious), |
274 PolicyEquals(&expectedCurrent))); | 259 PolicyEquals(&expectedCurrent))); |
275 provider0_.UpdateChromePolicy(policy0_); | 260 provider0_.UpdateChromePolicy(policy0_); |
276 Mock::VerifyAndClearExpectations(&observer); | 261 Mock::VerifyAndClearExpectations(&observer); |
277 | 262 |
(...skipping 13 matching lines...) Expand all Loading... |
291 const std::string kExtension2("extension-2"); | 276 const std::string kExtension2("extension-2"); |
292 MockPolicyServiceObserver chrome_observer; | 277 MockPolicyServiceObserver chrome_observer; |
293 MockPolicyServiceObserver extension_observer; | 278 MockPolicyServiceObserver extension_observer; |
294 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, &chrome_observer); | 279 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, &chrome_observer); |
295 policy_service_->AddObserver(POLICY_DOMAIN_EXTENSIONS, &extension_observer); | 280 policy_service_->AddObserver(POLICY_DOMAIN_EXTENSIONS, &extension_observer); |
296 | 281 |
297 PolicyMap previous_policy_map; | 282 PolicyMap previous_policy_map; |
298 previous_policy_map.Set("pre", | 283 previous_policy_map.Set("pre", |
299 POLICY_LEVEL_MANDATORY, | 284 POLICY_LEVEL_MANDATORY, |
300 POLICY_SCOPE_USER, | 285 POLICY_SCOPE_USER, |
301 POLICY_SOURCE_ENTERPRISE_DEFAULT, | |
302 new base::FundamentalValue(13), | 286 new base::FundamentalValue(13), |
303 NULL); | 287 NULL); |
304 PolicyMap policy_map; | 288 PolicyMap policy_map; |
305 policy_map.CopyFrom(previous_policy_map); | 289 policy_map.CopyFrom(previous_policy_map); |
306 policy_map.Set("policy", | 290 policy_map.Set("policy", |
307 POLICY_LEVEL_MANDATORY, | 291 POLICY_LEVEL_MANDATORY, |
308 POLICY_SCOPE_USER, | 292 POLICY_SCOPE_USER, |
309 POLICY_SOURCE_CLOUD, | |
310 new base::StringValue("value"), | 293 new base::StringValue("value"), |
311 NULL); | 294 NULL); |
312 | 295 |
313 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); | 296 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
314 // The initial setup includes a policy for chrome that is now changing. | 297 // The initial setup includes a policy for chrome that is now changing. |
315 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 298 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
316 .CopyFrom(policy_map); | 299 .CopyFrom(policy_map); |
317 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension0)) | 300 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension0)) |
318 .CopyFrom(policy_map); | 301 .CopyFrom(policy_map); |
319 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension1)) | 302 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension1)) |
(...skipping 22 matching lines...) Expand all Loading... |
342 | 325 |
343 // Chrome policy stays the same, kExtension0 is gone, kExtension1 changes, | 326 // Chrome policy stays the same, kExtension0 is gone, kExtension1 changes, |
344 // and kExtension2 is new. | 327 // and kExtension2 is new. |
345 previous_policy_map.CopyFrom(policy_map); | 328 previous_policy_map.CopyFrom(policy_map); |
346 bundle.reset(new PolicyBundle()); | 329 bundle.reset(new PolicyBundle()); |
347 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 330 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
348 .CopyFrom(policy_map); | 331 .CopyFrom(policy_map); |
349 policy_map.Set("policy", | 332 policy_map.Set("policy", |
350 POLICY_LEVEL_MANDATORY, | 333 POLICY_LEVEL_MANDATORY, |
351 POLICY_SCOPE_USER, | 334 POLICY_SCOPE_USER, |
352 POLICY_SOURCE_CLOUD, | |
353 new base::StringValue("another value"), | 335 new base::StringValue("another value"), |
354 NULL); | 336 NULL); |
355 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension1)) | 337 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension1)) |
356 .CopyFrom(policy_map); | 338 .CopyFrom(policy_map); |
357 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension2)) | 339 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension2)) |
358 .CopyFrom(policy_map); | 340 .CopyFrom(policy_map); |
359 | 341 |
360 EXPECT_CALL(chrome_observer, OnPolicyUpdated(_, _, _)).Times(0); | 342 EXPECT_CALL(chrome_observer, OnPolicyUpdated(_, _, _)).Times(0); |
361 EXPECT_CALL( | 343 EXPECT_CALL( |
362 extension_observer, | 344 extension_observer, |
(...skipping 19 matching lines...) Expand all Loading... |
382 policy_service_->RemoveObserver(POLICY_DOMAIN_EXTENSIONS, | 364 policy_service_->RemoveObserver(POLICY_DOMAIN_EXTENSIONS, |
383 &extension_observer); | 365 &extension_observer); |
384 } | 366 } |
385 | 367 |
386 TEST_F(PolicyServiceTest, ObserverChangesPolicy) { | 368 TEST_F(PolicyServiceTest, ObserverChangesPolicy) { |
387 ChangePolicyObserver observer(&provider0_); | 369 ChangePolicyObserver observer(&provider0_); |
388 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, &observer); | 370 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, &observer); |
389 policy0_.Set("aaa", | 371 policy0_.Set("aaa", |
390 POLICY_LEVEL_MANDATORY, | 372 POLICY_LEVEL_MANDATORY, |
391 POLICY_SCOPE_USER, | 373 POLICY_SCOPE_USER, |
392 POLICY_SOURCE_CLOUD, | |
393 new base::FundamentalValue(123), | 374 new base::FundamentalValue(123), |
394 NULL); | 375 NULL); |
395 policy0_.Set("bbb", | 376 policy0_.Set("bbb", |
396 POLICY_LEVEL_MANDATORY, | 377 POLICY_LEVEL_MANDATORY, |
397 POLICY_SCOPE_USER, | 378 POLICY_SCOPE_USER, |
398 POLICY_SOURCE_CLOUD, | |
399 new base::FundamentalValue(1234), | 379 new base::FundamentalValue(1234), |
400 NULL); | 380 NULL); |
401 // Should not crash. | 381 // Should not crash. |
402 provider0_.UpdateChromePolicy(policy0_); | 382 provider0_.UpdateChromePolicy(policy0_); |
403 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, &observer); | 383 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, &observer); |
404 EXPECT_TRUE(observer.observer_invoked()); | 384 EXPECT_TRUE(observer.observer_invoked()); |
405 } | 385 } |
406 | 386 |
407 TEST_F(PolicyServiceTest, Priorities) { | 387 TEST_F(PolicyServiceTest, Priorities) { |
408 PolicyMap expected; | 388 PolicyMap expected; |
409 expected.Set("pre", | 389 expected.Set("pre", |
410 POLICY_LEVEL_MANDATORY, | 390 POLICY_LEVEL_MANDATORY, |
411 POLICY_SCOPE_USER, | 391 POLICY_SCOPE_USER, |
412 POLICY_SOURCE_ENTERPRISE_DEFAULT, | |
413 new base::FundamentalValue(13), | 392 new base::FundamentalValue(13), |
414 NULL); | 393 NULL); |
415 expected.Set("aaa", | 394 expected.Set("aaa", |
416 POLICY_LEVEL_MANDATORY, | 395 POLICY_LEVEL_MANDATORY, |
417 POLICY_SCOPE_USER, | 396 POLICY_SCOPE_USER, |
418 POLICY_SOURCE_CLOUD, | |
419 new base::FundamentalValue(0), | 397 new base::FundamentalValue(0), |
420 NULL); | 398 NULL); |
421 policy0_.Set("aaa", | 399 policy0_.Set("aaa", |
422 POLICY_LEVEL_MANDATORY, | 400 POLICY_LEVEL_MANDATORY, |
423 POLICY_SCOPE_USER, | 401 POLICY_SCOPE_USER, |
424 POLICY_SOURCE_CLOUD, | |
425 new base::FundamentalValue(0), | 402 new base::FundamentalValue(0), |
426 NULL); | 403 NULL); |
427 policy1_.Set("aaa", | 404 policy1_.Set("aaa", |
428 POLICY_LEVEL_MANDATORY, | 405 POLICY_LEVEL_MANDATORY, |
429 POLICY_SCOPE_USER, | 406 POLICY_SCOPE_USER, |
430 POLICY_SOURCE_CLOUD, | |
431 new base::FundamentalValue(1), | 407 new base::FundamentalValue(1), |
432 NULL); | 408 NULL); |
433 policy2_.Set("aaa", | 409 policy2_.Set("aaa", |
434 POLICY_LEVEL_MANDATORY, | 410 POLICY_LEVEL_MANDATORY, |
435 POLICY_SCOPE_USER, | 411 POLICY_SCOPE_USER, |
436 POLICY_SOURCE_CLOUD, | |
437 new base::FundamentalValue(2), | 412 new base::FundamentalValue(2), |
438 NULL); | 413 NULL); |
439 provider0_.UpdateChromePolicy(policy0_); | 414 provider0_.UpdateChromePolicy(policy0_); |
440 provider1_.UpdateChromePolicy(policy1_); | 415 provider1_.UpdateChromePolicy(policy1_); |
441 provider2_.UpdateChromePolicy(policy2_); | 416 provider2_.UpdateChromePolicy(policy2_); |
442 EXPECT_TRUE(VerifyPolicies( | 417 EXPECT_TRUE(VerifyPolicies( |
443 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expected)); | 418 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expected)); |
444 | 419 |
445 expected.Set("aaa", | 420 expected.Set("aaa", |
446 POLICY_LEVEL_MANDATORY, | 421 POLICY_LEVEL_MANDATORY, |
447 POLICY_SCOPE_USER, | 422 POLICY_SCOPE_USER, |
448 POLICY_SOURCE_CLOUD, | |
449 new base::FundamentalValue(1), | 423 new base::FundamentalValue(1), |
450 NULL); | 424 NULL); |
451 policy0_.Erase("aaa"); | 425 policy0_.Erase("aaa"); |
452 provider0_.UpdateChromePolicy(policy0_); | 426 provider0_.UpdateChromePolicy(policy0_); |
453 EXPECT_TRUE(VerifyPolicies( | 427 EXPECT_TRUE(VerifyPolicies( |
454 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expected)); | 428 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expected)); |
455 | 429 |
456 expected.Set("aaa", | 430 expected.Set("aaa", |
457 POLICY_LEVEL_MANDATORY, | 431 POLICY_LEVEL_MANDATORY, |
458 POLICY_SCOPE_USER, | 432 POLICY_SCOPE_USER, |
459 POLICY_SOURCE_CLOUD, | |
460 new base::FundamentalValue(2), | 433 new base::FundamentalValue(2), |
461 NULL); | 434 NULL); |
462 policy1_.Set("aaa", | 435 policy1_.Set("aaa", |
463 POLICY_LEVEL_RECOMMENDED, | 436 POLICY_LEVEL_RECOMMENDED, |
464 POLICY_SCOPE_USER, | 437 POLICY_SCOPE_USER, |
465 POLICY_SOURCE_CLOUD, | |
466 new base::FundamentalValue(1), | 438 new base::FundamentalValue(1), |
467 NULL); | 439 NULL); |
468 provider1_.UpdateChromePolicy(policy1_); | 440 provider1_.UpdateChromePolicy(policy1_); |
469 EXPECT_TRUE(VerifyPolicies( | 441 EXPECT_TRUE(VerifyPolicies( |
470 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expected)); | 442 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), expected)); |
471 } | 443 } |
472 | 444 |
473 TEST_F(PolicyServiceTest, PolicyChangeRegistrar) { | 445 TEST_F(PolicyServiceTest, PolicyChangeRegistrar) { |
474 scoped_ptr<PolicyChangeRegistrar> registrar(new PolicyChangeRegistrar( | 446 scoped_ptr<PolicyChangeRegistrar> registrar(new PolicyChangeRegistrar( |
475 policy_service_.get(), | 447 policy_service_.get(), |
476 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))); | 448 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))); |
477 | 449 |
478 // Starting to observe existing policies doesn't trigger a notification. | 450 // Starting to observe existing policies doesn't trigger a notification. |
479 EXPECT_CALL(*this, OnPolicyValueUpdated(_, _)).Times(0); | 451 EXPECT_CALL(*this, OnPolicyValueUpdated(_, _)).Times(0); |
480 registrar->Observe("pre", base::Bind( | 452 registrar->Observe("pre", base::Bind( |
481 &PolicyServiceTest::OnPolicyValueUpdated, | 453 &PolicyServiceTest::OnPolicyValueUpdated, |
482 base::Unretained(this))); | 454 base::Unretained(this))); |
483 registrar->Observe("aaa", base::Bind( | 455 registrar->Observe("aaa", base::Bind( |
484 &PolicyServiceTest::OnPolicyValueUpdated, | 456 &PolicyServiceTest::OnPolicyValueUpdated, |
485 base::Unretained(this))); | 457 base::Unretained(this))); |
486 RunUntilIdle(); | 458 RunUntilIdle(); |
487 Mock::VerifyAndClearExpectations(this); | 459 Mock::VerifyAndClearExpectations(this); |
488 | 460 |
489 // Changing it now triggers a notification. | 461 // Changing it now triggers a notification. |
490 base::FundamentalValue kValue0(0); | 462 base::FundamentalValue kValue0(0); |
491 EXPECT_CALL(*this, OnPolicyValueUpdated(NULL, ValueEquals(&kValue0))); | 463 EXPECT_CALL(*this, OnPolicyValueUpdated(NULL, ValueEquals(&kValue0))); |
492 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 464 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
493 POLICY_SOURCE_CLOUD, kValue0.DeepCopy(), nullptr); | 465 kValue0.DeepCopy(), NULL); |
494 provider0_.UpdateChromePolicy(policy0_); | 466 provider0_.UpdateChromePolicy(policy0_); |
495 Mock::VerifyAndClearExpectations(this); | 467 Mock::VerifyAndClearExpectations(this); |
496 | 468 |
497 // Changing other values doesn't trigger a notification. | 469 // Changing other values doesn't trigger a notification. |
498 EXPECT_CALL(*this, OnPolicyValueUpdated(_, _)).Times(0); | 470 EXPECT_CALL(*this, OnPolicyValueUpdated(_, _)).Times(0); |
499 policy0_.Set("bbb", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 471 policy0_.Set("bbb", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
500 POLICY_SOURCE_CLOUD, kValue0.DeepCopy(), nullptr); | 472 kValue0.DeepCopy(), NULL); |
501 provider0_.UpdateChromePolicy(policy0_); | 473 provider0_.UpdateChromePolicy(policy0_); |
502 Mock::VerifyAndClearExpectations(this); | 474 Mock::VerifyAndClearExpectations(this); |
503 | 475 |
504 // Modifying the value triggers a notification. | 476 // Modifying the value triggers a notification. |
505 base::FundamentalValue kValue1(1); | 477 base::FundamentalValue kValue1(1); |
506 EXPECT_CALL(*this, OnPolicyValueUpdated(ValueEquals(&kValue0), | 478 EXPECT_CALL(*this, OnPolicyValueUpdated(ValueEquals(&kValue0), |
507 ValueEquals(&kValue1))); | 479 ValueEquals(&kValue1))); |
508 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 480 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
509 POLICY_SOURCE_CLOUD, kValue1.DeepCopy(), nullptr); | 481 kValue1.DeepCopy(), NULL); |
510 provider0_.UpdateChromePolicy(policy0_); | 482 provider0_.UpdateChromePolicy(policy0_); |
511 Mock::VerifyAndClearExpectations(this); | 483 Mock::VerifyAndClearExpectations(this); |
512 | 484 |
513 // Removing the value triggers a notification. | 485 // Removing the value triggers a notification. |
514 EXPECT_CALL(*this, OnPolicyValueUpdated(ValueEquals(&kValue1), NULL)); | 486 EXPECT_CALL(*this, OnPolicyValueUpdated(ValueEquals(&kValue1), NULL)); |
515 policy0_.Erase("aaa"); | 487 policy0_.Erase("aaa"); |
516 provider0_.UpdateChromePolicy(policy0_); | 488 provider0_.UpdateChromePolicy(policy0_); |
517 Mock::VerifyAndClearExpectations(this); | 489 Mock::VerifyAndClearExpectations(this); |
518 | 490 |
519 // No more notifications after destroying the registrar. | 491 // No more notifications after destroying the registrar. |
520 EXPECT_CALL(*this, OnPolicyValueUpdated(_, _)).Times(0); | 492 EXPECT_CALL(*this, OnPolicyValueUpdated(_, _)).Times(0); |
521 registrar.reset(); | 493 registrar.reset(); |
522 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 494 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
523 POLICY_SOURCE_CLOUD, kValue1.DeepCopy(), nullptr); | 495 kValue1.DeepCopy(), NULL); |
524 policy0_.Set("pre", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 496 policy0_.Set("pre", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
525 POLICY_SOURCE_ENTERPRISE_DEFAULT, kValue1.DeepCopy(), nullptr); | 497 kValue1.DeepCopy(), NULL); |
526 provider0_.UpdateChromePolicy(policy0_); | 498 provider0_.UpdateChromePolicy(policy0_); |
527 Mock::VerifyAndClearExpectations(this); | 499 Mock::VerifyAndClearExpectations(this); |
528 } | 500 } |
529 | 501 |
530 TEST_F(PolicyServiceTest, RefreshPolicies) { | 502 TEST_F(PolicyServiceTest, RefreshPolicies) { |
531 EXPECT_CALL(provider0_, RefreshPolicies()).Times(AnyNumber()); | 503 EXPECT_CALL(provider0_, RefreshPolicies()).Times(AnyNumber()); |
532 EXPECT_CALL(provider1_, RefreshPolicies()).Times(AnyNumber()); | 504 EXPECT_CALL(provider1_, RefreshPolicies()).Times(AnyNumber()); |
533 EXPECT_CALL(provider2_, RefreshPolicies()).Times(AnyNumber()); | 505 EXPECT_CALL(provider2_, RefreshPolicies()).Times(AnyNumber()); |
534 | 506 |
535 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); | 507 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); |
536 policy_service_->RefreshPolicies(base::Bind( | 508 policy_service_->RefreshPolicies(base::Bind( |
537 &PolicyServiceTest::OnPolicyRefresh, | 509 &PolicyServiceTest::OnPolicyRefresh, |
538 base::Unretained(this))); | 510 base::Unretained(this))); |
539 // Let any queued observer tasks run. | 511 // Let any queued observer tasks run. |
540 RunUntilIdle(); | 512 RunUntilIdle(); |
541 Mock::VerifyAndClearExpectations(this); | 513 Mock::VerifyAndClearExpectations(this); |
542 | 514 |
543 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); | 515 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); |
544 base::FundamentalValue kValue0(0); | 516 base::FundamentalValue kValue0(0); |
545 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 517 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
546 POLICY_SOURCE_CLOUD, kValue0.DeepCopy(), nullptr); | 518 kValue0.DeepCopy(), NULL); |
547 provider0_.UpdateChromePolicy(policy0_); | 519 provider0_.UpdateChromePolicy(policy0_); |
548 Mock::VerifyAndClearExpectations(this); | 520 Mock::VerifyAndClearExpectations(this); |
549 | 521 |
550 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); | 522 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); |
551 base::FundamentalValue kValue1(1); | 523 base::FundamentalValue kValue1(1); |
552 policy1_.Set("aaa", POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, | 524 policy1_.Set("aaa", POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, |
553 POLICY_SOURCE_CLOUD, kValue1.DeepCopy(), nullptr); | 525 kValue1.DeepCopy(), NULL); |
554 provider1_.UpdateChromePolicy(policy1_); | 526 provider1_.UpdateChromePolicy(policy1_); |
555 Mock::VerifyAndClearExpectations(this); | 527 Mock::VerifyAndClearExpectations(this); |
556 | 528 |
557 // A provider can refresh more than once after a RefreshPolicies call, but | 529 // A provider can refresh more than once after a RefreshPolicies call, but |
558 // OnPolicyRefresh should be triggered only after all providers are | 530 // OnPolicyRefresh should be triggered only after all providers are |
559 // refreshed. | 531 // refreshed. |
560 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); | 532 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); |
561 policy1_.Set("bbb", POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, | 533 policy1_.Set("bbb", POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, |
562 POLICY_SOURCE_CLOUD, kValue1.DeepCopy(), nullptr); | 534 kValue1.DeepCopy(), NULL); |
563 provider1_.UpdateChromePolicy(policy1_); | 535 provider1_.UpdateChromePolicy(policy1_); |
564 Mock::VerifyAndClearExpectations(this); | 536 Mock::VerifyAndClearExpectations(this); |
565 | 537 |
566 // If another RefreshPolicies() call happens while waiting for a previous | 538 // If another RefreshPolicies() call happens while waiting for a previous |
567 // one to complete, then all providers must refresh again. | 539 // one to complete, then all providers must refresh again. |
568 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); | 540 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); |
569 policy_service_->RefreshPolicies(base::Bind( | 541 policy_service_->RefreshPolicies(base::Bind( |
570 &PolicyServiceTest::OnPolicyRefresh, | 542 &PolicyServiceTest::OnPolicyRefresh, |
571 base::Unretained(this))); | 543 base::Unretained(this))); |
572 RunUntilIdle(); | 544 RunUntilIdle(); |
573 Mock::VerifyAndClearExpectations(this); | 545 Mock::VerifyAndClearExpectations(this); |
574 | 546 |
575 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); | 547 EXPECT_CALL(*this, OnPolicyRefresh()).Times(0); |
576 policy2_.Set("bbb", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 548 policy2_.Set("bbb", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
577 POLICY_SOURCE_CLOUD, kValue0.DeepCopy(), nullptr); | 549 kValue0.DeepCopy(), NULL); |
578 provider2_.UpdateChromePolicy(policy2_); | 550 provider2_.UpdateChromePolicy(policy2_); |
579 Mock::VerifyAndClearExpectations(this); | 551 Mock::VerifyAndClearExpectations(this); |
580 | 552 |
581 // Providers 0 and 1 must reload again. | 553 // Providers 0 and 1 must reload again. |
582 EXPECT_CALL(*this, OnPolicyRefresh()).Times(2); | 554 EXPECT_CALL(*this, OnPolicyRefresh()).Times(2); |
583 base::FundamentalValue kValue2(2); | 555 base::FundamentalValue kValue2(2); |
584 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 556 policy0_.Set("aaa", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
585 POLICY_SOURCE_CLOUD, kValue2.DeepCopy(), nullptr); | 557 kValue2.DeepCopy(), NULL); |
586 provider0_.UpdateChromePolicy(policy0_); | 558 provider0_.UpdateChromePolicy(policy0_); |
587 provider1_.UpdateChromePolicy(policy1_); | 559 provider1_.UpdateChromePolicy(policy1_); |
588 Mock::VerifyAndClearExpectations(this); | 560 Mock::VerifyAndClearExpectations(this); |
589 | 561 |
590 const PolicyMap& policies = policy_service_->GetPolicies( | 562 const PolicyMap& policies = policy_service_->GetPolicies( |
591 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 563 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
592 EXPECT_TRUE(base::Value::Equals(&kValue2, policies.GetValue("aaa"))); | 564 EXPECT_TRUE(base::Value::Equals(&kValue2, policies.GetValue("aaa"))); |
593 EXPECT_TRUE(base::Value::Equals(&kValue0, policies.GetValue("bbb"))); | 565 EXPECT_TRUE(base::Value::Equals(&kValue0, policies.GetValue("bbb"))); |
594 } | 566 } |
595 | 567 |
(...skipping 13 matching lines...) Expand all Loading... |
609 provider1_.UpdatePolicy(bundle1.Pass()); | 581 provider1_.UpdatePolicy(bundle1.Pass()); |
610 provider2_.UpdatePolicy(bundle2.Pass()); | 582 provider2_.UpdatePolicy(bundle2.Pass()); |
611 RunUntilIdle(); | 583 RunUntilIdle(); |
612 | 584 |
613 PolicyMap expected; | 585 PolicyMap expected; |
614 // For policies of the same level and scope, the first provider takes | 586 // For policies of the same level and scope, the first provider takes |
615 // precedence, on every namespace. | 587 // precedence, on every namespace. |
616 expected.Set(kSameLevelPolicy, | 588 expected.Set(kSameLevelPolicy, |
617 POLICY_LEVEL_MANDATORY, | 589 POLICY_LEVEL_MANDATORY, |
618 POLICY_SCOPE_USER, | 590 POLICY_SCOPE_USER, |
619 POLICY_SOURCE_ENTERPRISE_DEFAULT, | |
620 new base::StringValue("bundle0"), | 591 new base::StringValue("bundle0"), |
621 NULL); | 592 NULL); |
622 // For policies with different levels and scopes, the highest priority | 593 // For policies with different levels and scopes, the highest priority |
623 // level/scope combination takes precedence, on every namespace. | 594 // level/scope combination takes precedence, on every namespace. |
624 expected.Set(kDiffLevelPolicy, | 595 expected.Set(kDiffLevelPolicy, |
625 POLICY_LEVEL_MANDATORY, | 596 POLICY_LEVEL_MANDATORY, |
626 POLICY_SCOPE_MACHINE, | 597 POLICY_SCOPE_MACHINE, |
627 POLICY_SOURCE_PLATFORM, | |
628 new base::StringValue("bundle2"), | 598 new base::StringValue("bundle2"), |
629 NULL); | 599 NULL); |
630 EXPECT_TRUE(policy_service_->GetPolicies( | 600 EXPECT_TRUE(policy_service_->GetPolicies( |
631 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())).Equals(expected)); | 601 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())).Equals(expected)); |
632 EXPECT_TRUE(policy_service_->GetPolicies( | 602 EXPECT_TRUE(policy_service_->GetPolicies( |
633 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension)).Equals(expected)); | 603 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension)).Equals(expected)); |
634 } | 604 } |
635 | 605 |
636 TEST_F(PolicyServiceTest, IsInitializationComplete) { | 606 TEST_F(PolicyServiceTest, IsInitializationComplete) { |
637 // |provider0| has all domains initialized. | 607 // |provider0| has all domains initialized. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 const PolicyNamespace chrome_namespace(POLICY_DOMAIN_CHROME, std::string()); | 687 const PolicyNamespace chrome_namespace(POLICY_DOMAIN_CHROME, std::string()); |
718 const PolicyNamespace extension_namespace(POLICY_DOMAIN_EXTENSIONS, "xyz"); | 688 const PolicyNamespace extension_namespace(POLICY_DOMAIN_EXTENSIONS, "xyz"); |
719 | 689 |
720 scoped_ptr<PolicyBundle> policy_bundle(new PolicyBundle()); | 690 scoped_ptr<PolicyBundle> policy_bundle(new PolicyBundle()); |
721 PolicyMap& policy_map = policy_bundle->Get(chrome_namespace); | 691 PolicyMap& policy_map = policy_bundle->Get(chrome_namespace); |
722 // Individual proxy policy values in the Chrome namespace should be collected | 692 // Individual proxy policy values in the Chrome namespace should be collected |
723 // into a dictionary. | 693 // into a dictionary. |
724 policy_map.Set(key::kProxyServerMode, | 694 policy_map.Set(key::kProxyServerMode, |
725 POLICY_LEVEL_MANDATORY, | 695 POLICY_LEVEL_MANDATORY, |
726 POLICY_SCOPE_USER, | 696 POLICY_SCOPE_USER, |
727 POLICY_SOURCE_CLOUD, | |
728 new base::FundamentalValue(3), | 697 new base::FundamentalValue(3), |
729 NULL); | 698 NULL); |
730 | 699 |
731 // Both these policies should be ignored, since there's a higher priority | 700 // Both these policies should be ignored, since there's a higher priority |
732 // policy available. | 701 // policy available. |
733 policy_map.Set(key::kProxyMode, | 702 policy_map.Set(key::kProxyMode, |
734 POLICY_LEVEL_RECOMMENDED, | 703 POLICY_LEVEL_RECOMMENDED, |
735 POLICY_SCOPE_USER, | 704 POLICY_SCOPE_USER, |
736 POLICY_SOURCE_CLOUD, | |
737 new base::StringValue("pac_script"), | 705 new base::StringValue("pac_script"), |
738 NULL); | 706 NULL); |
739 policy_map.Set(key::kProxyPacUrl, | 707 policy_map.Set(key::kProxyPacUrl, |
740 POLICY_LEVEL_RECOMMENDED, | 708 POLICY_LEVEL_RECOMMENDED, |
741 POLICY_SCOPE_USER, | 709 POLICY_SCOPE_USER, |
742 POLICY_SOURCE_CLOUD, | |
743 new base::StringValue("http://example.com/wpad.dat"), | 710 new base::StringValue("http://example.com/wpad.dat"), |
744 NULL); | 711 NULL); |
745 | 712 |
746 // Add a value to a non-Chrome namespace. | 713 // Add a value to a non-Chrome namespace. |
747 policy_bundle->Get(extension_namespace).Set(key::kProxyServerMode, | 714 policy_bundle->Get(extension_namespace).Set(key::kProxyServerMode, |
748 POLICY_LEVEL_MANDATORY, | 715 POLICY_LEVEL_MANDATORY, |
749 POLICY_SCOPE_USER, | 716 POLICY_SCOPE_USER, |
750 POLICY_SOURCE_CLOUD, | |
751 new base::FundamentalValue(3), | 717 new base::FundamentalValue(3), |
752 NULL); | 718 NULL); |
753 | 719 |
754 // The resulting Chrome namespace map should have the collected policy. | 720 // The resulting Chrome namespace map should have the collected policy. |
755 PolicyMap expected_chrome; | 721 PolicyMap expected_chrome; |
756 scoped_ptr<base::DictionaryValue> expected_value(new base::DictionaryValue); | 722 scoped_ptr<base::DictionaryValue> expected_value(new base::DictionaryValue); |
757 expected_value->SetInteger(key::kProxyServerMode, 3); | 723 expected_value->SetInteger(key::kProxyServerMode, 3); |
758 expected_chrome.Set(key::kProxySettings, POLICY_LEVEL_MANDATORY, | 724 expected_chrome.Set(key::kProxySettings, POLICY_LEVEL_MANDATORY, |
759 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 725 POLICY_SCOPE_USER, expected_value.release(), NULL); |
760 expected_value.release(), nullptr); | |
761 | 726 |
762 // The resulting Extensions namespace map shouldn't have been modified. | 727 // The resulting Extensions namespace map shouldn't have been modified. |
763 PolicyMap expected_extension; | 728 PolicyMap expected_extension; |
764 expected_extension.Set(key::kProxyServerMode, | 729 expected_extension.Set(key::kProxyServerMode, |
765 POLICY_LEVEL_MANDATORY, | 730 POLICY_LEVEL_MANDATORY, |
766 POLICY_SCOPE_USER, | 731 POLICY_SCOPE_USER, |
767 POLICY_SOURCE_CLOUD, | |
768 new base::FundamentalValue(3), | 732 new base::FundamentalValue(3), |
769 NULL); | 733 NULL); |
770 | 734 |
771 provider0_.UpdatePolicy(policy_bundle.Pass()); | 735 provider0_.UpdatePolicy(policy_bundle.Pass()); |
772 RunUntilIdle(); | 736 RunUntilIdle(); |
773 | 737 |
774 EXPECT_TRUE(VerifyPolicies(chrome_namespace, expected_chrome)); | 738 EXPECT_TRUE(VerifyPolicies(chrome_namespace, expected_chrome)); |
775 EXPECT_TRUE(VerifyPolicies(extension_namespace, expected_extension)); | 739 EXPECT_TRUE(VerifyPolicies(extension_namespace, expected_extension)); |
776 } | 740 } |
777 | 741 |
778 } // namespace policy | 742 } // namespace policy |
OLD | NEW |