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