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

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: Refactored as a browser_test, share mocks 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 GetRecommendedPolicy(kPolicyProxyMode))); 232 GetRecommendedPolicy(kPolicyProxyMode)));
266 EXPECT_TRUE(Value::Equals(&expected_proxy_server, 233 EXPECT_TRUE(Value::Equals(&expected_proxy_server,
267 GetRecommendedPolicy(kPolicyProxyServer))); 234 GetRecommendedPolicy(kPolicyProxyServer)));
268 EXPECT_TRUE(Value::Equals(&expected_proxy_pac_url, 235 EXPECT_TRUE(Value::Equals(&expected_proxy_pac_url,
269 GetRecommendedPolicy(kPolicyProxyPacUrl))); 236 GetRecommendedPolicy(kPolicyProxyPacUrl)));
270 EXPECT_TRUE(Value::Equals(&expected_proxy_bypass_list, 237 EXPECT_TRUE(Value::Equals(&expected_proxy_bypass_list,
271 GetRecommendedPolicy(kPolicyProxyBypassList))); 238 GetRecommendedPolicy(kPolicyProxyBypassList)));
272 } 239 }
273 240
274 } // namespace policy 241 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698