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: delay AFS fetch properly 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(), nullptr);
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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, nullptr);
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 fetcher_service.Initialize(signin_client(), token_service(), &tracker, 538 fetcher_service.Initialize(signin_client(), token_service(), &tracker,
539 nullptr); 539 nullptr);
540 540
541 SimulateTokenAvailable("alpha"); 541 SimulateTokenAvailable("alpha");
542 IssueAccessToken("alpha"); 542 IssueAccessToken("alpha");
543 // No fetcher has been created yet. 543 // No fetcher has been created yet.
544 net::TestURLFetcher* fetcher = test_fetcher_factory()->GetFetcherByID( 544 net::TestURLFetcher* fetcher = test_fetcher_factory()->GetFetcherByID(
545 gaia::GaiaOAuthClient::kUrlFetcherId); 545 gaia::GaiaOAuthClient::kUrlFetcherId);
546 ASSERT_FALSE(fetcher); 546 ASSERT_FALSE(fetcher);
547 547
548 // Enable the network to create the fetcher then issue the access token. 548 // Enable the network fetches and refresh invalid accounts information.
549 fetcher_service.EnableNetworkFetches(); 549 fetcher_service.OnRefreshTokensLoaded();
550 550
551 // Fetcher was created and executes properly. 551 // Fetcher was created and executes properly.
552 ReturnOAuthUrlFetchSuccess("alpha"); 552 ReturnOAuthUrlFetchSuccess("alpha");
553 553
554 AccountInfo info = tracker.GetAccountInfo("alpha"); 554 AccountInfo info = tracker.GetAccountInfo("alpha");
555 CheckAccountDetails("alpha", info); 555 CheckAccountDetails("alpha", info);
556 fetcher_service.Shutdown(); 556 fetcher_service.Shutdown();
557 tracker.Shutdown(); 557 tracker.Shutdown();
558 } 558 }
559 559
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 TrackingEvent(UPDATED, "beta"))); 617 TrackingEvent(UPDATED, "beta")));
618 tracker.RemoveObserver(&observer); 618 tracker.RemoveObserver(&observer);
619 619
620 std::vector<AccountInfo> infos = tracker.GetAccounts(); 620 std::vector<AccountInfo> infos = tracker.GetAccounts();
621 ASSERT_EQ(2u, infos.size()); 621 ASSERT_EQ(2u, infos.size());
622 CheckAccountDetails("alpha", infos[0]); 622 CheckAccountDetails("alpha", infos[0]);
623 CheckAccountDetails("beta", infos[1]); 623 CheckAccountDetails("beta", infos[1]);
624 624
625 FakeAccountFetcherService fetcher; 625 FakeAccountFetcherService fetcher;
626 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 626 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr);
627 fetcher.EnableNetworkFetches(); 627 fetcher.OnRefreshTokensLoaded();
628 // Remove an account. 628 // Remove an account.
629 // This will allow testing removal as well as child accounts which is only 629 // This will allow testing removal as well as child accounts which is only
630 // allowed for a single account. 630 // allowed for a single account.
631 SimulateTokenRevoked("alpha"); 631 SimulateTokenRevoked("alpha");
632 fetcher.FakeSetIsChildAccount("beta", true); 632 fetcher.FakeSetIsChildAccount("beta", true);
633 633
634 fetcher.Shutdown(); 634 fetcher.Shutdown();
635 tracker.Shutdown(); 635 tracker.Shutdown();
636 } 636 }
637 637
(...skipping 29 matching lines...) Expand all
667 } 667 }
668 668
669 TEST_F(AccountTrackerServiceTest, UpgradeToFullAccountInfo) { 669 TEST_F(AccountTrackerServiceTest, UpgradeToFullAccountInfo) {
670 // Start by simulating an incomplete account info and let it be saved to 670 // Start by simulating an incomplete account info and let it be saved to
671 // prefs. 671 // prefs.
672 { 672 {
673 AccountTrackerService tracker; 673 AccountTrackerService tracker;
674 tracker.Initialize(signin_client()); 674 tracker.Initialize(signin_client());
675 AccountFetcherService fetcher; 675 AccountFetcherService fetcher;
676 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 676 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr);
677 fetcher.EnableNetworkFetches(); 677 fetcher.OnRefreshTokensLoaded();
678 SimulateTokenAvailable("incomplete"); 678 SimulateTokenAvailable("incomplete");
679 ReturnOAuthUrlFetchSuccessIncomplete("incomplete"); 679 ReturnOAuthUrlFetchSuccessIncomplete("incomplete");
680 tracker.Shutdown(); 680 tracker.Shutdown();
681 fetcher.Shutdown(); 681 fetcher.Shutdown();
682 } 682 }
683 683
684 { 684 {
685 AccountTrackerService tracker; 685 AccountTrackerService tracker;
686 tracker.Initialize(signin_client()); 686 tracker.Initialize(signin_client());
687 AccountFetcherService fetcher; 687 AccountFetcherService fetcher;
688 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 688 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr);
689 // Validate that the loaded AccountInfo from prefs is considered invalid. 689 // Validate that the loaded AccountInfo from prefs is considered invalid.
690 std::vector<AccountInfo> infos = tracker.GetAccounts(); 690 std::vector<AccountInfo> infos = tracker.GetAccounts();
691 ASSERT_EQ(1u, infos.size()); 691 ASSERT_EQ(1u, infos.size());
692 ASSERT_FALSE(infos[0].IsValid()); 692 ASSERT_FALSE(infos[0].IsValid());
693 693
694 // Enable network fetches and simulate the same account getting a refresh 694 // Enable network fetches and simulate the same account getting a refresh
695 // token containing all the info. 695 // token containing all the info.
696 fetcher.EnableNetworkFetches(); 696 fetcher.OnRefreshTokensLoaded();
697 SimulateTokenAvailable("incomplete"); 697 SimulateTokenAvailable("incomplete");
698 ReturnOAuthUrlFetchSuccess("incomplete"); 698 ReturnOAuthUrlFetchSuccess("incomplete");
699 699
700 // Validate that the account is now considered valid. 700 // Validate that the account is now considered valid.
701 infos = tracker.GetAccounts(); 701 infos = tracker.GetAccounts();
702 ASSERT_EQ(1u, infos.size()); 702 ASSERT_EQ(1u, infos.size());
703 ASSERT_TRUE(infos[0].IsValid()); 703 ASSERT_TRUE(infos[0].IsValid());
704 704
705 tracker.Shutdown(); 705 tracker.Shutdown();
706 fetcher.Shutdown(); 706 fetcher.Shutdown();
707 } 707 }
708 708
709 // Reinstantiate a tracker to validate that the AccountInfo saved to prefs is 709 // Reinstantiate a tracker to validate that the AccountInfo saved to prefs is
710 // now the upgraded one, considered valid. 710 // now the upgraded one, considered valid.
711 { 711 {
712 AccountTrackerService tracker; 712 AccountTrackerService tracker;
713 AccountTrackerObserver observer; 713 AccountTrackerObserver observer;
714 tracker.AddObserver(&observer); 714 tracker.AddObserver(&observer);
715 tracker.Initialize(signin_client()); 715 tracker.Initialize(signin_client());
716 AccountFetcherService fetcher; 716 AccountFetcherService fetcher;
717 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 717 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr);
718 718
719 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, "incomplete"))); 719 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, "incomplete")));
720 // Enabling network fetches shouldn't cause any actual fetch since the 720 // Enabling network fetches shouldn't cause any actual fetch since the
721 // AccountInfos loaded from prefs should be valid. 721 // AccountInfos loaded from prefs should be valid.
722 fetcher.EnableNetworkFetches(); 722 fetcher.OnRefreshTokensLoaded();
723 723
724 std::vector<AccountInfo> infos = tracker.GetAccounts(); 724 std::vector<AccountInfo> infos = tracker.GetAccounts();
725 ASSERT_EQ(1u, infos.size()); 725 ASSERT_EQ(1u, infos.size());
726 ASSERT_TRUE(infos[0].IsValid()); 726 ASSERT_TRUE(infos[0].IsValid());
727 // Check that no network fetches were made. 727 // Check that no network fetches were made.
728 ASSERT_TRUE(observer.CheckEvents()); 728 ASSERT_TRUE(observer.CheckEvents());
729 729
730 tracker.RemoveObserver(&observer); 730 tracker.RemoveObserver(&observer);
731 tracker.Shutdown(); 731 tracker.Shutdown();
732 fetcher.Shutdown(); 732 fetcher.Shutdown();
733 } 733 }
734 } 734 }
735 735
736 TEST_F(AccountTrackerServiceTest, TimerRefresh) { 736 TEST_F(AccountTrackerServiceTest, TimerRefresh) {
737 // Start by creating a tracker and adding a couple accounts to be persisted to 737 // Start by creating a tracker and adding a couple accounts to be persisted to
738 // prefs. 738 // prefs.
739 { 739 {
740 AccountTrackerService tracker; 740 AccountTrackerService tracker;
741 tracker.Initialize(signin_client()); 741 tracker.Initialize(signin_client());
742 AccountFetcherService fetcher; 742 AccountFetcherService fetcher;
743 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 743 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr);
744 fetcher.EnableNetworkFetches(); 744 fetcher.OnRefreshTokensLoaded();
745 SimulateTokenAvailable("alpha"); 745 SimulateTokenAvailable("alpha");
746 ReturnOAuthUrlFetchSuccess("alpha"); 746 ReturnOAuthUrlFetchSuccess("alpha");
747 SimulateTokenAvailable("beta"); 747 SimulateTokenAvailable("beta");
748 ReturnOAuthUrlFetchSuccess("beta"); 748 ReturnOAuthUrlFetchSuccess("beta");
749 tracker.Shutdown(); 749 tracker.Shutdown();
750 fetcher.Shutdown(); 750 fetcher.Shutdown();
751 } 751 }
752 752
753 // Rewind the time by half a day, which shouldn't be enough to trigger a 753 // Rewind the time by half a day, which shouldn't be enough to trigger a
754 // network refresh. 754 // network refresh.
755 base::Time fake_update = base::Time::Now() - base::TimeDelta::FromHours(12); 755 base::Time fake_update = base::Time::Now() - base::TimeDelta::FromHours(12);
756 signin_client()->GetPrefs()->SetInt64( 756 signin_client()->GetPrefs()->SetInt64(
757 AccountFetcherService::kLastUpdatePref, 757 AccountFetcherService::kLastUpdatePref,
758 fake_update.ToInternalValue()); 758 fake_update.ToInternalValue());
759 759
760 // Instantiate a new ATS, making sure the persisted accounts are still there 760 // Instantiate a new ATS, making sure the persisted accounts are still there
761 // and that no network fetches happen. 761 // and that no network fetches happen.
762 { 762 {
763 AccountTrackerService tracker; 763 AccountTrackerService tracker;
764 tracker.Initialize(signin_client()); 764 tracker.Initialize(signin_client());
765 AccountFetcherService fetcher; 765 AccountFetcherService fetcher;
766 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 766 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr);
767 767
768 ASSERT_TRUE(fetcher.IsAllUserInfoFetched()); 768 ASSERT_TRUE(fetcher.IsAllUserInfoFetched());
769 std::vector<AccountInfo> infos = tracker.GetAccounts(); 769 std::vector<AccountInfo> infos = tracker.GetAccounts();
770 ASSERT_EQ(2u, infos.size()); 770 ASSERT_EQ(2u, infos.size());
771 ASSERT_TRUE(infos[0].IsValid()); 771 ASSERT_TRUE(infos[0].IsValid());
772 ASSERT_TRUE(infos[1].IsValid()); 772 ASSERT_TRUE(infos[1].IsValid());
773 773
774 fetcher.EnableNetworkFetches(); 774 fetcher.OnRefreshTokensLoaded();
775 ASSERT_TRUE(fetcher.IsAllUserInfoFetched()); 775 ASSERT_TRUE(fetcher.IsAllUserInfoFetched());
776 tracker.Shutdown(); 776 tracker.Shutdown();
777 fetcher.Shutdown(); 777 fetcher.Shutdown();
778 } 778 }
779 779
780 // Rewind the last updated time enough to trigger a network refresh. 780 // Rewind the last updated time enough to trigger a network refresh.
781 fake_update = base::Time::Now() - base::TimeDelta::FromHours(25); 781 fake_update = base::Time::Now() - base::TimeDelta::FromHours(25);
782 signin_client()->GetPrefs()->SetInt64( 782 signin_client()->GetPrefs()->SetInt64(
783 AccountFetcherService::kLastUpdatePref, 783 AccountFetcherService::kLastUpdatePref,
784 fake_update.ToInternalValue()); 784 fake_update.ToInternalValue());
785 785
786 // Instantiate a new tracker and validate that even though the AccountInfos 786 // Instantiate a new tracker and validate that even though the AccountInfos
787 // are still valid, the network fetches are started. 787 // are still valid, the network fetches are started.
788 { 788 {
789 AccountTrackerService tracker; 789 AccountTrackerService tracker;
790 tracker.Initialize(signin_client()); 790 tracker.Initialize(signin_client());
791 AccountFetcherService fetcher; 791 AccountFetcherService fetcher;
792 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 792 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr);
793 793
794 ASSERT_TRUE(fetcher.IsAllUserInfoFetched()); 794 ASSERT_TRUE(fetcher.IsAllUserInfoFetched());
795 std::vector<AccountInfo> infos = tracker.GetAccounts(); 795 std::vector<AccountInfo> infos = tracker.GetAccounts();
796 ASSERT_EQ(2u, infos.size()); 796 ASSERT_EQ(2u, infos.size());
797 ASSERT_TRUE(infos[0].IsValid()); 797 ASSERT_TRUE(infos[0].IsValid());
798 ASSERT_TRUE(infos[1].IsValid()); 798 ASSERT_TRUE(infos[1].IsValid());
799 799
800 fetcher.EnableNetworkFetches(); 800 fetcher.OnRefreshTokensLoaded();
801 ASSERT_FALSE(fetcher.IsAllUserInfoFetched()); 801 ASSERT_FALSE(fetcher.IsAllUserInfoFetched());
802 tracker.Shutdown(); 802 tracker.Shutdown();
803 fetcher.Shutdown(); 803 fetcher.Shutdown();
804 } 804 }
805 } 805 }
806 806
807 TEST_F(AccountTrackerServiceTest, LegacyDottedAccountIds) { 807 TEST_F(AccountTrackerServiceTest, LegacyDottedAccountIds) {
808 // Start by creating a tracker and adding an account with a dotted account id 808 // 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 809 // 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. 810 // a correct non-dotted account id for the same account.
811 { 811 {
812 AccountTrackerService tracker; 812 AccountTrackerService tracker;
813 tracker.Initialize(signin_client()); 813 tracker.Initialize(signin_client());
814 AccountFetcherService fetcher; 814 AccountFetcherService fetcher;
815 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 815 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr);
816 fetcher.EnableNetworkFetches(); 816 fetcher.OnRefreshTokensLoaded();
817 SimulateTokenAvailable("foo.bar@gmail.com"); 817 SimulateTokenAvailable("foo.bar@gmail.com");
818 SimulateTokenAvailable("foobar@gmail.com"); 818 SimulateTokenAvailable("foobar@gmail.com");
819 ReturnOAuthUrlFetchSuccess("foo.bar@gmail.com"); 819 ReturnOAuthUrlFetchSuccess("foo.bar@gmail.com");
820 ReturnOAuthUrlFetchSuccess("foobar@gmail.com"); 820 ReturnOAuthUrlFetchSuccess("foobar@gmail.com");
821 tracker.Shutdown(); 821 tracker.Shutdown();
822 fetcher.Shutdown(); 822 fetcher.Shutdown();
823 } 823 }
824 824
825 // Remove the bad account now from the token service to simulate that it 825 // Remove the bad account now from the token service to simulate that it
826 // has been "fixed". 826 // has been "fixed".
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 accounts = tracker.GetAccounts(); 1026 accounts = tracker.GetAccounts();
1027 ASSERT_EQ(2u, accounts.size()); 1027 ASSERT_EQ(2u, accounts.size());
1028 } 1028 }
1029 } 1029 }
1030 1030
1031 TEST_F(AccountTrackerServiceTest, ChildAccountBasic) { 1031 TEST_F(AccountTrackerServiceTest, ChildAccountBasic) {
1032 AccountTrackerService tracker; 1032 AccountTrackerService tracker;
1033 tracker.Initialize(signin_client()); 1033 tracker.Initialize(signin_client());
1034 FakeAccountFetcherService fetcher; 1034 FakeAccountFetcherService fetcher;
1035 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 1035 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr);
1036 fetcher.EnableNetworkFetches(); 1036 fetcher.OnRefreshTokensLoaded();
1037 AccountTrackerObserver observer; 1037 AccountTrackerObserver observer;
1038 tracker.AddObserver(&observer); 1038 tracker.AddObserver(&observer);
1039 std::string child_id("child"); 1039 std::string child_id("child");
1040 { 1040 {
1041 // Responses are processed iff there is a single account with a valid token 1041 // Responses are processed iff there is a single account with a valid token
1042 // and the response is for that account. 1042 // and the response is for that account.
1043 fetcher.FakeSetIsChildAccount(child_id, true); 1043 fetcher.FakeSetIsChildAccount(child_id, true);
1044 ASSERT_TRUE(observer.CheckEvents()); 1044 ASSERT_TRUE(observer.CheckEvents());
1045 } 1045 }
1046 { 1046 {
(...skipping 10 matching lines...) Expand all
1057 tracker.RemoveObserver(&observer); 1057 tracker.RemoveObserver(&observer);
1058 fetcher.Shutdown(); 1058 fetcher.Shutdown();
1059 tracker.Shutdown(); 1059 tracker.Shutdown();
1060 } 1060 }
1061 1061
1062 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedAndRevoked) { 1062 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedAndRevoked) {
1063 AccountTrackerService tracker; 1063 AccountTrackerService tracker;
1064 tracker.Initialize(signin_client()); 1064 tracker.Initialize(signin_client());
1065 FakeAccountFetcherService fetcher; 1065 FakeAccountFetcherService fetcher;
1066 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 1066 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr);
1067 fetcher.EnableNetworkFetches(); 1067 fetcher.OnRefreshTokensLoaded();
1068 AccountTrackerObserver observer; 1068 AccountTrackerObserver observer;
1069 tracker.AddObserver(&observer); 1069 tracker.AddObserver(&observer);
1070 std::string child_id("child"); 1070 std::string child_id("child");
1071 1071
1072 SimulateTokenAvailable(child_id); 1072 SimulateTokenAvailable(child_id);
1073 IssueAccessToken(child_id); 1073 IssueAccessToken(child_id);
1074 fetcher.FakeSetIsChildAccount(child_id, false); 1074 fetcher.FakeSetIsChildAccount(child_id, false);
1075 FakeUserInfoFetchSuccess(&fetcher, child_id); 1075 FakeUserInfoFetchSuccess(&fetcher, child_id);
1076 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); 1076 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id)));
1077 AccountInfo info = tracker.GetAccountInfo(child_id); 1077 AccountInfo info = tracker.GetAccountInfo(child_id);
1078 ASSERT_FALSE(info.is_child_account); 1078 ASSERT_FALSE(info.is_child_account);
1079 SimulateTokenRevoked(child_id); 1079 SimulateTokenRevoked(child_id);
1080 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(REMOVED, child_id))); 1080 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(REMOVED, child_id)));
1081 1081
1082 tracker.RemoveObserver(&observer); 1082 tracker.RemoveObserver(&observer);
1083 fetcher.Shutdown(); 1083 fetcher.Shutdown();
1084 tracker.Shutdown(); 1084 tracker.Shutdown();
1085 } 1085 }
1086 1086
1087 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedAndRevokedWithUpdate) { 1087 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedAndRevokedWithUpdate) {
1088 AccountTrackerService tracker; 1088 AccountTrackerService tracker;
1089 tracker.Initialize(signin_client()); 1089 tracker.Initialize(signin_client());
1090 FakeAccountFetcherService fetcher; 1090 FakeAccountFetcherService fetcher;
1091 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 1091 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr);
1092 fetcher.EnableNetworkFetches(); 1092 fetcher.OnRefreshTokensLoaded();
1093 AccountTrackerObserver observer; 1093 AccountTrackerObserver observer;
1094 tracker.AddObserver(&observer); 1094 tracker.AddObserver(&observer);
1095 std::string child_id("child"); 1095 std::string child_id("child");
1096 1096
1097 SimulateTokenAvailable(child_id); 1097 SimulateTokenAvailable(child_id);
1098 IssueAccessToken(child_id); 1098 IssueAccessToken(child_id);
1099 fetcher.FakeSetIsChildAccount(child_id, true); 1099 fetcher.FakeSetIsChildAccount(child_id, true);
1100 FakeUserInfoFetchSuccess(&fetcher, child_id); 1100 FakeUserInfoFetchSuccess(&fetcher, child_id);
1101 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); 1101 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id)));
1102 AccountInfo info = tracker.GetAccountInfo(child_id); 1102 AccountInfo info = tracker.GetAccountInfo(child_id);
1103 ASSERT_TRUE(info.is_child_account); 1103 ASSERT_TRUE(info.is_child_account);
1104 SimulateTokenRevoked(child_id); 1104 SimulateTokenRevoked(child_id);
1105 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id), 1105 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id),
1106 TrackingEvent(REMOVED, child_id))); 1106 TrackingEvent(REMOVED, child_id)));
1107 1107
1108 tracker.RemoveObserver(&observer); 1108 tracker.RemoveObserver(&observer);
1109 fetcher.Shutdown(); 1109 fetcher.Shutdown();
1110 tracker.Shutdown(); 1110 tracker.Shutdown();
1111 } 1111 }
1112 1112
1113 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedTwiceThenRevoked) { 1113 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedTwiceThenRevoked) {
1114 AccountTrackerService tracker; 1114 AccountTrackerService tracker;
1115 tracker.Initialize(signin_client()); 1115 tracker.Initialize(signin_client());
1116 FakeAccountFetcherService fetcher; 1116 FakeAccountFetcherService fetcher;
1117 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 1117 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr);
1118 fetcher.EnableNetworkFetches(); 1118 fetcher.OnRefreshTokensLoaded();
1119 AccountTrackerObserver observer; 1119 AccountTrackerObserver observer;
1120 tracker.AddObserver(&observer); 1120 tracker.AddObserver(&observer);
1121 std::string child_id("child"); 1121 std::string child_id("child");
1122 1122
1123 SimulateTokenAvailable(child_id); 1123 SimulateTokenAvailable(child_id);
1124 IssueAccessToken(child_id); 1124 IssueAccessToken(child_id);
1125 // Observers notified the first time. 1125 // Observers notified the first time.
1126 FakeUserInfoFetchSuccess(&fetcher, child_id); 1126 FakeUserInfoFetchSuccess(&fetcher, child_id);
1127 // Since the account state is already valid, this will notify the 1127 // Since the account state is already valid, this will notify the
1128 // observers for the second time. 1128 // observers for the second time.
1129 fetcher.FakeSetIsChildAccount(child_id, true); 1129 fetcher.FakeSetIsChildAccount(child_id, true);
1130 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id), 1130 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id),
1131 TrackingEvent(UPDATED, child_id))); 1131 TrackingEvent(UPDATED, child_id)));
1132 SimulateTokenRevoked(child_id); 1132 SimulateTokenRevoked(child_id);
1133 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id), 1133 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id),
1134 TrackingEvent(REMOVED, child_id))); 1134 TrackingEvent(REMOVED, child_id)));
1135 1135
1136 tracker.RemoveObserver(&observer); 1136 tracker.RemoveObserver(&observer);
1137 fetcher.Shutdown(); 1137 fetcher.Shutdown();
1138 tracker.Shutdown(); 1138 tracker.Shutdown();
1139 } 1139 }
1140 1140
1141 TEST_F(AccountTrackerServiceTest, ChildAccountGraduation) { 1141 TEST_F(AccountTrackerServiceTest, ChildAccountGraduation) {
1142 AccountTrackerService tracker; 1142 AccountTrackerService tracker;
1143 tracker.Initialize(signin_client()); 1143 tracker.Initialize(signin_client());
1144 FakeAccountFetcherService fetcher; 1144 FakeAccountFetcherService fetcher;
1145 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); 1145 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr);
1146 fetcher.EnableNetworkFetches(); 1146 fetcher.OnRefreshTokensLoaded();
1147 AccountTrackerObserver observer; 1147 AccountTrackerObserver observer;
1148 tracker.AddObserver(&observer); 1148 tracker.AddObserver(&observer);
1149 std::string child_id("child"); 1149 std::string child_id("child");
1150 1150
1151 SimulateTokenAvailable(child_id); 1151 SimulateTokenAvailable(child_id);
1152 IssueAccessToken(child_id); 1152 IssueAccessToken(child_id);
1153 1153
1154 // Set and verify this is a child account. 1154 // Set and verify this is a child account.
1155 fetcher.FakeSetIsChildAccount(child_id, true); 1155 fetcher.FakeSetIsChildAccount(child_id, true);
1156 AccountInfo info = tracker.GetAccountInfo(child_id); 1156 AccountInfo info = tracker.GetAccountInfo(child_id);
1157 ASSERT_TRUE(info.is_child_account); 1157 ASSERT_TRUE(info.is_child_account);
1158 FakeUserInfoFetchSuccess(&fetcher, child_id); 1158 FakeUserInfoFetchSuccess(&fetcher, child_id);
1159 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); 1159 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id)));
1160 1160
1161 // Now simulate child account graduation. 1161 // Now simulate child account graduation.
1162 fetcher.FakeSetIsChildAccount(child_id, false); 1162 fetcher.FakeSetIsChildAccount(child_id, false);
1163 info = tracker.GetAccountInfo(child_id); 1163 info = tracker.GetAccountInfo(child_id);
1164 ASSERT_FALSE(info.is_child_account); 1164 ASSERT_FALSE(info.is_child_account);
1165 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); 1165 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id)));
1166 1166
1167 SimulateTokenRevoked(child_id); 1167 SimulateTokenRevoked(child_id);
1168 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(REMOVED, child_id))); 1168 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(REMOVED, child_id)));
1169 1169
1170 tracker.RemoveObserver(&observer); 1170 tracker.RemoveObserver(&observer);
1171 fetcher.Shutdown(); 1171 fetcher.Shutdown();
1172 tracker.Shutdown(); 1172 tracker.Shutdown();
1173 } 1173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698