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

Side by Side Diff: chrome/browser/signin/signin_manager_unittest.cc

Issue 12546016: Remove the Extensions URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile gdi. Created 7 years, 4 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 "chrome/browser/signin/signin_manager.h" 5 #include "chrome/browser/signin/signin_manager.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/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/prefs/testing_pref_service.h" 11 #include "base/prefs/testing_pref_service.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/prefs/browser_prefs.h" 16 #include "chrome/browser/prefs/browser_prefs.h"
17 #include "chrome/browser/signin/chrome_signin_manager_delegate.h" 17 #include "chrome/browser/signin/chrome_signin_manager_delegate.h"
18 #include "chrome/browser/signin/token_service.h" 18 #include "chrome/browser/signin/token_service.h"
19 #include "chrome/browser/signin/token_service_unittest.h" 19 #include "chrome/browser/signin/token_service_unittest.h"
20 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
21 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
22 #include "chrome/test/base/testing_browser_process.h" 22 #include "chrome/test/base/testing_browser_process.h"
23 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
24 #include "components/webdata/encryptor/encryptor.h" 24 #include "components/webdata/encryptor/encryptor.h"
25 #include "content/public/browser/child_process_security_policy.h" 25 #include "content/public/browser/child_process_security_policy.h"
26 #include "content/public/browser/cookie_store_map.h"
27 #include "content/public/browser/storage_partition.h"
26 #include "content/public/test/test_browser_thread_bundle.h" 28 #include "content/public/test/test_browser_thread_bundle.h"
27 #include "google_apis/gaia/gaia_constants.h" 29 #include "google_apis/gaia/gaia_constants.h"
28 #include "google_apis/gaia/gaia_urls.h" 30 #include "google_apis/gaia/gaia_urls.h"
29 #include "net/cookies/cookie_monster.h" 31 #include "net/cookies/cookie_monster.h"
30 #include "net/url_request/test_url_fetcher_factory.h" 32 #include "net/url_request/test_url_fetcher_factory.h"
31 #include "net/url_request/url_request.h" 33 #include "net/url_request/url_request.h"
32 #include "net/url_request/url_request_context_getter.h" 34 #include "net/url_request/url_request_context_getter.h"
33 #include "net/url_request/url_request_status.h" 35 #include "net/url_request/url_request_status.h"
34 36
35 #include "testing/gmock/include/gmock/gmock.h" 37 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 void CompleteSigninCallback(const std::string& oauth_token) { 195 void CompleteSigninCallback(const std::string& oauth_token) {
194 oauth_tokens_fetched_.push_back(oauth_token); 196 oauth_tokens_fetched_.push_back(oauth_token);
195 manager_->CompletePendingSignin(); 197 manager_->CompletePendingSignin();
196 } 198 }
197 199
198 void CancelSigninCallback(const std::string& oauth_token) { 200 void CancelSigninCallback(const std::string& oauth_token) {
199 oauth_tokens_fetched_.push_back(oauth_token); 201 oauth_tokens_fetched_.push_back(oauth_token);
200 manager_->SignOut(); 202 manager_->SignOut();
201 } 203 }
202 204
205 net::CookieMonster* GetCookieMonster(const GURL& origin) {
206 using content::BrowserContext;
207 // Since it's a unittest, assume default StoragePartition.
208 const content::CookieStoreMap& cookie_store_map =
209 BrowserContext::GetDefaultStoragePartition(profile())->
210 GetCookieStoreMap();
211 return cookie_store_map.GetForScheme(origin.scheme())->GetCookieMonster();
212 }
213
203 net::TestURLFetcherFactory factory_; 214 net::TestURLFetcherFactory factory_;
204 scoped_ptr<SigninManager> manager_; 215 scoped_ptr<SigninManager> manager_;
205 content::TestNotificationTracker google_login_success_; 216 content::TestNotificationTracker google_login_success_;
206 content::TestNotificationTracker google_login_failure_; 217 content::TestNotificationTracker google_login_failure_;
207 std::vector<std::string> oauth_tokens_fetched_; 218 std::vector<std::string> oauth_tokens_fetched_;
208 scoped_ptr<TestingPrefServiceSimple> prefs_; 219 scoped_ptr<TestingPrefServiceSimple> prefs_;
209 std::vector<std::string> cookies_; 220 std::vector<std::string> cookies_;
210 }; 221 };
211 222
212 // NOTE: ClientLogin's "StartSignin" is called after collecting credentials 223 // NOTE: ClientLogin's "StartSignin" is called after collecting credentials
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 SigninManager::OAuthTokenFetchedCallback()); 293 SigninManager::OAuthTokenFetchedCallback());
283 294
284 ExpectSignInWithCredentialsFail(true /* requestSent */); 295 ExpectSignInWithCredentialsFail(true /* requestSent */);
285 } 296 }
286 297
287 TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordValidCookie) { 298 TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordValidCookie) {
288 manager_->Initialize(profile(), NULL); 299 manager_->Initialize(profile(), NULL);
289 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 300 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
290 301
291 // Set a valid LSID cookie in the test cookie store. 302 // Set a valid LSID cookie in the test cookie store.
292 scoped_refptr<net::CookieMonster> cookie_monster = 303 GURL origin("https://accounts.google.com");
293 profile()->GetCookieMonster(); 304 scoped_refptr<net::CookieMonster> cookie_monster = GetCookieMonster(origin);
294 net::CookieOptions options; 305 net::CookieOptions options;
295 options.set_include_httponly(); 306 options.set_include_httponly();
296 cookie_monster->SetCookieWithOptionsAsync( 307 cookie_monster->SetCookieWithOptionsAsync(
297 GURL("https://accounts.google.com"), 308 origin,
298 "LSID=1234; secure; httponly", options, 309 "LSID=1234; secure; httponly", options,
299 net::CookieMonster::SetCookiesCallback()); 310 net::CookieMonster::SetCookiesCallback());
300 311
301 // Since the password is empty, will verify the gaia cookies first. 312 // Since the password is empty, will verify the gaia cookies first.
302 manager_->StartSignInWithCredentials( 313 manager_->StartSignInWithCredentials(
303 "0", 314 "0",
304 "user@gmail.com", 315 "user@gmail.com",
305 std::string(), 316 std::string(),
306 SigninManager::OAuthTokenFetchedCallback()); 317 SigninManager::OAuthTokenFetchedCallback());
307 318
308 base::RunLoop().RunUntilIdle(); 319 base::RunLoop().RunUntilIdle();
309 320
(...skipping 17 matching lines...) Expand all
327 // Since the test cookie store is empty, verification should fail and throws 338 // Since the test cookie store is empty, verification should fail and throws
328 // a login error. 339 // a login error.
329 ExpectSignInWithCredentialsFail(false /* requestSent */); 340 ExpectSignInWithCredentialsFail(false /* requestSent */);
330 } 341 }
331 342
332 TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordInValidCookie) { 343 TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordInValidCookie) {
333 manager_->Initialize(profile(), NULL); 344 manager_->Initialize(profile(), NULL);
334 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 345 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
335 346
336 // Set an invalid LSID cookie in the test cookie store. 347 // Set an invalid LSID cookie in the test cookie store.
337 scoped_refptr<net::CookieMonster> cookie_monster = 348 GURL origin("https://accounts.google.com");
338 profile()->GetCookieMonster(); 349 scoped_refptr<net::CookieMonster> cookie_monster = GetCookieMonster(origin);
339 net::CookieOptions options; 350 net::CookieOptions options;
340 options.set_include_httponly(); 351 options.set_include_httponly();
341 cookie_monster->SetCookieWithOptionsAsync( 352 cookie_monster->SetCookieWithOptionsAsync(
342 GURL("https://accounts.google.com"), 353 origin,
343 "LSID=1234; domain=google.com; secure; httponly", options, 354 "LSID=1234; domain=google.com; secure; httponly", options,
344 net::CookieMonster::SetCookiesCallback()); 355 net::CookieMonster::SetCookiesCallback());
345 356
346 // Since the password is empty, must verify the gaia cookies first. 357 // Since the password is empty, must verify the gaia cookies first.
347 manager_->StartSignInWithCredentials( 358 manager_->StartSignInWithCredentials(
348 "0", 359 "0",
349 "user@gmail.com", 360 "user@gmail.com",
350 std::string(), 361 std::string(),
351 SigninManager::OAuthTokenFetchedCallback()); 362 SigninManager::OAuthTokenFetchedCallback());
352 363
353 base::RunLoop().RunUntilIdle(); 364 base::RunLoop().RunUntilIdle();
354 365
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 EXPECT_EQ("", manager_->GetAuthenticatedUsername()); 634 EXPECT_EQ("", manager_->GetAuthenticatedUsername());
624 EXPECT_EQ(0u, google_login_success_.size()); 635 EXPECT_EQ(0u, google_login_success_.size());
625 636
626 manager_->OnExternalSigninCompleted("external@example.com"); 637 manager_->OnExternalSigninCompleted("external@example.com");
627 EXPECT_EQ(1u, google_login_success_.size()); 638 EXPECT_EQ(1u, google_login_success_.size());
628 EXPECT_EQ(0u, google_login_failure_.size()); 639 EXPECT_EQ(0u, google_login_failure_.size());
629 EXPECT_EQ("external@example.com", 640 EXPECT_EQ("external@example.com",
630 profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); 641 profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername));
631 EXPECT_EQ("external@example.com", manager_->GetAuthenticatedUsername()); 642 EXPECT_EQ("external@example.com", manager_->GetAuthenticatedUsername());
632 } 643 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698