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

Side by Side Diff: chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos_unittest.cc

Issue 23450022: Put a hard limit on initial policy fetch wait time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 3 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) 2012 The Chromium Authors. All rights reserved. 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 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/chromeos/policy/user_cloud_policy_manager_chromeos.h" 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/prefs/pref_registry_simple.h" 13 #include "base/prefs/pref_registry_simple.h"
14 #include "base/prefs/testing_pref_service.h" 14 #include "base/prefs/testing_pref_service.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/time/time.h"
18 #include "chrome/browser/chromeos/policy/user_cloud_policy_token_forwarder.h" 19 #include "chrome/browser/chromeos/policy/user_cloud_policy_token_forwarder.h"
19 #include "chrome/browser/chromeos/profiles/profile_helper.h" 20 #include "chrome/browser/chromeos/profiles/profile_helper.h"
20 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" 21 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
21 #include "chrome/browser/policy/cloud/cloud_policy_service.h" 22 #include "chrome/browser/policy/cloud/cloud_policy_service.h"
22 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" 23 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h"
23 #include "chrome/browser/policy/cloud/mock_device_management_service.h" 24 #include "chrome/browser/policy/cloud/mock_device_management_service.h"
24 #include "chrome/browser/policy/cloud/resource_cache.h" 25 #include "chrome/browser/policy/cloud/resource_cache.h"
25 #include "chrome/browser/policy/external_data_fetcher.h" 26 #include "chrome/browser/policy/external_data_fetcher.h"
26 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 27 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
27 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" 28 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 if (manager_) { 137 if (manager_) {
137 manager_->RemoveObserver(&observer_); 138 manager_->RemoveObserver(&observer_);
138 manager_->Shutdown(); 139 manager_->Shutdown();
139 } 140 }
140 signin_profile_ = NULL; 141 signin_profile_ = NULL;
141 profile_ = NULL; 142 profile_ = NULL;
142 profile_manager_->DeleteTestingProfile(kSigninProfile); 143 profile_manager_->DeleteTestingProfile(kSigninProfile);
143 profile_manager_->DeleteTestingProfile(chrome::kInitialProfile); 144 profile_manager_->DeleteTestingProfile(chrome::kInitialProfile);
144 } 145 }
145 146
146 void CreateManager(bool wait_for_fetch) { 147 void CreateManager(bool wait_for_fetch, int fetch_timeout) {
147 store_ = new MockCloudPolicyStore(); 148 store_ = new MockCloudPolicyStore();
148 EXPECT_CALL(*store_, Load()); 149 EXPECT_CALL(*store_, Load());
149 manager_.reset(new UserCloudPolicyManagerChromeOS( 150 manager_.reset(new UserCloudPolicyManagerChromeOS(
150 scoped_ptr<CloudPolicyStore>(store_), 151 scoped_ptr<CloudPolicyStore>(store_),
151 scoped_ptr<ResourceCache>(), 152 scoped_ptr<ResourceCache>(),
152 wait_for_fetch)); 153 wait_for_fetch,
154 base::TimeDelta::FromSeconds(fetch_timeout)));
153 manager_->Init(); 155 manager_->Init();
154 manager_->AddObserver(&observer_); 156 manager_->AddObserver(&observer_);
155 manager_->Connect(&prefs_, &device_management_service_, NULL, 157 manager_->Connect(&prefs_, &device_management_service_, NULL,
156 USER_AFFILIATION_NONE); 158 USER_AFFILIATION_NONE);
157 Mock::VerifyAndClearExpectations(store_); 159 Mock::VerifyAndClearExpectations(store_);
158 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 160 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
159 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 161 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
160 162
161 if (!wait_for_fetch) { 163 if (!wait_for_fetch) {
162 // Create the UserCloudPolicyTokenForwarder, which fetches the access 164 // Create the UserCloudPolicyTokenForwarder, which fetches the access
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 private: 301 private:
300 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerChromeOSTest); 302 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerChromeOSTest);
301 }; 303 };
302 304
303 const char UserCloudPolicyManagerChromeOSTest::kSigninProfile[] = 305 const char UserCloudPolicyManagerChromeOSTest::kSigninProfile[] =
304 "signin_profile"; 306 "signin_profile";
305 307
306 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFirstFetch) { 308 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFirstFetch) {
307 // Tests the initialization of a manager whose Profile is waiting for the 309 // Tests the initialization of a manager whose Profile is waiting for the
308 // initial fetch, when the policy cache is empty. 310 // initial fetch, when the policy cache is empty.
309 ASSERT_NO_FATAL_FAILURE(CreateManager(true)); 311 ASSERT_NO_FATAL_FAILURE(CreateManager(true, 1000));
310 312
311 // Initialize the CloudPolicyService without any stored data. 313 // Initialize the CloudPolicyService without any stored data.
312 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 314 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
313 store_->NotifyStoreLoaded(); 315 store_->NotifyStoreLoaded();
314 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 316 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
315 EXPECT_FALSE(manager_->core()->client()->is_registered()); 317 EXPECT_FALSE(manager_->core()->client()->is_registered());
316 318
317 // This starts the OAuth2 policy token fetcher using the signin Profile. 319 // This starts the OAuth2 policy token fetcher using the signin Profile.
318 // The manager will then issue the registration request. 320 // The manager will then issue the registration request.
319 MockDeviceManagementJob* register_request = IssueOAuthToken(false); 321 MockDeviceManagementJob* register_request = IssueOAuthToken(false);
320 ASSERT_TRUE(register_request); 322 ASSERT_TRUE(register_request);
321 323
322 // Reply with a valid registration response. This triggers the initial policy 324 // Reply with a valid registration response. This triggers the initial policy
323 // fetch. 325 // fetch.
324 FetchPolicy(base::Bind(&MockDeviceManagementJob::SendResponse, 326 FetchPolicy(base::Bind(&MockDeviceManagementJob::SendResponse,
325 base::Unretained(register_request), 327 base::Unretained(register_request),
326 DM_STATUS_SUCCESS, register_blob_)); 328 DM_STATUS_SUCCESS, register_blob_));
327 } 329 }
328 330
329 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingRefreshFetch) { 331 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingRefreshFetch) {
330 // Tests the initialization of a manager whose Profile is waiting for the 332 // Tests the initialization of a manager whose Profile is waiting for the
331 // initial fetch, when a previously cached policy and DMToken already exist. 333 // initial fetch, when a previously cached policy and DMToken already exist.
332 ASSERT_NO_FATAL_FAILURE(CreateManager(true)); 334 ASSERT_NO_FATAL_FAILURE(CreateManager(true, 1000));
333 335
334 // Set the initially cached data and initialize the CloudPolicyService. 336 // Set the initially cached data and initialize the CloudPolicyService.
335 // The initial policy fetch is issued using the cached DMToken. 337 // The initial policy fetch is issued using the cached DMToken.
336 store_->policy_.reset(new em::PolicyData(policy_data_)); 338 store_->policy_.reset(new em::PolicyData(policy_data_));
337 FetchPolicy(base::Bind(&MockCloudPolicyStore::NotifyStoreLoaded, 339 FetchPolicy(base::Bind(&MockCloudPolicyStore::NotifyStoreLoaded,
338 base::Unretained(store_))); 340 base::Unretained(store_)));
339 } 341 }
340 342
341 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchStoreError) { 343 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchStoreError) {
342 // Tests the initialization of a manager whose Profile is waiting for the 344 // Tests the initialization of a manager whose Profile is waiting for the
343 // initial fetch, when the initial store load fails. 345 // initial fetch, when the initial store load fails.
344 ASSERT_NO_FATAL_FAILURE(CreateManager(true)); 346 ASSERT_NO_FATAL_FAILURE(CreateManager(true, 1000));
345 347
346 // Initialize the CloudPolicyService without any stored data. 348 // Initialize the CloudPolicyService without any stored data.
347 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 349 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
348 store_->NotifyStoreError(); 350 store_->NotifyStoreError();
349 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 351 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
350 EXPECT_FALSE(manager_->core()->client()->is_registered()); 352 EXPECT_FALSE(manager_->core()->client()->is_registered());
351 353
352 // This starts the OAuth2 policy token fetcher using the signin Profile. 354 // This starts the OAuth2 policy token fetcher using the signin Profile.
353 // The manager will then issue the registration request. 355 // The manager will then issue the registration request.
354 MockDeviceManagementJob* register_request = IssueOAuthToken(false); 356 MockDeviceManagementJob* register_request = IssueOAuthToken(false);
355 ASSERT_TRUE(register_request); 357 ASSERT_TRUE(register_request);
356 358
357 // Reply with a valid registration response. This triggers the initial policy 359 // Reply with a valid registration response. This triggers the initial policy
358 // fetch. 360 // fetch.
359 FetchPolicy(base::Bind(&MockDeviceManagementJob::SendResponse, 361 FetchPolicy(base::Bind(&MockDeviceManagementJob::SendResponse,
360 base::Unretained(register_request), 362 base::Unretained(register_request),
361 DM_STATUS_SUCCESS, register_blob_)); 363 DM_STATUS_SUCCESS, register_blob_));
362 } 364 }
363 365
364 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchOAuthError) { 366 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchOAuthError) {
365 // Tests the initialization of a manager whose Profile is waiting for the 367 // Tests the initialization of a manager whose Profile is waiting for the
366 // initial fetch, when the OAuth2 token fetch fails. 368 // initial fetch, when the OAuth2 token fetch fails.
367 ASSERT_NO_FATAL_FAILURE(CreateManager(true)); 369 ASSERT_NO_FATAL_FAILURE(CreateManager(true, 1000));
368 370
369 // Initialize the CloudPolicyService without any stored data. 371 // Initialize the CloudPolicyService without any stored data.
370 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 372 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
371 store_->NotifyStoreLoaded(); 373 store_->NotifyStoreLoaded();
372 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 374 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
373 EXPECT_FALSE(manager_->core()->client()->is_registered()); 375 EXPECT_FALSE(manager_->core()->client()->is_registered());
374 376
375 // This starts the OAuth2 policy token fetcher using the signin Profile. 377 // This starts the OAuth2 policy token fetcher using the signin Profile.
376 // The manager will initialize with no policy after the token fetcher fails. 378 // The manager will initialize with no policy after the token fetcher fails.
377 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); 379 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get()));
378 380
379 // The PolicyOAuth2TokenFetcher posts delayed retries on some errors. This 381 // The PolicyOAuth2TokenFetcher posts delayed retries on some errors. This
380 // data will make it fail immediately. 382 // data will make it fail immediately.
381 net::TestURLFetcher* fetcher = PrepareOAuthFetcher( 383 net::TestURLFetcher* fetcher = PrepareOAuthFetcher(
382 GaiaUrls::GetInstance()->client_login_to_oauth2_url()); 384 GaiaUrls::GetInstance()->client_login_to_oauth2_url());
383 ASSERT_TRUE(fetcher); 385 ASSERT_TRUE(fetcher);
384 fetcher->set_response_code(400); 386 fetcher->set_response_code(400);
385 fetcher->SetResponseString("Error=BadAuthentication"); 387 fetcher->SetResponseString("Error=BadAuthentication");
386 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 388 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
387 fetcher->delegate()->OnURLFetchComplete(fetcher); 389 fetcher->delegate()->OnURLFetchComplete(fetcher);
388 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 390 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
389 EXPECT_TRUE(PolicyBundle().Equals(manager_->policies())); 391 EXPECT_TRUE(PolicyBundle().Equals(manager_->policies()));
390 Mock::VerifyAndClearExpectations(&observer_); 392 Mock::VerifyAndClearExpectations(&observer_);
391 } 393 }
392 394
393 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchRegisterError) { 395 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchRegisterError) {
394 // Tests the initialization of a manager whose Profile is waiting for the 396 // Tests the initialization of a manager whose Profile is waiting for the
395 // initial fetch, when the device management registration fails. 397 // initial fetch, when the device management registration fails.
396 ASSERT_NO_FATAL_FAILURE(CreateManager(true)); 398 ASSERT_NO_FATAL_FAILURE(CreateManager(true, 1000));
397 399
398 // Initialize the CloudPolicyService without any stored data. 400 // Initialize the CloudPolicyService without any stored data.
399 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 401 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
400 store_->NotifyStoreError(); 402 store_->NotifyStoreError();
401 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 403 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
402 EXPECT_FALSE(manager_->core()->client()->is_registered()); 404 EXPECT_FALSE(manager_->core()->client()->is_registered());
403 405
404 // This starts the OAuth2 policy token fetcher using the signin Profile. 406 // This starts the OAuth2 policy token fetcher using the signin Profile.
405 // The manager will then issue the registration request. 407 // The manager will then issue the registration request.
406 MockDeviceManagementJob* register_request = IssueOAuthToken(false); 408 MockDeviceManagementJob* register_request = IssueOAuthToken(false);
407 ASSERT_TRUE(register_request); 409 ASSERT_TRUE(register_request);
408 410
409 // Now make it fail. 411 // Now make it fail.
410 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 412 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
411 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); 413 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get()));
412 register_request->SendResponse(DM_STATUS_TEMPORARY_UNAVAILABLE, 414 register_request->SendResponse(DM_STATUS_TEMPORARY_UNAVAILABLE,
413 em::DeviceManagementResponse()); 415 em::DeviceManagementResponse());
414 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 416 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
415 EXPECT_TRUE(PolicyBundle().Equals(manager_->policies())); 417 EXPECT_TRUE(PolicyBundle().Equals(manager_->policies()));
416 Mock::VerifyAndClearExpectations(&observer_); 418 Mock::VerifyAndClearExpectations(&observer_);
417 } 419 }
418 420
419 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchPolicyFetchError) { 421 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchPolicyFetchError) {
420 // Tests the initialization of a manager whose Profile is waiting for the 422 // Tests the initialization of a manager whose Profile is waiting for the
421 // initial fetch, when the policy fetch request fails. 423 // initial fetch, when the policy fetch request fails.
422 ASSERT_NO_FATAL_FAILURE(CreateManager(true)); 424 ASSERT_NO_FATAL_FAILURE(CreateManager(true, 1000));
423 425
424 // Initialize the CloudPolicyService without any stored data. 426 // Initialize the CloudPolicyService without any stored data.
425 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 427 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
426 store_->NotifyStoreLoaded(); 428 store_->NotifyStoreLoaded();
427 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 429 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
428 EXPECT_FALSE(manager_->core()->client()->is_registered()); 430 EXPECT_FALSE(manager_->core()->client()->is_registered());
429 431
430 // This starts the OAuth2 policy token fetcher using the signin Profile. 432 // This starts the OAuth2 policy token fetcher using the signin Profile.
431 // The manager will then issue the registration request. 433 // The manager will then issue the registration request.
432 MockDeviceManagementJob* register_request = IssueOAuthToken(false); 434 MockDeviceManagementJob* register_request = IssueOAuthToken(false);
(...skipping 17 matching lines...) Expand all
450 // also correct and makes the implementation simpler. 452 // also correct and makes the implementation simpler.
451 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())).Times(AtLeast(1)); 453 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())).Times(AtLeast(1));
452 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 454 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
453 policy_request->SendResponse(DM_STATUS_TEMPORARY_UNAVAILABLE, 455 policy_request->SendResponse(DM_STATUS_TEMPORARY_UNAVAILABLE,
454 em::DeviceManagementResponse()); 456 em::DeviceManagementResponse());
455 Mock::VerifyAndClearExpectations(&observer_); 457 Mock::VerifyAndClearExpectations(&observer_);
456 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 458 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
457 EXPECT_TRUE(PolicyBundle().Equals(manager_->policies())); 459 EXPECT_TRUE(PolicyBundle().Equals(manager_->policies()));
458 } 460 }
459 461
462 TEST_F(UserCloudPolicyManagerChromeOSTest, BlockingFetchTimeout) {
463 // The blocking fetch should be abandoned after the timeout.
464 ASSERT_NO_FATAL_FAILURE(CreateManager(true, 0));
465
466 // Initialize the CloudPolicyService without any stored data.
467 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
468 store_->NotifyStoreLoaded();
469 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
470 EXPECT_FALSE(manager_->core()->client()->is_registered());
471
472 // Running the message loop should trigger the timeout.
473 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())).Times(AtLeast(1));
474 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
475 base::RunLoop().RunUntilIdle();
476 Mock::VerifyAndClearExpectations(&observer_);
477 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
478 EXPECT_TRUE(PolicyBundle().Equals(manager_->policies()));
479 }
480
481
460 TEST_F(UserCloudPolicyManagerChromeOSTest, NonBlockingFirstFetch) { 482 TEST_F(UserCloudPolicyManagerChromeOSTest, NonBlockingFirstFetch) {
461 // Tests the first policy fetch request by a Profile that isn't managed. 483 // Tests the first policy fetch request by a Profile that isn't managed.
462 ASSERT_NO_FATAL_FAILURE(CreateManager(false)); 484 ASSERT_NO_FATAL_FAILURE(CreateManager(false, 1000));
463 485
464 // Initialize the CloudPolicyService without any stored data. Since the 486 // Initialize the CloudPolicyService without any stored data. Since the
465 // manager is not waiting for the initial fetch, it will become initialized 487 // manager is not waiting for the initial fetch, it will become initialized
466 // once the store is ready. 488 // once the store is ready.
467 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 489 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
468 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 490 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
469 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); 491 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get()));
470 store_->NotifyStoreLoaded(); 492 store_->NotifyStoreLoaded();
471 Mock::VerifyAndClearExpectations(&observer_); 493 Mock::VerifyAndClearExpectations(&observer_);
472 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 494 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
(...skipping 22 matching lines...) Expand all
495 // It posts a delayed task with 0ms delay in this case, so spinning the loop 517 // It posts a delayed task with 0ms delay in this case, so spinning the loop
496 // issues the initial fetch. 518 // issues the initial fetch.
497 base::RunLoop loop; 519 base::RunLoop loop;
498 FetchPolicy( 520 FetchPolicy(
499 base::Bind(&base::RunLoop::RunUntilIdle, base::Unretained(&loop))); 521 base::Bind(&base::RunLoop::RunUntilIdle, base::Unretained(&loop)));
500 } 522 }
501 523
502 TEST_F(UserCloudPolicyManagerChromeOSTest, NonBlockingRefreshFetch) { 524 TEST_F(UserCloudPolicyManagerChromeOSTest, NonBlockingRefreshFetch) {
503 // Tests a non-blocking initial policy fetch for a Profile that already has 525 // Tests a non-blocking initial policy fetch for a Profile that already has
504 // a cached DMToken. 526 // a cached DMToken.
505 ASSERT_NO_FATAL_FAILURE(CreateManager(false)); 527 ASSERT_NO_FATAL_FAILURE(CreateManager(false, 1000));
506 528
507 // Set the initially cached data and initialize the CloudPolicyService. 529 // Set the initially cached data and initialize the CloudPolicyService.
508 // The initial policy fetch is issued using the cached DMToken. 530 // The initial policy fetch is issued using the cached DMToken.
509 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); 531 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete());
510 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 532 EXPECT_FALSE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
511 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get())); 533 EXPECT_CALL(observer_, OnUpdatePolicy(manager_.get()));
512 store_->policy_.reset(new em::PolicyData(policy_data_)); 534 store_->policy_.reset(new em::PolicyData(policy_data_));
513 store_->NotifyStoreLoaded(); 535 store_->NotifyStoreLoaded();
514 Mock::VerifyAndClearExpectations(&observer_); 536 Mock::VerifyAndClearExpectations(&observer_);
515 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete()); 537 EXPECT_TRUE(manager_->core()->service()->IsInitializationComplete());
516 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); 538 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
517 EXPECT_TRUE(manager_->core()->client()->is_registered()); 539 EXPECT_TRUE(manager_->core()->client()->is_registered());
518 540
519 // The refresh scheduler takes care of the initial fetch for unmanaged users. 541 // The refresh scheduler takes care of the initial fetch for unmanaged users.
520 // It posts a delayed task with 0ms delay in this case, so spinning the loop 542 // It posts a delayed task with 0ms delay in this case, so spinning the loop
521 // issues the initial fetch. 543 // issues the initial fetch.
522 base::RunLoop loop; 544 base::RunLoop loop;
523 FetchPolicy( 545 FetchPolicy(
524 base::Bind(&base::RunLoop::RunUntilIdle, base::Unretained(&loop))); 546 base::Bind(&base::RunLoop::RunUntilIdle, base::Unretained(&loop)));
525 } 547 }
526 548
527 } // namespace policy 549 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698