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_manager.h" | 5 #include "chrome/browser/signin/signin_manager.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 #include "testing/gmock/include/gmock/gmock.h" | 40 #include "testing/gmock/include/gmock/gmock.h" |
41 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
45 KeyedService* SigninManagerBuild(content::BrowserContext* context) { | 45 KeyedService* SigninManagerBuild(content::BrowserContext* context) { |
46 SigninManager* service = NULL; | 46 SigninManager* service = NULL; |
47 Profile* profile = static_cast<Profile*>(context); | 47 Profile* profile = static_cast<Profile*>(context); |
48 service = new SigninManager( | 48 service = new SigninManager( |
49 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile)); | 49 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile), |
| 50 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)); |
50 service->Initialize(profile, NULL); | 51 service->Initialize(profile, NULL); |
51 return service; | 52 return service; |
52 } | 53 } |
53 | 54 |
54 class TestSigninManagerObserver : public SigninManagerBase::Observer { | 55 class TestSigninManagerObserver : public SigninManagerBase::Observer { |
55 public: | 56 public: |
56 TestSigninManagerObserver() : num_failed_signins_(0), | 57 TestSigninManagerObserver() : num_failed_signins_(0), |
57 num_successful_signins_(0), | 58 num_successful_signins_(0), |
58 num_signouts_(0) { | 59 num_signouts_(0) { |
59 } | 60 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 DCHECK(!naked_manager_); | 132 DCHECK(!naked_manager_); |
132 manager_ = static_cast<SigninManager*>( | 133 manager_ = static_cast<SigninManager*>( |
133 SigninManagerFactory::GetForProfile(profile())); | 134 SigninManagerFactory::GetForProfile(profile())); |
134 manager_->AddObserver(&test_observer_); | 135 manager_->AddObserver(&test_observer_); |
135 } | 136 } |
136 | 137 |
137 // Create a naked signin manager if integration with PKSs is not needed. | 138 // Create a naked signin manager if integration with PKSs is not needed. |
138 void CreateNakedSigninManager() { | 139 void CreateNakedSigninManager() { |
139 DCHECK(!manager_); | 140 DCHECK(!manager_); |
140 naked_manager_.reset(new SigninManager( | 141 naked_manager_.reset(new SigninManager( |
141 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile()))); | 142 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile()), |
| 143 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()))); |
142 | 144 |
143 manager_ = naked_manager_.get(); | 145 manager_ = naked_manager_.get(); |
144 manager_->AddObserver(&test_observer_); | 146 manager_->AddObserver(&test_observer_); |
145 } | 147 } |
146 | 148 |
147 // Shuts down |manager_|. | 149 // Shuts down |manager_|. |
148 void ShutDownManager() { | 150 void ShutDownManager() { |
149 DCHECK(manager_); | 151 DCHECK(manager_); |
150 manager_->RemoveObserver(&test_observer_); | 152 manager_->RemoveObserver(&test_observer_); |
151 manager_->Shutdown(); | 153 manager_->Shutdown(); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); | 333 profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); |
332 EXPECT_EQ("external@example.com", manager_->GetAuthenticatedUsername()); | 334 EXPECT_EQ("external@example.com", manager_->GetAuthenticatedUsername()); |
333 } | 335 } |
334 | 336 |
335 TEST_F(SigninManagerTest, SigninNotAllowed) { | 337 TEST_F(SigninManagerTest, SigninNotAllowed) { |
336 std::string user("user@google.com"); | 338 std::string user("user@google.com"); |
337 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user); | 339 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user); |
338 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); | 340 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); |
339 SetUpSigninManagerAsService(); | 341 SetUpSigninManagerAsService(); |
340 } | 342 } |
OLD | NEW |