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

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

Issue 6979011: Move user cloud policy to BrowserProcess. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments by mnissler. 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/cloud_policy_controller.h" 5 #include "chrome/browser/policy/cloud_policy_controller.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/scoped_temp_dir.h" 8 #include "base/scoped_temp_dir.h"
9 #include "chrome/browser/policy/cloud_policy_provider.h"
10 #include "chrome/browser/policy/configuration_policy_pref_store.h"
9 #include "chrome/browser/policy/device_management_service.h" 11 #include "chrome/browser/policy/device_management_service.h"
10 #include "chrome/browser/policy/device_token_fetcher.h" 12 #include "chrome/browser/policy/device_token_fetcher.h"
11 #include "chrome/browser/policy/mock_configuration_policy_store.h" 13 #include "chrome/browser/policy/mock_configuration_policy_store.h"
12 #include "chrome/browser/policy/mock_device_management_backend.h" 14 #include "chrome/browser/policy/mock_device_management_backend.h"
13 #include "chrome/browser/policy/mock_device_management_service.h" 15 #include "chrome/browser/policy/mock_device_management_service.h"
14 #include "chrome/browser/policy/policy_notifier.h" 16 #include "chrome/browser/policy/policy_notifier.h"
15 #include "chrome/browser/policy/proto/device_management_backend.pb.h" 17 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
16 #include "chrome/browser/policy/user_policy_cache.h" 18 #include "chrome/browser/policy/user_policy_cache.h"
17 #include "content/browser/browser_thread.h" 19 #include "content/browser/browser_thread.h"
18 #include "policy/policy_constants.h" 20 #include "policy/policy_constants.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 CloudPolicyControllerTest() 80 CloudPolicyControllerTest()
79 : ui_thread_(BrowserThread::UI, &loop_), 81 : ui_thread_(BrowserThread::UI, &loop_),
80 file_thread_(BrowserThread::FILE, &loop_) {} 82 file_thread_(BrowserThread::FILE, &loop_) {}
81 83
82 virtual ~CloudPolicyControllerTest() {} 84 virtual ~CloudPolicyControllerTest() {}
83 85
84 virtual void SetUp() { 86 virtual void SetUp() {
85 ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir()); 87 ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir());
86 cache_.reset(new UserPolicyCache( 88 cache_.reset(new UserPolicyCache(
87 temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest"))); 89 temp_user_data_dir_.path().AppendASCII("CloudPolicyControllerTest")));
90 mandatory_cloud_provider_.reset(new CloudPolicyProvider(
91 policy::ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
92 CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY));
93 recommended_cloud_provider_.reset(new CloudPolicyProvider(
94 policy::ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
95 CloudPolicyCacheBase::POLICY_LEVEL_RECOMMENDED));
96 mandatory_cloud_provider_->AppendCache(cache_.get());
97 recommended_cloud_provider_->AppendCache(cache_.get());
88 token_fetcher_.reset(new MockDeviceTokenFetcher(cache_.get())); 98 token_fetcher_.reset(new MockDeviceTokenFetcher(cache_.get()));
89 service_.set_backend(&backend_); 99 service_.set_backend(&backend_);
90 } 100 }
91 101
92 virtual void TearDown() { 102 virtual void TearDown() {
93 controller_.reset(); // Unregisters observers. 103 controller_.reset(); // Unregisters observers.
94 } 104 }
95 105
96 // Takes ownership of |backend|. 106 // Takes ownership of |backend|.
97 void CreateNewController() { 107 void CreateNewController() {
(...skipping 11 matching lines...) Expand all
109 &notifier_, 119 &notifier_,
110 policy_refresh_rate_ms, 120 policy_refresh_rate_ms,
111 policy_refresh_deviation_factor_percent, 121 policy_refresh_deviation_factor_percent,
112 policy_refresh_deviation_max_ms, 122 policy_refresh_deviation_max_ms,
113 policy_refresh_error_delay_ms)); 123 policy_refresh_error_delay_ms));
114 } 124 }
115 125
116 void ExpectHasSpdyPolicy() { 126 void ExpectHasSpdyPolicy() {
117 MockConfigurationPolicyStore store; 127 MockConfigurationPolicyStore store;
118 EXPECT_CALL(store, Apply(_, _)).Times(AtLeast(1)); 128 EXPECT_CALL(store, Apply(_, _)).Times(AtLeast(1));
119 cache_->GetManagedPolicyProvider()->Provide(&store); 129 mandatory_cloud_provider_.get()->Provide(&store);
120 FundamentalValue expected(true); 130 FundamentalValue expected(true);
121 ASSERT_TRUE(store.Get(kPolicyDisableSpdy) != NULL); 131 const PolicyMap* policy_map = cache_->policy(
122 EXPECT_TRUE(store.Get(kPolicyDisableSpdy)->Equals(&expected)); 132 CloudPolicyCacheBase::POLICY_LEVEL_MANDATORY);
133 ASSERT_TRUE(policy_map->Get(kPolicyDisableSpdy));
134 EXPECT_TRUE(policy_map->Get(kPolicyDisableSpdy)->Equals(&expected));
123 } 135 }
124 136
125 void SetupIdentityStrategy( 137 void SetupIdentityStrategy(
126 const std::string& device_token, 138 const std::string& device_token,
127 const std::string& device_id, 139 const std::string& device_id,
128 const std::string& machine_id, 140 const std::string& machine_id,
129 const std::string& machine_model, 141 const std::string& machine_model,
130 const std::string& policy_type, 142 const std::string& policy_type,
131 const em::DeviceRegisterRequest_Type& policy_register_type, 143 const em::DeviceRegisterRequest_Type& policy_register_type,
132 const std::string& user_name, 144 const std::string& user_name,
(...skipping 11 matching lines...) Expand all
144 EXPECT_CALL(identity_strategy_, GetPolicyRegisterType()).WillRepeatedly( 156 EXPECT_CALL(identity_strategy_, GetPolicyRegisterType()).WillRepeatedly(
145 Return(policy_register_type)); 157 Return(policy_register_type));
146 if (!user_name.empty()) { 158 if (!user_name.empty()) {
147 EXPECT_CALL(identity_strategy_, GetCredentials(_, _)).WillRepeatedly( 159 EXPECT_CALL(identity_strategy_, GetCredentials(_, _)).WillRepeatedly(
148 MockCloudPolicyIdentityStrategyGetCredentials(user_name, auth_token)); 160 MockCloudPolicyIdentityStrategyGetCredentials(user_name, auth_token));
149 } 161 }
150 } 162 }
151 163
152 protected: 164 protected:
153 scoped_ptr<CloudPolicyCacheBase> cache_; 165 scoped_ptr<CloudPolicyCacheBase> cache_;
166 scoped_ptr<CloudPolicyProvider> recommended_cloud_provider_;
167 scoped_ptr<CloudPolicyProvider> mandatory_cloud_provider_;
154 scoped_ptr<CloudPolicyController> controller_; 168 scoped_ptr<CloudPolicyController> controller_;
155 scoped_ptr<MockDeviceTokenFetcher> token_fetcher_; 169 scoped_ptr<MockDeviceTokenFetcher> token_fetcher_;
156 MockCloudPolicyIdentityStrategy identity_strategy_; 170 MockCloudPolicyIdentityStrategy identity_strategy_;
157 MockDeviceManagementBackend backend_; 171 MockDeviceManagementBackend backend_;
158 MockDeviceManagementService service_; 172 MockDeviceManagementService service_;
159 PolicyNotifier notifier_; 173 PolicyNotifier notifier_;
160 ScopedTempDir temp_user_data_dir_; 174 ScopedTempDir temp_user_data_dir_;
161 MessageLoop loop_; 175 MessageLoop loop_;
162 176
163 private: 177 private:
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 "who@what.com", "auth"); 287 "who@what.com", "auth");
274 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 288 EXPECT_CALL(backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
275 MockDeviceManagementBackendFailPolicy( 289 MockDeviceManagementBackendFailPolicy(
276 DeviceManagementBackend::kErrorServiceManagementNotSupported)); 290 DeviceManagementBackend::kErrorServiceManagementNotSupported));
277 EXPECT_CALL(*token_fetcher_.get(), SetUnmanagedState()).Times(1); 291 EXPECT_CALL(*token_fetcher_.get(), SetUnmanagedState()).Times(1);
278 CreateNewController(0, 0, 0, 1000 * 1000); 292 CreateNewController(0, 0, 0, 1000 * 1000);
279 loop_.RunAllPending(); 293 loop_.RunAllPending();
280 } 294 }
281 295
282 } // namespace policy 296 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_cache_base.cc ('k') | chrome/browser/policy/cloud_policy_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698