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

Side by Side Diff: components/signin/core/browser/account_tracker_service_unittest.cc

Issue 1380103004: Delay fetching account info until OnRefreshTokensLoaded(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unregister Invalidation service correctly. Created 5 years, 2 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/prefs/pref_registry_simple.h" 8 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/scoped_user_pref_update.h" 9 #include "base/prefs/scoped_user_pref_update.h"
10 #include "base/prefs/testing_pref_service.h" 10 #include "base/prefs/testing_pref_service.h"
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 signin_client_.reset(new TestSigninClient(&pref_service_)); 264 signin_client_.reset(new TestSigninClient(&pref_service_));
265 signin_client_.get()->SetURLRequestContext( 265 signin_client_.get()->SetURLRequestContext(
266 new net::TestURLRequestContextGetter(message_loop_.task_runner())); 266 new net::TestURLRequestContextGetter(message_loop_.task_runner()));
267 267
268 account_tracker_.reset(new AccountTrackerService()); 268 account_tracker_.reset(new AccountTrackerService());
269 account_tracker_->Initialize(signin_client_.get()); 269 account_tracker_->Initialize(signin_client_.get());
270 270
271 account_fetcher_.reset(new AccountFetcherService()); 271 account_fetcher_.reset(new AccountFetcherService());
272 account_fetcher_->Initialize(signin_client_.get(), 272 account_fetcher_->Initialize(signin_client_.get(),
273 fake_oauth2_token_service_.get(), 273 fake_oauth2_token_service_.get(),
274 account_tracker_.get(), nullptr); 274 account_tracker_.get());
275 275
276 account_fetcher_->EnableNetworkFetches(); 276 account_fetcher_->OnRefreshTokensLoaded();
277 } 277 }
278 278
279 void TearDown() override { 279 void TearDown() override {
280 account_fetcher_->Shutdown(); 280 account_fetcher_->Shutdown();
281 account_tracker_->Shutdown(); 281 account_tracker_->Shutdown();
282 } 282 }
283 283
284 void SimulateTokenAvailable(const std::string& account_id) { 284 void SimulateTokenAvailable(const std::string& account_id) {
285 fake_oauth2_token_service_->AddAccount(account_id); 285 fake_oauth2_token_service_->AddAccount(account_id);
286 } 286 }
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 446
447 TEST_F(AccountTrackerServiceTest, TokenAlreadyExists) { 447 TEST_F(AccountTrackerServiceTest, TokenAlreadyExists) {
448 SimulateTokenAvailable("alpha"); 448 SimulateTokenAvailable("alpha");
449 AccountTrackerService tracker; 449 AccountTrackerService tracker;
450 AccountTrackerObserver observer; 450 AccountTrackerObserver observer;
451 AccountFetcherService fetcher; 451 AccountFetcherService fetcher;
452 452
453 tracker.AddObserver(&observer); 453 tracker.AddObserver(&observer);
454 tracker.Initialize(signin_client()); 454 tracker.Initialize(signin_client());
455 455
456 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 456 fetcher.Initialize(signin_client(), token_service(), &tracker);
457 fetcher.EnableNetworkFetches(); 457 fetcher.OnRefreshTokensLoaded();
458 ASSERT_FALSE(fetcher.IsAllUserInfoFetched()); 458 ASSERT_FALSE(fetcher.IsAllUserInfoFetched());
459 ASSERT_TRUE(observer.CheckEvents()); 459 ASSERT_TRUE(observer.CheckEvents());
460 tracker.RemoveObserver(&observer); 460 tracker.RemoveObserver(&observer);
461 tracker.Shutdown(); 461 tracker.Shutdown();
462 fetcher.Shutdown(); 462 fetcher.Shutdown();
463 } 463 }
464 464
465 TEST_F(AccountTrackerServiceTest, TwoTokenAvailable_TwoUserInfo) { 465 TEST_F(AccountTrackerServiceTest, TwoTokenAvailable_TwoUserInfo) {
466 AccountTrackerObserver observer; 466 AccountTrackerObserver observer;
467 account_tracker()->AddObserver(&observer); 467 account_tracker()->AddObserver(&observer);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 TEST_F(AccountTrackerServiceTest, GetAccountInfo_TokenAvailable_EnableNetwork) { 528 TEST_F(AccountTrackerServiceTest, GetAccountInfo_TokenAvailable_EnableNetwork) {
529 // Shutdown the network-enabled tracker built into the test case. 529 // Shutdown the network-enabled tracker built into the test case.
530 TearDown(); 530 TearDown();
531 531
532 // Create an account tracker and an account fetcher service but do not enable 532 // Create an account tracker and an account fetcher service but do not enable
533 // network fetches. 533 // network fetches.
534 AccountTrackerService tracker; 534 AccountTrackerService tracker;
535 tracker.Initialize(signin_client()); 535 tracker.Initialize(signin_client());
536 536
537 AccountFetcherService fetcher_service; 537 AccountFetcherService fetcher_service;
538 fetcher_service.Initialize(signin_client(), token_service(), &tracker, 538 fetcher_service.Initialize(signin_client(), token_service(), &tracker);
539 nullptr);
540 539
541 SimulateTokenAvailable("alpha"); 540 SimulateTokenAvailable("alpha");
542 IssueAccessToken("alpha"); 541 IssueAccessToken("alpha");
543 // No fetcher has been created yet. 542 // No fetcher has been created yet.
544 net::TestURLFetcher* fetcher = test_fetcher_factory()->GetFetcherByID( 543 net::TestURLFetcher* fetcher = test_fetcher_factory()->GetFetcherByID(
545 gaia::GaiaOAuthClient::kUrlFetcherId); 544 gaia::GaiaOAuthClient::kUrlFetcherId);
546 ASSERT_FALSE(fetcher); 545 ASSERT_FALSE(fetcher);
547 546
548 // Enable the network to create the fetcher then issue the access token. 547 // Enable the network fetches and refresh invalid accounts information.
549 fetcher_service.EnableNetworkFetches(); 548 fetcher_service.OnRefreshTokensLoaded();
550 549
551 // Fetcher was created and executes properly. 550 // Fetcher was created and executes properly.
552 ReturnOAuthUrlFetchSuccess("alpha"); 551 ReturnOAuthUrlFetchSuccess("alpha");
553 552
554 AccountInfo info = tracker.GetAccountInfo("alpha"); 553 AccountInfo info = tracker.GetAccountInfo("alpha");
555 CheckAccountDetails("alpha", info); 554 CheckAccountDetails("alpha", info);
556 fetcher_service.Shutdown(); 555 fetcher_service.Shutdown();
557 tracker.Shutdown(); 556 tracker.Shutdown();
558 } 557 }
559 558
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, "alpha"), 615 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, "alpha"),
617 TrackingEvent(UPDATED, "beta"))); 616 TrackingEvent(UPDATED, "beta")));
618 tracker.RemoveObserver(&observer); 617 tracker.RemoveObserver(&observer);
619 618
620 std::vector<AccountInfo> infos = tracker.GetAccounts(); 619 std::vector<AccountInfo> infos = tracker.GetAccounts();
621 ASSERT_EQ(2u, infos.size()); 620 ASSERT_EQ(2u, infos.size());
622 CheckAccountDetails("alpha", infos[0]); 621 CheckAccountDetails("alpha", infos[0]);
623 CheckAccountDetails("beta", infos[1]); 622 CheckAccountDetails("beta", infos[1]);
624 623
625 FakeAccountFetcherService fetcher; 624 FakeAccountFetcherService fetcher;
626 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 625 fetcher.Initialize(signin_client(), token_service(), &tracker);
627 fetcher.EnableNetworkFetches(); 626 fetcher.OnRefreshTokensLoaded();
628 // Remove an account. 627 // Remove an account.
629 // This will allow testing removal as well as child accounts which is only 628 // This will allow testing removal as well as child accounts which is only
630 // allowed for a single account. 629 // allowed for a single account.
631 SimulateTokenRevoked("alpha"); 630 SimulateTokenRevoked("alpha");
632 fetcher.FakeSetIsChildAccount("beta", true); 631 fetcher.FakeSetIsChildAccount("beta", true);
633 632
634 fetcher.Shutdown(); 633 fetcher.Shutdown();
635 tracker.Shutdown(); 634 tracker.Shutdown();
636 } 635 }
637 636
(...skipping 28 matching lines...) Expand all
666 EXPECT_EQ(email, infos[0].email); 665 EXPECT_EQ(email, infos[0].email);
667 } 666 }
668 667
669 TEST_F(AccountTrackerServiceTest, UpgradeToFullAccountInfo) { 668 TEST_F(AccountTrackerServiceTest, UpgradeToFullAccountInfo) {
670 // Start by simulating an incomplete account info and let it be saved to 669 // Start by simulating an incomplete account info and let it be saved to
671 // prefs. 670 // prefs.
672 { 671 {
673 AccountTrackerService tracker; 672 AccountTrackerService tracker;
674 tracker.Initialize(signin_client()); 673 tracker.Initialize(signin_client());
675 AccountFetcherService fetcher; 674 AccountFetcherService fetcher;
676 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 675 fetcher.Initialize(signin_client(), token_service(), &tracker);
677 fetcher.EnableNetworkFetches(); 676 fetcher.OnRefreshTokensLoaded();
678 SimulateTokenAvailable("incomplete"); 677 SimulateTokenAvailable("incomplete");
679 ReturnOAuthUrlFetchSuccessIncomplete("incomplete"); 678 ReturnOAuthUrlFetchSuccessIncomplete("incomplete");
680 tracker.Shutdown(); 679 tracker.Shutdown();
681 fetcher.Shutdown(); 680 fetcher.Shutdown();
682 } 681 }
683 682
684 { 683 {
685 AccountTrackerService tracker; 684 AccountTrackerService tracker;
686 tracker.Initialize(signin_client()); 685 tracker.Initialize(signin_client());
687 AccountFetcherService fetcher; 686 AccountFetcherService fetcher;
688 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 687 fetcher.Initialize(signin_client(), token_service(), &tracker);
689 // Validate that the loaded AccountInfo from prefs is considered invalid. 688 // Validate that the loaded AccountInfo from prefs is considered invalid.
690 std::vector<AccountInfo> infos = tracker.GetAccounts(); 689 std::vector<AccountInfo> infos = tracker.GetAccounts();
691 ASSERT_EQ(1u, infos.size()); 690 ASSERT_EQ(1u, infos.size());
692 ASSERT_FALSE(infos[0].IsValid()); 691 ASSERT_FALSE(infos[0].IsValid());
693 692
694 // Enable network fetches and simulate the same account getting a refresh 693 // Enable network fetches and simulate the same account getting a refresh
695 // token containing all the info. 694 // token containing all the info.
696 fetcher.EnableNetworkFetches(); 695 fetcher.OnRefreshTokensLoaded();
697 SimulateTokenAvailable("incomplete"); 696 SimulateTokenAvailable("incomplete");
698 ReturnOAuthUrlFetchSuccess("incomplete"); 697 ReturnOAuthUrlFetchSuccess("incomplete");
699 698
700 // Validate that the account is now considered valid. 699 // Validate that the account is now considered valid.
701 infos = tracker.GetAccounts(); 700 infos = tracker.GetAccounts();
702 ASSERT_EQ(1u, infos.size()); 701 ASSERT_EQ(1u, infos.size());
703 ASSERT_TRUE(infos[0].IsValid()); 702 ASSERT_TRUE(infos[0].IsValid());
704 703
705 tracker.Shutdown(); 704 tracker.Shutdown();
706 fetcher.Shutdown(); 705 fetcher.Shutdown();
707 } 706 }
708 707
709 // Reinstantiate a tracker to validate that the AccountInfo saved to prefs is 708 // Reinstantiate a tracker to validate that the AccountInfo saved to prefs is
710 // now the upgraded one, considered valid. 709 // now the upgraded one, considered valid.
711 { 710 {
712 AccountTrackerService tracker; 711 AccountTrackerService tracker;
713 AccountTrackerObserver observer; 712 AccountTrackerObserver observer;
714 tracker.AddObserver(&observer); 713 tracker.AddObserver(&observer);
715 tracker.Initialize(signin_client()); 714 tracker.Initialize(signin_client());
716 AccountFetcherService fetcher; 715 AccountFetcherService fetcher;
717 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 716 fetcher.Initialize(signin_client(), token_service(), &tracker);
718 717
719 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, "incomplete"))); 718 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, "incomplete")));
720 // Enabling network fetches shouldn't cause any actual fetch since the 719 // Enabling network fetches shouldn't cause any actual fetch since the
721 // AccountInfos loaded from prefs should be valid. 720 // AccountInfos loaded from prefs should be valid.
722 fetcher.EnableNetworkFetches(); 721 fetcher.OnRefreshTokensLoaded();
723 722
724 std::vector<AccountInfo> infos = tracker.GetAccounts(); 723 std::vector<AccountInfo> infos = tracker.GetAccounts();
725 ASSERT_EQ(1u, infos.size()); 724 ASSERT_EQ(1u, infos.size());
726 ASSERT_TRUE(infos[0].IsValid()); 725 ASSERT_TRUE(infos[0].IsValid());
727 // Check that no network fetches were made. 726 // Check that no network fetches were made.
728 ASSERT_TRUE(observer.CheckEvents()); 727 ASSERT_TRUE(observer.CheckEvents());
729 728
730 tracker.RemoveObserver(&observer); 729 tracker.RemoveObserver(&observer);
731 tracker.Shutdown(); 730 tracker.Shutdown();
732 fetcher.Shutdown(); 731 fetcher.Shutdown();
733 } 732 }
734 } 733 }
735 734
736 TEST_F(AccountTrackerServiceTest, TimerRefresh) { 735 TEST_F(AccountTrackerServiceTest, TimerRefresh) {
737 // Start by creating a tracker and adding a couple accounts to be persisted to 736 // Start by creating a tracker and adding a couple accounts to be persisted to
738 // prefs. 737 // prefs.
739 { 738 {
740 AccountTrackerService tracker; 739 AccountTrackerService tracker;
741 tracker.Initialize(signin_client()); 740 tracker.Initialize(signin_client());
742 AccountFetcherService fetcher; 741 AccountFetcherService fetcher;
743 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 742 fetcher.Initialize(signin_client(), token_service(), &tracker);
744 fetcher.EnableNetworkFetches(); 743 fetcher.OnRefreshTokensLoaded();
745 SimulateTokenAvailable("alpha"); 744 SimulateTokenAvailable("alpha");
746 ReturnOAuthUrlFetchSuccess("alpha"); 745 ReturnOAuthUrlFetchSuccess("alpha");
747 SimulateTokenAvailable("beta"); 746 SimulateTokenAvailable("beta");
748 ReturnOAuthUrlFetchSuccess("beta"); 747 ReturnOAuthUrlFetchSuccess("beta");
749 tracker.Shutdown(); 748 tracker.Shutdown();
750 fetcher.Shutdown(); 749 fetcher.Shutdown();
751 } 750 }
752 751
753 // Rewind the time by half a day, which shouldn't be enough to trigger a 752 // Rewind the time by half a day, which shouldn't be enough to trigger a
754 // network refresh. 753 // network refresh.
755 base::Time fake_update = base::Time::Now() - base::TimeDelta::FromHours(12); 754 base::Time fake_update = base::Time::Now() - base::TimeDelta::FromHours(12);
756 signin_client()->GetPrefs()->SetInt64( 755 signin_client()->GetPrefs()->SetInt64(
757 AccountFetcherService::kLastUpdatePref, 756 AccountFetcherService::kLastUpdatePref,
758 fake_update.ToInternalValue()); 757 fake_update.ToInternalValue());
759 758
760 // Instantiate a new ATS, making sure the persisted accounts are still there 759 // Instantiate a new ATS, making sure the persisted accounts are still there
761 // and that no network fetches happen. 760 // and that no network fetches happen.
762 { 761 {
763 AccountTrackerService tracker; 762 AccountTrackerService tracker;
764 tracker.Initialize(signin_client()); 763 tracker.Initialize(signin_client());
765 AccountFetcherService fetcher; 764 AccountFetcherService fetcher;
766 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 765 fetcher.Initialize(signin_client(), token_service(), &tracker);
767 766
768 ASSERT_TRUE(fetcher.IsAllUserInfoFetched()); 767 ASSERT_TRUE(fetcher.IsAllUserInfoFetched());
769 std::vector<AccountInfo> infos = tracker.GetAccounts(); 768 std::vector<AccountInfo> infos = tracker.GetAccounts();
770 ASSERT_EQ(2u, infos.size()); 769 ASSERT_EQ(2u, infos.size());
771 ASSERT_TRUE(infos[0].IsValid()); 770 ASSERT_TRUE(infos[0].IsValid());
772 ASSERT_TRUE(infos[1].IsValid()); 771 ASSERT_TRUE(infos[1].IsValid());
773 772
774 fetcher.EnableNetworkFetches(); 773 fetcher.OnRefreshTokensLoaded();
775 ASSERT_TRUE(fetcher.IsAllUserInfoFetched()); 774 ASSERT_TRUE(fetcher.IsAllUserInfoFetched());
776 tracker.Shutdown(); 775 tracker.Shutdown();
777 fetcher.Shutdown(); 776 fetcher.Shutdown();
778 } 777 }
779 778
780 // Rewind the last updated time enough to trigger a network refresh. 779 // Rewind the last updated time enough to trigger a network refresh.
781 fake_update = base::Time::Now() - base::TimeDelta::FromHours(25); 780 fake_update = base::Time::Now() - base::TimeDelta::FromHours(25);
782 signin_client()->GetPrefs()->SetInt64( 781 signin_client()->GetPrefs()->SetInt64(
783 AccountFetcherService::kLastUpdatePref, 782 AccountFetcherService::kLastUpdatePref,
784 fake_update.ToInternalValue()); 783 fake_update.ToInternalValue());
785 784
786 // Instantiate a new tracker and validate that even though the AccountInfos 785 // Instantiate a new tracker and validate that even though the AccountInfos
787 // are still valid, the network fetches are started. 786 // are still valid, the network fetches are started.
788 { 787 {
789 AccountTrackerService tracker; 788 AccountTrackerService tracker;
790 tracker.Initialize(signin_client()); 789 tracker.Initialize(signin_client());
791 AccountFetcherService fetcher; 790 AccountFetcherService fetcher;
792 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 791 fetcher.Initialize(signin_client(), token_service(), &tracker);
793 792
794 ASSERT_TRUE(fetcher.IsAllUserInfoFetched()); 793 ASSERT_TRUE(fetcher.IsAllUserInfoFetched());
795 std::vector<AccountInfo> infos = tracker.GetAccounts(); 794 std::vector<AccountInfo> infos = tracker.GetAccounts();
796 ASSERT_EQ(2u, infos.size()); 795 ASSERT_EQ(2u, infos.size());
797 ASSERT_TRUE(infos[0].IsValid()); 796 ASSERT_TRUE(infos[0].IsValid());
798 ASSERT_TRUE(infos[1].IsValid()); 797 ASSERT_TRUE(infos[1].IsValid());
799 798
800 fetcher.EnableNetworkFetches(); 799 fetcher.OnRefreshTokensLoaded();
801 ASSERT_FALSE(fetcher.IsAllUserInfoFetched()); 800 ASSERT_FALSE(fetcher.IsAllUserInfoFetched());
802 tracker.Shutdown(); 801 tracker.Shutdown();
803 fetcher.Shutdown(); 802 fetcher.Shutdown();
804 } 803 }
805 } 804 }
806 805
807 TEST_F(AccountTrackerServiceTest, LegacyDottedAccountIds) { 806 TEST_F(AccountTrackerServiceTest, LegacyDottedAccountIds) {
808 // Start by creating a tracker and adding an account with a dotted account id 807 // Start by creating a tracker and adding an account with a dotted account id
809 // because of an old bug in token service. The token service would also add 808 // because of an old bug in token service. The token service would also add
810 // a correct non-dotted account id for the same account. 809 // a correct non-dotted account id for the same account.
811 { 810 {
812 AccountTrackerService tracker; 811 AccountTrackerService tracker;
813 tracker.Initialize(signin_client()); 812 tracker.Initialize(signin_client());
814 AccountFetcherService fetcher; 813 AccountFetcherService fetcher;
815 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 814 fetcher.Initialize(signin_client(), token_service(), &tracker);
816 fetcher.EnableNetworkFetches(); 815 fetcher.OnRefreshTokensLoaded();
817 SimulateTokenAvailable("foo.bar@gmail.com"); 816 SimulateTokenAvailable("foo.bar@gmail.com");
818 SimulateTokenAvailable("foobar@gmail.com"); 817 SimulateTokenAvailable("foobar@gmail.com");
819 ReturnOAuthUrlFetchSuccess("foo.bar@gmail.com"); 818 ReturnOAuthUrlFetchSuccess("foo.bar@gmail.com");
820 ReturnOAuthUrlFetchSuccess("foobar@gmail.com"); 819 ReturnOAuthUrlFetchSuccess("foobar@gmail.com");
821 tracker.Shutdown(); 820 tracker.Shutdown();
822 fetcher.Shutdown(); 821 fetcher.Shutdown();
823 } 822 }
824 823
825 // Remove the bad account now from the token service to simulate that it 824 // Remove the bad account now from the token service to simulate that it
826 // has been "fixed". 825 // has been "fixed".
827 SimulateTokenRevoked("foo.bar@gmail.com"); 826 SimulateTokenRevoked("foo.bar@gmail.com");
828 827
829 // Instantiate a new tracker and validate that it has only one account, and 828 // Instantiate a new tracker and validate that it has only one account, and
830 // it is the correct non dotted one. 829 // it is the correct non dotted one.
831 { 830 {
832 AccountTrackerService tracker; 831 AccountTrackerService tracker;
833 tracker.Initialize(signin_client()); 832 tracker.Initialize(signin_client());
834 AccountFetcherService fetcher; 833 AccountFetcherService fetcher;
835 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 834 fetcher.Initialize(signin_client(), token_service(), &tracker);
836 835
837 ASSERT_TRUE(fetcher.IsAllUserInfoFetched()); 836 ASSERT_TRUE(fetcher.IsAllUserInfoFetched());
838 std::vector<AccountInfo> infos = tracker.GetAccounts(); 837 std::vector<AccountInfo> infos = tracker.GetAccounts();
839 ASSERT_EQ(1u, infos.size()); 838 ASSERT_EQ(1u, infos.size());
840 ASSERT_STREQ("foobar@gmail.com", infos[0].account_id.c_str()); 839 ASSERT_STREQ("foobar@gmail.com", infos[0].account_id.c_str());
841 tracker.Shutdown(); 840 tracker.Shutdown();
842 fetcher.Shutdown(); 841 fetcher.Shutdown();
843 } 842 }
844 } 843 }
845 844
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 accounts.clear(); 1024 accounts.clear();
1026 accounts = tracker.GetAccounts(); 1025 accounts = tracker.GetAccounts();
1027 ASSERT_EQ(2u, accounts.size()); 1026 ASSERT_EQ(2u, accounts.size());
1028 } 1027 }
1029 } 1028 }
1030 1029
1031 TEST_F(AccountTrackerServiceTest, ChildAccountBasic) { 1030 TEST_F(AccountTrackerServiceTest, ChildAccountBasic) {
1032 AccountTrackerService tracker; 1031 AccountTrackerService tracker;
1033 tracker.Initialize(signin_client()); 1032 tracker.Initialize(signin_client());
1034 FakeAccountFetcherService fetcher; 1033 FakeAccountFetcherService fetcher;
1035 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 1034 fetcher.Initialize(signin_client(), token_service(), &tracker);
1036 fetcher.EnableNetworkFetches(); 1035 fetcher.OnRefreshTokensLoaded();
1037 AccountTrackerObserver observer; 1036 AccountTrackerObserver observer;
1038 tracker.AddObserver(&observer); 1037 tracker.AddObserver(&observer);
1039 std::string child_id("child"); 1038 std::string child_id("child");
1040 { 1039 {
1041 // Responses are processed iff there is a single account with a valid token 1040 // Responses are processed iff there is a single account with a valid token
1042 // and the response is for that account. 1041 // and the response is for that account.
1043 fetcher.FakeSetIsChildAccount(child_id, true); 1042 fetcher.FakeSetIsChildAccount(child_id, true);
1044 ASSERT_TRUE(observer.CheckEvents()); 1043 ASSERT_TRUE(observer.CheckEvents());
1045 } 1044 }
1046 { 1045 {
1047 SimulateTokenAvailable(child_id); 1046 SimulateTokenAvailable(child_id);
1048 IssueAccessToken(child_id); 1047 IssueAccessToken(child_id);
1049 fetcher.FakeSetIsChildAccount(child_id, true); 1048 fetcher.FakeSetIsChildAccount(child_id, true);
1050 // Response was processed but observer is not notified as the account state 1049 // Response was processed but observer is not notified as the account state
1051 // is invalid. 1050 // is invalid.
1052 ASSERT_TRUE(observer.CheckEvents()); 1051 ASSERT_TRUE(observer.CheckEvents());
1053 AccountInfo info = tracker.GetAccountInfo(child_id); 1052 AccountInfo info = tracker.GetAccountInfo(child_id);
1054 ASSERT_TRUE(info.is_child_account); 1053 ASSERT_TRUE(info.is_child_account);
1055 SimulateTokenRevoked(child_id); 1054 SimulateTokenRevoked(child_id);
1056 } 1055 }
1057 tracker.RemoveObserver(&observer); 1056 tracker.RemoveObserver(&observer);
1058 fetcher.Shutdown(); 1057 fetcher.Shutdown();
1059 tracker.Shutdown(); 1058 tracker.Shutdown();
1060 } 1059 }
1061 1060
1062 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedAndRevoked) { 1061 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedAndRevoked) {
1063 AccountTrackerService tracker; 1062 AccountTrackerService tracker;
1064 tracker.Initialize(signin_client()); 1063 tracker.Initialize(signin_client());
1065 FakeAccountFetcherService fetcher; 1064 FakeAccountFetcherService fetcher;
1066 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 1065 fetcher.Initialize(signin_client(), token_service(), &tracker);
1067 fetcher.EnableNetworkFetches(); 1066 fetcher.OnRefreshTokensLoaded();
1068 AccountTrackerObserver observer; 1067 AccountTrackerObserver observer;
1069 tracker.AddObserver(&observer); 1068 tracker.AddObserver(&observer);
1070 std::string child_id("child"); 1069 std::string child_id("child");
1071 1070
1072 SimulateTokenAvailable(child_id); 1071 SimulateTokenAvailable(child_id);
1073 IssueAccessToken(child_id); 1072 IssueAccessToken(child_id);
1074 fetcher.FakeSetIsChildAccount(child_id, false); 1073 fetcher.FakeSetIsChildAccount(child_id, false);
1075 FakeUserInfoFetchSuccess(&fetcher, child_id); 1074 FakeUserInfoFetchSuccess(&fetcher, child_id);
1076 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); 1075 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id)));
1077 AccountInfo info = tracker.GetAccountInfo(child_id); 1076 AccountInfo info = tracker.GetAccountInfo(child_id);
1078 ASSERT_FALSE(info.is_child_account); 1077 ASSERT_FALSE(info.is_child_account);
1079 SimulateTokenRevoked(child_id); 1078 SimulateTokenRevoked(child_id);
1080 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(REMOVED, child_id))); 1079 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(REMOVED, child_id)));
1081 1080
1082 tracker.RemoveObserver(&observer); 1081 tracker.RemoveObserver(&observer);
1083 fetcher.Shutdown(); 1082 fetcher.Shutdown();
1084 tracker.Shutdown(); 1083 tracker.Shutdown();
1085 } 1084 }
1086 1085
1087 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedAndRevokedWithUpdate) { 1086 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedAndRevokedWithUpdate) {
1088 AccountTrackerService tracker; 1087 AccountTrackerService tracker;
1089 tracker.Initialize(signin_client()); 1088 tracker.Initialize(signin_client());
1090 FakeAccountFetcherService fetcher; 1089 FakeAccountFetcherService fetcher;
1091 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 1090 fetcher.Initialize(signin_client(), token_service(), &tracker);
1092 fetcher.EnableNetworkFetches(); 1091 fetcher.OnRefreshTokensLoaded();
1093 AccountTrackerObserver observer; 1092 AccountTrackerObserver observer;
1094 tracker.AddObserver(&observer); 1093 tracker.AddObserver(&observer);
1095 std::string child_id("child"); 1094 std::string child_id("child");
1096 1095
1097 SimulateTokenAvailable(child_id); 1096 SimulateTokenAvailable(child_id);
1098 IssueAccessToken(child_id); 1097 IssueAccessToken(child_id);
1099 fetcher.FakeSetIsChildAccount(child_id, true); 1098 fetcher.FakeSetIsChildAccount(child_id, true);
1100 FakeUserInfoFetchSuccess(&fetcher, child_id); 1099 FakeUserInfoFetchSuccess(&fetcher, child_id);
1101 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); 1100 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id)));
1102 AccountInfo info = tracker.GetAccountInfo(child_id); 1101 AccountInfo info = tracker.GetAccountInfo(child_id);
1103 ASSERT_TRUE(info.is_child_account); 1102 ASSERT_TRUE(info.is_child_account);
1104 SimulateTokenRevoked(child_id); 1103 SimulateTokenRevoked(child_id);
1105 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id), 1104 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id),
1106 TrackingEvent(REMOVED, child_id))); 1105 TrackingEvent(REMOVED, child_id)));
1107 1106
1108 tracker.RemoveObserver(&observer); 1107 tracker.RemoveObserver(&observer);
1109 fetcher.Shutdown(); 1108 fetcher.Shutdown();
1110 tracker.Shutdown(); 1109 tracker.Shutdown();
1111 } 1110 }
1112 1111
1113 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedTwiceThenRevoked) { 1112 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedTwiceThenRevoked) {
1114 AccountTrackerService tracker; 1113 AccountTrackerService tracker;
1115 tracker.Initialize(signin_client()); 1114 tracker.Initialize(signin_client());
1116 FakeAccountFetcherService fetcher; 1115 FakeAccountFetcherService fetcher;
1117 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 1116 fetcher.Initialize(signin_client(), token_service(), &tracker);
1118 fetcher.EnableNetworkFetches(); 1117 fetcher.OnRefreshTokensLoaded();
1119 AccountTrackerObserver observer; 1118 AccountTrackerObserver observer;
1120 tracker.AddObserver(&observer); 1119 tracker.AddObserver(&observer);
1121 std::string child_id("child"); 1120 std::string child_id("child");
1122 1121
1123 SimulateTokenAvailable(child_id); 1122 SimulateTokenAvailable(child_id);
1124 IssueAccessToken(child_id); 1123 IssueAccessToken(child_id);
1125 // Observers notified the first time. 1124 // Observers notified the first time.
1126 FakeUserInfoFetchSuccess(&fetcher, child_id); 1125 FakeUserInfoFetchSuccess(&fetcher, child_id);
1127 // Since the account state is already valid, this will notify the 1126 // Since the account state is already valid, this will notify the
1128 // observers for the second time. 1127 // observers for the second time.
1129 fetcher.FakeSetIsChildAccount(child_id, true); 1128 fetcher.FakeSetIsChildAccount(child_id, true);
1130 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id), 1129 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id),
1131 TrackingEvent(UPDATED, child_id))); 1130 TrackingEvent(UPDATED, child_id)));
1132 SimulateTokenRevoked(child_id); 1131 SimulateTokenRevoked(child_id);
1133 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id), 1132 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id),
1134 TrackingEvent(REMOVED, child_id))); 1133 TrackingEvent(REMOVED, child_id)));
1135 1134
1136 tracker.RemoveObserver(&observer); 1135 tracker.RemoveObserver(&observer);
1137 fetcher.Shutdown(); 1136 fetcher.Shutdown();
1138 tracker.Shutdown(); 1137 tracker.Shutdown();
1139 } 1138 }
1140 1139
1141 TEST_F(AccountTrackerServiceTest, ChildAccountGraduation) { 1140 TEST_F(AccountTrackerServiceTest, ChildAccountGraduation) {
1142 AccountTrackerService tracker; 1141 AccountTrackerService tracker;
1143 tracker.Initialize(signin_client()); 1142 tracker.Initialize(signin_client());
1144 FakeAccountFetcherService fetcher; 1143 FakeAccountFetcherService fetcher;
1145 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 1144 fetcher.Initialize(signin_client(), token_service(), &tracker);
1146 fetcher.EnableNetworkFetches(); 1145 fetcher.OnRefreshTokensLoaded();
1147 AccountTrackerObserver observer; 1146 AccountTrackerObserver observer;
1148 tracker.AddObserver(&observer); 1147 tracker.AddObserver(&observer);
1149 std::string child_id("child"); 1148 std::string child_id("child");
1150 1149
1151 SimulateTokenAvailable(child_id); 1150 SimulateTokenAvailable(child_id);
1152 IssueAccessToken(child_id); 1151 IssueAccessToken(child_id);
1153 1152
1154 // Set and verify this is a child account. 1153 // Set and verify this is a child account.
1155 fetcher.FakeSetIsChildAccount(child_id, true); 1154 fetcher.FakeSetIsChildAccount(child_id, true);
1156 AccountInfo info = tracker.GetAccountInfo(child_id); 1155 AccountInfo info = tracker.GetAccountInfo(child_id);
1157 ASSERT_TRUE(info.is_child_account); 1156 ASSERT_TRUE(info.is_child_account);
1158 FakeUserInfoFetchSuccess(&fetcher, child_id); 1157 FakeUserInfoFetchSuccess(&fetcher, child_id);
1159 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); 1158 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id)));
1160 1159
1161 // Now simulate child account graduation. 1160 // Now simulate child account graduation.
1162 fetcher.FakeSetIsChildAccount(child_id, false); 1161 fetcher.FakeSetIsChildAccount(child_id, false);
1163 info = tracker.GetAccountInfo(child_id); 1162 info = tracker.GetAccountInfo(child_id);
1164 ASSERT_FALSE(info.is_child_account); 1163 ASSERT_FALSE(info.is_child_account);
1165 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); 1164 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id)));
1166 1165
1167 SimulateTokenRevoked(child_id); 1166 SimulateTokenRevoked(child_id);
1168 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(REMOVED, child_id))); 1167 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(REMOVED, child_id)));
1169 1168
1170 tracker.RemoveObserver(&observer); 1169 tracker.RemoveObserver(&observer);
1171 fetcher.Shutdown(); 1170 fetcher.Shutdown();
1172 tracker.Shutdown(); 1171 tracker.Shutdown();
1173 } 1172 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698