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

Side by Side Diff: chrome/common/net/gaia/gaia_auth_fetcher_unittest.cc

Issue 10412050: Change most content::URLFetcher references to net::URLFetcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ChromeOS, address comments Created 8 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 // A complete set of unit tests for GaiaAuthFetcher. 5 // A complete set of unit tests for GaiaAuthFetcher.
6 // Originally ported from GoogleAuthenticator tests. 6 // Originally ported from GoogleAuthenticator tests.
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 EXPECT_EQ("prompt_text", error.second_factor().prompt_text); 77 EXPECT_EQ("prompt_text", error.second_factor().prompt_text);
78 EXPECT_EQ("alternate_text", error.second_factor().alternate_text); 78 EXPECT_EQ("alternate_text", error.second_factor().alternate_text);
79 EXPECT_EQ(10, error.second_factor().field_length); 79 EXPECT_EQ(10, error.second_factor().field_length);
80 } 80 }
81 81
82 } // namespace 82 } // namespace
83 83
84 MockFetcher::MockFetcher(bool success, 84 MockFetcher::MockFetcher(bool success,
85 const GURL& url, 85 const GURL& url,
86 const std::string& results, 86 const std::string& results,
87 content::URLFetcher::RequestType request_type, 87 net::URLFetcher::RequestType request_type,
88 net::URLFetcherDelegate* d) 88 net::URLFetcherDelegate* d)
89 : TestURLFetcher(0, url, d) { 89 : TestURLFetcher(0, url, d) {
90 set_url(url); 90 set_url(url);
91 net::URLRequestStatus::Status code; 91 net::URLRequestStatus::Status code;
92 92
93 if (success) { 93 if (success) {
94 set_response_code(net::HTTP_OK); 94 set_response_code(net::HTTP_OK);
95 code = net::URLRequestStatus::SUCCESS; 95 code = net::URLRequestStatus::SUCCESS;
96 } else { 96 } else {
97 set_response_code(net::HTTP_FORBIDDEN); 97 set_response_code(net::HTTP_FORBIDDEN);
98 code = net::URLRequestStatus::FAILED; 98 code = net::URLRequestStatus::FAILED;
99 } 99 }
100 100
101 set_status(net::URLRequestStatus(code, 0)); 101 set_status(net::URLRequestStatus(code, 0));
102 SetResponseString(results); 102 SetResponseString(results);
103 } 103 }
104 104
105 MockFetcher::MockFetcher(const GURL& url, 105 MockFetcher::MockFetcher(const GURL& url,
106 const net::URLRequestStatus& status, 106 const net::URLRequestStatus& status,
107 int response_code, 107 int response_code,
108 const net::ResponseCookies& cookies, 108 const net::ResponseCookies& cookies,
109 const std::string& results, 109 const std::string& results,
110 content::URLFetcher::RequestType request_type, 110 net::URLFetcher::RequestType request_type,
111 net::URLFetcherDelegate* d) 111 net::URLFetcherDelegate* d)
112 : TestURLFetcher(0, url, d) { 112 : TestURLFetcher(0, url, d) {
113 set_url(url); 113 set_url(url);
114 set_status(status); 114 set_status(status);
115 set_response_code(response_code); 115 set_response_code(response_code);
116 set_cookies(cookies); 116 set_cookies(cookies);
117 SetResponseString(results); 117 SetResponseString(results);
118 } 118 }
119 119
120 MockFetcher::~MockFetcher() {} 120 MockFetcher::~MockFetcher() {}
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 257
258 MockGaiaConsumer consumer; 258 MockGaiaConsumer consumer;
259 EXPECT_CALL(consumer, OnClientLoginFailure(expected_error)) 259 EXPECT_CALL(consumer, OnClientLoginFailure(expected_error))
260 .Times(1); 260 .Times(1);
261 261
262 GaiaAuthFetcher auth(&consumer, std::string(), 262 GaiaAuthFetcher auth(&consumer, std::string(),
263 profile_.GetRequestContext()); 263 profile_.GetRequestContext());
264 264
265 MockFetcher mock_fetcher( 265 MockFetcher mock_fetcher(
266 client_login_source_, status, 0, net::ResponseCookies(), std::string(), 266 client_login_source_, status, 0, net::ResponseCookies(), std::string(),
267 content::URLFetcher::GET, &auth); 267 net::URLFetcher::GET, &auth);
268 auth.OnURLFetchComplete(&mock_fetcher); 268 auth.OnURLFetchComplete(&mock_fetcher);
269 } 269 }
270 270
271 TEST_F(GaiaAuthFetcherTest, TokenNetFailure) { 271 TEST_F(GaiaAuthFetcherTest, TokenNetFailure) {
272 int error_no = net::ERR_CONNECTION_RESET; 272 int error_no = net::ERR_CONNECTION_RESET;
273 net::URLRequestStatus status(net::URLRequestStatus::FAILED, error_no); 273 net::URLRequestStatus status(net::URLRequestStatus::FAILED, error_no);
274 274
275 GoogleServiceAuthError expected_error = 275 GoogleServiceAuthError expected_error =
276 GoogleServiceAuthError::FromConnectionError(error_no); 276 GoogleServiceAuthError::FromConnectionError(error_no);
277 277
278 MockGaiaConsumer consumer; 278 MockGaiaConsumer consumer;
279 EXPECT_CALL(consumer, OnIssueAuthTokenFailure(_, expected_error)) 279 EXPECT_CALL(consumer, OnIssueAuthTokenFailure(_, expected_error))
280 .Times(1); 280 .Times(1);
281 281
282 GaiaAuthFetcher auth(&consumer, std::string(), 282 GaiaAuthFetcher auth(&consumer, std::string(),
283 profile_.GetRequestContext()); 283 profile_.GetRequestContext());
284 284
285 MockFetcher mock_fetcher( 285 MockFetcher mock_fetcher(
286 issue_auth_token_source_, status, 0, cookies_, std::string(), 286 issue_auth_token_source_, status, 0, cookies_, std::string(),
287 content::URLFetcher::GET, &auth); 287 net::URLFetcher::GET, &auth);
288 auth.OnURLFetchComplete(&mock_fetcher); 288 auth.OnURLFetchComplete(&mock_fetcher);
289 } 289 }
290 290
291 291
292 TEST_F(GaiaAuthFetcherTest, LoginDenied) { 292 TEST_F(GaiaAuthFetcherTest, LoginDenied) {
293 std::string data("Error=BadAuthentication"); 293 std::string data("Error=BadAuthentication");
294 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 294 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
295 295
296 GoogleServiceAuthError expected_error( 296 GoogleServiceAuthError expected_error(
297 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 297 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
298 298
299 MockGaiaConsumer consumer; 299 MockGaiaConsumer consumer;
300 EXPECT_CALL(consumer, OnClientLoginFailure(expected_error)) 300 EXPECT_CALL(consumer, OnClientLoginFailure(expected_error))
301 .Times(1); 301 .Times(1);
302 302
303 GaiaAuthFetcher auth(&consumer, std::string(), 303 GaiaAuthFetcher auth(&consumer, std::string(),
304 profile_.GetRequestContext()); 304 profile_.GetRequestContext());
305 305
306 MockFetcher mock_fetcher( 306 MockFetcher mock_fetcher(
307 client_login_source_, status, net::HTTP_FORBIDDEN, cookies_, data, 307 client_login_source_, status, net::HTTP_FORBIDDEN, cookies_, data,
308 content::URLFetcher::GET, &auth); 308 net::URLFetcher::GET, &auth);
309 auth.OnURLFetchComplete(&mock_fetcher); 309 auth.OnURLFetchComplete(&mock_fetcher);
310 } 310 }
311 311
312 TEST_F(GaiaAuthFetcherTest, ParseRequest) { 312 TEST_F(GaiaAuthFetcherTest, ParseRequest) {
313 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth\n", "sid", "lsid", "auth"); 313 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth\n", "sid", "lsid", "auth");
314 RunParsingTest("LSID=lsid\nSID=sid\nAuth=auth\n", "sid", "lsid", "auth"); 314 RunParsingTest("LSID=lsid\nSID=sid\nAuth=auth\n", "sid", "lsid", "auth");
315 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth", "sid", "lsid", "auth"); 315 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth", "sid", "lsid", "auth");
316 RunParsingTest("SID=sid\nAuth=auth\n", "sid", "", "auth"); 316 RunParsingTest("SID=sid\nAuth=auth\n", "sid", "", "auth");
317 RunParsingTest("LSID=lsid\nAuth=auth\n", "", "lsid", "auth"); 317 RunParsingTest("LSID=lsid\nAuth=auth\n", "", "lsid", "auth");
318 RunParsingTest("\nAuth=auth\n", "", "", "auth"); 318 RunParsingTest("\nAuth=auth\n", "", "", "auth");
(...skipping 27 matching lines...) Expand all
346 346
347 MockGaiaConsumer consumer; 347 MockGaiaConsumer consumer;
348 EXPECT_CALL(consumer, OnClientLoginSuccess(result)) 348 EXPECT_CALL(consumer, OnClientLoginSuccess(result))
349 .Times(1); 349 .Times(1);
350 350
351 GaiaAuthFetcher auth(&consumer, std::string(), 351 GaiaAuthFetcher auth(&consumer, std::string(),
352 profile_.GetRequestContext()); 352 profile_.GetRequestContext());
353 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 353 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
354 MockFetcher mock_fetcher( 354 MockFetcher mock_fetcher(
355 client_login_source_, status, net::HTTP_OK, cookies_, data, 355 client_login_source_, status, net::HTTP_OK, cookies_, data,
356 content::URLFetcher::GET, &auth); 356 net::URLFetcher::GET, &auth);
357 auth.OnURLFetchComplete(&mock_fetcher); 357 auth.OnURLFetchComplete(&mock_fetcher);
358 } 358 }
359 359
360 TEST_F(GaiaAuthFetcherTest, WorkingIssueAuthToken) { 360 TEST_F(GaiaAuthFetcherTest, WorkingIssueAuthToken) {
361 MockGaiaConsumer consumer; 361 MockGaiaConsumer consumer;
362 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess(_, "token")) 362 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess(_, "token"))
363 .Times(1); 363 .Times(1);
364 364
365 GaiaAuthFetcher auth(&consumer, std::string(), 365 GaiaAuthFetcher auth(&consumer, std::string(),
366 profile_.GetRequestContext()); 366 profile_.GetRequestContext());
367 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 367 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
368 MockFetcher mock_fetcher( 368 MockFetcher mock_fetcher(
369 issue_auth_token_source_, status, net::HTTP_OK, cookies_, "token", 369 issue_auth_token_source_, status, net::HTTP_OK, cookies_, "token",
370 content::URLFetcher::GET, &auth); 370 net::URLFetcher::GET, &auth);
371 auth.OnURLFetchComplete(&mock_fetcher); 371 auth.OnURLFetchComplete(&mock_fetcher);
372 } 372 }
373 373
374 TEST_F(GaiaAuthFetcherTest, CheckTwoFactorResponse) { 374 TEST_F(GaiaAuthFetcherTest, CheckTwoFactorResponse) {
375 std::string response = 375 std::string response =
376 base::StringPrintf("Error=BadAuthentication\n%s\n", 376 base::StringPrintf("Error=BadAuthentication\n%s\n",
377 GaiaAuthFetcher::kSecondFactor); 377 GaiaAuthFetcher::kSecondFactor);
378 EXPECT_TRUE(GaiaAuthFetcher::IsSecondFactorSuccess(response)); 378 EXPECT_TRUE(GaiaAuthFetcher::IsSecondFactorSuccess(response));
379 } 379 }
380 380
(...skipping 11 matching lines...) Expand all
392 392
393 MockGaiaConsumer consumer; 393 MockGaiaConsumer consumer;
394 EXPECT_CALL(consumer, OnClientLoginFailure(error)) 394 EXPECT_CALL(consumer, OnClientLoginFailure(error))
395 .Times(1); 395 .Times(1);
396 396
397 GaiaAuthFetcher auth(&consumer, std::string(), 397 GaiaAuthFetcher auth(&consumer, std::string(),
398 profile_.GetRequestContext()); 398 profile_.GetRequestContext());
399 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 399 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
400 MockFetcher mock_fetcher( 400 MockFetcher mock_fetcher(
401 client_login_source_, status, net::HTTP_FORBIDDEN, cookies_, response, 401 client_login_source_, status, net::HTTP_FORBIDDEN, cookies_, response,
402 content::URLFetcher::GET, &auth); 402 net::URLFetcher::GET, &auth);
403 auth.OnURLFetchComplete(&mock_fetcher); 403 auth.OnURLFetchComplete(&mock_fetcher);
404 } 404 }
405 405
406 TEST_F(GaiaAuthFetcherTest, CaptchaParse) { 406 TEST_F(GaiaAuthFetcherTest, CaptchaParse) {
407 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 407 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
408 std::string data = "Url=http://www.google.com/login/captcha\n" 408 std::string data = "Url=http://www.google.com/login/captcha\n"
409 "Error=CaptchaRequired\n" 409 "Error=CaptchaRequired\n"
410 "CaptchaToken=CCTOKEN\n" 410 "CaptchaToken=CCTOKEN\n"
411 "CaptchaUrl=Captcha?ctoken=CCTOKEN\n"; 411 "CaptchaUrl=Captcha?ctoken=CCTOKEN\n";
412 GoogleServiceAuthError error = 412 GoogleServiceAuthError error =
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 "service", 543 "service",
544 std::string(), 544 std::string(),
545 std::string(), 545 std::string(),
546 GaiaAuthFetcher::HostedAccountsAllowed); 546 GaiaAuthFetcher::HostedAccountsAllowed);
547 547
548 EXPECT_TRUE(auth.HasPendingFetch()); 548 EXPECT_TRUE(auth.HasPendingFetch());
549 MockFetcher mock_fetcher( 549 MockFetcher mock_fetcher(
550 client_login_source_, 550 client_login_source_,
551 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 551 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
552 net::HTTP_OK, cookies_, "SID=sid\nLSID=lsid\nAuth=auth\n", 552 net::HTTP_OK, cookies_, "SID=sid\nLSID=lsid\nAuth=auth\n",
553 content::URLFetcher::GET, &auth); 553 net::URLFetcher::GET, &auth);
554 auth.OnURLFetchComplete(&mock_fetcher); 554 auth.OnURLFetchComplete(&mock_fetcher);
555 EXPECT_FALSE(auth.HasPendingFetch()); 555 EXPECT_FALSE(auth.HasPendingFetch());
556 } 556 }
557 557
558 TEST_F(GaiaAuthFetcherTest, FullTokenSuccess) { 558 TEST_F(GaiaAuthFetcherTest, FullTokenSuccess) {
559 MockGaiaConsumer consumer; 559 MockGaiaConsumer consumer;
560 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess("service", "token")) 560 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess("service", "token"))
561 .Times(1); 561 .Times(1);
562 562
563 TestURLFetcherFactory factory; 563 TestURLFetcherFactory factory;
564 GaiaAuthFetcher auth(&consumer, std::string(), 564 GaiaAuthFetcher auth(&consumer, std::string(),
565 profile_.GetRequestContext()); 565 profile_.GetRequestContext());
566 auth.StartIssueAuthToken("sid", "lsid", "service"); 566 auth.StartIssueAuthToken("sid", "lsid", "service");
567 567
568 EXPECT_TRUE(auth.HasPendingFetch()); 568 EXPECT_TRUE(auth.HasPendingFetch());
569 MockFetcher mock_fetcher( 569 MockFetcher mock_fetcher(
570 issue_auth_token_source_, 570 issue_auth_token_source_,
571 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 571 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
572 net::HTTP_OK, cookies_, "token", 572 net::HTTP_OK, cookies_, "token",
573 content::URLFetcher::GET, &auth); 573 net::URLFetcher::GET, &auth);
574 auth.OnURLFetchComplete(&mock_fetcher); 574 auth.OnURLFetchComplete(&mock_fetcher);
575 EXPECT_FALSE(auth.HasPendingFetch()); 575 EXPECT_FALSE(auth.HasPendingFetch());
576 } 576 }
577 577
578 TEST_F(GaiaAuthFetcherTest, FullTokenFailure) { 578 TEST_F(GaiaAuthFetcherTest, FullTokenFailure) {
579 MockGaiaConsumer consumer; 579 MockGaiaConsumer consumer;
580 EXPECT_CALL(consumer, OnIssueAuthTokenFailure("service", _)) 580 EXPECT_CALL(consumer, OnIssueAuthTokenFailure("service", _))
581 .Times(1); 581 .Times(1);
582 582
583 TestURLFetcherFactory factory; 583 TestURLFetcherFactory factory;
584 584
585 GaiaAuthFetcher auth(&consumer, std::string(), 585 GaiaAuthFetcher auth(&consumer, std::string(),
586 profile_.GetRequestContext()); 586 profile_.GetRequestContext());
587 auth.StartIssueAuthToken("sid", "lsid", "service"); 587 auth.StartIssueAuthToken("sid", "lsid", "service");
588 588
589 EXPECT_TRUE(auth.HasPendingFetch()); 589 EXPECT_TRUE(auth.HasPendingFetch());
590 MockFetcher mock_fetcher( 590 MockFetcher mock_fetcher(
591 issue_auth_token_source_, 591 issue_auth_token_source_,
592 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 592 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
593 net::HTTP_FORBIDDEN, cookies_, "", content::URLFetcher::GET, &auth); 593 net::HTTP_FORBIDDEN, cookies_, "", net::URLFetcher::GET, &auth);
594 auth.OnURLFetchComplete(&mock_fetcher); 594 auth.OnURLFetchComplete(&mock_fetcher);
595 EXPECT_FALSE(auth.HasPendingFetch()); 595 EXPECT_FALSE(auth.HasPendingFetch());
596 } 596 }
597 597
598 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccess) { 598 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenSuccess) {
599 MockGaiaConsumer consumer; 599 MockGaiaConsumer consumer;
600 EXPECT_CALL(consumer, OnClientOAuthSuccess( 600 EXPECT_CALL(consumer, OnClientOAuthSuccess(
601 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1); 601 GaiaAuthConsumer::ClientOAuthResult("rt1", "at1", 3600))).Times(1);
602 602
603 TestURLFetcherFactory factory; 603 TestURLFetcherFactory factory;
604 GaiaAuthFetcher auth(&consumer, std::string(), 604 GaiaAuthFetcher auth(&consumer, std::string(),
605 profile_.GetRequestContext()); 605 profile_.GetRequestContext());
606 auth.StartLsoForOAuthLoginTokenExchange("lso_token"); 606 auth.StartLsoForOAuthLoginTokenExchange("lso_token");
607 TestURLFetcher* fetcher = factory.GetFetcherByID(0); 607 TestURLFetcher* fetcher = factory.GetFetcherByID(0);
608 EXPECT_TRUE(NULL != fetcher); 608 EXPECT_TRUE(NULL != fetcher);
609 EXPECT_EQ(net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES, 609 EXPECT_EQ(net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES,
610 fetcher->GetLoadFlags()); 610 fetcher->GetLoadFlags());
611 611
612 net::ResponseCookies cookies; 612 net::ResponseCookies cookies;
613 cookies.push_back(kGetAuthCodeValidCookie); 613 cookies.push_back(kGetAuthCodeValidCookie);
614 EXPECT_TRUE(auth.HasPendingFetch()); 614 EXPECT_TRUE(auth.HasPendingFetch());
615 MockFetcher mock_fetcher1( 615 MockFetcher mock_fetcher1(
616 client_login_to_oauth2_source_, 616 client_login_to_oauth2_source_,
617 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 617 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
618 net::HTTP_OK, cookies, "", 618 net::HTTP_OK, cookies, "",
619 content::URLFetcher::POST, &auth); 619 net::URLFetcher::POST, &auth);
620 auth.OnURLFetchComplete(&mock_fetcher1); 620 auth.OnURLFetchComplete(&mock_fetcher1);
621 EXPECT_TRUE(auth.HasPendingFetch()); 621 EXPECT_TRUE(auth.HasPendingFetch());
622 MockFetcher mock_fetcher2( 622 MockFetcher mock_fetcher2(
623 oauth2_token_source_, 623 oauth2_token_source_,
624 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 624 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
625 net::HTTP_OK, cookies_, kGetTokenPairValidResponse, 625 net::HTTP_OK, cookies_, kGetTokenPairValidResponse,
626 content::URLFetcher::POST, &auth); 626 net::URLFetcher::POST, &auth);
627 auth.OnURLFetchComplete(&mock_fetcher2); 627 auth.OnURLFetchComplete(&mock_fetcher2);
628 EXPECT_FALSE(auth.HasPendingFetch()); 628 EXPECT_FALSE(auth.HasPendingFetch());
629 } 629 }
630 630
631 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenWithCookies) { 631 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenWithCookies) {
632 MockGaiaConsumer consumer; 632 MockGaiaConsumer consumer;
633 TestURLFetcherFactory factory; 633 TestURLFetcherFactory factory;
634 GaiaAuthFetcher auth(&consumer, std::string(), 634 GaiaAuthFetcher auth(&consumer, std::string(),
635 profile_.GetRequestContext()); 635 profile_.GetRequestContext());
636 auth.StartCookieForOAuthLoginTokenExchange("0"); 636 auth.StartCookieForOAuthLoginTokenExchange("0");
(...skipping 11 matching lines...) Expand all
648 GaiaAuthFetcher auth(&consumer, std::string(), 648 GaiaAuthFetcher auth(&consumer, std::string(),
649 profile_.GetRequestContext()); 649 profile_.GetRequestContext());
650 auth.StartLsoForOAuthLoginTokenExchange("lso_token"); 650 auth.StartLsoForOAuthLoginTokenExchange("lso_token");
651 651
652 net::ResponseCookies cookies; 652 net::ResponseCookies cookies;
653 EXPECT_TRUE(auth.HasPendingFetch()); 653 EXPECT_TRUE(auth.HasPendingFetch());
654 MockFetcher mock_fetcher( 654 MockFetcher mock_fetcher(
655 client_login_to_oauth2_source_, 655 client_login_to_oauth2_source_,
656 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 656 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
657 net::HTTP_FORBIDDEN, cookies, "", 657 net::HTTP_FORBIDDEN, cookies, "",
658 content::URLFetcher::POST, &auth); 658 net::URLFetcher::POST, &auth);
659 auth.OnURLFetchComplete(&mock_fetcher); 659 auth.OnURLFetchComplete(&mock_fetcher);
660 EXPECT_FALSE(auth.HasPendingFetch()); 660 EXPECT_FALSE(auth.HasPendingFetch());
661 } 661 }
662 662
663 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenOAuth2TokenPairFailure) { 663 TEST_F(GaiaAuthFetcherTest, OAuthLoginTokenOAuth2TokenPairFailure) {
664 MockGaiaConsumer consumer; 664 MockGaiaConsumer consumer;
665 EXPECT_CALL(consumer, OnClientOAuthFailure(_)) 665 EXPECT_CALL(consumer, OnClientOAuthFailure(_))
666 .Times(1); 666 .Times(1);
667 667
668 TestURLFetcherFactory factory; 668 TestURLFetcherFactory factory;
669 GaiaAuthFetcher auth(&consumer, std::string(), 669 GaiaAuthFetcher auth(&consumer, std::string(),
670 profile_.GetRequestContext()); 670 profile_.GetRequestContext());
671 auth.StartLsoForOAuthLoginTokenExchange("lso_token"); 671 auth.StartLsoForOAuthLoginTokenExchange("lso_token");
672 672
673 net::ResponseCookies cookies; 673 net::ResponseCookies cookies;
674 cookies.push_back(kGetAuthCodeValidCookie); 674 cookies.push_back(kGetAuthCodeValidCookie);
675 EXPECT_TRUE(auth.HasPendingFetch()); 675 EXPECT_TRUE(auth.HasPendingFetch());
676 MockFetcher mock_fetcher1( 676 MockFetcher mock_fetcher1(
677 client_login_to_oauth2_source_, 677 client_login_to_oauth2_source_,
678 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 678 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
679 net::HTTP_OK, cookies, "", 679 net::HTTP_OK, cookies, "",
680 content::URLFetcher::POST, &auth); 680 net::URLFetcher::POST, &auth);
681 auth.OnURLFetchComplete(&mock_fetcher1); 681 auth.OnURLFetchComplete(&mock_fetcher1);
682 EXPECT_TRUE(auth.HasPendingFetch()); 682 EXPECT_TRUE(auth.HasPendingFetch());
683 MockFetcher mock_fetcher2( 683 MockFetcher mock_fetcher2(
684 oauth2_token_source_, 684 oauth2_token_source_,
685 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 685 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
686 net::HTTP_FORBIDDEN, cookies_, "", 686 net::HTTP_FORBIDDEN, cookies_, "",
687 content::URLFetcher::POST, &auth); 687 net::URLFetcher::POST, &auth);
688 auth.OnURLFetchComplete(&mock_fetcher2); 688 auth.OnURLFetchComplete(&mock_fetcher2);
689 EXPECT_FALSE(auth.HasPendingFetch()); 689 EXPECT_FALSE(auth.HasPendingFetch());
690 } 690 }
691 691
692 TEST_F(GaiaAuthFetcherTest, TokenAuthSuccess) { 692 TEST_F(GaiaAuthFetcherTest, TokenAuthSuccess) {
693 MockGaiaConsumer consumer; 693 MockGaiaConsumer consumer;
694 net::ResponseCookies cookies; 694 net::ResponseCookies cookies;
695 EXPECT_CALL(consumer, OnTokenAuthSuccess(cookies, "<html></html>")) 695 EXPECT_CALL(consumer, OnTokenAuthSuccess(cookies, "<html></html>"))
696 .Times(1); 696 .Times(1);
697 697
698 TestURLFetcherFactory factory; 698 TestURLFetcherFactory factory;
699 699
700 GaiaAuthFetcher auth(&consumer, std::string(), 700 GaiaAuthFetcher auth(&consumer, std::string(),
701 profile_.GetRequestContext()); 701 profile_.GetRequestContext());
702 auth.StartTokenAuth("myubertoken"); 702 auth.StartTokenAuth("myubertoken");
703 703
704 EXPECT_TRUE(auth.HasPendingFetch()); 704 EXPECT_TRUE(auth.HasPendingFetch());
705 MockFetcher mock_fetcher( 705 MockFetcher mock_fetcher(
706 token_auth_source_, 706 token_auth_source_,
707 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 707 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
708 net::HTTP_OK, cookies_, "<html></html>", content::URLFetcher::GET, 708 net::HTTP_OK, cookies_, "<html></html>", net::URLFetcher::GET,
709 &auth); 709 &auth);
710 auth.OnURLFetchComplete(&mock_fetcher); 710 auth.OnURLFetchComplete(&mock_fetcher);
711 EXPECT_FALSE(auth.HasPendingFetch()); 711 EXPECT_FALSE(auth.HasPendingFetch());
712 } 712 }
713 713
714 TEST_F(GaiaAuthFetcherTest, TokenAuthUnauthorizedFailure) { 714 TEST_F(GaiaAuthFetcherTest, TokenAuthUnauthorizedFailure) {
715 MockGaiaConsumer consumer; 715 MockGaiaConsumer consumer;
716 EXPECT_CALL(consumer, OnTokenAuthFailure(_)) 716 EXPECT_CALL(consumer, OnTokenAuthFailure(_))
717 .Times(1); 717 .Times(1);
718 718
719 TestURLFetcherFactory factory; 719 TestURLFetcherFactory factory;
720 720
721 GaiaAuthFetcher auth(&consumer, std::string(), 721 GaiaAuthFetcher auth(&consumer, std::string(),
722 profile_.GetRequestContext()); 722 profile_.GetRequestContext());
723 auth.StartTokenAuth("badubertoken"); 723 auth.StartTokenAuth("badubertoken");
724 724
725 EXPECT_TRUE(auth.HasPendingFetch()); 725 EXPECT_TRUE(auth.HasPendingFetch());
726 MockFetcher mock_fetcher( 726 MockFetcher mock_fetcher(
727 token_auth_source_, 727 token_auth_source_,
728 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 728 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
729 net::HTTP_UNAUTHORIZED, cookies_, "", content::URLFetcher::GET, &auth); 729 net::HTTP_UNAUTHORIZED, cookies_, "", net::URLFetcher::GET, &auth);
730 auth.OnURLFetchComplete(&mock_fetcher); 730 auth.OnURLFetchComplete(&mock_fetcher);
731 EXPECT_FALSE(auth.HasPendingFetch()); 731 EXPECT_FALSE(auth.HasPendingFetch());
732 } 732 }
733 733
734 TEST_F(GaiaAuthFetcherTest, TokenAuthNetFailure) { 734 TEST_F(GaiaAuthFetcherTest, TokenAuthNetFailure) {
735 MockGaiaConsumer consumer; 735 MockGaiaConsumer consumer;
736 EXPECT_CALL(consumer, OnTokenAuthFailure(_)) 736 EXPECT_CALL(consumer, OnTokenAuthFailure(_))
737 .Times(1); 737 .Times(1);
738 738
739 TestURLFetcherFactory factory; 739 TestURLFetcherFactory factory;
740 740
741 GaiaAuthFetcher auth(&consumer, std::string(), 741 GaiaAuthFetcher auth(&consumer, std::string(),
742 profile_.GetRequestContext()); 742 profile_.GetRequestContext());
743 auth.StartTokenAuth("badubertoken"); 743 auth.StartTokenAuth("badubertoken");
744 744
745 EXPECT_TRUE(auth.HasPendingFetch()); 745 EXPECT_TRUE(auth.HasPendingFetch());
746 MockFetcher mock_fetcher( 746 MockFetcher mock_fetcher(
747 token_auth_source_, 747 token_auth_source_,
748 net::URLRequestStatus(net::URLRequestStatus::FAILED, 0), 748 net::URLRequestStatus(net::URLRequestStatus::FAILED, 0),
749 net::HTTP_OK, cookies_, "", content::URLFetcher::GET, &auth); 749 net::HTTP_OK, cookies_, "", net::URLFetcher::GET, &auth);
750 auth.OnURLFetchComplete(&mock_fetcher); 750 auth.OnURLFetchComplete(&mock_fetcher);
751 EXPECT_FALSE(auth.HasPendingFetch()); 751 EXPECT_FALSE(auth.HasPendingFetch());
752 } 752 }
753 753
754 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) { 754 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) {
755 MockGaiaConsumer consumer; 755 MockGaiaConsumer consumer;
756 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) 756 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>"))
757 .Times(1); 757 .Times(1);
758 758
759 TestURLFetcherFactory factory; 759 TestURLFetcherFactory factory;
760 760
761 GaiaAuthFetcher auth(&consumer, std::string(), 761 GaiaAuthFetcher auth(&consumer, std::string(),
762 profile_.GetRequestContext()); 762 profile_.GetRequestContext());
763 auth.StartMergeSession("myubertoken"); 763 auth.StartMergeSession("myubertoken");
764 764
765 EXPECT_TRUE(auth.HasPendingFetch()); 765 EXPECT_TRUE(auth.HasPendingFetch());
766 MockFetcher mock_fetcher( 766 MockFetcher mock_fetcher(
767 merge_session_source_, 767 merge_session_source_,
768 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 768 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
769 net::HTTP_OK, cookies_, "<html></html>", content::URLFetcher::GET, 769 net::HTTP_OK, cookies_, "<html></html>", net::URLFetcher::GET,
770 &auth); 770 &auth);
771 auth.OnURLFetchComplete(&mock_fetcher); 771 auth.OnURLFetchComplete(&mock_fetcher);
772 EXPECT_FALSE(auth.HasPendingFetch()); 772 EXPECT_FALSE(auth.HasPendingFetch());
773 } 773 }
774 774
775 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccessRedirect) { 775 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccessRedirect) {
776 MockGaiaConsumer consumer; 776 MockGaiaConsumer consumer;
777 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) 777 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>"))
778 .Times(1); 778 .Times(1);
779 779
(...skipping 30 matching lines...) Expand all
810 TestURLFetcherFactory factory; 810 TestURLFetcherFactory factory;
811 811
812 GaiaAuthFetcher auth(&consumer, std::string(), 812 GaiaAuthFetcher auth(&consumer, std::string(),
813 profile_.GetRequestContext()); 813 profile_.GetRequestContext());
814 auth.StartTokenFetchForUberAuthExchange("myAccessToken"); 814 auth.StartTokenFetchForUberAuthExchange("myAccessToken");
815 815
816 EXPECT_TRUE(auth.HasPendingFetch()); 816 EXPECT_TRUE(auth.HasPendingFetch());
817 MockFetcher mock_fetcher( 817 MockFetcher mock_fetcher(
818 uberauth_token_source_, 818 uberauth_token_source_,
819 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 819 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
820 net::HTTP_OK, cookies_, "uberToken", content::URLFetcher::POST, 820 net::HTTP_OK, cookies_, "uberToken", net::URLFetcher::POST,
821 &auth); 821 &auth);
822 auth.OnURLFetchComplete(&mock_fetcher); 822 auth.OnURLFetchComplete(&mock_fetcher);
823 EXPECT_FALSE(auth.HasPendingFetch()); 823 EXPECT_FALSE(auth.HasPendingFetch());
824 } 824 }
825 825
826 TEST_F(GaiaAuthFetcherTest, ParseClientLoginToOAuth2Response) { 826 TEST_F(GaiaAuthFetcherTest, ParseClientLoginToOAuth2Response) {
827 { // No cookies. 827 { // No cookies.
828 std::string auth_code; 828 std::string auth_code;
829 net::ResponseCookies cookies; 829 net::ResponseCookies cookies;
830 EXPECT_FALSE(GaiaAuthFetcher::ParseClientLoginToOAuth2Response( 830 EXPECT_FALSE(GaiaAuthFetcher::ParseClientLoginToOAuth2Response(
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 1022
1023 MockGaiaConsumer consumer; 1023 MockGaiaConsumer consumer;
1024 EXPECT_CALL(consumer, OnClientLoginSuccess(result)) 1024 EXPECT_CALL(consumer, OnClientLoginSuccess(result))
1025 .Times(1); 1025 .Times(1);
1026 1026
1027 GaiaAuthFetcher auth(&consumer, std::string(), 1027 GaiaAuthFetcher auth(&consumer, std::string(),
1028 profile_.GetRequestContext()); 1028 profile_.GetRequestContext());
1029 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 1029 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
1030 MockFetcher mock_fetcher( 1030 MockFetcher mock_fetcher(
1031 oauth_login_gurl_, status, net::HTTP_OK, cookies_, data, 1031 oauth_login_gurl_, status, net::HTTP_OK, cookies_, data,
1032 content::URLFetcher::GET, &auth); 1032 net::URLFetcher::GET, &auth);
1033 auth.OnURLFetchComplete(&mock_fetcher); 1033 auth.OnURLFetchComplete(&mock_fetcher);
1034 } 1034 }
OLDNEW
« no previous file with comments | « chrome/common/net/gaia/gaia_auth_fetcher.cc ('k') | chrome/common/net/gaia/gaia_oauth_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698