| Index: chrome/browser/signin/account_reconcilor_unittest.cc
|
| diff --git a/chrome/browser/signin/account_reconcilor_unittest.cc b/chrome/browser/signin/account_reconcilor_unittest.cc
|
| index 7d6e9c5ae21cf48615471cacc8611124dfd85688..73d79c1dea62085739e751db8fac4db71d1d0eec 100644
|
| --- a/chrome/browser/signin/account_reconcilor_unittest.cc
|
| +++ b/chrome/browser/signin/account_reconcilor_unittest.cc
|
| @@ -13,6 +13,7 @@
|
| #include "chrome/browser/signin/account_reconcilor_factory.h"
|
| #include "chrome/browser/signin/account_tracker_service_factory.h"
|
| #include "chrome/browser/signin/chrome_signin_client_factory.h"
|
| +#include "chrome/browser/signin/fake_gaia_cookie_manager_service.h"
|
| #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
|
| #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
|
| #include "chrome/browser/signin/fake_signin_manager.h"
|
| @@ -88,6 +89,9 @@ class AccountReconcilorTest : public ::testing::TestWithParam<bool> {
|
| FakeProfileOAuth2TokenService* token_service() { return token_service_; }
|
| TestSigninClient* test_signin_client() { return test_signin_client_; }
|
| AccountTrackerService* account_tracker() { return account_tracker_; }
|
| + FakeGaiaCookieManagerService* cookie_manager_service() {
|
| + return cookie_manager_service_;
|
| + }
|
| base::HistogramTester* histogram_tester() { return &histogram_tester_; }
|
|
|
| void SetFakeResponse(const std::string& url,
|
| @@ -114,7 +118,6 @@ class AccountReconcilorTest : public ::testing::TestWithParam<bool> {
|
| content_settings::Observer* observer,
|
| const ContentSettingsPattern& primary_pattern);
|
|
|
| - GURL list_accounts_url() { return list_accounts_url_; }
|
| GURL get_check_connection_info_url() {
|
| return get_check_connection_info_url_;
|
| }
|
| @@ -126,11 +129,11 @@ class AccountReconcilorTest : public ::testing::TestWithParam<bool> {
|
| FakeProfileOAuth2TokenService* token_service_;
|
| TestSigninClient* test_signin_client_;
|
| AccountTrackerService* account_tracker_;
|
| + FakeGaiaCookieManagerService* cookie_manager_service_;
|
| MockAccountReconcilor* mock_reconcilor_;
|
| net::FakeURLFetcherFactory url_fetcher_factory_;
|
| scoped_ptr<TestingProfileManager> testing_profile_manager_;
|
| base::HistogramTester histogram_tester_;
|
| - GURL list_accounts_url_;
|
| GURL get_check_connection_info_url_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(AccountReconcilorTest);
|
| @@ -140,6 +143,7 @@ AccountReconcilorTest::AccountReconcilorTest()
|
| : signin_manager_(NULL),
|
| token_service_(NULL),
|
| test_signin_client_(NULL),
|
| + cookie_manager_service_(NULL),
|
| mock_reconcilor_(NULL),
|
| url_fetcher_factory_(NULL) {}
|
|
|
| @@ -151,16 +155,10 @@ void AccountReconcilorTest::SetUp() {
|
| switches::kEnableNewProfileManagement);
|
| }
|
|
|
| - list_accounts_url_ = GaiaUrls::GetInstance()->ListAccountsURLWithSource(
|
| - GaiaConstants::kReconcilorSource);
|
| get_check_connection_info_url_ =
|
| GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource(
|
| GaiaConstants::kChromeSource);
|
|
|
| - // Specific tests may set a response that includes specific accounts.
|
| - SetFakeResponse(list_accounts_url().spec(), "",
|
| - net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS);
|
| -
|
| testing_profile_manager_.reset(
|
| new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
|
| ASSERT_TRUE(testing_profile_manager_.get()->SetUp());
|
| @@ -171,6 +169,9 @@ void AccountReconcilorTest::SetUp() {
|
| factories.push_back(std::make_pair(
|
| ProfileOAuth2TokenServiceFactory::GetInstance(),
|
| BuildFakeProfileOAuth2TokenService));
|
| + factories.push_back(std::make_pair(
|
| + GaiaCookieManagerServiceFactory::GetInstance(),
|
| + FakeGaiaCookieManagerService::Build));
|
| factories.push_back(std::make_pair(SigninManagerFactory::GetInstance(),
|
| FakeSigninManagerBase::Build));
|
| factories.push_back(std::make_pair(AccountReconcilorFactory::GetInstance(),
|
| @@ -195,6 +196,17 @@ void AccountReconcilorTest::SetUp() {
|
| signin_manager_ =
|
| static_cast<FakeSigninManagerForTesting*>(
|
| SigninManagerFactory::GetForProfile(profile()));
|
| +
|
| + test_signin_client_ =
|
| + static_cast<TestSigninClient*>(
|
| + ChromeSigninClientFactory::GetForProfile(profile()));
|
| +
|
| + cookie_manager_service_ =
|
| + static_cast<FakeGaiaCookieManagerService*>(
|
| + GaiaCookieManagerServiceFactory::GetForProfile(profile()));
|
| + cookie_manager_service_->Init(&url_fetcher_factory_);
|
| +
|
| + cookie_manager_service_->SetListAccountsResponseHttpNotFound();
|
| }
|
|
|
| MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() {
|
| @@ -303,41 +315,37 @@ TEST_F(AccountReconcilorTest, ProfileAlreadyConnected) {
|
| TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) {
|
| const std::string account_id =
|
| ConnectProfileToAccount("12345", "user@gmail.com");
|
| + cookie_manager_service()->SetListAccountsResponseOneAccountWithExpiry(
|
| + "user@gmail.com", true);
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id));
|
|
|
| AccountReconcilor* reconcilor =
|
| AccountReconcilorFactory::GetForProfile(profile());
|
| ASSERT_TRUE(reconcilor);
|
|
|
| - SetFakeResponse(list_accounts_url().spec(),
|
| - "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]",
|
| - net::HTTP_OK, net::URLRequestStatus::SUCCESS);
|
| -
|
| reconcilor->StartReconcile();
|
| - ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
|
| -
|
| base::RunLoop().RunUntilIdle();
|
| - ASSERT_TRUE(reconcilor->AreGaiaAccountsSet());
|
| - const std::vector<std::pair<std::string, bool> >& accounts =
|
| - reconcilor->GetGaiaAccountsForTesting();
|
| +
|
| + std::vector<std::pair<std::string, bool> > accounts;
|
| + ASSERT_TRUE(cookie_manager_service()->ListAccounts(&accounts));
|
| ASSERT_EQ(1u, accounts.size());
|
| ASSERT_EQ(account_id, accounts[0].first);
|
| }
|
|
|
| TEST_F(AccountReconcilorTest, GetAccountsFromCookieFailure) {
|
| ConnectProfileToAccount("12345", "user@gmail.com");
|
| + cookie_manager_service()->SetListAccountsResponseHttpNotFound();
|
| +
|
| AccountReconcilor* reconcilor =
|
| AccountReconcilorFactory::GetForProfile(profile());
|
| ASSERT_TRUE(reconcilor);
|
|
|
| - SetFakeResponse(list_accounts_url().spec(), "",
|
| - net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS);
|
| -
|
| reconcilor->StartReconcile();
|
| - ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
|
| -
|
| base::RunLoop().RunUntilIdle();
|
| - ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
|
| +
|
| + std::vector<std::pair<std::string, bool> > accounts;
|
| + ASSERT_FALSE(cookie_manager_service()->ListAccounts(&accounts));
|
| + ASSERT_EQ(0u, accounts.size());
|
| }
|
|
|
| TEST_P(AccountReconcilorTest, StartReconcileNoop) {
|
| @@ -348,13 +356,10 @@ TEST_P(AccountReconcilorTest, StartReconcileNoop) {
|
| AccountReconcilorFactory::GetForProfile(profile());
|
| ASSERT_TRUE(reconcilor);
|
|
|
| - SetFakeResponse(list_accounts_url().spec(),
|
| - "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
|
| - net::HTTP_OK, net::URLRequestStatus::SUCCESS);
|
| + cookie_manager_service()->SetListAccountsResponseOneAccount("user@gmail.com");
|
|
|
| reconcilor->StartReconcile();
|
| ASSERT_TRUE(reconcilor->is_reconcile_started_);
|
| - ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
|
|
|
| base::RunLoop().RunUntilIdle();
|
| ASSERT_FALSE(reconcilor->is_reconcile_started_);
|
| @@ -379,9 +384,11 @@ TEST_P(AccountReconcilorTest, StartReconcileCookiesDisabled) {
|
|
|
| reconcilor->StartReconcile();
|
| ASSERT_FALSE(reconcilor->is_reconcile_started_);
|
| - ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
|
|
|
| base::RunLoop().RunUntilIdle();
|
| + std::vector<std::pair<std::string, bool> > accounts;
|
| + // This will be the first call to ListAccounts.
|
| + ASSERT_FALSE(cookie_manager_service()->ListAccounts(&accounts));
|
| ASSERT_FALSE(reconcilor->is_reconcile_started_);
|
| }
|
|
|
| @@ -468,17 +475,13 @@ TEST_P(AccountReconcilorTest, StartReconcileNoopWithDots) {
|
|
|
| const std::string account_id =
|
| ConnectProfileToAccount("12345", "Dot.S@gmail.com");
|
| + cookie_manager_service()->SetListAccountsResponseOneAccount(
|
| + "dot.s@gmail.com");
|
| AccountReconcilor* reconcilor =
|
| AccountReconcilorFactory::GetForProfile(profile());
|
| ASSERT_TRUE(reconcilor);
|
|
|
| - SetFakeResponse(list_accounts_url().spec(),
|
| - "[\"f\", [[\"b\", 0, \"n\", \"dot.s@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
|
| - net::HTTP_OK, net::URLRequestStatus::SUCCESS);
|
| -
|
| reconcilor->StartReconcile();
|
| - ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
|
| -
|
| base::RunLoop().RunUntilIdle();
|
| ASSERT_FALSE(reconcilor->is_reconcile_started_);
|
|
|
| @@ -493,19 +496,15 @@ TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) {
|
| ConnectProfileToAccount("12345", "user@gmail.com");
|
| const std::string account_id2 =
|
| PickAccountIdForAccount("67890", "other@gmail.com");
|
| + cookie_manager_service()->SetListAccountsResponseTwoAccounts(
|
| + "user@gmail.com", "other@gmail.com");
|
| token_service()->UpdateCredentials(account_id2, "refresh_token");
|
|
|
| AccountReconcilor* reconcilor =
|
| AccountReconcilorFactory::GetForProfile(profile());
|
| ASSERT_TRUE(reconcilor);
|
|
|
| - SetFakeResponse(list_accounts_url().spec(),
|
| - "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
|
| - "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
|
| - net::HTTP_OK, net::URLRequestStatus::SUCCESS);
|
| -
|
| reconcilor->StartReconcile();
|
| - ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
|
| base::RunLoop().RunUntilIdle();
|
| ASSERT_FALSE(reconcilor->is_reconcile_started_);
|
|
|
| @@ -521,6 +520,8 @@ TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) {
|
| const std::string account_id =
|
| ConnectProfileToAccount("12345", "user@gmail.com");
|
| token_service()->UpdateCredentials(account_id, "refresh_token");
|
| + cookie_manager_service()->SetListAccountsResponseOneAccount(
|
| + "user@gmail.com");
|
|
|
| const std::string account_id2 =
|
| PickAccountIdForAccount("67890", "other@gmail.com");
|
| @@ -528,10 +529,6 @@ TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) {
|
|
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id2));
|
|
|
| - SetFakeResponse(list_accounts_url().spec(),
|
| - "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
|
| - net::HTTP_OK, net::URLRequestStatus::SUCCESS);
|
| -
|
| AccountReconcilor* reconcilor = GetMockReconcilor();
|
| reconcilor->StartReconcile();
|
|
|
| @@ -555,15 +552,12 @@ TEST_P(AccountReconcilorTest, StartReconcileRemoveFromCookie) {
|
| const std::string account_id =
|
| ConnectProfileToAccount("12345", "user@gmail.com");
|
| token_service()->UpdateCredentials(account_id, "refresh_token");
|
| + cookie_manager_service()->SetListAccountsResponseTwoAccounts(
|
| + "user@gmail.com", "other@gmail.com");
|
|
|
| EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction());
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id));
|
|
|
| - SetFakeResponse(list_accounts_url().spec(),
|
| - "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
|
| - "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
|
| - net::HTTP_OK, net::URLRequestStatus::SUCCESS);
|
| -
|
| AccountReconcilor* reconcilor = GetMockReconcilor();
|
| reconcilor->StartReconcile();
|
| ASSERT_TRUE(reconcilor->is_reconcile_started_);
|
| @@ -591,17 +585,13 @@ TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) {
|
| const std::string account_id3 =
|
| PickAccountIdForAccount("34567", "third@gmail.com");
|
|
|
| + cookie_manager_service()->SetListAccountsResponseOneAccount(
|
| + "user@gmail.com");
|
| token_service()->UpdateCredentials(account_id2, "refresh_token");
|
|
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id2));
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id3));
|
|
|
| - SetFakeResponse(
|
| - list_accounts_url().spec(),
|
| - "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
|
| - net::HTTP_OK,
|
| - net::URLRequestStatus::SUCCESS);
|
| -
|
| AccountReconcilor* reconcilor = GetMockReconcilor();
|
| reconcilor->StartReconcile();
|
|
|
| @@ -621,13 +611,10 @@ TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) {
|
| "Signin.Reconciler.RemovedFromCookieJar.FirstRun", 0, 1);
|
|
|
| // Do another pass after I've added a third account to the token service
|
| + cookie_manager_service()->SetListAccountsResponseTwoAccounts(
|
| + "user@gmail.com", "other@gmail.com");
|
| + cookie_manager_service()->set_list_accounts_fetched_once_for_testing(false);
|
|
|
| - SetFakeResponse(
|
| - list_accounts_url().spec(),
|
| - "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
|
| - "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
|
| - net::HTTP_OK,
|
| - net::URLRequestStatus::SUCCESS);
|
| // This will cause the reconcilor to fire.
|
| token_service()->UpdateCredentials(account_id3, "refresh_token");
|
| base::RunLoop().RunUntilIdle();
|
| @@ -662,16 +649,13 @@ TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) {
|
| PickAccountIdForAccount("67890", "other@gmail.com");
|
|
|
| token_service()->UpdateCredentials(account_id2, "refresh_token");
|
| + cookie_manager_service()->SetListAccountsResponseTwoAccounts(
|
| + "other@gmail.com", "user@gmail.com");
|
|
|
| EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction());
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id));
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id2));
|
|
|
| - SetFakeResponse(list_accounts_url().spec(),
|
| - "[\"f\", [[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1], "
|
| - "[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
|
| - net::HTTP_OK, net::URLRequestStatus::SUCCESS);
|
| -
|
| AccountReconcilor* reconcilor = GetMockReconcilor();
|
| reconcilor->StartReconcile();
|
|
|
| @@ -697,15 +681,13 @@ TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) {
|
| TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) {
|
| const std::string account_id =
|
| ConnectProfileToAccount("12345", "user@gmail.com");
|
| + cookie_manager_service()->SetListAccountsResponseOneAccount(
|
| + "user@gmail.com");
|
|
|
| AccountReconcilor* reconcilor =
|
| AccountReconcilorFactory::GetForProfile(profile());
|
| ASSERT_TRUE(reconcilor);
|
|
|
| - SetFakeResponse(list_accounts_url().spec(),
|
| - "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
|
| - net::HTTP_OK, net::URLRequestStatus::SUCCESS);
|
| -
|
| ASSERT_FALSE(reconcilor->is_reconcile_started_);
|
| reconcilor->StartReconcile();
|
| ASSERT_TRUE(reconcilor->is_reconcile_started_);
|
| @@ -720,14 +702,11 @@ TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) {
|
| const std::string account_id2 =
|
| PickAccountIdForAccount("67890", "other@gmail.com");
|
| token_service()->UpdateCredentials(account_id2, "refresh_token");
|
| + cookie_manager_service()->SetListAccountsResponseTwoAccountsWithExpiry(
|
| + "user@gmail.com", true, "other@gmail.com", false);
|
|
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id));
|
|
|
| - SetFakeResponse(list_accounts_url().spec(),
|
| - "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0],"
|
| - "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
|
| - net::HTTP_OK, net::URLRequestStatus::SUCCESS);
|
| -
|
| AccountReconcilor* reconcilor =
|
| AccountReconcilorFactory::GetForProfile(profile());
|
| ASSERT_TRUE(reconcilor);
|
| @@ -745,13 +724,11 @@ TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) {
|
| TEST_F(AccountReconcilorTest, AddAccountToCookieCompletedWithBogusAccount) {
|
| const std::string account_id =
|
| ConnectProfileToAccount("12345", "user@gmail.com");
|
| + cookie_manager_service()->SetListAccountsResponseOneAccountWithExpiry(
|
| + "user@gmail.com", true);
|
|
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(account_id));
|
|
|
| - SetFakeResponse(list_accounts_url().spec(),
|
| - "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 0]]]",
|
| - net::HTTP_OK, net::URLRequestStatus::SUCCESS);
|
| -
|
| AccountReconcilor* reconcilor =
|
| AccountReconcilorFactory::GetForProfile(profile());
|
| ASSERT_TRUE(reconcilor);
|
|
|