| 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 "components/signin/core/browser/signin_manager.h" | 5 #include "components/signin/core/browser/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" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/prefs/testing_pref_service.h" | 13 #include "base/prefs/testing_pref_service.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
| 18 #include "chrome/browser/prefs/browser_prefs.h" | 18 #include "chrome/browser/prefs/browser_prefs.h" |
| 19 #include "chrome/browser/signin/chrome_signin_client_factory.h" | 19 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
| 20 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 20 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
| 21 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 21 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| 22 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 22 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 23 #include "chrome/browser/signin/signin_manager_factory.h" | 23 #include "chrome/browser/signin/signin_manager_factory.h" |
| 24 #include "chrome/browser/signin/test_signin_client_builder.h" |
| 24 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 26 #include "chrome/test/base/testing_browser_process.h" | 27 #include "chrome/test/base/testing_browser_process.h" |
| 27 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
| 28 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 29 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 30 #include "components/signin/core/browser/test_signin_client.h" |
| 29 #include "content/public/browser/child_process_security_policy.h" | 31 #include "content/public/browser/child_process_security_policy.h" |
| 30 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
| 31 #include "content/public/test/test_browser_thread_bundle.h" | 33 #include "content/public/test/test_browser_thread_bundle.h" |
| 32 #include "google_apis/gaia/gaia_constants.h" | 34 #include "google_apis/gaia/gaia_constants.h" |
| 33 #include "google_apis/gaia/gaia_urls.h" | 35 #include "google_apis/gaia/gaia_urls.h" |
| 34 #include "net/cookies/cookie_monster.h" | 36 #include "net/cookies/cookie_monster.h" |
| 35 #include "net/url_request/test_url_fetcher_factory.h" | 37 #include "net/url_request/test_url_fetcher_factory.h" |
| 36 #include "net/url_request/url_request.h" | 38 #include "net/url_request/url_request.h" |
| 37 #include "net/url_request/url_request_context_getter.h" | 39 #include "net/url_request/url_request_context_getter.h" |
| 38 #include "net/url_request/url_request_status.h" | 40 #include "net/url_request/url_request_status.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 94 |
| 93 virtual void SetUp() OVERRIDE { | 95 virtual void SetUp() OVERRIDE { |
| 94 manager_ = NULL; | 96 manager_ = NULL; |
| 95 prefs_.reset(new TestingPrefServiceSimple); | 97 prefs_.reset(new TestingPrefServiceSimple); |
| 96 chrome::RegisterLocalState(prefs_->registry()); | 98 chrome::RegisterLocalState(prefs_->registry()); |
| 97 TestingBrowserProcess::GetGlobal()->SetLocalState( | 99 TestingBrowserProcess::GetGlobal()->SetLocalState( |
| 98 prefs_.get()); | 100 prefs_.get()); |
| 99 TestingProfile::Builder builder; | 101 TestingProfile::Builder builder; |
| 100 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), | 102 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), |
| 101 BuildFakeProfileOAuth2TokenService); | 103 BuildFakeProfileOAuth2TokenService); |
| 104 builder.AddTestingFactory(ChromeSigninClientFactory::GetInstance(), |
| 105 signin::BuildTestSigninClient); |
| 102 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), | 106 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), |
| 103 SigninManagerBuild); | 107 SigninManagerBuild); |
| 104 profile_ = builder.Build(); | 108 profile_ = builder.Build(); |
| 109 |
| 110 static_cast<TestSigninClient*>( |
| 111 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile()))-> |
| 112 SetURLRequestContext(profile_->GetRequestContext()); |
| 105 } | 113 } |
| 106 | 114 |
| 107 virtual void TearDown() OVERRIDE { | 115 virtual void TearDown() OVERRIDE { |
| 108 if (manager_) | 116 if (manager_) |
| 109 manager_->RemoveObserver(&test_observer_); | 117 manager_->RemoveObserver(&test_observer_); |
| 110 | 118 |
| 111 // Destroy the SigninManager here, because it relies on profile() which is | 119 // Destroy the SigninManager here, because it relies on profile() which is |
| 112 // freed in the base class. | 120 // freed in the base class. |
| 113 if (naked_manager_) { | 121 if (naked_manager_) { |
| 114 naked_manager_->Shutdown(); | 122 naked_manager_->Shutdown(); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); | 341 profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); |
| 334 EXPECT_EQ("external@example.com", manager_->GetAuthenticatedUsername()); | 342 EXPECT_EQ("external@example.com", manager_->GetAuthenticatedUsername()); |
| 335 } | 343 } |
| 336 | 344 |
| 337 TEST_F(SigninManagerTest, SigninNotAllowed) { | 345 TEST_F(SigninManagerTest, SigninNotAllowed) { |
| 338 std::string user("user@google.com"); | 346 std::string user("user@google.com"); |
| 339 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user); | 347 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user); |
| 340 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); | 348 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); |
| 341 SetUpSigninManagerAsService(); | 349 SetUpSigninManagerAsService(); |
| 342 } | 350 } |
| OLD | NEW |