| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/signin/signin_tracker.h" | 5 #include "chrome/browser/signin/signin_tracker.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 class MockObserver : public SigninTracker::Observer { | 38 class MockObserver : public SigninTracker::Observer { |
| 39 public: | 39 public: |
| 40 MockObserver() {} | 40 MockObserver() {} |
| 41 ~MockObserver() {} | 41 ~MockObserver() {} |
| 42 | 42 |
| 43 MOCK_METHOD1(SigninFailed, void(const GoogleServiceAuthError&)); | 43 MOCK_METHOD1(SigninFailed, void(const GoogleServiceAuthError&)); |
| 44 MOCK_METHOD0(SigninSuccess, void(void)); | 44 MOCK_METHOD0(SigninSuccess, void(void)); |
| 45 MOCK_METHOD1(MergeSessionComplete, void(const GoogleServiceAuthError&)); |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 } // namespace | 48 } // namespace |
| 48 | 49 |
| 49 class SigninTrackerTest : public testing::Test { | 50 class SigninTrackerTest : public testing::Test { |
| 50 public: | 51 public: |
| 52 #if defined(OS_CHROMEOS) |
| 53 typedef FakeSigninManagerBase FakeSigninManagerForTesting; |
| 54 #else |
| 55 typedef FakeSigninManager FakeSigninManagerForTesting; |
| 56 #endif |
| 57 |
| 51 SigninTrackerTest() {} | 58 SigninTrackerTest() {} |
| 52 virtual void SetUp() OVERRIDE { | 59 virtual void SetUp() OVERRIDE { |
| 53 TestingProfile::Builder builder; | 60 TestingProfile::Builder builder; |
| 54 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), | 61 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), |
| 55 FakeProfileOAuth2TokenService::Build); | 62 FakeProfileOAuth2TokenService::Build); |
| 56 | 63 |
| 57 profile_ = builder.Build(); | 64 profile_ = builder.Build(); |
| 58 | 65 |
| 59 fake_oauth2_token_service_ = | 66 fake_oauth2_token_service_ = |
| 60 static_cast<FakeProfileOAuth2TokenService*>( | 67 static_cast<FakeProfileOAuth2TokenService*>( |
| 61 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get())); | 68 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get())); |
| 62 | 69 |
| 63 mock_signin_manager_ = static_cast<FakeSigninManagerBase*>( | 70 mock_signin_manager_ = static_cast<FakeSigninManagerForTesting*>( |
| 64 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 71 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
| 65 profile_.get(), FakeSigninManagerBase::Build)); | 72 profile_.get(), FakeSigninManagerForTesting::Build)); |
| 66 mock_signin_manager_->Initialize(profile_.get(), NULL); | 73 mock_signin_manager_->Initialize(profile_.get(), NULL); |
| 67 | 74 |
| 68 tracker_.reset(new SigninTracker(profile_.get(), &observer_)); | 75 tracker_.reset(new SigninTracker(profile_.get(), &observer_)); |
| 69 } | 76 } |
| 70 virtual void TearDown() OVERRIDE { | 77 virtual void TearDown() OVERRIDE { |
| 71 tracker_.reset(); | 78 tracker_.reset(); |
| 72 profile_.reset(); | 79 profile_.reset(); |
| 73 } | 80 } |
| 74 | 81 |
| 75 content::TestBrowserThreadBundle thread_bundle_; | 82 content::TestBrowserThreadBundle thread_bundle_; |
| 76 scoped_ptr<SigninTracker> tracker_; | 83 scoped_ptr<SigninTracker> tracker_; |
| 77 scoped_ptr<TestingProfile> profile_; | 84 scoped_ptr<TestingProfile> profile_; |
| 78 FakeSigninManagerBase* mock_signin_manager_; | 85 FakeSigninManagerForTesting* mock_signin_manager_; |
| 79 FakeProfileOAuth2TokenService* fake_oauth2_token_service_; | 86 FakeProfileOAuth2TokenService* fake_oauth2_token_service_; |
| 80 MockObserver observer_; | 87 MockObserver observer_; |
| 81 }; | 88 }; |
| 82 | 89 |
| 83 TEST_F(SigninTrackerTest, SignInFails) { | 90 TEST_F(SigninTrackerTest, SignInFails) { |
| 84 // SIGNIN_FAILED notification should result in a SigninFailed callback. | 91 // SIGNIN_FAILED notification should result in a SigninFailed callback. |
| 85 const GoogleServiceAuthError error( | 92 const GoogleServiceAuthError error( |
| 86 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 93 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 87 EXPECT_CALL(observer_, SigninSuccess()).Times(0); | 94 EXPECT_CALL(observer_, SigninSuccess()).Times(0); |
| 88 EXPECT_CALL(observer_, SigninFailed(error)); | 95 EXPECT_CALL(observer_, SigninFailed(error)); |
| 89 | 96 |
| 90 content::NotificationService::current()->Notify( | 97 content::NotificationService::current()->Notify( |
| 91 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, | 98 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, |
| 92 content::Source<Profile>(profile_.get()), | 99 content::Source<Profile>(profile_.get()), |
| 93 content::Details<const GoogleServiceAuthError>(&error)); | 100 content::Details<const GoogleServiceAuthError>(&error)); |
| 94 } | 101 } |
| 95 | 102 |
| 96 TEST_F(SigninTrackerTest, SignInSucceeds) { | 103 TEST_F(SigninTrackerTest, SignInSucceeds) { |
| 97 EXPECT_CALL(observer_, SigninSuccess()); | 104 EXPECT_CALL(observer_, SigninSuccess()); |
| 98 EXPECT_CALL(observer_, SigninFailed(_)).Times(0); | 105 EXPECT_CALL(observer_, SigninFailed(_)).Times(0); |
| 99 | 106 |
| 100 mock_signin_manager_->SetAuthenticatedUsername("user@gmail.com"); | 107 mock_signin_manager_->SetAuthenticatedUsername("user@gmail.com"); |
| 101 fake_oauth2_token_service_->IssueRefreshToken("refresh_token"); | 108 fake_oauth2_token_service_->IssueRefreshToken("refresh_token"); |
| 102 } | 109 } |
| OLD | NEW |