| 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/cloud/cloud_policy_manager.h" | 5 #include "components/policy/core/common/cloud/cloud_policy_manager.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 11 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 12 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h" | 12 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h" |
| 13 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" | 13 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" |
| 14 #include "components/policy/core/common/cloud/policy_builder.h" | 14 #include "components/policy/core/common/cloud/policy_builder.h" |
| 15 #include "components/policy/core/common/configuration_policy_provider_test.h" | 15 #include "components/policy/core/common/configuration_policy_provider_test.h" |
| 16 #include "components/policy/core/common/external_data_fetcher.h" | 16 #include "components/policy/core/common/external_data_fetcher.h" |
| 17 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 17 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 18 #include "components/policy/core/common/policy_types.h" |
| 18 #include "components/policy/core/common/schema_registry.h" | 19 #include "components/policy/core/common/schema_registry.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 using testing::Mock; | 23 using testing::Mock; |
| 23 using testing::_; | 24 using testing::_; |
| 24 | 25 |
| 25 namespace em = enterprise_management; | 26 namespace em = enterprise_management; |
| 26 | 27 |
| 27 namespace policy { | 28 namespace policy { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 55 static PolicyProviderTestHarness* CreateMandatory(); | 56 static PolicyProviderTestHarness* CreateMandatory(); |
| 56 static PolicyProviderTestHarness* CreateRecommended(); | 57 static PolicyProviderTestHarness* CreateRecommended(); |
| 57 | 58 |
| 58 private: | 59 private: |
| 59 MockCloudPolicyStore store_; | 60 MockCloudPolicyStore store_; |
| 60 | 61 |
| 61 DISALLOW_COPY_AND_ASSIGN(TestHarness); | 62 DISALLOW_COPY_AND_ASSIGN(TestHarness); |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 TestHarness::TestHarness(PolicyLevel level) | 65 TestHarness::TestHarness(PolicyLevel level) |
| 65 : PolicyProviderTestHarness(level, POLICY_SCOPE_USER) {} | 66 : PolicyProviderTestHarness(level, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD) { |
| 67 } |
| 66 | 68 |
| 67 TestHarness::~TestHarness() {} | 69 TestHarness::~TestHarness() {} |
| 68 | 70 |
| 69 void TestHarness::SetUp() {} | 71 void TestHarness::SetUp() {} |
| 70 | 72 |
| 71 ConfigurationPolicyProvider* TestHarness::CreateProvider( | 73 ConfigurationPolicyProvider* TestHarness::CreateProvider( |
| 72 SchemaRegistry* registry, | 74 SchemaRegistry* registry, |
| 73 scoped_refptr<base::SequencedTaskRunner> task_runner) { | 75 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
| 74 // Create and initialize the store. | 76 // Create and initialize the store. |
| 75 store_.NotifyStoreLoaded(); | 77 store_.NotifyStoreLoaded(); |
| 76 ConfigurationPolicyProvider* provider = | 78 ConfigurationPolicyProvider* provider = |
| 77 new CloudPolicyManager(dm_protocol::kChromeUserPolicyType, std::string(), | 79 new CloudPolicyManager(dm_protocol::kChromeUserPolicyType, std::string(), |
| 78 &store_, task_runner, task_runner, task_runner); | 80 &store_, task_runner, task_runner, task_runner); |
| 79 Mock::VerifyAndClearExpectations(&store_); | 81 Mock::VerifyAndClearExpectations(&store_); |
| 80 return provider; | 82 return provider; |
| 81 } | 83 } |
| 82 | 84 |
| 83 void TestHarness::InstallEmptyPolicy() {} | 85 void TestHarness::InstallEmptyPolicy() {} |
| 84 | 86 |
| 85 void TestHarness::InstallStringPolicy(const std::string& policy_name, | 87 void TestHarness::InstallStringPolicy(const std::string& policy_name, |
| 86 const std::string& policy_value) { | 88 const std::string& policy_value) { |
| 87 store_.policy_map_.Set(policy_name, | 89 store_.policy_map_.Set(policy_name, |
| 88 policy_level(), | 90 policy_level(), |
| 89 policy_scope(), | 91 policy_scope(), |
| 92 POLICY_SOURCE_CLOUD, |
| 90 new base::StringValue(policy_value), | 93 new base::StringValue(policy_value), |
| 91 nullptr); | 94 nullptr); |
| 92 } | 95 } |
| 93 | 96 |
| 94 void TestHarness::InstallIntegerPolicy(const std::string& policy_name, | 97 void TestHarness::InstallIntegerPolicy(const std::string& policy_name, |
| 95 int policy_value) { | 98 int policy_value) { |
| 96 store_.policy_map_.Set(policy_name, | 99 store_.policy_map_.Set(policy_name, |
| 97 policy_level(), | 100 policy_level(), |
| 98 policy_scope(), | 101 policy_scope(), |
| 99 new base::FundamentalValue(policy_value), | 102 POLICY_SOURCE_CLOUD, |
| 103 new base:: |
| 104 FundamentalValue(policy_value), |
| 100 nullptr); | 105 nullptr); |
| 101 } | 106 } |
| 102 | 107 |
| 103 void TestHarness::InstallBooleanPolicy(const std::string& policy_name, | 108 void TestHarness::InstallBooleanPolicy(const std::string& policy_name, |
| 104 bool policy_value) { | 109 bool policy_value) { |
| 105 store_.policy_map_.Set(policy_name, | 110 store_.policy_map_.Set(policy_name, |
| 106 policy_level(), | 111 policy_level(), |
| 107 policy_scope(), | 112 policy_scope(), |
| 108 new base::FundamentalValue(policy_value), | 113 POLICY_SOURCE_CLOUD, |
| 114 new base:: |
| 115 FundamentalValue(policy_value), |
| 109 nullptr); | 116 nullptr); |
| 110 } | 117 } |
| 111 | 118 |
| 112 void TestHarness::InstallStringListPolicy(const std::string& policy_name, | 119 void TestHarness::InstallStringListPolicy(const std::string& policy_name, |
| 113 const base::ListValue* policy_value) { | 120 const base::ListValue* policy_value) { |
| 114 store_.policy_map_.Set(policy_name, policy_level(), policy_scope(), | 121 store_.policy_map_.Set(policy_name, |
| 115 policy_value->DeepCopy(), nullptr); | 122 policy_level(), |
| 123 policy_scope(), |
| 124 POLICY_SOURCE_CLOUD, |
| 125 policy_value->DeepCopy(), |
| 126 nullptr); |
| 116 } | 127 } |
| 117 | 128 |
| 118 void TestHarness::InstallDictionaryPolicy( | 129 void TestHarness::InstallDictionaryPolicy( |
| 119 const std::string& policy_name, | 130 const std::string& policy_name, |
| 120 const base::DictionaryValue* policy_value) { | 131 const base::DictionaryValue* policy_value) { |
| 121 store_.policy_map_.Set(policy_name, policy_level(), policy_scope(), | 132 store_.policy_map_.Set(policy_name, |
| 122 policy_value->DeepCopy(), nullptr); | 133 policy_level(), |
| 134 policy_scope(), |
| 135 POLICY_SOURCE_CLOUD, |
| 136 policy_value->DeepCopy(), |
| 137 nullptr); |
| 123 } | 138 } |
| 124 | 139 |
| 125 // static | 140 // static |
| 126 PolicyProviderTestHarness* TestHarness::CreateMandatory() { | 141 PolicyProviderTestHarness* TestHarness::CreateMandatory() { |
| 127 return new TestHarness(POLICY_LEVEL_MANDATORY); | 142 return new TestHarness(POLICY_LEVEL_MANDATORY); |
| 128 } | 143 } |
| 129 | 144 |
| 130 // static | 145 // static |
| 131 PolicyProviderTestHarness* TestHarness::CreateRecommended() { | 146 PolicyProviderTestHarness* TestHarness::CreateRecommended() { |
| 132 return new TestHarness(POLICY_LEVEL_RECOMMENDED); | 147 return new TestHarness(POLICY_LEVEL_RECOMMENDED); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 class CloudPolicyManagerTest : public testing::Test { | 184 class CloudPolicyManagerTest : public testing::Test { |
| 170 protected: | 185 protected: |
| 171 CloudPolicyManagerTest() | 186 CloudPolicyManagerTest() |
| 172 : policy_type_(dm_protocol::kChromeUserPolicyType) {} | 187 : policy_type_(dm_protocol::kChromeUserPolicyType) {} |
| 173 | 188 |
| 174 void SetUp() override { | 189 void SetUp() override { |
| 175 // Set up a policy map for testing. | 190 // Set up a policy map for testing. |
| 176 policy_map_.Set("key", | 191 policy_map_.Set("key", |
| 177 POLICY_LEVEL_MANDATORY, | 192 POLICY_LEVEL_MANDATORY, |
| 178 POLICY_SCOPE_USER, | 193 POLICY_SCOPE_USER, |
| 194 POLICY_SOURCE_CLOUD, |
| 179 new base::StringValue("value"), | 195 new base::StringValue("value"), |
| 180 nullptr); | 196 nullptr); |
| 181 expected_bundle_.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 197 expected_bundle_.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 182 .CopyFrom(policy_map_); | 198 .CopyFrom(policy_map_); |
| 183 | 199 |
| 184 policy_.payload().mutable_passwordmanagerenabled()->set_value(false); | 200 policy_.payload().mutable_passwordmanagerenabled()->set_value(false); |
| 185 policy_.Build(); | 201 policy_.Build(); |
| 186 | 202 |
| 187 EXPECT_CALL(store_, Load()); | 203 EXPECT_CALL(store_, Load()); |
| 188 manager_.reset(new TestCloudPolicyManager(&store_, loop_.task_runner())); | 204 manager_.reset(new TestCloudPolicyManager(&store_, loop_.task_runner())); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 store_.policy_.reset(new em::PolicyData(policy_.policy_data())); | 366 store_.policy_.reset(new em::PolicyData(policy_.policy_data())); |
| 351 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); | 367 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); |
| 352 store_.NotifyStoreError(); | 368 store_.NotifyStoreError(); |
| 353 Mock::VerifyAndClearExpectations(&observer_); | 369 Mock::VerifyAndClearExpectations(&observer_); |
| 354 | 370 |
| 355 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); | 371 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); |
| 356 } | 372 } |
| 357 | 373 |
| 358 } // namespace | 374 } // namespace |
| 359 } // namespace policy | 375 } // namespace policy |
| OLD | NEW |