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

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

Issue 257773002: Use new people.get api instead of oauth2/v1/userinfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix user image manager tests Created 6 years, 7 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/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
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"
39 #include "google_apis/gaia/google_service_auth_error.h" 40 #include "google_apis/gaia/google_service_auth_error.h"
40 #include "net/http/http_status_code.h" 41 #include "net/http/http_status_code.h"
41 #include "net/url_request/test_url_fetcher_factory.h" 42 #include "net/url_request/test_url_fetcher_factory.h"
42 #include "net/url_request/url_request_context_getter.h" 43 #include "net/url_request/url_request_context_getter.h"
43 #include "net/url_request/url_request_status.h" 44 #include "net/url_request/url_request_status.h"
44 #include "net/url_request/url_request_test_util.h" 45 #include "net/url_request/url_request_test_util.h"
45 #include "testing/gmock/include/gmock/gmock.h" 46 #include "testing/gmock/include/gmock/gmock.h"
46 #include "testing/gtest/include/gtest/gtest.h" 47 #include "testing/gtest/include/gtest/gtest.h"
47 48
48 #if defined(OS_ANDROID) 49 #if defined(OS_ANDROID)
(...skipping 18 matching lines...) Expand all
67 const char kValidTokenResponse[] = 68 const char kValidTokenResponse[] =
68 "{" 69 "{"
69 " \"access_token\": \"at1\"," 70 " \"access_token\": \"at1\","
70 " \"expires_in\": 3600," 71 " \"expires_in\": 3600,"
71 " \"token_type\": \"Bearer\"" 72 " \"token_type\": \"Bearer\""
72 "}"; 73 "}";
73 #endif 74 #endif
74 75
75 const char kHostedDomainResponse[] = 76 const char kHostedDomainResponse[] =
76 "{" 77 "{"
77 " \"hd\": \"test.com\"" 78 " \"domain\": \"test.com\""
78 "}"; 79 "}";
79 80
80 class SigninManagerFake : public FakeSigninManager { 81 class SigninManagerFake : public FakeSigninManager {
81 public: 82 public:
82 explicit SigninManagerFake(Profile* profile) 83 explicit SigninManagerFake(Profile* profile)
83 : FakeSigninManager(profile) { 84 : FakeSigninManager(profile) {
84 Initialize(NULL); 85 Initialize(NULL);
85 } 86 }
86 87
87 void ForceSignOut() { 88 void ForceSignOut() {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 content::Source<Profile>(profile_.get()), 225 content::Source<Profile>(profile_.get()),
225 content::NotificationService::NoDetails()); 226 content::NotificationService::NoDetails());
226 } 227 }
227 228
228 FakeProfileOAuth2TokenService* GetTokenService() { 229 FakeProfileOAuth2TokenService* GetTokenService() {
229 ProfileOAuth2TokenService* service = 230 ProfileOAuth2TokenService* service =
230 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); 231 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get());
231 return static_cast<FakeProfileOAuth2TokenService*>(service); 232 return static_cast<FakeProfileOAuth2TokenService*>(service);
232 } 233 }
233 234
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).
234 bool IsRequestActive() { 239 bool IsRequestActive() {
235 if (!GetTokenService()->GetPendingRequests().empty()) 240 if (!GetTokenService()->GetPendingRequests().empty())
236 return true; 241 return true;
237 return url_factory_.GetFetcherByID(0); 242 return url_factory_.GetFetcherByID(0) ||
243 url_factory_.GetFetcherByID(gaia::GaiaOAuthClient::kUrlFetcherId);
238 } 244 }
239 245
240 void MakeOAuthTokenFetchSucceed() { 246 void MakeOAuthTokenFetchSucceed() {
241 ASSERT_TRUE(IsRequestActive()); 247 ASSERT_TRUE(IsRequestActive());
242 #if defined(OS_ANDROID) 248 #if defined(OS_ANDROID)
243 GetTokenService()->IssueTokenForAllPendingRequests("access_token", 249 GetTokenService()->IssueTokenForAllPendingRequests("access_token",
244 base::Time::Now()); 250 base::Time::Now());
245 #else 251 #else
246 net::TestURLFetcher* fetcher = url_factory_.GetFetcherByID(0); 252 net::TestURLFetcher* fetcher = url_factory_.GetFetcherByID(0);
247 fetcher->set_response_code(net::HTTP_OK); 253 fetcher->set_response_code(net::HTTP_OK);
248 fetcher->SetResponseString(kValidTokenResponse); 254 fetcher->SetResponseString(kValidTokenResponse);
249 fetcher->delegate()->OnURLFetchComplete(fetcher); 255 fetcher->delegate()->OnURLFetchComplete(fetcher);
250 #endif 256 #endif
251 } 257 }
252 258
253 void ReportHostedDomainStatus(bool is_hosted_domain) { 259 void ReportHostedDomainStatus(bool is_hosted_domain) {
254 ASSERT_TRUE(IsRequestActive()); 260 ASSERT_TRUE(IsRequestActive());
255 net::TestURLFetcher* fetcher = url_factory_.GetFetcherByID(0); 261 net::TestURLFetcher* fetcher =
262 url_factory_.GetFetcherByID(gaia::GaiaOAuthClient::kUrlFetcherId);
256 fetcher->set_response_code(net::HTTP_OK); 263 fetcher->set_response_code(net::HTTP_OK);
257 fetcher->SetResponseString(is_hosted_domain ? kHostedDomainResponse : "{}"); 264 fetcher->SetResponseString(is_hosted_domain ? kHostedDomainResponse : "{}");
258 fetcher->delegate()->OnURLFetchComplete(fetcher); 265 fetcher->delegate()->OnURLFetchComplete(fetcher);
259 } 266 }
260 267
261 void TestSuccessfulSignin() { 268 void TestSuccessfulSignin() {
262 UserPolicySigninService* signin_service = 269 UserPolicySigninService* signin_service =
263 UserPolicySigninServiceFactory::GetForProfile(profile_.get()); 270 UserPolicySigninServiceFactory::GetForProfile(profile_.get());
264 EXPECT_CALL(*this, OnPolicyRefresh(true)).Times(0); 271 EXPECT_CALL(*this, OnPolicyRefresh(true)).Times(0);
265 RegisterPolicyClientWithCallback(signin_service); 272 RegisterPolicyClientWithCallback(signin_service);
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 base::RunLoop().RunUntilIdle(); 812 base::RunLoop().RunUntilIdle();
806 EXPECT_FALSE(manager_->IsClientRegistered()); 813 EXPECT_FALSE(manager_->IsClientRegistered());
807 #if !defined(OS_ANDROID) 814 #if !defined(OS_ANDROID)
808 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); 815 EXPECT_FALSE(signin_manager_->IsSignoutProhibited());
809 #endif 816 #endif
810 } 817 }
811 818
812 } // namespace 819 } // namespace
813 820
814 } // namespace policy 821 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/wildcard_login_checker.cc ('k') | chrome/browser/profiles/profile_downloader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698