Chromium Code Reviews| 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 "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 |
| 59 namespace { | 58 namespace { |
| 60 | 59 |
| 61 const char kTestUser[] = "testuser@test.com"; | 60 const char kTestUser[] = "testuser@test.com"; |
| 62 | 61 |
| 63 const char kValidTokenResponse[] = | 62 const char kValidTokenResponse[] = |
| 64 "{" | 63 "{" |
| 65 " \"access_token\": \"at1\"," | 64 " \"access_token\": \"at1\"," |
| 66 " \"expires_in\": 3600," | 65 " \"expires_in\": 3600," |
| 67 " \"token_type\": \"Bearer\"" | 66 " \"token_type\": \"Bearer\"" |
| 68 "}"; | 67 "}"; |
| 69 | 68 |
| 70 const char kHostedDomainResponse[] = | 69 const char kHostedDomainResponse[] = |
| 71 "{" | 70 "{" |
| 72 " \"hd\": \"test.com\"" | 71 " \"hd\": \"test.com\"" |
| 73 "}"; | 72 "}"; |
| 74 | 73 |
| 75 const char kCombinedScopes[] = | |
| 76 "https://www.googleapis.com/auth/chromeosdevicemanagement " | |
| 77 "https://www.googleapis.com/auth/userinfo.email"; | |
| 78 | |
| 79 class SigninManagerFake : public FakeSigninManager { | 74 class SigninManagerFake : public FakeSigninManager { |
| 80 public: | 75 public: |
| 81 explicit SigninManagerFake(Profile* profile) | 76 explicit SigninManagerFake(Profile* profile) |
| 82 : FakeSigninManager(profile) { | 77 : FakeSigninManager(profile) { |
| 83 Initialize(profile, NULL); | 78 Initialize(profile, NULL); |
| 84 } | 79 } |
| 85 | 80 |
| 86 void ForceSignOut() { | 81 void ForceSignOut() { |
| 87 // Allow signing out now. | 82 // Allow signing out now. |
| 88 prohibit_signout_ = false; | 83 prohibit_signout_ = false; |
| 89 SignOut(); | 84 SignOut(); |
| 90 } | 85 } |
| 91 | 86 |
| 92 static BrowserContextKeyedService* Build(content::BrowserContext* profile) { | 87 static BrowserContextKeyedService* Build(content::BrowserContext* profile) { |
| 93 return new SigninManagerFake(static_cast<Profile*>(profile)); | 88 return new SigninManagerFake(static_cast<Profile*>(profile)); |
| 94 } | 89 } |
| 95 }; | 90 }; |
| 96 | 91 |
| 92 | |
|
awong
2013/08/16 17:53:16
nit: spurious newline
Andrew T Wilson (Slow)
2013/08/19 12:15:56
Done.
| |
| 97 #if defined(OS_ANDROID) | 93 #if defined(OS_ANDROID) |
| 98 | 94 // TODO(atwilson): Remove this when ProfileOAuth2TokenService supports |
| 99 class FakeProfileOAuth2TokenService : public AndroidProfileOAuth2TokenService { | 95 // usernames. |
| 96 class FakeAndroidProfileOAuth2TokenService : | |
| 97 public AndroidProfileOAuth2TokenService { | |
| 100 public: | 98 public: |
| 101 explicit FakeProfileOAuth2TokenService(Profile* profile) { | 99 explicit FakeAndroidProfileOAuth2TokenService(Profile* profile) { |
| 102 Initialize(profile); | 100 Initialize(profile); |
| 103 } | 101 } |
| 104 | 102 |
| 105 static BrowserContextKeyedService* Build(content::BrowserContext* profile) { | 103 static BrowserContextKeyedService* Build(content::BrowserContext* profile) { |
| 106 return new FakeProfileOAuth2TokenService(static_cast<Profile*>(profile)); | 104 return new FakeAndroidProfileOAuth2TokenService( |
| 105 static_cast<Profile*>(profile)); | |
| 107 } | 106 } |
| 108 | 107 |
| 109 // AndroidProfileOAuth2TokenService overrides: | 108 // AndroidProfileOAuth2TokenService overrides: |
| 110 virtual void FetchOAuth2Token( | 109 virtual void FetchOAuth2TokenWithUsername( |
| 110 RequestImpl* request, | |
| 111 const std::string& username, | 111 const std::string& username, |
| 112 const std::string& scope, | 112 const OAuth2TokenService::ScopeSet& scope) OVERRIDE { |
| 113 const FetchOAuth2TokenCallback& callback) OVERRIDE { | |
| 114 ASSERT_TRUE(!HasPendingRequest()); | 113 ASSERT_TRUE(!HasPendingRequest()); |
|
awong
2013/08/16 17:53:16
hmm...I wonder if the original author expected thi
Andrew T Wilson (Slow)
2013/08/19 12:15:56
Yeah, he probably expects it to abort the whole te
| |
| 115 ASSERT_EQ(kTestUser, username); | 114 ASSERT_EQ(kTestUser, username); |
| 116 ASSERT_EQ(kCombinedScopes, scope); | 115 ASSERT_EQ(2U, scope.size()); |
| 117 pending_callback_ = callback; | 116 EXPECT_EQ(1U, scope.count(GaiaConstants::kDeviceManagementServiceOAuth)); |
| 117 EXPECT_EQ(1U, scope.count( | |
| 118 "https://www.googleapis.com/auth/userinfo.email")); | |
| 119 pending_request_ = request->AsWeakPtr(); | |
| 118 } | 120 } |
| 119 | 121 |
| 120 void IssueToken(const std::string& token) { | 122 void IssueToken(const std::string& token) { |
| 121 ASSERT_TRUE(HasPendingRequest()); | 123 ASSERT_TRUE(HasPendingRequest()); |
| 122 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); | 124 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); |
| 123 if (token.empty()) | 125 if (token.empty()) |
| 124 error = GoogleServiceAuthError::FromServiceError("fail"); | 126 error = GoogleServiceAuthError::FromServiceError("fail"); |
| 125 pending_callback_.Run( | 127 if (pending_request_) { |
| 126 error, token, base::Time::Now() + base::TimeDelta::FromDays(1)); | 128 pending_request_->InformConsumer( |
| 127 pending_callback_.Reset(); | 129 error, |
| 130 token, | |
| 131 base::Time::Now() + base::TimeDelta::FromDays(1)); | |
| 132 } | |
| 133 pending_request_.reset(); | |
| 128 } | 134 } |
| 129 | 135 |
| 130 bool HasPendingRequest() const { | 136 bool HasPendingRequest() const { |
| 131 return !pending_callback_.is_null(); | 137 return pending_request_; |
| 132 } | 138 } |
| 133 | 139 |
| 134 private: | 140 private: |
| 135 FetchOAuth2TokenCallback pending_callback_; | 141 base::WeakPtr<RequestImpl> pending_request_; |
| 136 }; | 142 }; |
| 137 | 143 |
| 138 #endif | 144 #endif |
| 139 | 145 |
| 140 class UserPolicySigninServiceTest : public testing::Test { | 146 class UserPolicySigninServiceTest : public testing::Test { |
| 141 public: | 147 public: |
| 142 UserPolicySigninServiceTest() | 148 UserPolicySigninServiceTest() |
| 143 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 149 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 144 register_completed_(false) {} | 150 register_completed_(false) {} |
| 145 | 151 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 173 g_browser_process->browser_policy_connector()->Init( | 179 g_browser_process->browser_policy_connector()->Init( |
| 174 local_state_.get(), system_request_context); | 180 local_state_.get(), system_request_context); |
| 175 | 181 |
| 176 // Create a testing profile with cloud-policy-on-signin enabled, and bring | 182 // Create a testing profile with cloud-policy-on-signin enabled, and bring |
| 177 // up a UserCloudPolicyManager with a MockUserCloudPolicyStore. | 183 // up a UserCloudPolicyManager with a MockUserCloudPolicyStore. |
| 178 scoped_ptr<TestingPrefServiceSyncable> prefs( | 184 scoped_ptr<TestingPrefServiceSyncable> prefs( |
| 179 new TestingPrefServiceSyncable()); | 185 new TestingPrefServiceSyncable()); |
| 180 chrome::RegisterUserProfilePrefs(prefs->registry()); | 186 chrome::RegisterUserProfilePrefs(prefs->registry()); |
| 181 TestingProfile::Builder builder; | 187 TestingProfile::Builder builder; |
| 182 builder.SetPrefService(scoped_ptr<PrefServiceSyncable>(prefs.Pass())); | 188 builder.SetPrefService(scoped_ptr<PrefServiceSyncable>(prefs.Pass())); |
| 189 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), | |
| 190 SigninManagerFake::Build); | |
| 191 #if defined(OS_ANDROID) | |
| 192 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), | |
| 193 FakeAndroidProfileOAuth2TokenService::Build); | |
| 194 #else | |
| 195 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), | |
| 196 FakeProfileOAuth2TokenService::Build); | |
| 197 #endif | |
| 198 | |
| 183 profile_ = builder.Build().Pass(); | 199 profile_ = builder.Build().Pass(); |
| 200 signin_manager_ = static_cast<SigninManagerFake*>( | |
| 201 SigninManagerFactory::GetForProfile(profile_.get())); | |
| 184 | 202 |
| 185 mock_store_ = new MockUserCloudPolicyStore(); | 203 mock_store_ = new MockUserCloudPolicyStore(); |
| 186 EXPECT_CALL(*mock_store_, Load()).Times(AnyNumber()); | 204 EXPECT_CALL(*mock_store_, Load()).Times(AnyNumber()); |
| 187 manager_.reset(new UserCloudPolicyManager( | 205 manager_.reset(new UserCloudPolicyManager( |
| 188 profile_.get(), scoped_ptr<UserCloudPolicyStore>(mock_store_))); | 206 profile_.get(), scoped_ptr<UserCloudPolicyStore>(mock_store_))); |
| 189 signin_manager_ = static_cast<SigninManagerFake*>( | |
| 190 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( | |
| 191 profile_.get(), SigninManagerFake::Build)); | |
| 192 | 207 |
| 193 #if defined(OS_ANDROID) | |
| 194 ProfileOAuth2TokenServiceFactory* factory = | |
| 195 ProfileOAuth2TokenServiceFactory::GetInstance(); | |
| 196 token_service_ = static_cast<FakeProfileOAuth2TokenService*>( | |
| 197 factory->SetTestingFactoryAndUse(profile_.get(), | |
| 198 FakeProfileOAuth2TokenService::Build)); | |
| 199 #endif | |
| 200 | |
| 201 // Make sure the UserPolicySigninService is created. | |
| 202 UserPolicySigninServiceFactory::GetForProfile(profile_.get()); | |
| 203 Mock::VerifyAndClearExpectations(mock_store_); | 208 Mock::VerifyAndClearExpectations(mock_store_); |
| 204 url_factory_.set_remove_fetcher_on_delete(true); | 209 url_factory_.set_remove_fetcher_on_delete(true); |
| 205 } | 210 } |
| 206 | 211 |
| 207 virtual void TearDown() OVERRIDE { | 212 virtual void TearDown() OVERRIDE { |
| 208 UserPolicySigninServiceFactory::SetDeviceManagementServiceForTesting(NULL); | 213 UserPolicySigninServiceFactory::SetDeviceManagementServiceForTesting(NULL); |
| 209 // Free the profile before we clear out the browser prefs. | 214 // Free the profile before we clear out the browser prefs. |
| 210 profile_.reset(); | 215 profile_.reset(); |
| 211 TestingBrowserProcess* testing_browser_process = | 216 TestingBrowserProcess* testing_browser_process = |
| 212 TestingBrowserProcess::GetGlobal(); | 217 TestingBrowserProcess::GetGlobal(); |
| 213 testing_browser_process->SetLocalState(NULL); | 218 testing_browser_process->SetLocalState(NULL); |
| 214 local_state_.reset(); | 219 local_state_.reset(); |
| 215 testing_browser_process->SetBrowserPolicyConnector(NULL); | 220 testing_browser_process->SetBrowserPolicyConnector(NULL); |
| 216 base::RunLoop run_loop; | 221 base::RunLoop run_loop; |
| 217 run_loop.RunUntilIdle(); | 222 run_loop.RunUntilIdle(); |
| 218 } | 223 } |
| 219 | 224 |
| 225 #if defined(OS_ANDROID) | |
| 226 FakeAndroidProfileOAuth2TokenService* GetTokenService() { | |
| 227 ProfileOAuth2TokenService* service = | |
| 228 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); | |
| 229 return static_cast<FakeAndroidProfileOAuth2TokenService*>(service); | |
| 230 } | |
| 231 #else | |
| 232 FakeProfileOAuth2TokenService* GetTokenService() { | |
| 233 ProfileOAuth2TokenService* service = | |
| 234 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); | |
| 235 return static_cast<FakeProfileOAuth2TokenService*>(service); | |
| 236 } | |
| 237 #endif | |
| 238 | |
| 220 bool IsRequestActive() { | 239 bool IsRequestActive() { |
| 221 #if defined(OS_ANDROID) | 240 #if defined(OS_ANDROID) |
| 222 if (token_service_->HasPendingRequest()) | 241 if (GetTokenService()->HasPendingRequest()) |
| 242 return true; | |
| 243 #else | |
| 244 if (!GetTokenService()->GetPendingRequests().empty()) | |
| 223 return true; | 245 return true; |
| 224 #endif | 246 #endif |
| 225 return url_factory_.GetFetcherByID(0); | 247 return url_factory_.GetFetcherByID(0); |
| 226 } | 248 } |
| 227 | 249 |
| 228 void MakeOAuthTokenFetchSucceed() { | 250 void MakeOAuthTokenFetchSucceed() { |
| 229 #if defined(OS_ANDROID) | 251 #if defined(OS_ANDROID) |
| 230 ASSERT_TRUE(token_service_->HasPendingRequest()); | 252 ASSERT_TRUE(GetTokenService()->HasPendingRequest()); |
| 231 token_service_->IssueToken("fake_token"); | 253 GetTokenService()->IssueToken("fake_token"); |
| 232 #else | 254 #else |
| 233 ASSERT_TRUE(IsRequestActive()); | 255 ASSERT_TRUE(IsRequestActive()); |
| 234 net::TestURLFetcher* fetcher = url_factory_.GetFetcherByID(0); | 256 net::TestURLFetcher* fetcher = url_factory_.GetFetcherByID(0); |
| 235 fetcher->set_response_code(net::HTTP_OK); | 257 fetcher->set_response_code(net::HTTP_OK); |
| 236 fetcher->SetResponseString(kValidTokenResponse); | 258 fetcher->SetResponseString(kValidTokenResponse); |
| 237 fetcher->delegate()->OnURLFetchComplete(fetcher); | 259 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 238 #endif | 260 #endif |
| 239 } | 261 } |
| 240 | 262 |
| 241 void ReportHostedDomainStatus(bool is_hosted_domain) { | 263 void ReportHostedDomainStatus(bool is_hosted_domain) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 MockUserCloudPolicyStore* mock_store_; | 355 MockUserCloudPolicyStore* mock_store_; |
| 334 scoped_ptr<UserCloudPolicyManager> manager_; | 356 scoped_ptr<UserCloudPolicyManager> manager_; |
| 335 | 357 |
| 336 // BrowserPolicyConnector and UrlFetcherFactory want to initialize and free | 358 // BrowserPolicyConnector and UrlFetcherFactory want to initialize and free |
| 337 // various components asynchronously via tasks, so create fake threads here. | 359 // various components asynchronously via tasks, so create fake threads here. |
| 338 content::TestBrowserThreadBundle thread_bundle_; | 360 content::TestBrowserThreadBundle thread_bundle_; |
| 339 | 361 |
| 340 net::TestURLFetcherFactory url_factory_; | 362 net::TestURLFetcherFactory url_factory_; |
| 341 | 363 |
| 342 SigninManagerFake* signin_manager_; | 364 SigninManagerFake* signin_manager_; |
| 343 #if defined(OS_ANDROID) | |
| 344 FakeProfileOAuth2TokenService* token_service_; // Not owned. | |
| 345 #endif | |
| 346 | 365 |
| 347 // Used in conjunction with OnRegisterCompleted() to test client registration | 366 // Used in conjunction with OnRegisterCompleted() to test client registration |
| 348 // callbacks. | 367 // callbacks. |
| 349 scoped_ptr<CloudPolicyClient> created_client_; | 368 scoped_ptr<CloudPolicyClient> created_client_; |
| 350 | 369 |
| 351 // True if OnRegisterCompleted() was called. | 370 // True if OnRegisterCompleted() was called. |
| 352 bool register_completed_; | 371 bool register_completed_; |
| 353 | 372 |
| 354 // Weak ptr to the MockDeviceManagementService (object is owned by the | 373 // Weak ptr to the MockDeviceManagementService (object is owned by the |
| 355 // BrowserPolicyConnector). | 374 // BrowserPolicyConnector). |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 // UserCloudPolicyManager should be initialized. | 412 // UserCloudPolicyManager should be initialized. |
| 394 ASSERT_TRUE(manager_->core()->service()); | 413 ASSERT_TRUE(manager_->core()->service()); |
| 395 | 414 |
| 396 // Complete initialization of the store. | 415 // Complete initialization of the store. |
| 397 mock_store_->NotifyStoreLoaded(); | 416 mock_store_->NotifyStoreLoaded(); |
| 398 | 417 |
| 399 // No oauth access token yet, so client registration should be deferred. | 418 // No oauth access token yet, so client registration should be deferred. |
| 400 ASSERT_FALSE(IsRequestActive()); | 419 ASSERT_FALSE(IsRequestActive()); |
| 401 | 420 |
| 402 // Make oauth token available. | 421 // Make oauth token available. |
| 403 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 422 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token"); |
| 404 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token"); | |
| 405 | 423 |
| 406 // Client registration should be in progress since we now have an oauth token. | 424 // Client registration should be in progress since we now have an oauth token. |
| 407 ASSERT_TRUE(IsRequestActive()); | 425 ASSERT_TRUE(IsRequestActive()); |
| 408 } | 426 } |
| 409 | 427 |
| 410 TEST_F(UserPolicySigninServiceTest, SignInAfterInit) { | 428 TEST_F(UserPolicySigninServiceTest, SignInAfterInit) { |
| 411 EXPECT_CALL(*mock_store_, Clear()); | 429 EXPECT_CALL(*mock_store_, Clear()); |
| 412 // Let the SigninService know that the profile has been created. | 430 // Let the SigninService know that the profile has been created. |
| 413 content::NotificationService::current()->Notify( | 431 content::NotificationService::current()->Notify( |
| 414 chrome::NOTIFICATION_PROFILE_ADDED, | 432 chrome::NOTIFICATION_PROFILE_ADDED, |
| 415 content::Source<Profile>(profile_.get()), | 433 content::Source<Profile>(profile_.get()), |
| 416 content::NotificationService::NoDetails()); | 434 content::NotificationService::NoDetails()); |
| 417 | 435 |
| 418 // UserCloudPolicyManager should not be initialized since there is no | 436 // UserCloudPolicyManager should not be initialized since there is no |
| 419 // signed-in user. | 437 // signed-in user. |
| 420 ASSERT_FALSE(manager_->core()->service()); | 438 ASSERT_FALSE(manager_->core()->service()); |
| 421 | 439 |
| 422 // Now sign in the user. | 440 // Now sign in the user. |
| 423 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 441 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( |
| 424 kTestUser); | 442 kTestUser); |
| 425 | 443 |
| 426 // Complete initialization of the store. | 444 // Complete initialization of the store. |
| 427 mock_store_->NotifyStoreLoaded(); | 445 mock_store_->NotifyStoreLoaded(); |
| 428 | 446 |
| 429 // Make oauth token available. | 447 // Make oauth token available. |
| 430 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 448 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token"); |
| 431 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token"); | |
| 432 | 449 |
| 433 // UserCloudPolicyManager should be initialized. | 450 // UserCloudPolicyManager should be initialized. |
| 434 ASSERT_TRUE(manager_->core()->service()); | 451 ASSERT_TRUE(manager_->core()->service()); |
| 435 | 452 |
| 436 // Client registration should be in progress since we have an oauth token. | 453 // Client registration should be in progress since we have an oauth token. |
| 437 ASSERT_TRUE(IsRequestActive()); | 454 ASSERT_TRUE(IsRequestActive()); |
| 438 } | 455 } |
| 439 | 456 |
| 440 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) { | 457 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) { |
| 441 EXPECT_CALL(*mock_store_, Clear()); | 458 EXPECT_CALL(*mock_store_, Clear()); |
| 442 // Let the SigninService know that the profile has been created. | 459 // Let the SigninService know that the profile has been created. |
| 443 content::NotificationService::current()->Notify( | 460 content::NotificationService::current()->Notify( |
| 444 chrome::NOTIFICATION_PROFILE_ADDED, | 461 chrome::NOTIFICATION_PROFILE_ADDED, |
| 445 content::Source<Profile>(profile_.get()), | 462 content::Source<Profile>(profile_.get()), |
| 446 content::NotificationService::NoDetails()); | 463 content::NotificationService::NoDetails()); |
| 447 | 464 |
| 448 // UserCloudPolicyManager should not be initialized since there is no | 465 // UserCloudPolicyManager should not be initialized since there is no |
| 449 // signed-in user. | 466 // signed-in user. |
| 450 ASSERT_FALSE(manager_->core()->service()); | 467 ASSERT_FALSE(manager_->core()->service()); |
| 451 | 468 |
| 452 // Now sign in a non-enterprise user (blacklisted gmail.com domain). | 469 // Now sign in a non-enterprise user (blacklisted gmail.com domain). |
| 453 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 470 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( |
| 454 "non_enterprise_user@gmail.com"); | 471 "non_enterprise_user@gmail.com"); |
| 455 | 472 |
| 456 // Complete initialization of the store. | 473 // Complete initialization of the store. |
| 457 mock_store_->NotifyStoreLoaded(); | 474 mock_store_->NotifyStoreLoaded(); |
| 458 | 475 |
| 459 // Make oauth token available. | 476 // Make oauth token available. |
| 460 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 477 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token"); |
| 461 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token"); | |
| 462 | 478 |
| 463 // UserCloudPolicyManager should not be initialized and there should be no | 479 // UserCloudPolicyManager should not be initialized and there should be no |
| 464 // DMToken request active. | 480 // DMToken request active. |
| 465 ASSERT_TRUE(!manager_->core()->service()); | 481 ASSERT_TRUE(!manager_->core()->service()); |
| 466 ASSERT_FALSE(IsRequestActive()); | 482 ASSERT_FALSE(IsRequestActive()); |
| 467 } | 483 } |
| 468 | 484 |
| 469 TEST_F(UserPolicySigninServiceTest, UnregisteredClient) { | 485 TEST_F(UserPolicySigninServiceTest, UnregisteredClient) { |
| 470 EXPECT_CALL(*mock_store_, Clear()); | 486 EXPECT_CALL(*mock_store_, Clear()); |
| 471 // Let the SigninService know that the profile has been created. | 487 // Let the SigninService know that the profile has been created. |
| 472 content::NotificationService::current()->Notify( | 488 content::NotificationService::current()->Notify( |
| 473 chrome::NOTIFICATION_PROFILE_ADDED, | 489 chrome::NOTIFICATION_PROFILE_ADDED, |
| 474 content::Source<Profile>(profile_.get()), | 490 content::Source<Profile>(profile_.get()), |
| 475 content::NotificationService::NoDetails()); | 491 content::NotificationService::NoDetails()); |
| 476 | 492 |
| 477 // UserCloudPolicyManager should not be initialized since there is no | 493 // UserCloudPolicyManager should not be initialized since there is no |
| 478 // signed-in user. | 494 // signed-in user. |
| 479 ASSERT_FALSE(manager_->core()->service()); | 495 ASSERT_FALSE(manager_->core()->service()); |
| 480 | 496 |
| 481 // Now sign in the user. | 497 // Now sign in the user. |
| 482 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 498 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( |
| 483 kTestUser); | 499 kTestUser); |
| 484 | 500 |
| 485 // Make oauth token available. | 501 // Make oauth token available. |
| 486 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 502 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token"); |
| 487 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token"); | |
| 488 | 503 |
| 489 // UserCloudPolicyManager should be initialized. | 504 // UserCloudPolicyManager should be initialized. |
| 490 ASSERT_TRUE(manager_->core()->service()); | 505 ASSERT_TRUE(manager_->core()->service()); |
| 491 | 506 |
| 492 // Client registration should not be in progress since the store is not | 507 // Client registration should not be in progress since the store is not |
| 493 // yet initialized. | 508 // yet initialized. |
| 494 ASSERT_FALSE(IsRequestActive()); | 509 ASSERT_FALSE(IsRequestActive()); |
| 495 | 510 |
| 496 // Complete initialization of the store with no policy (unregistered client). | 511 // Complete initialization of the store with no policy (unregistered client). |
| 497 mock_store_->NotifyStoreLoaded(); | 512 mock_store_->NotifyStoreLoaded(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 510 | 525 |
| 511 // UserCloudPolicyManager should not be initialized since there is no | 526 // UserCloudPolicyManager should not be initialized since there is no |
| 512 // signed-in user. | 527 // signed-in user. |
| 513 ASSERT_FALSE(manager_->core()->service()); | 528 ASSERT_FALSE(manager_->core()->service()); |
| 514 | 529 |
| 515 // Now sign in the user. | 530 // Now sign in the user. |
| 516 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( | 531 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( |
| 517 kTestUser); | 532 kTestUser); |
| 518 | 533 |
| 519 // Make oauth token available. | 534 // Make oauth token available. |
| 520 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 535 GetTokenService()->IssueRefreshToken("oauth_login_refresh_token"); |
| 521 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth_login_refresh_token"); | |
| 522 | 536 |
| 523 // UserCloudPolicyManager should be initialized. | 537 // UserCloudPolicyManager should be initialized. |
| 524 ASSERT_TRUE(manager_->core()->service()); | 538 ASSERT_TRUE(manager_->core()->service()); |
| 525 | 539 |
| 526 // Client registration should not be in progress since the store is not | 540 // Client registration should not be in progress since the store is not |
| 527 // yet initialized. | 541 // yet initialized. |
| 528 ASSERT_FALSE(manager_->IsClientRegistered()); | 542 ASSERT_FALSE(manager_->IsClientRegistered()); |
| 529 ASSERT_FALSE(IsRequestActive()); | 543 ASSERT_FALSE(IsRequestActive()); |
| 530 | 544 |
| 531 mock_store_->policy_.reset(new enterprise_management::PolicyData()); | 545 mock_store_->policy_.reset(new enterprise_management::PolicyData()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 RegisterPolicyClientWithCallback(signin_service); | 585 RegisterPolicyClientWithCallback(signin_service); |
| 572 Mock::VerifyAndClearExpectations(this); | 586 Mock::VerifyAndClearExpectations(this); |
| 573 | 587 |
| 574 // UserCloudPolicyManager should not be initialized. | 588 // UserCloudPolicyManager should not be initialized. |
| 575 ASSERT_FALSE(manager_->core()->service()); | 589 ASSERT_FALSE(manager_->core()->service()); |
| 576 ASSERT_TRUE(IsRequestActive()); | 590 ASSERT_TRUE(IsRequestActive()); |
| 577 EXPECT_FALSE(register_completed_); | 591 EXPECT_FALSE(register_completed_); |
| 578 | 592 |
| 579 // Cause the access token fetch to fail - callback should be invoked. | 593 // Cause the access token fetch to fail - callback should be invoked. |
| 580 #if defined(OS_ANDROID) | 594 #if defined(OS_ANDROID) |
| 581 ASSERT_TRUE(token_service_->HasPendingRequest()); | 595 ASSERT_TRUE(GetTokenService()->HasPendingRequest()); |
| 582 token_service_->IssueToken(""); | 596 GetTokenService()->IssueToken(""); |
| 583 #else | 597 #else |
| 584 net::TestURLFetcher* fetcher = url_factory_.GetFetcherByID(0); | 598 net::TestURLFetcher* fetcher = url_factory_.GetFetcherByID(0); |
| 585 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED, -1)); | 599 fetcher->set_status(net::URLRequestStatus(net::URLRequestStatus::FAILED, -1)); |
| 586 fetcher->delegate()->OnURLFetchComplete(fetcher); | 600 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 587 #endif | 601 #endif |
| 588 | 602 |
| 589 EXPECT_TRUE(register_completed_); | 603 EXPECT_TRUE(register_completed_); |
| 590 EXPECT_FALSE(created_client_.get()); | 604 EXPECT_FALSE(created_client_.get()); |
| 591 EXPECT_FALSE(IsRequestActive()); | 605 EXPECT_FALSE(IsRequestActive()); |
| 592 } | 606 } |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 793 base::RunLoop().RunUntilIdle(); | 807 base::RunLoop().RunUntilIdle(); |
| 794 EXPECT_FALSE(manager_->IsClientRegistered()); | 808 EXPECT_FALSE(manager_->IsClientRegistered()); |
| 795 #if !defined(OS_ANDROID) | 809 #if !defined(OS_ANDROID) |
| 796 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); | 810 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); |
| 797 #endif | 811 #endif |
| 798 } | 812 } |
| 799 | 813 |
| 800 } // namespace | 814 } // namespace |
| 801 | 815 |
| 802 } // namespace policy | 816 } // namespace policy |
| OLD | NEW |