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 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 122 |
123 builder_.policy_data().set_policy_type( | 123 builder_.policy_data().set_policy_type( |
124 dm_protocol::kChromeExtensionPolicyType); | 124 dm_protocol::kChromeExtensionPolicyType); |
125 builder_.policy_data().set_settings_entity_id(kTestExtension); | 125 builder_.policy_data().set_settings_entity_id(kTestExtension); |
126 builder_.payload().set_download_url(kTestDownload); | 126 builder_.payload().set_download_url(kTestDownload); |
127 builder_.payload().set_secure_hash(crypto::SHA256HashString(kTestPolicy)); | 127 builder_.payload().set_secure_hash(crypto::SHA256HashString(kTestPolicy)); |
128 | 128 |
129 expected_policy_.Set("Name", | 129 expected_policy_.Set("Name", |
130 POLICY_LEVEL_MANDATORY, | 130 POLICY_LEVEL_MANDATORY, |
131 POLICY_SCOPE_USER, | 131 POLICY_SCOPE_USER, |
132 POLICY_SOURCE_CLOUD, | |
133 new base::StringValue("disabled"), | 132 new base::StringValue("disabled"), |
134 nullptr); | 133 nullptr); |
135 expected_policy_.Set("Second", | 134 expected_policy_.Set("Second", |
136 POLICY_LEVEL_RECOMMENDED, | 135 POLICY_LEVEL_RECOMMENDED, |
137 POLICY_SCOPE_USER, | 136 POLICY_SCOPE_USER, |
138 POLICY_SOURCE_CLOUD, | |
139 new base::StringValue("maybe"), | 137 new base::StringValue("maybe"), |
140 nullptr); | 138 nullptr); |
141 } | 139 } |
142 | 140 |
143 void TearDown() override { | 141 void TearDown() override { |
144 // The service cleans up its backend on the background thread. | 142 // The service cleans up its backend on the background thread. |
145 service_.reset(); | 143 service_.reset(); |
146 RunUntilIdle(); | 144 RunUntilIdle(); |
147 } | 145 } |
148 | 146 |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 // The initial, cached policy will be served once the backend is initialized. | 507 // The initial, cached policy will be served once the backend is initialized. |
510 EXPECT_CALL(delegate_, OnComponentCloudPolicyUpdated()); | 508 EXPECT_CALL(delegate_, OnComponentCloudPolicyUpdated()); |
511 Connect(); | 509 Connect(); |
512 Mock::VerifyAndClearExpectations(&delegate_); | 510 Mock::VerifyAndClearExpectations(&delegate_); |
513 | 511 |
514 PolicyBundle expected_bundle; | 512 PolicyBundle expected_bundle; |
515 const PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension); | 513 const PolicyNamespace ns(POLICY_DOMAIN_EXTENSIONS, kTestExtension); |
516 expected_bundle.Get(ns).Set("Name", | 514 expected_bundle.Get(ns).Set("Name", |
517 POLICY_LEVEL_MANDATORY, | 515 POLICY_LEVEL_MANDATORY, |
518 POLICY_SCOPE_USER, | 516 POLICY_SCOPE_USER, |
519 POLICY_SOURCE_CLOUD, | |
520 new base::StringValue("published"), | 517 new base::StringValue("published"), |
521 nullptr); | 518 nullptr); |
522 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); | 519 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); |
523 } | 520 } |
524 | 521 |
525 TEST_F(ComponentCloudPolicyServiceTest, PurgeWhenServerRemovesPolicy) { | 522 TEST_F(ComponentCloudPolicyServiceTest, PurgeWhenServerRemovesPolicy) { |
526 // Initialize with cached policy. | 523 // Initialize with cached policy. |
527 PopulateCache(); | 524 PopulateCache(); |
528 Connect(); | 525 Connect(); |
529 | 526 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 EXPECT_TRUE(ContainsKey(contents, kTestExtension)); | 572 EXPECT_TRUE(ContainsKey(contents, kTestExtension)); |
576 EXPECT_FALSE(ContainsKey(contents, kTestExtension2)); | 573 EXPECT_FALSE(ContainsKey(contents, kTestExtension2)); |
577 | 574 |
578 // And the service isn't publishing policy for the second extension anymore. | 575 // And the service isn't publishing policy for the second extension anymore. |
579 expected_bundle.Clear(); | 576 expected_bundle.Clear(); |
580 expected_bundle.Get(ns).CopyFrom(expected_policy_); | 577 expected_bundle.Get(ns).CopyFrom(expected_policy_); |
581 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); | 578 EXPECT_TRUE(service_->policy().Equals(expected_bundle)); |
582 } | 579 } |
583 | 580 |
584 } // namespace policy | 581 } // namespace policy |
OLD | NEW |