OLD | NEW |
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 "net/url_request/url_request_ftp_job.h" | 5 #include "net/url_request/url_request_ftp_job.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 302 |
303 TestDelegate request_delegate; | 303 TestDelegate request_delegate; |
304 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 304 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
305 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 305 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); |
306 url_request->Start(); | 306 url_request->Start(); |
307 ASSERT_TRUE(url_request->is_pending()); | 307 ASSERT_TRUE(url_request->is_pending()); |
308 | 308 |
309 // The TestDelegate will by default quit the message loop on completion. | 309 // The TestDelegate will by default quit the message loop on completion. |
310 base::RunLoop().Run(); | 310 base::RunLoop().Run(); |
311 | 311 |
312 EXPECT_TRUE(url_request->status().is_success()); | 312 EXPECT_EQ(OK, request_delegate.request_status()); |
313 EXPECT_TRUE(url_request->proxy_server().Equals( | 313 EXPECT_TRUE(url_request->proxy_server().Equals( |
314 HostPortPair::FromString("localhost:80"))); | 314 HostPortPair::FromString("localhost:80"))); |
315 EXPECT_EQ(1, network_delegate()->completed_requests()); | 315 EXPECT_EQ(1, network_delegate()->completed_requests()); |
316 EXPECT_EQ(0, network_delegate()->error_count()); | 316 EXPECT_EQ(0, network_delegate()->error_count()); |
317 EXPECT_FALSE(request_delegate.auth_required_called()); | 317 EXPECT_FALSE(request_delegate.auth_required_called()); |
318 EXPECT_EQ("test.html", request_delegate.data_received()); | 318 EXPECT_EQ("test.html", request_delegate.data_received()); |
319 } | 319 } |
320 | 320 |
321 // Regression test for http://crbug.com/237526. | 321 // Regression test for http://crbug.com/237526. |
322 TEST_F(URLRequestFtpJobTest, FtpProxyRequestOrphanJob) { | 322 TEST_F(URLRequestFtpJobTest, FtpProxyRequestOrphanJob) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 398 |
399 TestDelegate request_delegate; | 399 TestDelegate request_delegate; |
400 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 400 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
401 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 401 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); |
402 url_request->Start(); | 402 url_request->Start(); |
403 ASSERT_TRUE(url_request->is_pending()); | 403 ASSERT_TRUE(url_request->is_pending()); |
404 | 404 |
405 // The TestDelegate will by default quit the message loop on completion. | 405 // The TestDelegate will by default quit the message loop on completion. |
406 base::RunLoop().Run(); | 406 base::RunLoop().Run(); |
407 | 407 |
408 EXPECT_TRUE(url_request->status().is_success()); | 408 EXPECT_EQ(OK, request_delegate.request_status()); |
409 EXPECT_TRUE(url_request->proxy_server().Equals( | 409 EXPECT_TRUE(url_request->proxy_server().Equals( |
410 HostPortPair::FromString("localhost:80"))); | 410 HostPortPair::FromString("localhost:80"))); |
411 EXPECT_EQ(1, network_delegate()->completed_requests()); | 411 EXPECT_EQ(1, network_delegate()->completed_requests()); |
412 EXPECT_EQ(0, network_delegate()->error_count()); | 412 EXPECT_EQ(0, network_delegate()->error_count()); |
413 EXPECT_TRUE(request_delegate.auth_required_called()); | 413 EXPECT_TRUE(request_delegate.auth_required_called()); |
414 EXPECT_EQ("test.html", request_delegate.data_received()); | 414 EXPECT_EQ("test.html", request_delegate.data_received()); |
415 } | 415 } |
416 | 416 |
417 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedProxyAuthWithCredentials) { | 417 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedProxyAuthWithCredentials) { |
418 MockWrite writes[] = { | 418 MockWrite writes[] = { |
(...skipping 25 matching lines...) Expand all Loading... |
444 request_delegate.set_credentials( | 444 request_delegate.set_credentials( |
445 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); | 445 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); |
446 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 446 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
447 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 447 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); |
448 url_request->Start(); | 448 url_request->Start(); |
449 ASSERT_TRUE(url_request->is_pending()); | 449 ASSERT_TRUE(url_request->is_pending()); |
450 | 450 |
451 // The TestDelegate will by default quit the message loop on completion. | 451 // The TestDelegate will by default quit the message loop on completion. |
452 base::RunLoop().Run(); | 452 base::RunLoop().Run(); |
453 | 453 |
454 EXPECT_TRUE(url_request->status().is_success()); | 454 EXPECT_EQ(OK, request_delegate.request_status()); |
455 EXPECT_EQ(1, network_delegate()->completed_requests()); | 455 EXPECT_EQ(1, network_delegate()->completed_requests()); |
456 EXPECT_EQ(0, network_delegate()->error_count()); | 456 EXPECT_EQ(0, network_delegate()->error_count()); |
457 EXPECT_TRUE(request_delegate.auth_required_called()); | 457 EXPECT_TRUE(request_delegate.auth_required_called()); |
458 EXPECT_EQ("test2.html", request_delegate.data_received()); | 458 EXPECT_EQ("test2.html", request_delegate.data_received()); |
459 } | 459 } |
460 | 460 |
461 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedServerAuthNoCredentials) { | 461 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedServerAuthNoCredentials) { |
462 MockWrite writes[] = { | 462 MockWrite writes[] = { |
463 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 463 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
464 "Host: ftp.example.com\r\n" | 464 "Host: ftp.example.com\r\n" |
(...skipping 12 matching lines...) Expand all Loading... |
477 | 477 |
478 TestDelegate request_delegate; | 478 TestDelegate request_delegate; |
479 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 479 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
480 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 480 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); |
481 url_request->Start(); | 481 url_request->Start(); |
482 ASSERT_TRUE(url_request->is_pending()); | 482 ASSERT_TRUE(url_request->is_pending()); |
483 | 483 |
484 // The TestDelegate will by default quit the message loop on completion. | 484 // The TestDelegate will by default quit the message loop on completion. |
485 base::RunLoop().Run(); | 485 base::RunLoop().Run(); |
486 | 486 |
487 EXPECT_TRUE(url_request->status().is_success()); | 487 EXPECT_EQ(OK, request_delegate.request_status()); |
488 EXPECT_EQ(1, network_delegate()->completed_requests()); | 488 EXPECT_EQ(1, network_delegate()->completed_requests()); |
489 EXPECT_EQ(0, network_delegate()->error_count()); | 489 EXPECT_EQ(0, network_delegate()->error_count()); |
490 EXPECT_TRUE(request_delegate.auth_required_called()); | 490 EXPECT_TRUE(request_delegate.auth_required_called()); |
491 EXPECT_EQ("test.html", request_delegate.data_received()); | 491 EXPECT_EQ("test.html", request_delegate.data_received()); |
492 } | 492 } |
493 | 493 |
494 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedServerAuthWithCredentials) { | 494 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedServerAuthWithCredentials) { |
495 MockWrite writes[] = { | 495 MockWrite writes[] = { |
496 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 496 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
497 "Host: ftp.example.com\r\n" | 497 "Host: ftp.example.com\r\n" |
(...skipping 23 matching lines...) Expand all Loading... |
521 request_delegate.set_credentials( | 521 request_delegate.set_credentials( |
522 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); | 522 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); |
523 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 523 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
524 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 524 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); |
525 url_request->Start(); | 525 url_request->Start(); |
526 ASSERT_TRUE(url_request->is_pending()); | 526 ASSERT_TRUE(url_request->is_pending()); |
527 | 527 |
528 // The TestDelegate will by default quit the message loop on completion. | 528 // The TestDelegate will by default quit the message loop on completion. |
529 base::RunLoop().Run(); | 529 base::RunLoop().Run(); |
530 | 530 |
531 EXPECT_TRUE(url_request->status().is_success()); | 531 EXPECT_EQ(OK, request_delegate.request_status()); |
532 EXPECT_EQ(1, network_delegate()->completed_requests()); | 532 EXPECT_EQ(1, network_delegate()->completed_requests()); |
533 EXPECT_EQ(0, network_delegate()->error_count()); | 533 EXPECT_EQ(0, network_delegate()->error_count()); |
534 EXPECT_TRUE(request_delegate.auth_required_called()); | 534 EXPECT_TRUE(request_delegate.auth_required_called()); |
535 EXPECT_EQ("test2.html", request_delegate.data_received()); | 535 EXPECT_EQ("test2.html", request_delegate.data_received()); |
536 } | 536 } |
537 | 537 |
538 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedProxyAndServerAuth) { | 538 TEST_F(URLRequestFtpJobTest, FtpProxyRequestNeedProxyAndServerAuth) { |
539 MockWrite writes[] = { | 539 MockWrite writes[] = { |
540 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 540 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
541 "Host: ftp.example.com\r\n" | 541 "Host: ftp.example.com\r\n" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 | 595 |
596 ASSERT_TRUE(request_delegate.auth_required_called()); | 596 ASSERT_TRUE(request_delegate.auth_required_called()); |
597 EXPECT_EQ(0, network_delegate()->completed_requests()); | 597 EXPECT_EQ(0, network_delegate()->completed_requests()); |
598 EXPECT_EQ(0, network_delegate()->error_count()); | 598 EXPECT_EQ(0, network_delegate()->error_count()); |
599 url_request->SetAuth( | 599 url_request->SetAuth( |
600 AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass"))); | 600 AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass"))); |
601 | 601 |
602 // Run until server auth is requested. | 602 // Run until server auth is requested. |
603 base::RunLoop().Run(); | 603 base::RunLoop().Run(); |
604 | 604 |
605 EXPECT_TRUE(url_request->status().is_success()); | |
606 EXPECT_EQ(0, network_delegate()->completed_requests()); | 605 EXPECT_EQ(0, network_delegate()->completed_requests()); |
607 EXPECT_EQ(0, network_delegate()->error_count()); | 606 EXPECT_EQ(0, network_delegate()->error_count()); |
608 url_request->SetAuth( | 607 url_request->SetAuth( |
609 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); | 608 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); |
610 | 609 |
611 // The TestDelegate will by default quit the message loop on completion. | 610 // The TestDelegate will by default quit the message loop on completion. |
612 base::RunLoop().Run(); | 611 base::RunLoop().Run(); |
613 | 612 |
614 EXPECT_TRUE(url_request->status().is_success()); | 613 EXPECT_EQ(OK, request_delegate.request_status()); |
615 EXPECT_EQ(1, network_delegate()->completed_requests()); | 614 EXPECT_EQ(1, network_delegate()->completed_requests()); |
616 EXPECT_EQ(0, network_delegate()->error_count()); | 615 EXPECT_EQ(0, network_delegate()->error_count()); |
617 EXPECT_TRUE(request_delegate.auth_required_called()); | 616 EXPECT_TRUE(request_delegate.auth_required_called()); |
618 EXPECT_EQ("test2.html", request_delegate.data_received()); | 617 EXPECT_EQ("test2.html", request_delegate.data_received()); |
619 } | 618 } |
620 | 619 |
621 TEST_F(URLRequestFtpJobTest, FtpProxyRequestDoNotSaveCookies) { | 620 TEST_F(URLRequestFtpJobTest, FtpProxyRequestDoNotSaveCookies) { |
622 MockWrite writes[] = { | 621 MockWrite writes[] = { |
623 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 622 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
624 "Host: ftp.example.com\r\n" | 623 "Host: ftp.example.com\r\n" |
(...skipping 10 matching lines...) Expand all Loading... |
635 | 634 |
636 TestDelegate request_delegate; | 635 TestDelegate request_delegate; |
637 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 636 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
638 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 637 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); |
639 url_request->Start(); | 638 url_request->Start(); |
640 ASSERT_TRUE(url_request->is_pending()); | 639 ASSERT_TRUE(url_request->is_pending()); |
641 | 640 |
642 // The TestDelegate will by default quit the message loop on completion. | 641 // The TestDelegate will by default quit the message loop on completion. |
643 base::RunLoop().Run(); | 642 base::RunLoop().Run(); |
644 | 643 |
645 EXPECT_TRUE(url_request->status().is_success()); | 644 EXPECT_EQ(OK, request_delegate.request_status()); |
646 EXPECT_EQ(1, network_delegate()->completed_requests()); | 645 EXPECT_EQ(1, network_delegate()->completed_requests()); |
647 EXPECT_EQ(0, network_delegate()->error_count()); | 646 EXPECT_EQ(0, network_delegate()->error_count()); |
648 | 647 |
649 // Make sure we do not accept cookies. | 648 // Make sure we do not accept cookies. |
650 EXPECT_EQ(0, network_delegate()->set_cookie_count()); | 649 EXPECT_EQ(0, network_delegate()->set_cookie_count()); |
651 | 650 |
652 EXPECT_FALSE(request_delegate.auth_required_called()); | 651 EXPECT_FALSE(request_delegate.auth_required_called()); |
653 EXPECT_EQ("test.html", request_delegate.data_received()); | 652 EXPECT_EQ("test.html", request_delegate.data_received()); |
654 } | 653 } |
655 | 654 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 EXPECT_TRUE(url_request2->status().is_success()); | 796 EXPECT_TRUE(url_request2->status().is_success()); |
798 EXPECT_EQ(2, network_delegate()->completed_requests()); | 797 EXPECT_EQ(2, network_delegate()->completed_requests()); |
799 EXPECT_EQ(0, network_delegate()->error_count()); | 798 EXPECT_EQ(0, network_delegate()->error_count()); |
800 EXPECT_FALSE(request_delegate2.auth_required_called()); | 799 EXPECT_FALSE(request_delegate2.auth_required_called()); |
801 EXPECT_EQ("test2.html", request_delegate2.data_received()); | 800 EXPECT_EQ("test2.html", request_delegate2.data_received()); |
802 } | 801 } |
803 | 802 |
804 } // namespace | 803 } // namespace |
805 | 804 |
806 } // namespace net | 805 } // namespace net |
OLD | NEW |