| 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/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 MOCK_METHOD1(SigninFailed, void(const GoogleServiceAuthError&)); | 53 MOCK_METHOD1(SigninFailed, void(const GoogleServiceAuthError&)); |
| 54 MOCK_METHOD0(SigninSuccess, void(void)); | 54 MOCK_METHOD0(SigninSuccess, void(void)); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 class SigninTrackerTest : public testing::Test { | 59 class SigninTrackerTest : public testing::Test { |
| 60 public: | 60 public: |
| 61 SigninTrackerTest() {} | 61 SigninTrackerTest() {} |
| 62 virtual void SetUp() OVERRIDE { | 62 virtual void SetUp() OVERRIDE { |
| 63 profile_.reset(ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 63 profile_.reset(new TestingProfile()); |
| 64 mock_token_service_ = static_cast<MockTokenService*>( | 64 mock_token_service_ = static_cast<MockTokenService*>( |
| 65 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 65 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 66 profile_.get(), BuildMockTokenService)); | 66 profile_.get(), BuildMockTokenService)); |
| 67 mock_pss_ = static_cast<ProfileSyncServiceMock*>( | 67 mock_pss_ = static_cast<ProfileSyncServiceMock*>( |
| 68 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 68 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 69 profile_.get(), | 69 profile_.get(), |
| 70 ProfileSyncServiceMock::BuildMockProfileSyncService)); | 70 ProfileSyncServiceMock::BuildMockProfileSyncService)); |
| 71 mock_pss_->Initialize(); | 71 mock_pss_->Initialize(); |
| 72 | 72 |
| 73 mock_signin_manager_ = static_cast<FakeSigninManagerBase*>( | 73 mock_signin_manager_ = static_cast<FakeSigninManagerBase*>( |
| 74 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 74 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
| 75 profile_.get(), FakeSigninManagerBase::Build)); | 75 profile_.get(), FakeSigninManagerBase::Build)); |
| 76 | 76 mock_signin_manager_->Initialize(profile_.get()); |
| 77 // Make gmock not spam the output with information about these uninteresting | 77 // Make gmock not spam the output with information about these uninteresting |
| 78 // calls. | 78 // calls. |
| 79 EXPECT_CALL(*mock_pss_, AddObserver(_)).Times(AnyNumber()); | 79 EXPECT_CALL(*mock_pss_, AddObserver(_)).Times(AnyNumber()); |
| 80 EXPECT_CALL(*mock_pss_, RemoveObserver(_)).Times(AnyNumber()); | 80 EXPECT_CALL(*mock_pss_, RemoveObserver(_)).Times(AnyNumber()); |
| 81 tracker_.reset(new SigninTracker(profile_.get(), &observer_)); | 81 tracker_.reset(new SigninTracker(profile_.get(), &observer_)); |
| 82 } | 82 } |
| 83 virtual void TearDown() OVERRIDE { | 83 virtual void TearDown() OVERRIDE { |
| 84 tracker_.reset(); | 84 tracker_.reset(); |
| 85 profile_.reset(); | 85 profile_.reset(); |
| 86 } | 86 } |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); | 353 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); |
| 354 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()).WillRepeatedly( | 354 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()).WillRepeatedly( |
| 355 Return(false)); | 355 Return(false)); |
| 356 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(true)); | 356 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(true)); |
| 357 // Any error should result in SigninFailed() being called. | 357 // Any error should result in SigninFailed() being called. |
| 358 EXPECT_CALL(observer_, SigninFailed(error)); | 358 EXPECT_CALL(observer_, SigninFailed(error)); |
| 359 tracker_.reset(new SigninTracker(profile_.get(), &observer_, | 359 tracker_.reset(new SigninTracker(profile_.get(), &observer_, |
| 360 SigninTracker::SERVICES_INITIALIZING)); | 360 SigninTracker::SERVICES_INITIALIZING)); |
| 361 } | 361 } |
| 362 | 362 |
| 363 | |
| 364 TEST_F(SigninTrackerTest, SigninFailedWhenInitializing) { | 363 TEST_F(SigninTrackerTest, SigninFailedWhenInitializing) { |
| 365 tracker_.reset(); | 364 tracker_.reset(); |
| 366 // SigninFailed() should be called. | 365 // SigninFailed() should be called. |
| 367 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); | 366 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); |
| 368 EXPECT_CALL(observer_, SigninFailed(error)); | 367 EXPECT_CALL(observer_, SigninFailed(error)); |
| 369 tracker_.reset(new SigninTracker(profile_.get(), &observer_, | 368 tracker_.reset(new SigninTracker(profile_.get(), &observer_, |
| 370 SigninTracker::SERVICES_INITIALIZING)); | 369 SigninTracker::SERVICES_INITIALIZING)); |
| 371 tracker_->OnStateChanged(); | 370 tracker_->OnStateChanged(); |
| 372 } | 371 } |
| OLD | NEW |