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

Side by Side Diff: chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc

Issue 1257623002: Componentize FakeSigninManager and SigninManager prefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comment Created 5 years, 5 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
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 "base/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" 13 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h"
14 #include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h" 14 #include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h"
15 #include "chrome/browser/prefs/browser_prefs.h" 15 #include "chrome/browser/prefs/browser_prefs.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/signin/account_fetcher_service_factory.h" 17 #include "chrome/browser/signin/account_fetcher_service_factory.h"
18 #include "chrome/browser/signin/chrome_signin_client_factory.h" 18 #include "chrome/browser/signin/chrome_signin_client_factory.h"
19 #include "chrome/browser/signin/fake_account_fetcher_service.h" 19 #include "chrome/browser/signin/fake_account_fetcher_service.h"
20 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" 20 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
21 #include "chrome/browser/signin/fake_signin_manager.h" 21 #include "chrome/browser/signin/fake_signin_manager_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/browser/signin/test_signin_client_builder.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_pref_service_syncable.h" 26 #include "chrome/test/base/testing_pref_service_syncable.h"
27 #include "chrome/test/base/testing_profile.h" 27 #include "chrome/test/base/testing_profile.h"
28 #include "components/policy/core/browser/browser_policy_connector.h" 28 #include "components/policy/core/browser/browser_policy_connector.h"
29 #include "components/policy/core/common/cloud/cloud_external_data_manager.h" 29 #include "components/policy/core/common/cloud/cloud_external_data_manager.h"
30 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 30 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
31 #include "components/policy/core/common/cloud/mock_device_management_service.h" 31 #include "components/policy/core/common/cloud/mock_device_management_service.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 " \"expires_in\": 3600," 76 " \"expires_in\": 3600,"
77 " \"token_type\": \"Bearer\"" 77 " \"token_type\": \"Bearer\""
78 "}"; 78 "}";
79 #endif 79 #endif
80 80
81 const char kHostedDomainResponse[] = 81 const char kHostedDomainResponse[] =
82 "{" 82 "{"
83 " \"hd\": \"test.com\"" 83 " \"hd\": \"test.com\""
84 "}"; 84 "}";
85 85
86 class SigninManagerFake : public FakeSigninManager {
87 public:
88 explicit SigninManagerFake(Profile* profile)
89 : FakeSigninManager(profile) {
90 Initialize(NULL);
91 }
92
93 void ForceSignOut() {
94 // Allow signing out now.
95 prohibit_signout_ = false;
96 SignOut(signin_metrics::SIGNOUT_TEST);
97 }
98
99 static scoped_ptr<KeyedService> Build(content::BrowserContext* profile) {
100 return make_scoped_ptr(
101 new SigninManagerFake(static_cast<Profile*>(profile)));
102 }
103 };
104
105 UserCloudPolicyManager* BuildCloudPolicyManager( 86 UserCloudPolicyManager* BuildCloudPolicyManager(
106 content::BrowserContext* context) { 87 content::BrowserContext* context) {
107 MockUserCloudPolicyStore* store = new MockUserCloudPolicyStore(); 88 MockUserCloudPolicyStore* store = new MockUserCloudPolicyStore();
108 EXPECT_CALL(*store, Load()).Times(AnyNumber()); 89 EXPECT_CALL(*store, Load()).Times(AnyNumber());
109 90
110 return new UserCloudPolicyManager( 91 return new UserCloudPolicyManager(
111 scoped_ptr<UserCloudPolicyStore>(store), 92 scoped_ptr<UserCloudPolicyStore>(store),
112 base::FilePath(), 93 base::FilePath(),
113 scoped_ptr<CloudExternalDataManager>(), 94 scoped_ptr<CloudExternalDataManager>(),
114 base::ThreadTaskRunnerHandle::Get(), 95 base::ThreadTaskRunnerHandle::Get(),
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // UserCloudPolicyManagerFactory isn't a real 157 // UserCloudPolicyManagerFactory isn't a real
177 // BrowserContextKeyedServiceFactory (it derives from 158 // BrowserContextKeyedServiceFactory (it derives from
178 // BrowserContextKeyedBaseFactory and exposes its own APIs to get 159 // BrowserContextKeyedBaseFactory and exposes its own APIs to get
179 // instances) so we have to inject our testing factory via a special 160 // instances) so we have to inject our testing factory via a special
180 // API before creating the profile. 161 // API before creating the profile.
181 UserCloudPolicyManagerFactory::GetInstance()->RegisterTestingFactory( 162 UserCloudPolicyManagerFactory::GetInstance()->RegisterTestingFactory(
182 BuildCloudPolicyManager); 163 BuildCloudPolicyManager);
183 TestingProfile::Builder builder; 164 TestingProfile::Builder builder;
184 builder.SetPrefService(scoped_ptr<PrefServiceSyncable>(prefs.Pass())); 165 builder.SetPrefService(scoped_ptr<PrefServiceSyncable>(prefs.Pass()));
185 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), 166 builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
186 SigninManagerFake::Build); 167 BuildFakeSigninManagerBase);
187 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), 168 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(),
188 BuildFakeProfileOAuth2TokenService); 169 BuildFakeProfileOAuth2TokenService);
189 builder.AddTestingFactory(AccountFetcherServiceFactory::GetInstance(), 170 builder.AddTestingFactory(AccountFetcherServiceFactory::GetInstance(),
190 FakeAccountFetcherService::BuildForTests); 171 FakeAccountFetcherService::BuildForTests);
191 builder.AddTestingFactory(ChromeSigninClientFactory::GetInstance(), 172 builder.AddTestingFactory(ChromeSigninClientFactory::GetInstance(),
192 signin::BuildTestSigninClient); 173 signin::BuildTestSigninClient);
193 174
194 profile_ = builder.Build().Pass(); 175 profile_ = builder.Build().Pass();
195 url_factory_.set_remove_fetcher_on_delete(true); 176 url_factory_.set_remove_fetcher_on_delete(true);
196 177
197 signin_manager_ = static_cast<SigninManagerFake*>( 178 signin_manager_ = static_cast<FakeSigninManager*>(
198 SigninManagerFactory::GetForProfile(profile_.get())); 179 SigninManagerFactory::GetForProfile(profile_.get()));
199 // Tests are responsible for freeing the UserCloudPolicyManager instances 180 // Tests are responsible for freeing the UserCloudPolicyManager instances
200 // they inject. 181 // they inject.
201 manager_.reset(UserCloudPolicyManagerFactory::GetForBrowserContext( 182 manager_.reset(UserCloudPolicyManagerFactory::GetForBrowserContext(
202 profile_.get())); 183 profile_.get()));
203 manager_->Init(&schema_registry_); 184 manager_->Init(&schema_registry_);
204 mock_store_ = static_cast<MockUserCloudPolicyStore*>( 185 mock_store_ = static_cast<MockUserCloudPolicyStore*>(
205 manager_->core()->store()); 186 manager_->core()->store());
206 DCHECK(mock_store_); 187 DCHECK(mock_store_);
207 AddProfile(); 188 AddProfile();
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 MockUserCloudPolicyStore* mock_store_; // Not owned. 343 MockUserCloudPolicyStore* mock_store_; // Not owned.
363 SchemaRegistry schema_registry_; 344 SchemaRegistry schema_registry_;
364 scoped_ptr<UserCloudPolicyManager> manager_; 345 scoped_ptr<UserCloudPolicyManager> manager_;
365 346
366 // BrowserPolicyConnector and UrlFetcherFactory want to initialize and free 347 // BrowserPolicyConnector and UrlFetcherFactory want to initialize and free
367 // various components asynchronously via tasks, so create fake threads here. 348 // various components asynchronously via tasks, so create fake threads here.
368 content::TestBrowserThreadBundle thread_bundle_; 349 content::TestBrowserThreadBundle thread_bundle_;
369 350
370 net::TestURLFetcherFactory url_factory_; 351 net::TestURLFetcherFactory url_factory_;
371 352
372 SigninManagerFake* signin_manager_; 353 FakeSigninManager* signin_manager_;
373 354
374 // Used in conjunction with OnRegisterCompleted() to test client registration 355 // Used in conjunction with OnRegisterCompleted() to test client registration
375 // callbacks. 356 // callbacks.
376 std::string dm_token_; 357 std::string dm_token_;
377 std::string client_id_; 358 std::string client_id_;
378 359
379 // True if OnRegisterCompleted() was called. 360 // True if OnRegisterCompleted() was called.
380 bool register_completed_; 361 bool register_completed_;
381 362
382 // Weak ptr to the MockDeviceManagementService (object is owned by the 363 // Weak ptr to the MockDeviceManagementService (object is owned by the
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 base::RunLoop().RunUntilIdle(); 813 base::RunLoop().RunUntilIdle();
833 EXPECT_FALSE(manager_->IsClientRegistered()); 814 EXPECT_FALSE(manager_->IsClientRegistered());
834 #if !defined(OS_ANDROID) 815 #if !defined(OS_ANDROID)
835 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); 816 EXPECT_FALSE(signin_manager_->IsSignoutProhibited());
836 #endif 817 #endif
837 } 818 }
838 819
839 } // namespace 820 } // namespace
840 821
841 } // namespace policy 822 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698