Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Unified Diff: chrome/browser/signin/signin_tracker_unittest.cc

Issue 19567004: Convert SigninTracker to use OAuth2TokenService notifications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/signin/signin_tracker_unittest.cc
diff --git a/chrome/browser/signin/signin_tracker_unittest.cc b/chrome/browser/signin/signin_tracker_unittest.cc
index ac2d366ebb4d258f28c09441b6afc3c23bef7f3b..0298effad7d7145643351238f30e09ff9e6c09c8 100644
--- a/chrome/browser/signin/signin_tracker_unittest.cc
+++ b/chrome/browser/signin/signin_tracker_unittest.cc
@@ -11,10 +11,10 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/fake_auth_status_provider.h"
#include "chrome/browser/signin/fake_signin_manager.h"
+#include "chrome/browser/signin/profile_oauth2_token_service.h"
+#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
-#include "chrome/browser/signin/token_service.h"
-#include "chrome/browser/signin/token_service_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/profile_sync_service_mock.h"
#include "content/public/browser/notification_service.h"
@@ -33,17 +33,19 @@ using ::testing::ReturnRef;
namespace {
-class MockTokenService : public TokenService {
+class MockOAuth2TokenService : public ProfileOAuth2TokenService {
public:
- MockTokenService() { }
- virtual ~MockTokenService() { }
+ MockOAuth2TokenService() : ProfileOAuth2TokenService() {}
+ virtual ~MockOAuth2TokenService() {}
- MOCK_CONST_METHOD1(HasTokenForService, bool(const char*));
+ MOCK_METHOD0(GetRefreshToken, std::string());
Andrew T Wilson (Slow) 2013/08/19 15:23:06 BTW, this is a misuse of GMock (using a mock inste
Roger Tawa OOO till Jul 10th 2013/08/29 19:28:41 Changed to use new fake o2ts.
};
-BrowserContextKeyedService* BuildMockTokenService(
+BrowserContextKeyedService* BuildMockOAuth2TokenService(
content::BrowserContext* profile) {
- return new MockTokenService;
+ MockOAuth2TokenService* token_service = new MockOAuth2TokenService;
+ token_service->Initialize(static_cast<Profile*>(profile));
+ return token_service;
}
class MockObserver : public SigninTracker::Observer {
@@ -62,9 +64,10 @@ class SigninTrackerTest : public testing::Test {
SigninTrackerTest() {}
virtual void SetUp() OVERRIDE {
profile_.reset(new TestingProfile());
- mock_token_service_ = static_cast<MockTokenService*>(
- TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse(
- profile_.get(), BuildMockTokenService));
+ mock_oauth2_token_service_ = static_cast<MockOAuth2TokenService*>(
+ ProfileOAuth2TokenServiceFactory::GetInstance()->
Andrew T Wilson (Slow) 2013/08/19 15:23:06 After I land my CL, this is going to crash - you'l
Roger Tawa OOO till Jul 10th 2013/08/29 19:28:41 Done.
+ SetTestingFactoryAndUse(profile_.get(),
+ BuildMockOAuth2TokenService));
mock_signin_manager_ = static_cast<FakeSigninManagerBase*>(
SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
@@ -90,7 +93,7 @@ class SigninTrackerTest : public testing::Test {
scoped_ptr<SigninTracker> tracker_;
scoped_ptr<TestingProfile> profile_;
FakeSigninManagerBase* mock_signin_manager_;
- MockTokenService* mock_token_service_;
+ MockOAuth2TokenService* mock_oauth2_token_service_;
MockObserver observer_;
};
@@ -109,8 +112,8 @@ TEST_F(SigninTrackerTest, GaiaSignInSucceeded) {
// SIGNIN_SUCCEEDED notification should lead us to get a SigninSuccess()
// callback.
EXPECT_CALL(observer_, SigninSuccess());
- EXPECT_CALL(*mock_token_service_, HasTokenForService(_))
- .WillRepeatedly(Return(true));
+ EXPECT_CALL(*mock_oauth2_token_service_, GetRefreshToken())
+ .WillRepeatedly(Return("refresh_token"));
SendSigninSuccessful();
}
@@ -119,12 +122,8 @@ TEST_F(SigninTrackerTest, NoGaiaSigninWhenOAuthTokensNotAvailable) {
// callback if our oauth token hasn't been fetched.
EXPECT_CALL(observer_, SigninSuccess()).Times(0);
EXPECT_CALL(observer_, SigninFailed(_)).Times(0);
- EXPECT_CALL(*mock_token_service_,
- HasTokenForService(GaiaConstants::kSyncService))
- .WillRepeatedly(Return(true));
- EXPECT_CALL(*mock_token_service_,
- HasTokenForService(GaiaConstants::kGaiaOAuth2LoginRefreshToken))
- .WillRepeatedly(Return(false));
+ EXPECT_CALL(*mock_oauth2_token_service_, GetRefreshToken())
+ .WillRepeatedly(Return(""));
SendSigninSuccessful();
}
@@ -132,23 +131,14 @@ TEST_F(SigninTrackerTest, GaiaSigninAfterOAuthTokenBecomesAvailable) {
// SIGNIN_SUCCESSFUL notification should not result in a SigninSuccess()
// callback until after our oauth token has been fetched.
EXPECT_CALL(observer_, SigninSuccess()).Times(0);
- EXPECT_CALL(*mock_token_service_,
- HasTokenForService(GaiaConstants::kSyncService))
- .WillRepeatedly(Return(true));
- EXPECT_CALL(*mock_token_service_,
- HasTokenForService(GaiaConstants::kGaiaOAuth2LoginRefreshToken))
- .WillRepeatedly(Return(false));
+ EXPECT_CALL(*mock_oauth2_token_service_, GetRefreshToken())
+ .WillRepeatedly(Return(""));
SendSigninSuccessful();
- Mock::VerifyAndClearExpectations(mock_token_service_);
+
EXPECT_CALL(observer_, SigninSuccess());
- TokenService::TokenAvailableDetails available(
- GaiaConstants::kGaiaOAuth2LoginRefreshToken, "foo_token");
- EXPECT_CALL(*mock_token_service_, HasTokenForService(_))
- .WillRepeatedly(Return(true));
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_TOKEN_AVAILABLE,
- content::Source<TokenService>(mock_token_service_),
- content::Details<const TokenService::TokenAvailableDetails>(&available));
+ EXPECT_CALL(*mock_oauth2_token_service_, GetRefreshToken())
+ .WillRepeatedly(Return("refresh_token"));
+ tracker_->OnRefreshTokenAvailable("username@gmail.com");
Andrew T Wilson (Slow) 2013/08/19 15:23:06 If you change to use FakeProfileOAuth2TokenService
Roger Tawa OOO till Jul 10th 2013/08/29 19:28:41 Done.
}
TEST_F(SigninTrackerTest, SigninFailedWhenTokenFetchFails) {
@@ -156,22 +146,13 @@ TEST_F(SigninTrackerTest, SigninFailedWhenTokenFetchFails) {
// We should not get any SigninFailed() callbacks until we issue the
// TOKEN_REQUEST_FAILED notification.
EXPECT_CALL(observer_, SigninFailed(_)).Times(0);
- EXPECT_CALL(*mock_token_service_,
- HasTokenForService(GaiaConstants::kSyncService))
- .WillRepeatedly(Return(true));
- EXPECT_CALL(*mock_token_service_,
- HasTokenForService(GaiaConstants::kGaiaOAuth2LoginRefreshToken))
- .WillRepeatedly(Return(false));
+ EXPECT_CALL(*mock_oauth2_token_service_, GetRefreshToken())
+ .WillRepeatedly(Return(""));
SendSigninSuccessful();
Mock::VerifyAndClearExpectations(&observer_);
GoogleServiceAuthError error(
GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
EXPECT_CALL(observer_, SigninFailed(error));
- TokenService::TokenRequestFailedDetails failed(
- GaiaConstants::kGaiaOAuth2LoginRefreshToken, error);
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_TOKEN_REQUEST_FAILED,
- content::Source<TokenService>(mock_token_service_),
- content::Details<const TokenService::TokenRequestFailedDetails>(&failed));
+ tracker_->OnRefreshTokenRevoked("username@gmail.com", error);
Andrew T Wilson (Slow) 2013/08/19 15:23:06 Ditto for previous comment - you shouldn't have to
Roger Tawa OOO till Jul 10th 2013/08/29 19:28:41 Done.
}

Powered by Google App Engine
This is Rietveld 408576698