OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <cstddef> | 9 #include <cstddef> |
10 | 10 |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 | 624 |
625 // Confirm we don't advertise SDCH encoding in the case of a POST. | 625 // Confirm we don't advertise SDCH encoding in the case of a POST. |
626 TEST_F(URLRequestHttpJobTest, SdchAdvertisementPost) { | 626 TEST_F(URLRequestHttpJobTest, SdchAdvertisementPost) { |
627 EnableSdch(); | 627 EnableSdch(); |
628 req_->set_method("POST"); | 628 req_->set_method("POST"); |
629 scoped_ptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(req_.get())); | 629 scoped_ptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(req_.get())); |
630 job->Start(); | 630 job->Start(); |
631 EXPECT_FALSE(TransactionAcceptsSdchEncoding()); | 631 EXPECT_FALSE(TransactionAcceptsSdchEncoding()); |
632 } | 632 } |
633 | 633 |
| 634 class URLRequestHttpJobWithBrotliSupportTest : public ::testing::Test { |
| 635 protected: |
| 636 URLRequestHttpJobWithBrotliSupportTest() |
| 637 : context_(new TestURLRequestContext(true)) { |
| 638 scoped_ptr<HttpNetworkSession::Params> params( |
| 639 new HttpNetworkSession::Params); |
| 640 params->enable_brotli = true; |
| 641 context_->set_http_network_session_params(params.Pass()); |
| 642 context_->set_client_socket_factory(&socket_factory_); |
| 643 context_->Init(); |
| 644 } |
| 645 |
| 646 MockClientSocketFactory socket_factory_; |
| 647 scoped_ptr<TestURLRequestContext> context_; |
| 648 }; |
| 649 |
| 650 TEST_F(URLRequestHttpJobWithBrotliSupportTest, NoBrotliAdvertisementOverHttp) { |
| 651 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 652 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 653 "Content-Length: 12\r\n\r\n"), |
| 654 MockRead("Test Content")}; |
| 655 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 656 arraysize(writes)); |
| 657 socket_factory_.AddSocketDataProvider(&socket_data); |
| 658 |
| 659 TestDelegate delegate; |
| 660 scoped_ptr<URLRequest> request = |
| 661 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY, |
| 662 &delegate) |
| 663 .Pass(); |
| 664 request->Start(); |
| 665 base::RunLoop().RunUntilIdle(); |
| 666 |
| 667 EXPECT_TRUE(request->status().is_success()); |
| 668 EXPECT_EQ(12, request->received_response_content_length()); |
| 669 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 670 request->GetTotalSentBytes()); |
| 671 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 672 request->GetTotalReceivedBytes()); |
| 673 } |
| 674 |
| 675 TEST_F(URLRequestHttpJobWithBrotliSupportTest, BrotliAdvertisement) { |
| 676 net::SSLSocketDataProvider ssl_socket_data_provider(net::ASYNC, net::OK); |
| 677 ssl_socket_data_provider.SetNextProto(kProtoHTTP11); |
| 678 ssl_socket_data_provider.cert = |
| 679 ImportCertFromFile(GetTestCertsDirectory(), "unittest.selfsigned.der"); |
| 680 socket_factory_.AddSSLSocketDataProvider(&ssl_socket_data_provider); |
| 681 |
| 682 MockWrite writes[] = { |
| 683 MockWrite("GET / HTTP/1.1\r\n" |
| 684 "Host: www.example.com\r\n" |
| 685 "Connection: keep-alive\r\n" |
| 686 "User-Agent:\r\n" |
| 687 "Accept-Encoding: gzip, deflate, br\r\n" |
| 688 "Accept-Language: en-us,fr\r\n\r\n")}; |
| 689 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 690 "Content-Length: 12\r\n\r\n"), |
| 691 MockRead("Test Content")}; |
| 692 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 693 arraysize(writes)); |
| 694 socket_factory_.AddSocketDataProvider(&socket_data); |
| 695 |
| 696 TestDelegate delegate; |
| 697 scoped_ptr<URLRequest> request = |
| 698 context_->CreateRequest(GURL("https://www.example.com"), DEFAULT_PRIORITY, |
| 699 &delegate) |
| 700 .Pass(); |
| 701 request->Start(); |
| 702 base::RunLoop().RunUntilIdle(); |
| 703 |
| 704 EXPECT_TRUE(request->status().is_success()); |
| 705 EXPECT_EQ(12, request->received_response_content_length()); |
| 706 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 707 request->GetTotalSentBytes()); |
| 708 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 709 request->GetTotalReceivedBytes()); |
| 710 } |
| 711 |
634 // This base class just serves to set up some things before the TestURLRequest | 712 // This base class just serves to set up some things before the TestURLRequest |
635 // constructor is called. | 713 // constructor is called. |
636 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test { | 714 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test { |
637 protected: | 715 protected: |
638 URLRequestHttpJobWebSocketTestBase() : socket_data_(nullptr, 0, nullptr, 0), | 716 URLRequestHttpJobWebSocketTestBase() : socket_data_(nullptr, 0, nullptr, 0), |
639 context_(true) { | 717 context_(true) { |
640 // A Network Delegate is required for the WebSocketHandshakeStreamBase | 718 // A Network Delegate is required for the WebSocketHandshakeStreamBase |
641 // object to be passed on to the HttpNetworkTransaction. | 719 // object to be passed on to the HttpNetworkTransaction. |
642 context_.set_network_delegate(&network_delegate_); | 720 context_.set_network_delegate(&network_delegate_); |
643 | 721 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 req_->SetLoadFlags(LOAD_DISABLE_CACHE); | 869 req_->SetLoadFlags(LOAD_DISABLE_CACHE); |
792 job->Start(); | 870 job->Start(); |
793 base::RunLoop().RunUntilIdle(); | 871 base::RunLoop().RunUntilIdle(); |
794 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); | 872 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); |
795 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 873 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
796 } | 874 } |
797 | 875 |
798 } // namespace | 876 } // namespace |
799 | 877 |
800 } // namespace net | 878 } // namespace net |
OLD | NEW |