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

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

Issue 8373021: Convert URLFetcher::Delegates to use an interface in content/public/common. Also remove the old U... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync and remove unncessary forward declares Created 9 years, 2 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/common/net/gaia/gaia_auth_fetcher_unittest.h" 8 #include "chrome/common/net/gaia/gaia_auth_fetcher_unittest.h"
9 9
10 #include <string> 10 #include <string>
11 11
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "chrome/common/net/gaia/gaia_auth_consumer.h" 14 #include "chrome/common/net/gaia/gaia_auth_consumer.h"
15 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" 15 #include "chrome/common/net/gaia/gaia_auth_fetcher.h"
16 #include "chrome/common/net/gaia/gaia_urls.h" 16 #include "chrome/common/net/gaia/gaia_urls.h"
17 #include "chrome/common/net/gaia/google_service_auth_error.h" 17 #include "chrome/common/net/gaia/google_service_auth_error.h"
18 #include "chrome/common/net/http_return.h" 18 #include "chrome/common/net/http_return.h"
19 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
20 #include "content/common/net/url_fetcher.h" 20 #include "content/common/net/url_fetcher.h"
21 #include "content/public/common/url_fetcher_delegate.h"
21 #include "content/test/test_url_fetcher_factory.h" 22 #include "content/test/test_url_fetcher_factory.h"
22 #include "googleurl/src/gurl.h" 23 #include "googleurl/src/gurl.h"
23 #include "net/base/load_flags.h" 24 #include "net/base/load_flags.h"
24 #include "net/base/net_errors.h" 25 #include "net/base/net_errors.h"
25 #include "net/url_request/url_request_status.h" 26 #include "net/url_request/url_request_status.h"
26 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 29
29 using ::testing::_; 30 using ::testing::_;
30 31
31 MockFetcher::MockFetcher(bool success, 32 MockFetcher::MockFetcher(bool success,
32 const GURL& url, 33 const GURL& url,
33 const std::string& results, 34 const std::string& results,
34 URLFetcher::RequestType request_type, 35 URLFetcher::RequestType request_type,
35 URLFetcher::Delegate* d) 36 content::URLFetcherDelegate* d)
36 : URLFetcher(url, request_type, d), 37 : URLFetcher(url, request_type, d),
37 success_(success),
38 url_(url), 38 url_(url),
39 results_(results) {} 39 results_(results) {
40 net::URLRequestStatus::Status code;
41
42 if (success) {
43 response_code_ = RC_REQUEST_OK;
44 code = net::URLRequestStatus::SUCCESS;
45 } else {
46 response_code_ = RC_FORBIDDEN;
47 code = net::URLRequestStatus::FAILED;
48 }
49
50 status_ = net::URLRequestStatus(code, 0);
51 }
52
53 MockFetcher::MockFetcher(const GURL& url,
54 const net::URLRequestStatus& status,
55 int response_code,
56 const net::ResponseCookies& cookies,
57 const std::string& results,
58 URLFetcher::RequestType request_type,
59 content::URLFetcherDelegate* d)
60 : URLFetcher(url, request_type, d),
61 url_(url),
62 status_(status),
63 response_code_(response_code),
64 cookies_(cookies),
65 results_(results) {
66 }
40 67
41 MockFetcher::~MockFetcher() {} 68 MockFetcher::~MockFetcher() {}
42 69
43 void MockFetcher::Start() { 70 void MockFetcher::Start() {
44 net::URLRequestStatus::Status code; 71 delegate()->OnURLFetchComplete(this);
45 int http_code; 72 }
46 if (success_) {
47 http_code = RC_REQUEST_OK;
48 code = net::URLRequestStatus::SUCCESS;
49 } else {
50 http_code = RC_FORBIDDEN;
51 code = net::URLRequestStatus::FAILED;
52 }
53 73
54 net::URLRequestStatus status(code, 0); 74 const GURL& MockFetcher::url() const {
55 delegate()->OnURLFetchComplete(NULL, 75 return url_;
56 url_, 76 }
57 status, 77
58 http_code, 78 const net::URLRequestStatus& MockFetcher::status() const {
59 net::ResponseCookies(), 79 return status_;
60 results_); 80 }
81
82 int MockFetcher::response_code() const {
83 return response_code_;
84 }
85
86 const net::ResponseCookies& MockFetcher::cookies() const {
87 return cookies_;
88 }
89
90 bool MockFetcher::GetResponseAsString(std::string* out_response_string) const {
91 *out_response_string = results_;
92 return true;
61 } 93 }
62 94
63 95
64 class GaiaAuthFetcherTest : public testing::Test { 96 class GaiaAuthFetcherTest : public testing::Test {
65 public: 97 public:
66 GaiaAuthFetcherTest() 98 GaiaAuthFetcherTest()
67 : client_login_source_(GaiaUrls::GetInstance()->client_login_url()), 99 : client_login_source_(GaiaUrls::GetInstance()->client_login_url()),
68 issue_auth_token_source_( 100 issue_auth_token_source_(
69 GaiaUrls::GetInstance()->issue_auth_token_url()), 101 GaiaUrls::GetInstance()->issue_auth_token_url()),
70 token_auth_source_(GaiaUrls::GetInstance()->token_auth_url()), 102 token_auth_source_(GaiaUrls::GetInstance()->token_auth_url()),
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 GoogleServiceAuthError expected_error = 198 GoogleServiceAuthError expected_error =
167 GoogleServiceAuthError::FromConnectionError(error_no); 199 GoogleServiceAuthError::FromConnectionError(error_no);
168 200
169 MockGaiaConsumer consumer; 201 MockGaiaConsumer consumer;
170 EXPECT_CALL(consumer, OnClientLoginFailure(expected_error)) 202 EXPECT_CALL(consumer, OnClientLoginFailure(expected_error))
171 .Times(1); 203 .Times(1);
172 204
173 GaiaAuthFetcher auth(&consumer, std::string(), 205 GaiaAuthFetcher auth(&consumer, std::string(),
174 profile_.GetRequestContext()); 206 profile_.GetRequestContext());
175 207
176 auth.OnURLFetchComplete(NULL, 208 MockFetcher mock_fetcher(
177 client_login_source_, 209 client_login_source_, status, 0, net::ResponseCookies(), std::string(),
178 status, 210 URLFetcher::GET, &auth);
179 0, 211 auth.OnURLFetchComplete(&mock_fetcher);
180 cookies_,
181 std::string());
182 } 212 }
183 213
184 TEST_F(GaiaAuthFetcherTest, TokenNetFailure) { 214 TEST_F(GaiaAuthFetcherTest, TokenNetFailure) {
185 int error_no = net::ERR_CONNECTION_RESET; 215 int error_no = net::ERR_CONNECTION_RESET;
186 net::URLRequestStatus status(net::URLRequestStatus::FAILED, error_no); 216 net::URLRequestStatus status(net::URLRequestStatus::FAILED, error_no);
187 217
188 GoogleServiceAuthError expected_error = 218 GoogleServiceAuthError expected_error =
189 GoogleServiceAuthError::FromConnectionError(error_no); 219 GoogleServiceAuthError::FromConnectionError(error_no);
190 220
191 MockGaiaConsumer consumer; 221 MockGaiaConsumer consumer;
192 EXPECT_CALL(consumer, OnIssueAuthTokenFailure(_, expected_error)) 222 EXPECT_CALL(consumer, OnIssueAuthTokenFailure(_, expected_error))
193 .Times(1); 223 .Times(1);
194 224
195 GaiaAuthFetcher auth(&consumer, std::string(), 225 GaiaAuthFetcher auth(&consumer, std::string(),
196 profile_.GetRequestContext()); 226 profile_.GetRequestContext());
197 227
198 auth.OnURLFetchComplete(NULL, 228 MockFetcher mock_fetcher(
199 issue_auth_token_source_, 229 issue_auth_token_source_, status, 0, cookies_, std::string(),
200 status, 230 URLFetcher::GET, &auth);
201 0, 231 auth.OnURLFetchComplete(&mock_fetcher);
202 cookies_,
203 std::string());
204 } 232 }
205 233
206 234
207 TEST_F(GaiaAuthFetcherTest, LoginDenied) { 235 TEST_F(GaiaAuthFetcherTest, LoginDenied) {
208 std::string data("Error=BadAuthentication"); 236 std::string data("Error=BadAuthentication");
209 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 237 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
210 238
211 GoogleServiceAuthError expected_error( 239 GoogleServiceAuthError expected_error(
212 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 240 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
213 241
214 MockGaiaConsumer consumer; 242 MockGaiaConsumer consumer;
215 EXPECT_CALL(consumer, OnClientLoginFailure(expected_error)) 243 EXPECT_CALL(consumer, OnClientLoginFailure(expected_error))
216 .Times(1); 244 .Times(1);
217 245
218 GaiaAuthFetcher auth(&consumer, std::string(), 246 GaiaAuthFetcher auth(&consumer, std::string(),
219 profile_.GetRequestContext()); 247 profile_.GetRequestContext());
220 auth.OnURLFetchComplete(NULL, 248
221 client_login_source_, 249 MockFetcher mock_fetcher(
222 status, 250 client_login_source_, status, RC_FORBIDDEN, cookies_, data,
223 RC_FORBIDDEN, 251 URLFetcher::GET, &auth);
224 cookies_, 252 auth.OnURLFetchComplete(&mock_fetcher);
225 data);
226 } 253 }
227 254
228 TEST_F(GaiaAuthFetcherTest, ParseRequest) { 255 TEST_F(GaiaAuthFetcherTest, ParseRequest) {
229 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth\n", "sid", "lsid", "auth"); 256 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth\n", "sid", "lsid", "auth");
230 RunParsingTest("LSID=lsid\nSID=sid\nAuth=auth\n", "sid", "lsid", "auth"); 257 RunParsingTest("LSID=lsid\nSID=sid\nAuth=auth\n", "sid", "lsid", "auth");
231 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth", "sid", "lsid", "auth"); 258 RunParsingTest("SID=sid\nLSID=lsid\nAuth=auth", "sid", "lsid", "auth");
232 RunParsingTest("SID=sid\nAuth=auth\n", "sid", "", "auth"); 259 RunParsingTest("SID=sid\nAuth=auth\n", "sid", "", "auth");
233 RunParsingTest("LSID=lsid\nAuth=auth\n", "", "lsid", "auth"); 260 RunParsingTest("LSID=lsid\nAuth=auth\n", "", "lsid", "auth");
234 RunParsingTest("\nAuth=auth\n", "", "", "auth"); 261 RunParsingTest("\nAuth=auth\n", "", "", "auth");
235 RunParsingTest("SID=sid", "sid", "", ""); 262 RunParsingTest("SID=sid", "sid", "", "");
(...skipping 24 matching lines...) Expand all
260 result.token = "auth"; 287 result.token = "auth";
261 result.data = data; 288 result.data = data;
262 289
263 MockGaiaConsumer consumer; 290 MockGaiaConsumer consumer;
264 EXPECT_CALL(consumer, OnClientLoginSuccess(result)) 291 EXPECT_CALL(consumer, OnClientLoginSuccess(result))
265 .Times(1); 292 .Times(1);
266 293
267 GaiaAuthFetcher auth(&consumer, std::string(), 294 GaiaAuthFetcher auth(&consumer, std::string(),
268 profile_.GetRequestContext()); 295 profile_.GetRequestContext());
269 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 296 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
270 auth.OnURLFetchComplete(NULL, 297 MockFetcher mock_fetcher(
271 client_login_source_, 298 client_login_source_, status, RC_REQUEST_OK, cookies_, data,
272 status, 299 URLFetcher::GET, &auth);
273 RC_REQUEST_OK, 300 auth.OnURLFetchComplete(&mock_fetcher);
274 cookies_,
275 data);
276 } 301 }
277 302
278 TEST_F(GaiaAuthFetcherTest, WorkingIssueAuthToken) { 303 TEST_F(GaiaAuthFetcherTest, WorkingIssueAuthToken) {
279 MockGaiaConsumer consumer; 304 MockGaiaConsumer consumer;
280 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess(_, "token")) 305 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess(_, "token"))
281 .Times(1); 306 .Times(1);
282 307
283 GaiaAuthFetcher auth(&consumer, std::string(), 308 GaiaAuthFetcher auth(&consumer, std::string(),
284 profile_.GetRequestContext()); 309 profile_.GetRequestContext());
285 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 310 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
286 auth.OnURLFetchComplete(NULL, 311 MockFetcher mock_fetcher(
287 issue_auth_token_source_, 312 issue_auth_token_source_, status, RC_REQUEST_OK, cookies_, "token",
288 status, 313 URLFetcher::GET, &auth);
289 RC_REQUEST_OK, 314 auth.OnURLFetchComplete(&mock_fetcher);
290 cookies_,
291 "token");
292 } 315 }
293 316
294 TEST_F(GaiaAuthFetcherTest, CheckTwoFactorResponse) { 317 TEST_F(GaiaAuthFetcherTest, CheckTwoFactorResponse) {
295 std::string response = 318 std::string response =
296 base::StringPrintf("Error=BadAuthentication\n%s\n", 319 base::StringPrintf("Error=BadAuthentication\n%s\n",
297 GaiaAuthFetcher::kSecondFactor); 320 GaiaAuthFetcher::kSecondFactor);
298 EXPECT_TRUE(GaiaAuthFetcher::IsSecondFactorSuccess(response)); 321 EXPECT_TRUE(GaiaAuthFetcher::IsSecondFactorSuccess(response));
299 } 322 }
300 323
301 TEST_F(GaiaAuthFetcherTest, CheckNormalErrorCode) { 324 TEST_F(GaiaAuthFetcherTest, CheckNormalErrorCode) {
302 std::string response = "Error=BadAuthentication\n"; 325 std::string response = "Error=BadAuthentication\n";
303 EXPECT_FALSE(GaiaAuthFetcher::IsSecondFactorSuccess(response)); 326 EXPECT_FALSE(GaiaAuthFetcher::IsSecondFactorSuccess(response));
304 } 327 }
305 328
306 TEST_F(GaiaAuthFetcherTest, TwoFactorLogin) { 329 TEST_F(GaiaAuthFetcherTest, TwoFactorLogin) {
307 std::string response = base::StringPrintf("Error=BadAuthentication\n%s\n", 330 std::string response = base::StringPrintf("Error=BadAuthentication\n%s\n",
308 GaiaAuthFetcher::kSecondFactor); 331 GaiaAuthFetcher::kSecondFactor);
309 332
310 GoogleServiceAuthError error = 333 GoogleServiceAuthError error =
311 GoogleServiceAuthError(GoogleServiceAuthError::TWO_FACTOR); 334 GoogleServiceAuthError(GoogleServiceAuthError::TWO_FACTOR);
312 335
313 MockGaiaConsumer consumer; 336 MockGaiaConsumer consumer;
314 EXPECT_CALL(consumer, OnClientLoginFailure(error)) 337 EXPECT_CALL(consumer, OnClientLoginFailure(error))
315 .Times(1); 338 .Times(1);
316 339
317 GaiaAuthFetcher auth(&consumer, std::string(), 340 GaiaAuthFetcher auth(&consumer, std::string(),
318 profile_.GetRequestContext()); 341 profile_.GetRequestContext());
319 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 342 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
320 auth.OnURLFetchComplete(NULL, 343 MockFetcher mock_fetcher(
321 client_login_source_, 344 client_login_source_, status, RC_FORBIDDEN, cookies_, response,
322 status, 345 URLFetcher::GET, &auth);
323 RC_FORBIDDEN, 346 auth.OnURLFetchComplete(&mock_fetcher);
324 cookies_,
325 response);
326 } 347 }
327 348
328 TEST_F(GaiaAuthFetcherTest, CaptchaParse) { 349 TEST_F(GaiaAuthFetcherTest, CaptchaParse) {
329 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 350 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
330 std::string data = "Url=http://www.google.com/login/captcha\n" 351 std::string data = "Url=http://www.google.com/login/captcha\n"
331 "Error=CaptchaRequired\n" 352 "Error=CaptchaRequired\n"
332 "CaptchaToken=CCTOKEN\n" 353 "CaptchaToken=CCTOKEN\n"
333 "CaptchaUrl=Captcha?ctoken=CCTOKEN\n"; 354 "CaptchaUrl=Captcha?ctoken=CCTOKEN\n";
334 GoogleServiceAuthError error = 355 GoogleServiceAuthError error =
335 GaiaAuthFetcher::GenerateAuthError(data, status); 356 GaiaAuthFetcher::GenerateAuthError(data, status);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 GaiaAuthFetcher auth(&consumer, std::string(), 487 GaiaAuthFetcher auth(&consumer, std::string(),
467 profile_.GetRequestContext()); 488 profile_.GetRequestContext());
468 auth.StartClientLogin("username", 489 auth.StartClientLogin("username",
469 "password", 490 "password",
470 "service", 491 "service",
471 std::string(), 492 std::string(),
472 std::string(), 493 std::string(),
473 GaiaAuthFetcher::HostedAccountsAllowed); 494 GaiaAuthFetcher::HostedAccountsAllowed);
474 495
475 EXPECT_TRUE(auth.HasPendingFetch()); 496 EXPECT_TRUE(auth.HasPendingFetch());
476 auth.OnURLFetchComplete( 497 MockFetcher mock_fetcher(
477 NULL,
478 client_login_source_, 498 client_login_source_,
479 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 499 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
480 RC_REQUEST_OK, 500 RC_REQUEST_OK, cookies_, "SID=sid\nLSID=lsid\nAuth=auth\n",
481 cookies_, 501 URLFetcher::GET, &auth);
482 "SID=sid\nLSID=lsid\nAuth=auth\n"); 502 auth.OnURLFetchComplete(&mock_fetcher);
483 EXPECT_FALSE(auth.HasPendingFetch()); 503 EXPECT_FALSE(auth.HasPendingFetch());
484 } 504 }
485 505
486 TEST_F(GaiaAuthFetcherTest, FullTokenSuccess) { 506 TEST_F(GaiaAuthFetcherTest, FullTokenSuccess) {
487 MockGaiaConsumer consumer; 507 MockGaiaConsumer consumer;
488 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess("service", "token")) 508 EXPECT_CALL(consumer, OnIssueAuthTokenSuccess("service", "token"))
489 .Times(1); 509 .Times(1);
490 510
491 TestingProfile profile; 511 TestingProfile profile;
492 512
493 TestURLFetcherFactory factory; 513 TestURLFetcherFactory factory;
494 GaiaAuthFetcher auth(&consumer, std::string(), 514 GaiaAuthFetcher auth(&consumer, std::string(),
495 profile_.GetRequestContext()); 515 profile_.GetRequestContext());
496 auth.StartIssueAuthToken("sid", "lsid", "service"); 516 auth.StartIssueAuthToken("sid", "lsid", "service");
497 517
498 EXPECT_TRUE(auth.HasPendingFetch()); 518 EXPECT_TRUE(auth.HasPendingFetch());
499 auth.OnURLFetchComplete( 519 MockFetcher mock_fetcher(
500 NULL,
501 issue_auth_token_source_, 520 issue_auth_token_source_,
502 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 521 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
503 RC_REQUEST_OK, 522 RC_REQUEST_OK, cookies_, "token",
504 cookies_, 523 URLFetcher::GET, &auth);
505 "token"); 524 auth.OnURLFetchComplete(&mock_fetcher);
506 EXPECT_FALSE(auth.HasPendingFetch()); 525 EXPECT_FALSE(auth.HasPendingFetch());
507 } 526 }
508 527
509 TEST_F(GaiaAuthFetcherTest, FullTokenFailure) { 528 TEST_F(GaiaAuthFetcherTest, FullTokenFailure) {
510 MockGaiaConsumer consumer; 529 MockGaiaConsumer consumer;
511 EXPECT_CALL(consumer, OnIssueAuthTokenFailure("service", _)) 530 EXPECT_CALL(consumer, OnIssueAuthTokenFailure("service", _))
512 .Times(1); 531 .Times(1);
513 532
514 TestingProfile profile; 533 TestingProfile profile;
515 TestURLFetcherFactory factory; 534 TestURLFetcherFactory factory;
516 535
517 GaiaAuthFetcher auth(&consumer, std::string(), 536 GaiaAuthFetcher auth(&consumer, std::string(),
518 profile_.GetRequestContext()); 537 profile_.GetRequestContext());
519 auth.StartIssueAuthToken("sid", "lsid", "service"); 538 auth.StartIssueAuthToken("sid", "lsid", "service");
520 539
521 EXPECT_TRUE(auth.HasPendingFetch()); 540 EXPECT_TRUE(auth.HasPendingFetch());
522 auth.OnURLFetchComplete( 541 MockFetcher mock_fetcher(
523 NULL,
524 issue_auth_token_source_, 542 issue_auth_token_source_,
525 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 543 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
526 RC_FORBIDDEN, 544 RC_FORBIDDEN, cookies_, "", URLFetcher::GET, &auth);
527 cookies_, 545 auth.OnURLFetchComplete(&mock_fetcher);
528 "");
529 EXPECT_FALSE(auth.HasPendingFetch()); 546 EXPECT_FALSE(auth.HasPendingFetch());
530 } 547 }
531 548
532 TEST_F(GaiaAuthFetcherTest, TokenAuthSuccess) { 549 TEST_F(GaiaAuthFetcherTest, TokenAuthSuccess) {
533 MockGaiaConsumer consumer; 550 MockGaiaConsumer consumer;
534 EXPECT_CALL(consumer, OnTokenAuthSuccess("<html></html>")) 551 EXPECT_CALL(consumer, OnTokenAuthSuccess("<html></html>"))
535 .Times(1); 552 .Times(1);
536 553
537 TestingProfile profile; 554 TestingProfile profile;
538 TestURLFetcherFactory factory; 555 TestURLFetcherFactory factory;
539 556
540 GaiaAuthFetcher auth(&consumer, std::string(), 557 GaiaAuthFetcher auth(&consumer, std::string(),
541 profile_.GetRequestContext()); 558 profile_.GetRequestContext());
542 auth.StartTokenAuth("myubertoken"); 559 auth.StartTokenAuth("myubertoken");
543 560
544 EXPECT_TRUE(auth.HasPendingFetch()); 561 EXPECT_TRUE(auth.HasPendingFetch());
545 auth.OnURLFetchComplete( 562 MockFetcher mock_fetcher(
546 NULL,
547 token_auth_source_, 563 token_auth_source_,
548 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 564 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
549 RC_REQUEST_OK, 565 RC_REQUEST_OK, cookies_, "<html></html>", URLFetcher::GET, &auth);
550 cookies_, 566 auth.OnURLFetchComplete(&mock_fetcher);
551 "<html></html>");
552 EXPECT_FALSE(auth.HasPendingFetch()); 567 EXPECT_FALSE(auth.HasPendingFetch());
553 } 568 }
554 569
555 TEST_F(GaiaAuthFetcherTest, TokenAuthUnauthorizedFailure) { 570 TEST_F(GaiaAuthFetcherTest, TokenAuthUnauthorizedFailure) {
556 MockGaiaConsumer consumer; 571 MockGaiaConsumer consumer;
557 EXPECT_CALL(consumer, OnTokenAuthFailure(_)) 572 EXPECT_CALL(consumer, OnTokenAuthFailure(_))
558 .Times(1); 573 .Times(1);
559 574
560 TestingProfile profile; 575 TestingProfile profile;
561 TestURLFetcherFactory factory; 576 TestURLFetcherFactory factory;
562 577
563 GaiaAuthFetcher auth(&consumer, std::string(), 578 GaiaAuthFetcher auth(&consumer, std::string(),
564 profile_.GetRequestContext()); 579 profile_.GetRequestContext());
565 auth.StartTokenAuth("badubertoken"); 580 auth.StartTokenAuth("badubertoken");
566 581
567 EXPECT_TRUE(auth.HasPendingFetch()); 582 EXPECT_TRUE(auth.HasPendingFetch());
568 auth.OnURLFetchComplete( 583 MockFetcher mock_fetcher(
569 NULL,
570 token_auth_source_, 584 token_auth_source_,
571 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 585 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
572 RC_UNAUTHORIZED, 586 RC_UNAUTHORIZED, cookies_, "", URLFetcher::GET, &auth);
573 cookies_, 587 auth.OnURLFetchComplete(&mock_fetcher);
574 "");
575 EXPECT_FALSE(auth.HasPendingFetch()); 588 EXPECT_FALSE(auth.HasPendingFetch());
576 } 589 }
577 590
578 TEST_F(GaiaAuthFetcherTest, TokenAuthNetFailure) { 591 TEST_F(GaiaAuthFetcherTest, TokenAuthNetFailure) {
579 MockGaiaConsumer consumer; 592 MockGaiaConsumer consumer;
580 EXPECT_CALL(consumer, OnTokenAuthFailure(_)) 593 EXPECT_CALL(consumer, OnTokenAuthFailure(_))
581 .Times(1); 594 .Times(1);
582 595
583 TestingProfile profile; 596 TestingProfile profile;
584 TestURLFetcherFactory factory; 597 TestURLFetcherFactory factory;
585 598
586 GaiaAuthFetcher auth(&consumer, std::string(), 599 GaiaAuthFetcher auth(&consumer, std::string(),
587 profile_.GetRequestContext()); 600 profile_.GetRequestContext());
588 auth.StartTokenAuth("badubertoken"); 601 auth.StartTokenAuth("badubertoken");
589 602
590 EXPECT_TRUE(auth.HasPendingFetch()); 603 EXPECT_TRUE(auth.HasPendingFetch());
591 auth.OnURLFetchComplete( 604 MockFetcher mock_fetcher(
592 NULL,
593 token_auth_source_, 605 token_auth_source_,
594 net::URLRequestStatus(net::URLRequestStatus::FAILED, 0), 606 net::URLRequestStatus(net::URLRequestStatus::FAILED, 0),
595 RC_REQUEST_OK, 607 RC_REQUEST_OK, cookies_, "", URLFetcher::GET, &auth);
596 cookies_, 608 auth.OnURLFetchComplete(&mock_fetcher);
597 "");
598 EXPECT_FALSE(auth.HasPendingFetch()); 609 EXPECT_FALSE(auth.HasPendingFetch());
599 } 610 }
600 611
601 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) { 612 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccess) {
602 MockGaiaConsumer consumer; 613 MockGaiaConsumer consumer;
603 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) 614 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>"))
604 .Times(1); 615 .Times(1);
605 616
606 TestingProfile profile; 617 TestingProfile profile;
607 TestURLFetcherFactory factory; 618 TestURLFetcherFactory factory;
608 619
609 GaiaAuthFetcher auth(&consumer, std::string(), 620 GaiaAuthFetcher auth(&consumer, std::string(),
610 profile_.GetRequestContext()); 621 profile_.GetRequestContext());
611 auth.StartMergeSession("myubertoken"); 622 auth.StartMergeSession("myubertoken");
612 623
613 EXPECT_TRUE(auth.HasPendingFetch()); 624 EXPECT_TRUE(auth.HasPendingFetch());
614 auth.OnURLFetchComplete( 625 MockFetcher mock_fetcher(
615 NULL,
616 merge_session_source_, 626 merge_session_source_,
617 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0), 627 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
618 RC_REQUEST_OK, 628 RC_REQUEST_OK, cookies_, "<html></html>", URLFetcher::GET, &auth);
619 cookies_, 629 auth.OnURLFetchComplete(&mock_fetcher);
620 "<html></html>");
621 EXPECT_FALSE(auth.HasPendingFetch()); 630 EXPECT_FALSE(auth.HasPendingFetch());
622 } 631 }
623 632
624 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccessRedirect) { 633 TEST_F(GaiaAuthFetcherTest, MergeSessionSuccessRedirect) {
625 MockGaiaConsumer consumer; 634 MockGaiaConsumer consumer;
626 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>")) 635 EXPECT_CALL(consumer, OnMergeSessionSuccess("<html></html>"))
627 .Times(1); 636 .Times(1);
628 637
629 TestingProfile profile; 638 TestingProfile profile;
630 TestURLFetcherFactory factory; 639 TestURLFetcherFactory factory;
631 640
632 GaiaAuthFetcher auth(&consumer, std::string(), 641 GaiaAuthFetcher auth(&consumer, std::string(),
633 profile_.GetRequestContext()); 642 profile_.GetRequestContext());
634 auth.StartMergeSession("myubertoken"); 643 auth.StartMergeSession("myubertoken");
635 644
636 // Make sure the fetcher created has the expected flags. Set its url() 645 // Make sure the fetcher created has the expected flags. Set its url()
637 // properties to reflect a redirect. 646 // properties to reflect a redirect.
638 TestURLFetcher* test_fetcher = factory.GetFetcherByID(0); 647 TestURLFetcher* test_fetcher = factory.GetFetcherByID(0);
639 EXPECT_TRUE(test_fetcher != NULL); 648 EXPECT_TRUE(test_fetcher != NULL);
640 EXPECT_TRUE(test_fetcher->load_flags() == net::LOAD_NORMAL); 649 EXPECT_TRUE(test_fetcher->load_flags() == net::LOAD_NORMAL);
641 EXPECT_TRUE(auth.HasPendingFetch()); 650 EXPECT_TRUE(auth.HasPendingFetch());
642 651
643 GURL final_url("http://www.google.com/CheckCookie"); 652 GURL final_url("http://www.google.com/CheckCookie");
644 test_fetcher->set_url(final_url); 653 test_fetcher->set_url(final_url);
654 test_fetcher->set_status(
655 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0));
656 test_fetcher->set_response_code(RC_REQUEST_OK);
657 test_fetcher->set_cookies(cookies_);
658 test_fetcher->SetResponseString("<html></html>");
645 659
646 auth.OnURLFetchComplete( 660 auth.OnURLFetchComplete(test_fetcher);
647 test_fetcher,
648 test_fetcher->url(),
649 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0),
650 RC_REQUEST_OK,
651 cookies_,
652 "<html></html>");
653 EXPECT_FALSE(auth.HasPendingFetch()); 661 EXPECT_FALSE(auth.HasPendingFetch());
654 } 662 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698