| 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 "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 "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/prefs/testing_pref_service.h" | 11 #include "base/prefs/testing_pref_service.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/prefs/browser_prefs.h" | 16 #include "chrome/browser/prefs/browser_prefs.h" |
| 17 #include "chrome/browser/signin/chrome_signin_manager_delegate.h" | 17 #include "chrome/browser/signin/chrome_signin_client.h" |
| 18 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 18 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
| 19 #include "chrome/browser/signin/fake_profile_oauth2_token_service_wrapper.h" | 19 #include "chrome/browser/signin/fake_profile_oauth2_token_service_wrapper.h" |
| 20 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 20 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 22 #include "chrome/browser/signin/signin_manager_factory.h" | 22 #include "chrome/browser/signin/signin_manager_factory.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 25 #include "chrome/test/base/testing_browser_process.h" | 25 #include "chrome/test/base/testing_browser_process.h" |
| 26 #include "chrome/test/base/testing_profile.h" | 26 #include "chrome/test/base/testing_profile.h" |
| 27 #include "content/public/browser/child_process_security_policy.h" | 27 #include "content/public/browser/child_process_security_policy.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 48 " \"token_type\": \"Bearer\"" | 48 " \"token_type\": \"Bearer\"" |
| 49 "}"; | 49 "}"; |
| 50 | 50 |
| 51 const char kUberAuthTokenURLFormat[] = "?source=%s&issueuberauth=1"; | 51 const char kUberAuthTokenURLFormat[] = "?source=%s&issueuberauth=1"; |
| 52 | 52 |
| 53 BrowserContextKeyedService* SigninManagerBuild( | 53 BrowserContextKeyedService* SigninManagerBuild( |
| 54 content::BrowserContext* context) { | 54 content::BrowserContext* context) { |
| 55 SigninManager* service = NULL; | 55 SigninManager* service = NULL; |
| 56 Profile* profile = static_cast<Profile*>(context); | 56 Profile* profile = static_cast<Profile*>(context); |
| 57 service = new SigninManager( | 57 service = new SigninManager( |
| 58 scoped_ptr<SigninManagerDelegate>( | 58 scoped_ptr<SigninClient>(new ChromeSigninClient(profile))); |
| 59 new ChromeSigninManagerDelegate(profile))); | |
| 60 service->Initialize(profile, NULL); | 59 service->Initialize(profile, NULL); |
| 61 return service; | 60 return service; |
| 62 } | 61 } |
| 63 | 62 |
| 64 class TestSigninManagerObserver : public SigninManagerBase::Observer { | 63 class TestSigninManagerObserver : public SigninManagerBase::Observer { |
| 65 public: | 64 public: |
| 66 TestSigninManagerObserver() : num_failed_signins_(0), | 65 TestSigninManagerObserver() : num_failed_signins_(0), |
| 67 num_successful_signins_(0), | 66 num_successful_signins_(0), |
| 68 num_signouts_(0) { | 67 num_signouts_(0) { |
| 69 } | 68 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 manager_ = static_cast<SigninManager*>( | 139 manager_ = static_cast<SigninManager*>( |
| 141 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 140 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
| 142 profile(), SigninManagerBuild)); | 141 profile(), SigninManagerBuild)); |
| 143 manager_->AddObserver(&test_observer_); | 142 manager_->AddObserver(&test_observer_); |
| 144 } | 143 } |
| 145 | 144 |
| 146 // Create a naked signin manager if integration with PKSs is not needed. | 145 // Create a naked signin manager if integration with PKSs is not needed. |
| 147 void CreateNakedSigninManager() { | 146 void CreateNakedSigninManager() { |
| 148 DCHECK(!manager_); | 147 DCHECK(!manager_); |
| 149 naked_manager_.reset(new SigninManager( | 148 naked_manager_.reset(new SigninManager( |
| 150 scoped_ptr<SigninManagerDelegate>( | 149 scoped_ptr<SigninClient>(new ChromeSigninClient(profile())))); |
| 151 new ChromeSigninManagerDelegate(profile())))); | |
| 152 | 150 |
| 153 manager_ = naked_manager_.get(); | 151 manager_ = naked_manager_.get(); |
| 154 manager_->AddObserver(&test_observer_); | 152 manager_->AddObserver(&test_observer_); |
| 155 } | 153 } |
| 156 | 154 |
| 157 // Shuts down |manager_|. | 155 // Shuts down |manager_|. |
| 158 void ShutDownManager() { | 156 void ShutDownManager() { |
| 159 DCHECK(manager_); | 157 DCHECK(manager_); |
| 160 manager_->RemoveObserver(&test_observer_); | 158 manager_->RemoveObserver(&test_observer_); |
| 161 manager_->Shutdown(); | 159 manager_->Shutdown(); |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); | 571 profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); |
| 574 EXPECT_EQ("external@example.com", manager_->GetAuthenticatedUsername()); | 572 EXPECT_EQ("external@example.com", manager_->GetAuthenticatedUsername()); |
| 575 } | 573 } |
| 576 | 574 |
| 577 TEST_F(SigninManagerTest, SigninNotAllowed) { | 575 TEST_F(SigninManagerTest, SigninNotAllowed) { |
| 578 std::string user("user@google.com"); | 576 std::string user("user@google.com"); |
| 579 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user); | 577 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user); |
| 580 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); | 578 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); |
| 581 CreateSigninManagerAsService(); | 579 CreateSigninManagerAsService(); |
| 582 } | 580 } |
| OLD | NEW |