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

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

Issue 9911029: Refactored the CloudPolicyProvider so that it becomes initialized once and stays initialized. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Updated expectations in failing browser_tests Created 8 years, 8 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/policy/device_policy_cache_test_base.h"
6
7 #include "testing/gmock/include/gmock/gmock.h"
8
9 namespace em = enterprise_management;
10
11 using ::chromeos::SignedSettings;
12 using ::testing::_;
13
14 namespace policy {
15
16 const char DevicePolicyCacheTestHelper::kTestUser[] = "test@example.com";
17
18 DevicePolicyCacheTestHelper::DevicePolicyCacheTestHelper()
19 : cryptohome_(chromeos::CryptohomeLibrary::GetImpl(true)),
20 install_attributes_(cryptohome_.get()),
21 data_store_(CloudPolicyDataStore::CreateForDevicePolicies()),
22 scoped_cache_(new DevicePolicyCache(data_store_.get(),
23 &install_attributes_,
24 &signed_settings_helper_)),
25 cache_(scoped_cache_.get()),
26 username_(kTestUser) {}
27
28 DevicePolicyCacheTestHelper::~DevicePolicyCacheTestHelper() {}
29
30 bool DevicePolicyCacheTestHelper::MakeEnterpriseDevice() {
31 return EnterpriseInstallAttributes::LOCK_SUCCESS ==
32 install_attributes_.LockDevice(kTestUser, DEVICE_MODE_ENTERPRISE, "");
33 }
34
35 void DevicePolicyCacheTestHelper::ResetPolicy() {
36 settings_.Clear();
37 username_ = kTestUser;
38 }
39
40 void DevicePolicyCacheTestHelper::SetRefreshRatePolicy(int refresh_rate) {
41 settings_.mutable_device_policy_refresh_rate()->
42 set_device_policy_refresh_rate(refresh_rate);
43 }
44
45 void DevicePolicyCacheTestHelper::SetProxyPolicy(
46 const std::string& proxy_mode,
47 const std::string& proxy_server,
48 const std::string& proxy_pac_url,
49 const std::string& proxy_bypass_list) {
50 em::DeviceProxySettingsProto* proxy_settings =
51 settings_.mutable_device_proxy_settings();
52 proxy_settings->set_proxy_mode(proxy_mode);
53 proxy_settings->set_proxy_server(proxy_server);
54 proxy_settings->set_proxy_pac_url(proxy_pac_url);
55 proxy_settings->set_proxy_bypass_list(proxy_bypass_list);
56 }
57
58 void DevicePolicyCacheTestHelper::SetSettings(
59 const enterprise_management::ChromeDeviceSettingsProto& proto) {
60 settings_.CopyFrom(proto);
61 }
62
63 bool DevicePolicyCacheTestHelper::LoadPolicy() {
64 if (!SerializePolicy())
65 return false;
66
67 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
68 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
69 policy_));
70
71 cache_->Load();
72 return testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
73 }
74
75 bool DevicePolicyCacheTestHelper::SetPolicy(bool expect_store) {
76 if (!SerializePolicy())
77 return false;
78
79 if (expect_store) {
80 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).WillOnce(
81 MockSignedSettingsHelperStorePolicy(chromeos::SignedSettings::SUCCESS));
82 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
83 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
84 policy_));
85 }
86
87 bool result = cache_->SetPolicy(policy_);
88 cache_->SetFetchingDone();
89 if (!result)
90 return false;
91 return testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_);
92 }
93
94 bool DevicePolicyCacheTestHelper::SerializePolicy() {
95 // This method omits a few fields which currently aren't needed by tests:
96 // timestamp, machine_name, public key info.
97 em::PolicyData signed_response;
98 signed_response.set_username(username_);
99 signed_response.set_request_token("dmtoken");
100 signed_response.set_device_id("deviceid");
101 if (!settings_.SerializeToString(signed_response.mutable_policy_value()))
102 return false;
103 std::string serialized_signed_response;
104 if (!signed_response.SerializeToString(&serialized_signed_response))
105 return false;
106 policy_.set_policy_data(serialized_signed_response);
107 return true;
108 }
109
110 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698