diff options
author | ckocagil@chromium.org <ckocagil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-23 05:09:41 +0000 |
---|---|---|
committer | ckocagil@chromium.org <ckocagil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-23 05:09:41 +0000 |
commit | b000edf932ccdf22ed58ec0905bd4befecb1832c (patch) | |
tree | 13770eed95df612216330cb93316deff1024cd5b /chrome/browser/signin/account_reconcilor_unittest.cc | |
parent | 253044d433881f89846adb69a58122e47c2523e5 (diff) | |
download | chromium_src-b000edf932ccdf22ed58ec0905bd4befecb1832c.zip chromium_src-b000edf932ccdf22ed58ec0905bd4befecb1832c.tar.gz chromium_src-b000edf932ccdf22ed58ec0905bd4befecb1832c.tar.bz2 |
Revert of https://codereview.chromium.org/83773002/
Reason for revert: Speculatively reverting to fix the cros breakage: http://build.chromium.org/p/chromium.chromiumos/builders/Linux%20ChromiumOS%20Tests%20%28dbg%29%282%29/builds/10024
TBR=acleung@chromium.org,guohui@chromium.org,atwilson@chromium.org,rogerta@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=320351
Review URL: https://codereview.chromium.org/120653002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242355 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/signin/account_reconcilor_unittest.cc')
-rw-r--r-- | chrome/browser/signin/account_reconcilor_unittest.cc | 183 |
1 files changed, 5 insertions, 178 deletions
diff --git a/chrome/browser/signin/account_reconcilor_unittest.cc b/chrome/browser/signin/account_reconcilor_unittest.cc index 320b050..ca5a8d2 100644 --- a/chrome/browser/signin/account_reconcilor_unittest.cc +++ b/chrome/browser/signin/account_reconcilor_unittest.cc @@ -3,8 +3,6 @@ // found in the LICENSE file. #include "base/memory/scoped_ptr.h" -#include "base/run_loop.h" -#include "base/time/time.h" #include "chrome/browser/signin/account_reconcilor.h" #include "chrome/browser/signin/account_reconcilor_factory.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" @@ -15,7 +13,6 @@ #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/test/base/testing_profile.h" #include "content/public/test/test_browser_thread_bundle.h" -#include "net/url_request/test_url_fetcher_factory.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -39,25 +36,15 @@ class AccountReconcilorTest : public testing::Test { FakeSigninManagerForTesting* signin_manager() { return signin_manager_; } FakeProfileOAuth2TokenService* token_service() { return token_service_; } - void SetFakeResponse(const std::string& url, - const std::string& data, - net::HttpStatusCode code, - net::URLRequestStatus::Status status) { - url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status); - } - private: content::TestBrowserThreadBundle bundle_; scoped_ptr<TestingProfile> profile_; FakeSigninManagerForTesting* signin_manager_; FakeProfileOAuth2TokenService* token_service_; - net::FakeURLFetcherFactory url_fetcher_factory_; }; AccountReconcilorTest::AccountReconcilorTest() - : signin_manager_(NULL), - token_service_(NULL), - url_fetcher_factory_(NULL) {} + : signin_manager_(NULL), token_service_(NULL) {} void AccountReconcilorTest::SetUp() { TestingProfile::Builder builder; @@ -87,191 +74,31 @@ void AccountReconcilorTest::TearDown() { TEST_F(AccountReconcilorTest, Basic) { AccountReconcilor* reconcilor = AccountReconcilorFactory::GetForProfile(profile()); - ASSERT_TRUE(reconcilor); + ASSERT_TRUE(NULL != reconcilor); ASSERT_EQ(profile(), reconcilor->profile()); } #if !defined(OS_CHROMEOS) - TEST_F(AccountReconcilorTest, SigninManagerRegistration) { AccountReconcilor* reconcilor = AccountReconcilorFactory::GetForProfile(profile()); - ASSERT_TRUE(reconcilor); + ASSERT_TRUE(NULL != reconcilor); ASSERT_FALSE(reconcilor->IsPeriodicReconciliationRunning()); - ASSERT_FALSE(reconcilor->IsRegisteredWithTokenService()); signin_manager()->OnExternalSigninCompleted(kTestEmail); ASSERT_TRUE(reconcilor->IsPeriodicReconciliationRunning()); - ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); signin_manager()->SignOut(); ASSERT_FALSE(reconcilor->IsPeriodicReconciliationRunning()); - ASSERT_FALSE(reconcilor->IsRegisteredWithTokenService()); -} - -TEST_F(AccountReconcilorTest, Reauth) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - - AccountReconcilor* reconcilor = - AccountReconcilorFactory::GetForProfile(profile()); - ASSERT_TRUE(reconcilor); - ASSERT_TRUE(reconcilor->IsPeriodicReconciliationRunning()); - ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); - - // Simulate reauth. The state of the reconcilor should not change. - signin_manager()->OnExternalSigninCompleted(kTestEmail); - ASSERT_TRUE(reconcilor->IsPeriodicReconciliationRunning()); - ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); } - -#endif // !defined(OS_CHROMEOS) +#endif TEST_F(AccountReconcilorTest, ProfileAlreadyConnected) { signin_manager()->SetAuthenticatedUsername(kTestEmail); AccountReconcilor* reconcilor = AccountReconcilorFactory::GetForProfile(profile()); - ASSERT_TRUE(reconcilor); + ASSERT_TRUE(NULL != reconcilor); ASSERT_TRUE(reconcilor->IsPeriodicReconciliationRunning()); - ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); -} - -TEST_F(AccountReconcilorTest, GetAccountsFromCookieSuccess) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - AccountReconcilor* reconcilor = - AccountReconcilorFactory::GetForProfile(profile()); - ASSERT_TRUE(reconcilor); - - SetFakeResponse("https://accounts.google.com/ListAccounts", - "[\"foo\", [[\"bar\", 0, \"name\", \"email\", \"photo\", 0, 0, 0]]]", - net::HTTP_OK, net::URLRequestStatus::SUCCESS); - - reconcilor->GetAccountsFromCookie(); - ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); - - base::RunLoop().RunUntilIdle(); - ASSERT_TRUE(reconcilor->AreGaiaAccountsSet()); - const std::vector<std::string>& accounts = - reconcilor->GetGaiaAccountsForTesting(); - ASSERT_EQ(1u, accounts.size()); - ASSERT_EQ("email", accounts[0]); -} - -TEST_F(AccountReconcilorTest, GetAccountsFromCookieFailure) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - AccountReconcilor* reconcilor = - AccountReconcilorFactory::GetForProfile(profile()); - ASSERT_TRUE(reconcilor); - - SetFakeResponse("https://accounts.google.com/ListAccounts", "", - net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS); - - reconcilor->GetAccountsFromCookie(); - ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); - - base::RunLoop().RunUntilIdle(); - ASSERT_TRUE(reconcilor->AreGaiaAccountsSet()); - ASSERT_EQ(0u, reconcilor->GetGaiaAccountsForTesting().size()); -} - -TEST_F(AccountReconcilorTest, ValidateAccountsFromTokens) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - token_service()->UpdateCredentials(kTestEmail, "refresh_token"); - - AccountReconcilor* reconcilor = - AccountReconcilorFactory::GetForProfile(profile()); - ASSERT_TRUE(reconcilor); - - reconcilor->ValidateAccountsFromTokenService(); - ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); - - SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", - "{\"id\":\"foo\"}", net::HTTP_OK, net::URLRequestStatus::SUCCESS); - token_service()->IssueTokenForAllPendingRequests("access_token", - base::Time::Now() + base::TimeDelta::FromHours(1)); - - base::RunLoop().RunUntilIdle(); - ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); - ASSERT_EQ(1u, reconcilor->GetValidChromeAccountsForTesting().size()); - ASSERT_EQ(0u, reconcilor->GetInvalidChromeAccountsForTesting().size()); -} - -TEST_F(AccountReconcilorTest, ValidateAccountsFromTokensFailedUserInfo) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - token_service()->UpdateCredentials(kTestEmail, "refresh_token"); - - AccountReconcilor* reconcilor = - AccountReconcilorFactory::GetForProfile(profile()); - ASSERT_TRUE(reconcilor); - - reconcilor->ValidateAccountsFromTokenService(); - ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); - - SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", - "", net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS); - token_service()->IssueTokenForAllPendingRequests("access_token", - base::Time::Now() + base::TimeDelta::FromHours(1)); - - base::RunLoop().RunUntilIdle(); - ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); - ASSERT_EQ(0u, reconcilor->GetValidChromeAccountsForTesting().size()); - ASSERT_EQ(1u, reconcilor->GetInvalidChromeAccountsForTesting().size()); -} - -TEST_F(AccountReconcilorTest, ValidateAccountsFromTokensFailedTokenRequest) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - token_service()->UpdateCredentials(kTestEmail, "refresh_token"); - - AccountReconcilor* reconcilor = - AccountReconcilorFactory::GetForProfile(profile()); - ASSERT_TRUE(reconcilor); - - reconcilor->ValidateAccountsFromTokenService(); - ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); - - token_service()->IssueErrorForAllPendingRequests( - GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); - - base::RunLoop().RunUntilIdle(); - ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); - ASSERT_EQ(0u, reconcilor->GetValidChromeAccountsForTesting().size()); - ASSERT_EQ(1u, reconcilor->GetInvalidChromeAccountsForTesting().size()); -} - -TEST_F(AccountReconcilorTest, StartReconcileAction) { - signin_manager()->SetAuthenticatedUsername(kTestEmail); - token_service()->UpdateCredentials(kTestEmail, "refresh_token"); - - AccountReconcilor* reconcilor = - AccountReconcilorFactory::GetForProfile(profile()); - ASSERT_TRUE(reconcilor); - - SetFakeResponse("https://accounts.google.com/ListAccounts", - "[\"foo\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0], " - "[\"b\", 0, \"n\", \"other@gmail.com\", \"p\", 0, 0, 0]]]", - net::HTTP_OK, net::URLRequestStatus::SUCCESS); - - reconcilor->StartReconcileAction(); - ASSERT_FALSE(reconcilor->AreGaiaAccountsSet()); - ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); - - base::RunLoop().RunUntilIdle(); - ASSERT_TRUE(reconcilor->AreGaiaAccountsSet()); - ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); - ASSERT_EQ(2u, reconcilor->GetGaiaAccountsForTesting().size()); - - SetFakeResponse("https://www.googleapis.com/oauth2/v1/userinfo", - "", net::HTTP_NOT_FOUND, net::URLRequestStatus::SUCCESS); - token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token", - base::Time::Now() + base::TimeDelta::FromHours(1)); - - base::RunLoop().RunUntilIdle(); - ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); - - token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", - base::Time::Now() + base::TimeDelta::FromHours(1)); - - base::RunLoop().RunUntilIdle(); - ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); } |