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 "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
12 #include "base/prefs/testing_pref_service.h" | 12 #include "base/prefs/testing_pref_service.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/test/test_simple_task_runner.h" | 17 #include "base/test/test_simple_task_runner.h" |
18 #include "chrome/browser/chromeos/policy/user_cloud_policy_token_forwarder.h" | 18 #include "chrome/browser/chromeos/policy/user_cloud_policy_token_forwarder.h" |
19 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
20 #include "chrome/browser/prefs/browser_prefs.h" | 20 #include "chrome/browser/prefs/browser_prefs.h" |
21 #include "chrome/browser/prefs/pref_service_syncable.h" | 21 #include "chrome/browser/prefs/pref_service_syncable.h" |
22 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 22 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
23 #include "chrome/browser/signin/fake_profile_oauth2_token_service_wrapper.h" | 23 #include "chrome/browser/signin/fake_profile_oauth2_token_service_wrapper.h" |
24 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 24 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 26 #include "chrome/browser/signin/signin_manager.h" |
| 27 #include "chrome/browser/signin/signin_manager_factory.h" |
26 #include "chrome/common/chrome_constants.h" | 28 #include "chrome/common/chrome_constants.h" |
27 #include "chrome/test/base/testing_browser_process.h" | 29 #include "chrome/test/base/testing_browser_process.h" |
28 #include "chrome/test/base/testing_profile.h" | 30 #include "chrome/test/base/testing_profile.h" |
29 #include "chrome/test/base/testing_profile_manager.h" | 31 #include "chrome/test/base/testing_profile_manager.h" |
30 #include "components/policy/core/common/cloud/cloud_external_data_manager.h" | 32 #include "components/policy/core/common/cloud/cloud_external_data_manager.h" |
31 #include "components/policy/core/common/cloud/mock_cloud_external_data_manager.h
" | 33 #include "components/policy/core/common/cloud/mock_cloud_external_data_manager.h
" |
32 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" | 34 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" |
33 #include "components/policy/core/common/cloud/mock_device_management_service.h" | 35 #include "components/policy/core/common/cloud/mock_device_management_service.h" |
34 #include "components/policy/core/common/external_data_fetcher.h" | 36 #include "components/policy/core/common/external_data_fetcher.h" |
35 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 37 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); | 175 EXPECT_FALSE(manager_->core()->service()->IsInitializationComplete()); |
174 | 176 |
175 if (!wait_for_fetch) { | 177 if (!wait_for_fetch) { |
176 // Create the UserCloudPolicyTokenForwarder, which fetches the access | 178 // Create the UserCloudPolicyTokenForwarder, which fetches the access |
177 // token using the OAuth2PolicyFetcher and forwards it to the | 179 // token using the OAuth2PolicyFetcher and forwards it to the |
178 // UserCloudPolicyManagerChromeOS. This service is automatically created | 180 // UserCloudPolicyManagerChromeOS. This service is automatically created |
179 // for regular Profiles but not for testing Profiles. | 181 // for regular Profiles but not for testing Profiles. |
180 ProfileOAuth2TokenService* token_service = | 182 ProfileOAuth2TokenService* token_service = |
181 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 183 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
182 ASSERT_TRUE(token_service); | 184 ASSERT_TRUE(token_service); |
| 185 SigninManagerBase* signin_manager = |
| 186 SigninManagerFactory::GetForProfile(profile_); |
| 187 ASSERT_TRUE(signin_manager); |
183 token_forwarder_.reset( | 188 token_forwarder_.reset( |
184 new UserCloudPolicyTokenForwarder(manager_.get(), token_service)); | 189 new UserCloudPolicyTokenForwarder(manager_.get(), token_service, |
| 190 signin_manager)); |
185 } | 191 } |
186 } | 192 } |
187 | 193 |
188 // Expects a pending URLFetcher for the |expected_url|, and returns it with | 194 // Expects a pending URLFetcher for the |expected_url|, and returns it with |
189 // prepared to deliver a response to its delegate. | 195 // prepared to deliver a response to its delegate. |
190 net::TestURLFetcher* PrepareOAuthFetcher(const GURL& expected_url) { | 196 net::TestURLFetcher* PrepareOAuthFetcher(const GURL& expected_url) { |
191 net::TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0); | 197 net::TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0); |
192 EXPECT_TRUE(fetcher); | 198 EXPECT_TRUE(fetcher); |
193 if (!fetcher) | 199 if (!fetcher) |
194 return NULL; | 200 return NULL; |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 | 534 |
529 // The manager is waiting for the refresh token, and hasn't started any | 535 // The manager is waiting for the refresh token, and hasn't started any |
530 // fetchers. | 536 // fetchers. |
531 EXPECT_FALSE(test_url_fetcher_factory_.GetFetcherByID(0)); | 537 EXPECT_FALSE(test_url_fetcher_factory_.GetFetcherByID(0)); |
532 | 538 |
533 // Set a fake refresh token at the OAuth2TokenService. | 539 // Set a fake refresh token at the OAuth2TokenService. |
534 FakeProfileOAuth2TokenService* token_service = | 540 FakeProfileOAuth2TokenService* token_service = |
535 static_cast<FakeProfileOAuth2TokenService*>( | 541 static_cast<FakeProfileOAuth2TokenService*>( |
536 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)); | 542 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)); |
537 ASSERT_TRUE(token_service); | 543 ASSERT_TRUE(token_service); |
538 const std::string account_id = token_service->GetPrimaryAccountId(); | 544 SigninManagerBase* signin_manager = |
| 545 SigninManagerFactory::GetForProfile(profile_); |
| 546 ASSERT_TRUE(signin_manager); |
| 547 const std::string& account_id = signin_manager->GetAuthenticatedAccountId(); |
539 EXPECT_FALSE(token_service->RefreshTokenIsAvailable(account_id)); | 548 EXPECT_FALSE(token_service->RefreshTokenIsAvailable(account_id)); |
540 token_service->UpdateCredentials(account_id, "refresh_token"); | 549 token_service->UpdateCredentials(account_id, "refresh_token"); |
541 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(account_id)); | 550 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(account_id)); |
542 | 551 |
543 // That should have notified the manager, which now issues the request for the | 552 // That should have notified the manager, which now issues the request for the |
544 // policy oauth token. | 553 // policy oauth token. |
545 MockDeviceManagementJob* register_request = IssueOAuthToken(true); | 554 MockDeviceManagementJob* register_request = IssueOAuthToken(true); |
546 ASSERT_TRUE(register_request); | 555 ASSERT_TRUE(register_request); |
547 register_request->SendResponse(DM_STATUS_SUCCESS, register_blob_); | 556 register_request->SendResponse(DM_STATUS_SUCCESS, register_blob_); |
548 | 557 |
(...skipping 20 matching lines...) Expand all Loading... |
569 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); | 578 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); |
570 EXPECT_TRUE(manager_->core()->client()->is_registered()); | 579 EXPECT_TRUE(manager_->core()->client()->is_registered()); |
571 | 580 |
572 // The refresh scheduler takes care of the initial fetch for unmanaged users. | 581 // The refresh scheduler takes care of the initial fetch for unmanaged users. |
573 // Running the task runner issues the initial fetch. | 582 // Running the task runner issues the initial fetch. |
574 FetchPolicy( | 583 FetchPolicy( |
575 base::Bind(&base::TestSimpleTaskRunner::RunUntilIdle, task_runner_)); | 584 base::Bind(&base::TestSimpleTaskRunner::RunUntilIdle, task_runner_)); |
576 } | 585 } |
577 | 586 |
578 } // namespace policy | 587 } // namespace policy |
OLD | NEW |