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

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

Issue 7345010: Tests for cloud policy UMA metrics. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reviewed, rebased Created 9 years, 5 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/chromeos/login/mock_signed_settings_helper.h"
8 #include "chrome/browser/policy/cloud_policy_data_store.h" 9 #include "chrome/browser/policy/cloud_policy_data_store.h"
9 #include "chrome/browser/policy/enterprise_install_attributes.h" 10 #include "chrome/browser/policy/enterprise_install_attributes.h"
10 #include "policy/configuration_policy_type.h" 11 #include "policy/configuration_policy_type.h"
11 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace policy { 15 namespace policy {
15 16
16 namespace { 17 namespace {
17 18
18 // Test registration user name. 19 // Test registration user name.
19 const char kTestUser[] = "test@example.com"; 20 const char kTestUser[] = "test@example.com";
20 21
21 using ::chromeos::SignedSettings; 22 using ::chromeos::SignedSettings;
22 using ::chromeos::SignedSettingsHelper; 23 using ::chromeos::SignedSettingsHelper;
23 using ::testing::_; 24 using ::testing::_;
24 using ::testing::InSequence; 25 using ::testing::InSequence;
25 26
26 class MockSignedSettingsHelper : public SignedSettingsHelper {
27 public:
28 MockSignedSettingsHelper() {}
29 virtual ~MockSignedSettingsHelper() {}
30
31 MOCK_METHOD2(StartStorePolicyOp, void(const em::PolicyFetchResponse&,
32 SignedSettingsHelper::Callback*));
33 MOCK_METHOD1(StartRetrievePolicyOp, void(SignedSettingsHelper::Callback*));
34 MOCK_METHOD1(CancelCallback, void(SignedSettingsHelper::Callback*));
35
36 // This test doesn't need these methods, but since they're pure virtual in
37 // SignedSettingsHelper, they must be implemented:
38 MOCK_METHOD2(StartCheckWhitelistOp, void(const std::string&,
39 SignedSettingsHelper::Callback*));
40 MOCK_METHOD3(StartWhitelistOp, void(const std::string&, bool,
41 SignedSettingsHelper::Callback*));
42 MOCK_METHOD3(StartStorePropertyOp, void(const std::string&,
43 const std::string&,
44 SignedSettingsHelper::Callback*));
45 MOCK_METHOD2(StartRetrieveProperty, void(const std::string&,
46 SignedSettingsHelper::Callback*));
47
48 private:
49 DISALLOW_COPY_AND_ASSIGN(MockSignedSettingsHelper);
50 };
51
52 ACTION_P(MockSignedSettingsHelperStorePolicy, status_code) {
53 arg1->OnStorePolicyCompleted(status_code);
54 }
55
56 ACTION_P2(MockSignedSettingsHelperRetrievePolicy, status_code, policy) {
57 arg0->OnRetrievePolicyCompleted(status_code, policy);
58 }
59
60 void CreateRefreshRatePolicy(em::PolicyFetchResponse* policy, 27 void CreateRefreshRatePolicy(em::PolicyFetchResponse* policy,
61 const std::string& user, 28 const std::string& user,
62 int refresh_rate) { 29 int refresh_rate) {
63 // This method omits a few fields which currently aren't needed by tests: 30 // This method omits a few fields which currently aren't needed by tests:
64 // timestamp, machine_name, policy_type, public key info. 31 // timestamp, machine_name, policy_type, public key info.
65 em::PolicyData signed_response; 32 em::PolicyData signed_response;
66 em::ChromeDeviceSettingsProto settings; 33 em::ChromeDeviceSettingsProto settings;
67 settings.mutable_device_policy_refresh_rate()-> 34 settings.mutable_device_policy_refresh_rate()->
68 set_device_policy_refresh_rate(refresh_rate); 35 set_device_policy_refresh_rate(refresh_rate);
69 signed_response.set_username(user); 36 signed_response.set_username(user);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 return cache_->mandatory_policy_.Get(policy); 96 return cache_->mandatory_policy_.Get(policy);
130 } 97 }
131 98
132 const Value* GetRecommendedPolicy(ConfigurationPolicyType policy) { 99 const Value* GetRecommendedPolicy(ConfigurationPolicyType policy) {
133 return cache_->recommended_policy_.Get(policy); 100 return cache_->recommended_policy_.Get(policy);
134 } 101 }
135 102
136 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_; 103 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_;
137 EnterpriseInstallAttributes install_attributes_; 104 EnterpriseInstallAttributes install_attributes_;
138 scoped_ptr<CloudPolicyDataStore> data_store_; 105 scoped_ptr<CloudPolicyDataStore> data_store_;
139 MockSignedSettingsHelper signed_settings_helper_; 106 chromeos::MockSignedSettingsHelper signed_settings_helper_;
140 scoped_ptr<DevicePolicyCache> cache_; 107 scoped_ptr<DevicePolicyCache> cache_;
141 108
142 private: 109 private:
143 DISALLOW_COPY_AND_ASSIGN(DevicePolicyCacheTest); 110 DISALLOW_COPY_AND_ASSIGN(DevicePolicyCacheTest);
144 }; 111 };
145 112
146 TEST_F(DevicePolicyCacheTest, Startup) { 113 TEST_F(DevicePolicyCacheTest, Startup) {
147 em::PolicyFetchResponse policy; 114 em::PolicyFetchResponse policy;
148 CreateRefreshRatePolicy(&policy, kTestUser, 120); 115 CreateRefreshRatePolicy(&policy, kTestUser, 120);
149 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( 116 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
(...skipping 26 matching lines...) Expand all
176 kPolicyDevicePolicyRefreshRate))); 143 kPolicyDevicePolicyRefreshRate)));
177 144
178 // Set new policy information. 145 // Set new policy information.
179 em::PolicyFetchResponse new_policy; 146 em::PolicyFetchResponse new_policy;
180 CreateRefreshRatePolicy(&new_policy, kTestUser, 300); 147 CreateRefreshRatePolicy(&new_policy, kTestUser, 300);
181 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).WillOnce( 148 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).WillOnce(
182 MockSignedSettingsHelperStorePolicy(chromeos::SignedSettings::SUCCESS)); 149 MockSignedSettingsHelperStorePolicy(chromeos::SignedSettings::SUCCESS));
183 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( 150 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
184 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, 151 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
185 new_policy)); 152 new_policy));
153 EXPECT_CALL(signed_settings_helper_, CancelCallback(_));
186 cache_->SetPolicy(new_policy); 154 cache_->SetPolicy(new_policy);
187 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); 155 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
188 FundamentalValue updated_expected(300); 156 FundamentalValue updated_expected(300);
189 EXPECT_TRUE(Value::Equals(&updated_expected, 157 EXPECT_TRUE(Value::Equals(&updated_expected,
190 GetMandatoryPolicy( 158 GetMandatoryPolicy(
191 kPolicyDevicePolicyRefreshRate))); 159 kPolicyDevicePolicyRefreshRate)));
192 } 160 }
193 161
194 TEST_F(DevicePolicyCacheTest, SetPolicyWrongUser) { 162 TEST_F(DevicePolicyCacheTest, SetPolicyWrongUser) {
195 InSequence s; 163 InSequence s;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 GetRecommendedPolicy(kPolicyProxyMode))); 233 GetRecommendedPolicy(kPolicyProxyMode)));
266 EXPECT_TRUE(Value::Equals(&expected_proxy_server, 234 EXPECT_TRUE(Value::Equals(&expected_proxy_server,
267 GetRecommendedPolicy(kPolicyProxyServer))); 235 GetRecommendedPolicy(kPolicyProxyServer)));
268 EXPECT_TRUE(Value::Equals(&expected_proxy_pac_url, 236 EXPECT_TRUE(Value::Equals(&expected_proxy_pac_url,
269 GetRecommendedPolicy(kPolicyProxyPacUrl))); 237 GetRecommendedPolicy(kPolicyProxyPacUrl)));
270 EXPECT_TRUE(Value::Equals(&expected_proxy_bypass_list, 238 EXPECT_TRUE(Value::Equals(&expected_proxy_bypass_list,
271 GetRecommendedPolicy(kPolicyProxyBypassList))); 239 GetRecommendedPolicy(kPolicyProxyBypassList)));
272 } 240 }
273 241
274 } // namespace policy 242 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/device_policy_cache.h ('k') | chrome/browser/policy/device_token_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698