Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: chrome/browser/policy/device_policy_cache_unittest.cc

Issue 7014036: Split the policy refresh rate preference into user- and device-policy refresh rate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits. Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/policy/device_policy_cache.h" 5 #include "chrome/browser/policy/device_policy_cache.h"
6 6
7 #include "chrome/browser/chromeos/cros/cryptohome_library.h" 7 #include "chrome/browser/chromeos/cros/cryptohome_library.h"
8 #include "chrome/browser/policy/device_policy_identity_strategy.h" 8 #include "chrome/browser/policy/device_policy_identity_strategy.h"
9 #include "chrome/browser/policy/enterprise_install_attributes.h" 9 #include "chrome/browser/policy/enterprise_install_attributes.h"
10 #include "policy/configuration_policy_type.h" 10 #include "policy/configuration_policy_type.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 arg0->OnRetrievePolicyCompleted(status_code, policy); 57 arg0->OnRetrievePolicyCompleted(status_code, policy);
58 } 58 }
59 59
60 void CreateRefreshRatePolicy(em::PolicyFetchResponse* policy, 60 void CreateRefreshRatePolicy(em::PolicyFetchResponse* policy,
61 const std::string& user, 61 const std::string& user,
62 int refresh_rate) { 62 int refresh_rate) {
63 // This method omits a few fields which currently aren't needed by tests: 63 // This method omits a few fields which currently aren't needed by tests:
64 // timestamp, machine_name, policy_type, public key info. 64 // timestamp, machine_name, policy_type, public key info.
65 em::PolicyData signed_response; 65 em::PolicyData signed_response;
66 em::ChromeDeviceSettingsProto settings; 66 em::ChromeDeviceSettingsProto settings;
67 settings.mutable_policy_refresh_rate()->set_policy_refresh_rate(refresh_rate); 67 settings.mutable_device_policy_refresh_rate()->
68 set_device_policy_refresh_rate(refresh_rate);
68 signed_response.set_username(user); 69 signed_response.set_username(user);
69 signed_response.set_request_token("dmtoken"); 70 signed_response.set_request_token("dmtoken");
70 signed_response.set_device_id("deviceid"); 71 signed_response.set_device_id("deviceid");
71 EXPECT_TRUE( 72 EXPECT_TRUE(
72 settings.SerializeToString(signed_response.mutable_policy_value())); 73 settings.SerializeToString(signed_response.mutable_policy_value()));
73 std::string serialized_signed_response; 74 std::string serialized_signed_response;
74 EXPECT_TRUE(signed_response.SerializeToString(&serialized_signed_response)); 75 EXPECT_TRUE(signed_response.SerializeToString(&serialized_signed_response));
75 policy->set_policy_data(serialized_signed_response); 76 policy->set_policy_data(serialized_signed_response);
76 } 77 }
77 78
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 TEST_F(DevicePolicyCacheTest, Startup) { 145 TEST_F(DevicePolicyCacheTest, Startup) {
145 em::PolicyFetchResponse policy; 146 em::PolicyFetchResponse policy;
146 CreateRefreshRatePolicy(&policy, kTestUser, 120); 147 CreateRefreshRatePolicy(&policy, kTestUser, 120);
147 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( 148 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
148 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, 149 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
149 policy)); 150 policy));
150 cache_->Load(); 151 cache_->Load();
151 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); 152 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
152 FundamentalValue expected(120); 153 FundamentalValue expected(120);
153 EXPECT_TRUE(Value::Equals(&expected, 154 EXPECT_TRUE(Value::Equals(&expected,
154 GetMandatoryPolicy(kPolicyPolicyRefreshRate))); 155 GetMandatoryPolicy(
156 kPolicyDevicePolicyRefreshRate)));
155 } 157 }
156 158
157 TEST_F(DevicePolicyCacheTest, SetPolicy) { 159 TEST_F(DevicePolicyCacheTest, SetPolicy) {
158 InSequence s; 160 InSequence s;
159 161
160 MakeEnterpriseDevice(kTestUser); 162 MakeEnterpriseDevice(kTestUser);
161 163
162 // Startup. 164 // Startup.
163 em::PolicyFetchResponse policy; 165 em::PolicyFetchResponse policy;
164 CreateRefreshRatePolicy(&policy, kTestUser, 120); 166 CreateRefreshRatePolicy(&policy, kTestUser, 120);
165 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( 167 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
166 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, 168 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
167 policy)); 169 policy));
168 cache_->Load(); 170 cache_->Load();
169 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); 171 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
170 FundamentalValue expected(120); 172 FundamentalValue expected(120);
171 EXPECT_TRUE(Value::Equals(&expected, 173 EXPECT_TRUE(Value::Equals(&expected,
172 GetMandatoryPolicy(kPolicyPolicyRefreshRate))); 174 GetMandatoryPolicy(
175 kPolicyDevicePolicyRefreshRate)));
173 176
174 // Set new policy information. 177 // Set new policy information.
175 em::PolicyFetchResponse new_policy; 178 em::PolicyFetchResponse new_policy;
176 CreateRefreshRatePolicy(&new_policy, kTestUser, 300); 179 CreateRefreshRatePolicy(&new_policy, kTestUser, 300);
177 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).WillOnce( 180 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).WillOnce(
178 MockSignedSettingsHelperStorePolicy(chromeos::SignedSettings::SUCCESS)); 181 MockSignedSettingsHelperStorePolicy(chromeos::SignedSettings::SUCCESS));
179 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( 182 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
180 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, 183 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
181 new_policy)); 184 new_policy));
182 cache_->SetPolicy(new_policy); 185 cache_->SetPolicy(new_policy);
183 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); 186 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
184 FundamentalValue updated_expected(300); 187 FundamentalValue updated_expected(300);
185 EXPECT_TRUE(Value::Equals(&updated_expected, 188 EXPECT_TRUE(Value::Equals(&updated_expected,
186 GetMandatoryPolicy(kPolicyPolicyRefreshRate))); 189 GetMandatoryPolicy(
190 kPolicyDevicePolicyRefreshRate)));
187 } 191 }
188 192
189 TEST_F(DevicePolicyCacheTest, SetPolicyWrongUser) { 193 TEST_F(DevicePolicyCacheTest, SetPolicyWrongUser) {
190 InSequence s; 194 InSequence s;
191 195
192 MakeEnterpriseDevice(kTestUser); 196 MakeEnterpriseDevice(kTestUser);
193 197
194 // Startup. 198 // Startup.
195 em::PolicyFetchResponse policy; 199 em::PolicyFetchResponse policy;
196 CreateRefreshRatePolicy(&policy, kTestUser, 120); 200 CreateRefreshRatePolicy(&policy, kTestUser, 120);
197 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( 201 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
198 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, 202 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
199 policy)); 203 policy));
200 cache_->Load(); 204 cache_->Load();
201 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); 205 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
202 206
203 // Set new policy information. This should fail due to invalid user. 207 // Set new policy information. This should fail due to invalid user.
204 em::PolicyFetchResponse new_policy; 208 em::PolicyFetchResponse new_policy;
205 CreateRefreshRatePolicy(&new_policy, "foreign_user@example.com", 300); 209 CreateRefreshRatePolicy(&new_policy, "foreign_user@example.com", 300);
206 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0); 210 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0);
207 cache_->SetPolicy(new_policy); 211 cache_->SetPolicy(new_policy);
208 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); 212 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
209 213
210 FundamentalValue expected(120); 214 FundamentalValue expected(120);
211 EXPECT_TRUE(Value::Equals(&expected, 215 EXPECT_TRUE(Value::Equals(&expected,
212 GetMandatoryPolicy(kPolicyPolicyRefreshRate))); 216 GetMandatoryPolicy(
217 kPolicyDevicePolicyRefreshRate)));
213 } 218 }
214 219
215 TEST_F(DevicePolicyCacheTest, SetPolicyNonEnterpriseDevice) { 220 TEST_F(DevicePolicyCacheTest, SetPolicyNonEnterpriseDevice) {
216 InSequence s; 221 InSequence s;
217 222
218 // Startup. 223 // Startup.
219 em::PolicyFetchResponse policy; 224 em::PolicyFetchResponse policy;
220 CreateRefreshRatePolicy(&policy, kTestUser, 120); 225 CreateRefreshRatePolicy(&policy, kTestUser, 120);
221 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( 226 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
222 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, 227 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
223 policy)); 228 policy));
224 cache_->Load(); 229 cache_->Load();
225 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); 230 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
226 231
227 // Set new policy information. This should fail due to invalid user. 232 // Set new policy information. This should fail due to invalid user.
228 em::PolicyFetchResponse new_policy; 233 em::PolicyFetchResponse new_policy;
229 CreateRefreshRatePolicy(&new_policy, kTestUser, 120); 234 CreateRefreshRatePolicy(&new_policy, kTestUser, 120);
230 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0); 235 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0);
231 cache_->SetPolicy(new_policy); 236 cache_->SetPolicy(new_policy);
232 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); 237 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
233 238
234 FundamentalValue expected(120); 239 FundamentalValue expected(120);
235 EXPECT_TRUE(Value::Equals(&expected, 240 EXPECT_TRUE(Value::Equals(&expected,
236 GetMandatoryPolicy(kPolicyPolicyRefreshRate))); 241 GetMandatoryPolicy(
242 kPolicyDevicePolicyRefreshRate)));
237 } 243 }
238 244
239 TEST_F(DevicePolicyCacheTest, SetProxyPolicy) { 245 TEST_F(DevicePolicyCacheTest, SetProxyPolicy) {
240 InSequence s; 246 InSequence s;
241 247
242 MakeEnterpriseDevice(kTestUser); 248 MakeEnterpriseDevice(kTestUser);
243 249
244 // Startup. 250 // Startup.
245 em::PolicyFetchResponse policy; 251 em::PolicyFetchResponse policy;
246 CreateProxyPolicy(&policy, kTestUser, "direct", "http://proxy:8080", 252 CreateProxyPolicy(&policy, kTestUser, "direct", "http://proxy:8080",
(...skipping 11 matching lines...) Expand all
258 GetRecommendedPolicy(kPolicyProxyMode))); 264 GetRecommendedPolicy(kPolicyProxyMode)));
259 EXPECT_TRUE(Value::Equals(&expected_proxy_server, 265 EXPECT_TRUE(Value::Equals(&expected_proxy_server,
260 GetRecommendedPolicy(kPolicyProxyServer))); 266 GetRecommendedPolicy(kPolicyProxyServer)));
261 EXPECT_TRUE(Value::Equals(&expected_proxy_pac_url, 267 EXPECT_TRUE(Value::Equals(&expected_proxy_pac_url,
262 GetRecommendedPolicy(kPolicyProxyPacUrl))); 268 GetRecommendedPolicy(kPolicyProxyPacUrl)));
263 EXPECT_TRUE(Value::Equals(&expected_proxy_bypass_list, 269 EXPECT_TRUE(Value::Equals(&expected_proxy_bypass_list,
264 GetRecommendedPolicy(kPolicyProxyBypassList))); 270 GetRecommendedPolicy(kPolicyProxyBypassList)));
265 } 271 }
266 272
267 } // namespace policy 273 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/device_policy_cache.cc ('k') | chrome/browser/policy/profile_policy_connector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698