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" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 num_signouts_++; | 84 num_signouts_++; |
85 } | 85 } |
86 }; | 86 }; |
87 | 87 |
88 } // namespace | 88 } // namespace |
89 | 89 |
90 | 90 |
91 class SigninManagerTest : public testing::Test { | 91 class SigninManagerTest : public testing::Test { |
92 public: | 92 public: |
93 SigninManagerTest() : manager_(NULL) {} | 93 SigninManagerTest() : manager_(NULL) {} |
94 virtual ~SigninManagerTest() {} | 94 ~SigninManagerTest() override {} |
95 | 95 |
96 virtual void SetUp() override { | 96 void SetUp() override { |
97 manager_ = NULL; | 97 manager_ = NULL; |
98 prefs_.reset(new TestingPrefServiceSimple); | 98 prefs_.reset(new TestingPrefServiceSimple); |
99 chrome::RegisterLocalState(prefs_->registry()); | 99 chrome::RegisterLocalState(prefs_->registry()); |
100 TestingBrowserProcess::GetGlobal()->SetLocalState( | 100 TestingBrowserProcess::GetGlobal()->SetLocalState( |
101 prefs_.get()); | 101 prefs_.get()); |
102 TestingProfile::Builder builder; | 102 TestingProfile::Builder builder; |
103 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), | 103 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), |
104 BuildFakeProfileOAuth2TokenService); | 104 BuildFakeProfileOAuth2TokenService); |
105 builder.AddTestingFactory(ChromeSigninClientFactory::GetInstance(), | 105 builder.AddTestingFactory(ChromeSigninClientFactory::GetInstance(), |
106 signin::BuildTestSigninClient); | 106 signin::BuildTestSigninClient); |
107 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), | 107 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), |
108 SigninManagerBuild); | 108 SigninManagerBuild); |
109 profile_ = builder.Build(); | 109 profile_ = builder.Build(); |
110 | 110 |
111 static_cast<TestSigninClient*>( | 111 static_cast<TestSigninClient*>( |
112 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile()))-> | 112 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile()))-> |
113 SetURLRequestContext(profile_->GetRequestContext()); | 113 SetURLRequestContext(profile_->GetRequestContext()); |
114 } | 114 } |
115 | 115 |
116 virtual void TearDown() override { | 116 void TearDown() override { |
117 if (manager_) | 117 if (manager_) |
118 manager_->RemoveObserver(&test_observer_); | 118 manager_->RemoveObserver(&test_observer_); |
119 | 119 |
120 // Destroy the SigninManager here, because it relies on profile() which is | 120 // Destroy the SigninManager here, because it relies on profile() which is |
121 // freed in the base class. | 121 // freed in the base class. |
122 if (naked_manager_) { | 122 if (naked_manager_) { |
123 naked_manager_->Shutdown(); | 123 naked_manager_->Shutdown(); |
124 naked_manager_.reset(NULL); | 124 naked_manager_.reset(NULL); |
125 } | 125 } |
126 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); | 126 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); | 342 profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); |
343 EXPECT_EQ("external@example.com", manager_->GetAuthenticatedUsername()); | 343 EXPECT_EQ("external@example.com", manager_->GetAuthenticatedUsername()); |
344 } | 344 } |
345 | 345 |
346 TEST_F(SigninManagerTest, SigninNotAllowed) { | 346 TEST_F(SigninManagerTest, SigninNotAllowed) { |
347 std::string user("user@google.com"); | 347 std::string user("user@google.com"); |
348 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user); | 348 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user); |
349 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); | 349 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); |
350 SetUpSigninManagerAsService(); | 350 SetUpSigninManagerAsService(); |
351 } | 351 } |
OLD | NEW |