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

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: Rebase 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
« no previous file with comments | « chrome/browser/android/chrome_startup_flags.cc ('k') | chrome/browser/sync/about_sync_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 20 matching lines...) Expand all
51 ~MockObserver() {} 52 ~MockObserver() {}
52 53
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(new TestingProfile()); 65 profile_.reset(new TestingProfile());
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 69
68 mock_signin_manager_ = static_cast<FakeSigninManagerBase*>( 70 mock_signin_manager_ = static_cast<FakeSigninManagerBase*>(
69 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( 71 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
70 profile_.get(), FakeSigninManagerBase::Build)); 72 profile_.get(), FakeSigninManagerBase::Build));
71 mock_signin_manager_->Initialize(profile_.get(), NULL); 73 mock_signin_manager_->Initialize(profile_.get(), NULL);
(...skipping 11 matching lines...) Expand all
83 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, 85 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
84 content::Source<Profile>(profile_.get()), 86 content::Source<Profile>(profile_.get()),
85 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); 87 content::Details<const GoogleServiceSigninSuccessDetails>(&details));
86 } 88 }
87 89
88 scoped_ptr<SigninTracker> tracker_; 90 scoped_ptr<SigninTracker> tracker_;
89 scoped_ptr<TestingProfile> profile_; 91 scoped_ptr<TestingProfile> profile_;
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 base::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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 GoogleServiceAuthError error( 170 GoogleServiceAuthError error(
167 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 171 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
168 EXPECT_CALL(observer_, SigninFailed(error)); 172 EXPECT_CALL(observer_, SigninFailed(error));
169 TokenService::TokenRequestFailedDetails failed( 173 TokenService::TokenRequestFailedDetails failed(
170 GaiaConstants::kGaiaOAuth2LoginRefreshToken, error); 174 GaiaConstants::kGaiaOAuth2LoginRefreshToken, error);
171 content::NotificationService::current()->Notify( 175 content::NotificationService::current()->Notify(
172 chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, 176 chrome::NOTIFICATION_TOKEN_REQUEST_FAILED,
173 content::Source<TokenService>(mock_token_service_), 177 content::Source<TokenService>(mock_token_service_),
174 content::Details<const TokenService::TokenRequestFailedDetails>(&failed)); 178 content::Details<const TokenService::TokenRequestFailedDetails>(&failed));
175 } 179 }
OLDNEW
« no previous file with comments | « chrome/browser/android/chrome_startup_flags.cc ('k') | chrome/browser/sync/about_sync_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698