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

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

Issue 23068005: Convert UserPolicySigninService to use OAuth2TokenService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
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/memory/ref_counted.h" 5 #include "base/memory/ref_counted.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.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/browser_policy_connector.h" 13 #include "chrome/browser/policy/browser_policy_connector.h"
14 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" 14 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
15 #include "chrome/browser/policy/cloud/mock_device_management_service.h" 15 #include "chrome/browser/policy/cloud/mock_device_management_service.h"
16 #include "chrome/browser/policy/cloud/mock_user_cloud_policy_store.h" 16 #include "chrome/browser/policy/cloud/mock_user_cloud_policy_store.h"
17 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" 17 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h"
18 #include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h" 18 #include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h"
19 #include "chrome/browser/prefs/browser_prefs.h" 19 #include "chrome/browser/prefs/browser_prefs.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/signin/fake_signin_manager.h" 21 #include "chrome/browser/signin/fake_signin_manager.h"
22 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
22 #include "chrome/browser/signin/signin_manager.h" 23 #include "chrome/browser/signin/signin_manager.h"
23 #include "chrome/browser/signin/signin_manager_factory.h" 24 #include "chrome/browser/signin/signin_manager_factory.h"
24 #include "chrome/test/base/testing_browser_process.h" 25 #include "chrome/test/base/testing_browser_process.h"
25 #include "chrome/test/base/testing_pref_service_syncable.h" 26 #include "chrome/test/base/testing_pref_service_syncable.h"
26 #include "chrome/test/base/testing_profile.h" 27 #include "chrome/test/base/testing_profile.h"
27 #include "content/public/browser/browser_context.h" 28 #include "content/public/browser/browser_context.h"
28 #include "content/public/browser/notification_details.h" 29 #include "content/public/browser/notification_details.h"
29 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/notification_source.h" 31 #include "content/public/browser/notification_source.h"
31 #include "content/public/test/test_browser_thread_bundle.h" 32 #include "content/public/test/test_browser_thread_bundle.h"
32 #include "google_apis/gaia/gaia_constants.h" 33 #include "google_apis/gaia/gaia_constants.h"
33 #include "google_apis/gaia/google_service_auth_error.h" 34 #include "google_apis/gaia/google_service_auth_error.h"
34 #include "net/http/http_status_code.h" 35 #include "net/http/http_status_code.h"
35 #include "net/url_request/test_url_fetcher_factory.h" 36 #include "net/url_request/test_url_fetcher_factory.h"
36 #include "net/url_request/url_request_context_getter.h" 37 #include "net/url_request/url_request_context_getter.h"
37 #include "net/url_request/url_request_status.h" 38 #include "net/url_request/url_request_status.h"
38 #include "testing/gmock/include/gmock/gmock.h" 39 #include "testing/gmock/include/gmock/gmock.h"
39 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
40 41
41 #if defined(OS_ANDROID) 42 #if defined(OS_ANDROID)
42 #include "chrome/browser/policy/cloud/user_policy_signin_service_android.h" 43 #include "chrome/browser/policy/cloud/user_policy_signin_service_android.h"
43 #include "chrome/browser/signin/android_profile_oauth2_token_service.h" 44 #include "chrome/browser/signin/android_profile_oauth2_token_service.h"
44 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
45 #else 45 #else
46 #include "chrome/browser/policy/cloud/user_policy_signin_service.h" 46 #include "chrome/browser/policy/cloud/user_policy_signin_service.h"
47 #include "chrome/browser/signin/token_service.h" 47 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
48 #include "chrome/browser/signin/token_service_factory.h"
49 #endif 48 #endif
50 49
51 namespace em = enterprise_management; 50 namespace em = enterprise_management;
52 51
53 using testing::AnyNumber; 52 using testing::AnyNumber;
54 using testing::Mock; 53 using testing::Mock;
55 using testing::_; 54 using testing::_;
56 55
57 namespace policy { 56 namespace policy {
58 57
(...skipping 28 matching lines...) Expand all
87 // Allow signing out now. 86 // Allow signing out now.
88 prohibit_signout_ = false; 87 prohibit_signout_ = false;
89 SignOut(); 88 SignOut();
90 } 89 }
91 90
92 static BrowserContextKeyedService* Build(content::BrowserContext* profile) { 91 static BrowserContextKeyedService* Build(content::BrowserContext* profile) {
93 return new SigninManagerFake(static_cast<Profile*>(profile)); 92 return new SigninManagerFake(static_cast<Profile*>(profile));
94 } 93 }
95 }; 94 };
96 95
96
97 #if defined(OS_ANDROID) 97 #if defined(OS_ANDROID)
98 98 // TODO(atwilson): Remove this when ProfileOAuth2TokenService supports
99 class FakeProfileOAuth2TokenService : public AndroidProfileOAuth2TokenService { 99 // usernames.
100 class FakeAndroidProfileOAuth2TokenService :
101 public AndroidProfileOAuth2TokenService {
100 public: 102 public:
101 explicit FakeProfileOAuth2TokenService(Profile* profile) { 103 explicit FakeAndroidProfileOAuth2TokenService(Profile* profile) {
102 Initialize(profile); 104 Initialize(profile);
103 } 105 }
104 106
105 static BrowserContextKeyedService* Build(content::BrowserContext* profile) { 107 static BrowserContextKeyedService* Build(content::BrowserContext* profile) {
106 return new FakeProfileOAuth2TokenService(static_cast<Profile*>(profile)); 108 return new FakeAndroidProfileOAuth2TokenService(
109 static_cast<Profile*>(profile));
107 } 110 }
108 111
109 // AndroidProfileOAuth2TokenService overrides: 112 // AndroidProfileOAuth2TokenService overrides:
110 virtual void FetchOAuth2Token( 113 virtual void FetchOAuth2TokenWithUsername(
114 RequestImpl* request,
111 const std::string& username, 115 const std::string& username,
112 const std::string& scope, 116 const std::string& scope) OVERRIDE {
113 const FetchOAuth2TokenCallback& callback) OVERRIDE {
114 ASSERT_TRUE(!HasPendingRequest()); 117 ASSERT_TRUE(!HasPendingRequest());
115 ASSERT_EQ(kTestUser, username); 118 ASSERT_EQ(kTestUser, username);
116 ASSERT_EQ(kCombinedScopes, scope); 119 ASSERT_EQ(kCombinedScopes, scope);
117 pending_callback_ = callback; 120 pending_request_ = request->AsWeakPtr();
118 } 121 }
119 122
120 void IssueToken(const std::string& token) { 123 void IssueToken(const std::string& token) {
121 ASSERT_TRUE(HasPendingRequest()); 124 ASSERT_TRUE(HasPendingRequest());
122 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); 125 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone();
123 if (token.empty()) 126 if (token.empty())
124 error = GoogleServiceAuthError::FromServiceError("fail"); 127 error = GoogleServiceAuthError::FromServiceError("fail");
125 pending_callback_.Run( 128 if (pending_request_) {
126 error, token, base::Time::Now() + base::TimeDelta::FromDays(1)); 129 pending_request_->InformConsumer(
127 pending_callback_.Reset(); 130 error,
131 token,
132 base::Time::Now() + base::TimeDelta::FromDays(1));
133 }
134 pending_request_.reset();
128 } 135 }
129 136
130 bool HasPendingRequest() const { 137 bool HasPendingRequest() const {
131 return !pending_callback_.is_null(); 138 return pending_request_;
132 } 139 }
133 140
134 private: 141 private:
135 FetchOAuth2TokenCallback pending_callback_; 142 WeakPtr<RequestImpl> pending_request_;
136 }; 143 };
137 144
138 #endif 145 #endif
139 146
140 class UserPolicySigninServiceTest : public testing::Test { 147 class UserPolicySigninServiceTest : public testing::Test {
141 public: 148 public:
142 UserPolicySigninServiceTest() 149 UserPolicySigninServiceTest()
143 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 150 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
144 register_completed_(false) {} 151 register_completed_(false) {}
145 152
(...skipping 29 matching lines...) Expand all
175 g_browser_process->browser_policy_connector()->Init( 182 g_browser_process->browser_policy_connector()->Init(
176 local_state_.get(), system_request_context); 183 local_state_.get(), system_request_context);
177 184
178 // Create a testing profile with cloud-policy-on-signin enabled, and bring 185 // Create a testing profile with cloud-policy-on-signin enabled, and bring
179 // up a UserCloudPolicyManager with a MockUserCloudPolicyStore. 186 // up a UserCloudPolicyManager with a MockUserCloudPolicyStore.
180 scoped_ptr<TestingPrefServiceSyncable> prefs( 187 scoped_ptr<TestingPrefServiceSyncable> prefs(
181 new TestingPrefServiceSyncable()); 188 new TestingPrefServiceSyncable());
182 chrome::RegisterUserProfilePrefs(prefs->registry()); 189 chrome::RegisterUserProfilePrefs(prefs->registry());
183 TestingProfile::Builder builder; 190 TestingProfile::Builder builder;
184 builder.SetPrefService(scoped_ptr<PrefServiceSyncable>(prefs.Pass())); 191 builder.SetPrefService(scoped_ptr<PrefServiceSyncable>(prefs.Pass()));
192 builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
193 SigninManagerFake::Build);
194 #if defined(OS_ANDROID)
195 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(),
196 FakeAndroidProfileOAuth2TokenService::Build);
197 #else
198 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(),
199 FakeProfileOAuth2TokenService::Build);
200 #endif
201
185 profile_ = builder.Build().Pass(); 202 profile_ = builder.Build().Pass();
203 signin_manager_ = static_cast<SigninManagerFake*>(
204 SigninManagerFactory::GetForProfile(profile_.get()));
186 205
187 mock_store_ = new MockUserCloudPolicyStore(); 206 mock_store_ = new MockUserCloudPolicyStore();
188 EXPECT_CALL(*mock_store_, Load()).Times(AnyNumber()); 207 EXPECT_CALL(*mock_store_, Load()).Times(AnyNumber());
189 manager_.reset(new UserCloudPolicyManager( 208 manager_.reset(new UserCloudPolicyManager(
190 profile_.get(), scoped_ptr<UserCloudPolicyStore>(mock_store_))); 209 profile_.get(), scoped_ptr<UserCloudPolicyStore>(mock_store_)));
191 signin_manager_ = static_cast<SigninManagerFake*>(
192 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
193 profile_.get(), SigninManagerFake::Build));
194 210
195 #if defined(OS_ANDROID)
196 ProfileOAuth2TokenServiceFactory* factory =
197 ProfileOAuth2TokenServiceFactory::GetInstance();
198 token_service_ = static_cast<FakeProfileOAuth2TokenService*>(
199 factory->SetTestingFactoryAndUse(profile_.get(),
200 FakeProfileOAuth2TokenService::Build));
201 #endif
202
203 // Make sure the UserPolicySigninService is created.
204 UserPolicySigninServiceFactory::GetForProfile(profile_.get());
205 Mock::VerifyAndClearExpectations(mock_store_); 211 Mock::VerifyAndClearExpectations(mock_store_);
206 url_factory_.set_remove_fetcher_on_delete(true); 212 url_factory_.set_remove_fetcher_on_delete(true);
207 } 213 }
208 214
209 virtual void TearDown() OVERRIDE { 215 virtual void TearDown() OVERRIDE {
210 // Free the profile before we clear out the browser prefs. 216 // Free the profile before we clear out the browser prefs.
211 profile_.reset(); 217 profile_.reset();
212 TestingBrowserProcess* testing_browser_process = 218 TestingBrowserProcess* testing_browser_process =
213 TestingBrowserProcess::GetGlobal(); 219 TestingBrowserProcess::GetGlobal();
214 testing_browser_process->SetLocalState(NULL); 220 testing_browser_process->SetLocalState(NULL);
215 local_state_.reset(); 221 local_state_.reset();
216 testing_browser_process->SetBrowserPolicyConnector(NULL); 222 testing_browser_process->SetBrowserPolicyConnector(NULL);
217 base::RunLoop run_loop; 223 base::RunLoop run_loop;
218 run_loop.RunUntilIdle(); 224 run_loop.RunUntilIdle();
219 } 225 }
220 226
227 virtual void OnProfileCreated(Profile* profile) OVERRIDE {
228 }
229
230 #if defined(OS_ANDROID)
231 FakeAndroidProfileOAuth2TokenService* GetTokenService() {
232 ProfileOAuth2TokenService* service =
233 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get());
234 return static_cast<FakeAndroidProfileOAuth2TokenService*>(service);
235 }
236 #else
237 FakeProfileOAuth2TokenService* GetTokenService() {
238 ProfileOAuth2TokenService* service =
239 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get());
240 return static_cast<FakeProfileOAuth2TokenService*>(service);
241 }
242 #endif
243
221 bool IsRequestActive() { 244 bool IsRequestActive() {
222 #if defined(OS_ANDROID) 245 #if defined(OS_ANDROID)
223 if (token_service_->HasPendingRequest()) 246 if (GetTokenService()->HasPendingRequest())
247 return true;
248 #else
249 if (!GetTokenService()->GetPendingRequests().empty())
224 return true; 250 return true;
225 #endif 251 #endif
226 return url_factory_.GetFetcherByID(0); 252 return url_factory_.GetFetcherByID(0);
227 } 253 }
228 254
229 void MakeOAuthTokenFetchSucceed() { 255 void MakeOAuthTokenFetchSucceed() {
230 #if defined(OS_ANDROID) 256 #if defined(OS_ANDROID)
231 ASSERT_TRUE(token_service_->HasPendingRequest()); 257 ASSERT_TRUE(GetTokenService()->HasPendingRequest());
232 token_service_->IssueToken("fake_token"); 258 GetTokenService()->IssueToken("fake_token");
233 #else 259 #else
234 ASSERT_TRUE(IsRequestActive()); 260 ASSERT_TRUE(IsRequestActive());
235 net::TestURLFetcher* fetcher = url_factory_.GetFetcherByID(0); 261 net::TestURLFetcher* fetcher = url_factory_.GetFetcherByID(0);
236 fetcher->set_response_code(net::HTTP_OK); 262 fetcher->set_response_code(net::HTTP_OK);
237 fetcher->SetResponseString(kValidTokenResponse); 263 fetcher->SetResponseString(kValidTokenResponse);
238 fetcher->delegate()->OnURLFetchComplete(fetcher); 264 fetcher->delegate()->OnURLFetchComplete(fetcher);
239 #endif 265 #endif
240 } 266 }
241 267
242 void ReportHostedDomainStatus(bool is_hosted_domain) { 268 void ReportHostedDomainStatus(bool is_hosted_domain) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 MockUserCloudPolicyStore* mock_store_; 360 MockUserCloudPolicyStore* mock_store_;
335 scoped_ptr<UserCloudPolicyManager> manager_; 361 scoped_ptr<UserCloudPolicyManager> manager_;
336 362
337 // BrowserPolicyConnector and UrlFetcherFactory want to initialize and free 363 // BrowserPolicyConnector and UrlFetcherFactory want to initialize and free
338 // various components asynchronously via tasks, so create fake threads here. 364 // various components asynchronously via tasks, so create fake threads here.
339 content::TestBrowserThreadBundle thread_bundle_; 365 content::TestBrowserThreadBundle thread_bundle_;
340 366
341 net::TestURLFetcherFactory url_factory_; 367 net::TestURLFetcherFactory url_factory_;
342 368
343 SigninManagerFake* signin_manager_; 369 SigninManagerFake* signin_manager_;
344 #if defined(OS_ANDROID)
345 FakeProfileOAuth2TokenService* token_service_; // Not owned.
346 #endif
347 370
348 // Used in conjunction with OnRegisterCompleted() to test client registration 371 // Used in conjunction with OnRegisterCompleted() to test client registration
349 // callbacks. 372 // callbacks.
350 scoped_ptr<CloudPolicyClient> created_client_; 373 scoped_ptr<CloudPolicyClient> created_client_;
351 374
352 // True if OnRegisterCompleted() was called. 375 // True if OnRegisterCompleted() was called.
353 bool register_completed_; 376 bool register_completed_;
354 377
355 // Weak ptr to the MockDeviceManagementService (object is owned by the 378 // Weak ptr to the MockDeviceManagementService (object is owned by the
356 // BrowserPolicyConnector). 379 // BrowserPolicyConnector).
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 // UserCloudPolicyManager should be initialized. 417 // UserCloudPolicyManager should be initialized.
395 ASSERT_TRUE(manager_->core()->service()); 418 ASSERT_TRUE(manager_->core()->service());
396 419
397 // Complete initialization of the store. 420 // Complete initialization of the store.
398 mock_store_->NotifyStoreLoaded(); 421 mock_store_->NotifyStoreLoaded();
399 422
400 // No oauth access token yet, so client registration should be deferred. 423 // No oauth access token yet, so client registration should be deferred.
401 ASSERT_FALSE(IsRequestActive()); 424 ASSERT_FALSE(IsRequestActive());
402 425
403 // Make oauth token available. 426 // Make oauth token available.
404 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 427 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token");
405 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token");
406 428
407 // Client registration should be in progress since we now have an oauth token. 429 // Client registration should be in progress since we now have an oauth token.
408 ASSERT_TRUE(IsRequestActive()); 430 ASSERT_TRUE(IsRequestActive());
409 } 431 }
410 432
411 TEST_F(UserPolicySigninServiceTest, SignInAfterInit) { 433 TEST_F(UserPolicySigninServiceTest, SignInAfterInit) {
412 EXPECT_CALL(*mock_store_, Clear()); 434 EXPECT_CALL(*mock_store_, Clear());
413 // Let the SigninService know that the profile has been created. 435 // Let the SigninService know that the profile has been created.
414 content::NotificationService::current()->Notify( 436 content::NotificationService::current()->Notify(
415 chrome::NOTIFICATION_PROFILE_ADDED, 437 chrome::NOTIFICATION_PROFILE_ADDED,
416 content::Source<Profile>(profile_.get()), 438 content::Source<Profile>(profile_.get()),
417 content::NotificationService::NoDetails()); 439 content::NotificationService::NoDetails());
418 440
419 // UserCloudPolicyManager should not be initialized since there is no 441 // UserCloudPolicyManager should not be initialized since there is no
420 // signed-in user. 442 // signed-in user.
421 ASSERT_FALSE(manager_->core()->service()); 443 ASSERT_FALSE(manager_->core()->service());
422 444
423 // Now sign in the user. 445 // Now sign in the user.
424 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( 446 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername(
425 kTestUser); 447 kTestUser);
426 448
427 // Complete initialization of the store. 449 // Complete initialization of the store.
428 mock_store_->NotifyStoreLoaded(); 450 mock_store_->NotifyStoreLoaded();
429 451
430 // Make oauth token available. 452 // Make oauth token available.
431 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 453 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token");
432 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token");
433 454
434 // UserCloudPolicyManager should be initialized. 455 // UserCloudPolicyManager should be initialized.
435 ASSERT_TRUE(manager_->core()->service()); 456 ASSERT_TRUE(manager_->core()->service());
436 457
437 // Client registration should be in progress since we have an oauth token. 458 // Client registration should be in progress since we have an oauth token.
438 ASSERT_TRUE(IsRequestActive()); 459 ASSERT_TRUE(IsRequestActive());
439 } 460 }
440 461
441 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) { 462 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) {
442 EXPECT_CALL(*mock_store_, Clear()); 463 EXPECT_CALL(*mock_store_, Clear());
443 // Let the SigninService know that the profile has been created. 464 // Let the SigninService know that the profile has been created.
444 content::NotificationService::current()->Notify( 465 content::NotificationService::current()->Notify(
445 chrome::NOTIFICATION_PROFILE_ADDED, 466 chrome::NOTIFICATION_PROFILE_ADDED,
446 content::Source<Profile>(profile_.get()), 467 content::Source<Profile>(profile_.get()),
447 content::NotificationService::NoDetails()); 468 content::NotificationService::NoDetails());
448 469
449 // UserCloudPolicyManager should not be initialized since there is no 470 // UserCloudPolicyManager should not be initialized since there is no
450 // signed-in user. 471 // signed-in user.
451 ASSERT_FALSE(manager_->core()->service()); 472 ASSERT_FALSE(manager_->core()->service());
452 473
453 // Now sign in a non-enterprise user (blacklisted gmail.com domain). 474 // Now sign in a non-enterprise user (blacklisted gmail.com domain).
454 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( 475 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername(
455 "non_enterprise_user@gmail.com"); 476 "non_enterprise_user@gmail.com");
456 477
457 // Complete initialization of the store. 478 // Complete initialization of the store.
458 mock_store_->NotifyStoreLoaded(); 479 mock_store_->NotifyStoreLoaded();
459 480
460 // Make oauth token available. 481 // Make oauth token available.
461 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 482 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token");
462 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token");
463 483
464 // UserCloudPolicyManager should not be initialized and there should be no 484 // UserCloudPolicyManager should not be initialized and there should be no
465 // DMToken request active. 485 // DMToken request active.
466 ASSERT_TRUE(!manager_->core()->service()); 486 ASSERT_TRUE(!manager_->core()->service());
467 ASSERT_FALSE(IsRequestActive()); 487 ASSERT_FALSE(IsRequestActive());
468 } 488 }
469 489
470 TEST_F(UserPolicySigninServiceTest, UnregisteredClient) { 490 TEST_F(UserPolicySigninServiceTest, UnregisteredClient) {
471 EXPECT_CALL(*mock_store_, Clear()); 491 EXPECT_CALL(*mock_store_, Clear());
472 // Let the SigninService know that the profile has been created. 492 // Let the SigninService know that the profile has been created.
473 content::NotificationService::current()->Notify( 493 content::NotificationService::current()->Notify(
474 chrome::NOTIFICATION_PROFILE_ADDED, 494 chrome::NOTIFICATION_PROFILE_ADDED,
475 content::Source<Profile>(profile_.get()), 495 content::Source<Profile>(profile_.get()),
476 content::NotificationService::NoDetails()); 496 content::NotificationService::NoDetails());
477 497
478 // UserCloudPolicyManager should not be initialized since there is no 498 // UserCloudPolicyManager should not be initialized since there is no
479 // signed-in user. 499 // signed-in user.
480 ASSERT_FALSE(manager_->core()->service()); 500 ASSERT_FALSE(manager_->core()->service());
481 501
482 // Now sign in the user. 502 // Now sign in the user.
483 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( 503 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername(
484 kTestUser); 504 kTestUser);
485 505
486 // Make oauth token available. 506 // Make oauth token available.
487 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 507 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token");
488 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token");
489 508
490 // UserCloudPolicyManager should be initialized. 509 // UserCloudPolicyManager should be initialized.
491 ASSERT_TRUE(manager_->core()->service()); 510 ASSERT_TRUE(manager_->core()->service());
492 511
493 // Client registration should not be in progress since the store is not 512 // Client registration should not be in progress since the store is not
494 // yet initialized. 513 // yet initialized.
495 ASSERT_FALSE(IsRequestActive()); 514 ASSERT_FALSE(IsRequestActive());
496 515
497 // Complete initialization of the store with no policy (unregistered client). 516 // Complete initialization of the store with no policy (unregistered client).
498 mock_store_->NotifyStoreLoaded(); 517 mock_store_->NotifyStoreLoaded();
(...skipping 12 matching lines...) Expand all
511 530
512 // UserCloudPolicyManager should not be initialized since there is no 531 // UserCloudPolicyManager should not be initialized since there is no
513 // signed-in user. 532 // signed-in user.
514 ASSERT_FALSE(manager_->core()->service()); 533 ASSERT_FALSE(manager_->core()->service());
515 534
516 // Now sign in the user. 535 // Now sign in the user.
517 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( 536 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername(
518 kTestUser); 537 kTestUser);
519 538
520 // Make oauth token available. 539 // Make oauth token available.
521 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 540 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token");
522 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token");
523 541
524 // UserCloudPolicyManager should be initialized. 542 // UserCloudPolicyManager should be initialized.
525 ASSERT_TRUE(manager_->core()->service()); 543 ASSERT_TRUE(manager_->core()->service());
526 544
527 // Client registration should not be in progress since the store is not 545 // Client registration should not be in progress since the store is not
528 // yet initialized. 546 // yet initialized.
529 ASSERT_FALSE(manager_->IsClientRegistered()); 547 ASSERT_FALSE(manager_->IsClientRegistered());
530 ASSERT_FALSE(IsRequestActive()); 548 ASSERT_FALSE(IsRequestActive());
531 549
532 mock_store_->policy_.reset(new enterprise_management::PolicyData()); 550 mock_store_->policy_.reset(new enterprise_management::PolicyData());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 RegisterPolicyClientWithCallback(signin_service); 590 RegisterPolicyClientWithCallback(signin_service);
573 Mock::VerifyAndClearExpectations(this); 591 Mock::VerifyAndClearExpectations(this);
574 592
575 // UserCloudPolicyManager should not be initialized. 593 // UserCloudPolicyManager should not be initialized.
576 ASSERT_FALSE(manager_->core()->service()); 594 ASSERT_FALSE(manager_->core()->service());
577 ASSERT_TRUE(IsRequestActive()); 595 ASSERT_TRUE(IsRequestActive());
578 EXPECT_FALSE(register_completed_); 596 EXPECT_FALSE(register_completed_);
579 597
580 // Cause the access token fetch to fail - callback should be invoked. 598 // Cause the access token fetch to fail - callback should be invoked.
581 #if defined(OS_ANDROID) 599 #if defined(OS_ANDROID)
582 ASSERT_TRUE(token_service_->HasPendingRequest()); 600 ASSERT_TRUE(GetTokenService()->HasPendingRequest());
583 token_service_->IssueToken(""); 601 GetTokenService()->IssueToken("");
584 #else 602 #else
585 net::TestURLFetcher* fetcher = url_factory_.GetFetcherByID(0); 603 net::TestURLFetcher* fetcher = url_factory_.GetFetcherByID(0);
586 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED, -1)); 604 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED, -1));
587 fetcher->delegate()->OnURLFetchComplete(fetcher); 605 fetcher->delegate()->OnURLFetchComplete(fetcher);
588 #endif 606 #endif
589 607
590 EXPECT_TRUE(register_completed_); 608 EXPECT_TRUE(register_completed_);
591 EXPECT_FALSE(created_client_.get()); 609 EXPECT_FALSE(created_client_.get());
592 EXPECT_FALSE(IsRequestActive()); 610 EXPECT_FALSE(IsRequestActive());
593 } 611 }
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 base::RunLoop().RunUntilIdle(); 812 base::RunLoop().RunUntilIdle();
795 EXPECT_FALSE(manager_->IsClientRegistered()); 813 EXPECT_FALSE(manager_->IsClientRegistered());
796 #if !defined(OS_ANDROID) 814 #if !defined(OS_ANDROID)
797 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); 815 EXPECT_FALSE(signin_manager_->IsSignoutProhibited());
798 #endif 816 #endif
799 } 817 }
800 818
801 } // namespace 819 } // namespace
802 820
803 } // namespace policy 821 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698