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

Side by Side Diff: chrome/browser/signin/signin_tracker_unittest.cc

Issue 15421011: Use OAuth2 token for sync (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix issues based on feedback Created 7 years, 6 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 unified diff | Download patch
OLDNEW
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 21 matching lines...) Expand all
52 53
53 MOCK_METHOD0(GaiaCredentialsValid, void(void)); 54 MOCK_METHOD0(GaiaCredentialsValid, void(void));
54 MOCK_METHOD1(SigninFailed, void(const GoogleServiceAuthError&)); 55 MOCK_METHOD1(SigninFailed, void(const GoogleServiceAuthError&));
55 MOCK_METHOD0(SigninSuccess, void(void)); 56 MOCK_METHOD0(SigninSuccess, void(void));
56 }; 57 };
57 58
58 } // namespace 59 } // namespace
59 60
60 class SigninTrackerTest : public testing::Test { 61 class SigninTrackerTest : public testing::Test {
61 public: 62 public:
62 SigninTrackerTest() {} 63 SigninTrackerTest()
64 : ui_thread_(content::BrowserThread::UI, &ui_loop_) {}
63 virtual void SetUp() OVERRIDE { 65 virtual void SetUp() OVERRIDE {
64 profile_.reset(new TestingProfile()); 66 profile_.reset(new TestingProfile());
65 mock_token_service_ = static_cast<MockTokenService*>( 67 mock_token_service_ = static_cast<MockTokenService*>(
66 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse( 68 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse(
67 profile_.get(), BuildMockTokenService)); 69 profile_.get(), BuildMockTokenService));
70 mock_signin_manager_ = static_cast<FakeSigninManagerBase*>(
71 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
72 profile_.get(), FakeSigninManagerBase::Build));
68 mock_pss_ = static_cast<ProfileSyncServiceMock*>( 73 mock_pss_ = static_cast<ProfileSyncServiceMock*>(
69 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( 74 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
70 profile_.get(), 75 profile_.get(),
71 ProfileSyncServiceMock::BuildMockProfileSyncService)); 76 ProfileSyncServiceMock::BuildMockProfileSyncService));
72 mock_pss_->Initialize(); 77 mock_pss_->Initialize();
73 78
74 mock_signin_manager_ = static_cast<FakeSigninManagerBase*>( 79 mock_signin_manager_ = static_cast<FakeSigninManagerBase*>(
75 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( 80 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
76 profile_.get(), FakeSigninManagerBase::Build)); 81 profile_.get(), FakeSigninManagerBase::Build));
77 mock_signin_manager_->Initialize(profile_.get(), NULL); 82 mock_signin_manager_->Initialize(profile_.get(), NULL);
78 // Make gmock not spam the output with information about these uninteresting 83 // Make gmock not spam the output with information about these uninteresting
79 // calls. 84 // calls.
80 EXPECT_CALL(*mock_pss_, AddObserver(_)).Times(AnyNumber()); 85 EXPECT_CALL(*mock_pss_, AddObserver(_)).Times(AnyNumber());
81 EXPECT_CALL(*mock_pss_, RemoveObserver(_)).Times(AnyNumber()); 86 EXPECT_CALL(*mock_pss_, RemoveObserver(_)).Times(AnyNumber());
82 tracker_.reset(new SigninTracker(profile_.get(), &observer_)); 87 tracker_.reset(new SigninTracker(profile_.get(), &observer_));
83 } 88 }
84 virtual void TearDown() OVERRIDE { 89 virtual void TearDown() OVERRIDE {
85 tracker_.reset(); 90 tracker_.reset();
86 profile_.reset(); 91 profile_.reset();
87 } 92 }
88 scoped_ptr<SigninTracker> tracker_; 93 scoped_ptr<SigninTracker> tracker_;
89 scoped_ptr<TestingProfile> profile_; 94 scoped_ptr<TestingProfile> profile_;
90 ProfileSyncServiceMock* mock_pss_; 95 ProfileSyncServiceMock* mock_pss_;
91 FakeSigninManagerBase* mock_signin_manager_; 96 FakeSigninManagerBase* mock_signin_manager_;
92 MockTokenService* mock_token_service_; 97 MockTokenService* mock_token_service_;
93 MockObserver observer_; 98 MockObserver observer_;
99 MessageLoop ui_loop_;
100 content::TestBrowserThread ui_thread_;
94 }; 101 };
95 102
96 TEST_F(SigninTrackerTest, GaiaSignInFailed) { 103 TEST_F(SigninTrackerTest, GaiaSignInFailed) {
97 // SIGNIN_FAILED notification should result in a SigninFailed callback. 104 // SIGNIN_FAILED notification should result in a SigninFailed callback.
98 GoogleServiceAuthError error( 105 GoogleServiceAuthError error(
99 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 106 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
100 EXPECT_CALL(observer_, SigninFailed(error)); 107 EXPECT_CALL(observer_, SigninFailed(error));
101 content::NotificationService::current()->Notify( 108 content::NotificationService::current()->Notify(
102 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, 109 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED,
103 content::Source<Profile>(profile_.get()), 110 content::Source<Profile>(profile_.get()),
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 370
364 TEST_F(SigninTrackerTest, SigninFailedWhenInitializing) { 371 TEST_F(SigninTrackerTest, SigninFailedWhenInitializing) {
365 tracker_.reset(); 372 tracker_.reset();
366 // SigninFailed() should be called. 373 // SigninFailed() should be called.
367 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); 374 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED);
368 EXPECT_CALL(observer_, SigninFailed(error)); 375 EXPECT_CALL(observer_, SigninFailed(error));
369 tracker_.reset(new SigninTracker(profile_.get(), &observer_, 376 tracker_.reset(new SigninTracker(profile_.get(), &observer_,
370 SigninTracker::SERVICES_INITIALIZING)); 377 SigninTracker::SERVICES_INITIALIZING));
371 tracker_->OnStateChanged(); 378 tracker_->OnStateChanged();
372 } 379 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698