| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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); |
| 688 fetcher.OnRefreshTokensLoaded(); |
| 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 // Simulate the same account getting a refresh token with all the info. |
| 695 // token containing all the info. | |
| 696 fetcher.EnableNetworkFetches(); | |
| 697 SimulateTokenAvailable("incomplete"); | 695 SimulateTokenAvailable("incomplete"); |
| 698 ReturnOAuthUrlFetchSuccess("incomplete"); | 696 ReturnOAuthUrlFetchSuccess("incomplete"); |
| 699 | 697 |
| 700 // Validate that the account is now considered valid. | 698 // Validate that the account is now considered valid. |
| 701 infos = tracker.GetAccounts(); | 699 infos = tracker.GetAccounts(); |
| 702 ASSERT_EQ(1u, infos.size()); | 700 ASSERT_EQ(1u, infos.size()); |
| 703 ASSERT_TRUE(infos[0].IsValid()); | 701 ASSERT_TRUE(infos[0].IsValid()); |
| 704 | 702 |
| 705 tracker.Shutdown(); | 703 tracker.Shutdown(); |
| 706 fetcher.Shutdown(); | 704 fetcher.Shutdown(); |
| 707 } | 705 } |
| 708 | 706 |
| 709 // Reinstantiate a tracker to validate that the AccountInfo saved to prefs is | 707 // Reinstantiate a tracker to validate that the AccountInfo saved to prefs is |
| 710 // now the upgraded one, considered valid. | 708 // now the upgraded one, considered valid. |
| 711 { | 709 { |
| 712 AccountTrackerService tracker; | 710 AccountTrackerService tracker; |
| 713 AccountTrackerObserver observer; | 711 AccountTrackerObserver observer; |
| 714 tracker.AddObserver(&observer); | 712 tracker.AddObserver(&observer); |
| 715 tracker.Initialize(signin_client()); | 713 tracker.Initialize(signin_client()); |
| 716 AccountFetcherService fetcher; | 714 AccountFetcherService fetcher; |
| 717 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); | 715 fetcher.Initialize(signin_client(), token_service(), &tracker); |
| 718 | 716 |
| 719 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, "incomplete"))); | 717 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, "incomplete"))); |
| 720 // Enabling network fetches shouldn't cause any actual fetch since the | 718 // Enabling network fetches shouldn't cause any actual fetch since the |
| 721 // AccountInfos loaded from prefs should be valid. | 719 // AccountInfos loaded from prefs should be valid. |
| 722 fetcher.EnableNetworkFetches(); | 720 fetcher.OnRefreshTokensLoaded(); |
| 723 | 721 |
| 724 std::vector<AccountInfo> infos = tracker.GetAccounts(); | 722 std::vector<AccountInfo> infos = tracker.GetAccounts(); |
| 725 ASSERT_EQ(1u, infos.size()); | 723 ASSERT_EQ(1u, infos.size()); |
| 726 ASSERT_TRUE(infos[0].IsValid()); | 724 ASSERT_TRUE(infos[0].IsValid()); |
| 727 // Check that no network fetches were made. | 725 // Check that no network fetches were made. |
| 728 ASSERT_TRUE(observer.CheckEvents()); | 726 ASSERT_TRUE(observer.CheckEvents()); |
| 729 | 727 |
| 730 tracker.RemoveObserver(&observer); | 728 tracker.RemoveObserver(&observer); |
| 731 tracker.Shutdown(); | 729 tracker.Shutdown(); |
| 732 fetcher.Shutdown(); | 730 fetcher.Shutdown(); |
| 733 } | 731 } |
| 734 } | 732 } |
| 735 | 733 |
| 736 TEST_F(AccountTrackerServiceTest, TimerRefresh) { | 734 TEST_F(AccountTrackerServiceTest, TimerRefresh) { |
| 737 // Start by creating a tracker and adding a couple accounts to be persisted to | 735 // Start by creating a tracker and adding a couple accounts to be persisted to |
| 738 // prefs. | 736 // prefs. |
| 739 { | 737 { |
| 740 AccountTrackerService tracker; | 738 AccountTrackerService tracker; |
| 741 tracker.Initialize(signin_client()); | 739 tracker.Initialize(signin_client()); |
| 742 AccountFetcherService fetcher; | 740 AccountFetcherService fetcher; |
| 743 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); | 741 fetcher.Initialize(signin_client(), token_service(), &tracker); |
| 744 fetcher.EnableNetworkFetches(); | 742 fetcher.OnRefreshTokensLoaded(); |
| 745 SimulateTokenAvailable("alpha"); | 743 SimulateTokenAvailable("alpha"); |
| 746 ReturnOAuthUrlFetchSuccess("alpha"); | 744 ReturnOAuthUrlFetchSuccess("alpha"); |
| 747 SimulateTokenAvailable("beta"); | 745 SimulateTokenAvailable("beta"); |
| 748 ReturnOAuthUrlFetchSuccess("beta"); | 746 ReturnOAuthUrlFetchSuccess("beta"); |
| 749 tracker.Shutdown(); | 747 tracker.Shutdown(); |
| 750 fetcher.Shutdown(); | 748 fetcher.Shutdown(); |
| 751 } | 749 } |
| 752 | 750 |
| 753 // Rewind the time by half a day, which shouldn't be enough to trigger a | 751 // Rewind the time by half a day, which shouldn't be enough to trigger a |
| 754 // network refresh. | 752 // network refresh. |
| 755 base::Time fake_update = base::Time::Now() - base::TimeDelta::FromHours(12); | 753 base::Time fake_update = base::Time::Now() - base::TimeDelta::FromHours(12); |
| 756 signin_client()->GetPrefs()->SetInt64( | 754 signin_client()->GetPrefs()->SetInt64( |
| 757 AccountFetcherService::kLastUpdatePref, | 755 AccountFetcherService::kLastUpdatePref, |
| 758 fake_update.ToInternalValue()); | 756 fake_update.ToInternalValue()); |
| 759 | 757 |
| 760 // Instantiate a new ATS, making sure the persisted accounts are still there | 758 // Instantiate a new ATS, making sure the persisted accounts are still there |
| 761 // and that no network fetches happen. | 759 // and that no network fetches happen. |
| 762 { | 760 { |
| 763 AccountTrackerService tracker; | 761 AccountTrackerService tracker; |
| 764 tracker.Initialize(signin_client()); | 762 tracker.Initialize(signin_client()); |
| 765 AccountFetcherService fetcher; | 763 AccountFetcherService fetcher; |
| 766 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); | 764 fetcher.Initialize(signin_client(), token_service(), &tracker); |
| 767 | 765 |
| 768 ASSERT_TRUE(fetcher.IsAllUserInfoFetched()); | 766 ASSERT_TRUE(fetcher.IsAllUserInfoFetched()); |
| 769 std::vector<AccountInfo> infos = tracker.GetAccounts(); | 767 std::vector<AccountInfo> infos = tracker.GetAccounts(); |
| 770 ASSERT_EQ(2u, infos.size()); | 768 ASSERT_EQ(2u, infos.size()); |
| 771 ASSERT_TRUE(infos[0].IsValid()); | 769 ASSERT_TRUE(infos[0].IsValid()); |
| 772 ASSERT_TRUE(infos[1].IsValid()); | 770 ASSERT_TRUE(infos[1].IsValid()); |
| 773 | 771 |
| 774 fetcher.EnableNetworkFetches(); | 772 fetcher.OnRefreshTokensLoaded(); |
| 775 ASSERT_TRUE(fetcher.IsAllUserInfoFetched()); | 773 ASSERT_TRUE(fetcher.IsAllUserInfoFetched()); |
| 776 tracker.Shutdown(); | 774 tracker.Shutdown(); |
| 777 fetcher.Shutdown(); | 775 fetcher.Shutdown(); |
| 778 } | 776 } |
| 779 | 777 |
| 780 // Rewind the last updated time enough to trigger a network refresh. | 778 // Rewind the last updated time enough to trigger a network refresh. |
| 781 fake_update = base::Time::Now() - base::TimeDelta::FromHours(25); | 779 fake_update = base::Time::Now() - base::TimeDelta::FromHours(25); |
| 782 signin_client()->GetPrefs()->SetInt64( | 780 signin_client()->GetPrefs()->SetInt64( |
| 783 AccountFetcherService::kLastUpdatePref, | 781 AccountFetcherService::kLastUpdatePref, |
| 784 fake_update.ToInternalValue()); | 782 fake_update.ToInternalValue()); |
| 785 | 783 |
| 786 // Instantiate a new tracker and validate that even though the AccountInfos | 784 // Instantiate a new tracker and validate that even though the AccountInfos |
| 787 // are still valid, the network fetches are started. | 785 // are still valid, the network fetches are started. |
| 788 { | 786 { |
| 789 AccountTrackerService tracker; | 787 AccountTrackerService tracker; |
| 790 tracker.Initialize(signin_client()); | 788 tracker.Initialize(signin_client()); |
| 791 AccountFetcherService fetcher; | 789 AccountFetcherService fetcher; |
| 792 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); | 790 fetcher.Initialize(signin_client(), token_service(), &tracker); |
| 793 | 791 |
| 794 ASSERT_TRUE(fetcher.IsAllUserInfoFetched()); | 792 ASSERT_TRUE(fetcher.IsAllUserInfoFetched()); |
| 795 std::vector<AccountInfo> infos = tracker.GetAccounts(); | 793 std::vector<AccountInfo> infos = tracker.GetAccounts(); |
| 796 ASSERT_EQ(2u, infos.size()); | 794 ASSERT_EQ(2u, infos.size()); |
| 797 ASSERT_TRUE(infos[0].IsValid()); | 795 ASSERT_TRUE(infos[0].IsValid()); |
| 798 ASSERT_TRUE(infos[1].IsValid()); | 796 ASSERT_TRUE(infos[1].IsValid()); |
| 799 | 797 |
| 800 fetcher.EnableNetworkFetches(); | 798 fetcher.OnRefreshTokensLoaded(); |
| 801 ASSERT_FALSE(fetcher.IsAllUserInfoFetched()); | 799 ASSERT_FALSE(fetcher.IsAllUserInfoFetched()); |
| 802 tracker.Shutdown(); | 800 tracker.Shutdown(); |
| 803 fetcher.Shutdown(); | 801 fetcher.Shutdown(); |
| 804 } | 802 } |
| 805 } | 803 } |
| 806 | 804 |
| 807 TEST_F(AccountTrackerServiceTest, LegacyDottedAccountIds) { | 805 TEST_F(AccountTrackerServiceTest, LegacyDottedAccountIds) { |
| 808 // Start by creating a tracker and adding an account with a dotted account id | 806 // 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 | 807 // 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. | 808 // a correct non-dotted account id for the same account. |
| 811 { | 809 { |
| 812 AccountTrackerService tracker; | 810 AccountTrackerService tracker; |
| 813 tracker.Initialize(signin_client()); | 811 tracker.Initialize(signin_client()); |
| 814 AccountFetcherService fetcher; | 812 AccountFetcherService fetcher; |
| 815 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); | 813 fetcher.Initialize(signin_client(), token_service(), &tracker); |
| 816 fetcher.EnableNetworkFetches(); | 814 fetcher.OnRefreshTokensLoaded(); |
| 817 SimulateTokenAvailable("foo.bar@gmail.com"); | 815 SimulateTokenAvailable("foo.bar@gmail.com"); |
| 818 SimulateTokenAvailable("foobar@gmail.com"); | 816 SimulateTokenAvailable("foobar@gmail.com"); |
| 819 ReturnOAuthUrlFetchSuccess("foo.bar@gmail.com"); | 817 ReturnOAuthUrlFetchSuccess("foo.bar@gmail.com"); |
| 820 ReturnOAuthUrlFetchSuccess("foobar@gmail.com"); | 818 ReturnOAuthUrlFetchSuccess("foobar@gmail.com"); |
| 821 tracker.Shutdown(); | 819 tracker.Shutdown(); |
| 822 fetcher.Shutdown(); | 820 fetcher.Shutdown(); |
| 823 } | 821 } |
| 824 | 822 |
| 825 // Remove the bad account now from the token service to simulate that it | 823 // Remove the bad account now from the token service to simulate that it |
| 826 // has been "fixed". | 824 // has been "fixed". |
| 827 SimulateTokenRevoked("foo.bar@gmail.com"); | 825 SimulateTokenRevoked("foo.bar@gmail.com"); |
| 828 | 826 |
| 829 // Instantiate a new tracker and validate that it has only one account, and | 827 // Instantiate a new tracker and validate that it has only one account, and |
| 830 // it is the correct non dotted one. | 828 // it is the correct non dotted one. |
| 831 { | 829 { |
| 832 AccountTrackerService tracker; | 830 AccountTrackerService tracker; |
| 833 tracker.Initialize(signin_client()); | 831 tracker.Initialize(signin_client()); |
| 834 AccountFetcherService fetcher; | 832 AccountFetcherService fetcher; |
| 835 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); | 833 fetcher.Initialize(signin_client(), token_service(), &tracker); |
| 836 | 834 |
| 837 ASSERT_TRUE(fetcher.IsAllUserInfoFetched()); | 835 ASSERT_TRUE(fetcher.IsAllUserInfoFetched()); |
| 838 std::vector<AccountInfo> infos = tracker.GetAccounts(); | 836 std::vector<AccountInfo> infos = tracker.GetAccounts(); |
| 839 ASSERT_EQ(1u, infos.size()); | 837 ASSERT_EQ(1u, infos.size()); |
| 840 ASSERT_STREQ("foobar@gmail.com", infos[0].account_id.c_str()); | 838 ASSERT_STREQ("foobar@gmail.com", infos[0].account_id.c_str()); |
| 841 tracker.Shutdown(); | 839 tracker.Shutdown(); |
| 842 fetcher.Shutdown(); | 840 fetcher.Shutdown(); |
| 843 } | 841 } |
| 844 } | 842 } |
| 845 | 843 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 accounts.clear(); | 1023 accounts.clear(); |
| 1026 accounts = tracker.GetAccounts(); | 1024 accounts = tracker.GetAccounts(); |
| 1027 ASSERT_EQ(2u, accounts.size()); | 1025 ASSERT_EQ(2u, accounts.size()); |
| 1028 } | 1026 } |
| 1029 } | 1027 } |
| 1030 | 1028 |
| 1031 TEST_F(AccountTrackerServiceTest, ChildAccountBasic) { | 1029 TEST_F(AccountTrackerServiceTest, ChildAccountBasic) { |
| 1032 AccountTrackerService tracker; | 1030 AccountTrackerService tracker; |
| 1033 tracker.Initialize(signin_client()); | 1031 tracker.Initialize(signin_client()); |
| 1034 FakeAccountFetcherService fetcher; | 1032 FakeAccountFetcherService fetcher; |
| 1035 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); | 1033 fetcher.Initialize(signin_client(), token_service(), &tracker); |
| 1036 fetcher.EnableNetworkFetches(); | 1034 fetcher.OnRefreshTokensLoaded(); |
| 1037 AccountTrackerObserver observer; | 1035 AccountTrackerObserver observer; |
| 1038 tracker.AddObserver(&observer); | 1036 tracker.AddObserver(&observer); |
| 1039 std::string child_id("child"); | 1037 std::string child_id("child"); |
| 1040 { | 1038 { |
| 1041 // Responses are processed iff there is a single account with a valid token | 1039 // Responses are processed iff there is a single account with a valid token |
| 1042 // and the response is for that account. | 1040 // and the response is for that account. |
| 1043 fetcher.FakeSetIsChildAccount(child_id, true); | 1041 fetcher.FakeSetIsChildAccount(child_id, true); |
| 1044 ASSERT_TRUE(observer.CheckEvents()); | 1042 ASSERT_TRUE(observer.CheckEvents()); |
| 1045 } | 1043 } |
| 1046 { | 1044 { |
| 1047 SimulateTokenAvailable(child_id); | 1045 SimulateTokenAvailable(child_id); |
| 1048 IssueAccessToken(child_id); | 1046 IssueAccessToken(child_id); |
| 1049 fetcher.FakeSetIsChildAccount(child_id, true); | 1047 fetcher.FakeSetIsChildAccount(child_id, true); |
| 1050 // Response was processed but observer is not notified as the account state | 1048 // Response was processed but observer is not notified as the account state |
| 1051 // is invalid. | 1049 // is invalid. |
| 1052 ASSERT_TRUE(observer.CheckEvents()); | 1050 ASSERT_TRUE(observer.CheckEvents()); |
| 1053 AccountInfo info = tracker.GetAccountInfo(child_id); | 1051 AccountInfo info = tracker.GetAccountInfo(child_id); |
| 1054 ASSERT_TRUE(info.is_child_account); | 1052 ASSERT_TRUE(info.is_child_account); |
| 1055 SimulateTokenRevoked(child_id); | 1053 SimulateTokenRevoked(child_id); |
| 1056 } | 1054 } |
| 1057 tracker.RemoveObserver(&observer); | 1055 tracker.RemoveObserver(&observer); |
| 1058 fetcher.Shutdown(); | 1056 fetcher.Shutdown(); |
| 1059 tracker.Shutdown(); | 1057 tracker.Shutdown(); |
| 1060 } | 1058 } |
| 1061 | 1059 |
| 1062 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedAndRevoked) { | 1060 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedAndRevoked) { |
| 1063 AccountTrackerService tracker; | 1061 AccountTrackerService tracker; |
| 1064 tracker.Initialize(signin_client()); | 1062 tracker.Initialize(signin_client()); |
| 1065 FakeAccountFetcherService fetcher; | 1063 FakeAccountFetcherService fetcher; |
| 1066 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); | 1064 fetcher.Initialize(signin_client(), token_service(), &tracker); |
| 1067 fetcher.EnableNetworkFetches(); | 1065 fetcher.OnRefreshTokensLoaded(); |
| 1068 AccountTrackerObserver observer; | 1066 AccountTrackerObserver observer; |
| 1069 tracker.AddObserver(&observer); | 1067 tracker.AddObserver(&observer); |
| 1070 std::string child_id("child"); | 1068 std::string child_id("child"); |
| 1071 | 1069 |
| 1072 SimulateTokenAvailable(child_id); | 1070 SimulateTokenAvailable(child_id); |
| 1073 IssueAccessToken(child_id); | 1071 IssueAccessToken(child_id); |
| 1074 fetcher.FakeSetIsChildAccount(child_id, false); | 1072 fetcher.FakeSetIsChildAccount(child_id, false); |
| 1075 FakeUserInfoFetchSuccess(&fetcher, child_id); | 1073 FakeUserInfoFetchSuccess(&fetcher, child_id); |
| 1076 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); | 1074 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); |
| 1077 AccountInfo info = tracker.GetAccountInfo(child_id); | 1075 AccountInfo info = tracker.GetAccountInfo(child_id); |
| 1078 ASSERT_FALSE(info.is_child_account); | 1076 ASSERT_FALSE(info.is_child_account); |
| 1079 SimulateTokenRevoked(child_id); | 1077 SimulateTokenRevoked(child_id); |
| 1080 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(REMOVED, child_id))); | 1078 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(REMOVED, child_id))); |
| 1081 | 1079 |
| 1082 tracker.RemoveObserver(&observer); | 1080 tracker.RemoveObserver(&observer); |
| 1083 fetcher.Shutdown(); | 1081 fetcher.Shutdown(); |
| 1084 tracker.Shutdown(); | 1082 tracker.Shutdown(); |
| 1085 } | 1083 } |
| 1086 | 1084 |
| 1087 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedAndRevokedWithUpdate) { | 1085 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedAndRevokedWithUpdate) { |
| 1088 AccountTrackerService tracker; | 1086 AccountTrackerService tracker; |
| 1089 tracker.Initialize(signin_client()); | 1087 tracker.Initialize(signin_client()); |
| 1090 FakeAccountFetcherService fetcher; | 1088 FakeAccountFetcherService fetcher; |
| 1091 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); | 1089 fetcher.Initialize(signin_client(), token_service(), &tracker); |
| 1092 fetcher.EnableNetworkFetches(); | 1090 fetcher.OnRefreshTokensLoaded(); |
| 1093 AccountTrackerObserver observer; | 1091 AccountTrackerObserver observer; |
| 1094 tracker.AddObserver(&observer); | 1092 tracker.AddObserver(&observer); |
| 1095 std::string child_id("child"); | 1093 std::string child_id("child"); |
| 1096 | 1094 |
| 1097 SimulateTokenAvailable(child_id); | 1095 SimulateTokenAvailable(child_id); |
| 1098 IssueAccessToken(child_id); | 1096 IssueAccessToken(child_id); |
| 1099 fetcher.FakeSetIsChildAccount(child_id, true); | 1097 fetcher.FakeSetIsChildAccount(child_id, true); |
| 1100 FakeUserInfoFetchSuccess(&fetcher, child_id); | 1098 FakeUserInfoFetchSuccess(&fetcher, child_id); |
| 1101 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); | 1099 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); |
| 1102 AccountInfo info = tracker.GetAccountInfo(child_id); | 1100 AccountInfo info = tracker.GetAccountInfo(child_id); |
| 1103 ASSERT_TRUE(info.is_child_account); | 1101 ASSERT_TRUE(info.is_child_account); |
| 1104 SimulateTokenRevoked(child_id); | 1102 SimulateTokenRevoked(child_id); |
| 1105 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id), | 1103 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id), |
| 1106 TrackingEvent(REMOVED, child_id))); | 1104 TrackingEvent(REMOVED, child_id))); |
| 1107 | 1105 |
| 1108 tracker.RemoveObserver(&observer); | 1106 tracker.RemoveObserver(&observer); |
| 1109 fetcher.Shutdown(); | 1107 fetcher.Shutdown(); |
| 1110 tracker.Shutdown(); | 1108 tracker.Shutdown(); |
| 1111 } | 1109 } |
| 1112 | 1110 |
| 1113 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedTwiceThenRevoked) { | 1111 TEST_F(AccountTrackerServiceTest, ChildAccountUpdatedTwiceThenRevoked) { |
| 1114 AccountTrackerService tracker; | 1112 AccountTrackerService tracker; |
| 1115 tracker.Initialize(signin_client()); | 1113 tracker.Initialize(signin_client()); |
| 1116 FakeAccountFetcherService fetcher; | 1114 FakeAccountFetcherService fetcher; |
| 1117 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); | 1115 fetcher.Initialize(signin_client(), token_service(), &tracker); |
| 1118 fetcher.EnableNetworkFetches(); | 1116 fetcher.OnRefreshTokensLoaded(); |
| 1119 AccountTrackerObserver observer; | 1117 AccountTrackerObserver observer; |
| 1120 tracker.AddObserver(&observer); | 1118 tracker.AddObserver(&observer); |
| 1121 std::string child_id("child"); | 1119 std::string child_id("child"); |
| 1122 | 1120 |
| 1123 SimulateTokenAvailable(child_id); | 1121 SimulateTokenAvailable(child_id); |
| 1124 IssueAccessToken(child_id); | 1122 IssueAccessToken(child_id); |
| 1125 // Observers notified the first time. | 1123 // Observers notified the first time. |
| 1126 FakeUserInfoFetchSuccess(&fetcher, child_id); | 1124 FakeUserInfoFetchSuccess(&fetcher, child_id); |
| 1127 // Since the account state is already valid, this will notify the | 1125 // Since the account state is already valid, this will notify the |
| 1128 // observers for the second time. | 1126 // observers for the second time. |
| 1129 fetcher.FakeSetIsChildAccount(child_id, true); | 1127 fetcher.FakeSetIsChildAccount(child_id, true); |
| 1130 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id), | 1128 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id), |
| 1131 TrackingEvent(UPDATED, child_id))); | 1129 TrackingEvent(UPDATED, child_id))); |
| 1132 SimulateTokenRevoked(child_id); | 1130 SimulateTokenRevoked(child_id); |
| 1133 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id), | 1131 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id), |
| 1134 TrackingEvent(REMOVED, child_id))); | 1132 TrackingEvent(REMOVED, child_id))); |
| 1135 | 1133 |
| 1136 tracker.RemoveObserver(&observer); | 1134 tracker.RemoveObserver(&observer); |
| 1137 fetcher.Shutdown(); | 1135 fetcher.Shutdown(); |
| 1138 tracker.Shutdown(); | 1136 tracker.Shutdown(); |
| 1139 } | 1137 } |
| 1140 | 1138 |
| 1141 TEST_F(AccountTrackerServiceTest, ChildAccountGraduation) { | 1139 TEST_F(AccountTrackerServiceTest, ChildAccountGraduation) { |
| 1142 AccountTrackerService tracker; | 1140 AccountTrackerService tracker; |
| 1143 tracker.Initialize(signin_client()); | 1141 tracker.Initialize(signin_client()); |
| 1144 FakeAccountFetcherService fetcher; | 1142 FakeAccountFetcherService fetcher; |
| 1145 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr); | 1143 fetcher.Initialize(signin_client(), token_service(), &tracker); |
| 1146 fetcher.EnableNetworkFetches(); | 1144 fetcher.OnRefreshTokensLoaded(); |
| 1147 AccountTrackerObserver observer; | 1145 AccountTrackerObserver observer; |
| 1148 tracker.AddObserver(&observer); | 1146 tracker.AddObserver(&observer); |
| 1149 std::string child_id("child"); | 1147 std::string child_id("child"); |
| 1150 | 1148 |
| 1151 SimulateTokenAvailable(child_id); | 1149 SimulateTokenAvailable(child_id); |
| 1152 IssueAccessToken(child_id); | 1150 IssueAccessToken(child_id); |
| 1153 | 1151 |
| 1154 // Set and verify this is a child account. | 1152 // Set and verify this is a child account. |
| 1155 fetcher.FakeSetIsChildAccount(child_id, true); | 1153 fetcher.FakeSetIsChildAccount(child_id, true); |
| 1156 AccountInfo info = tracker.GetAccountInfo(child_id); | 1154 AccountInfo info = tracker.GetAccountInfo(child_id); |
| 1157 ASSERT_TRUE(info.is_child_account); | 1155 ASSERT_TRUE(info.is_child_account); |
| 1158 FakeUserInfoFetchSuccess(&fetcher, child_id); | 1156 FakeUserInfoFetchSuccess(&fetcher, child_id); |
| 1159 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); | 1157 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); |
| 1160 | 1158 |
| 1161 // Now simulate child account graduation. | 1159 // Now simulate child account graduation. |
| 1162 fetcher.FakeSetIsChildAccount(child_id, false); | 1160 fetcher.FakeSetIsChildAccount(child_id, false); |
| 1163 info = tracker.GetAccountInfo(child_id); | 1161 info = tracker.GetAccountInfo(child_id); |
| 1164 ASSERT_FALSE(info.is_child_account); | 1162 ASSERT_FALSE(info.is_child_account); |
| 1165 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); | 1163 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); |
| 1166 | 1164 |
| 1167 SimulateTokenRevoked(child_id); | 1165 SimulateTokenRevoked(child_id); |
| 1168 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(REMOVED, child_id))); | 1166 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(REMOVED, child_id))); |
| 1169 | 1167 |
| 1170 tracker.RemoveObserver(&observer); | 1168 tracker.RemoveObserver(&observer); |
| 1171 fetcher.Shutdown(); | 1169 fetcher.Shutdown(); |
| 1172 tracker.Shutdown(); | 1170 tracker.Shutdown(); |
| 1173 } | 1171 } |
| OLD | NEW |