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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 10299002: Stop refcounting URLRequestContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initialize to NULL 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
« no previous file with comments | « net/url_request/url_request_test_util.cc ('k') | net/url_request/view_cache_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 #endif 10 #endif
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 main_intercept_job_ = job; 399 main_intercept_job_ = job;
400 } 400 }
401 401
402 private: 402 private:
403 mutable URLRequestJob* main_intercept_job_; 403 mutable URLRequestJob* main_intercept_job_;
404 }; 404 };
405 405
406 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f 406 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f
407 class URLRequestTest : public PlatformTest { 407 class URLRequestTest : public PlatformTest {
408 public: 408 public:
409 URLRequestTest() : default_context_(new TestURLRequestContext(true)) { 409 URLRequestTest() : default_context_(true) {
410 default_context_->set_network_delegate(&default_network_delegate_); 410 default_context_.set_network_delegate(&default_network_delegate_);
411 default_context_->Init(); 411 default_context_.Init();
412 } 412 }
413 413
414 // Adds the TestJobInterceptor to the default context. 414 // Adds the TestJobInterceptor to the default context.
415 TestJobInterceptor* AddTestInterceptor() { 415 TestJobInterceptor* AddTestInterceptor() {
416 TestJobInterceptor* interceptor = new TestJobInterceptor(); 416 TestJobInterceptor* interceptor = new TestJobInterceptor();
417 default_context_->set_job_factory(&job_factory_); 417 default_context_.set_job_factory(&job_factory_);
418 job_factory_.AddInterceptor(interceptor); 418 job_factory_.AddInterceptor(interceptor);
419 return interceptor; 419 return interceptor;
420 } 420 }
421 421
422 protected: 422 protected:
423 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest 423 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest
424 scoped_refptr<TestURLRequestContext> default_context_;
425 URLRequestJobFactory job_factory_; 424 URLRequestJobFactory job_factory_;
425 TestURLRequestContext default_context_;
426 }; 426 };
427 427
428 class URLRequestTestHTTP : public URLRequestTest { 428 class URLRequestTestHTTP : public URLRequestTest {
429 public: 429 public:
430 URLRequestTestHTTP() 430 URLRequestTestHTTP()
431 : test_server_(FilePath(FILE_PATH_LITERAL( 431 : test_server_(FilePath(FILE_PATH_LITERAL(
432 "net/data/url_request_unittest"))) { 432 "net/data/url_request_unittest"))) {
433 } 433 }
434 434
435 protected: 435 protected:
436 // Requests |redirect_url|, which must return a HTTP 3xx redirect. 436 // Requests |redirect_url|, which must return a HTTP 3xx redirect.
437 // |request_method| is the method to use for the initial request. 437 // |request_method| is the method to use for the initial request.
438 // |redirect_method| is the method that is expected to be used for the second 438 // |redirect_method| is the method that is expected to be used for the second
439 // request, after redirection. 439 // request, after redirection.
440 // If |include_data| is true, data is uploaded with the request. The 440 // If |include_data| is true, data is uploaded with the request. The
441 // response body is expected to match it exactly, if and only if 441 // response body is expected to match it exactly, if and only if
442 // |request_method| == |redirect_method|. 442 // |request_method| == |redirect_method|.
443 void HTTPRedirectMethodTest(const GURL& redirect_url, 443 void HTTPRedirectMethodTest(const GURL& redirect_url,
444 const std::string& request_method, 444 const std::string& request_method,
445 const std::string& redirect_method, 445 const std::string& redirect_method,
446 bool include_data) { 446 bool include_data) {
447 static const char kData[] = "hello world"; 447 static const char kData[] = "hello world";
448 TestDelegate d; 448 TestDelegate d;
449 TestURLRequest req(redirect_url, &d); 449 URLRequest req(redirect_url, &d);
450 req.set_context(default_context_); 450 req.set_context(&default_context_);
451 req.set_method(request_method); 451 req.set_method(request_method);
452 if (include_data) { 452 if (include_data) {
453 req.set_upload(CreateSimpleUploadData(kData).get()); 453 req.set_upload(CreateSimpleUploadData(kData).get());
454 HttpRequestHeaders headers; 454 HttpRequestHeaders headers;
455 headers.SetHeader(HttpRequestHeaders::kContentLength, 455 headers.SetHeader(HttpRequestHeaders::kContentLength,
456 base::UintToString(arraysize(kData) - 1)); 456 base::UintToString(arraysize(kData) - 1));
457 req.SetExtraRequestHeaders(headers); 457 req.SetExtraRequestHeaders(headers);
458 } 458 }
459 req.Start(); 459 req.Start();
460 MessageLoop::current()->Run(); 460 MessageLoop::current()->Run();
(...skipping 25 matching lines...) Expand all
486 *ptr++ = marker; 486 *ptr++ = marker;
487 if (++marker > 'z') 487 if (++marker > 'z')
488 marker = 'a'; 488 marker = 'a';
489 } 489 }
490 } 490 }
491 uploadBytes[kMsgSize] = '\0'; 491 uploadBytes[kMsgSize] = '\0';
492 492
493 for (int i = 0; i < kIterations; ++i) { 493 for (int i = 0; i < kIterations; ++i) {
494 TestDelegate d; 494 TestDelegate d;
495 URLRequest r(test_server_.GetURL("echo"), &d); 495 URLRequest r(test_server_.GetURL("echo"), &d);
496 r.set_context(default_context_); 496 r.set_context(&default_context_);
497 r.set_method(method.c_str()); 497 r.set_method(method.c_str());
498 498
499 r.AppendBytesToUpload(uploadBytes, kMsgSize); 499 r.AppendBytesToUpload(uploadBytes, kMsgSize);
500 500
501 r.Start(); 501 r.Start();
502 EXPECT_TRUE(r.is_pending()); 502 EXPECT_TRUE(r.is_pending());
503 503
504 MessageLoop::current()->Run(); 504 MessageLoop::current()->Run();
505 505
506 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << 506 ASSERT_EQ(1, d.response_started_count()) << "request failed: " <<
507 (int) r.status().status() << ", os error: " << r.status().error(); 507 (int) r.status().status() << ", os error: " << r.status().error();
508 508
509 EXPECT_FALSE(d.received_data_before_response()); 509 EXPECT_FALSE(d.received_data_before_response());
510 EXPECT_EQ(uploadBytes, d.data_received()); 510 EXPECT_EQ(uploadBytes, d.data_received());
511 EXPECT_EQ(memcmp(uploadBytes, d.data_received().c_str(), kMsgSize), 0); 511 EXPECT_EQ(memcmp(uploadBytes, d.data_received().c_str(), kMsgSize), 0);
512 EXPECT_EQ(d.data_received().compare(uploadBytes), 0); 512 EXPECT_EQ(d.data_received().compare(uploadBytes), 0);
513 } 513 }
514 delete[] uploadBytes; 514 delete[] uploadBytes;
515 } 515 }
516 516
517 void AddChunksToUpload(TestURLRequest* r) { 517 void AddChunksToUpload(URLRequest* r) {
518 r->AppendChunkToUpload("a", 1, false); 518 r->AppendChunkToUpload("a", 1, false);
519 r->AppendChunkToUpload("bcd", 3, false); 519 r->AppendChunkToUpload("bcd", 3, false);
520 r->AppendChunkToUpload("this is a longer chunk than before.", 35, false); 520 r->AppendChunkToUpload("this is a longer chunk than before.", 35, false);
521 r->AppendChunkToUpload("\r\n\r\n", 4, false); 521 r->AppendChunkToUpload("\r\n\r\n", 4, false);
522 r->AppendChunkToUpload("0", 1, false); 522 r->AppendChunkToUpload("0", 1, false);
523 r->AppendChunkToUpload("2323", 4, true); 523 r->AppendChunkToUpload("2323", 4, true);
524 } 524 }
525 525
526 void VerifyReceivedDataMatchesChunks(TestURLRequest* r, TestDelegate* d) { 526 void VerifyReceivedDataMatchesChunks(URLRequest* r, TestDelegate* d) {
527 // This should match the chunks sent by AddChunksToUpload(). 527 // This should match the chunks sent by AddChunksToUpload().
528 const char* expected_data = 528 const char* expected_data =
529 "abcdthis is a longer chunk than before.\r\n\r\n02323"; 529 "abcdthis is a longer chunk than before.\r\n\r\n02323";
530 530
531 ASSERT_EQ(1, d->response_started_count()) << "request failed: " << 531 ASSERT_EQ(1, d->response_started_count()) << "request failed: " <<
532 (int) r->status().status() << ", os error: " << r->status().error(); 532 (int) r->status().status() << ", os error: " << r->status().error();
533 533
534 EXPECT_FALSE(d->received_data_before_response()); 534 EXPECT_FALSE(d->received_data_before_response());
535 535
536 ASSERT_EQ(strlen(expected_data), static_cast<size_t>(d->bytes_received())); 536 ASSERT_EQ(strlen(expected_data), static_cast<size_t>(d->bytes_received()));
537 EXPECT_EQ(0, memcmp(d->data_received().c_str(), expected_data, 537 EXPECT_EQ(0, memcmp(d->data_received().c_str(), expected_data,
538 strlen(expected_data))); 538 strlen(expected_data)));
539 } 539 }
540 540
541 LocalHttpTestServer test_server_; 541 LocalHttpTestServer test_server_;
542 }; 542 };
543 543
544 // In this unit test, we're using the HTTPTestServer as a proxy server and 544 // In this unit test, we're using the HTTPTestServer as a proxy server and
545 // issuing a CONNECT request with the magic host name "www.redirect.com". 545 // issuing a CONNECT request with the magic host name "www.redirect.com".
546 // The HTTPTestServer will return a 302 response, which we should not 546 // The HTTPTestServer will return a 302 response, which we should not
547 // follow. 547 // follow.
548 // flaky: crbug.com/96594 548 // flaky: crbug.com/96594
549 TEST_F(URLRequestTestHTTP, FLAKY_ProxyTunnelRedirectTest) { 549 TEST_F(URLRequestTestHTTP, FLAKY_ProxyTunnelRedirectTest) {
550 ASSERT_TRUE(test_server_.Start()); 550 ASSERT_TRUE(test_server_.Start());
551 551
552 TestNetworkDelegate network_delegate; // must outlive URLRequest 552 TestNetworkDelegate network_delegate; // must outlive URLRequest
553 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 553 TestURLRequestContext context(true);
554 context->SetProxyFromString(test_server_.host_port_pair().ToString()); 554 context.SetProxyFromString(test_server_.host_port_pair().ToString());
555 context->set_network_delegate(&network_delegate); 555 context.set_network_delegate(&network_delegate);
556 context->Init(); 556 context.Init();
557 557
558 TestDelegate d; 558 TestDelegate d;
559 { 559 {
560 URLRequest r(GURL("https://www.redirect.com/"), &d); 560 URLRequest r(GURL("https://www.redirect.com/"), &d);
561 r.set_context(context); 561 r.set_context(&context);
562 r.Start(); 562 r.Start();
563 EXPECT_TRUE(r.is_pending()); 563 EXPECT_TRUE(r.is_pending());
564 564
565 MessageLoop::current()->Run(); 565 MessageLoop::current()->Run();
566 566
567 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 567 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
568 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); 568 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error());
569 EXPECT_EQ(1, d.response_started_count()); 569 EXPECT_EQ(1, d.response_started_count());
570 // We should not have followed the redirect. 570 // We should not have followed the redirect.
571 EXPECT_EQ(0, d.received_redirect_count()); 571 EXPECT_EQ(0, d.received_redirect_count());
572 } 572 }
573 } 573 }
574 574
575 // This is the same as the previous test, but checks that the network delegate 575 // This is the same as the previous test, but checks that the network delegate
576 // registers the error. 576 // registers the error.
577 // This test was disabled because it made chrome_frame_net_tests hang 577 // This test was disabled because it made chrome_frame_net_tests hang
578 // (see bug 102991). 578 // (see bug 102991).
579 TEST_F(URLRequestTestHTTP, DISABLED_NetworkDelegateTunnelConnectionFailed) { 579 TEST_F(URLRequestTestHTTP, DISABLED_NetworkDelegateTunnelConnectionFailed) {
580 ASSERT_TRUE(test_server_.Start()); 580 ASSERT_TRUE(test_server_.Start());
581 581
582 TestNetworkDelegate network_delegate; // must outlive URLRequest 582 TestNetworkDelegate network_delegate; // must outlive URLRequest
583 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 583 TestURLRequestContext context(true);
584 context->SetProxyFromString(test_server_.host_port_pair().ToString()); 584 context.SetProxyFromString(test_server_.host_port_pair().ToString());
585 context->set_network_delegate(&network_delegate); 585 context.set_network_delegate(&network_delegate);
586 context->Init(); 586 context.Init();
587 587
588 TestDelegate d; 588 TestDelegate d;
589 { 589 {
590 URLRequest r(GURL("https://www.redirect.com/"), &d); 590 URLRequest r(GURL("https://www.redirect.com/"), &d);
591 r.set_context(context); 591 r.set_context(&context);
592 r.Start(); 592 r.Start();
593 EXPECT_TRUE(r.is_pending()); 593 EXPECT_TRUE(r.is_pending());
594 594
595 MessageLoop::current()->Run(); 595 MessageLoop::current()->Run();
596 596
597 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 597 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
598 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); 598 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error());
599 EXPECT_EQ(1, d.response_started_count()); 599 EXPECT_EQ(1, d.response_started_count());
600 // We should not have followed the redirect. 600 // We should not have followed the redirect.
601 EXPECT_EQ(0, d.received_redirect_count()); 601 EXPECT_EQ(0, d.received_redirect_count());
602 602
603 EXPECT_EQ(1, network_delegate.error_count()); 603 EXPECT_EQ(1, network_delegate.error_count());
604 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error()); 604 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error());
605 } 605 }
606 } 606 }
607 607
608 // Tests that the network delegate can block and cancel a request. 608 // Tests that the network delegate can block and cancel a request.
609 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { 609 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) {
610 ASSERT_TRUE(test_server_.Start()); 610 ASSERT_TRUE(test_server_.Start());
611 611
612 TestDelegate d; 612 TestDelegate d;
613 BlockingNetworkDelegate network_delegate; 613 BlockingNetworkDelegate network_delegate;
614 network_delegate.set_callback_retval(ERR_EMPTY_RESPONSE); 614 network_delegate.set_callback_retval(ERR_EMPTY_RESPONSE);
615 615
616 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 616 TestURLRequestContext context(true);
617 context->SetProxyFromString(test_server_.host_port_pair().ToString()); 617 context.SetProxyFromString(test_server_.host_port_pair().ToString());
618 context->set_network_delegate(&network_delegate); 618 context.set_network_delegate(&network_delegate);
619 context->Init(); 619 context.Init();
620 620
621 { 621 {
622 TestURLRequest r(test_server_.GetURL(""), &d); 622 URLRequest r(test_server_.GetURL(""), &d);
623 r.set_context(context); 623 r.set_context(&context);
624 624
625 r.Start(); 625 r.Start();
626 MessageLoop::current()->Run(); 626 MessageLoop::current()->Run();
627 627
628 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 628 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
629 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); 629 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error());
630 EXPECT_EQ(1, network_delegate.created_requests()); 630 EXPECT_EQ(1, network_delegate.created_requests());
631 EXPECT_EQ(0, network_delegate.destroyed_requests()); 631 EXPECT_EQ(0, network_delegate.destroyed_requests());
632 } 632 }
633 EXPECT_EQ(1, network_delegate.destroyed_requests()); 633 EXPECT_EQ(1, network_delegate.destroyed_requests());
634 } 634 }
635 635
636 // Tests that the network delegate can cancel a request synchronously. 636 // Tests that the network delegate can cancel a request synchronously.
637 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) { 637 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) {
638 ASSERT_TRUE(test_server_.Start()); 638 ASSERT_TRUE(test_server_.Start());
639 639
640 TestDelegate d; 640 TestDelegate d;
641 BlockingNetworkDelegate network_delegate; 641 BlockingNetworkDelegate network_delegate;
642 network_delegate.set_retval(ERR_EMPTY_RESPONSE); 642 network_delegate.set_retval(ERR_EMPTY_RESPONSE);
643 643
644 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 644 TestURLRequestContext context(true);
645 context->SetProxyFromString(test_server_.host_port_pair().ToString()); 645 context.SetProxyFromString(test_server_.host_port_pair().ToString());
646 context->set_network_delegate(&network_delegate); 646 context.set_network_delegate(&network_delegate);
647 context->Init(); 647 context.Init();
648 648
649 { 649 {
650 TestURLRequest r(test_server_.GetURL(""), &d); 650 URLRequest r(test_server_.GetURL(""), &d);
651 r.set_context(context); 651 r.set_context(&context);
652 652
653 r.Start(); 653 r.Start();
654 MessageLoop::current()->Run(); 654 MessageLoop::current()->Run();
655 655
656 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 656 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
657 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); 657 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error());
658 EXPECT_EQ(1, network_delegate.created_requests()); 658 EXPECT_EQ(1, network_delegate.created_requests());
659 EXPECT_EQ(0, network_delegate.destroyed_requests()); 659 EXPECT_EQ(0, network_delegate.destroyed_requests());
660 } 660 }
661 EXPECT_EQ(1, network_delegate.destroyed_requests()); 661 EXPECT_EQ(1, network_delegate.destroyed_requests());
662 } 662 }
663 663
664 // Tests that the network delegate can block and redirect a request to a new 664 // Tests that the network delegate can block and redirect a request to a new
665 // URL. 665 // URL.
666 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) { 666 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) {
667 ASSERT_TRUE(test_server_.Start()); 667 ASSERT_TRUE(test_server_.Start());
668 668
669 TestDelegate d; 669 TestDelegate d;
670 BlockingNetworkDelegate network_delegate; 670 BlockingNetworkDelegate network_delegate;
671 GURL redirect_url(test_server_.GetURL("simple.html")); 671 GURL redirect_url(test_server_.GetURL("simple.html"));
672 network_delegate.set_redirect_url(redirect_url); 672 network_delegate.set_redirect_url(redirect_url);
673 673
674 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 674 TestURLRequestContext context(true);
675 context->SetProxyFromString(test_server_.host_port_pair().ToString()); 675 context.SetProxyFromString(test_server_.host_port_pair().ToString());
676 context->set_network_delegate(&network_delegate); 676 context.set_network_delegate(&network_delegate);
677 context->Init(); 677 context.Init();
678 678
679 { 679 {
680 GURL original_url(test_server_.GetURL("empty.html")); 680 GURL original_url(test_server_.GetURL("empty.html"));
681 TestURLRequest r(original_url, &d); 681 URLRequest r(original_url, &d);
682 r.set_context(context); 682 r.set_context(&context);
683 683
684 r.Start(); 684 r.Start();
685 MessageLoop::current()->Run(); 685 MessageLoop::current()->Run();
686 686
687 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 687 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
688 EXPECT_EQ(0, r.status().error()); 688 EXPECT_EQ(0, r.status().error());
689 EXPECT_EQ(redirect_url, r.url()); 689 EXPECT_EQ(redirect_url, r.url());
690 EXPECT_EQ(original_url, r.original_url()); 690 EXPECT_EQ(original_url, r.original_url());
691 EXPECT_EQ(2U, r.url_chain().size()); 691 EXPECT_EQ(2U, r.url_chain().size());
692 EXPECT_EQ(1, network_delegate.created_requests()); 692 EXPECT_EQ(1, network_delegate.created_requests());
693 EXPECT_EQ(0, network_delegate.destroyed_requests()); 693 EXPECT_EQ(0, network_delegate.destroyed_requests());
694 } 694 }
695 EXPECT_EQ(1, network_delegate.destroyed_requests()); 695 EXPECT_EQ(1, network_delegate.destroyed_requests());
696 } 696 }
697 697
698 // Tests that the network delegate can block and redirect a request to a new 698 // Tests that the network delegate can block and redirect a request to a new
699 // URL by setting a redirect_url and returning in OnBeforeURLRequest directly. 699 // URL by setting a redirect_url and returning in OnBeforeURLRequest directly.
700 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestSynchronously) { 700 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestSynchronously) {
701 ASSERT_TRUE(test_server_.Start()); 701 ASSERT_TRUE(test_server_.Start());
702 702
703 TestDelegate d; 703 TestDelegate d;
704 BlockingNetworkDelegate network_delegate; 704 BlockingNetworkDelegate network_delegate;
705 GURL redirect_url(test_server_.GetURL("simple.html")); 705 GURL redirect_url(test_server_.GetURL("simple.html"));
706 network_delegate.set_redirect_url(redirect_url); 706 network_delegate.set_redirect_url(redirect_url);
707 network_delegate.set_retval(OK); 707 network_delegate.set_retval(OK);
708 708
709 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 709 TestURLRequestContext context(true);
710 context->SetProxyFromString(test_server_.host_port_pair().ToString()); 710 context.SetProxyFromString(test_server_.host_port_pair().ToString());
711 context->set_network_delegate(&network_delegate); 711 context.set_network_delegate(&network_delegate);
712 context->Init(); 712 context.Init();
713 713
714 { 714 {
715 GURL original_url(test_server_.GetURL("empty.html")); 715 GURL original_url(test_server_.GetURL("empty.html"));
716 TestURLRequest r(original_url, &d); 716 URLRequest r(original_url, &d);
717 r.set_context(context); 717 r.set_context(&context);
718 718
719 r.Start(); 719 r.Start();
720 MessageLoop::current()->Run(); 720 MessageLoop::current()->Run();
721 721
722 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 722 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
723 EXPECT_EQ(0, r.status().error()); 723 EXPECT_EQ(0, r.status().error());
724 EXPECT_EQ(redirect_url, r.url()); 724 EXPECT_EQ(redirect_url, r.url());
725 EXPECT_EQ(original_url, r.original_url()); 725 EXPECT_EQ(original_url, r.original_url());
726 EXPECT_EQ(2U, r.url_chain().size()); 726 EXPECT_EQ(2U, r.url_chain().size());
727 EXPECT_EQ(1, network_delegate.created_requests()); 727 EXPECT_EQ(1, network_delegate.created_requests());
728 EXPECT_EQ(0, network_delegate.destroyed_requests()); 728 EXPECT_EQ(0, network_delegate.destroyed_requests());
729 } 729 }
730 EXPECT_EQ(1, network_delegate.destroyed_requests()); 730 EXPECT_EQ(1, network_delegate.destroyed_requests());
731 } 731 }
732 732
733 // Tests that redirects caused by the network delegate preserve POST data. 733 // Tests that redirects caused by the network delegate preserve POST data.
734 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestPost) { 734 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestPost) {
735 ASSERT_TRUE(test_server_.Start()); 735 ASSERT_TRUE(test_server_.Start());
736 736
737 const char kData[] = "hello world"; 737 const char kData[] = "hello world";
738 738
739 TestDelegate d; 739 TestDelegate d;
740 BlockingNetworkDelegate network_delegate; 740 BlockingNetworkDelegate network_delegate;
741 GURL redirect_url(test_server_.GetURL("echo")); 741 GURL redirect_url(test_server_.GetURL("echo"));
742 network_delegate.set_redirect_url(redirect_url); 742 network_delegate.set_redirect_url(redirect_url);
743 743
744 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 744 TestURLRequestContext context(true);
745 context->set_network_delegate(&network_delegate); 745 context.set_network_delegate(&network_delegate);
746 context->Init(); 746 context.Init();
747 747
748 { 748 {
749 GURL original_url(test_server_.GetURL("empty.html")); 749 GURL original_url(test_server_.GetURL("empty.html"));
750 TestURLRequest r(original_url, &d); 750 URLRequest r(original_url, &d);
751 r.set_context(context); 751 r.set_context(&context);
752 r.set_method("POST"); 752 r.set_method("POST");
753 r.set_upload(CreateSimpleUploadData(kData).get()); 753 r.set_upload(CreateSimpleUploadData(kData).get());
754 HttpRequestHeaders headers; 754 HttpRequestHeaders headers;
755 headers.SetHeader(HttpRequestHeaders::kContentLength, 755 headers.SetHeader(HttpRequestHeaders::kContentLength,
756 base::UintToString(arraysize(kData) - 1)); 756 base::UintToString(arraysize(kData) - 1));
757 r.SetExtraRequestHeaders(headers); 757 r.SetExtraRequestHeaders(headers);
758 r.Start(); 758 r.Start();
759 MessageLoop::current()->Run(); 759 MessageLoop::current()->Run();
760 760
761 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 761 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
(...skipping 14 matching lines...) Expand all
776 // handle the challenge, and is passing the buck along to the 776 // handle the challenge, and is passing the buck along to the
777 // URLRequest::Delegate. 777 // URLRequest::Delegate.
778 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncNoAction) { 778 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncNoAction) {
779 ASSERT_TRUE(test_server_.Start()); 779 ASSERT_TRUE(test_server_.Start());
780 780
781 TestDelegate d; 781 TestDelegate d;
782 BlockingNetworkDelegate network_delegate; 782 BlockingNetworkDelegate network_delegate;
783 network_delegate.set_auth_retval( 783 network_delegate.set_auth_retval(
784 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION); 784 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION);
785 785
786 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 786 TestURLRequestContext context(true);
787 context->set_network_delegate(&network_delegate); 787 context.set_network_delegate(&network_delegate);
788 context->Init(); 788 context.Init();
789 789
790 d.set_credentials(AuthCredentials(kUser, kSecret)); 790 d.set_credentials(AuthCredentials(kUser, kSecret));
791 791
792 { 792 {
793 GURL url(test_server_.GetURL("auth-basic")); 793 GURL url(test_server_.GetURL("auth-basic"));
794 TestURLRequest r(url, &d); 794 URLRequest r(url, &d);
795 r.set_context(context); 795 r.set_context(&context);
796 r.Start(); 796 r.Start();
797 MessageLoop::current()->Run(); 797 MessageLoop::current()->Run();
798 798
799 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 799 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
800 EXPECT_EQ(0, r.status().error()); 800 EXPECT_EQ(0, r.status().error());
801 EXPECT_EQ(200, r.GetResponseCode()); 801 EXPECT_EQ(200, r.GetResponseCode());
802 EXPECT_TRUE(d.auth_required_called()); 802 EXPECT_TRUE(d.auth_required_called());
803 EXPECT_EQ(1, network_delegate.created_requests()); 803 EXPECT_EQ(1, network_delegate.created_requests());
804 EXPECT_EQ(0, network_delegate.destroyed_requests()); 804 EXPECT_EQ(0, network_delegate.destroyed_requests());
805 } 805 }
806 EXPECT_EQ(1, network_delegate.destroyed_requests()); 806 EXPECT_EQ(1, network_delegate.destroyed_requests());
807 } 807 }
808 808
809 // Tests that the network delegate can synchronously complete OnAuthRequired 809 // Tests that the network delegate can synchronously complete OnAuthRequired
810 // by setting credentials. 810 // by setting credentials.
811 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncSetAuth) { 811 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncSetAuth) {
812 ASSERT_TRUE(test_server_.Start()); 812 ASSERT_TRUE(test_server_.Start());
813 813
814 TestDelegate d; 814 TestDelegate d;
815 BlockingNetworkDelegate network_delegate; 815 BlockingNetworkDelegate network_delegate;
816 network_delegate.set_auth_retval( 816 network_delegate.set_auth_retval(
817 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); 817 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH);
818 818
819 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); 819 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret));
820 820
821 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 821 TestURLRequestContext context(true);
822 context->set_network_delegate(&network_delegate); 822 context.set_network_delegate(&network_delegate);
823 context->Init(); 823 context.Init();
824 824
825 { 825 {
826 GURL url(test_server_.GetURL("auth-basic")); 826 GURL url(test_server_.GetURL("auth-basic"));
827 TestURLRequest r(url, &d); 827 URLRequest r(url, &d);
828 r.set_context(context); 828 r.set_context(&context);
829 r.Start(); 829 r.Start();
830 MessageLoop::current()->Run(); 830 MessageLoop::current()->Run();
831 831
832 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 832 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
833 EXPECT_EQ(0, r.status().error()); 833 EXPECT_EQ(0, r.status().error());
834 EXPECT_EQ(200, r.GetResponseCode()); 834 EXPECT_EQ(200, r.GetResponseCode());
835 EXPECT_FALSE(d.auth_required_called()); 835 EXPECT_FALSE(d.auth_required_called());
836 EXPECT_EQ(1, network_delegate.created_requests()); 836 EXPECT_EQ(1, network_delegate.created_requests());
837 EXPECT_EQ(0, network_delegate.destroyed_requests()); 837 EXPECT_EQ(0, network_delegate.destroyed_requests());
838 } 838 }
839 EXPECT_EQ(1, network_delegate.destroyed_requests()); 839 EXPECT_EQ(1, network_delegate.destroyed_requests());
840 } 840 }
841 841
842 // Tests that the network delegate can synchronously complete OnAuthRequired 842 // Tests that the network delegate can synchronously complete OnAuthRequired
843 // by cancelling authentication. 843 // by cancelling authentication.
844 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncCancel) { 844 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncCancel) {
845 ASSERT_TRUE(test_server_.Start()); 845 ASSERT_TRUE(test_server_.Start());
846 846
847 TestDelegate d; 847 TestDelegate d;
848 BlockingNetworkDelegate network_delegate; 848 BlockingNetworkDelegate network_delegate;
849 network_delegate.set_auth_retval( 849 network_delegate.set_auth_retval(
850 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); 850 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH);
851 851
852 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 852 TestURLRequestContext context(true);
853 context->set_network_delegate(&network_delegate); 853 context.set_network_delegate(&network_delegate);
854 context->Init(); 854 context.Init();
855 855
856 { 856 {
857 GURL url(test_server_.GetURL("auth-basic")); 857 GURL url(test_server_.GetURL("auth-basic"));
858 TestURLRequest r(url, &d); 858 URLRequest r(url, &d);
859 r.set_context(context); 859 r.set_context(&context);
860 r.Start(); 860 r.Start();
861 MessageLoop::current()->Run(); 861 MessageLoop::current()->Run();
862 862
863 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 863 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
864 EXPECT_EQ(OK, r.status().error()); 864 EXPECT_EQ(OK, r.status().error());
865 EXPECT_EQ(401, r.GetResponseCode()); 865 EXPECT_EQ(401, r.GetResponseCode());
866 EXPECT_FALSE(d.auth_required_called()); 866 EXPECT_FALSE(d.auth_required_called());
867 EXPECT_EQ(1, network_delegate.created_requests()); 867 EXPECT_EQ(1, network_delegate.created_requests());
868 EXPECT_EQ(0, network_delegate.destroyed_requests()); 868 EXPECT_EQ(0, network_delegate.destroyed_requests());
869 } 869 }
870 EXPECT_EQ(1, network_delegate.destroyed_requests()); 870 EXPECT_EQ(1, network_delegate.destroyed_requests());
871 } 871 }
872 872
873 // Tests that the network delegate can asynchronously complete OnAuthRequired 873 // Tests that the network delegate can asynchronously complete OnAuthRequired
874 // by taking no action. This indicates that the NetworkDelegate does not want 874 // by taking no action. This indicates that the NetworkDelegate does not want
875 // to handle the challenge, and is passing the buck along to the 875 // to handle the challenge, and is passing the buck along to the
876 // URLRequest::Delegate. 876 // URLRequest::Delegate.
877 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncNoAction) { 877 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncNoAction) {
878 ASSERT_TRUE(test_server_.Start()); 878 ASSERT_TRUE(test_server_.Start());
879 879
880 TestDelegate d; 880 TestDelegate d;
881 BlockingNetworkDelegate network_delegate; 881 BlockingNetworkDelegate network_delegate;
882 network_delegate.set_auth_retval( 882 network_delegate.set_auth_retval(
883 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING); 883 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING);
884 network_delegate.set_auth_callback_retval( 884 network_delegate.set_auth_callback_retval(
885 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION); 885 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION);
886 886
887 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 887 TestURLRequestContext context(true);
888 context->set_network_delegate(&network_delegate); 888 context.set_network_delegate(&network_delegate);
889 context->Init(); 889 context.Init();
890 890
891 d.set_credentials(AuthCredentials(kUser, kSecret)); 891 d.set_credentials(AuthCredentials(kUser, kSecret));
892 892
893 { 893 {
894 GURL url(test_server_.GetURL("auth-basic")); 894 GURL url(test_server_.GetURL("auth-basic"));
895 TestURLRequest r(url, &d); 895 URLRequest r(url, &d);
896 r.set_context(context); 896 r.set_context(&context);
897 r.Start(); 897 r.Start();
898 MessageLoop::current()->Run(); 898 MessageLoop::current()->Run();
899 899
900 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 900 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
901 EXPECT_EQ(0, r.status().error()); 901 EXPECT_EQ(0, r.status().error());
902 EXPECT_EQ(200, r.GetResponseCode()); 902 EXPECT_EQ(200, r.GetResponseCode());
903 EXPECT_TRUE(d.auth_required_called()); 903 EXPECT_TRUE(d.auth_required_called());
904 EXPECT_EQ(1, network_delegate.created_requests()); 904 EXPECT_EQ(1, network_delegate.created_requests());
905 EXPECT_EQ(0, network_delegate.destroyed_requests()); 905 EXPECT_EQ(0, network_delegate.destroyed_requests());
906 } 906 }
907 EXPECT_EQ(1, network_delegate.destroyed_requests()); 907 EXPECT_EQ(1, network_delegate.destroyed_requests());
908 } 908 }
909 909
910 // Tests that the network delegate can asynchronously complete OnAuthRequired 910 // Tests that the network delegate can asynchronously complete OnAuthRequired
911 // by setting credentials. 911 // by setting credentials.
912 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncSetAuth) { 912 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncSetAuth) {
913 ASSERT_TRUE(test_server_.Start()); 913 ASSERT_TRUE(test_server_.Start());
914 914
915 TestDelegate d; 915 TestDelegate d;
916 BlockingNetworkDelegate network_delegate; 916 BlockingNetworkDelegate network_delegate;
917 network_delegate.set_auth_retval( 917 network_delegate.set_auth_retval(
918 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING); 918 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING);
919 network_delegate.set_auth_callback_retval( 919 network_delegate.set_auth_callback_retval(
920 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); 920 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH);
921 921
922 AuthCredentials auth_credentials(kUser, kSecret); 922 AuthCredentials auth_credentials(kUser, kSecret);
923 network_delegate.set_auth_credentials(auth_credentials); 923 network_delegate.set_auth_credentials(auth_credentials);
924 924
925 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 925 TestURLRequestContext context(true);
926 context->set_network_delegate(&network_delegate); 926 context.set_network_delegate(&network_delegate);
927 context->Init(); 927 context.Init();
928 928
929 { 929 {
930 GURL url(test_server_.GetURL("auth-basic")); 930 GURL url(test_server_.GetURL("auth-basic"));
931 TestURLRequest r(url, &d); 931 URLRequest r(url, &d);
932 r.set_context(context); 932 r.set_context(&context);
933 r.Start(); 933 r.Start();
934 MessageLoop::current()->Run(); 934 MessageLoop::current()->Run();
935 935
936 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 936 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
937 EXPECT_EQ(0, r.status().error()); 937 EXPECT_EQ(0, r.status().error());
938 938
939 EXPECT_EQ(200, r.GetResponseCode()); 939 EXPECT_EQ(200, r.GetResponseCode());
940 EXPECT_FALSE(d.auth_required_called()); 940 EXPECT_FALSE(d.auth_required_called());
941 EXPECT_EQ(1, network_delegate.created_requests()); 941 EXPECT_EQ(1, network_delegate.created_requests());
942 EXPECT_EQ(0, network_delegate.destroyed_requests()); 942 EXPECT_EQ(0, network_delegate.destroyed_requests());
943 } 943 }
944 EXPECT_EQ(1, network_delegate.destroyed_requests()); 944 EXPECT_EQ(1, network_delegate.destroyed_requests());
945 } 945 }
946 946
947 // Tests that the network delegate can asynchronously complete OnAuthRequired 947 // Tests that the network delegate can asynchronously complete OnAuthRequired
948 // by cancelling authentication. 948 // by cancelling authentication.
949 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncCancel) { 949 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncCancel) {
950 ASSERT_TRUE(test_server_.Start()); 950 ASSERT_TRUE(test_server_.Start());
951 951
952 TestDelegate d; 952 TestDelegate d;
953 BlockingNetworkDelegate network_delegate; 953 BlockingNetworkDelegate network_delegate;
954 network_delegate.set_auth_retval( 954 network_delegate.set_auth_retval(
955 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING); 955 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING);
956 network_delegate.set_auth_callback_retval( 956 network_delegate.set_auth_callback_retval(
957 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); 957 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH);
958 958
959 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 959 TestURLRequestContext context(true);
960 context->set_network_delegate(&network_delegate); 960 context.set_network_delegate(&network_delegate);
961 context->Init(); 961 context.Init();
962 962
963 { 963 {
964 GURL url(test_server_.GetURL("auth-basic")); 964 GURL url(test_server_.GetURL("auth-basic"));
965 TestURLRequest r(url, &d); 965 URLRequest r(url, &d);
966 r.set_context(context); 966 r.set_context(&context);
967 r.Start(); 967 r.Start();
968 MessageLoop::current()->Run(); 968 MessageLoop::current()->Run();
969 969
970 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 970 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
971 EXPECT_EQ(OK, r.status().error()); 971 EXPECT_EQ(OK, r.status().error());
972 EXPECT_EQ(401, r.GetResponseCode()); 972 EXPECT_EQ(401, r.GetResponseCode());
973 EXPECT_FALSE(d.auth_required_called()); 973 EXPECT_FALSE(d.auth_required_called());
974 EXPECT_EQ(1, network_delegate.created_requests()); 974 EXPECT_EQ(1, network_delegate.created_requests());
975 EXPECT_EQ(0, network_delegate.destroyed_requests()); 975 EXPECT_EQ(0, network_delegate.destroyed_requests());
976 } 976 }
977 EXPECT_EQ(1, network_delegate.destroyed_requests()); 977 EXPECT_EQ(1, network_delegate.destroyed_requests());
978 } 978 }
979 979
980 // Tests that we can handle when a network request was canceled while we were 980 // Tests that we can handle when a network request was canceled while we were
981 // waiting for the network delegate. 981 // waiting for the network delegate.
982 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback. 982 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback.
983 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) { 983 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) {
984 ASSERT_TRUE(test_server_.Start()); 984 ASSERT_TRUE(test_server_.Start());
985 985
986 TestDelegate d; 986 TestDelegate d;
987 BlockingNetworkDelegateWithManualCallback network_delegate; 987 BlockingNetworkDelegateWithManualCallback network_delegate;
988 network_delegate.BlockOn( 988 network_delegate.BlockOn(
989 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_URL_REQUEST); 989 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_URL_REQUEST);
990 990
991 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 991 TestURLRequestContext context(true);
992 context->set_network_delegate(&network_delegate); 992 context.set_network_delegate(&network_delegate);
993 context->Init(); 993 context.Init();
994 994
995 { 995 {
996 TestURLRequest r(test_server_.GetURL(""), &d); 996 URLRequest r(test_server_.GetURL(""), &d);
997 r.set_context(context); 997 r.set_context(&context);
998 998
999 r.Start(); 999 r.Start();
1000 network_delegate.WaitForState( 1000 network_delegate.WaitForState(
1001 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_URL_REQUEST); 1001 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_URL_REQUEST);
1002 EXPECT_EQ(0, network_delegate.completed_requests()); 1002 EXPECT_EQ(0, network_delegate.completed_requests());
1003 // Cancel before callback. 1003 // Cancel before callback.
1004 r.Cancel(); 1004 r.Cancel();
1005 // Ensure that network delegate is notified. 1005 // Ensure that network delegate is notified.
1006 EXPECT_EQ(1, network_delegate.completed_requests()); 1006 EXPECT_EQ(1, network_delegate.completed_requests());
1007 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 1007 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
1008 EXPECT_EQ(ERR_ABORTED, r.status().error()); 1008 EXPECT_EQ(ERR_ABORTED, r.status().error());
1009 EXPECT_EQ(1, network_delegate.created_requests()); 1009 EXPECT_EQ(1, network_delegate.created_requests());
1010 EXPECT_EQ(0, network_delegate.destroyed_requests()); 1010 EXPECT_EQ(0, network_delegate.destroyed_requests());
1011 } 1011 }
1012 EXPECT_EQ(1, network_delegate.destroyed_requests()); 1012 EXPECT_EQ(1, network_delegate.destroyed_requests());
1013 } 1013 }
1014 1014
1015 // Tests that we can handle when a network request was canceled while we were 1015 // Tests that we can handle when a network request was canceled while we were
1016 // waiting for the network delegate. 1016 // waiting for the network delegate.
1017 // Part 2: Request is cancelled while waiting for OnBeforeSendHeaders callback. 1017 // Part 2: Request is cancelled while waiting for OnBeforeSendHeaders callback.
1018 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting2) { 1018 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting2) {
1019 ASSERT_TRUE(test_server_.Start()); 1019 ASSERT_TRUE(test_server_.Start());
1020 1020
1021 TestDelegate d; 1021 TestDelegate d;
1022 BlockingNetworkDelegateWithManualCallback network_delegate; 1022 BlockingNetworkDelegateWithManualCallback network_delegate;
1023 network_delegate.BlockOn( 1023 network_delegate.BlockOn(
1024 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_SEND_HEADERS); 1024 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_SEND_HEADERS);
1025 1025
1026 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 1026 TestURLRequestContext context(true);
1027 context->set_network_delegate(&network_delegate); 1027 context.set_network_delegate(&network_delegate);
1028 context->Init(); 1028 context.Init();
1029 1029
1030 { 1030 {
1031 TestURLRequest r(test_server_.GetURL(""), &d); 1031 URLRequest r(test_server_.GetURL(""), &d);
1032 r.set_context(context); 1032 r.set_context(&context);
1033 1033
1034 r.Start(); 1034 r.Start();
1035 network_delegate.WaitForState( 1035 network_delegate.WaitForState(
1036 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_SEND_HEADERS); 1036 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_SEND_HEADERS);
1037 EXPECT_EQ(0, network_delegate.completed_requests()); 1037 EXPECT_EQ(0, network_delegate.completed_requests());
1038 // Cancel before callback. 1038 // Cancel before callback.
1039 r.Cancel(); 1039 r.Cancel();
1040 // Ensure that network delegate is notified. 1040 // Ensure that network delegate is notified.
1041 EXPECT_EQ(1, network_delegate.completed_requests()); 1041 EXPECT_EQ(1, network_delegate.completed_requests());
1042 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 1042 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
1043 EXPECT_EQ(ERR_ABORTED, r.status().error()); 1043 EXPECT_EQ(ERR_ABORTED, r.status().error());
1044 EXPECT_EQ(1, network_delegate.created_requests()); 1044 EXPECT_EQ(1, network_delegate.created_requests());
1045 EXPECT_EQ(0, network_delegate.destroyed_requests()); 1045 EXPECT_EQ(0, network_delegate.destroyed_requests());
1046 } 1046 }
1047 EXPECT_EQ(1, network_delegate.destroyed_requests()); 1047 EXPECT_EQ(1, network_delegate.destroyed_requests());
1048 } 1048 }
1049 1049
1050 // Tests that we can handle when a network request was canceled while we were 1050 // Tests that we can handle when a network request was canceled while we were
1051 // waiting for the network delegate. 1051 // waiting for the network delegate.
1052 // Part 3: Request is cancelled while waiting for OnHeadersReceived callback. 1052 // Part 3: Request is cancelled while waiting for OnHeadersReceived callback.
1053 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting3) { 1053 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting3) {
1054 ASSERT_TRUE(test_server_.Start()); 1054 ASSERT_TRUE(test_server_.Start());
1055 1055
1056 TestDelegate d; 1056 TestDelegate d;
1057 BlockingNetworkDelegateWithManualCallback network_delegate; 1057 BlockingNetworkDelegateWithManualCallback network_delegate;
1058 network_delegate.BlockOn( 1058 network_delegate.BlockOn(
1059 BlockingNetworkDelegateWithManualCallback::ON_HEADERS_RECEIVED); 1059 BlockingNetworkDelegateWithManualCallback::ON_HEADERS_RECEIVED);
1060 1060
1061 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 1061 TestURLRequestContext context(true);
1062 context->set_network_delegate(&network_delegate); 1062 context.set_network_delegate(&network_delegate);
1063 context->Init(); 1063 context.Init();
1064 1064
1065 { 1065 {
1066 TestURLRequest r(test_server_.GetURL(""), &d); 1066 URLRequest r(test_server_.GetURL(""), &d);
1067 r.set_context(context); 1067 r.set_context(&context);
1068 1068
1069 r.Start(); 1069 r.Start();
1070 network_delegate.WaitForState( 1070 network_delegate.WaitForState(
1071 BlockingNetworkDelegateWithManualCallback::ON_HEADERS_RECEIVED); 1071 BlockingNetworkDelegateWithManualCallback::ON_HEADERS_RECEIVED);
1072 EXPECT_EQ(0, network_delegate.completed_requests()); 1072 EXPECT_EQ(0, network_delegate.completed_requests());
1073 // Cancel before callback. 1073 // Cancel before callback.
1074 r.Cancel(); 1074 r.Cancel();
1075 // Ensure that network delegate is notified. 1075 // Ensure that network delegate is notified.
1076 EXPECT_EQ(1, network_delegate.completed_requests()); 1076 EXPECT_EQ(1, network_delegate.completed_requests());
1077 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 1077 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
1078 EXPECT_EQ(ERR_ABORTED, r.status().error()); 1078 EXPECT_EQ(ERR_ABORTED, r.status().error());
1079 EXPECT_EQ(1, network_delegate.created_requests()); 1079 EXPECT_EQ(1, network_delegate.created_requests());
1080 EXPECT_EQ(0, network_delegate.destroyed_requests()); 1080 EXPECT_EQ(0, network_delegate.destroyed_requests());
1081 } 1081 }
1082 EXPECT_EQ(1, network_delegate.destroyed_requests()); 1082 EXPECT_EQ(1, network_delegate.destroyed_requests());
1083 } 1083 }
1084 1084
1085 // Tests that we can handle when a network request was canceled while we were 1085 // Tests that we can handle when a network request was canceled while we were
1086 // waiting for the network delegate. 1086 // waiting for the network delegate.
1087 // Part 4: Request is cancelled while waiting for OnAuthRequired callback. 1087 // Part 4: Request is cancelled while waiting for OnAuthRequired callback.
1088 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting4) { 1088 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting4) {
1089 ASSERT_TRUE(test_server_.Start()); 1089 ASSERT_TRUE(test_server_.Start());
1090 1090
1091 TestDelegate d; 1091 TestDelegate d;
1092 BlockingNetworkDelegateWithManualCallback network_delegate; 1092 BlockingNetworkDelegateWithManualCallback network_delegate;
1093 network_delegate.BlockOn( 1093 network_delegate.BlockOn(
1094 BlockingNetworkDelegateWithManualCallback::ON_AUTH_REQUIRED); 1094 BlockingNetworkDelegateWithManualCallback::ON_AUTH_REQUIRED);
1095 1095
1096 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 1096 TestURLRequestContext context(true);
1097 context->set_network_delegate(&network_delegate); 1097 context.set_network_delegate(&network_delegate);
1098 context->Init(); 1098 context.Init();
1099 1099
1100 { 1100 {
1101 TestURLRequest r(test_server_.GetURL("auth-basic"), &d); 1101 URLRequest r(test_server_.GetURL("auth-basic"), &d);
1102 r.set_context(context); 1102 r.set_context(&context);
1103 1103
1104 r.Start(); 1104 r.Start();
1105 network_delegate.WaitForState( 1105 network_delegate.WaitForState(
1106 BlockingNetworkDelegateWithManualCallback::ON_AUTH_REQUIRED); 1106 BlockingNetworkDelegateWithManualCallback::ON_AUTH_REQUIRED);
1107 EXPECT_EQ(0, network_delegate.completed_requests()); 1107 EXPECT_EQ(0, network_delegate.completed_requests());
1108 // Cancel before callback. 1108 // Cancel before callback.
1109 r.Cancel(); 1109 r.Cancel();
1110 // Ensure that network delegate is notified. 1110 // Ensure that network delegate is notified.
1111 EXPECT_EQ(1, network_delegate.completed_requests()); 1111 EXPECT_EQ(1, network_delegate.completed_requests());
1112 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 1112 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
1113 EXPECT_EQ(ERR_ABORTED, r.status().error()); 1113 EXPECT_EQ(ERR_ABORTED, r.status().error());
1114 EXPECT_EQ(1, network_delegate.created_requests()); 1114 EXPECT_EQ(1, network_delegate.created_requests());
1115 EXPECT_EQ(0, network_delegate.destroyed_requests()); 1115 EXPECT_EQ(0, network_delegate.destroyed_requests());
1116 } 1116 }
1117 EXPECT_EQ(1, network_delegate.destroyed_requests()); 1117 EXPECT_EQ(1, network_delegate.destroyed_requests());
1118 } 1118 }
1119 1119
1120 // In this unit test, we're using the HTTPTestServer as a proxy server and 1120 // In this unit test, we're using the HTTPTestServer as a proxy server and
1121 // issuing a CONNECT request with the magic host name "www.server-auth.com". 1121 // issuing a CONNECT request with the magic host name "www.server-auth.com".
1122 // The HTTPTestServer will return a 401 response, which we should balk at. 1122 // The HTTPTestServer will return a 401 response, which we should balk at.
1123 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { 1123 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) {
1124 ASSERT_TRUE(test_server_.Start()); 1124 ASSERT_TRUE(test_server_.Start());
1125 1125
1126 TestNetworkDelegate network_delegate; // must outlive URLRequest 1126 TestNetworkDelegate network_delegate; // must outlive URLRequest
1127 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 1127 TestURLRequestContext context(true);
1128 context->SetProxyFromString(test_server_.host_port_pair().ToString()); 1128 context.SetProxyFromString(test_server_.host_port_pair().ToString());
1129 context->set_network_delegate(&network_delegate); 1129 context.set_network_delegate(&network_delegate);
1130 context->Init(); 1130 context.Init();
1131 1131
1132 TestDelegate d; 1132 TestDelegate d;
1133 { 1133 {
1134 URLRequest r(GURL("https://www.server-auth.com/"), &d); 1134 URLRequest r(GURL("https://www.server-auth.com/"), &d);
1135 r.set_context(context); 1135 r.set_context(&context);
1136 1136
1137 r.Start(); 1137 r.Start();
1138 EXPECT_TRUE(r.is_pending()); 1138 EXPECT_TRUE(r.is_pending());
1139 1139
1140 MessageLoop::current()->Run(); 1140 MessageLoop::current()->Run();
1141 1141
1142 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); 1142 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status());
1143 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); 1143 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error());
1144 } 1144 }
1145 } 1145 }
1146 1146
1147 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { 1147 TEST_F(URLRequestTestHTTP, GetTest_NoCache) {
1148 ASSERT_TRUE(test_server_.Start()); 1148 ASSERT_TRUE(test_server_.Start());
1149 1149
1150 TestDelegate d; 1150 TestDelegate d;
1151 { 1151 {
1152 TestURLRequest r(test_server_.GetURL(""), &d); 1152 URLRequest r(test_server_.GetURL(""), &d);
1153 r.set_context(default_context_); 1153 r.set_context(&default_context_);
1154 1154
1155 r.Start(); 1155 r.Start();
1156 EXPECT_TRUE(r.is_pending()); 1156 EXPECT_TRUE(r.is_pending());
1157 1157
1158 MessageLoop::current()->Run(); 1158 MessageLoop::current()->Run();
1159 1159
1160 EXPECT_EQ(1, d.response_started_count()); 1160 EXPECT_EQ(1, d.response_started_count());
1161 EXPECT_FALSE(d.received_data_before_response()); 1161 EXPECT_FALSE(d.received_data_before_response());
1162 EXPECT_NE(0, d.bytes_received()); 1162 EXPECT_NE(0, d.bytes_received());
1163 EXPECT_EQ(test_server_.host_port_pair().host(), 1163 EXPECT_EQ(test_server_.host_port_pair().host(),
1164 r.GetSocketAddress().host()); 1164 r.GetSocketAddress().host());
1165 EXPECT_EQ(test_server_.host_port_pair().port(), 1165 EXPECT_EQ(test_server_.host_port_pair().port(),
1166 r.GetSocketAddress().port()); 1166 r.GetSocketAddress().port());
1167 1167
1168 // TODO(eroman): Add back the NetLog tests... 1168 // TODO(eroman): Add back the NetLog tests...
1169 } 1169 }
1170 } 1170 }
1171 1171
1172 TEST_F(URLRequestTestHTTP, GetTest) { 1172 TEST_F(URLRequestTestHTTP, GetTest) {
1173 ASSERT_TRUE(test_server_.Start()); 1173 ASSERT_TRUE(test_server_.Start());
1174 1174
1175 TestDelegate d; 1175 TestDelegate d;
1176 { 1176 {
1177 TestURLRequest r(test_server_.GetURL(""), &d); 1177 URLRequest r(test_server_.GetURL(""), &d);
1178 r.set_context(default_context_); 1178 r.set_context(&default_context_);
1179 1179
1180 r.Start(); 1180 r.Start();
1181 EXPECT_TRUE(r.is_pending()); 1181 EXPECT_TRUE(r.is_pending());
1182 1182
1183 MessageLoop::current()->Run(); 1183 MessageLoop::current()->Run();
1184 1184
1185 EXPECT_EQ(1, d.response_started_count()); 1185 EXPECT_EQ(1, d.response_started_count());
1186 EXPECT_FALSE(d.received_data_before_response()); 1186 EXPECT_FALSE(d.received_data_before_response());
1187 EXPECT_NE(0, d.bytes_received()); 1187 EXPECT_NE(0, d.bytes_received());
1188 EXPECT_EQ(test_server_.host_port_pair().host(), 1188 EXPECT_EQ(test_server_.host_port_pair().host(),
(...skipping 21 matching lines...) Expand all
1210 { true, true, false, false, true }; 1210 { true, true, false, false, true };
1211 1211
1212 for (int i = 0; i < num_tests ; i++) { 1212 for (int i = 0; i < num_tests ; i++) {
1213 TestDelegate d; 1213 TestDelegate d;
1214 { 1214 {
1215 std::string test_file = 1215 std::string test_file =
1216 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", 1216 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c",
1217 test_parameters[i]); 1217 test_parameters[i]);
1218 1218
1219 TestNetworkDelegate network_delegate; // must outlive URLRequest 1219 TestNetworkDelegate network_delegate; // must outlive URLRequest
1220 scoped_refptr<TestURLRequestContext> context( 1220 TestURLRequestContext context(true);
1221 new TestURLRequestContext(true)); 1221 context.set_network_delegate(&network_delegate);
1222 context->set_network_delegate(&network_delegate); 1222 context.Init();
1223 context->Init();
1224 1223
1225 TestURLRequest r(test_server_.GetURL(test_file), &d); 1224 URLRequest r(test_server_.GetURL(test_file), &d);
1226 r.set_context(context); 1225 r.set_context(&context);
1227 r.Start(); 1226 r.Start();
1228 EXPECT_TRUE(r.is_pending()); 1227 EXPECT_TRUE(r.is_pending());
1229 1228
1230 MessageLoop::current()->Run(); 1229 MessageLoop::current()->Run();
1231 1230
1232 EXPECT_EQ(1, d.response_started_count()); 1231 EXPECT_EQ(1, d.response_started_count());
1233 EXPECT_FALSE(d.received_data_before_response()); 1232 EXPECT_FALSE(d.received_data_before_response());
1234 VLOG(1) << " Received " << d.bytes_received() << " bytes" 1233 VLOG(1) << " Received " << d.bytes_received() << " bytes"
1235 << " status = " << r.status().status() 1234 << " status = " << r.status().status()
1236 << " error = " << r.status().error(); 1235 << " error = " << r.status().error();
(...skipping 17 matching lines...) Expand all
1254 TestServer https_test_server(TestServer::TYPE_HTTPS, 1253 TestServer https_test_server(TestServer::TYPE_HTTPS,
1255 TestServer::kLocalhost, 1254 TestServer::kLocalhost,
1256 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 1255 FilePath(FILE_PATH_LITERAL("net/data/ssl")));
1257 ASSERT_TRUE(https_test_server.Start()); 1256 ASSERT_TRUE(https_test_server.Start());
1258 1257
1259 // An https server is sent a request with an https referer, 1258 // An https server is sent a request with an https referer,
1260 // and responds with a redirect to an http url. The http 1259 // and responds with a redirect to an http url. The http
1261 // server should not be sent the referer. 1260 // server should not be sent the referer.
1262 GURL http_destination = test_server_.GetURL(""); 1261 GURL http_destination = test_server_.GetURL("");
1263 TestDelegate d; 1262 TestDelegate d;
1264 TestURLRequest req(https_test_server.GetURL( 1263 URLRequest req(https_test_server.GetURL(
1265 "server-redirect?" + http_destination.spec()), &d); 1264 "server-redirect?" + http_destination.spec()), &d);
1266 req.set_context(default_context_); 1265 req.set_context(&default_context_);
1267 req.set_referrer("https://www.referrer.com/"); 1266 req.set_referrer("https://www.referrer.com/");
1268 req.Start(); 1267 req.Start();
1269 MessageLoop::current()->Run(); 1268 MessageLoop::current()->Run();
1270 1269
1271 EXPECT_EQ(1, d.response_started_count()); 1270 EXPECT_EQ(1, d.response_started_count());
1272 EXPECT_EQ(1, d.received_redirect_count()); 1271 EXPECT_EQ(1, d.received_redirect_count());
1273 EXPECT_EQ(http_destination, req.url()); 1272 EXPECT_EQ(http_destination, req.url());
1274 EXPECT_EQ(std::string(), req.referrer()); 1273 EXPECT_EQ(std::string(), req.referrer());
1275 } 1274 }
1276 1275
1277 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { 1276 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) {
1278 ASSERT_TRUE(test_server_.Start()); 1277 ASSERT_TRUE(test_server_.Start());
1279 1278
1280 GURL destination_url = test_server_.GetURL(""); 1279 GURL destination_url = test_server_.GetURL("");
1281 GURL middle_redirect_url = test_server_.GetURL( 1280 GURL middle_redirect_url = test_server_.GetURL(
1282 "server-redirect?" + destination_url.spec()); 1281 "server-redirect?" + destination_url.spec());
1283 GURL original_url = test_server_.GetURL( 1282 GURL original_url = test_server_.GetURL(
1284 "server-redirect?" + middle_redirect_url.spec()); 1283 "server-redirect?" + middle_redirect_url.spec());
1285 TestDelegate d; 1284 TestDelegate d;
1286 TestURLRequest req(original_url, &d); 1285 URLRequest req(original_url, &d);
1287 req.set_context(default_context_); 1286 req.set_context(&default_context_);
1288 req.Start(); 1287 req.Start();
1289 MessageLoop::current()->Run(); 1288 MessageLoop::current()->Run();
1290 1289
1291 EXPECT_EQ(1, d.response_started_count()); 1290 EXPECT_EQ(1, d.response_started_count());
1292 EXPECT_EQ(2, d.received_redirect_count()); 1291 EXPECT_EQ(2, d.received_redirect_count());
1293 EXPECT_EQ(destination_url, req.url()); 1292 EXPECT_EQ(destination_url, req.url());
1294 EXPECT_EQ(original_url, req.original_url()); 1293 EXPECT_EQ(original_url, req.original_url());
1295 ASSERT_EQ(3U, req.url_chain().size()); 1294 ASSERT_EQ(3U, req.url_chain().size());
1296 EXPECT_EQ(original_url, req.url_chain()[0]); 1295 EXPECT_EQ(original_url, req.url_chain()[0]);
1297 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]); 1296 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]);
1298 EXPECT_EQ(destination_url, req.url_chain()[2]); 1297 EXPECT_EQ(destination_url, req.url_chain()[2]);
1299 } 1298 }
1300 1299
1301 class HTTPSRequestTest : public testing::Test { 1300 class HTTPSRequestTest : public testing::Test {
1302 public: 1301 public:
1303 HTTPSRequestTest() : default_context_(new TestURLRequestContext(true)) { 1302 HTTPSRequestTest() : default_context_(true) {
1304 default_context_->set_network_delegate(&default_network_delegate_); 1303 default_context_.set_network_delegate(&default_network_delegate_);
1305 default_context_->Init(); 1304 default_context_.Init();
1306 } 1305 }
1307 virtual ~HTTPSRequestTest() {} 1306 virtual ~HTTPSRequestTest() {}
1308 1307
1309 protected: 1308 protected:
1310 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest 1309 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest
1311 scoped_refptr<TestURLRequestContext> default_context_; 1310 TestURLRequestContext default_context_;
1312 }; 1311 };
1313 1312
1314 // This test was disabled because it made chrome_frame_net_tests hang 1313 // This test was disabled because it made chrome_frame_net_tests hang
1315 // (see bug 102991). 1314 // (see bug 102991).
1316 TEST_F(HTTPSRequestTest, DISABLED_HTTPSGetTest) { 1315 TEST_F(HTTPSRequestTest, DISABLED_HTTPSGetTest) {
1317 TestServer test_server(TestServer::TYPE_HTTPS, 1316 TestServer test_server(TestServer::TYPE_HTTPS,
1318 TestServer::kLocalhost, 1317 TestServer::kLocalhost,
1319 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 1318 FilePath(FILE_PATH_LITERAL("net/data/ssl")));
1320 ASSERT_TRUE(test_server.Start()); 1319 ASSERT_TRUE(test_server.Start());
1321 1320
1322 TestDelegate d; 1321 TestDelegate d;
1323 { 1322 {
1324 TestURLRequest r(test_server.GetURL(""), &d); 1323 URLRequest r(test_server.GetURL(""), &d);
1325 r.set_context(default_context_); 1324 r.set_context(&default_context_);
1326 r.Start(); 1325 r.Start();
1327 EXPECT_TRUE(r.is_pending()); 1326 EXPECT_TRUE(r.is_pending());
1328 1327
1329 MessageLoop::current()->Run(); 1328 MessageLoop::current()->Run();
1330 1329
1331 EXPECT_EQ(1, d.response_started_count()); 1330 EXPECT_EQ(1, d.response_started_count());
1332 EXPECT_FALSE(d.received_data_before_response()); 1331 EXPECT_FALSE(d.received_data_before_response());
1333 EXPECT_NE(0, d.bytes_received()); 1332 EXPECT_NE(0, d.bytes_received());
1334 CheckSSLInfo(r.ssl_info()); 1333 CheckSSLInfo(r.ssl_info());
1335 EXPECT_EQ(test_server.host_port_pair().host(), 1334 EXPECT_EQ(test_server.host_port_pair().host(),
1336 r.GetSocketAddress().host()); 1335 r.GetSocketAddress().host());
1337 EXPECT_EQ(test_server.host_port_pair().port(), 1336 EXPECT_EQ(test_server.host_port_pair().port(),
1338 r.GetSocketAddress().port()); 1337 r.GetSocketAddress().port());
1339 } 1338 }
1340 } 1339 }
1341 1340
1342 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { 1341 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) {
1343 TestServer::HTTPSOptions https_options( 1342 TestServer::HTTPSOptions https_options(
1344 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); 1343 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME);
1345 TestServer test_server(https_options, 1344 TestServer test_server(https_options,
1346 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 1345 FilePath(FILE_PATH_LITERAL("net/data/ssl")));
1347 ASSERT_TRUE(test_server.Start()); 1346 ASSERT_TRUE(test_server.Start());
1348 1347
1349 bool err_allowed = true; 1348 bool err_allowed = true;
1350 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { 1349 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) {
1351 TestDelegate d; 1350 TestDelegate d;
1352 { 1351 {
1353 d.set_allow_certificate_errors(err_allowed); 1352 d.set_allow_certificate_errors(err_allowed);
1354 TestURLRequest r(test_server.GetURL(""), &d); 1353 URLRequest r(test_server.GetURL(""), &d);
1355 r.set_context(default_context_); 1354 r.set_context(&default_context_);
1356 1355
1357 r.Start(); 1356 r.Start();
1358 EXPECT_TRUE(r.is_pending()); 1357 EXPECT_TRUE(r.is_pending());
1359 1358
1360 MessageLoop::current()->Run(); 1359 MessageLoop::current()->Run();
1361 1360
1362 EXPECT_EQ(1, d.response_started_count()); 1361 EXPECT_EQ(1, d.response_started_count());
1363 EXPECT_FALSE(d.received_data_before_response()); 1362 EXPECT_FALSE(d.received_data_before_response());
1364 EXPECT_TRUE(d.have_certificate_errors()); 1363 EXPECT_TRUE(d.have_certificate_errors());
1365 if (err_allowed) { 1364 if (err_allowed) {
(...skipping 13 matching lines...) Expand all
1379 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 1378 FilePath(FILE_PATH_LITERAL("net/data/ssl")));
1380 ASSERT_TRUE(test_server.Start()); 1379 ASSERT_TRUE(test_server.Start());
1381 1380
1382 // Iterate from false to true, just so that we do the opposite of the 1381 // Iterate from false to true, just so that we do the opposite of the
1383 // previous test in order to increase test coverage. 1382 // previous test in order to increase test coverage.
1384 bool err_allowed = false; 1383 bool err_allowed = false;
1385 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { 1384 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) {
1386 TestDelegate d; 1385 TestDelegate d;
1387 { 1386 {
1388 d.set_allow_certificate_errors(err_allowed); 1387 d.set_allow_certificate_errors(err_allowed);
1389 TestURLRequest r(test_server.GetURL(""), &d); 1388 URLRequest r(test_server.GetURL(""), &d);
1390 r.set_context(default_context_); 1389 r.set_context(&default_context_);
1391 1390
1392 r.Start(); 1391 r.Start();
1393 EXPECT_TRUE(r.is_pending()); 1392 EXPECT_TRUE(r.is_pending());
1394 1393
1395 MessageLoop::current()->Run(); 1394 MessageLoop::current()->Run();
1396 1395
1397 EXPECT_EQ(1, d.response_started_count()); 1396 EXPECT_EQ(1, d.response_started_count());
1398 EXPECT_FALSE(d.received_data_before_response()); 1397 EXPECT_FALSE(d.received_data_before_response());
1399 EXPECT_TRUE(d.have_certificate_errors()); 1398 EXPECT_TRUE(d.have_certificate_errors());
1400 if (err_allowed) { 1399 if (err_allowed) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 { { 0xf1, 0xad, 0xf6, 0xce, 0x42, 0xac, 0xe7, 0xb4, 0xf4, 0x24, 1434 { { 0xf1, 0xad, 0xf6, 0xce, 0x42, 0xac, 0xe7, 0xb4, 0xf4, 0x24,
1436 0xdb, 0x1a, 0xf7, 0xa0, 0x9f, 0x09, 0xa1, 0xea, 0xf1, 0x5c } }; 1435 0xdb, 0x1a, 0xf7, 0xa0, 0x9f, 0x09, 0xa1, 0xea, 0xf1, 0x5c } };
1437 1436
1438 // This is the policy OID contained in the certificates that testserver 1437 // This is the policy OID contained in the certificates that testserver
1439 // generates. 1438 // generates.
1440 static const char kOCSPTestCertPolicy[] = "1.3.6.1.4.1.11129.2.4.1"; 1439 static const char kOCSPTestCertPolicy[] = "1.3.6.1.4.1.11129.2.4.1";
1441 1440
1442 class HTTPSOCSPTest : public HTTPSRequestTest { 1441 class HTTPSOCSPTest : public HTTPSRequestTest {
1443 public: 1442 public:
1444 HTTPSOCSPTest() 1443 HTTPSOCSPTest()
1445 : context_(new TestURLRequestContext(true)), 1444 : context_(true),
1446 ev_test_policy_(EVRootCAMetadata::GetInstance(), 1445 ev_test_policy_(EVRootCAMetadata::GetInstance(),
1447 kOCSPTestCertFingerprint, 1446 kOCSPTestCertFingerprint,
1448 kOCSPTestCertPolicy) { 1447 kOCSPTestCertPolicy) {
1449 } 1448 }
1450 1449
1451 virtual void SetUp() OVERRIDE { 1450 virtual void SetUp() OVERRIDE {
1452 SetupContext(context_); 1451 SetupContext(&context_);
1453 context_->Init(); 1452 context_.Init();
1454 1453
1455 scoped_refptr<net::X509Certificate> root_cert = 1454 scoped_refptr<net::X509Certificate> root_cert =
1456 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem"); 1455 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem");
1457 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert); 1456 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert);
1458 test_root_.reset(new ScopedTestRoot(root_cert)); 1457 test_root_.reset(new ScopedTestRoot(root_cert));
1459 1458
1460 #if defined(USE_NSS) 1459 #if defined(USE_NSS)
1461 SetURLRequestContextForNSSHttpIO(context_.get()); 1460 SetURLRequestContextForNSSHttpIO(&context_);
1462 EnsureNSSHttpIOInit(); 1461 EnsureNSSHttpIOInit();
1463 #endif 1462 #endif
1464 } 1463 }
1465 1464
1466 void DoConnection(const TestServer::HTTPSOptions& https_options, 1465 void DoConnection(const TestServer::HTTPSOptions& https_options,
1467 CertStatus* out_cert_status) { 1466 CertStatus* out_cert_status) {
1468 TestServer test_server(https_options, 1467 TestServer test_server(https_options,
1469 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 1468 FilePath(FILE_PATH_LITERAL("net/data/ssl")));
1470 ASSERT_TRUE(test_server.Start()); 1469 ASSERT_TRUE(test_server.Start());
1471 1470
1472 TestDelegate d; 1471 TestDelegate d;
1473 d.set_allow_certificate_errors(true); 1472 d.set_allow_certificate_errors(true);
1474 URLRequest r(test_server.GetURL(""), &d); 1473 URLRequest r(test_server.GetURL(""), &d);
1475 r.set_context(context_.get()); 1474 r.set_context(&context_);
1476 r.Start(); 1475 r.Start();
1477 1476
1478 MessageLoop::current()->Run(); 1477 MessageLoop::current()->Run();
1479 1478
1480 EXPECT_EQ(1, d.response_started_count()); 1479 EXPECT_EQ(1, d.response_started_count());
1481 *out_cert_status = r.ssl_info().cert_status; 1480 *out_cert_status = r.ssl_info().cert_status;
1482 } 1481 }
1483 1482
1484 ~HTTPSOCSPTest() { 1483 ~HTTPSOCSPTest() {
1485 #if defined(USE_NSS) 1484 #if defined(USE_NSS)
1486 ShutdownNSSHttpIO(); 1485 ShutdownNSSHttpIO();
1487 #endif 1486 #endif
1488 } 1487 }
1489 1488
1490 protected: 1489 protected:
1491 // SetupContext configures the URLRequestContext that will be used for making 1490 // SetupContext configures the URLRequestContext that will be used for making
1492 // connetions to testserver. This can be overridden in test subclasses for 1491 // connetions to testserver. This can be overridden in test subclasses for
1493 // different behaviour. 1492 // different behaviour.
1494 virtual void SetupContext(URLRequestContext* context) { 1493 virtual void SetupContext(URLRequestContext* context) {
1495 context->set_ssl_config_service( 1494 context->set_ssl_config_service(
1496 new TestSSLConfigService(true /* check for EV */, 1495 new TestSSLConfigService(true /* check for EV */,
1497 true /* online revocation checking */)); 1496 true /* online revocation checking */));
1498 } 1497 }
1499 1498
1500 scoped_ptr<ScopedTestRoot> test_root_; 1499 scoped_ptr<ScopedTestRoot> test_root_;
1501 scoped_refptr<TestURLRequestContext> context_; 1500 TestURLRequestContext context_;
1502 ScopedTestEVPolicy ev_test_policy_; 1501 ScopedTestEVPolicy ev_test_policy_;
1503 }; 1502 };
1504 1503
1505 static CertStatus ExpectedCertStatusForFailedOnlineRevocationCheck() { 1504 static CertStatus ExpectedCertStatusForFailedOnlineRevocationCheck() {
1506 #if defined(OS_WIN) 1505 #if defined(OS_WIN)
1507 // Windows can return CERT_STATUS_UNABLE_TO_CHECK_REVOCATION but we don't 1506 // Windows can return CERT_STATUS_UNABLE_TO_CHECK_REVOCATION but we don't
1508 // have that ability on other platforms. 1507 // have that ability on other platforms.
1509 return CERT_STATUS_UNABLE_TO_CHECK_REVOCATION; 1508 return CERT_STATUS_UNABLE_TO_CHECK_REVOCATION;
1510 #else 1509 #else
1511 return 0; 1510 return 0;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 1727
1729 TEST_F(HTTPSRequestTest, SSLv3Fallback) { 1728 TEST_F(HTTPSRequestTest, SSLv3Fallback) {
1730 TestServer::HTTPSOptions https_options( 1729 TestServer::HTTPSOptions https_options(
1731 TestServer::HTTPSOptions::CERT_OK); 1730 TestServer::HTTPSOptions::CERT_OK);
1732 https_options.tls_intolerant = true; 1731 https_options.tls_intolerant = true;
1733 TestServer test_server(https_options, 1732 TestServer test_server(https_options,
1734 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 1733 FilePath(FILE_PATH_LITERAL("net/data/ssl")));
1735 ASSERT_TRUE(test_server.Start()); 1734 ASSERT_TRUE(test_server.Start());
1736 1735
1737 TestDelegate d; 1736 TestDelegate d;
1738 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 1737 TestURLRequestContext context(true);
1739 context->Init(); 1738 context.Init();
1740 d.set_allow_certificate_errors(true); 1739 d.set_allow_certificate_errors(true);
1741 URLRequest r(test_server.GetURL(""), &d); 1740 URLRequest r(test_server.GetURL(""), &d);
1742 r.set_context(context.get()); 1741 r.set_context(&context);
1743 r.Start(); 1742 r.Start();
1744 1743
1745 MessageLoop::current()->Run(); 1744 MessageLoop::current()->Run();
1746 1745
1747 EXPECT_EQ(1, d.response_started_count()); 1746 EXPECT_EQ(1, d.response_started_count());
1748 EXPECT_NE(0, d.bytes_received()); 1747 EXPECT_NE(0, d.bytes_received());
1749 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_SSL3_FALLBACK); 1748 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_SSL3_FALLBACK);
1750 } 1749 }
1751 1750
1752 // This tests that a load of www.google.com with a certificate error sets 1751 // This tests that a load of www.google.com with a certificate error sets
1753 // the |certificate_errors_are_fatal| flag correctly. This flag will cause 1752 // the |certificate_errors_are_fatal| flag correctly. This flag will cause
1754 // the interstitial to be fatal. 1753 // the interstitial to be fatal.
1755 TEST_F(HTTPSRequestTest, HTTPSPreloadedHSTSTest) { 1754 TEST_F(HTTPSRequestTest, HTTPSPreloadedHSTSTest) {
1756 TestServer::HTTPSOptions https_options( 1755 TestServer::HTTPSOptions https_options(
1757 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); 1756 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME);
1758 TestServer test_server(https_options, 1757 TestServer test_server(https_options,
1759 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 1758 FilePath(FILE_PATH_LITERAL("net/data/ssl")));
1760 ASSERT_TRUE(test_server.Start()); 1759 ASSERT_TRUE(test_server.Start());
1761 1760
1762 // We require that the URL be www.google.com in order to pick up the 1761 // We require that the URL be www.google.com in order to pick up the
1763 // preloaded HSTS entries in the TransportSecurityState. This means that we 1762 // preloaded HSTS entries in the TransportSecurityState. This means that we
1764 // have to use a MockHostResolver in order to direct www.google.com to the 1763 // have to use a MockHostResolver in order to direct www.google.com to the
1765 // testserver. 1764 // testserver.
1766 1765
1767 MockHostResolver host_resolver; 1766 MockHostResolver host_resolver;
1768 host_resolver.rules()->AddRule("www.google.com", "127.0.0.1"); 1767 host_resolver.rules()->AddRule("www.google.com", "127.0.0.1");
1769 TestNetworkDelegate network_delegate; // must outlive URLRequest 1768 TestNetworkDelegate network_delegate; // must outlive URLRequest
1770 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 1769 TestURLRequestContext context(true);
1771 context->set_network_delegate(&network_delegate); 1770 context.set_network_delegate(&network_delegate);
1772 context->set_host_resolver(&host_resolver); 1771 context.set_host_resolver(&host_resolver);
1773 TransportSecurityState transport_security_state; 1772 TransportSecurityState transport_security_state;
1774 context->set_transport_security_state(&transport_security_state); 1773 context.set_transport_security_state(&transport_security_state);
1775 context->Init(); 1774 context.Init();
1776 1775
1777 TestDelegate d; 1776 TestDelegate d;
1778 TestURLRequest r(GURL(StringPrintf("https://www.google.com:%d", 1777 URLRequest r(GURL(StringPrintf("https://www.google.com:%d",
1779 test_server.host_port_pair().port())), 1778 test_server.host_port_pair().port())),
1780 &d); 1779 &d);
1781 r.set_context(context); 1780 r.set_context(&context);
1782 1781
1783 r.Start(); 1782 r.Start();
1784 EXPECT_TRUE(r.is_pending()); 1783 EXPECT_TRUE(r.is_pending());
1785 1784
1786 MessageLoop::current()->Run(); 1785 MessageLoop::current()->Run();
1787 1786
1788 EXPECT_EQ(1, d.response_started_count()); 1787 EXPECT_EQ(1, d.response_started_count());
1789 EXPECT_FALSE(d.received_data_before_response()); 1788 EXPECT_FALSE(d.received_data_before_response());
1790 EXPECT_TRUE(d.have_certificate_errors()); 1789 EXPECT_TRUE(d.have_certificate_errors());
1791 EXPECT_TRUE(d.certificate_errors_are_fatal()); 1790 EXPECT_TRUE(d.certificate_errors_are_fatal());
(...skipping 11 matching lines...) Expand all
1803 ASSERT_TRUE(test_server.Start()); 1802 ASSERT_TRUE(test_server.Start());
1804 1803
1805 // We require that the URL be www.google.com in order to pick up the 1804 // We require that the URL be www.google.com in order to pick up the
1806 // preloaded and dynamic HSTS and public key pin entries in the 1805 // preloaded and dynamic HSTS and public key pin entries in the
1807 // TransportSecurityState. This means that we have to use a 1806 // TransportSecurityState. This means that we have to use a
1808 // MockHostResolver in order to direct www.google.com to the testserver. 1807 // MockHostResolver in order to direct www.google.com to the testserver.
1809 1808
1810 MockHostResolver host_resolver; 1809 MockHostResolver host_resolver;
1811 host_resolver.rules()->AddRule("www.google.com", "127.0.0.1"); 1810 host_resolver.rules()->AddRule("www.google.com", "127.0.0.1");
1812 TestNetworkDelegate network_delegate; // must outlive URLRequest 1811 TestNetworkDelegate network_delegate; // must outlive URLRequest
1813 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 1812 TestURLRequestContext context(true);
1814 context->set_network_delegate(&network_delegate); 1813 context.set_network_delegate(&network_delegate);
1815 context->set_host_resolver(&host_resolver); 1814 context.set_host_resolver(&host_resolver);
1816 TransportSecurityState transport_security_state; 1815 TransportSecurityState transport_security_state;
1817 TransportSecurityState::DomainState domain_state; 1816 TransportSecurityState::DomainState domain_state;
1818 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, 1817 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true,
1819 &domain_state)); 1818 &domain_state));
1820 context->set_transport_security_state(&transport_security_state); 1819 context.set_transport_security_state(&transport_security_state);
1821 context->Init(); 1820 context.Init();
1822 1821
1823 TestDelegate d; 1822 TestDelegate d;
1824 TestURLRequest r(GURL(StringPrintf("https://www.google.com:%d", 1823 URLRequest r(GURL(StringPrintf("https://www.google.com:%d",
1825 test_server.host_port_pair().port())), 1824 test_server.host_port_pair().port())),
1826 &d); 1825 &d);
1827 r.set_context(context); 1826 r.set_context(&context);
1828 1827
1829 r.Start(); 1828 r.Start();
1830 EXPECT_TRUE(r.is_pending()); 1829 EXPECT_TRUE(r.is_pending());
1831 1830
1832 MessageLoop::current()->Run(); 1831 MessageLoop::current()->Run();
1833 1832
1834 EXPECT_EQ(1, d.response_started_count()); 1833 EXPECT_EQ(1, d.response_started_count());
1835 EXPECT_FALSE(d.received_data_before_response()); 1834 EXPECT_FALSE(d.received_data_before_response());
1836 EXPECT_TRUE(d.have_certificate_errors()); 1835 EXPECT_TRUE(d.have_certificate_errors());
1837 EXPECT_TRUE(d.certificate_errors_are_fatal()); 1836 EXPECT_TRUE(d.certificate_errors_are_fatal());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1879 // HTTP request. 1878 // HTTP request.
1880 TEST_F(HTTPSRequestTest, ClientAuthTest) { 1879 TEST_F(HTTPSRequestTest, ClientAuthTest) {
1881 TestServer::HTTPSOptions https_options; 1880 TestServer::HTTPSOptions https_options;
1882 https_options.request_client_certificate = true; 1881 https_options.request_client_certificate = true;
1883 TestServer test_server(https_options, 1882 TestServer test_server(https_options,
1884 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 1883 FilePath(FILE_PATH_LITERAL("net/data/ssl")));
1885 ASSERT_TRUE(test_server.Start()); 1884 ASSERT_TRUE(test_server.Start());
1886 1885
1887 SSLClientAuthTestDelegate d; 1886 SSLClientAuthTestDelegate d;
1888 { 1887 {
1889 TestURLRequest r(test_server.GetURL(""), &d); 1888 URLRequest r(test_server.GetURL(""), &d);
1890 r.set_context(default_context_); 1889 r.set_context(&default_context_);
1891 1890
1892 r.Start(); 1891 r.Start();
1893 EXPECT_TRUE(r.is_pending()); 1892 EXPECT_TRUE(r.is_pending());
1894 1893
1895 MessageLoop::current()->Run(); 1894 MessageLoop::current()->Run();
1896 1895
1897 EXPECT_EQ(1, d.on_certificate_requested_count()); 1896 EXPECT_EQ(1, d.on_certificate_requested_count());
1898 EXPECT_FALSE(d.received_data_before_response()); 1897 EXPECT_FALSE(d.received_data_before_response());
1899 EXPECT_EQ(0, d.bytes_received()); 1898 EXPECT_EQ(0, d.bytes_received());
1900 1899
(...skipping 16 matching lines...) Expand all
1917 TestServer::HTTPSOptions https_options; 1916 TestServer::HTTPSOptions https_options;
1918 https_options.record_resume = true; 1917 https_options.record_resume = true;
1919 TestServer test_server(https_options, 1918 TestServer test_server(https_options,
1920 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 1919 FilePath(FILE_PATH_LITERAL("net/data/ssl")));
1921 ASSERT_TRUE(test_server.Start()); 1920 ASSERT_TRUE(test_server.Start());
1922 1921
1923 SSLClientSocket::ClearSessionCache(); 1922 SSLClientSocket::ClearSessionCache();
1924 1923
1925 { 1924 {
1926 TestDelegate d; 1925 TestDelegate d;
1927 TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); 1926 URLRequest r(test_server.GetURL("ssl-session-cache"), &d);
1928 r.set_context(default_context_); 1927 r.set_context(&default_context_);
1929 1928
1930 r.Start(); 1929 r.Start();
1931 EXPECT_TRUE(r.is_pending()); 1930 EXPECT_TRUE(r.is_pending());
1932 1931
1933 MessageLoop::current()->Run(); 1932 MessageLoop::current()->Run();
1934 1933
1935 EXPECT_EQ(1, d.response_started_count()); 1934 EXPECT_EQ(1, d.response_started_count());
1936 } 1935 }
1937 1936
1938 reinterpret_cast<HttpCache*>(default_context_->http_transaction_factory())-> 1937 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())->
1939 CloseAllConnections(); 1938 CloseAllConnections();
1940 1939
1941 { 1940 {
1942 TestDelegate d; 1941 TestDelegate d;
1943 TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); 1942 URLRequest r(test_server.GetURL("ssl-session-cache"), &d);
1944 r.set_context(default_context_); 1943 r.set_context(&default_context_);
1945 1944
1946 r.Start(); 1945 r.Start();
1947 EXPECT_TRUE(r.is_pending()); 1946 EXPECT_TRUE(r.is_pending());
1948 1947
1949 MessageLoop::current()->Run(); 1948 MessageLoop::current()->Run();
1950 1949
1951 // The response will look like; 1950 // The response will look like;
1952 // insert abc 1951 // insert abc
1953 // lookup abc 1952 // lookup abc
1954 // insert xyz 1953 // insert xyz
(...skipping 29 matching lines...) Expand all
1984 TestServer::HTTPSOptions https_options; 1983 TestServer::HTTPSOptions https_options;
1985 https_options.record_resume = true; 1984 https_options.record_resume = true;
1986 TestServer test_server(https_options, 1985 TestServer test_server(https_options,
1987 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 1986 FilePath(FILE_PATH_LITERAL("net/data/ssl")));
1988 ASSERT_TRUE(test_server.Start()); 1987 ASSERT_TRUE(test_server.Start());
1989 1988
1990 SSLClientSocket::ClearSessionCache(); 1989 SSLClientSocket::ClearSessionCache();
1991 1990
1992 { 1991 {
1993 TestDelegate d; 1992 TestDelegate d;
1994 TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); 1993 URLRequest r(test_server.GetURL("ssl-session-cache"), &d);
1995 r.set_context(default_context_); 1994 r.set_context(&default_context_);
1996 1995
1997 r.Start(); 1996 r.Start();
1998 EXPECT_TRUE(r.is_pending()); 1997 EXPECT_TRUE(r.is_pending());
1999 1998
2000 MessageLoop::current()->Run(); 1999 MessageLoop::current()->Run();
2001 2000
2002 EXPECT_EQ(1, d.response_started_count()); 2001 EXPECT_EQ(1, d.response_started_count());
2003 } 2002 }
2004 2003
2005 // Now create a new HttpCache with a different ssl_session_cache_shard value. 2004 // Now create a new HttpCache with a different ssl_session_cache_shard value.
2006 HttpNetworkSession::Params params; 2005 HttpNetworkSession::Params params;
2007 params.host_resolver = default_context_->host_resolver(); 2006 params.host_resolver = default_context_.host_resolver();
2008 params.cert_verifier = default_context_->cert_verifier(); 2007 params.cert_verifier = default_context_.cert_verifier();
2009 params.proxy_service = default_context_->proxy_service(); 2008 params.proxy_service = default_context_.proxy_service();
2010 params.ssl_config_service = default_context_->ssl_config_service(); 2009 params.ssl_config_service = default_context_.ssl_config_service();
2011 params.http_auth_handler_factory = 2010 params.http_auth_handler_factory =
2012 default_context_->http_auth_handler_factory(); 2011 default_context_.http_auth_handler_factory();
2013 params.network_delegate = default_context_->network_delegate(); 2012 params.network_delegate = default_context_.network_delegate();
2014 params.http_server_properties = default_context_->http_server_properties(); 2013 params.http_server_properties = default_context_.http_server_properties();
2015 params.ssl_session_cache_shard = "alternate"; 2014 params.ssl_session_cache_shard = "alternate";
2016 2015
2017 scoped_ptr<net::HttpCache> cache(new net::HttpCache( 2016 scoped_ptr<net::HttpCache> cache(new net::HttpCache(
2018 new net::HttpNetworkSession(params), 2017 new net::HttpNetworkSession(params),
2019 net::HttpCache::DefaultBackend::InMemory(0))); 2018 net::HttpCache::DefaultBackend::InMemory(0)));
2020 2019
2021 default_context_->set_http_transaction_factory(cache.get()); 2020 default_context_.set_http_transaction_factory(cache.get());
2022 2021
2023 { 2022 {
2024 TestDelegate d; 2023 TestDelegate d;
2025 TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); 2024 URLRequest r(test_server.GetURL("ssl-session-cache"), &d);
2026 r.set_context(default_context_); 2025 r.set_context(&default_context_);
2027 2026
2028 r.Start(); 2027 r.Start();
2029 EXPECT_TRUE(r.is_pending()); 2028 EXPECT_TRUE(r.is_pending());
2030 2029
2031 MessageLoop::current()->Run(); 2030 MessageLoop::current()->Run();
2032 2031
2033 // The response will look like; 2032 // The response will look like;
2034 // insert abc 2033 // insert abc
2035 // insert xyz 2034 // insert xyz
2036 // 2035 //
(...skipping 16 matching lines...) Expand all
2053 } else { 2052 } else {
2054 EXPECT_NE(session_id, parts[1]); 2053 EXPECT_NE(session_id, parts[1]);
2055 } 2054 }
2056 } 2055 }
2057 } 2056 }
2058 } 2057 }
2059 2058
2060 TEST_F(URLRequestTestHTTP, CancelTest) { 2059 TEST_F(URLRequestTestHTTP, CancelTest) {
2061 TestDelegate d; 2060 TestDelegate d;
2062 { 2061 {
2063 TestURLRequest r(GURL("http://www.google.com/"), &d); 2062 URLRequest r(GURL("http://www.google.com/"), &d);
2064 r.set_context(default_context_); 2063 r.set_context(&default_context_);
2065 2064
2066 r.Start(); 2065 r.Start();
2067 EXPECT_TRUE(r.is_pending()); 2066 EXPECT_TRUE(r.is_pending());
2068 2067
2069 r.Cancel(); 2068 r.Cancel();
2070 2069
2071 MessageLoop::current()->Run(); 2070 MessageLoop::current()->Run();
2072 2071
2073 // We expect to receive OnResponseStarted even though the request has been 2072 // We expect to receive OnResponseStarted even though the request has been
2074 // cancelled. 2073 // cancelled.
2075 EXPECT_EQ(1, d.response_started_count()); 2074 EXPECT_EQ(1, d.response_started_count());
2076 EXPECT_EQ(0, d.bytes_received()); 2075 EXPECT_EQ(0, d.bytes_received());
2077 EXPECT_FALSE(d.received_data_before_response()); 2076 EXPECT_FALSE(d.received_data_before_response());
2078 } 2077 }
2079 } 2078 }
2080 2079
2081 TEST_F(URLRequestTestHTTP, CancelTest2) { 2080 TEST_F(URLRequestTestHTTP, CancelTest2) {
2082 ASSERT_TRUE(test_server_.Start()); 2081 ASSERT_TRUE(test_server_.Start());
2083 2082
2084 TestDelegate d; 2083 TestDelegate d;
2085 { 2084 {
2086 TestURLRequest r(test_server_.GetURL(""), &d); 2085 URLRequest r(test_server_.GetURL(""), &d);
2087 r.set_context(default_context_); 2086 r.set_context(&default_context_);
2088 2087
2089 d.set_cancel_in_response_started(true); 2088 d.set_cancel_in_response_started(true);
2090 2089
2091 r.Start(); 2090 r.Start();
2092 EXPECT_TRUE(r.is_pending()); 2091 EXPECT_TRUE(r.is_pending());
2093 2092
2094 MessageLoop::current()->Run(); 2093 MessageLoop::current()->Run();
2095 2094
2096 EXPECT_EQ(1, d.response_started_count()); 2095 EXPECT_EQ(1, d.response_started_count());
2097 EXPECT_EQ(0, d.bytes_received()); 2096 EXPECT_EQ(0, d.bytes_received());
2098 EXPECT_FALSE(d.received_data_before_response()); 2097 EXPECT_FALSE(d.received_data_before_response());
2099 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 2098 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
2100 } 2099 }
2101 } 2100 }
2102 2101
2103 TEST_F(URLRequestTestHTTP, CancelTest3) { 2102 TEST_F(URLRequestTestHTTP, CancelTest3) {
2104 ASSERT_TRUE(test_server_.Start()); 2103 ASSERT_TRUE(test_server_.Start());
2105 2104
2106 TestDelegate d; 2105 TestDelegate d;
2107 { 2106 {
2108 TestURLRequest r(test_server_.GetURL(""), &d); 2107 URLRequest r(test_server_.GetURL(""), &d);
2109 r.set_context(default_context_); 2108 r.set_context(&default_context_);
2110 2109
2111 d.set_cancel_in_received_data(true); 2110 d.set_cancel_in_received_data(true);
2112 2111
2113 r.Start(); 2112 r.Start();
2114 EXPECT_TRUE(r.is_pending()); 2113 EXPECT_TRUE(r.is_pending());
2115 2114
2116 MessageLoop::current()->Run(); 2115 MessageLoop::current()->Run();
2117 2116
2118 EXPECT_EQ(1, d.response_started_count()); 2117 EXPECT_EQ(1, d.response_started_count());
2119 // There is no guarantee about how much data was received 2118 // There is no guarantee about how much data was received
2120 // before the cancel was issued. It could have been 0 bytes, 2119 // before the cancel was issued. It could have been 0 bytes,
2121 // or it could have been all the bytes. 2120 // or it could have been all the bytes.
2122 // EXPECT_EQ(0, d.bytes_received()); 2121 // EXPECT_EQ(0, d.bytes_received());
2123 EXPECT_FALSE(d.received_data_before_response()); 2122 EXPECT_FALSE(d.received_data_before_response());
2124 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 2123 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
2125 } 2124 }
2126 } 2125 }
2127 2126
2128 TEST_F(URLRequestTestHTTP, CancelTest4) { 2127 TEST_F(URLRequestTestHTTP, CancelTest4) {
2129 ASSERT_TRUE(test_server_.Start()); 2128 ASSERT_TRUE(test_server_.Start());
2130 2129
2131 TestDelegate d; 2130 TestDelegate d;
2132 { 2131 {
2133 TestURLRequest r(test_server_.GetURL(""), &d); 2132 URLRequest r(test_server_.GetURL(""), &d);
2134 r.set_context(default_context_); 2133 r.set_context(&default_context_);
2135 2134
2136 r.Start(); 2135 r.Start();
2137 EXPECT_TRUE(r.is_pending()); 2136 EXPECT_TRUE(r.is_pending());
2138 2137
2139 // The request will be implicitly canceled when it is destroyed. The 2138 // The request will be implicitly canceled when it is destroyed. The
2140 // test delegate must not post a quit message when this happens because 2139 // test delegate must not post a quit message when this happens because
2141 // this test doesn't actually have a message loop. The quit message would 2140 // this test doesn't actually have a message loop. The quit message would
2142 // get put on this thread's message queue and the next test would exit 2141 // get put on this thread's message queue and the next test would exit
2143 // early, causing problems. 2142 // early, causing problems.
2144 d.set_quit_on_complete(false); 2143 d.set_quit_on_complete(false);
2145 } 2144 }
2146 // expect things to just cleanup properly. 2145 // expect things to just cleanup properly.
2147 2146
2148 // we won't actually get a received reponse here because we've never run the 2147 // we won't actually get a received reponse here because we've never run the
2149 // message loop 2148 // message loop
2150 EXPECT_FALSE(d.received_data_before_response()); 2149 EXPECT_FALSE(d.received_data_before_response());
2151 EXPECT_EQ(0, d.bytes_received()); 2150 EXPECT_EQ(0, d.bytes_received());
2152 } 2151 }
2153 2152
2154 TEST_F(URLRequestTestHTTP, CancelTest5) { 2153 TEST_F(URLRequestTestHTTP, CancelTest5) {
2155 ASSERT_TRUE(test_server_.Start()); 2154 ASSERT_TRUE(test_server_.Start());
2156 2155
2157 // populate cache 2156 // populate cache
2158 { 2157 {
2159 TestDelegate d; 2158 TestDelegate d;
2160 URLRequest r(test_server_.GetURL("cachetime"), &d); 2159 URLRequest r(test_server_.GetURL("cachetime"), &d);
2161 r.set_context(default_context_); 2160 r.set_context(&default_context_);
2162 r.Start(); 2161 r.Start();
2163 MessageLoop::current()->Run(); 2162 MessageLoop::current()->Run();
2164 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 2163 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
2165 } 2164 }
2166 2165
2167 // cancel read from cache (see bug 990242) 2166 // cancel read from cache (see bug 990242)
2168 { 2167 {
2169 TestDelegate d; 2168 TestDelegate d;
2170 URLRequest r(test_server_.GetURL("cachetime"), &d); 2169 URLRequest r(test_server_.GetURL("cachetime"), &d);
2171 r.set_context(default_context_); 2170 r.set_context(&default_context_);
2172 r.Start(); 2171 r.Start();
2173 r.Cancel(); 2172 r.Cancel();
2174 MessageLoop::current()->Run(); 2173 MessageLoop::current()->Run();
2175 2174
2176 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); 2175 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status());
2177 EXPECT_EQ(1, d.response_started_count()); 2176 EXPECT_EQ(1, d.response_started_count());
2178 EXPECT_EQ(0, d.bytes_received()); 2177 EXPECT_EQ(0, d.bytes_received());
2179 EXPECT_FALSE(d.received_data_before_response()); 2178 EXPECT_FALSE(d.received_data_before_response());
2180 } 2179 }
2181 } 2180 }
2182 2181
2183 TEST_F(URLRequestTestHTTP, PostTest) { 2182 TEST_F(URLRequestTestHTTP, PostTest) {
2184 ASSERT_TRUE(test_server_.Start()); 2183 ASSERT_TRUE(test_server_.Start());
2185 HTTPUploadDataOperationTest("POST"); 2184 HTTPUploadDataOperationTest("POST");
2186 } 2185 }
2187 2186
2188 TEST_F(URLRequestTestHTTP, PutTest) { 2187 TEST_F(URLRequestTestHTTP, PutTest) {
2189 ASSERT_TRUE(test_server_.Start()); 2188 ASSERT_TRUE(test_server_.Start());
2190 HTTPUploadDataOperationTest("PUT"); 2189 HTTPUploadDataOperationTest("PUT");
2191 } 2190 }
2192 2191
2193 TEST_F(URLRequestTestHTTP, PostEmptyTest) { 2192 TEST_F(URLRequestTestHTTP, PostEmptyTest) {
2194 ASSERT_TRUE(test_server_.Start()); 2193 ASSERT_TRUE(test_server_.Start());
2195 2194
2196 TestDelegate d; 2195 TestDelegate d;
2197 { 2196 {
2198 TestURLRequest r(test_server_.GetURL("echo"), &d); 2197 URLRequest r(test_server_.GetURL("echo"), &d);
2199 r.set_context(default_context_); 2198 r.set_context(&default_context_);
2200 r.set_method("POST"); 2199 r.set_method("POST");
2201 2200
2202 r.Start(); 2201 r.Start();
2203 EXPECT_TRUE(r.is_pending()); 2202 EXPECT_TRUE(r.is_pending());
2204 2203
2205 MessageLoop::current()->Run(); 2204 MessageLoop::current()->Run();
2206 2205
2207 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << 2206 ASSERT_EQ(1, d.response_started_count()) << "request failed: " <<
2208 (int) r.status().status() << ", error: " << r.status().error(); 2207 (int) r.status().status() << ", error: " << r.status().error();
2209 2208
2210 EXPECT_FALSE(d.received_data_before_response()); 2209 EXPECT_FALSE(d.received_data_before_response());
2211 EXPECT_TRUE(d.data_received().empty()); 2210 EXPECT_TRUE(d.data_received().empty());
2212 } 2211 }
2213 } 2212 }
2214 2213
2215 TEST_F(URLRequestTestHTTP, PostFileTest) { 2214 TEST_F(URLRequestTestHTTP, PostFileTest) {
2216 ASSERT_TRUE(test_server_.Start()); 2215 ASSERT_TRUE(test_server_.Start());
2217 2216
2218 TestDelegate d; 2217 TestDelegate d;
2219 { 2218 {
2220 TestURLRequest r(test_server_.GetURL("echo"), &d); 2219 URLRequest r(test_server_.GetURL("echo"), &d);
2221 r.set_context(default_context_); 2220 r.set_context(&default_context_);
2222 r.set_method("POST"); 2221 r.set_method("POST");
2223 2222
2224 FilePath dir; 2223 FilePath dir;
2225 PathService::Get(base::DIR_EXE, &dir); 2224 PathService::Get(base::DIR_EXE, &dir);
2226 file_util::SetCurrentDirectory(dir); 2225 file_util::SetCurrentDirectory(dir);
2227 2226
2228 scoped_refptr<UploadData> upload_data(new UploadData); 2227 scoped_refptr<UploadData> upload_data(new UploadData);
2229 2228
2230 FilePath path; 2229 FilePath path;
2231 PathService::Get(base::DIR_SOURCE_ROOT, &path); 2230 PathService::Get(base::DIR_SOURCE_ROOT, &path);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2264 ASSERT_EQ(size, d.bytes_received()); 2263 ASSERT_EQ(size, d.bytes_received());
2265 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size)); 2264 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size));
2266 } 2265 }
2267 } 2266 }
2268 2267
2269 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { 2268 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) {
2270 ASSERT_TRUE(test_server_.Start()); 2269 ASSERT_TRUE(test_server_.Start());
2271 2270
2272 TestDelegate d; 2271 TestDelegate d;
2273 { 2272 {
2274 TestURLRequest r(test_server_.GetURL("echo"), &d); 2273 URLRequest r(test_server_.GetURL("echo"), &d);
2275 r.set_context(default_context_); 2274 r.set_context(&default_context_);
2276 r.EnableChunkedUpload(); 2275 r.EnableChunkedUpload();
2277 r.set_method("POST"); 2276 r.set_method("POST");
2278 AddChunksToUpload(&r); 2277 AddChunksToUpload(&r);
2279 r.Start(); 2278 r.Start();
2280 EXPECT_TRUE(r.is_pending()); 2279 EXPECT_TRUE(r.is_pending());
2281 2280
2282 MessageLoop::current()->Run(); 2281 MessageLoop::current()->Run();
2283 2282
2284 VerifyReceivedDataMatchesChunks(&r, &d); 2283 VerifyReceivedDataMatchesChunks(&r, &d);
2285 } 2284 }
2286 } 2285 }
2287 2286
2288 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { 2287 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) {
2289 ASSERT_TRUE(test_server_.Start()); 2288 ASSERT_TRUE(test_server_.Start());
2290 2289
2291 TestDelegate d; 2290 TestDelegate d;
2292 { 2291 {
2293 TestURLRequest r(test_server_.GetURL("echo"), &d); 2292 URLRequest r(test_server_.GetURL("echo"), &d);
2294 r.set_context(default_context_); 2293 r.set_context(&default_context_);
2295 r.EnableChunkedUpload(); 2294 r.EnableChunkedUpload();
2296 r.set_method("POST"); 2295 r.set_method("POST");
2297 r.Start(); 2296 r.Start();
2298 EXPECT_TRUE(r.is_pending()); 2297 EXPECT_TRUE(r.is_pending());
2299 2298
2300 MessageLoop::current()->RunAllPending(); 2299 MessageLoop::current()->RunAllPending();
2301 AddChunksToUpload(&r); 2300 AddChunksToUpload(&r);
2302 MessageLoop::current()->Run(); 2301 MessageLoop::current()->Run();
2303 2302
2304 VerifyReceivedDataMatchesChunks(&r, &d); 2303 VerifyReceivedDataMatchesChunks(&r, &d);
2305 } 2304 }
2306 } 2305 }
2307 2306
2308 TEST_F(URLRequestTest, AboutBlankTest) { 2307 TEST_F(URLRequestTest, AboutBlankTest) {
2309 TestDelegate d; 2308 TestDelegate d;
2310 { 2309 {
2311 TestURLRequest r(GURL("about:blank"), &d); 2310 URLRequest r(GURL("about:blank"), &d);
2312 r.set_context(default_context_); 2311 r.set_context(&default_context_);
2313 2312
2314 r.Start(); 2313 r.Start();
2315 EXPECT_TRUE(r.is_pending()); 2314 EXPECT_TRUE(r.is_pending());
2316 2315
2317 MessageLoop::current()->Run(); 2316 MessageLoop::current()->Run();
2318 2317
2319 EXPECT_TRUE(!r.is_pending()); 2318 EXPECT_TRUE(!r.is_pending());
2320 EXPECT_FALSE(d.received_data_before_response()); 2319 EXPECT_FALSE(d.received_data_before_response());
2321 EXPECT_EQ(d.bytes_received(), 0); 2320 EXPECT_EQ(d.bytes_received(), 0);
2322 EXPECT_EQ("", r.GetSocketAddress().host()); 2321 EXPECT_EQ("", r.GetSocketAddress().host());
2323 EXPECT_EQ(0, r.GetSocketAddress().port()); 2322 EXPECT_EQ(0, r.GetSocketAddress().port());
2324 } 2323 }
2325 } 2324 }
2326 2325
2327 TEST_F(URLRequestTest, DataURLImageTest) { 2326 TEST_F(URLRequestTest, DataURLImageTest) {
2328 TestDelegate d; 2327 TestDelegate d;
2329 { 2328 {
2330 // Use our nice little Chrome logo. 2329 // Use our nice little Chrome logo.
2331 TestURLRequest r(GURL( 2330 URLRequest r(GURL(
2332 "data:image/png;base64," 2331 "data:image/png;base64,"
2333 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3" 2332 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3"
2334 "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD" 2333 "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD"
2335 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/P827vnucRmYN0gyF01GI5MpCVdW0gO7t" 2334 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/P827vnucRmYN0gyF01GI5MpCVdW0gO7t"
2336 "vNC+vqSEtbZefk5NuLv1jdJ46p/zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9" 2335 "vNC+vqSEtbZefk5NuLv1jdJ46p/zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9"
2337 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/MWq12UctI1" 2336 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/MWq12UctI1"
2338 "dWWm99ypqSYmRUBdKem8MkrO/kgaTt1O7YzlpzE5GIVd0WYUqt57yWf2McHTObYPbVD+Z" 2337 "dWWm99ypqSYmRUBdKem8MkrO/kgaTt1O7YzlpzE5GIVd0WYUqt57yWf2McHTObYPbVD+Z"
2339 "wbtlLTVMZ3BW+TnLyXLaWtmEq6WJVbT3HBh3Svj2HQQcm43XwmtoYM6vVKleh0uoWvnzW" 2338 "wbtlLTVMZ3BW+TnLyXLaWtmEq6WJVbT3HBh3Svj2HQQcm43XwmtoYM6vVKleh0uoWvnzW"
2340 "3v3MpidruPTQPf0bia7sJOtBM0ufTWNvus/nkDFHF9ZS+uYVjRUasMeHUmyLYtcklTvzW" 2339 "3v3MpidruPTQPf0bia7sJOtBM0ufTWNvus/nkDFHF9ZS+uYVjRUasMeHUmyLYtcklTvzW"
2341 "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4IoyhTb" 2340 "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4IoyhTb"
2342 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5" 2341 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5"
2343 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV" 2342 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV"
2344 "Md6q5c8GdosynKmSeRuGzpjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq" 2343 "Md6q5c8GdosynKmSeRuGzpjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq"
2345 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7F" 2344 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7F"
2346 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB" 2345 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB"
2347 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM" 2346 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM"
2348 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" 2347 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm"
2349 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En" 2348 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En"
2350 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), 2349 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="),
2351 &d); 2350 &d);
2352 r.set_context(default_context_); 2351 r.set_context(&default_context_);
2353 2352
2354 r.Start(); 2353 r.Start();
2355 EXPECT_TRUE(r.is_pending()); 2354 EXPECT_TRUE(r.is_pending());
2356 2355
2357 MessageLoop::current()->Run(); 2356 MessageLoop::current()->Run();
2358 2357
2359 EXPECT_TRUE(!r.is_pending()); 2358 EXPECT_TRUE(!r.is_pending());
2360 EXPECT_FALSE(d.received_data_before_response()); 2359 EXPECT_FALSE(d.received_data_before_response());
2361 EXPECT_EQ(d.bytes_received(), 911); 2360 EXPECT_EQ(d.bytes_received(), 911);
2362 EXPECT_EQ("", r.GetSocketAddress().host()); 2361 EXPECT_EQ("", r.GetSocketAddress().host());
2363 EXPECT_EQ(0, r.GetSocketAddress().port()); 2362 EXPECT_EQ(0, r.GetSocketAddress().port());
2364 } 2363 }
2365 } 2364 }
2366 2365
2367 TEST_F(URLRequestTest, FileTest) { 2366 TEST_F(URLRequestTest, FileTest) {
2368 FilePath app_path; 2367 FilePath app_path;
2369 PathService::Get(base::FILE_EXE, &app_path); 2368 PathService::Get(base::FILE_EXE, &app_path);
2370 GURL app_url = FilePathToFileURL(app_path); 2369 GURL app_url = FilePathToFileURL(app_path);
2371 2370
2372 TestDelegate d; 2371 TestDelegate d;
2373 { 2372 {
2374 TestURLRequest r(app_url, &d); 2373 URLRequest r(app_url, &d);
2375 r.set_context(default_context_); 2374 r.set_context(&default_context_);
2376 2375
2377 r.Start(); 2376 r.Start();
2378 EXPECT_TRUE(r.is_pending()); 2377 EXPECT_TRUE(r.is_pending());
2379 2378
2380 MessageLoop::current()->Run(); 2379 MessageLoop::current()->Run();
2381 2380
2382 int64 file_size = -1; 2381 int64 file_size = -1;
2383 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size)); 2382 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size));
2384 2383
2385 EXPECT_TRUE(!r.is_pending()); 2384 EXPECT_TRUE(!r.is_pending());
(...skipping 19 matching lines...) Expand all
2405 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); 2404 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size));
2406 2405
2407 const size_t first_byte_position = 500; 2406 const size_t first_byte_position = 500;
2408 const size_t last_byte_position = buffer_size - first_byte_position; 2407 const size_t last_byte_position = buffer_size - first_byte_position;
2409 const size_t content_length = last_byte_position - first_byte_position + 1; 2408 const size_t content_length = last_byte_position - first_byte_position + 1;
2410 std::string partial_buffer_string(buffer.get() + first_byte_position, 2409 std::string partial_buffer_string(buffer.get() + first_byte_position,
2411 buffer.get() + last_byte_position + 1); 2410 buffer.get() + last_byte_position + 1);
2412 2411
2413 TestDelegate d; 2412 TestDelegate d;
2414 { 2413 {
2415 TestURLRequest r(temp_url, &d); 2414 URLRequest r(temp_url, &d);
2416 r.set_context(default_context_); 2415 r.set_context(&default_context_);
2417 2416
2418 HttpRequestHeaders headers; 2417 HttpRequestHeaders headers;
2419 headers.SetHeader(HttpRequestHeaders::kRange, 2418 headers.SetHeader(HttpRequestHeaders::kRange,
2420 base::StringPrintf( 2419 base::StringPrintf(
2421 "bytes=%" PRIuS "-%" PRIuS, 2420 "bytes=%" PRIuS "-%" PRIuS,
2422 first_byte_position, last_byte_position)); 2421 first_byte_position, last_byte_position));
2423 r.SetExtraRequestHeaders(headers); 2422 r.SetExtraRequestHeaders(headers);
2424 r.Start(); 2423 r.Start();
2425 EXPECT_TRUE(r.is_pending()); 2424 EXPECT_TRUE(r.is_pending());
2426 2425
(...skipping 23 matching lines...) Expand all
2450 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); 2449 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size));
2451 2450
2452 const size_t first_byte_position = 500; 2451 const size_t first_byte_position = 500;
2453 const size_t last_byte_position = buffer_size - 1; 2452 const size_t last_byte_position = buffer_size - 1;
2454 const size_t content_length = last_byte_position - first_byte_position + 1; 2453 const size_t content_length = last_byte_position - first_byte_position + 1;
2455 std::string partial_buffer_string(buffer.get() + first_byte_position, 2454 std::string partial_buffer_string(buffer.get() + first_byte_position,
2456 buffer.get() + last_byte_position + 1); 2455 buffer.get() + last_byte_position + 1);
2457 2456
2458 TestDelegate d; 2457 TestDelegate d;
2459 { 2458 {
2460 TestURLRequest r(temp_url, &d); 2459 URLRequest r(temp_url, &d);
2461 r.set_context(default_context_); 2460 r.set_context(&default_context_);
2462 2461
2463 HttpRequestHeaders headers; 2462 HttpRequestHeaders headers;
2464 headers.SetHeader(HttpRequestHeaders::kRange, 2463 headers.SetHeader(HttpRequestHeaders::kRange,
2465 base::StringPrintf("bytes=%" PRIuS "-", 2464 base::StringPrintf("bytes=%" PRIuS "-",
2466 first_byte_position)); 2465 first_byte_position));
2467 r.SetExtraRequestHeaders(headers); 2466 r.SetExtraRequestHeaders(headers);
2468 r.Start(); 2467 r.Start();
2469 EXPECT_TRUE(r.is_pending()); 2468 EXPECT_TRUE(r.is_pending());
2470 2469
2471 MessageLoop::current()->Run(); 2470 MessageLoop::current()->Run();
(...skipping 16 matching lines...) Expand all
2488 FilePath temp_path; 2487 FilePath temp_path;
2489 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); 2488 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path));
2490 GURL temp_url = FilePathToFileURL(temp_path); 2489 GURL temp_url = FilePathToFileURL(temp_path);
2491 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); 2490 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size));
2492 2491
2493 int64 file_size; 2492 int64 file_size;
2494 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); 2493 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size));
2495 2494
2496 TestDelegate d; 2495 TestDelegate d;
2497 { 2496 {
2498 TestURLRequest r(temp_url, &d); 2497 URLRequest r(temp_url, &d);
2499 r.set_context(default_context_); 2498 r.set_context(&default_context_);
2500 2499
2501 HttpRequestHeaders headers; 2500 HttpRequestHeaders headers;
2502 headers.SetHeader(HttpRequestHeaders::kRange, 2501 headers.SetHeader(HttpRequestHeaders::kRange,
2503 "bytes=0-0,10-200,200-300"); 2502 "bytes=0-0,10-200,200-300");
2504 r.SetExtraRequestHeaders(headers); 2503 r.SetExtraRequestHeaders(headers);
2505 r.Start(); 2504 r.Start();
2506 EXPECT_TRUE(r.is_pending()); 2505 EXPECT_TRUE(r.is_pending());
2507 2506
2508 MessageLoop::current()->Run(); 2507 MessageLoop::current()->Run();
2509 EXPECT_TRUE(d.request_failed()); 2508 EXPECT_TRUE(d.request_failed());
2510 } 2509 }
2511 2510
2512 EXPECT_TRUE(file_util::Delete(temp_path, false)); 2511 EXPECT_TRUE(file_util::Delete(temp_path, false));
2513 } 2512 }
2514 2513
2515 TEST_F(URLRequestTest, InvalidUrlTest) { 2514 TEST_F(URLRequestTest, InvalidUrlTest) {
2516 TestDelegate d; 2515 TestDelegate d;
2517 { 2516 {
2518 TestURLRequest r(GURL("invalid url"), &d); 2517 URLRequest r(GURL("invalid url"), &d);
2519 r.set_context(default_context_); 2518 r.set_context(&default_context_);
2520 2519
2521 r.Start(); 2520 r.Start();
2522 EXPECT_TRUE(r.is_pending()); 2521 EXPECT_TRUE(r.is_pending());
2523 2522
2524 MessageLoop::current()->Run(); 2523 MessageLoop::current()->Run();
2525 EXPECT_TRUE(d.request_failed()); 2524 EXPECT_TRUE(d.request_failed());
2526 } 2525 }
2527 } 2526 }
2528 2527
2529 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { 2528 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) {
2530 ASSERT_TRUE(test_server_.Start()); 2529 ASSERT_TRUE(test_server_.Start());
2531 2530
2532 TestDelegate d; 2531 TestDelegate d;
2533 TestURLRequest req(test_server_.GetURL("files/with-headers.html"), &d); 2532 URLRequest req(test_server_.GetURL("files/with-headers.html"), &d);
2534 req.set_context(default_context_); 2533 req.set_context(&default_context_);
2535 req.Start(); 2534 req.Start();
2536 MessageLoop::current()->Run(); 2535 MessageLoop::current()->Run();
2537 2536
2538 const HttpResponseHeaders* headers = req.response_headers(); 2537 const HttpResponseHeaders* headers = req.response_headers();
2539 2538
2540 // Simple sanity check that response_info() accesses the same data. 2539 // Simple sanity check that response_info() accesses the same data.
2541 EXPECT_EQ(headers, req.response_info().headers.get()); 2540 EXPECT_EQ(headers, req.response_info().headers.get());
2542 2541
2543 std::string header; 2542 std::string header;
2544 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); 2543 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2585 EXPECT_TRUE(SUCCEEDED(result)); 2584 EXPECT_TRUE(SUCCEEDED(result));
2586 result = persist->Save(lnk_path.c_str(), TRUE); 2585 result = persist->Save(lnk_path.c_str(), TRUE);
2587 EXPECT_TRUE(SUCCEEDED(result)); 2586 EXPECT_TRUE(SUCCEEDED(result));
2588 if (persist) 2587 if (persist)
2589 persist->Release(); 2588 persist->Release();
2590 if (shell) 2589 if (shell)
2591 shell->Release(); 2590 shell->Release();
2592 2591
2593 TestDelegate d; 2592 TestDelegate d;
2594 { 2593 {
2595 TestURLRequest r(FilePathToFileURL(FilePath(lnk_path)), &d); 2594 URLRequest r(FilePathToFileURL(FilePath(lnk_path)), &d);
2596 r.set_context(default_context_); 2595 r.set_context(&default_context_);
2597 2596
2598 r.Start(); 2597 r.Start();
2599 EXPECT_TRUE(r.is_pending()); 2598 EXPECT_TRUE(r.is_pending());
2600 2599
2601 MessageLoop::current()->Run(); 2600 MessageLoop::current()->Run();
2602 2601
2603 WIN32_FILE_ATTRIBUTE_DATA data; 2602 WIN32_FILE_ATTRIBUTE_DATA data;
2604 GetFileAttributesEx(app_path.value().c_str(), 2603 GetFileAttributesEx(app_path.value().c_str(),
2605 GetFileExInfoStandard, &data); 2604 GetFileExInfoStandard, &data);
2606 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, 2605 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ,
(...skipping 16 matching lines...) Expand all
2623 // Clean the shortcut 2622 // Clean the shortcut
2624 DeleteFile(lnk_path.c_str()); 2623 DeleteFile(lnk_path.c_str());
2625 CoUninitialize(); 2624 CoUninitialize();
2626 } 2625 }
2627 #endif // defined(OS_WIN) 2626 #endif // defined(OS_WIN)
2628 2627
2629 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { 2628 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) {
2630 ASSERT_TRUE(test_server_.Start()); 2629 ASSERT_TRUE(test_server_.Start());
2631 2630
2632 TestDelegate d; 2631 TestDelegate d;
2633 TestURLRequest req(test_server_.GetURL( 2632 URLRequest req(test_server_.GetURL(
2634 "files/content-type-normalization.html"), &d); 2633 "files/content-type-normalization.html"), &d);
2635 req.set_context(default_context_); 2634 req.set_context(&default_context_);
2636 req.Start(); 2635 req.Start();
2637 MessageLoop::current()->Run(); 2636 MessageLoop::current()->Run();
2638 2637
2639 std::string mime_type; 2638 std::string mime_type;
2640 req.GetMimeType(&mime_type); 2639 req.GetMimeType(&mime_type);
2641 EXPECT_EQ("text/html", mime_type); 2640 EXPECT_EQ("text/html", mime_type);
2642 2641
2643 std::string charset; 2642 std::string charset;
2644 req.GetCharset(&charset); 2643 req.GetCharset(&charset);
2645 EXPECT_EQ("utf-8", charset); 2644 EXPECT_EQ("utf-8", charset);
2646 req.Cancel(); 2645 req.Cancel();
2647 } 2646 }
2648 2647
2649 TEST_F(URLRequestTest, FileDirCancelTest) { 2648 TEST_F(URLRequestTest, FileDirCancelTest) {
2650 // Put in mock resource provider. 2649 // Put in mock resource provider.
2651 NetModule::SetResourceProvider(TestNetResourceProvider); 2650 NetModule::SetResourceProvider(TestNetResourceProvider);
2652 2651
2653 TestDelegate d; 2652 TestDelegate d;
2654 { 2653 {
2655 FilePath file_path; 2654 FilePath file_path;
2656 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); 2655 PathService::Get(base::DIR_SOURCE_ROOT, &file_path);
2657 file_path = file_path.Append(FILE_PATH_LITERAL("net")); 2656 file_path = file_path.Append(FILE_PATH_LITERAL("net"));
2658 file_path = file_path.Append(FILE_PATH_LITERAL("data")); 2657 file_path = file_path.Append(FILE_PATH_LITERAL("data"));
2659 2658
2660 TestURLRequest req(FilePathToFileURL(file_path), &d); 2659 URLRequest req(FilePathToFileURL(file_path), &d);
2661 req.set_context(default_context_); 2660 req.set_context(&default_context_);
2662 req.Start(); 2661 req.Start();
2663 EXPECT_TRUE(req.is_pending()); 2662 EXPECT_TRUE(req.is_pending());
2664 2663
2665 d.set_cancel_in_received_data_pending(true); 2664 d.set_cancel_in_received_data_pending(true);
2666 2665
2667 MessageLoop::current()->Run(); 2666 MessageLoop::current()->Run();
2668 } 2667 }
2669 2668
2670 // Take out mock resource provider. 2669 // Take out mock resource provider.
2671 NetModule::SetResourceProvider(NULL); 2670 NetModule::SetResourceProvider(NULL);
2672 } 2671 }
2673 2672
2674 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { 2673 TEST_F(URLRequestTest, FileDirRedirectNoCrash) {
2675 // There is an implicit redirect when loading a file path that matches a 2674 // There is an implicit redirect when loading a file path that matches a
2676 // directory and does not end with a slash. Ensure that following such 2675 // directory and does not end with a slash. Ensure that following such
2677 // redirects does not crash. See http://crbug.com/18686. 2676 // redirects does not crash. See http://crbug.com/18686.
2678 2677
2679 FilePath path; 2678 FilePath path;
2680 PathService::Get(base::DIR_SOURCE_ROOT, &path); 2679 PathService::Get(base::DIR_SOURCE_ROOT, &path);
2681 path = path.Append(FILE_PATH_LITERAL("net")); 2680 path = path.Append(FILE_PATH_LITERAL("net"));
2682 path = path.Append(FILE_PATH_LITERAL("data")); 2681 path = path.Append(FILE_PATH_LITERAL("data"));
2683 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); 2682 path = path.Append(FILE_PATH_LITERAL("url_request_unittest"));
2684 2683
2685 TestDelegate d; 2684 TestDelegate d;
2686 TestURLRequest req(FilePathToFileURL(path), &d); 2685 URLRequest req(FilePathToFileURL(path), &d);
2687 req.set_context(default_context_); 2686 req.set_context(&default_context_);
2688 req.Start(); 2687 req.Start();
2689 MessageLoop::current()->Run(); 2688 MessageLoop::current()->Run();
2690 2689
2691 ASSERT_EQ(1, d.received_redirect_count()); 2690 ASSERT_EQ(1, d.received_redirect_count());
2692 ASSERT_LT(0, d.bytes_received()); 2691 ASSERT_LT(0, d.bytes_received());
2693 ASSERT_FALSE(d.request_failed()); 2692 ASSERT_FALSE(d.request_failed());
2694 ASSERT_TRUE(req.status().is_success()); 2693 ASSERT_TRUE(req.status().is_success());
2695 } 2694 }
2696 2695
2697 #if defined(OS_WIN) 2696 #if defined(OS_WIN)
2698 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. 2697 // Don't accept the url "file:///" on windows. See http://crbug.com/1474.
2699 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { 2698 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) {
2700 TestDelegate d; 2699 TestDelegate d;
2701 TestURLRequest req(GURL("file:///"), &d); 2700 URLRequest req(GURL("file:///"), &d);
2702 req.set_context(default_context_); 2701 req.set_context(&default_context_);
2703 req.Start(); 2702 req.Start();
2704 MessageLoop::current()->Run(); 2703 MessageLoop::current()->Run();
2705 2704
2706 ASSERT_EQ(1, d.received_redirect_count()); 2705 ASSERT_EQ(1, d.received_redirect_count());
2707 ASSERT_FALSE(req.status().is_success()); 2706 ASSERT_FALSE(req.status().is_success());
2708 } 2707 }
2709 #endif 2708 #endif
2710 2709
2711 TEST_F(URLRequestTestHTTP, RestrictRedirects) { 2710 TEST_F(URLRequestTestHTTP, RestrictRedirects) {
2712 ASSERT_TRUE(test_server_.Start()); 2711 ASSERT_TRUE(test_server_.Start());
2713 2712
2714 TestDelegate d; 2713 TestDelegate d;
2715 TestURLRequest req(test_server_.GetURL( 2714 URLRequest req(test_server_.GetURL(
2716 "files/redirect-to-file.html"), &d); 2715 "files/redirect-to-file.html"), &d);
2717 req.set_context(default_context_); 2716 req.set_context(&default_context_);
2718 req.Start(); 2717 req.Start();
2719 MessageLoop::current()->Run(); 2718 MessageLoop::current()->Run();
2720 2719
2721 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); 2720 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status());
2722 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); 2721 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error());
2723 } 2722 }
2724 2723
2725 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { 2724 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) {
2726 ASSERT_TRUE(test_server_.Start()); 2725 ASSERT_TRUE(test_server_.Start());
2727 2726
2728 TestDelegate d; 2727 TestDelegate d;
2729 TestURLRequest req(test_server_.GetURL( 2728 URLRequest req(test_server_.GetURL(
2730 "files/redirect-to-invalid-url.html"), &d); 2729 "files/redirect-to-invalid-url.html"), &d);
2731 req.set_context(default_context_); 2730 req.set_context(&default_context_);
2732 req.Start(); 2731 req.Start();
2733 MessageLoop::current()->Run(); 2732 MessageLoop::current()->Run();
2734 2733
2735 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); 2734 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status());
2736 EXPECT_EQ(ERR_INVALID_URL, req.status().error()); 2735 EXPECT_EQ(ERR_INVALID_URL, req.status().error());
2737 } 2736 }
2738 2737
2739 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { 2738 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) {
2740 ASSERT_TRUE(test_server_.Start()); 2739 ASSERT_TRUE(test_server_.Start());
2741 2740
2742 TestDelegate d; 2741 TestDelegate d;
2743 TestURLRequest req(test_server_.GetURL("echoheader?Referer"), &d); 2742 URLRequest req(test_server_.GetURL("echoheader?Referer"), &d);
2744 req.set_context(default_context_); 2743 req.set_context(&default_context_);
2745 req.set_referrer("http://user:pass@foo.com/"); 2744 req.set_referrer("http://user:pass@foo.com/");
2746 req.Start(); 2745 req.Start();
2747 MessageLoop::current()->Run(); 2746 MessageLoop::current()->Run();
2748 2747
2749 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); 2748 EXPECT_EQ(std::string("http://foo.com/"), d.data_received());
2750 } 2749 }
2751 2750
2752 TEST_F(URLRequestTestHTTP, CancelRedirect) { 2751 TEST_F(URLRequestTestHTTP, CancelRedirect) {
2753 ASSERT_TRUE(test_server_.Start()); 2752 ASSERT_TRUE(test_server_.Start());
2754 2753
2755 TestDelegate d; 2754 TestDelegate d;
2756 { 2755 {
2757 d.set_cancel_in_received_redirect(true); 2756 d.set_cancel_in_received_redirect(true);
2758 TestURLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); 2757 URLRequest req(test_server_.GetURL("files/redirect-test.html"), &d);
2759 req.set_context(default_context_); 2758 req.set_context(&default_context_);
2760 req.Start(); 2759 req.Start();
2761 MessageLoop::current()->Run(); 2760 MessageLoop::current()->Run();
2762 2761
2763 EXPECT_EQ(1, d.response_started_count()); 2762 EXPECT_EQ(1, d.response_started_count());
2764 EXPECT_EQ(0, d.bytes_received()); 2763 EXPECT_EQ(0, d.bytes_received());
2765 EXPECT_FALSE(d.received_data_before_response()); 2764 EXPECT_FALSE(d.received_data_before_response());
2766 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 2765 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status());
2767 } 2766 }
2768 } 2767 }
2769 2768
2770 TEST_F(URLRequestTestHTTP, DeferredRedirect) { 2769 TEST_F(URLRequestTestHTTP, DeferredRedirect) {
2771 ASSERT_TRUE(test_server_.Start()); 2770 ASSERT_TRUE(test_server_.Start());
2772 2771
2773 TestDelegate d; 2772 TestDelegate d;
2774 { 2773 {
2775 d.set_quit_on_redirect(true); 2774 d.set_quit_on_redirect(true);
2776 TestURLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); 2775 URLRequest req(test_server_.GetURL("files/redirect-test.html"), &d);
2777 req.set_context(default_context_); 2776 req.set_context(&default_context_);
2778 req.Start(); 2777 req.Start();
2779 MessageLoop::current()->Run(); 2778 MessageLoop::current()->Run();
2780 2779
2781 EXPECT_EQ(1, d.received_redirect_count()); 2780 EXPECT_EQ(1, d.received_redirect_count());
2782 2781
2783 req.FollowDeferredRedirect(); 2782 req.FollowDeferredRedirect();
2784 MessageLoop::current()->Run(); 2783 MessageLoop::current()->Run();
2785 2784
2786 EXPECT_EQ(1, d.response_started_count()); 2785 EXPECT_EQ(1, d.response_started_count());
2787 EXPECT_FALSE(d.received_data_before_response()); 2786 EXPECT_FALSE(d.received_data_before_response());
(...skipping 11 matching lines...) Expand all
2799 EXPECT_EQ(contents, d.data_received()); 2798 EXPECT_EQ(contents, d.data_received());
2800 } 2799 }
2801 } 2800 }
2802 2801
2803 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { 2802 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) {
2804 ASSERT_TRUE(test_server_.Start()); 2803 ASSERT_TRUE(test_server_.Start());
2805 2804
2806 TestDelegate d; 2805 TestDelegate d;
2807 { 2806 {
2808 d.set_quit_on_redirect(true); 2807 d.set_quit_on_redirect(true);
2809 TestURLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); 2808 URLRequest req(test_server_.GetURL("files/redirect-test.html"), &d);
2810 req.set_context(default_context_); 2809 req.set_context(&default_context_);
2811 req.Start(); 2810 req.Start();
2812 MessageLoop::current()->Run(); 2811 MessageLoop::current()->Run();
2813 2812
2814 EXPECT_EQ(1, d.received_redirect_count()); 2813 EXPECT_EQ(1, d.received_redirect_count());
2815 2814
2816 req.Cancel(); 2815 req.Cancel();
2817 MessageLoop::current()->Run(); 2816 MessageLoop::current()->Run();
2818 2817
2819 EXPECT_EQ(1, d.response_started_count()); 2818 EXPECT_EQ(1, d.response_started_count());
2820 EXPECT_EQ(0, d.bytes_received()); 2819 EXPECT_EQ(0, d.bytes_received());
2821 EXPECT_FALSE(d.received_data_before_response()); 2820 EXPECT_FALSE(d.received_data_before_response());
2822 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 2821 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status());
2823 } 2822 }
2824 } 2823 }
2825 2824
2826 TEST_F(URLRequestTestHTTP, VaryHeader) { 2825 TEST_F(URLRequestTestHTTP, VaryHeader) {
2827 ASSERT_TRUE(test_server_.Start()); 2826 ASSERT_TRUE(test_server_.Start());
2828 2827
2829 // populate the cache 2828 // populate the cache
2830 { 2829 {
2831 TestDelegate d; 2830 TestDelegate d;
2832 URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d); 2831 URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d);
2833 req.set_context(default_context_); 2832 req.set_context(&default_context_);
2834 HttpRequestHeaders headers; 2833 HttpRequestHeaders headers;
2835 headers.SetHeader("foo", "1"); 2834 headers.SetHeader("foo", "1");
2836 req.SetExtraRequestHeaders(headers); 2835 req.SetExtraRequestHeaders(headers);
2837 req.Start(); 2836 req.Start();
2838 MessageLoop::current()->Run(); 2837 MessageLoop::current()->Run();
2839 } 2838 }
2840 2839
2841 // expect a cache hit 2840 // expect a cache hit
2842 { 2841 {
2843 TestDelegate d; 2842 TestDelegate d;
2844 URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d); 2843 URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d);
2845 req.set_context(default_context_); 2844 req.set_context(&default_context_);
2846 HttpRequestHeaders headers; 2845 HttpRequestHeaders headers;
2847 headers.SetHeader("foo", "1"); 2846 headers.SetHeader("foo", "1");
2848 req.SetExtraRequestHeaders(headers); 2847 req.SetExtraRequestHeaders(headers);
2849 req.Start(); 2848 req.Start();
2850 MessageLoop::current()->Run(); 2849 MessageLoop::current()->Run();
2851 2850
2852 EXPECT_TRUE(req.was_cached()); 2851 EXPECT_TRUE(req.was_cached());
2853 } 2852 }
2854 2853
2855 // expect a cache miss 2854 // expect a cache miss
2856 { 2855 {
2857 TestDelegate d; 2856 TestDelegate d;
2858 URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d); 2857 URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d);
2859 req.set_context(default_context_); 2858 req.set_context(&default_context_);
2860 HttpRequestHeaders headers; 2859 HttpRequestHeaders headers;
2861 headers.SetHeader("foo", "2"); 2860 headers.SetHeader("foo", "2");
2862 req.SetExtraRequestHeaders(headers); 2861 req.SetExtraRequestHeaders(headers);
2863 req.Start(); 2862 req.Start();
2864 MessageLoop::current()->Run(); 2863 MessageLoop::current()->Run();
2865 2864
2866 EXPECT_FALSE(req.was_cached()); 2865 EXPECT_FALSE(req.was_cached());
2867 } 2866 }
2868 } 2867 }
2869 2868
2870 TEST_F(URLRequestTestHTTP, BasicAuth) { 2869 TEST_F(URLRequestTestHTTP, BasicAuth) {
2871 ASSERT_TRUE(test_server_.Start()); 2870 ASSERT_TRUE(test_server_.Start());
2872 2871
2873 // populate the cache 2872 // populate the cache
2874 { 2873 {
2875 TestDelegate d; 2874 TestDelegate d;
2876 d.set_credentials(AuthCredentials(kUser, kSecret)); 2875 d.set_credentials(AuthCredentials(kUser, kSecret));
2877 2876
2878 URLRequest r(test_server_.GetURL("auth-basic"), &d); 2877 URLRequest r(test_server_.GetURL("auth-basic"), &d);
2879 r.set_context(default_context_); 2878 r.set_context(&default_context_);
2880 r.Start(); 2879 r.Start();
2881 2880
2882 MessageLoop::current()->Run(); 2881 MessageLoop::current()->Run();
2883 2882
2884 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 2883 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
2885 } 2884 }
2886 2885
2887 // repeat request with end-to-end validation. since auth-basic results in a 2886 // repeat request with end-to-end validation. since auth-basic results in a
2888 // cachable page, we expect this test to result in a 304. in which case, the 2887 // cachable page, we expect this test to result in a 304. in which case, the
2889 // response should be fetched from the cache. 2888 // response should be fetched from the cache.
2890 { 2889 {
2891 TestDelegate d; 2890 TestDelegate d;
2892 d.set_credentials(AuthCredentials(kUser, kSecret)); 2891 d.set_credentials(AuthCredentials(kUser, kSecret));
2893 2892
2894 URLRequest r(test_server_.GetURL("auth-basic"), &d); 2893 URLRequest r(test_server_.GetURL("auth-basic"), &d);
2895 r.set_context(default_context_); 2894 r.set_context(&default_context_);
2896 r.set_load_flags(LOAD_VALIDATE_CACHE); 2895 r.set_load_flags(LOAD_VALIDATE_CACHE);
2897 r.Start(); 2896 r.Start();
2898 2897
2899 MessageLoop::current()->Run(); 2898 MessageLoop::current()->Run();
2900 2899
2901 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 2900 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
2902 2901
2903 // Should be the same cached document. 2902 // Should be the same cached document.
2904 EXPECT_TRUE(r.was_cached()); 2903 EXPECT_TRUE(r.was_cached());
2905 } 2904 }
2906 } 2905 }
2907 2906
2908 // Check that Set-Cookie headers in 401 responses are respected. 2907 // Check that Set-Cookie headers in 401 responses are respected.
2909 // http://crbug.com/6450 2908 // http://crbug.com/6450
2910 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { 2909 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) {
2911 ASSERT_TRUE(test_server_.Start()); 2910 ASSERT_TRUE(test_server_.Start());
2912 2911
2913 GURL url_requiring_auth = 2912 GURL url_requiring_auth =
2914 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); 2913 test_server_.GetURL("auth-basic?set-cookie-if-challenged");
2915 2914
2916 // Request a page that will give a 401 containing a Set-Cookie header. 2915 // Request a page that will give a 401 containing a Set-Cookie header.
2917 // Verify that when the transaction is restarted, it includes the new cookie. 2916 // Verify that when the transaction is restarted, it includes the new cookie.
2918 { 2917 {
2919 TestNetworkDelegate network_delegate; // must outlive URLRequest 2918 TestNetworkDelegate network_delegate; // must outlive URLRequest
2920 scoped_refptr<TestURLRequestContext> context( 2919 TestURLRequestContext context(true);
2921 new TestURLRequestContext(true)); 2920 context.set_network_delegate(&network_delegate);
2922 context->set_network_delegate(&network_delegate); 2921 context.Init();
2923 context->Init();
2924 2922
2925 TestDelegate d; 2923 TestDelegate d;
2926 d.set_credentials(AuthCredentials(kUser, kSecret)); 2924 d.set_credentials(AuthCredentials(kUser, kSecret));
2927 2925
2928 URLRequest r(url_requiring_auth, &d); 2926 URLRequest r(url_requiring_auth, &d);
2929 r.set_context(context); 2927 r.set_context(&context);
2930 r.Start(); 2928 r.Start();
2931 2929
2932 MessageLoop::current()->Run(); 2930 MessageLoop::current()->Run();
2933 2931
2934 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 2932 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
2935 2933
2936 // Make sure we sent the cookie in the restarted transaction. 2934 // Make sure we sent the cookie in the restarted transaction.
2937 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") 2935 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true")
2938 != std::string::npos); 2936 != std::string::npos);
2939 } 2937 }
2940 } 2938 }
2941 2939
2942 TEST_F(URLRequestTest, DelayedCookieCallback) { 2940 TEST_F(URLRequestTest, DelayedCookieCallback) {
2943 LocalHttpTestServer test_server; 2941 LocalHttpTestServer test_server;
2944 ASSERT_TRUE(test_server.Start()); 2942 ASSERT_TRUE(test_server.Start());
2945 2943
2946 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); 2944 TestURLRequestContext context;
2947 scoped_refptr<DelayedCookieMonster> delayed_cm = 2945 scoped_refptr<DelayedCookieMonster> delayed_cm =
2948 new DelayedCookieMonster(); 2946 new DelayedCookieMonster();
2949 scoped_refptr<CookieStore> cookie_store = delayed_cm; 2947 scoped_refptr<CookieStore> cookie_store = delayed_cm;
2950 context->set_cookie_store(delayed_cm); 2948 context.set_cookie_store(delayed_cm);
2951 2949
2952 // Set up a cookie. 2950 // Set up a cookie.
2953 { 2951 {
2954 TestNetworkDelegate network_delegate; 2952 TestNetworkDelegate network_delegate;
2955 context->set_network_delegate(&network_delegate); 2953 context.set_network_delegate(&network_delegate);
2956 TestDelegate d; 2954 TestDelegate d;
2957 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); 2955 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d);
2958 req.set_context(context); 2956 req.set_context(&context);
2959 req.Start(); 2957 req.Start();
2960 MessageLoop::current()->Run(); 2958 MessageLoop::current()->Run();
2961 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2959 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2962 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2960 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2963 EXPECT_EQ(1, network_delegate.set_cookie_count()); 2961 EXPECT_EQ(1, network_delegate.set_cookie_count());
2964 } 2962 }
2965 2963
2966 // Verify that the cookie is set. 2964 // Verify that the cookie is set.
2967 { 2965 {
2968 TestNetworkDelegate network_delegate; 2966 TestNetworkDelegate network_delegate;
2969 context->set_network_delegate(&network_delegate); 2967 context.set_network_delegate(&network_delegate);
2970 TestDelegate d; 2968 TestDelegate d;
2971 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 2969 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
2972 req.set_context(context); 2970 req.set_context(&context);
2973 req.Start(); 2971 req.Start();
2974 MessageLoop::current()->Run(); 2972 MessageLoop::current()->Run();
2975 2973
2976 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 2974 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
2977 != std::string::npos); 2975 != std::string::npos);
2978 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2976 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2979 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2977 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2980 } 2978 }
2981 } 2979 }
2982 2980
2983 TEST_F(URLRequestTest, DoNotSendCookies) { 2981 TEST_F(URLRequestTest, DoNotSendCookies) {
2984 LocalHttpTestServer test_server; 2982 LocalHttpTestServer test_server;
2985 ASSERT_TRUE(test_server.Start()); 2983 ASSERT_TRUE(test_server.Start());
2986 2984
2987 // Set up a cookie. 2985 // Set up a cookie.
2988 { 2986 {
2989 TestNetworkDelegate network_delegate; 2987 TestNetworkDelegate network_delegate;
2990 default_context_->set_network_delegate(&network_delegate); 2988 default_context_.set_network_delegate(&network_delegate);
2991 TestDelegate d; 2989 TestDelegate d;
2992 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); 2990 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d);
2993 req.set_context(default_context_); 2991 req.set_context(&default_context_);
2994 req.Start(); 2992 req.Start();
2995 MessageLoop::current()->Run(); 2993 MessageLoop::current()->Run();
2996 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2994 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2997 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2995 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2998 } 2996 }
2999 2997
3000 // Verify that the cookie is set. 2998 // Verify that the cookie is set.
3001 { 2999 {
3002 TestNetworkDelegate network_delegate; 3000 TestNetworkDelegate network_delegate;
3003 default_context_->set_network_delegate(&network_delegate); 3001 default_context_.set_network_delegate(&network_delegate);
3004 TestDelegate d; 3002 TestDelegate d;
3005 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 3003 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
3006 req.set_context(default_context_); 3004 req.set_context(&default_context_);
3007 req.Start(); 3005 req.Start();
3008 MessageLoop::current()->Run(); 3006 MessageLoop::current()->Run();
3009 3007
3010 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 3008 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
3011 != std::string::npos); 3009 != std::string::npos);
3012 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3010 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3013 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3011 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3014 } 3012 }
3015 3013
3016 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. 3014 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set.
3017 { 3015 {
3018 TestNetworkDelegate network_delegate; 3016 TestNetworkDelegate network_delegate;
3019 default_context_->set_network_delegate(&network_delegate); 3017 default_context_.set_network_delegate(&network_delegate);
3020 TestDelegate d; 3018 TestDelegate d;
3021 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 3019 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
3022 req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES); 3020 req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES);
3023 req.set_context(default_context_); 3021 req.set_context(&default_context_);
3024 req.Start(); 3022 req.Start();
3025 MessageLoop::current()->Run(); 3023 MessageLoop::current()->Run();
3026 3024
3027 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 3025 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
3028 == std::string::npos); 3026 == std::string::npos);
3029 3027
3030 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. 3028 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies.
3031 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3029 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3032 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3030 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3033 } 3031 }
3034 3032
3035 default_context_->set_network_delegate(&default_network_delegate_); 3033 default_context_.set_network_delegate(&default_network_delegate_);
3036 } 3034 }
3037 3035
3038 TEST_F(URLRequestTest, DoNotSaveCookies) { 3036 TEST_F(URLRequestTest, DoNotSaveCookies) {
3039 LocalHttpTestServer test_server; 3037 LocalHttpTestServer test_server;
3040 ASSERT_TRUE(test_server.Start()); 3038 ASSERT_TRUE(test_server.Start());
3041 3039
3042 // Set up a cookie. 3040 // Set up a cookie.
3043 { 3041 {
3044 TestNetworkDelegate network_delegate; 3042 TestNetworkDelegate network_delegate;
3045 default_context_->set_network_delegate(&network_delegate); 3043 default_context_.set_network_delegate(&network_delegate);
3046 TestDelegate d; 3044 TestDelegate d;
3047 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); 3045 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d);
3048 req.set_context(default_context_); 3046 req.set_context(&default_context_);
3049 req.Start(); 3047 req.Start();
3050 MessageLoop::current()->Run(); 3048 MessageLoop::current()->Run();
3051 3049
3052 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3050 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3053 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3051 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3054 EXPECT_EQ(1, network_delegate.set_cookie_count()); 3052 EXPECT_EQ(1, network_delegate.set_cookie_count());
3055 } 3053 }
3056 3054
3057 // Try to set-up another cookie and update the previous cookie. 3055 // Try to set-up another cookie and update the previous cookie.
3058 { 3056 {
3059 TestNetworkDelegate network_delegate; 3057 TestNetworkDelegate network_delegate;
3060 default_context_->set_network_delegate(&network_delegate); 3058 default_context_.set_network_delegate(&network_delegate);
3061 TestDelegate d; 3059 TestDelegate d;
3062 URLRequest req(test_server.GetURL( 3060 URLRequest req(test_server.GetURL(
3063 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); 3061 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d);
3064 req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES); 3062 req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES);
3065 req.set_context(default_context_); 3063 req.set_context(&default_context_);
3066 req.Start(); 3064 req.Start();
3067 3065
3068 MessageLoop::current()->Run(); 3066 MessageLoop::current()->Run();
3069 3067
3070 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. 3068 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie.
3071 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3069 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3072 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3070 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3073 EXPECT_EQ(0, network_delegate.set_cookie_count()); 3071 EXPECT_EQ(0, network_delegate.set_cookie_count());
3074 } 3072 }
3075 3073
3076 // Verify the cookies weren't saved or updated. 3074 // Verify the cookies weren't saved or updated.
3077 { 3075 {
3078 TestNetworkDelegate network_delegate; 3076 TestNetworkDelegate network_delegate;
3079 default_context_->set_network_delegate(&network_delegate); 3077 default_context_.set_network_delegate(&network_delegate);
3080 TestDelegate d; 3078 TestDelegate d;
3081 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 3079 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
3082 req.set_context(default_context_); 3080 req.set_context(&default_context_);
3083 req.Start(); 3081 req.Start();
3084 MessageLoop::current()->Run(); 3082 MessageLoop::current()->Run();
3085 3083
3086 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 3084 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
3087 == std::string::npos); 3085 == std::string::npos);
3088 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 3086 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
3089 != std::string::npos); 3087 != std::string::npos);
3090 3088
3091 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3089 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3092 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3090 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3093 EXPECT_EQ(0, network_delegate.set_cookie_count()); 3091 EXPECT_EQ(0, network_delegate.set_cookie_count());
3094 } 3092 }
3095 3093
3096 default_context_->set_network_delegate(&default_network_delegate_); 3094 default_context_.set_network_delegate(&default_network_delegate_);
3097 } 3095 }
3098 3096
3099 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { 3097 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) {
3100 LocalHttpTestServer test_server; 3098 LocalHttpTestServer test_server;
3101 ASSERT_TRUE(test_server.Start()); 3099 ASSERT_TRUE(test_server.Start());
3102 3100
3103 // Set up a cookie. 3101 // Set up a cookie.
3104 { 3102 {
3105 TestNetworkDelegate network_delegate; 3103 TestNetworkDelegate network_delegate;
3106 default_context_->set_network_delegate(&network_delegate); 3104 default_context_.set_network_delegate(&network_delegate);
3107 TestDelegate d; 3105 TestDelegate d;
3108 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); 3106 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d);
3109 req.set_context(default_context_); 3107 req.set_context(&default_context_);
3110 req.Start(); 3108 req.Start();
3111 MessageLoop::current()->Run(); 3109 MessageLoop::current()->Run();
3112 3110
3113 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3111 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3114 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3112 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3115 } 3113 }
3116 3114
3117 // Verify that the cookie is set. 3115 // Verify that the cookie is set.
3118 { 3116 {
3119 TestNetworkDelegate network_delegate; 3117 TestNetworkDelegate network_delegate;
3120 default_context_->set_network_delegate(&network_delegate); 3118 default_context_.set_network_delegate(&network_delegate);
3121 TestDelegate d; 3119 TestDelegate d;
3122 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 3120 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
3123 req.set_context(default_context_); 3121 req.set_context(&default_context_);
3124 req.Start(); 3122 req.Start();
3125 MessageLoop::current()->Run(); 3123 MessageLoop::current()->Run();
3126 3124
3127 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 3125 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
3128 != std::string::npos); 3126 != std::string::npos);
3129 3127
3130 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3128 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3131 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3129 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3132 } 3130 }
3133 3131
3134 // Verify that the cookie isn't sent. 3132 // Verify that the cookie isn't sent.
3135 { 3133 {
3136 TestNetworkDelegate network_delegate; 3134 TestNetworkDelegate network_delegate;
3137 default_context_->set_network_delegate(&network_delegate); 3135 default_context_.set_network_delegate(&network_delegate);
3138 TestDelegate d; 3136 TestDelegate d;
3139 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); 3137 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES);
3140 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 3138 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
3141 req.set_context(default_context_); 3139 req.set_context(&default_context_);
3142 req.Start(); 3140 req.Start();
3143 MessageLoop::current()->Run(); 3141 MessageLoop::current()->Run();
3144 3142
3145 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 3143 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
3146 == std::string::npos); 3144 == std::string::npos);
3147 3145
3148 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); 3146 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count());
3149 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3147 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3150 } 3148 }
3151 3149
3152 default_context_->set_network_delegate(&default_network_delegate_); 3150 default_context_.set_network_delegate(&default_network_delegate_);
3153 } 3151 }
3154 3152
3155 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { 3153 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) {
3156 LocalHttpTestServer test_server; 3154 LocalHttpTestServer test_server;
3157 ASSERT_TRUE(test_server.Start()); 3155 ASSERT_TRUE(test_server.Start());
3158 3156
3159 // Set up a cookie. 3157 // Set up a cookie.
3160 { 3158 {
3161 TestNetworkDelegate network_delegate; 3159 TestNetworkDelegate network_delegate;
3162 default_context_->set_network_delegate(&network_delegate); 3160 default_context_.set_network_delegate(&network_delegate);
3163 TestDelegate d; 3161 TestDelegate d;
3164 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); 3162 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d);
3165 req.set_context(default_context_); 3163 req.set_context(&default_context_);
3166 req.Start(); 3164 req.Start();
3167 MessageLoop::current()->Run(); 3165 MessageLoop::current()->Run();
3168 3166
3169 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3167 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3170 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3168 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3171 } 3169 }
3172 3170
3173 // Try to set-up another cookie and update the previous cookie. 3171 // Try to set-up another cookie and update the previous cookie.
3174 { 3172 {
3175 TestNetworkDelegate network_delegate; 3173 TestNetworkDelegate network_delegate;
3176 default_context_->set_network_delegate(&network_delegate); 3174 default_context_.set_network_delegate(&network_delegate);
3177 TestDelegate d; 3175 TestDelegate d;
3178 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); 3176 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE);
3179 URLRequest req(test_server.GetURL( 3177 URLRequest req(test_server.GetURL(
3180 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); 3178 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d);
3181 req.set_context(default_context_); 3179 req.set_context(&default_context_);
3182 req.Start(); 3180 req.Start();
3183 3181
3184 MessageLoop::current()->Run(); 3182 MessageLoop::current()->Run();
3185 3183
3186 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3184 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3187 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); 3185 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count());
3188 } 3186 }
3189 3187
3190 3188
3191 // Verify the cookies weren't saved or updated. 3189 // Verify the cookies weren't saved or updated.
3192 { 3190 {
3193 TestNetworkDelegate network_delegate; 3191 TestNetworkDelegate network_delegate;
3194 default_context_->set_network_delegate(&network_delegate); 3192 default_context_.set_network_delegate(&network_delegate);
3195 TestDelegate d; 3193 TestDelegate d;
3196 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 3194 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
3197 req.set_context(default_context_); 3195 req.set_context(&default_context_);
3198 req.Start(); 3196 req.Start();
3199 MessageLoop::current()->Run(); 3197 MessageLoop::current()->Run();
3200 3198
3201 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 3199 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
3202 == std::string::npos); 3200 == std::string::npos);
3203 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 3201 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
3204 != std::string::npos); 3202 != std::string::npos);
3205 3203
3206 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3204 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3207 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3205 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3208 } 3206 }
3209 3207
3210 default_context_->set_network_delegate(&default_network_delegate_); 3208 default_context_.set_network_delegate(&default_network_delegate_);
3211 } 3209 }
3212 3210
3213 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { 3211 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) {
3214 LocalHttpTestServer test_server; 3212 LocalHttpTestServer test_server;
3215 ASSERT_TRUE(test_server.Start()); 3213 ASSERT_TRUE(test_server.Start());
3216 3214
3217 // Set up an empty cookie. 3215 // Set up an empty cookie.
3218 { 3216 {
3219 TestNetworkDelegate network_delegate; 3217 TestNetworkDelegate network_delegate;
3220 default_context_->set_network_delegate(&network_delegate); 3218 default_context_.set_network_delegate(&network_delegate);
3221 TestDelegate d; 3219 TestDelegate d;
3222 URLRequest req(test_server.GetURL("set-cookie"), &d); 3220 URLRequest req(test_server.GetURL("set-cookie"), &d);
3223 req.set_context(default_context_); 3221 req.set_context(&default_context_);
3224 req.Start(); 3222 req.Start();
3225 MessageLoop::current()->Run(); 3223 MessageLoop::current()->Run();
3226 3224
3227 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3225 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3228 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3226 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3229 EXPECT_EQ(0, network_delegate.set_cookie_count()); 3227 EXPECT_EQ(0, network_delegate.set_cookie_count());
3230 } 3228 }
3231 3229
3232 default_context_->set_network_delegate(&default_network_delegate_); 3230 default_context_.set_network_delegate(&default_network_delegate_);
3233 } 3231 }
3234 3232
3235 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { 3233 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) {
3236 LocalHttpTestServer test_server; 3234 LocalHttpTestServer test_server;
3237 ASSERT_TRUE(test_server.Start()); 3235 ASSERT_TRUE(test_server.Start());
3238 3236
3239 // Set up a cookie. 3237 // Set up a cookie.
3240 { 3238 {
3241 TestNetworkDelegate network_delegate; 3239 TestNetworkDelegate network_delegate;
3242 default_context_->set_network_delegate(&network_delegate); 3240 default_context_.set_network_delegate(&network_delegate);
3243 TestDelegate d; 3241 TestDelegate d;
3244 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); 3242 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d);
3245 req.set_context(default_context_); 3243 req.set_context(&default_context_);
3246 req.Start(); 3244 req.Start();
3247 MessageLoop::current()->Run(); 3245 MessageLoop::current()->Run();
3248 3246
3249 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3247 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3250 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3248 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3251 } 3249 }
3252 3250
3253 // Verify that the cookie is set. 3251 // Verify that the cookie is set.
3254 { 3252 {
3255 TestNetworkDelegate network_delegate; 3253 TestNetworkDelegate network_delegate;
3256 default_context_->set_network_delegate(&network_delegate); 3254 default_context_.set_network_delegate(&network_delegate);
3257 TestDelegate d; 3255 TestDelegate d;
3258 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 3256 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
3259 req.set_context(default_context_); 3257 req.set_context(&default_context_);
3260 req.Start(); 3258 req.Start();
3261 MessageLoop::current()->Run(); 3259 MessageLoop::current()->Run();
3262 3260
3263 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 3261 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
3264 != std::string::npos); 3262 != std::string::npos);
3265 3263
3266 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3264 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3267 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3265 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3268 } 3266 }
3269 3267
3270 // Verify that the cookie isn't sent. 3268 // Verify that the cookie isn't sent.
3271 { 3269 {
3272 TestNetworkDelegate network_delegate; 3270 TestNetworkDelegate network_delegate;
3273 default_context_->set_network_delegate(&network_delegate); 3271 default_context_.set_network_delegate(&network_delegate);
3274 TestDelegate d; 3272 TestDelegate d;
3275 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); 3273 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES);
3276 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 3274 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
3277 req.set_context(default_context_); 3275 req.set_context(&default_context_);
3278 req.Start(); 3276 req.Start();
3279 MessageLoop::current()->Run(); 3277 MessageLoop::current()->Run();
3280 3278
3281 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 3279 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
3282 == std::string::npos); 3280 == std::string::npos);
3283 3281
3284 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); 3282 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count());
3285 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3283 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3286 } 3284 }
3287 3285
3288 default_context_->set_network_delegate(&default_network_delegate_); 3286 default_context_.set_network_delegate(&default_network_delegate_);
3289 } 3287 }
3290 3288
3291 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { 3289 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) {
3292 LocalHttpTestServer test_server; 3290 LocalHttpTestServer test_server;
3293 ASSERT_TRUE(test_server.Start()); 3291 ASSERT_TRUE(test_server.Start());
3294 3292
3295 // Set up a cookie. 3293 // Set up a cookie.
3296 { 3294 {
3297 TestNetworkDelegate network_delegate; 3295 TestNetworkDelegate network_delegate;
3298 default_context_->set_network_delegate(&network_delegate); 3296 default_context_.set_network_delegate(&network_delegate);
3299 TestDelegate d; 3297 TestDelegate d;
3300 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); 3298 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d);
3301 req.set_context(default_context_); 3299 req.set_context(&default_context_);
3302 req.Start(); 3300 req.Start();
3303 MessageLoop::current()->Run(); 3301 MessageLoop::current()->Run();
3304 3302
3305 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3303 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3306 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3304 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3307 } 3305 }
3308 3306
3309 // Try to set-up another cookie and update the previous cookie. 3307 // Try to set-up another cookie and update the previous cookie.
3310 { 3308 {
3311 TestNetworkDelegate network_delegate; 3309 TestNetworkDelegate network_delegate;
3312 default_context_->set_network_delegate(&network_delegate); 3310 default_context_.set_network_delegate(&network_delegate);
3313 TestDelegate d; 3311 TestDelegate d;
3314 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); 3312 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE);
3315 URLRequest req(test_server.GetURL( 3313 URLRequest req(test_server.GetURL(
3316 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); 3314 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d);
3317 req.set_context(default_context_); 3315 req.set_context(&default_context_);
3318 req.Start(); 3316 req.Start();
3319 3317
3320 MessageLoop::current()->Run(); 3318 MessageLoop::current()->Run();
3321 3319
3322 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3320 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3323 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); 3321 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count());
3324 } 3322 }
3325 3323
3326 // Verify the cookies weren't saved or updated. 3324 // Verify the cookies weren't saved or updated.
3327 { 3325 {
3328 TestNetworkDelegate network_delegate; 3326 TestNetworkDelegate network_delegate;
3329 default_context_->set_network_delegate(&network_delegate); 3327 default_context_.set_network_delegate(&network_delegate);
3330 TestDelegate d; 3328 TestDelegate d;
3331 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 3329 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
3332 req.set_context(default_context_); 3330 req.set_context(&default_context_);
3333 req.Start(); 3331 req.Start();
3334 MessageLoop::current()->Run(); 3332 MessageLoop::current()->Run();
3335 3333
3336 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 3334 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
3337 == std::string::npos); 3335 == std::string::npos);
3338 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 3336 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
3339 != std::string::npos); 3337 != std::string::npos);
3340 3338
3341 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3339 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3342 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3340 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3343 } 3341 }
3344 3342
3345 default_context_->set_network_delegate(&default_network_delegate_); 3343 default_context_.set_network_delegate(&default_network_delegate_);
3346 } 3344 }
3347 3345
3348 void CheckCookiePolicyCallback(bool* was_run, const CookieList& cookies) { 3346 void CheckCookiePolicyCallback(bool* was_run, const CookieList& cookies) {
3349 EXPECT_EQ(1U, cookies.size()); 3347 EXPECT_EQ(1U, cookies.size());
3350 EXPECT_FALSE(cookies[0].IsPersistent()); 3348 EXPECT_FALSE(cookies[0].IsPersistent());
3351 *was_run = true; 3349 *was_run = true;
3352 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 3350 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
3353 } 3351 }
3354 3352
3355 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { 3353 TEST_F(URLRequestTest, CookiePolicy_ForceSession) {
3356 LocalHttpTestServer test_server; 3354 LocalHttpTestServer test_server;
3357 ASSERT_TRUE(test_server.Start()); 3355 ASSERT_TRUE(test_server.Start());
3358 3356
3359 // Set up a cookie. 3357 // Set up a cookie.
3360 { 3358 {
3361 TestNetworkDelegate network_delegate; 3359 TestNetworkDelegate network_delegate;
3362 default_context_->set_network_delegate(&network_delegate); 3360 default_context_.set_network_delegate(&network_delegate);
3363 TestDelegate d; 3361 TestDelegate d;
3364 network_delegate.set_cookie_options(TestNetworkDelegate::FORCE_SESSION); 3362 network_delegate.set_cookie_options(TestNetworkDelegate::FORCE_SESSION);
3365 URLRequest req(test_server.GetURL( 3363 URLRequest req(test_server.GetURL(
3366 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); 3364 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d);
3367 req.set_context(default_context_); 3365 req.set_context(&default_context_);
3368 req.Start(); // Triggers an asynchronous cookie policy check. 3366 req.Start(); // Triggers an asynchronous cookie policy check.
3369 3367
3370 MessageLoop::current()->Run(); 3368 MessageLoop::current()->Run();
3371 3369
3372 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 3370 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
3373 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 3371 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
3374 } 3372 }
3375 default_context_->set_network_delegate(&default_network_delegate_); 3373 default_context_.set_network_delegate(&default_network_delegate_);
3376 3374
3377 // Now, check the cookie store. 3375 // Now, check the cookie store.
3378 bool was_run = false; 3376 bool was_run = false;
3379 default_context_->cookie_store()->GetCookieMonster()->GetAllCookiesAsync( 3377 default_context_.cookie_store()->GetCookieMonster()->GetAllCookiesAsync(
3380 base::Bind(&CheckCookiePolicyCallback, &was_run)); 3378 base::Bind(&CheckCookiePolicyCallback, &was_run));
3381 MessageLoop::current()->RunAllPending(); 3379 MessageLoop::current()->RunAllPending();
3382 DCHECK(was_run); 3380 DCHECK(was_run);
3383 } 3381 }
3384 3382
3385 // In this test, we do a POST which the server will 302 redirect. 3383 // In this test, we do a POST which the server will 302 redirect.
3386 // The subsequent transaction should use GET, and should not send the 3384 // The subsequent transaction should use GET, and should not send the
3387 // Content-Type header. 3385 // Content-Type header.
3388 // http://code.google.com/p/chromium/issues/detail?id=843 3386 // http://code.google.com/p/chromium/issues/detail?id=843
3389 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { 3387 TEST_F(URLRequestTestHTTP, Post302RedirectGet) {
3390 ASSERT_TRUE(test_server_.Start()); 3388 ASSERT_TRUE(test_server_.Start());
3391 3389
3392 const char kData[] = "hello world"; 3390 const char kData[] = "hello world";
3393 3391
3394 TestDelegate d; 3392 TestDelegate d;
3395 TestURLRequest req(test_server_.GetURL("files/redirect-to-echoall"), &d); 3393 URLRequest req(test_server_.GetURL("files/redirect-to-echoall"), &d);
3396 req.set_context(default_context_); 3394 req.set_context(&default_context_);
3397 req.set_method("POST"); 3395 req.set_method("POST");
3398 req.set_upload(CreateSimpleUploadData(kData)); 3396 req.set_upload(CreateSimpleUploadData(kData));
3399 3397
3400 // Set headers (some of which are specific to the POST). 3398 // Set headers (some of which are specific to the POST).
3401 HttpRequestHeaders headers; 3399 HttpRequestHeaders headers;
3402 headers.AddHeadersFromString( 3400 headers.AddHeadersFromString(
3403 "Content-Type: multipart/form-data; " 3401 "Content-Type: multipart/form-data; "
3404 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" 3402 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n"
3405 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," 3403 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,"
3406 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" 3404 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3472 HTTPRedirectMethodTest(url, "PUT", "PUT", true); 3470 HTTPRedirectMethodTest(url, "PUT", "PUT", true);
3473 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); 3471 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false);
3474 } 3472 }
3475 3473
3476 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { 3474 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) {
3477 ASSERT_TRUE(test_server_.Start()); 3475 ASSERT_TRUE(test_server_.Start());
3478 3476
3479 const char kData[] = "hello world"; 3477 const char kData[] = "hello world";
3480 3478
3481 TestDelegate d; 3479 TestDelegate d;
3482 TestURLRequest req(test_server_.GetURL("empty.html"), &d); 3480 URLRequest req(test_server_.GetURL("empty.html"), &d);
3483 req.set_context(default_context_); 3481 req.set_context(&default_context_);
3484 req.set_method("POST"); 3482 req.set_method("POST");
3485 req.set_upload(CreateSimpleUploadData(kData).get()); 3483 req.set_upload(CreateSimpleUploadData(kData).get());
3486 HttpRequestHeaders headers; 3484 HttpRequestHeaders headers;
3487 headers.SetHeader(HttpRequestHeaders::kContentLength, 3485 headers.SetHeader(HttpRequestHeaders::kContentLength,
3488 base::UintToString(arraysize(kData) - 1)); 3486 base::UintToString(arraysize(kData) - 1));
3489 req.SetExtraRequestHeaders(headers); 3487 req.SetExtraRequestHeaders(headers);
3490 3488
3491 URLRequestRedirectJob* job = 3489 URLRequestRedirectJob* job =
3492 new URLRequestRedirectJob(&req, test_server_.GetURL("echo")); 3490 new URLRequestRedirectJob(&req, test_server_.GetURL("echo"));
3493 AddTestInterceptor()->set_main_intercept_job(job); 3491 AddTestInterceptor()->set_main_intercept_job(job);
3494 3492
3495 req.Start(); 3493 req.Start();
3496 MessageLoop::current()->Run(); 3494 MessageLoop::current()->Run();
3497 EXPECT_EQ("GET", req.method()); 3495 EXPECT_EQ("GET", req.method());
3498 } 3496 }
3499 3497
3500 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { 3498 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) {
3501 ASSERT_TRUE(test_server_.Start()); 3499 ASSERT_TRUE(test_server_.Start());
3502 3500
3503 const char kData[] = "hello world"; 3501 const char kData[] = "hello world";
3504 3502
3505 TestDelegate d; 3503 TestDelegate d;
3506 TestURLRequest req(test_server_.GetURL("empty.html"), &d); 3504 URLRequest req(test_server_.GetURL("empty.html"), &d);
3507 req.set_context(default_context_); 3505 req.set_context(&default_context_);
3508 req.set_method("POST"); 3506 req.set_method("POST");
3509 req.set_upload(CreateSimpleUploadData(kData).get()); 3507 req.set_upload(CreateSimpleUploadData(kData).get());
3510 HttpRequestHeaders headers; 3508 HttpRequestHeaders headers;
3511 headers.SetHeader(HttpRequestHeaders::kContentLength, 3509 headers.SetHeader(HttpRequestHeaders::kContentLength,
3512 base::UintToString(arraysize(kData) - 1)); 3510 base::UintToString(arraysize(kData) - 1));
3513 req.SetExtraRequestHeaders(headers); 3511 req.SetExtraRequestHeaders(headers);
3514 3512
3515 URLRequestRedirectJob* job = 3513 URLRequestRedirectJob* job =
3516 new URLRequestRedirectJob(&req, test_server_.GetURL("echo")); 3514 new URLRequestRedirectJob(&req, test_server_.GetURL("echo"));
3517 job->set_redirect_code( 3515 job->set_redirect_code(
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
3716 3714
3717 TEST_F(URLRequestTest, Intercept) { 3715 TEST_F(URLRequestTest, Intercept) {
3718 TestInterceptor interceptor; 3716 TestInterceptor interceptor;
3719 3717
3720 // intercept the main request and respond with a simple response 3718 // intercept the main request and respond with a simple response
3721 interceptor.intercept_main_request_ = true; 3719 interceptor.intercept_main_request_ = true;
3722 interceptor.main_headers_ = TestInterceptor::ok_headers(); 3720 interceptor.main_headers_ = TestInterceptor::ok_headers();
3723 interceptor.main_data_ = TestInterceptor::ok_data(); 3721 interceptor.main_data_ = TestInterceptor::ok_data();
3724 3722
3725 TestDelegate d; 3723 TestDelegate d;
3726 TestURLRequest req(GURL("http://test_intercept/foo"), &d); 3724 URLRequest req(GURL("http://test_intercept/foo"), &d);
3727 req.set_context(default_context_); 3725 req.set_context(&default_context_);
3728 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); 3726 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data();
3729 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); 3727 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data();
3730 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); 3728 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data();
3731 req.SetUserData(NULL, user_data0); 3729 req.SetUserData(NULL, user_data0);
3732 req.SetUserData(&user_data1, user_data1); 3730 req.SetUserData(&user_data1, user_data1);
3733 req.SetUserData(&user_data2, user_data2); 3731 req.SetUserData(&user_data2, user_data2);
3734 req.set_method("GET"); 3732 req.set_method("GET");
3735 req.Start(); 3733 req.Start();
3736 MessageLoop::current()->Run(); 3734 MessageLoop::current()->Run();
3737 3735
(...skipping 20 matching lines...) Expand all
3758 interceptor.intercept_main_request_ = true; 3756 interceptor.intercept_main_request_ = true;
3759 interceptor.main_headers_ = TestInterceptor::redirect_headers(); 3757 interceptor.main_headers_ = TestInterceptor::redirect_headers();
3760 interceptor.main_data_ = TestInterceptor::redirect_data(); 3758 interceptor.main_data_ = TestInterceptor::redirect_data();
3761 3759
3762 // intercept that redirect and respond a final OK response 3760 // intercept that redirect and respond a final OK response
3763 interceptor.intercept_redirect_ = true; 3761 interceptor.intercept_redirect_ = true;
3764 interceptor.redirect_headers_ = TestInterceptor::ok_headers(); 3762 interceptor.redirect_headers_ = TestInterceptor::ok_headers();
3765 interceptor.redirect_data_ = TestInterceptor::ok_data(); 3763 interceptor.redirect_data_ = TestInterceptor::ok_data();
3766 3764
3767 TestDelegate d; 3765 TestDelegate d;
3768 TestURLRequest req(GURL("http://test_intercept/foo"), &d); 3766 URLRequest req(GURL("http://test_intercept/foo"), &d);
3769 req.set_context(default_context_); 3767 req.set_context(&default_context_);
3770 req.set_method("GET"); 3768 req.set_method("GET");
3771 req.Start(); 3769 req.Start();
3772 MessageLoop::current()->Run(); 3770 MessageLoop::current()->Run();
3773 3771
3774 // Check the interceptor got called as expected 3772 // Check the interceptor got called as expected
3775 EXPECT_TRUE(interceptor.did_intercept_main_); 3773 EXPECT_TRUE(interceptor.did_intercept_main_);
3776 EXPECT_TRUE(interceptor.did_intercept_redirect_); 3774 EXPECT_TRUE(interceptor.did_intercept_redirect_);
3777 3775
3778 // Check we got one good response 3776 // Check we got one good response
3779 EXPECT_TRUE(req.status().is_success()); 3777 EXPECT_TRUE(req.status().is_success());
(...skipping 12 matching lines...) Expand all
3792 interceptor.intercept_main_request_ = true; 3790 interceptor.intercept_main_request_ = true;
3793 interceptor.main_headers_ = TestInterceptor::error_headers(); 3791 interceptor.main_headers_ = TestInterceptor::error_headers();
3794 interceptor.main_data_ = TestInterceptor::error_data(); 3792 interceptor.main_data_ = TestInterceptor::error_data();
3795 3793
3796 // intercept that error and respond with an OK response 3794 // intercept that error and respond with an OK response
3797 interceptor.intercept_final_response_ = true; 3795 interceptor.intercept_final_response_ = true;
3798 interceptor.final_headers_ = TestInterceptor::ok_headers(); 3796 interceptor.final_headers_ = TestInterceptor::ok_headers();
3799 interceptor.final_data_ = TestInterceptor::ok_data(); 3797 interceptor.final_data_ = TestInterceptor::ok_data();
3800 3798
3801 TestDelegate d; 3799 TestDelegate d;
3802 TestURLRequest req(GURL("http://test_intercept/foo"), &d); 3800 URLRequest req(GURL("http://test_intercept/foo"), &d);
3803 req.set_context(default_context_); 3801 req.set_context(&default_context_);
3804 req.set_method("GET"); 3802 req.set_method("GET");
3805 req.Start(); 3803 req.Start();
3806 MessageLoop::current()->Run(); 3804 MessageLoop::current()->Run();
3807 3805
3808 // Check the interceptor got called as expected 3806 // Check the interceptor got called as expected
3809 EXPECT_TRUE(interceptor.did_intercept_main_); 3807 EXPECT_TRUE(interceptor.did_intercept_main_);
3810 EXPECT_TRUE(interceptor.did_intercept_final_); 3808 EXPECT_TRUE(interceptor.did_intercept_final_);
3811 3809
3812 // Check we got one good response 3810 // Check we got one good response
3813 EXPECT_TRUE(req.status().is_success()); 3811 EXPECT_TRUE(req.status().is_success());
3814 EXPECT_EQ(200, req.response_headers()->response_code()); 3812 EXPECT_EQ(200, req.response_headers()->response_code());
3815 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); 3813 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received());
3816 EXPECT_EQ(1, d.response_started_count()); 3814 EXPECT_EQ(1, d.response_started_count());
3817 EXPECT_EQ(0, d.received_redirect_count()); 3815 EXPECT_EQ(0, d.received_redirect_count());
3818 } 3816 }
3819 3817
3820 TEST_F(URLRequestTest, InterceptNetworkError) { 3818 TEST_F(URLRequestTest, InterceptNetworkError) {
3821 TestInterceptor interceptor; 3819 TestInterceptor interceptor;
3822 3820
3823 // intercept the main request to simulate a network error 3821 // intercept the main request to simulate a network error
3824 interceptor.simulate_main_network_error_ = true; 3822 interceptor.simulate_main_network_error_ = true;
3825 3823
3826 // intercept that error and respond with an OK response 3824 // intercept that error and respond with an OK response
3827 interceptor.intercept_final_response_ = true; 3825 interceptor.intercept_final_response_ = true;
3828 interceptor.final_headers_ = TestInterceptor::ok_headers(); 3826 interceptor.final_headers_ = TestInterceptor::ok_headers();
3829 interceptor.final_data_ = TestInterceptor::ok_data(); 3827 interceptor.final_data_ = TestInterceptor::ok_data();
3830 3828
3831 TestDelegate d; 3829 TestDelegate d;
3832 TestURLRequest req(GURL("http://test_intercept/foo"), &d); 3830 URLRequest req(GURL("http://test_intercept/foo"), &d);
3833 req.set_context(default_context_); 3831 req.set_context(&default_context_);
3834 req.set_method("GET"); 3832 req.set_method("GET");
3835 req.Start(); 3833 req.Start();
3836 MessageLoop::current()->Run(); 3834 MessageLoop::current()->Run();
3837 3835
3838 // Check the interceptor got called as expected 3836 // Check the interceptor got called as expected
3839 EXPECT_TRUE(interceptor.did_simulate_error_main_); 3837 EXPECT_TRUE(interceptor.did_simulate_error_main_);
3840 EXPECT_TRUE(interceptor.did_intercept_final_); 3838 EXPECT_TRUE(interceptor.did_intercept_final_);
3841 3839
3842 // Check we received one good response 3840 // Check we received one good response
3843 EXPECT_TRUE(req.status().is_success()); 3841 EXPECT_TRUE(req.status().is_success());
3844 EXPECT_EQ(200, req.response_headers()->response_code()); 3842 EXPECT_EQ(200, req.response_headers()->response_code());
3845 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); 3843 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received());
3846 EXPECT_EQ(1, d.response_started_count()); 3844 EXPECT_EQ(1, d.response_started_count());
3847 EXPECT_EQ(0, d.received_redirect_count()); 3845 EXPECT_EQ(0, d.received_redirect_count());
3848 } 3846 }
3849 3847
3850 TEST_F(URLRequestTest, InterceptRestartRequired) { 3848 TEST_F(URLRequestTest, InterceptRestartRequired) {
3851 TestInterceptor interceptor; 3849 TestInterceptor interceptor;
3852 3850
3853 // restart the main request 3851 // restart the main request
3854 interceptor.restart_main_request_ = true; 3852 interceptor.restart_main_request_ = true;
3855 3853
3856 // then intercept the new main request and respond with an OK response 3854 // then intercept the new main request and respond with an OK response
3857 interceptor.intercept_main_request_ = true; 3855 interceptor.intercept_main_request_ = true;
3858 interceptor.main_headers_ = TestInterceptor::ok_headers(); 3856 interceptor.main_headers_ = TestInterceptor::ok_headers();
3859 interceptor.main_data_ = TestInterceptor::ok_data(); 3857 interceptor.main_data_ = TestInterceptor::ok_data();
3860 3858
3861 TestDelegate d; 3859 TestDelegate d;
3862 TestURLRequest req(GURL("http://test_intercept/foo"), &d); 3860 URLRequest req(GURL("http://test_intercept/foo"), &d);
3863 req.set_context(default_context_); 3861 req.set_context(&default_context_);
3864 req.set_method("GET"); 3862 req.set_method("GET");
3865 req.Start(); 3863 req.Start();
3866 MessageLoop::current()->Run(); 3864 MessageLoop::current()->Run();
3867 3865
3868 // Check the interceptor got called as expected 3866 // Check the interceptor got called as expected
3869 EXPECT_TRUE(interceptor.did_restart_main_); 3867 EXPECT_TRUE(interceptor.did_restart_main_);
3870 EXPECT_TRUE(interceptor.did_intercept_main_); 3868 EXPECT_TRUE(interceptor.did_intercept_main_);
3871 3869
3872 // Check we received one good response 3870 // Check we received one good response
3873 EXPECT_TRUE(req.status().is_success()); 3871 EXPECT_TRUE(req.status().is_success());
(...skipping 10 matching lines...) Expand all
3884 3882
3885 // intercept the main request and cancel from within the restarted job 3883 // intercept the main request and cancel from within the restarted job
3886 interceptor.cancel_main_request_ = true; 3884 interceptor.cancel_main_request_ = true;
3887 3885
3888 // setup to intercept final response and override it with an OK response 3886 // setup to intercept final response and override it with an OK response
3889 interceptor.intercept_final_response_ = true; 3887 interceptor.intercept_final_response_ = true;
3890 interceptor.final_headers_ = TestInterceptor::ok_headers(); 3888 interceptor.final_headers_ = TestInterceptor::ok_headers();
3891 interceptor.final_data_ = TestInterceptor::ok_data(); 3889 interceptor.final_data_ = TestInterceptor::ok_data();
3892 3890
3893 TestDelegate d; 3891 TestDelegate d;
3894 TestURLRequest req(GURL("http://test_intercept/foo"), &d); 3892 URLRequest req(GURL("http://test_intercept/foo"), &d);
3895 req.set_context(default_context_); 3893 req.set_context(&default_context_);
3896 req.set_method("GET"); 3894 req.set_method("GET");
3897 req.Start(); 3895 req.Start();
3898 MessageLoop::current()->Run(); 3896 MessageLoop::current()->Run();
3899 3897
3900 // Check the interceptor got called as expected 3898 // Check the interceptor got called as expected
3901 EXPECT_TRUE(interceptor.did_cancel_main_); 3899 EXPECT_TRUE(interceptor.did_cancel_main_);
3902 EXPECT_FALSE(interceptor.did_intercept_final_); 3900 EXPECT_FALSE(interceptor.did_intercept_final_);
3903 3901
3904 // Check we see a canceled request 3902 // Check we see a canceled request
3905 EXPECT_FALSE(req.status().is_success()); 3903 EXPECT_FALSE(req.status().is_success());
(...skipping 10 matching lines...) Expand all
3916 3914
3917 // intercept the redirect and cancel from within that job 3915 // intercept the redirect and cancel from within that job
3918 interceptor.cancel_redirect_request_ = true; 3916 interceptor.cancel_redirect_request_ = true;
3919 3917
3920 // setup to intercept final response and override it with an OK response 3918 // setup to intercept final response and override it with an OK response
3921 interceptor.intercept_final_response_ = true; 3919 interceptor.intercept_final_response_ = true;
3922 interceptor.final_headers_ = TestInterceptor::ok_headers(); 3920 interceptor.final_headers_ = TestInterceptor::ok_headers();
3923 interceptor.final_data_ = TestInterceptor::ok_data(); 3921 interceptor.final_data_ = TestInterceptor::ok_data();
3924 3922
3925 TestDelegate d; 3923 TestDelegate d;
3926 TestURLRequest req(GURL("http://test_intercept/foo"), &d); 3924 URLRequest req(GURL("http://test_intercept/foo"), &d);
3927 req.set_context(default_context_); 3925 req.set_context(&default_context_);
3928 req.set_method("GET"); 3926 req.set_method("GET");
3929 req.Start(); 3927 req.Start();
3930 MessageLoop::current()->Run(); 3928 MessageLoop::current()->Run();
3931 3929
3932 // Check the interceptor got called as expected 3930 // Check the interceptor got called as expected
3933 EXPECT_TRUE(interceptor.did_intercept_main_); 3931 EXPECT_TRUE(interceptor.did_intercept_main_);
3934 EXPECT_TRUE(interceptor.did_cancel_redirect_); 3932 EXPECT_TRUE(interceptor.did_cancel_redirect_);
3935 EXPECT_FALSE(interceptor.did_intercept_final_); 3933 EXPECT_FALSE(interceptor.did_intercept_final_);
3936 3934
3937 // Check we see a canceled request 3935 // Check we see a canceled request
3938 EXPECT_FALSE(req.status().is_success()); 3936 EXPECT_FALSE(req.status().is_success());
3939 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 3937 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status());
3940 } 3938 }
3941 3939
3942 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { 3940 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) {
3943 TestInterceptor interceptor; 3941 TestInterceptor interceptor;
3944 3942
3945 // intercept the main request to simulate a network error 3943 // intercept the main request to simulate a network error
3946 interceptor.simulate_main_network_error_ = true; 3944 interceptor.simulate_main_network_error_ = true;
3947 3945
3948 // setup to intercept final response and cancel from within that job 3946 // setup to intercept final response and cancel from within that job
3949 interceptor.cancel_final_request_ = true; 3947 interceptor.cancel_final_request_ = true;
3950 3948
3951 TestDelegate d; 3949 TestDelegate d;
3952 TestURLRequest req(GURL("http://test_intercept/foo"), &d); 3950 URLRequest req(GURL("http://test_intercept/foo"), &d);
3953 req.set_context(default_context_); 3951 req.set_context(&default_context_);
3954 req.set_method("GET"); 3952 req.set_method("GET");
3955 req.Start(); 3953 req.Start();
3956 MessageLoop::current()->Run(); 3954 MessageLoop::current()->Run();
3957 3955
3958 // Check the interceptor got called as expected 3956 // Check the interceptor got called as expected
3959 EXPECT_TRUE(interceptor.did_simulate_error_main_); 3957 EXPECT_TRUE(interceptor.did_simulate_error_main_);
3960 EXPECT_TRUE(interceptor.did_cancel_final_); 3958 EXPECT_TRUE(interceptor.did_cancel_final_);
3961 3959
3962 // Check we see a canceled request 3960 // Check we see a canceled request
3963 EXPECT_FALSE(req.status().is_success()); 3961 EXPECT_FALSE(req.status().is_success());
3964 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 3962 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status());
3965 } 3963 }
3966 3964
3967 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { 3965 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) {
3968 TestInterceptor interceptor; 3966 TestInterceptor interceptor;
3969 3967
3970 // intercept the main request and cancel then restart from within that job 3968 // intercept the main request and cancel then restart from within that job
3971 interceptor.cancel_then_restart_main_request_ = true; 3969 interceptor.cancel_then_restart_main_request_ = true;
3972 3970
3973 // setup to intercept final response and override it with an OK response 3971 // setup to intercept final response and override it with an OK response
3974 interceptor.intercept_final_response_ = true; 3972 interceptor.intercept_final_response_ = true;
3975 interceptor.final_headers_ = TestInterceptor::ok_headers(); 3973 interceptor.final_headers_ = TestInterceptor::ok_headers();
3976 interceptor.final_data_ = TestInterceptor::ok_data(); 3974 interceptor.final_data_ = TestInterceptor::ok_data();
3977 3975
3978 TestDelegate d; 3976 TestDelegate d;
3979 TestURLRequest req(GURL("http://test_intercept/foo"), &d); 3977 URLRequest req(GURL("http://test_intercept/foo"), &d);
3980 req.set_context(default_context_); 3978 req.set_context(&default_context_);
3981 req.set_method("GET"); 3979 req.set_method("GET");
3982 req.Start(); 3980 req.Start();
3983 MessageLoop::current()->Run(); 3981 MessageLoop::current()->Run();
3984 3982
3985 // Check the interceptor got called as expected 3983 // Check the interceptor got called as expected
3986 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); 3984 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_);
3987 EXPECT_FALSE(interceptor.did_intercept_final_); 3985 EXPECT_FALSE(interceptor.did_intercept_final_);
3988 3986
3989 // Check we see a canceled request 3987 // Check we see a canceled request
3990 EXPECT_FALSE(req.status().is_success()); 3988 EXPECT_FALSE(req.status().is_success());
3991 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); 3989 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status());
3992 } 3990 }
3993 3991
3994 // Check that two different URL requests have different identifiers. 3992 // Check that two different URL requests have different identifiers.
3995 TEST_F(URLRequestTest, Identifiers) { 3993 TEST_F(URLRequestTest, Identifiers) {
3996 TestDelegate d; 3994 TestDelegate d;
3997 TestURLRequest req(GURL("http://example.com"), &d); 3995 TestURLRequest req(GURL("http://example.com"), &d);
3998 TestURLRequest other_req(GURL("http://example.com"), &d); 3996 TestURLRequest other_req(GURL("http://example.com"), &d);
3999 3997
4000 ASSERT_NE(req.identifier(), other_req.identifier()); 3998 ASSERT_NE(req.identifier(), other_req.identifier());
4001 } 3999 }
4002 4000
4003 // Check that a failure to connect to the proxy is reported to the network 4001 // Check that a failure to connect to the proxy is reported to the network
4004 // delegate. 4002 // delegate.
4005 TEST_F(URLRequestTest, NetworkDelegateProxyError) { 4003 TEST_F(URLRequestTest, NetworkDelegateProxyError) {
4006 MockHostResolver host_resolver; 4004 MockHostResolver host_resolver;
4007 host_resolver.rules()->AddSimulatedFailure("*"); 4005 host_resolver.rules()->AddSimulatedFailure("*");
4008 4006
4009 TestNetworkDelegate network_delegate; // must outlive URLRequests 4007 TestNetworkDelegate network_delegate; // must outlive URLRequests
4010 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 4008 TestURLRequestContext context(true);
4011 context->set_network_delegate(&network_delegate); 4009 context.set_network_delegate(&network_delegate);
4012 context->SetProxyFromString("myproxy:70"); 4010 context.SetProxyFromString("myproxy:70");
4013 context->set_host_resolver(&host_resolver); 4011 context.set_host_resolver(&host_resolver);
4014 context->Init(); 4012 context.Init();
4015 4013
4016 TestDelegate d; 4014 TestDelegate d;
4017 TestURLRequest req(GURL("http://example.com"), &d); 4015 URLRequest req(GURL("http://example.com"), &d);
4018 req.set_context(context); 4016 req.set_context(&context);
4019 req.set_method("GET"); 4017 req.set_method("GET");
4020 4018
4021 req.Start(); 4019 req.Start();
4022 MessageLoop::current()->Run(); 4020 MessageLoop::current()->Run();
4023 4021
4024 // Check we see a failed request. 4022 // Check we see a failed request.
4025 EXPECT_FALSE(req.status().is_success()); 4023 EXPECT_FALSE(req.status().is_success());
4026 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); 4024 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status());
4027 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().error()); 4025 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().error());
4028 4026
4029 EXPECT_EQ(1, network_delegate.error_count()); 4027 EXPECT_EQ(1, network_delegate.error_count());
4030 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error()); 4028 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error());
4031 EXPECT_EQ(1, network_delegate.completed_requests()); 4029 EXPECT_EQ(1, network_delegate.completed_requests());
4032 } 4030 }
4033 4031
4034 // Check that it is impossible to change the referrer in the extra headers of 4032 // Check that it is impossible to change the referrer in the extra headers of
4035 // an URLRequest. 4033 // an URLRequest.
4036 TEST_F(URLRequestTest, DoNotOverrideReferrer) { 4034 TEST_F(URLRequestTest, DoNotOverrideReferrer) {
4037 LocalHttpTestServer test_server; 4035 LocalHttpTestServer test_server;
4038 ASSERT_TRUE(test_server.Start()); 4036 ASSERT_TRUE(test_server.Start());
4039 4037
4040 // If extra headers contain referer and the request contains a referer, 4038 // If extra headers contain referer and the request contains a referer,
4041 // only the latter shall be respected. 4039 // only the latter shall be respected.
4042 { 4040 {
4043 TestDelegate d; 4041 TestDelegate d;
4044 TestURLRequest req(test_server.GetURL("echoheader?Referer"), &d); 4042 URLRequest req(test_server.GetURL("echoheader?Referer"), &d);
4045 req.set_referrer("http://foo.com/"); 4043 req.set_referrer("http://foo.com/");
4046 req.set_context(default_context_); 4044 req.set_context(&default_context_);
4047 4045
4048 HttpRequestHeaders headers; 4046 HttpRequestHeaders headers;
4049 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); 4047 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/");
4050 req.SetExtraRequestHeaders(headers); 4048 req.SetExtraRequestHeaders(headers);
4051 4049
4052 req.Start(); 4050 req.Start();
4053 MessageLoop::current()->Run(); 4051 MessageLoop::current()->Run();
4054 4052
4055 EXPECT_EQ("http://foo.com/", d.data_received()); 4053 EXPECT_EQ("http://foo.com/", d.data_received());
4056 } 4054 }
4057 4055
4058 // If extra headers contain a referer but the request does not, no referer 4056 // If extra headers contain a referer but the request does not, no referer
4059 // shall be sent in the header. 4057 // shall be sent in the header.
4060 { 4058 {
4061 TestDelegate d; 4059 TestDelegate d;
4062 TestURLRequest req(test_server.GetURL("echoheader?Referer"), &d); 4060 URLRequest req(test_server.GetURL("echoheader?Referer"), &d);
4063 req.set_context(default_context_); 4061 req.set_context(&default_context_);
4064 4062
4065 HttpRequestHeaders headers; 4063 HttpRequestHeaders headers;
4066 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); 4064 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/");
4067 req.SetExtraRequestHeaders(headers); 4065 req.SetExtraRequestHeaders(headers);
4068 req.set_load_flags(LOAD_VALIDATE_CACHE); 4066 req.set_load_flags(LOAD_VALIDATE_CACHE);
4069 4067
4070 req.Start(); 4068 req.Start();
4071 MessageLoop::current()->Run(); 4069 MessageLoop::current()->Run();
4072 4070
4073 EXPECT_EQ("None", d.data_received()); 4071 EXPECT_EQ("None", d.data_received());
4074 } 4072 }
4075 } 4073 }
4076 4074
4077 // Make sure that net::NetworkDelegate::NotifyCompleted is called if 4075 // Make sure that net::NetworkDelegate::NotifyCompleted is called if
4078 // content is empty. 4076 // content is empty.
4079 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { 4077 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) {
4080 TestDelegate d; 4078 TestDelegate d;
4081 TestURLRequest req(GURL("data:,"), &d); 4079 URLRequest req(GURL("data:,"), &d);
4082 req.set_context(new TestURLRequestContext()); 4080 req.set_context(&default_context_);
4083 req.set_context(default_context_);
4084 req.Start(); 4081 req.Start();
4085 MessageLoop::current()->Run(); 4082 MessageLoop::current()->Run();
4086 EXPECT_EQ("", d.data_received()); 4083 EXPECT_EQ("", d.data_received());
4087 EXPECT_EQ(1, default_network_delegate_.completed_requests()); 4084 EXPECT_EQ(1, default_network_delegate_.completed_requests());
4088 } 4085 }
4089 4086
4090 class URLRequestTestFTP : public URLRequestTest { 4087 class URLRequestTestFTP : public URLRequestTest {
4091 public: 4088 public:
4092 URLRequestTestFTP() 4089 URLRequestTestFTP()
4093 : test_server_(TestServer::TYPE_FTP, TestServer::kLocalhost, FilePath()) { 4090 : test_server_(TestServer::TYPE_FTP, TestServer::kLocalhost, FilePath()) {
4094 } 4091 }
4095 4092
4096 protected: 4093 protected:
4097 TestServer test_server_; 4094 TestServer test_server_;
4098 }; 4095 };
4099 4096
4100 // Flaky, see http://crbug.com/25045. 4097 // Flaky, see http://crbug.com/25045.
4101 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) { 4098 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) {
4102 ASSERT_TRUE(test_server_.Start()); 4099 ASSERT_TRUE(test_server_.Start());
4103 4100
4104 TestDelegate d; 4101 TestDelegate d;
4105 { 4102 {
4106 TestURLRequest r(test_server_.GetURL("/"), &d); 4103 URLRequest r(test_server_.GetURL("/"), &d);
4107 r.set_context(default_context_); 4104 r.set_context(&default_context_);
4108 r.Start(); 4105 r.Start();
4109 EXPECT_TRUE(r.is_pending()); 4106 EXPECT_TRUE(r.is_pending());
4110 4107
4111 MessageLoop::current()->Run(); 4108 MessageLoop::current()->Run();
4112 4109
4113 EXPECT_FALSE(r.is_pending()); 4110 EXPECT_FALSE(r.is_pending());
4114 EXPECT_EQ(1, d.response_started_count()); 4111 EXPECT_EQ(1, d.response_started_count());
4115 EXPECT_FALSE(d.received_data_before_response()); 4112 EXPECT_FALSE(d.received_data_before_response());
4116 EXPECT_LT(0, d.bytes_received()); 4113 EXPECT_LT(0, d.bytes_received());
4117 EXPECT_EQ(test_server_.host_port_pair().host(), 4114 EXPECT_EQ(test_server_.host_port_pair().host(),
4118 r.GetSocketAddress().host()); 4115 r.GetSocketAddress().host());
4119 EXPECT_EQ(test_server_.host_port_pair().port(), 4116 EXPECT_EQ(test_server_.host_port_pair().port(),
4120 r.GetSocketAddress().port()); 4117 r.GetSocketAddress().port());
4121 } 4118 }
4122 } 4119 }
4123 4120
4124 // Flaky, see http://crbug.com/25045. 4121 // Flaky, see http://crbug.com/25045.
4125 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) { 4122 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) {
4126 ASSERT_TRUE(test_server_.Start()); 4123 ASSERT_TRUE(test_server_.Start());
4127 4124
4128 FilePath app_path; 4125 FilePath app_path;
4129 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 4126 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
4130 app_path = app_path.AppendASCII("LICENSE"); 4127 app_path = app_path.AppendASCII("LICENSE");
4131 TestDelegate d; 4128 TestDelegate d;
4132 { 4129 {
4133 TestURLRequest r(test_server_.GetURL("/LICENSE"), &d); 4130 URLRequest r(test_server_.GetURL("/LICENSE"), &d);
4134 r.set_context(default_context_); 4131 r.set_context(&default_context_);
4135 r.Start(); 4132 r.Start();
4136 EXPECT_TRUE(r.is_pending()); 4133 EXPECT_TRUE(r.is_pending());
4137 4134
4138 MessageLoop::current()->Run(); 4135 MessageLoop::current()->Run();
4139 4136
4140 int64 file_size = 0; 4137 int64 file_size = 0;
4141 file_util::GetFileSize(app_path, &file_size); 4138 file_util::GetFileSize(app_path, &file_size);
4142 4139
4143 EXPECT_FALSE(r.is_pending()); 4140 EXPECT_FALSE(r.is_pending());
4144 EXPECT_EQ(1, d.response_started_count()); 4141 EXPECT_EQ(1, d.response_started_count());
4145 EXPECT_FALSE(d.received_data_before_response()); 4142 EXPECT_FALSE(d.received_data_before_response());
4146 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 4143 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
4147 EXPECT_EQ(test_server_.host_port_pair().host(), 4144 EXPECT_EQ(test_server_.host_port_pair().host(),
4148 r.GetSocketAddress().host()); 4145 r.GetSocketAddress().host());
4149 EXPECT_EQ(test_server_.host_port_pair().port(), 4146 EXPECT_EQ(test_server_.host_port_pair().port(),
4150 r.GetSocketAddress().port()); 4147 r.GetSocketAddress().port());
4151 } 4148 }
4152 } 4149 }
4153 4150
4154 // Flaky, see http://crbug.com/25045. 4151 // Flaky, see http://crbug.com/25045.
4155 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTest) { 4152 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTest) {
4156 ASSERT_TRUE(test_server_.Start()); 4153 ASSERT_TRUE(test_server_.Start());
4157 4154
4158 FilePath app_path; 4155 FilePath app_path;
4159 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 4156 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
4160 app_path = app_path.AppendASCII("LICENSE"); 4157 app_path = app_path.AppendASCII("LICENSE");
4161 TestDelegate d; 4158 TestDelegate d;
4162 { 4159 {
4163 TestURLRequest r( 4160 URLRequest r(
4164 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), 4161 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"),
4165 &d); 4162 &d);
4166 r.set_context(default_context_); 4163 r.set_context(&default_context_);
4167 r.Start(); 4164 r.Start();
4168 EXPECT_TRUE(r.is_pending()); 4165 EXPECT_TRUE(r.is_pending());
4169 4166
4170 MessageLoop::current()->Run(); 4167 MessageLoop::current()->Run();
4171 4168
4172 int64 file_size = 0; 4169 int64 file_size = 0;
4173 file_util::GetFileSize(app_path, &file_size); 4170 file_util::GetFileSize(app_path, &file_size);
4174 4171
4175 EXPECT_FALSE(r.is_pending()); 4172 EXPECT_FALSE(r.is_pending());
4176 EXPECT_EQ(test_server_.host_port_pair().host(), 4173 EXPECT_EQ(test_server_.host_port_pair().host(),
4177 r.GetSocketAddress().host()); 4174 r.GetSocketAddress().host());
4178 EXPECT_EQ(test_server_.host_port_pair().port(), 4175 EXPECT_EQ(test_server_.host_port_pair().port(),
4179 r.GetSocketAddress().port()); 4176 r.GetSocketAddress().port());
4180 EXPECT_EQ(1, d.response_started_count()); 4177 EXPECT_EQ(1, d.response_started_count());
4181 EXPECT_FALSE(d.received_data_before_response()); 4178 EXPECT_FALSE(d.received_data_before_response());
4182 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 4179 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
4183 } 4180 }
4184 } 4181 }
4185 4182
4186 // Flaky, see http://crbug.com/25045. 4183 // Flaky, see http://crbug.com/25045.
4187 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPassword) { 4184 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPassword) {
4188 ASSERT_TRUE(test_server_.Start()); 4185 ASSERT_TRUE(test_server_.Start());
4189 4186
4190 FilePath app_path; 4187 FilePath app_path;
4191 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 4188 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
4192 app_path = app_path.AppendASCII("LICENSE"); 4189 app_path = app_path.AppendASCII("LICENSE");
4193 TestDelegate d; 4190 TestDelegate d;
4194 { 4191 {
4195 TestURLRequest r( 4192 URLRequest r(
4196 test_server_.GetURLWithUserAndPassword("/LICENSE", 4193 test_server_.GetURLWithUserAndPassword("/LICENSE",
4197 "chrome", 4194 "chrome",
4198 "wrong_password"), 4195 "wrong_password"),
4199 &d); 4196 &d);
4200 r.set_context(default_context_); 4197 r.set_context(&default_context_);
4201 r.Start(); 4198 r.Start();
4202 EXPECT_TRUE(r.is_pending()); 4199 EXPECT_TRUE(r.is_pending());
4203 4200
4204 MessageLoop::current()->Run(); 4201 MessageLoop::current()->Run();
4205 4202
4206 int64 file_size = 0; 4203 int64 file_size = 0;
4207 file_util::GetFileSize(app_path, &file_size); 4204 file_util::GetFileSize(app_path, &file_size);
4208 4205
4209 EXPECT_FALSE(r.is_pending()); 4206 EXPECT_FALSE(r.is_pending());
4210 EXPECT_EQ(1, d.response_started_count()); 4207 EXPECT_EQ(1, d.response_started_count());
4211 EXPECT_FALSE(d.received_data_before_response()); 4208 EXPECT_FALSE(d.received_data_before_response());
4212 EXPECT_EQ(d.bytes_received(), 0); 4209 EXPECT_EQ(d.bytes_received(), 0);
4213 } 4210 }
4214 } 4211 }
4215 4212
4216 // Flaky, see http://crbug.com/25045. 4213 // Flaky, see http://crbug.com/25045.
4217 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPasswordRestart) { 4214 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPasswordRestart) {
4218 ASSERT_TRUE(test_server_.Start()); 4215 ASSERT_TRUE(test_server_.Start());
4219 4216
4220 FilePath app_path; 4217 FilePath app_path;
4221 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 4218 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
4222 app_path = app_path.AppendASCII("LICENSE"); 4219 app_path = app_path.AppendASCII("LICENSE");
4223 TestDelegate d; 4220 TestDelegate d;
4224 // Set correct login credentials. The delegate will be asked for them when 4221 // Set correct login credentials. The delegate will be asked for them when
4225 // the initial login with wrong credentials will fail. 4222 // the initial login with wrong credentials will fail.
4226 d.set_credentials(AuthCredentials(kChrome, kChrome)); 4223 d.set_credentials(AuthCredentials(kChrome, kChrome));
4227 { 4224 {
4228 TestURLRequest r( 4225 URLRequest r(
4229 test_server_.GetURLWithUserAndPassword("/LICENSE", 4226 test_server_.GetURLWithUserAndPassword("/LICENSE",
4230 "chrome", 4227 "chrome",
4231 "wrong_password"), 4228 "wrong_password"),
4232 &d); 4229 &d);
4233 r.set_context(default_context_); 4230 r.set_context(&default_context_);
4234 r.Start(); 4231 r.Start();
4235 EXPECT_TRUE(r.is_pending()); 4232 EXPECT_TRUE(r.is_pending());
4236 4233
4237 MessageLoop::current()->Run(); 4234 MessageLoop::current()->Run();
4238 4235
4239 int64 file_size = 0; 4236 int64 file_size = 0;
4240 file_util::GetFileSize(app_path, &file_size); 4237 file_util::GetFileSize(app_path, &file_size);
4241 4238
4242 EXPECT_FALSE(r.is_pending()); 4239 EXPECT_FALSE(r.is_pending());
4243 EXPECT_EQ(1, d.response_started_count()); 4240 EXPECT_EQ(1, d.response_started_count());
4244 EXPECT_FALSE(d.received_data_before_response()); 4241 EXPECT_FALSE(d.received_data_before_response());
4245 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 4242 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
4246 } 4243 }
4247 } 4244 }
4248 4245
4249 // Flaky, see http://crbug.com/25045. 4246 // Flaky, see http://crbug.com/25045.
4250 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) { 4247 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) {
4251 ASSERT_TRUE(test_server_.Start()); 4248 ASSERT_TRUE(test_server_.Start());
4252 4249
4253 FilePath app_path; 4250 FilePath app_path;
4254 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 4251 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
4255 app_path = app_path.AppendASCII("LICENSE"); 4252 app_path = app_path.AppendASCII("LICENSE");
4256 TestDelegate d; 4253 TestDelegate d;
4257 { 4254 {
4258 TestURLRequest r( 4255 URLRequest r(
4259 test_server_.GetURLWithUserAndPassword("/LICENSE", 4256 test_server_.GetURLWithUserAndPassword("/LICENSE",
4260 "wrong_user", 4257 "wrong_user",
4261 "chrome"), 4258 "chrome"),
4262 &d); 4259 &d);
4263 r.set_context(default_context_); 4260 r.set_context(&default_context_);
4264 r.Start(); 4261 r.Start();
4265 EXPECT_TRUE(r.is_pending()); 4262 EXPECT_TRUE(r.is_pending());
4266 4263
4267 MessageLoop::current()->Run(); 4264 MessageLoop::current()->Run();
4268 4265
4269 int64 file_size = 0; 4266 int64 file_size = 0;
4270 file_util::GetFileSize(app_path, &file_size); 4267 file_util::GetFileSize(app_path, &file_size);
4271 4268
4272 EXPECT_FALSE(r.is_pending()); 4269 EXPECT_FALSE(r.is_pending());
4273 EXPECT_EQ(1, d.response_started_count()); 4270 EXPECT_EQ(1, d.response_started_count());
4274 EXPECT_FALSE(d.received_data_before_response()); 4271 EXPECT_FALSE(d.received_data_before_response());
4275 EXPECT_EQ(d.bytes_received(), 0); 4272 EXPECT_EQ(d.bytes_received(), 0);
4276 } 4273 }
4277 } 4274 }
4278 4275
4279 // Flaky, see http://crbug.com/25045. 4276 // Flaky, see http://crbug.com/25045.
4280 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUserRestart) { 4277 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUserRestart) {
4281 ASSERT_TRUE(test_server_.Start()); 4278 ASSERT_TRUE(test_server_.Start());
4282 4279
4283 FilePath app_path; 4280 FilePath app_path;
4284 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 4281 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
4285 app_path = app_path.AppendASCII("LICENSE"); 4282 app_path = app_path.AppendASCII("LICENSE");
4286 TestDelegate d; 4283 TestDelegate d;
4287 // Set correct login credentials. The delegate will be asked for them when 4284 // Set correct login credentials. The delegate will be asked for them when
4288 // the initial login with wrong credentials will fail. 4285 // the initial login with wrong credentials will fail.
4289 d.set_credentials(AuthCredentials(kChrome, kChrome)); 4286 d.set_credentials(AuthCredentials(kChrome, kChrome));
4290 { 4287 {
4291 TestURLRequest r( 4288 URLRequest r(
4292 test_server_.GetURLWithUserAndPassword("/LICENSE", 4289 test_server_.GetURLWithUserAndPassword("/LICENSE",
4293 "wrong_user", 4290 "wrong_user",
4294 "chrome"), 4291 "chrome"),
4295 &d); 4292 &d);
4296 r.set_context(default_context_); 4293 r.set_context(&default_context_);
4297 r.Start(); 4294 r.Start();
4298 EXPECT_TRUE(r.is_pending()); 4295 EXPECT_TRUE(r.is_pending());
4299 4296
4300 MessageLoop::current()->Run(); 4297 MessageLoop::current()->Run();
4301 4298
4302 int64 file_size = 0; 4299 int64 file_size = 0;
4303 file_util::GetFileSize(app_path, &file_size); 4300 file_util::GetFileSize(app_path, &file_size);
4304 4301
4305 EXPECT_FALSE(r.is_pending()); 4302 EXPECT_FALSE(r.is_pending());
4306 EXPECT_EQ(1, d.response_started_count()); 4303 EXPECT_EQ(1, d.response_started_count());
4307 EXPECT_FALSE(d.received_data_before_response()); 4304 EXPECT_FALSE(d.received_data_before_response());
4308 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 4305 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
4309 } 4306 }
4310 } 4307 }
4311 4308
4312 // Flaky, see http://crbug.com/25045. 4309 // Flaky, see http://crbug.com/25045.
4313 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheURLCredentials) { 4310 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheURLCredentials) {
4314 ASSERT_TRUE(test_server_.Start()); 4311 ASSERT_TRUE(test_server_.Start());
4315 4312
4316 FilePath app_path; 4313 FilePath app_path;
4317 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 4314 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
4318 app_path = app_path.AppendASCII("LICENSE"); 4315 app_path = app_path.AppendASCII("LICENSE");
4319 4316
4320 scoped_ptr<TestDelegate> d(new TestDelegate); 4317 scoped_ptr<TestDelegate> d(new TestDelegate);
4321 { 4318 {
4322 // Pass correct login identity in the URL. 4319 // Pass correct login identity in the URL.
4323 TestURLRequest r( 4320 URLRequest r(
4324 test_server_.GetURLWithUserAndPassword("/LICENSE", 4321 test_server_.GetURLWithUserAndPassword("/LICENSE",
4325 "chrome", 4322 "chrome",
4326 "chrome"), 4323 "chrome"),
4327 d.get()); 4324 d.get());
4328 r.set_context(default_context_); 4325 r.set_context(&default_context_);
4329 r.Start(); 4326 r.Start();
4330 EXPECT_TRUE(r.is_pending()); 4327 EXPECT_TRUE(r.is_pending());
4331 4328
4332 MessageLoop::current()->Run(); 4329 MessageLoop::current()->Run();
4333 4330
4334 int64 file_size = 0; 4331 int64 file_size = 0;
4335 file_util::GetFileSize(app_path, &file_size); 4332 file_util::GetFileSize(app_path, &file_size);
4336 4333
4337 EXPECT_FALSE(r.is_pending()); 4334 EXPECT_FALSE(r.is_pending());
4338 EXPECT_EQ(1, d->response_started_count()); 4335 EXPECT_EQ(1, d->response_started_count());
4339 EXPECT_FALSE(d->received_data_before_response()); 4336 EXPECT_FALSE(d->received_data_before_response());
4340 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 4337 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
4341 } 4338 }
4342 4339
4343 d.reset(new TestDelegate); 4340 d.reset(new TestDelegate);
4344 { 4341 {
4345 // This request should use cached identity from previous request. 4342 // This request should use cached identity from previous request.
4346 TestURLRequest r(test_server_.GetURL("/LICENSE"), d.get()); 4343 URLRequest r(test_server_.GetURL("/LICENSE"), d.get());
4347 r.set_context(default_context_); 4344 r.set_context(&default_context_);
4348 r.Start(); 4345 r.Start();
4349 EXPECT_TRUE(r.is_pending()); 4346 EXPECT_TRUE(r.is_pending());
4350 4347
4351 MessageLoop::current()->Run(); 4348 MessageLoop::current()->Run();
4352 4349
4353 int64 file_size = 0; 4350 int64 file_size = 0;
4354 file_util::GetFileSize(app_path, &file_size); 4351 file_util::GetFileSize(app_path, &file_size);
4355 4352
4356 EXPECT_FALSE(r.is_pending()); 4353 EXPECT_FALSE(r.is_pending());
4357 EXPECT_EQ(1, d->response_started_count()); 4354 EXPECT_EQ(1, d->response_started_count());
4358 EXPECT_FALSE(d->received_data_before_response()); 4355 EXPECT_FALSE(d->received_data_before_response());
4359 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 4356 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
4360 } 4357 }
4361 } 4358 }
4362 4359
4363 // Flaky, see http://crbug.com/25045. 4360 // Flaky, see http://crbug.com/25045.
4364 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheLoginBoxCredentials) { 4361 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheLoginBoxCredentials) {
4365 ASSERT_TRUE(test_server_.Start()); 4362 ASSERT_TRUE(test_server_.Start());
4366 4363
4367 FilePath app_path; 4364 FilePath app_path;
4368 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 4365 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
4369 app_path = app_path.AppendASCII("LICENSE"); 4366 app_path = app_path.AppendASCII("LICENSE");
4370 4367
4371 scoped_ptr<TestDelegate> d(new TestDelegate); 4368 scoped_ptr<TestDelegate> d(new TestDelegate);
4372 // Set correct login credentials. The delegate will be asked for them when 4369 // Set correct login credentials. The delegate will be asked for them when
4373 // the initial login with wrong credentials will fail. 4370 // the initial login with wrong credentials will fail.
4374 d->set_credentials(AuthCredentials(kChrome, kChrome)); 4371 d->set_credentials(AuthCredentials(kChrome, kChrome));
4375 { 4372 {
4376 TestURLRequest r( 4373 URLRequest r(
4377 test_server_.GetURLWithUserAndPassword("/LICENSE", 4374 test_server_.GetURLWithUserAndPassword("/LICENSE",
4378 "chrome", 4375 "chrome",
4379 "wrong_password"), 4376 "wrong_password"),
4380 d.get()); 4377 d.get());
4381 r.set_context(default_context_); 4378 r.set_context(&default_context_);
4382 r.Start(); 4379 r.Start();
4383 EXPECT_TRUE(r.is_pending()); 4380 EXPECT_TRUE(r.is_pending());
4384 4381
4385 MessageLoop::current()->Run(); 4382 MessageLoop::current()->Run();
4386 4383
4387 int64 file_size = 0; 4384 int64 file_size = 0;
4388 file_util::GetFileSize(app_path, &file_size); 4385 file_util::GetFileSize(app_path, &file_size);
4389 4386
4390 EXPECT_FALSE(r.is_pending()); 4387 EXPECT_FALSE(r.is_pending());
4391 EXPECT_EQ(1, d->response_started_count()); 4388 EXPECT_EQ(1, d->response_started_count());
4392 EXPECT_FALSE(d->received_data_before_response()); 4389 EXPECT_FALSE(d->received_data_before_response());
4393 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 4390 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
4394 } 4391 }
4395 4392
4396 // Use a new delegate without explicit credentials. The cached ones should be 4393 // Use a new delegate without explicit credentials. The cached ones should be
4397 // used. 4394 // used.
4398 d.reset(new TestDelegate); 4395 d.reset(new TestDelegate);
4399 { 4396 {
4400 // Don't pass wrong credentials in the URL, they would override valid cached 4397 // Don't pass wrong credentials in the URL, they would override valid cached
4401 // ones. 4398 // ones.
4402 TestURLRequest r(test_server_.GetURL("/LICENSE"), d.get()); 4399 URLRequest r(test_server_.GetURL("/LICENSE"), d.get());
4403 r.set_context(default_context_); 4400 r.set_context(&default_context_);
4404 r.Start(); 4401 r.Start();
4405 EXPECT_TRUE(r.is_pending()); 4402 EXPECT_TRUE(r.is_pending());
4406 4403
4407 MessageLoop::current()->Run(); 4404 MessageLoop::current()->Run();
4408 4405
4409 int64 file_size = 0; 4406 int64 file_size = 0;
4410 file_util::GetFileSize(app_path, &file_size); 4407 file_util::GetFileSize(app_path, &file_size);
4411 4408
4412 EXPECT_FALSE(r.is_pending()); 4409 EXPECT_FALSE(r.is_pending());
4413 EXPECT_EQ(1, d->response_started_count()); 4410 EXPECT_EQ(1, d->response_started_count());
4414 EXPECT_FALSE(d->received_data_before_response()); 4411 EXPECT_FALSE(d->received_data_before_response());
4415 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 4412 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
4416 } 4413 }
4417 } 4414 }
4418 4415
4419 // Check that default A-L header is sent. 4416 // Check that default A-L header is sent.
4420 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { 4417 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) {
4421 ASSERT_TRUE(test_server_.Start()); 4418 ASSERT_TRUE(test_server_.Start());
4422 4419
4423 TestNetworkDelegate network_delegate; // must outlive URLRequests 4420 TestNetworkDelegate network_delegate; // must outlive URLRequests
4424 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 4421 TestURLRequestContext context(true);
4425 context->set_network_delegate(&network_delegate); 4422 context.set_network_delegate(&network_delegate);
4426 context->set_accept_language("en"); 4423 context.set_accept_language("en");
4427 context->Init(); 4424 context.Init();
4428 4425
4429 TestDelegate d; 4426 TestDelegate d;
4430 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); 4427 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d);
4431 req.set_context(context); 4428 req.set_context(&context);
4432 req.Start(); 4429 req.Start();
4433 MessageLoop::current()->Run(); 4430 MessageLoop::current()->Run();
4434 EXPECT_EQ("en", d.data_received()); 4431 EXPECT_EQ("en", d.data_received());
4435 } 4432 }
4436 4433
4437 // Check that an empty A-L header is not sent. http://crbug.com/77365. 4434 // Check that an empty A-L header is not sent. http://crbug.com/77365.
4438 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { 4435 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) {
4439 ASSERT_TRUE(test_server_.Start()); 4436 ASSERT_TRUE(test_server_.Start());
4440 4437
4441 TestNetworkDelegate network_delegate; // must outlive URLRequests 4438 TestNetworkDelegate network_delegate; // must outlive URLRequests
4442 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 4439 TestURLRequestContext context(true);
4443 context->set_network_delegate(&network_delegate); 4440 context.set_network_delegate(&network_delegate);
4444 context->Init(); 4441 context.Init();
4445 // We override the language after initialization because empty entries 4442 // We override the language after initialization because empty entries
4446 // get overridden by Init(). 4443 // get overridden by Init().
4447 context->set_accept_language(""); 4444 context.set_accept_language("");
4448 4445
4449 TestDelegate d; 4446 TestDelegate d;
4450 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); 4447 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d);
4451 req.set_context(context); 4448 req.set_context(&context);
4452 req.Start(); 4449 req.Start();
4453 MessageLoop::current()->Run(); 4450 MessageLoop::current()->Run();
4454 EXPECT_EQ("None", d.data_received()); 4451 EXPECT_EQ("None", d.data_received());
4455 } 4452 }
4456 4453
4457 // Check that if request overrides the A-L header, the default is not appended. 4454 // Check that if request overrides the A-L header, the default is not appended.
4458 // See http://crbug.com/20894 4455 // See http://crbug.com/20894
4459 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { 4456 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) {
4460 ASSERT_TRUE(test_server_.Start()); 4457 ASSERT_TRUE(test_server_.Start());
4461 4458
4462 TestDelegate d; 4459 TestDelegate d;
4463 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); 4460 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d);
4464 req.set_context(default_context_); 4461 req.set_context(&default_context_);
4465 HttpRequestHeaders headers; 4462 HttpRequestHeaders headers;
4466 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); 4463 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru");
4467 req.SetExtraRequestHeaders(headers); 4464 req.SetExtraRequestHeaders(headers);
4468 req.Start(); 4465 req.Start();
4469 MessageLoop::current()->Run(); 4466 MessageLoop::current()->Run();
4470 EXPECT_EQ(std::string("ru"), d.data_received()); 4467 EXPECT_EQ(std::string("ru"), d.data_received());
4471 } 4468 }
4472 4469
4473 // Check that default A-E header is sent. 4470 // Check that default A-E header is sent.
4474 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { 4471 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) {
4475 ASSERT_TRUE(test_server_.Start()); 4472 ASSERT_TRUE(test_server_.Start());
4476 4473
4477 TestDelegate d; 4474 TestDelegate d;
4478 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), &d); 4475 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), &d);
4479 req.set_context(default_context_); 4476 req.set_context(&default_context_);
4480 HttpRequestHeaders headers; 4477 HttpRequestHeaders headers;
4481 req.SetExtraRequestHeaders(headers); 4478 req.SetExtraRequestHeaders(headers);
4482 req.Start(); 4479 req.Start();
4483 MessageLoop::current()->Run(); 4480 MessageLoop::current()->Run();
4484 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); 4481 EXPECT_TRUE(ContainsString(d.data_received(), "gzip"));
4485 } 4482 }
4486 4483
4487 // Check that if request overrides the A-E header, the default is not appended. 4484 // Check that if request overrides the A-E header, the default is not appended.
4488 // See http://crbug.com/47381 4485 // See http://crbug.com/47381
4489 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { 4486 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) {
4490 ASSERT_TRUE(test_server_.Start()); 4487 ASSERT_TRUE(test_server_.Start());
4491 4488
4492 TestDelegate d; 4489 TestDelegate d;
4493 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), &d); 4490 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), &d);
4494 req.set_context(default_context_); 4491 req.set_context(&default_context_);
4495 HttpRequestHeaders headers; 4492 HttpRequestHeaders headers;
4496 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); 4493 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity");
4497 req.SetExtraRequestHeaders(headers); 4494 req.SetExtraRequestHeaders(headers);
4498 req.Start(); 4495 req.Start();
4499 MessageLoop::current()->Run(); 4496 MessageLoop::current()->Run();
4500 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); 4497 EXPECT_FALSE(ContainsString(d.data_received(), "gzip"));
4501 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); 4498 EXPECT_TRUE(ContainsString(d.data_received(), "identity"));
4502 } 4499 }
4503 4500
4504 // Check that default A-C header is sent. 4501 // Check that default A-C header is sent.
4505 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { 4502 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) {
4506 ASSERT_TRUE(test_server_.Start()); 4503 ASSERT_TRUE(test_server_.Start());
4507 4504
4508 TestNetworkDelegate network_delegate; // must outlive URLRequests 4505 TestNetworkDelegate network_delegate; // must outlive URLRequests
4509 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 4506 TestURLRequestContext context(true);
4510 context->set_network_delegate(&network_delegate); 4507 context.set_network_delegate(&network_delegate);
4511 context->set_accept_charset("en"); 4508 context.set_accept_charset("en");
4512 context->Init(); 4509 context.Init();
4513 4510
4514 TestDelegate d; 4511 TestDelegate d;
4515 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); 4512 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d);
4516 req.set_context(context); 4513 req.set_context(&context);
4517 req.Start(); 4514 req.Start();
4518 MessageLoop::current()->Run(); 4515 MessageLoop::current()->Run();
4519 EXPECT_EQ("en", d.data_received()); 4516 EXPECT_EQ("en", d.data_received());
4520 } 4517 }
4521 4518
4522 // Check that an empty A-C header is not sent. http://crbug.com/77365. 4519 // Check that an empty A-C header is not sent. http://crbug.com/77365.
4523 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) { 4520 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) {
4524 ASSERT_TRUE(test_server_.Start()); 4521 ASSERT_TRUE(test_server_.Start());
4525 4522
4526 TestNetworkDelegate network_delegate; // must outlive URLRequests 4523 TestNetworkDelegate network_delegate; // must outlive URLRequests
4527 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); 4524 TestURLRequestContext context(true);
4528 context->set_network_delegate(&network_delegate); 4525 context.set_network_delegate(&network_delegate);
4529 context->Init(); 4526 context.Init();
4530 // We override the accepted charset after initialization because empty 4527 // We override the accepted charset after initialization because empty
4531 // entries get overridden otherwise. 4528 // entries get overridden otherwise.
4532 context->set_accept_charset(""); 4529 context.set_accept_charset("");
4533 4530
4534 TestDelegate d; 4531 TestDelegate d;
4535 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); 4532 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d);
4536 req.set_context(context); 4533 req.set_context(&context);
4537 req.Start(); 4534 req.Start();
4538 MessageLoop::current()->Run(); 4535 MessageLoop::current()->Run();
4539 EXPECT_EQ("None", d.data_received()); 4536 EXPECT_EQ("None", d.data_received());
4540 } 4537 }
4541 4538
4542 // Check that if request overrides the A-C header, the default is not appended. 4539 // Check that if request overrides the A-C header, the default is not appended.
4543 // See http://crbug.com/20894 4540 // See http://crbug.com/20894
4544 TEST_F(URLRequestTestHTTP, OverrideAcceptCharset) { 4541 TEST_F(URLRequestTestHTTP, OverrideAcceptCharset) {
4545 ASSERT_TRUE(test_server_.Start()); 4542 ASSERT_TRUE(test_server_.Start());
4546 4543
4547 TestDelegate d; 4544 TestDelegate d;
4548 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); 4545 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d);
4549 req.set_context(default_context_); 4546 req.set_context(&default_context_);
4550 HttpRequestHeaders headers; 4547 HttpRequestHeaders headers;
4551 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); 4548 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r");
4552 req.SetExtraRequestHeaders(headers); 4549 req.SetExtraRequestHeaders(headers);
4553 req.Start(); 4550 req.Start();
4554 MessageLoop::current()->Run(); 4551 MessageLoop::current()->Run();
4555 EXPECT_EQ(std::string("koi-8r"), d.data_received()); 4552 EXPECT_EQ(std::string("koi-8r"), d.data_received());
4556 } 4553 }
4557 4554
4558 // Check that default User-Agent header is sent. 4555 // Check that default User-Agent header is sent.
4559 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { 4556 TEST_F(URLRequestTestHTTP, DefaultUserAgent) {
4560 ASSERT_TRUE(test_server_.Start()); 4557 ASSERT_TRUE(test_server_.Start());
4561 4558
4562 TestDelegate d; 4559 TestDelegate d;
4563 TestURLRequest req(test_server_.GetURL("echoheader?User-Agent"), &d); 4560 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), &d);
4564 req.set_context(default_context_); 4561 req.set_context(&default_context_);
4565 req.Start(); 4562 req.Start();
4566 MessageLoop::current()->Run(); 4563 MessageLoop::current()->Run();
4567 EXPECT_EQ(req.context()->GetUserAgent(req.url()), d.data_received()); 4564 EXPECT_EQ(req.context()->GetUserAgent(req.url()), d.data_received());
4568 } 4565 }
4569 4566
4570 // Check that if request overrides the User-Agent header, 4567 // Check that if request overrides the User-Agent header,
4571 // the default is not appended. 4568 // the default is not appended.
4572 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { 4569 TEST_F(URLRequestTestHTTP, OverrideUserAgent) {
4573 ASSERT_TRUE(test_server_.Start()); 4570 ASSERT_TRUE(test_server_.Start());
4574 4571
4575 TestDelegate d; 4572 TestDelegate d;
4576 TestURLRequest req(test_server_.GetURL("echoheader?User-Agent"), &d); 4573 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), &d);
4577 req.set_context(default_context_); 4574 req.set_context(&default_context_);
4578 HttpRequestHeaders headers; 4575 HttpRequestHeaders headers;
4579 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); 4576 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)");
4580 req.SetExtraRequestHeaders(headers); 4577 req.SetExtraRequestHeaders(headers);
4581 req.Start(); 4578 req.Start();
4582 MessageLoop::current()->Run(); 4579 MessageLoop::current()->Run();
4583 // If the net tests are being run with ChromeFrame then we need to allow for 4580 // If the net tests are being run with ChromeFrame then we need to allow for
4584 // the 'chromeframe' suffix which is added to the user agent before the 4581 // the 'chromeframe' suffix which is added to the user agent before the
4585 // closing parentheses. 4582 // closing parentheses.
4586 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); 4583 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true));
4587 } 4584 }
4588 4585
4589 } // namespace net 4586 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_test_util.cc ('k') | net/url_request/view_cache_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698