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_THAT(request_delegate.request_status(), IsOk()); | 312 EXPECT_TRUE(url_request->status().is_success()); |
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_THAT(request_delegate.request_status(), IsOk()); | 408 EXPECT_TRUE(url_request->status().is_success()); |
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_THAT(request_delegate.request_status(), IsOk()); | 454 EXPECT_TRUE(url_request->status().is_success()); |
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_THAT(request_delegate.request_status(), IsOk()); | 487 EXPECT_TRUE(url_request->status().is_success()); |
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_THAT(request_delegate.request_status(), IsOk()); | 531 EXPECT_TRUE(url_request->status().is_success()); |
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()); |
605 EXPECT_EQ(0, network_delegate()->completed_requests()); | 606 EXPECT_EQ(0, network_delegate()->completed_requests()); |
606 EXPECT_EQ(0, network_delegate()->error_count()); | 607 EXPECT_EQ(0, network_delegate()->error_count()); |
607 url_request->SetAuth( | 608 url_request->SetAuth( |
608 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); | 609 AuthCredentials(ASCIIToUTF16("myuser"), ASCIIToUTF16("mypass"))); |
609 | 610 |
610 // The TestDelegate will by default quit the message loop on completion. | 611 // The TestDelegate will by default quit the message loop on completion. |
611 base::RunLoop().Run(); | 612 base::RunLoop().Run(); |
612 | 613 |
613 EXPECT_THAT(request_delegate.request_status(), IsOk()); | 614 EXPECT_TRUE(url_request->status().is_success()); |
614 EXPECT_EQ(1, network_delegate()->completed_requests()); | 615 EXPECT_EQ(1, network_delegate()->completed_requests()); |
615 EXPECT_EQ(0, network_delegate()->error_count()); | 616 EXPECT_EQ(0, network_delegate()->error_count()); |
616 EXPECT_TRUE(request_delegate.auth_required_called()); | 617 EXPECT_TRUE(request_delegate.auth_required_called()); |
617 EXPECT_EQ("test2.html", request_delegate.data_received()); | 618 EXPECT_EQ("test2.html", request_delegate.data_received()); |
618 } | 619 } |
619 | 620 |
620 TEST_F(URLRequestFtpJobTest, FtpProxyRequestDoNotSaveCookies) { | 621 TEST_F(URLRequestFtpJobTest, FtpProxyRequestDoNotSaveCookies) { |
621 MockWrite writes[] = { | 622 MockWrite writes[] = { |
622 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" | 623 MockWrite(ASYNC, 0, "GET ftp://ftp.example.com/ HTTP/1.1\r\n" |
623 "Host: ftp.example.com\r\n" | 624 "Host: ftp.example.com\r\n" |
(...skipping 10 matching lines...) Expand all Loading... |
634 | 635 |
635 TestDelegate request_delegate; | 636 TestDelegate request_delegate; |
636 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( | 637 std::unique_ptr<URLRequest> url_request(request_context()->CreateRequest( |
637 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); | 638 GURL("ftp://ftp.example.com/"), DEFAULT_PRIORITY, &request_delegate)); |
638 url_request->Start(); | 639 url_request->Start(); |
639 ASSERT_TRUE(url_request->is_pending()); | 640 ASSERT_TRUE(url_request->is_pending()); |
640 | 641 |
641 // The TestDelegate will by default quit the message loop on completion. | 642 // The TestDelegate will by default quit the message loop on completion. |
642 base::RunLoop().Run(); | 643 base::RunLoop().Run(); |
643 | 644 |
644 EXPECT_THAT(request_delegate.request_status(), IsOk()); | 645 EXPECT_TRUE(url_request->status().is_success()); |
645 EXPECT_EQ(1, network_delegate()->completed_requests()); | 646 EXPECT_EQ(1, network_delegate()->completed_requests()); |
646 EXPECT_EQ(0, network_delegate()->error_count()); | 647 EXPECT_EQ(0, network_delegate()->error_count()); |
647 | 648 |
648 // Make sure we do not accept cookies. | 649 // Make sure we do not accept cookies. |
649 EXPECT_EQ(0, network_delegate()->set_cookie_count()); | 650 EXPECT_EQ(0, network_delegate()->set_cookie_count()); |
650 | 651 |
651 EXPECT_FALSE(request_delegate.auth_required_called()); | 652 EXPECT_FALSE(request_delegate.auth_required_called()); |
652 EXPECT_EQ("test.html", request_delegate.data_received()); | 653 EXPECT_EQ("test.html", request_delegate.data_received()); |
653 } | 654 } |
654 | 655 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 EXPECT_TRUE(url_request2->status().is_success()); | 797 EXPECT_TRUE(url_request2->status().is_success()); |
797 EXPECT_EQ(2, network_delegate()->completed_requests()); | 798 EXPECT_EQ(2, network_delegate()->completed_requests()); |
798 EXPECT_EQ(0, network_delegate()->error_count()); | 799 EXPECT_EQ(0, network_delegate()->error_count()); |
799 EXPECT_FALSE(request_delegate2.auth_required_called()); | 800 EXPECT_FALSE(request_delegate2.auth_required_called()); |
800 EXPECT_EQ("test2.html", request_delegate2.data_received()); | 801 EXPECT_EQ("test2.html", request_delegate2.data_received()); |
801 } | 802 } |
802 | 803 |
803 } // namespace | 804 } // namespace |
804 | 805 |
805 } // namespace net | 806 } // namespace net |
OLD | NEW |