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

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

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

Powered by Google App Engine
This is Rietveld 408576698