| 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 43f97c4d7d348a7b3f0f698bbafce6fa8c13519f..92a1e5698a83a0c12640a0442e036cce2b91647f 100644
|
| --- a/chrome/browser/signin/account_reconcilor_unittest.cc
|
| +++ b/chrome/browser/signin/account_reconcilor_unittest.cc
|
| @@ -12,6 +12,7 @@
|
| #include "chrome/browser/prefs/pref_service_syncable.h"
|
| #include "chrome/browser/signin/account_reconcilor_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"
|
| @@ -87,6 +88,9 @@ class AccountReconcilorTest : public ::testing::TestWithParam<bool> {
|
| FakeSigninManagerForTesting* signin_manager() { return signin_manager_; }
|
| FakeProfileOAuth2TokenService* token_service() { return token_service_; }
|
| TestSigninClient* test_signin_client() { return test_signin_client_; }
|
| + FakeGaiaCookieManagerService* cookie_manager_service() {
|
| + return cookie_manager_service_;
|
| + }
|
| base::HistogramTester* histogram_tester() { return &histogram_tester_; }
|
|
|
| void SetFakeResponse(const std::string& url,
|
| @@ -107,7 +111,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_;
|
| }
|
| @@ -118,11 +121,11 @@ class AccountReconcilorTest : public ::testing::TestWithParam<bool> {
|
| FakeSigninManagerForTesting* signin_manager_;
|
| FakeProfileOAuth2TokenService* token_service_;
|
| TestSigninClient* test_signin_client_;
|
| + 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);
|
| @@ -132,6 +135,7 @@ AccountReconcilorTest::AccountReconcilorTest()
|
| : signin_manager_(NULL),
|
| token_service_(NULL),
|
| test_signin_client_(NULL),
|
| + cookie_manager_service_(NULL),
|
| mock_reconcilor_(NULL),
|
| url_fetcher_factory_(NULL) {}
|
|
|
| @@ -143,16 +147,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());
|
| @@ -163,6 +161,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(),
|
| @@ -184,6 +185,13 @@ void AccountReconcilorTest::SetUp() {
|
| 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() {
|
| @@ -273,22 +281,19 @@ TEST_F(AccountReconcilorTest, ProfileAlreadyConnected) {
|
| TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) {
|
| signin_manager()->SetAuthenticatedUsername(kTestEmail);
|
| token_service()->UpdateCredentials(kTestEmail, "refresh_token");
|
| + cookie_manager_service()->SetListAccountsResponseOneAccountWithExpiry(
|
| + kTestEmail, true);
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction(kTestEmail));
|
| +
|
| 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("user@gmail.com", accounts[0].first);
|
| }
|
| @@ -296,18 +301,18 @@ TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) {
|
| TEST_F(AccountReconcilorTest, GetAccountsFromCookieFailure) {
|
| signin_manager()->SetAuthenticatedUsername(kTestEmail);
|
| token_service()->UpdateCredentials(kTestEmail, "refresh_token");
|
| + 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) {
|
| @@ -318,13 +323,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(kTestEmail);
|
|
|
| reconcilor->StartReconcile();
|
| ASSERT_TRUE(reconcilor->is_reconcile_started_);
|
| - ASSERT_FALSE(reconcilor->AreGaiaAccountsSet());
|
|
|
| base::RunLoop().RunUntilIdle();
|
| ASSERT_FALSE(reconcilor->is_reconcile_started_);
|
| @@ -348,9 +350,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_);
|
| }
|
|
|
| @@ -428,18 +432,14 @@ TEST_P(AccountReconcilorTest, StartReconcileContentSettingsInvalidPattern) {
|
| TEST_P(AccountReconcilorTest, StartReconcileNoopWithDots) {
|
| signin_manager()->SetAuthenticatedUsername("Dot.S@gmail.com");
|
| token_service()->UpdateCredentials("Dot.S@gmail.com", "refresh_token");
|
| + 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_);
|
|
|
| @@ -453,18 +453,14 @@ TEST_P(AccountReconcilorTest, StartReconcileNoopMultiple) {
|
| signin_manager()->SetAuthenticatedUsername("user@gmail.com");
|
| token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
|
| token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
|
| + cookie_manager_service()->SetListAccountsResponseTwoAccounts(
|
| + "user@gmail.com", "other@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], "
|
| - "[\"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_);
|
|
|
| @@ -480,13 +476,11 @@ TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) {
|
| signin_manager()->SetAuthenticatedUsername("user@gmail.com");
|
| token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
|
| token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
|
| + cookie_manager_service()->SetListAccountsResponseOneAccount(
|
| + "user@gmail.com");
|
|
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com"));
|
|
|
| - 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();
|
|
|
| @@ -509,15 +503,12 @@ TEST_P(AccountReconcilorTest, StartReconcileAddToCookie) {
|
| TEST_P(AccountReconcilorTest, StartReconcileRemoveFromCookie) {
|
| signin_manager()->SetAuthenticatedUsername("user@gmail.com");
|
| token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
|
| + cookie_manager_service()->SetListAccountsResponseTwoAccounts(
|
| + "user@gmail.com", "other@gmail.com");
|
|
|
| EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction());
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com"));
|
|
|
| - 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_);
|
| @@ -541,16 +532,12 @@ TEST_P(AccountReconcilorTest, StartReconcileAddToCookieTwice) {
|
| signin_manager()->SetAuthenticatedUsername("user@gmail.com");
|
| token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
|
| token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
|
| + cookie_manager_service()->SetListAccountsResponseOneAccount(
|
| + "user@gmail.com");
|
|
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com"));
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("third@gmail.com"));
|
|
|
| - 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();
|
|
|
| @@ -570,13 +557,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("third@gmail.com", "refresh_token");
|
|
|
| @@ -609,16 +593,13 @@ TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) {
|
| signin_manager()->SetAuthenticatedUsername("user@gmail.com");
|
| token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
|
| token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
|
| + cookie_manager_service()->SetListAccountsResponseTwoAccounts(
|
| + "other@gmail.com", "user@gmail.com");
|
|
|
| EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction());
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com"));
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com"));
|
|
|
| - 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();
|
|
|
| @@ -644,15 +625,13 @@ TEST_P(AccountReconcilorTest, StartReconcileBadPrimary) {
|
| TEST_P(AccountReconcilorTest, StartReconcileOnlyOnce) {
|
| signin_manager()->SetAuthenticatedUsername(kTestEmail);
|
| token_service()->UpdateCredentials(kTestEmail, "refresh_token");
|
| + 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_);
|
| @@ -665,14 +644,11 @@ TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) {
|
| signin_manager()->SetAuthenticatedUsername("user@gmail.com");
|
| token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
|
| token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
|
| + cookie_manager_service()->SetListAccountsResponseTwoAccountsWithExpiry(
|
| + "user@gmail.com", true, "other@gmail.com", false);
|
|
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com"));
|
|
|
| - 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);
|
| @@ -690,13 +666,11 @@ TEST_P(AccountReconcilorTest, StartReconcileWithSessionInfoExpiredDefault) {
|
| TEST_F(AccountReconcilorTest, AddAccountToCookieCompletedWithBogusAccount) {
|
| signin_manager()->SetAuthenticatedUsername("user@gmail.com");
|
| token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
|
| + cookie_manager_service()->SetListAccountsResponseOneAccountWithExpiry(
|
| + "user@gmail.com", true);
|
|
|
| EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("user@gmail.com"));
|
|
|
| - 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);
|
|
|