OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/cloud/component_cloud_policy_service.h" | 5 #include "components/policy/core/common/cloud/component_cloud_policy_service.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 owned_cache_.reset( | 121 owned_cache_.reset( |
122 new ResourceCache(temp_dir_.path(), loop_.task_runner())); | 122 new ResourceCache(temp_dir_.path(), loop_.task_runner())); |
123 cache_ = owned_cache_.get(); | 123 cache_ = owned_cache_.get(); |
124 | 124 |
125 builder_.policy_data().set_policy_type( | 125 builder_.policy_data().set_policy_type( |
126 dm_protocol::kChromeExtensionPolicyType); | 126 dm_protocol::kChromeExtensionPolicyType); |
127 builder_.policy_data().set_settings_entity_id(kTestExtension); | 127 builder_.policy_data().set_settings_entity_id(kTestExtension); |
128 builder_.payload().set_download_url(kTestDownload); | 128 builder_.payload().set_download_url(kTestDownload); |
129 builder_.payload().set_secure_hash(crypto::SHA256HashString(kTestPolicy)); | 129 builder_.payload().set_secure_hash(crypto::SHA256HashString(kTestPolicy)); |
130 | 130 |
131 expected_policy_.Set("Name", | 131 expected_policy_.Set( |
132 POLICY_LEVEL_MANDATORY, | 132 "Name", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
133 POLICY_SCOPE_USER, | 133 base::WrapUnique(new base::StringValue("disabled")), nullptr); |
| 134 expected_policy_.Set("Second", POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, |
134 POLICY_SOURCE_CLOUD, | 135 POLICY_SOURCE_CLOUD, |
135 new base::StringValue("disabled"), | 136 base::WrapUnique(new base::StringValue("maybe")), |
136 nullptr); | |
137 expected_policy_.Set("Second", | |
138 POLICY_LEVEL_RECOMMENDED, | |
139 POLICY_SCOPE_USER, | |
140 POLICY_SOURCE_CLOUD, | |
141 new base::StringValue("maybe"), | |
142 nullptr); | 137 nullptr); |
143 } | 138 } |
144 | 139 |
145 void TearDown() override { | 140 void TearDown() override { |
146 // The service cleans up its backend on the background thread. | 141 // The service cleans up its backend on the background thread. |
147 service_.reset(); | 142 service_.reset(); |
148 RunUntilIdle(); | 143 RunUntilIdle(); |
149 } | 144 } |
150 | 145 |
151 void RunUntilIdle() { | 146 void RunUntilIdle() { |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 LoadStore(); | 503 LoadStore(); |
509 InitializeRegistry(); | 504 InitializeRegistry(); |
510 | 505 |
511 // The initial, cached policy will be served once the backend is initialized. | 506 // The initial, cached policy will be served once the backend is initialized. |
512 EXPECT_CALL(delegate_, OnComponentCloudPolicyUpdated()); | 507 EXPECT_CALL(delegate_, OnComponentCloudPolicyUpdated()); |
513 Connect(); | 508 Connect(); |
514 Mock::VerifyAndClearExpectations(&delegate_); | 509 Mock::VerifyAndClearExpectations(&delegate_); |
515 | 510 |
516 PolicyBundle expected_bundle; | 511 PolicyBundle expected_bundle; |
517 const PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension); | 512 const PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension); |
518 expected_bundle.Get(ns).Set("Name", | 513 expected_bundle.Get(ns).Set( |
519 POLICY_LEVEL_MANDATORY, | 514 "Name", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
520 POLICY_SCOPE_USER, | 515 base::WrapUnique(new base::StringValue("published")), nullptr); |
521 POLICY_SOURCE_CLOUD, | |
522 new base::StringValue("published"), | |
523 nullptr); | |
524 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); | 516 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); |
525 } | 517 } |
526 | 518 |
527 TEST_F(ComponentCloudPolicyServiceTest, PurgeWhenServerRemovesPolicy) { | 519 TEST_F(ComponentCloudPolicyServiceTest, PurgeWhenServerRemovesPolicy) { |
528 // Initialize with cached policy. | 520 // Initialize with cached policy. |
529 PopulateCache(); | 521 PopulateCache(); |
530 Connect(); | 522 Connect(); |
531 | 523 |
532 EXPECT_CALL(delegate_, OnComponentCloudPolicyUpdated()); | 524 EXPECT_CALL(delegate_, OnComponentCloudPolicyUpdated()); |
533 EXPECT_CALL(*client_, FetchPolicy()).Times(0); | 525 EXPECT_CALL(*client_, FetchPolicy()).Times(0); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 EXPECT_TRUE(ContainsKey(contents, kTestExtension)); | 569 EXPECT_TRUE(ContainsKey(contents, kTestExtension)); |
578 EXPECT_FALSE(ContainsKey(contents, kTestExtension2)); | 570 EXPECT_FALSE(ContainsKey(contents, kTestExtension2)); |
579 | 571 |
580 // And the service isn't publishing policy for the second extension anymore. | 572 // And the service isn't publishing policy for the second extension anymore. |
581 expected_bundle.Clear(); | 573 expected_bundle.Clear(); |
582 expected_bundle.Get(ns).CopyFrom(expected_policy_); | 574 expected_bundle.Get(ns).CopyFrom(expected_policy_); |
583 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); | 575 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); |
584 } | 576 } |
585 | 577 |
586 } // namespace policy | 578 } // namespace policy |
OLD | NEW |