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

Side by Side Diff: chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc

Issue 49783006: policy: Remove SigninManager from UserCloudPolicyStore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 7 years, 1 month 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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "base/message_loop/message_loop_proxy.h" 6 #include "base/message_loop/message_loop_proxy.h"
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 EXPECT_TRUE(register_completed_); 249 EXPECT_TRUE(register_completed_);
250 EXPECT_TRUE(created_client_.get()); 250 EXPECT_TRUE(created_client_.get());
251 251
252 // Now call to fetch policy - this should fire off a fetch request. 252 // Now call to fetch policy - this should fire off a fetch request.
253 MockDeviceManagementJob* fetch_request = NULL; 253 MockDeviceManagementJob* fetch_request = NULL;
254 EXPECT_CALL(device_management_service_, 254 EXPECT_CALL(device_management_service_,
255 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) 255 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
256 .WillOnce(device_management_service_.CreateAsyncJob(&fetch_request)); 256 .WillOnce(device_management_service_.CreateAsyncJob(&fetch_request));
257 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _)) 257 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _))
258 .Times(1); 258 .Times(1);
259
259 signin_service->FetchPolicyForSignedInUser( 260 signin_service->FetchPolicyForSignedInUser(
261 kTestUser,
260 created_client_.Pass(), 262 created_client_.Pass(),
261 base::Bind(&UserPolicySigninServiceTest::OnPolicyRefresh, 263 base::Bind(&UserPolicySigninServiceTest::OnPolicyRefresh,
262 base::Unretained(this))); 264 base::Unretained(this)));
263 265
264 Mock::VerifyAndClearExpectations(this); 266 Mock::VerifyAndClearExpectations(this);
265 ASSERT_TRUE(fetch_request); 267 ASSERT_TRUE(fetch_request);
266 268
267 // UserCloudPolicyManager should now be initialized. 269 // UserCloudPolicyManager should now be initialized.
270 EXPECT_EQ(mock_store_->signin_username_, kTestUser);
268 ASSERT_TRUE(manager_->core()->service()); 271 ASSERT_TRUE(manager_->core()->service());
269 272
270 // Make the policy fetch succeed - this should result in a write to the 273 // Make the policy fetch succeed - this should result in a write to the
271 // store and ultimately result in a call to OnPolicyRefresh(). 274 // store and ultimately result in a call to OnPolicyRefresh().
272 EXPECT_CALL(*mock_store_, Store(_)); 275 EXPECT_CALL(*mock_store_, Store(_));
273 EXPECT_CALL(*this, OnPolicyRefresh(true)).Times(1); 276 EXPECT_CALL(*this, OnPolicyRefresh(true)).Times(1);
274 277
275 // Create a fake policy blob to deliver to the client. 278 // Create a fake policy blob to deliver to the client.
276 em::DeviceManagementResponse policy_blob; 279 em::DeviceManagementResponse policy_blob;
277 em::PolicyData policy_data; 280 em::PolicyData policy_data;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 // Complete initialization of the store. 355 // Complete initialization of the store.
353 mock_store_->NotifyStoreLoaded(); 356 mock_store_->NotifyStoreLoaded();
354 357
355 // No oauth access token yet, so client registration should be deferred. 358 // No oauth access token yet, so client registration should be deferred.
356 ASSERT_FALSE(IsRequestActive()); 359 ASSERT_FALSE(IsRequestActive());
357 360
358 // Make oauth token available. 361 // Make oauth token available.
359 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token"); 362 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token");
360 363
361 // Client registration should be in progress since we now have an oauth token. 364 // Client registration should be in progress since we now have an oauth token.
365 EXPECT_EQ(mock_store_->signin_username_, kTestUser);
362 ASSERT_TRUE(IsRequestActive()); 366 ASSERT_TRUE(IsRequestActive());
363 } 367 }
364 368
365 TEST_F(UserPolicySigninServiceTest, InitWhileSignedInOAuthError) { 369 TEST_F(UserPolicySigninServiceTest, InitWhileSignedInOAuthError) {
366 // Set the user as signed in. 370 // Set the user as signed in.
367 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( 371 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername(
368 kTestUser); 372 kTestUser);
369 373
370 // Let the SigninService know that the profile has been created. 374 // Let the SigninService know that the profile has been created.
371 content::NotificationService::current()->Notify( 375 content::NotificationService::current()->Notify(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( 415 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername(
412 kTestUser); 416 kTestUser);
413 417
414 // Complete initialization of the store. 418 // Complete initialization of the store.
415 mock_store_->NotifyStoreLoaded(); 419 mock_store_->NotifyStoreLoaded();
416 420
417 // Make oauth token available. 421 // Make oauth token available.
418 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token"); 422 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token");
419 423
420 // UserCloudPolicyManager should be initialized. 424 // UserCloudPolicyManager should be initialized.
425 EXPECT_EQ(mock_store_->signin_username_, kTestUser);
421 ASSERT_TRUE(manager_->core()->service()); 426 ASSERT_TRUE(manager_->core()->service());
422 427
423 // Client registration should be in progress since we have an oauth token. 428 // Client registration should be in progress since we have an oauth token.
424 ASSERT_TRUE(IsRequestActive()); 429 ASSERT_TRUE(IsRequestActive());
425 } 430 }
426 431
427 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) { 432 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) {
428 EXPECT_CALL(*mock_store_, Clear()); 433 EXPECT_CALL(*mock_store_, Clear());
429 // Let the SigninService know that the profile has been created. 434 // Let the SigninService know that the profile has been created.
430 content::NotificationService::current()->Notify( 435 content::NotificationService::current()->Notify(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 ASSERT_FALSE(manager_->core()->service()); 470 ASSERT_FALSE(manager_->core()->service());
466 471
467 // Now sign in the user. 472 // Now sign in the user.
468 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( 473 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername(
469 kTestUser); 474 kTestUser);
470 475
471 // Make oauth token available. 476 // Make oauth token available.
472 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token"); 477 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token");
473 478
474 // UserCloudPolicyManager should be initialized. 479 // UserCloudPolicyManager should be initialized.
480 EXPECT_EQ(mock_store_->signin_username_, kTestUser);
475 ASSERT_TRUE(manager_->core()->service()); 481 ASSERT_TRUE(manager_->core()->service());
476 482
477 // Client registration should not be in progress since the store is not 483 // Client registration should not be in progress since the store is not
478 // yet initialized. 484 // yet initialized.
479 ASSERT_FALSE(IsRequestActive()); 485 ASSERT_FALSE(IsRequestActive());
480 486
481 // Complete initialization of the store with no policy (unregistered client). 487 // Complete initialization of the store with no policy (unregistered client).
482 mock_store_->NotifyStoreLoaded(); 488 mock_store_->NotifyStoreLoaded();
483 489
484 // Client registration should be in progress since we have an oauth token. 490 // Client registration should be in progress since we have an oauth token.
(...skipping 13 matching lines...) Expand all
498 ASSERT_FALSE(manager_->core()->service()); 504 ASSERT_FALSE(manager_->core()->service());
499 505
500 // Now sign in the user. 506 // Now sign in the user.
501 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( 507 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername(
502 kTestUser); 508 kTestUser);
503 509
504 // Make oauth token available. 510 // Make oauth token available.
505 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token"); 511 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token");
506 512
507 // UserCloudPolicyManager should be initialized. 513 // UserCloudPolicyManager should be initialized.
514 EXPECT_EQ(mock_store_->signin_username_, kTestUser);
508 ASSERT_TRUE(manager_->core()->service()); 515 ASSERT_TRUE(manager_->core()->service());
509 516
510 // Client registration should not be in progress since the store is not 517 // Client registration should not be in progress since the store is not
511 // yet initialized. 518 // yet initialized.
512 ASSERT_FALSE(manager_->IsClientRegistered()); 519 ASSERT_FALSE(manager_->IsClientRegistered());
513 ASSERT_FALSE(IsRequestActive()); 520 ASSERT_FALSE(IsRequestActive());
514 521
515 mock_store_->policy_.reset(new enterprise_management::PolicyData()); 522 mock_store_->policy_.reset(new enterprise_management::PolicyData());
516 mock_store_->policy_->set_request_token("fake token"); 523 mock_store_->policy_->set_request_token("fake token");
517 mock_store_->policy_->set_device_id("fake client id"); 524 mock_store_->policy_->set_device_id("fake client id");
518 525
519 // Complete initialization of the store. 526 // Complete initialization of the store.
520 mock_store_->NotifyStoreLoaded(); 527 mock_store_->NotifyStoreLoaded();
521 528
522 // Client registration should not be in progress since the client should be 529 // Client registration should not be in progress since the client should be
523 // already registered. 530 // already registered.
524 ASSERT_TRUE(manager_->IsClientRegistered()); 531 ASSERT_TRUE(manager_->IsClientRegistered());
525 ASSERT_FALSE(IsRequestActive()); 532 ASSERT_FALSE(IsRequestActive());
526 } 533 }
527 534
528 #endif // !defined(OS_ANDROID) 535 #endif // !defined(OS_ANDROID)
529 536
530 TEST_F(UserPolicySigninServiceTest, SignOutAfterInit) { 537 TEST_F(UserPolicySigninServiceTest, SignOutAfterInit) {
531 EXPECT_CALL(*mock_store_, Clear()); 538 EXPECT_CALL(*mock_store_, Clear());
539
532 // Set the user as signed in. 540 // Set the user as signed in.
533 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( 541 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername(
534 kTestUser); 542 kTestUser);
535 543
536 // Let the SigninService know that the profile has been created. 544 // Let the SigninService know that the profile has been created.
537 content::NotificationService::current()->Notify( 545 content::NotificationService::current()->Notify(
538 chrome::NOTIFICATION_PROFILE_ADDED, 546 chrome::NOTIFICATION_PROFILE_ADDED,
539 content::Source<Profile>(profile_.get()), 547 content::Source<Profile>(profile_.get()),
540 content::NotificationService::NoDetails()); 548 content::NotificationService::NoDetails());
541 549
542 // UserCloudPolicyManager should be initialized. 550 // UserCloudPolicyManager should be initialized.
551 EXPECT_EQ(mock_store_->signin_username_, kTestUser);
543 ASSERT_TRUE(manager_->core()->service()); 552 ASSERT_TRUE(manager_->core()->service());
544 553
545 // Now sign out. 554 // Now sign out.
546 SigninManagerFactory::GetForProfile(profile_.get())->SignOut(); 555 SigninManagerFactory::GetForProfile(profile_.get())->SignOut();
547 556
548 // UserCloudPolicyManager should be shut down. 557 // UserCloudPolicyManager should be shut down.
549 ASSERT_FALSE(manager_->core()->service()); 558 ASSERT_FALSE(manager_->core()->service());
550 } 559 }
551 560
552 TEST_F(UserPolicySigninServiceTest, RegisterPolicyClientOAuthFailure) { 561 TEST_F(UserPolicySigninServiceTest, RegisterPolicyClientOAuthFailure) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 // Initiate a policy fetch request. 702 // Initiate a policy fetch request.
694 MockDeviceManagementJob* fetch_request = NULL; 703 MockDeviceManagementJob* fetch_request = NULL;
695 EXPECT_CALL(device_management_service_, 704 EXPECT_CALL(device_management_service_,
696 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) 705 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
697 .WillOnce(device_management_service_.CreateAsyncJob(&fetch_request)); 706 .WillOnce(device_management_service_.CreateAsyncJob(&fetch_request));
698 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _)) 707 EXPECT_CALL(device_management_service_, StartJob(_, _, _, _, _, _, _))
699 .Times(1); 708 .Times(1);
700 UserPolicySigninService* signin_service = 709 UserPolicySigninService* signin_service =
701 UserPolicySigninServiceFactory::GetForProfile(profile_.get()); 710 UserPolicySigninServiceFactory::GetForProfile(profile_.get());
702 signin_service->FetchPolicyForSignedInUser( 711 signin_service->FetchPolicyForSignedInUser(
712 kTestUser,
703 client.Pass(), 713 client.Pass(),
704 base::Bind(&UserPolicySigninServiceTest::OnPolicyRefresh, 714 base::Bind(&UserPolicySigninServiceTest::OnPolicyRefresh,
705 base::Unretained(this))); 715 base::Unretained(this)));
706 ASSERT_TRUE(fetch_request); 716 ASSERT_TRUE(fetch_request);
707 717
708 // Make the policy fetch fail. 718 // Make the policy fetch fail.
709 EXPECT_CALL(*this, OnPolicyRefresh(false)).Times(1); 719 EXPECT_CALL(*this, OnPolicyRefresh(false)).Times(1);
710 fetch_request->SendResponse(DM_STATUS_REQUEST_FAILED, 720 fetch_request->SendResponse(DM_STATUS_REQUEST_FAILED,
711 em::DeviceManagementResponse()); 721 em::DeviceManagementResponse());
722
712 // UserCloudPolicyManager should be initialized. 723 // UserCloudPolicyManager should be initialized.
724 EXPECT_EQ(mock_store_->signin_username_, kTestUser);
713 ASSERT_TRUE(manager_->core()->service()); 725 ASSERT_TRUE(manager_->core()->service());
714 } 726 }
715 727
716 TEST_F(UserPolicySigninServiceTest, FetchPolicySuccess) { 728 TEST_F(UserPolicySigninServiceTest, FetchPolicySuccess) {
717 ASSERT_NO_FATAL_FAILURE(TestSuccessfulSignin()); 729 ASSERT_NO_FATAL_FAILURE(TestSuccessfulSignin());
718 } 730 }
719 731
720 TEST_F(UserPolicySigninServiceTest, SignOutThenSignInAgain) { 732 TEST_F(UserPolicySigninServiceTest, SignOutThenSignInAgain) {
721 ASSERT_NO_FATAL_FAILURE(TestSuccessfulSignin()); 733 ASSERT_NO_FATAL_FAILURE(TestSuccessfulSignin());
722 734
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 base::RunLoop().RunUntilIdle(); 790 base::RunLoop().RunUntilIdle();
779 EXPECT_FALSE(manager_->IsClientRegistered()); 791 EXPECT_FALSE(manager_->IsClientRegistered());
780 #if !defined(OS_ANDROID) 792 #if !defined(OS_ANDROID)
781 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); 793 EXPECT_FALSE(signin_manager_->IsSignoutProhibited());
782 #endif 794 #endif
783 } 795 }
784 796
785 } // namespace 797 } // namespace
786 798
787 } // namespace policy 799 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698