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/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "components/policy/core/common/cloud/mock_user_cloud_policy_store.h" | 29 #include "components/policy/core/common/cloud/mock_user_cloud_policy_store.h" |
30 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" | 30 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" |
31 #include "components/policy/core/common/schema_registry.h" | 31 #include "components/policy/core/common/schema_registry.h" |
32 #include "components/signin/core/browser/signin_manager.h" | 32 #include "components/signin/core/browser/signin_manager.h" |
33 #include "content/public/browser/browser_context.h" | 33 #include "content/public/browser/browser_context.h" |
34 #include "content/public/browser/notification_details.h" | 34 #include "content/public/browser/notification_details.h" |
35 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
36 #include "content/public/browser/notification_source.h" | 36 #include "content/public/browser/notification_source.h" |
37 #include "content/public/test/test_browser_thread_bundle.h" | 37 #include "content/public/test/test_browser_thread_bundle.h" |
38 #include "google_apis/gaia/gaia_constants.h" | 38 #include "google_apis/gaia/gaia_constants.h" |
39 #include "google_apis/gaia/gaia_oauth_client.h" | |
40 #include "google_apis/gaia/google_service_auth_error.h" | 39 #include "google_apis/gaia/google_service_auth_error.h" |
41 #include "net/http/http_status_code.h" | 40 #include "net/http/http_status_code.h" |
42 #include "net/url_request/test_url_fetcher_factory.h" | 41 #include "net/url_request/test_url_fetcher_factory.h" |
43 #include "net/url_request/url_request_context_getter.h" | 42 #include "net/url_request/url_request_context_getter.h" |
44 #include "net/url_request/url_request_status.h" | 43 #include "net/url_request/url_request_status.h" |
45 #include "net/url_request/url_request_test_util.h" | 44 #include "net/url_request/url_request_test_util.h" |
46 #include "testing/gmock/include/gmock/gmock.h" | 45 #include "testing/gmock/include/gmock/gmock.h" |
47 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
48 | 47 |
49 #if defined(OS_ANDROID) | 48 #if defined(OS_ANDROID) |
(...skipping 18 matching lines...) Expand all Loading... |
68 const char kValidTokenResponse[] = | 67 const char kValidTokenResponse[] = |
69 "{" | 68 "{" |
70 " \"access_token\": \"at1\"," | 69 " \"access_token\": \"at1\"," |
71 " \"expires_in\": 3600," | 70 " \"expires_in\": 3600," |
72 " \"token_type\": \"Bearer\"" | 71 " \"token_type\": \"Bearer\"" |
73 "}"; | 72 "}"; |
74 #endif | 73 #endif |
75 | 74 |
76 const char kHostedDomainResponse[] = | 75 const char kHostedDomainResponse[] = |
77 "{" | 76 "{" |
78 " \"domain\": \"test.com\"" | 77 " \"hd\": \"test.com\"" |
79 "}"; | 78 "}"; |
80 | 79 |
81 class SigninManagerFake : public FakeSigninManager { | 80 class SigninManagerFake : public FakeSigninManager { |
82 public: | 81 public: |
83 explicit SigninManagerFake(Profile* profile) | 82 explicit SigninManagerFake(Profile* profile) |
84 : FakeSigninManager(profile) { | 83 : FakeSigninManager(profile) { |
85 Initialize(NULL); | 84 Initialize(NULL); |
86 } | 85 } |
87 | 86 |
88 void ForceSignOut() { | 87 void ForceSignOut() { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 content::Source<Profile>(profile_.get()), | 224 content::Source<Profile>(profile_.get()), |
226 content::NotificationService::NoDetails()); | 225 content::NotificationService::NoDetails()); |
227 } | 226 } |
228 | 227 |
229 FakeProfileOAuth2TokenService* GetTokenService() { | 228 FakeProfileOAuth2TokenService* GetTokenService() { |
230 ProfileOAuth2TokenService* service = | 229 ProfileOAuth2TokenService* service = |
231 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); | 230 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); |
232 return static_cast<FakeProfileOAuth2TokenService*>(service); | 231 return static_cast<FakeProfileOAuth2TokenService*>(service); |
233 } | 232 } |
234 | 233 |
235 // Returns true if a request for policy information is active. A request | |
236 // is considered active if there is an active fetcher for an access token | |
237 // hosted domain information (i.e. the gaia oauth client) or some other | |
238 // fecther used in the code (id 0). | |
239 bool IsRequestActive() { | 234 bool IsRequestActive() { |
240 if (!GetTokenService()->GetPendingRequests().empty()) | 235 if (!GetTokenService()->GetPendingRequests().empty()) |
241 return true; | 236 return true; |
242 return url_factory_.GetFetcherByID(0) || | 237 return url_factory_.GetFetcherByID(0); |
243 url_factory_.GetFetcherByID(gaia::GaiaOAuthClient::kUrlFetcherId); | |
244 } | 238 } |
245 | 239 |
246 void MakeOAuthTokenFetchSucceed() { | 240 void MakeOAuthTokenFetchSucceed() { |
247 ASSERT_TRUE(IsRequestActive()); | 241 ASSERT_TRUE(IsRequestActive()); |
248 #if defined(OS_ANDROID) | 242 #if defined(OS_ANDROID) |
249 GetTokenService()->IssueTokenForAllPendingRequests("access_token", | 243 GetTokenService()->IssueTokenForAllPendingRequests("access_token", |
250 base::Time::Now()); | 244 base::Time::Now()); |
251 #else | 245 #else |
252 net::TestURLFetcher* fetcher = url_factory_.GetFetcherByID(0); | 246 net::TestURLFetcher* fetcher = url_factory_.GetFetcherByID(0); |
253 fetcher->set_response_code(net::HTTP_OK); | 247 fetcher->set_response_code(net::HTTP_OK); |
254 fetcher->SetResponseString(kValidTokenResponse); | 248 fetcher->SetResponseString(kValidTokenResponse); |
255 fetcher->delegate()->OnURLFetchComplete(fetcher); | 249 fetcher->delegate()->OnURLFetchComplete(fetcher); |
256 #endif | 250 #endif |
257 } | 251 } |
258 | 252 |
259 void ReportHostedDomainStatus(bool is_hosted_domain) { | 253 void ReportHostedDomainStatus(bool is_hosted_domain) { |
260 ASSERT_TRUE(IsRequestActive()); | 254 ASSERT_TRUE(IsRequestActive()); |
261 net::TestURLFetcher* fetcher = | 255 net::TestURLFetcher* fetcher = url_factory_.GetFetcherByID(0); |
262 url_factory_.GetFetcherByID(gaia::GaiaOAuthClient::kUrlFetcherId); | |
263 fetcher->set_response_code(net::HTTP_OK); | 256 fetcher->set_response_code(net::HTTP_OK); |
264 fetcher->SetResponseString(is_hosted_domain ? kHostedDomainResponse : "{}"); | 257 fetcher->SetResponseString(is_hosted_domain ? kHostedDomainResponse : "{}"); |
265 fetcher->delegate()->OnURLFetchComplete(fetcher); | 258 fetcher->delegate()->OnURLFetchComplete(fetcher); |
266 } | 259 } |
267 | 260 |
268 void TestSuccessfulSignin() { | 261 void TestSuccessfulSignin() { |
269 UserPolicySigninService* signin_service = | 262 UserPolicySigninService* signin_service = |
270 UserPolicySigninServiceFactory::GetForProfile(profile_.get()); | 263 UserPolicySigninServiceFactory::GetForProfile(profile_.get()); |
271 EXPECT_CALL(*this, OnPolicyRefresh(true)).Times(0); | 264 EXPECT_CALL(*this, OnPolicyRefresh(true)).Times(0); |
272 RegisterPolicyClientWithCallback(signin_service); | 265 RegisterPolicyClientWithCallback(signin_service); |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 base::RunLoop().RunUntilIdle(); | 805 base::RunLoop().RunUntilIdle(); |
813 EXPECT_FALSE(manager_->IsClientRegistered()); | 806 EXPECT_FALSE(manager_->IsClientRegistered()); |
814 #if !defined(OS_ANDROID) | 807 #if !defined(OS_ANDROID) |
815 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); | 808 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); |
816 #endif | 809 #endif |
817 } | 810 } |
818 | 811 |
819 } // namespace | 812 } // namespace |
820 | 813 |
821 } // namespace policy | 814 } // namespace policy |
OLD | NEW |