| 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" |
| 11 #include "chrome/browser/signin/fake_auth_status_provider.h" | 11 #include "chrome/browser/signin/fake_auth_status_provider.h" |
| 12 #include "chrome/browser/signin/fake_signin_manager.h" | 12 #include "chrome/browser/signin/fake_signin_manager.h" |
| 13 #include "chrome/browser/signin/signin_manager.h" | 13 #include "chrome/browser/signin/signin_manager.h" |
| 14 #include "chrome/browser/signin/signin_manager_factory.h" | 14 #include "chrome/browser/signin/signin_manager_factory.h" |
| 15 #include "chrome/browser/signin/token_service.h" | 15 #include "chrome/browser/signin/token_service.h" |
| 16 #include "chrome/browser/signin/token_service_factory.h" | 16 #include "chrome/browser/signin/token_service_factory.h" |
| 17 #include "chrome/browser/sync/profile_sync_service_factory.h" | 17 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 18 #include "chrome/browser/sync/profile_sync_service_mock.h" | 18 #include "chrome/browser/sync/profile_sync_service_mock.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/test/test_browser_thread.h" |
| 21 #include "google_apis/gaia/gaia_constants.h" | 22 #include "google_apis/gaia/gaia_constants.h" |
| 22 #include "google_apis/gaia/google_service_auth_error.h" | 23 #include "google_apis/gaia/google_service_auth_error.h" |
| 23 | 24 |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 27 |
| 27 using ::testing::_; | 28 using ::testing::_; |
| 28 using ::testing::AnyNumber; | 29 using ::testing::AnyNumber; |
| 29 using ::testing::Mock; | 30 using ::testing::Mock; |
| 30 using ::testing::Return; | 31 using ::testing::Return; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 51 | 52 |
| 52 MOCK_METHOD0(GaiaCredentialsValid, void(void)); | 53 MOCK_METHOD0(GaiaCredentialsValid, void(void)); |
| 53 MOCK_METHOD1(SigninFailed, void(const GoogleServiceAuthError&)); | 54 MOCK_METHOD1(SigninFailed, void(const GoogleServiceAuthError&)); |
| 54 MOCK_METHOD0(SigninSuccess, void(void)); | 55 MOCK_METHOD0(SigninSuccess, void(void)); |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 } // namespace | 58 } // namespace |
| 58 | 59 |
| 59 class SigninTrackerTest : public testing::Test { | 60 class SigninTrackerTest : public testing::Test { |
| 60 public: | 61 public: |
| 61 SigninTrackerTest() {} | 62 SigninTrackerTest() |
| 63 : ui_thread_(content::BrowserThread::UI, &ui_loop_) {} |
| 62 virtual void SetUp() OVERRIDE { | 64 virtual void SetUp() OVERRIDE { |
| 63 profile_.reset(ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 65 profile_.reset(ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 64 mock_token_service_ = static_cast<MockTokenService*>( | 66 mock_token_service_ = static_cast<MockTokenService*>( |
| 65 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 67 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 66 profile_.get(), BuildMockTokenService)); | 68 profile_.get(), BuildMockTokenService)); |
| 67 mock_pss_ = static_cast<ProfileSyncServiceMock*>( | 69 mock_pss_ = static_cast<ProfileSyncServiceMock*>( |
| 68 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 70 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 69 profile_.get(), | 71 profile_.get(), |
| 70 ProfileSyncServiceMock::BuildMockProfileSyncService)); | 72 ProfileSyncServiceMock::BuildMockProfileSyncService)); |
| 71 mock_pss_->Initialize(); | 73 mock_pss_->Initialize(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 83 virtual void TearDown() OVERRIDE { | 85 virtual void TearDown() OVERRIDE { |
| 84 tracker_.reset(); | 86 tracker_.reset(); |
| 85 profile_.reset(); | 87 profile_.reset(); |
| 86 } | 88 } |
| 87 scoped_ptr<SigninTracker> tracker_; | 89 scoped_ptr<SigninTracker> tracker_; |
| 88 scoped_ptr<TestingProfile> profile_; | 90 scoped_ptr<TestingProfile> profile_; |
| 89 ProfileSyncServiceMock* mock_pss_; | 91 ProfileSyncServiceMock* mock_pss_; |
| 90 FakeSigninManagerBase* mock_signin_manager_; | 92 FakeSigninManagerBase* mock_signin_manager_; |
| 91 MockTokenService* mock_token_service_; | 93 MockTokenService* mock_token_service_; |
| 92 MockObserver observer_; | 94 MockObserver observer_; |
| 95 MessageLoop ui_loop_; |
| 96 content::TestBrowserThread ui_thread_; |
| 93 }; | 97 }; |
| 94 | 98 |
| 95 TEST_F(SigninTrackerTest, GaiaSignInFailed) { | 99 TEST_F(SigninTrackerTest, GaiaSignInFailed) { |
| 96 // SIGNIN_FAILED notification should result in a SigninFailed callback. | 100 // SIGNIN_FAILED notification should result in a SigninFailed callback. |
| 97 GoogleServiceAuthError error( | 101 GoogleServiceAuthError error( |
| 98 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 102 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 99 EXPECT_CALL(observer_, SigninFailed(error)); | 103 EXPECT_CALL(observer_, SigninFailed(error)); |
| 100 content::NotificationService::current()->Notify( | 104 content::NotificationService::current()->Notify( |
| 101 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, | 105 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, |
| 102 content::Source<Profile>(profile_.get()), | 106 content::Source<Profile>(profile_.get()), |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 | 367 |
| 364 TEST_F(SigninTrackerTest, SigninFailedWhenInitializing) { | 368 TEST_F(SigninTrackerTest, SigninFailedWhenInitializing) { |
| 365 tracker_.reset(); | 369 tracker_.reset(); |
| 366 // SigninFailed() should be called. | 370 // SigninFailed() should be called. |
| 367 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); | 371 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); |
| 368 EXPECT_CALL(observer_, SigninFailed(error)); | 372 EXPECT_CALL(observer_, SigninFailed(error)); |
| 369 tracker_.reset(new SigninTracker(profile_.get(), &observer_, | 373 tracker_.reset(new SigninTracker(profile_.get(), &observer_, |
| 370 SigninTracker::SERVICES_INITIALIZING)); | 374 SigninTracker::SERVICES_INITIALIZING)); |
| 371 tracker_->OnStateChanged(); | 375 tracker_->OnStateChanged(); |
| 372 } | 376 } |
| OLD | NEW |