| 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/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 13 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/test/test_simple_task_runner.h" | 17 #include "base/test/test_simple_task_runner.h" |
| 17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 18 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 18 #include "chrome/browser/chromeos/policy/user_cloud_policy_token_forwarder.h" | 19 #include "chrome/browser/chromeos/policy/user_cloud_policy_token_forwarder.h" |
| 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 20 #include "chrome/browser/prefs/browser_prefs.h" | 21 #include "chrome/browser/prefs/browser_prefs.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 37 #include "components/prefs/testing_pref_service.h" | 38 #include "components/prefs/testing_pref_service.h" |
| 38 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" | 39 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| 39 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 40 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 40 #include "components/signin/core/browser/signin_manager.h" | 41 #include "components/signin/core/browser/signin_manager.h" |
| 41 #include "components/syncable_prefs/pref_service_syncable.h" | 42 #include "components/syncable_prefs/pref_service_syncable.h" |
| 42 #include "components/user_manager/fake_user_manager.h" | 43 #include "components/user_manager/fake_user_manager.h" |
| 43 #include "content/public/test/test_browser_thread_bundle.h" | 44 #include "content/public/test/test_browser_thread_bundle.h" |
| 44 #include "google_apis/gaia/gaia_auth_consumer.h" | 45 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 45 #include "google_apis/gaia/gaia_constants.h" | 46 #include "google_apis/gaia/gaia_constants.h" |
| 46 #include "google_apis/gaia/gaia_urls.h" | 47 #include "google_apis/gaia/gaia_urls.h" |
| 48 #include "net/http/http_response_headers.h" |
| 47 #include "net/url_request/test_url_fetcher_factory.h" | 49 #include "net/url_request/test_url_fetcher_factory.h" |
| 48 #include "net/url_request/url_fetcher_delegate.h" | 50 #include "net/url_request/url_fetcher_delegate.h" |
| 49 #include "net/url_request/url_request_context_getter.h" | 51 #include "net/url_request/url_request_context_getter.h" |
| 50 #include "net/url_request/url_request_status.h" | 52 #include "net/url_request/url_request_status.h" |
| 51 #include "policy/policy_constants.h" | 53 #include "policy/policy_constants.h" |
| 52 #include "policy/proto/device_management_backend.pb.h" | 54 #include "policy/proto/device_management_backend.pb.h" |
| 53 #include "testing/gmock/include/gmock/gmock.h" | 55 #include "testing/gmock/include/gmock/gmock.h" |
| 54 #include "testing/gtest/include/gtest/gtest.h" | 56 #include "testing/gtest/include/gtest/gtest.h" |
| 55 | 57 |
| 56 namespace em = enterprise_management; | 58 namespace em = enterprise_management; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 .WillOnce(device_management_service_.CreateAsyncJob(®ister_request)); | 235 .WillOnce(device_management_service_.CreateAsyncJob(®ister_request)); |
| 234 | 236 |
| 235 if (!has_request_token) { | 237 if (!has_request_token) { |
| 236 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); | 238 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); |
| 237 net::TestURLFetcher* fetcher = NULL; | 239 net::TestURLFetcher* fetcher = NULL; |
| 238 | 240 |
| 239 // Issue the oauth_token cookie first. | 241 // Issue the oauth_token cookie first. |
| 240 fetcher = PrepareOAuthFetcher(gaia_urls->client_login_to_oauth2_url()); | 242 fetcher = PrepareOAuthFetcher(gaia_urls->client_login_to_oauth2_url()); |
| 241 if (!fetcher) | 243 if (!fetcher) |
| 242 return NULL; | 244 return NULL; |
| 243 net::ResponseCookies cookies; | |
| 244 cookies.push_back(kOAuthCodeCookie); | |
| 245 | 245 |
| 246 fetcher->set_cookies(cookies); | 246 scoped_refptr<net::HttpResponseHeaders> reponse_headers = |
| 247 new net::HttpResponseHeaders(""); |
| 248 reponse_headers->AddCookie(kOAuthCodeCookie); |
| 249 fetcher->set_response_headers(reponse_headers); |
| 247 fetcher->delegate()->OnURLFetchComplete(fetcher); | 250 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 248 | 251 |
| 249 // Issue the refresh token. | 252 // Issue the refresh token. |
| 250 fetcher = PrepareOAuthFetcher(gaia_urls->oauth2_token_url()); | 253 fetcher = PrepareOAuthFetcher(gaia_urls->oauth2_token_url()); |
| 251 if (!fetcher) | 254 if (!fetcher) |
| 252 return NULL; | 255 return NULL; |
| 253 fetcher->SetResponseString(kOAuth2TokenPairData); | 256 fetcher->SetResponseString(kOAuth2TokenPairData); |
| 254 fetcher->delegate()->OnURLFetchComplete(fetcher); | 257 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 255 | 258 |
| 256 // Issue the access token. | 259 // Issue the access token. |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); | 601 EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME)); |
| 599 EXPECT_TRUE(manager_->core()->client()->is_registered()); | 602 EXPECT_TRUE(manager_->core()->client()->is_registered()); |
| 600 | 603 |
| 601 // The refresh scheduler takes care of the initial fetch for unmanaged users. | 604 // The refresh scheduler takes care of the initial fetch for unmanaged users. |
| 602 // Running the task runner issues the initial fetch. | 605 // Running the task runner issues the initial fetch. |
| 603 FetchPolicy( | 606 FetchPolicy( |
| 604 base::Bind(&base::TestSimpleTaskRunner::RunUntilIdle, task_runner_)); | 607 base::Bind(&base::TestSimpleTaskRunner::RunUntilIdle, task_runner_)); |
| 605 } | 608 } |
| 606 | 609 |
| 607 } // namespace policy | 610 } // namespace policy |
| OLD | NEW |