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

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

Issue 6523058: New policy protobuf protocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/scoped_temp_dir.h" 7 #include "base/scoped_temp_dir.h"
8 #include "chrome/browser/browser_thread.h" 8 #include "chrome/browser/browser_thread.h"
9 #include "chrome/browser/net/gaia/token_service.h" 9 #include "chrome/browser/net/gaia/token_service.h"
10 #include "chrome/browser/policy/cloud_policy_cache.h"
10 #include "chrome/browser/policy/configuration_policy_pref_store.h" 11 #include "chrome/browser/policy/configuration_policy_pref_store.h"
11 #include "chrome/browser/policy/configuration_policy_provider.h" 12 #include "chrome/browser/policy/configuration_policy_provider.h"
12 #include "chrome/browser/policy/device_management_policy_cache.h"
13 #include "chrome/browser/policy/device_management_policy_provider.h" 13 #include "chrome/browser/policy/device_management_policy_provider.h"
14 #include "chrome/browser/policy/mock_configuration_policy_store.h" 14 #include "chrome/browser/policy/mock_configuration_policy_store.h"
15 #include "chrome/browser/policy/mock_device_management_backend.h" 15 #include "chrome/browser/policy/mock_device_management_backend.h"
16 #include "chrome/common/net/gaia/gaia_constants.h" 16 #include "chrome/common/net/gaia/gaia_constants.h"
17 #include "chrome/common/notification_observer_mock.h" 17 #include "chrome/common/notification_observer_mock.h"
18 #include "chrome/common/notification_service.h" 18 #include "chrome/common/notification_service.h"
19 #include "chrome/test/testing_device_token_fetcher.h" 19 #include "chrome/test/testing_device_token_fetcher.h"
20 #include "chrome/test/testing_profile.h" 20 #include "chrome/test/testing_profile.h"
21 #include "policy/policy_constants.h" 21 #include "policy/policy_constants.h"
22 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 static_cast<TestingDeviceTokenFetcher*>( 106 static_cast<TestingDeviceTokenFetcher*>(
107 provider_->token_fetcher_.get()); 107 provider_->token_fetcher_.get());
108 fetcher->SimulateLogin(kTestManagedDomainUsername); 108 fetcher->SimulateLogin(kTestManagedDomainUsername);
109 loop_.RunAllPending(); 109 loop_.RunAllPending();
110 } 110 }
111 111
112 void SimulateSuccessfulInitialPolicyFetch() { 112 void SimulateSuccessfulInitialPolicyFetch() {
113 MockConfigurationPolicyStore store; 113 MockConfigurationPolicyStore store;
114 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( 114 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
115 MockDeviceManagementBackendSucceedRegister()); 115 MockDeviceManagementBackendSucceedRegister());
116 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 116 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
117 MockDeviceManagementBackendSucceedBooleanPolicy( 117 MockDeviceManagementBackendSucceedSpdyCloudPolicy());
118 key::kDisableSpdy, true));
119 SimulateSuccessfulLoginAndRunPending(); 118 SimulateSuccessfulLoginAndRunPending();
120 EXPECT_FALSE(waiting_for_initial_policies()); 119 EXPECT_FALSE(waiting_for_initial_policies());
121 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); 120 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1);
122 provider_->Provide(&store); 121 provider_->Provide(&store);
123 ASSERT_EQ(1U, store.policy_map().size()); 122 ASSERT_EQ(1U, store.policy_map().size());
124 Mock::VerifyAndClearExpectations(backend_); 123 Mock::VerifyAndClearExpectations(backend_);
125 Mock::VerifyAndClearExpectations(&store); 124 Mock::VerifyAndClearExpectations(&store);
126 } 125 }
127 126
128 virtual void TearDown() { 127 virtual void TearDown() {
129 provider_.reset(); 128 provider_.reset();
130 loop_.RunAllPending(); 129 loop_.RunAllPending();
131 } 130 }
132 131
133 bool waiting_for_initial_policies() const { 132 bool waiting_for_initial_policies() const {
134 return !provider_->IsInitializationComplete(); 133 return !provider_->IsInitializationComplete();
135 } 134 }
136 135
137 MockDeviceManagementBackend* backend_; // weak 136 MockDeviceManagementBackend* backend_; // weak
138 scoped_ptr<DeviceManagementPolicyProvider> provider_; 137 scoped_ptr<DeviceManagementPolicyProvider> provider_;
139 138
140 protected: 139 protected:
141 DeviceManagementPolicyCache* cache(DeviceManagementPolicyProvider* provider) { 140 CloudPolicyCache* cache(DeviceManagementPolicyProvider* provider) {
142 return provider->cache_.get(); 141 return provider->cache_.get();
143 } 142 }
144 143
145 MessageLoop loop_; 144 MessageLoop loop_;
146 145
147 private: 146 private:
148 BrowserThread ui_thread_; 147 BrowserThread ui_thread_;
149 BrowserThread file_thread_; 148 BrowserThread file_thread_;
150 scoped_ptr<Profile> profile_; 149 scoped_ptr<Profile> profile_;
151 150
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 185
187 // If a policy has been fetched previously, if should be available even before 186 // If a policy has been fetched previously, if should be available even before
188 // the login succeeds or the device management backend is available. 187 // the login succeeds or the device management backend is available.
189 TEST_F(DeviceManagementPolicyProviderTest, SecondProvide) { 188 TEST_F(DeviceManagementPolicyProviderTest, SecondProvide) {
190 // Pre-fetch and persist a policy 189 // Pre-fetch and persist a policy
191 SimulateSuccessfulInitialPolicyFetch(); 190 SimulateSuccessfulInitialPolicyFetch();
192 191
193 // Simulate a app relaunch by constructing a new provider. Policy should be 192 // Simulate a app relaunch by constructing a new provider. Policy should be
194 // refreshed (since that might be the purpose of the app relaunch). 193 // refreshed (since that might be the purpose of the app relaunch).
195 CreateNewProvider(); 194 CreateNewProvider();
196 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 195 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
197 MockDeviceManagementBackendSucceedBooleanPolicy( 196 MockDeviceManagementBackendSucceedSpdyCloudPolicy());
198 key::kDisableSpdy, true));
199 loop_.RunAllPending(); 197 loop_.RunAllPending();
200 Mock::VerifyAndClearExpectations(backend_); 198 Mock::VerifyAndClearExpectations(backend_);
201 199
202 // Simulate another app relaunch, this time against a failing backend. 200 // Simulate another app relaunch, this time against a failing backend.
203 // Cached policy should still be available. 201 // Cached policy should still be available.
204 MockConfigurationPolicyStore store; 202 MockConfigurationPolicyStore store;
205 CreateNewProvider(); 203 CreateNewProvider();
206 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 204 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
207 MockDeviceManagementBackendFailPolicy( 205 MockDeviceManagementBackendFailPolicy(
208 DeviceManagementBackend::kErrorRequestFailed)); 206 DeviceManagementBackend::kErrorRequestFailed));
209 SimulateSuccessfulLoginAndRunPending(); 207 SimulateSuccessfulLoginAndRunPending();
210 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); 208 EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1);
211 provider_->Provide(&store); 209 provider_->Provide(&store);
212 ASSERT_EQ(1U, store.policy_map().size()); 210 ASSERT_EQ(1U, store.policy_map().size());
213 } 211 }
214 212
215 // When policy is successfully fetched from the device management server, it 213 // When policy is successfully fetched from the device management server, it
216 // should force a policy refresh. 214 // should force a policy refresh.
217 TEST_F(DeviceManagementPolicyProviderTest, FetchTriggersRefresh) { 215 TEST_F(DeviceManagementPolicyProviderTest, FetchTriggersRefresh) {
218 MockConfigurationPolicyObserver observer; 216 MockConfigurationPolicyObserver observer;
219 ConfigurationPolicyObserverRegistrar registrar; 217 ConfigurationPolicyObserverRegistrar registrar;
220 registrar.Init(provider_.get(), &observer); 218 registrar.Init(provider_.get(), &observer);
221 EXPECT_CALL(observer, OnUpdatePolicy()).Times(1); 219 EXPECT_CALL(observer, OnUpdatePolicy()).Times(1);
222 SimulateSuccessfulInitialPolicyFetch(); 220 SimulateSuccessfulInitialPolicyFetch();
223 } 221 }
224 222
225 TEST_F(DeviceManagementPolicyProviderTest, ErrorCausesNewRequest) { 223 TEST_F(DeviceManagementPolicyProviderTest, ErrorCausesNewRequest) {
226 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence. 224 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence.
227 InSequence s; 225 InSequence s;
228 CreateNewProvider(1000 * 1000, 0, 0, 0, 0, 0); 226 CreateNewProvider(1000 * 1000, 0, 0, 0, 0, 0);
229 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( 227 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
230 MockDeviceManagementBackendFailRegister( 228 MockDeviceManagementBackendFailRegister(
231 DeviceManagementBackend::kErrorRequestFailed)); 229 DeviceManagementBackend::kErrorRequestFailed));
232 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( 230 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
233 MockDeviceManagementBackendSucceedRegister()); 231 MockDeviceManagementBackendSucceedRegister());
234 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 232 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
235 MockDeviceManagementBackendFailPolicy( 233 MockDeviceManagementBackendFailPolicy(
236 DeviceManagementBackend::kErrorRequestFailed)); 234 DeviceManagementBackend::kErrorRequestFailed));
237 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 235 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
238 MockDeviceManagementBackendFailPolicy( 236 MockDeviceManagementBackendFailPolicy(
239 DeviceManagementBackend::kErrorRequestFailed)); 237 DeviceManagementBackend::kErrorRequestFailed));
240 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 238 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
241 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, 239 MockDeviceManagementBackendSucceedSpdyCloudPolicy());
242 true));
243 } 240 }
244 SimulateSuccessfulLoginAndRunPending(); 241 SimulateSuccessfulLoginAndRunPending();
245 } 242 }
246 243
247 TEST_F(DeviceManagementPolicyProviderTest, RefreshPolicies) { 244 TEST_F(DeviceManagementPolicyProviderTest, RefreshPolicies) {
248 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence. 245 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence.
249 InSequence s; 246 InSequence s;
250 CreateNewProvider(0, 0, 0, 1000 * 1000, 1000, 0); 247 CreateNewProvider(0, 0, 0, 1000 * 1000, 1000, 0);
251 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( 248 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
252 MockDeviceManagementBackendSucceedRegister()); 249 MockDeviceManagementBackendSucceedRegister());
253 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 250 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
254 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, 251 MockDeviceManagementBackendSucceedSpdyCloudPolicy());
255 true)); 252 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
256 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 253 MockDeviceManagementBackendSucceedSpdyCloudPolicy());
257 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, 254 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
258 true)); 255 MockDeviceManagementBackendSucceedSpdyCloudPolicy());
259 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 256 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
260 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy,
261 true));
262 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
263 MockDeviceManagementBackendFailPolicy( 257 MockDeviceManagementBackendFailPolicy(
264 DeviceManagementBackend::kErrorRequestFailed)); 258 DeviceManagementBackend::kErrorRequestFailed));
265 } 259 }
266 SimulateSuccessfulLoginAndRunPending(); 260 SimulateSuccessfulLoginAndRunPending();
267 } 261 }
268 262
269 // The client should try to re-register the device if the device server reports 263 // The client should try to re-register the device if the device server reports
270 // back that it doesn't recognize the device token on a policy request. 264 // back that it doesn't recognize the device token on a policy request.
271 TEST_F(DeviceManagementPolicyProviderTest, DeviceNotFound) { 265 TEST_F(DeviceManagementPolicyProviderTest, DeviceNotFound) {
272 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence. 266 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence.
273 InSequence s; 267 InSequence s;
274 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( 268 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
275 MockDeviceManagementBackendSucceedRegister()); 269 MockDeviceManagementBackendSucceedRegister());
276 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 270 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
277 MockDeviceManagementBackendFailPolicy( 271 MockDeviceManagementBackendFailPolicy(
278 DeviceManagementBackend::kErrorServiceDeviceNotFound)); 272 DeviceManagementBackend::kErrorServiceDeviceNotFound));
279 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( 273 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
280 MockDeviceManagementBackendSucceedRegister()); 274 MockDeviceManagementBackendSucceedRegister());
281 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 275 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
282 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, 276 MockDeviceManagementBackendSucceedSpdyCloudPolicy());
283 true));
284 } 277 }
285 SimulateSuccessfulLoginAndRunPending(); 278 SimulateSuccessfulLoginAndRunPending();
286 } 279 }
287 280
288 // The client should try to re-register the device if the device server reports 281 // The client should try to re-register the device if the device server reports
289 // back that the device token is invalid on a policy request. 282 // back that the device token is invalid on a policy request.
290 TEST_F(DeviceManagementPolicyProviderTest, InvalidTokenOnPolicyRequest) { 283 TEST_F(DeviceManagementPolicyProviderTest, InvalidTokenOnPolicyRequest) {
291 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence. 284 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence.
292 InSequence s; 285 InSequence s;
293 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( 286 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
294 MockDeviceManagementBackendSucceedRegister()); 287 MockDeviceManagementBackendSucceedRegister());
295 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 288 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
296 MockDeviceManagementBackendFailPolicy( 289 MockDeviceManagementBackendFailPolicy(
297 DeviceManagementBackend::kErrorServiceManagementTokenInvalid)); 290 DeviceManagementBackend::kErrorServiceManagementTokenInvalid));
298 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( 291 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
299 MockDeviceManagementBackendSucceedRegister()); 292 MockDeviceManagementBackendSucceedRegister());
300 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 293 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
301 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, 294 MockDeviceManagementBackendSucceedSpdyCloudPolicy());
302 true));
303 } 295 }
304 SimulateSuccessfulLoginAndRunPending(); 296 SimulateSuccessfulLoginAndRunPending();
305 } 297 }
306 298
307 // If the client is successfully managed, but the admin stops managing the 299 // If the client is successfully managed, but the admin stops managing the
308 // device, the client should notice and throw away the device token and id. 300 // device, the client should notice and throw away the device token and id.
309 TEST_F(DeviceManagementPolicyProviderTest, DeviceNoLongerManaged) { 301 TEST_F(DeviceManagementPolicyProviderTest, DeviceNoLongerManaged) {
310 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence. 302 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence.
311 InSequence s; 303 InSequence s;
312 CreateNewProvider(0, 0, 0, 0, 0, 1000 * 1000); 304 CreateNewProvider(0, 0, 0, 0, 0, 1000 * 1000);
313 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( 305 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
314 MockDeviceManagementBackendSucceedRegister()); 306 MockDeviceManagementBackendSucceedRegister());
315 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 307 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
316 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, 308 MockDeviceManagementBackendSucceedSpdyCloudPolicy());
317 true)); 309 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
318 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 310 MockDeviceManagementBackendSucceedSpdyCloudPolicy());
319 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, 311 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
320 true));
321 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
322 MockDeviceManagementBackendFailPolicy( 312 MockDeviceManagementBackendFailPolicy(
323 DeviceManagementBackend::kErrorServiceManagementNotSupported)); 313 DeviceManagementBackend::kErrorServiceManagementNotSupported));
324 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( 314 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
325 MockDeviceManagementBackendFailRegister( 315 MockDeviceManagementBackendFailRegister(
326 DeviceManagementBackend::kErrorServiceManagementNotSupported)); 316 DeviceManagementBackend::kErrorServiceManagementNotSupported));
327 } 317 }
328 SimulateSuccessfulLoginAndRunPending(); 318 SimulateSuccessfulLoginAndRunPending();
329 FilePath token_path(GetTokenPath()); 319 FilePath token_path(GetTokenPath());
330 EXPECT_FALSE(file_util::PathExists(token_path)); 320 EXPECT_FALSE(file_util::PathExists(token_path));
331 } 321 }
332 322
333 // This test tests three things (see numbered comments below): 323 // This test tests three things (see numbered comments below):
334 TEST_F(DeviceManagementPolicyProviderTest, UnmanagedDevice) { 324 TEST_F(DeviceManagementPolicyProviderTest, UnmanagedDevice) {
335 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence. 325 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence.
336 InSequence s; 326 InSequence s;
337 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( 327 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
338 MockDeviceManagementBackendFailRegister( 328 MockDeviceManagementBackendFailRegister(
339 DeviceManagementBackend::kErrorServiceManagementNotSupported)); 329 DeviceManagementBackend::kErrorServiceManagementNotSupported));
340 } 330 }
341 SimulateSuccessfulLoginAndRunPending(); 331 SimulateSuccessfulLoginAndRunPending();
342 // (1) The provider's DMPolicyCache should know that the device is not 332 // (1) The provider's DMPolicyCache should know that the device is not
343 // managed. 333 // managed.
344 EXPECT_TRUE(cache(provider_.get())->is_device_unmanaged()); 334 EXPECT_TRUE(cache(provider_.get())->is_unmanaged());
345 // (2) On restart, the provider should detect that this is not the first 335 // (2) On restart, the provider should detect that this is not the first
346 // login. 336 // login.
347 CreateNewProvider(1000 * 1000, 0, 0, 0, 0, 0); 337 CreateNewProvider(1000 * 1000, 0, 0, 0, 0, 0);
348 EXPECT_FALSE(waiting_for_initial_policies()); 338 EXPECT_FALSE(waiting_for_initial_policies());
349 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence. 339 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence.
350 InSequence s; 340 InSequence s;
351 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce( 341 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
352 MockDeviceManagementBackendSucceedRegister()); 342 MockDeviceManagementBackendSucceedRegister());
353 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce( 343 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
354 MockDeviceManagementBackendSucceedBooleanPolicy(key::kDisableSpdy, 344 MockDeviceManagementBackendSucceedSpdyCloudPolicy());
355 true));
356 } 345 }
357 SimulateSuccessfulLoginAndRunPending(); 346 SimulateSuccessfulLoginAndRunPending();
358 // (3) Since the backend call this time returned a device id, the "unmanaged" 347 // (3) Since the backend call this time returned a device id, the "unmanaged"
359 // marker should have been deleted. 348 // marker should have been deleted.
360 EXPECT_FALSE(cache(provider_.get())->is_device_unmanaged()); 349 EXPECT_FALSE(cache(provider_.get())->is_unmanaged());
350 }
351
352 TEST_F(DeviceManagementPolicyProviderTest, FallbackToOldProtocol) {
353 { // Scoping so SimulateSuccessfulLoginAndRunPending doesn't see the sequence.
354 InSequence s;
355 CreateNewProvider(0, 0, 0, 0, 0, 1000 * 1000);
356 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
357 MockDeviceManagementBackendSucceedRegister());
358 // If the CloudPolicyRequest fails with kErrorRequestInvalid...
359 EXPECT_CALL(*backend_, ProcessCloudPolicyRequest(_, _, _, _)).WillOnce(
360 MockDeviceManagementBackendFailPolicy(
361 DeviceManagementBackend::kErrorRequestInvalid));
362 // ...the client should fall back to a classic PolicyRequest...
363 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
364 MockDeviceManagementBackendSucceedBooleanPolicy(
365 key::kDisableSpdy, true));
366 // ...and remember this fallback for any future request, ...
367 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
368 MockDeviceManagementBackendFailPolicy(
369 DeviceManagementBackend::kErrorHttpStatus));
370 // ...both after successful fetches and after errors.
371 EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _, _)).WillOnce(
372 MockDeviceManagementBackendFailPolicy(
373 DeviceManagementBackend::kErrorServiceManagementNotSupported));
374 // Finally, we set the client to 'unmanaged' to stop its request stream.
375 EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).WillOnce(
376 MockDeviceManagementBackendFailRegister(
377 DeviceManagementBackend::kErrorServiceManagementNotSupported));
378 }
379 SimulateSuccessfulLoginAndRunPending();
361 } 380 }
362 381
363 } // namespace policy 382 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/device_management_policy_provider.cc ('k') | chrome/browser/policy/mock_device_management_backend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698