Chromium Code Reviews| 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 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 // Confirm we don't advertise SDCH encoding in the case of a POST. | 622 // Confirm we don't advertise SDCH encoding in the case of a POST. |
| 623 TEST_F(URLRequestHttpJobTest, SdchAdvertisementPost) { | 623 TEST_F(URLRequestHttpJobTest, SdchAdvertisementPost) { |
| 624 EnableSdch(); | 624 EnableSdch(); |
| 625 req_->set_method("POST"); | 625 req_->set_method("POST"); |
| 626 scoped_refptr<TestURLRequestHttpJob> job( | 626 scoped_refptr<TestURLRequestHttpJob> job( |
| 627 new TestURLRequestHttpJob(req_.get())); | 627 new TestURLRequestHttpJob(req_.get())); |
| 628 job->Start(); | 628 job->Start(); |
| 629 EXPECT_FALSE(TransactionAcceptsSdchEncoding()); | 629 EXPECT_FALSE(TransactionAcceptsSdchEncoding()); |
| 630 } | 630 } |
| 631 | 631 |
| 632 class URLRequestHttpJobWithBrotliSupportTest : public ::testing::Test { | |
| 633 protected: | |
| 634 URLRequestHttpJobWithBrotliSupportTest() | |
| 635 : context_(new TestURLRequestContext(true)) { | |
| 636 scoped_ptr<HttpNetworkSession::Params> params( | |
| 637 new HttpNetworkSession::Params); | |
| 638 params->enable_brotli = true; | |
| 639 context_->set_http_network_session_params(params.Pass()); | |
| 640 context_->set_client_socket_factory(&socket_factory_); | |
| 641 context_->Init(); | |
| 642 } | |
| 643 | |
| 644 void RunRequest(const GURL& url) { | |
| 645 TestDelegate delegate; | |
| 646 scoped_ptr<URLRequest> request( | |
| 647 context_->CreateRequest(url, DEFAULT_PRIORITY, &delegate)); | |
| 648 request->Start(); | |
| 649 base::RunLoop().RunUntilIdle(); | |
| 650 EXPECT_NE(0, request->GetTotalSentBytes()); | |
|
xunjieli
2015/12/07 16:27:20
Why is this 0? It is because it is a GET request?
eustas
2015/12/08 11:31:31
Surely. Done.
| |
| 651 } | |
| 652 | |
| 653 MockClientSocketFactory socket_factory_; | |
| 654 | |
| 655 private: | |
| 656 scoped_ptr<TestURLRequestContext> context_; | |
| 657 }; | |
| 658 | |
| 659 TEST_F(URLRequestHttpJobWithBrotliSupportTest, NoBrotliAdvertisementOverHttp) { | |
| 660 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | |
| 661 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | |
| 662 "Content-Length: 12\r\n\r\n"), | |
| 663 MockRead("Test Content")}; | |
| 664 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | |
| 665 arraysize(writes)); | |
| 666 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 667 RunRequest(GURL("http://www.example.com")); | |
| 668 } | |
| 669 | |
| 670 TEST_F(URLRequestHttpJobWithBrotliSupportTest, BrotliAdvertisement) { | |
| 671 net::SSLSocketDataProvider ssl_socket_data_provider(net::ASYNC, net::OK); | |
| 672 ssl_socket_data_provider.SetNextProto(kProtoHTTP11); | |
| 673 ssl_socket_data_provider.cert = | |
| 674 ImportCertFromFile(GetTestCertsDirectory(), "unittest.selfsigned.der"); | |
| 675 socket_factory_.AddSSLSocketDataProvider(&ssl_socket_data_provider); | |
| 676 | |
| 677 MockWrite accept_brotli_encoding_writes[] = { | |
| 678 MockWrite("GET / HTTP/1.1\r\n" | |
| 679 "Host: www.example.com\r\n" | |
| 680 "Connection: keep-alive\r\n" | |
| 681 "User-Agent:\r\n" | |
| 682 "Accept-Encoding: gzip, deflate, br\r\n" | |
| 683 "Accept-Language: en-us,fr\r\n\r\n")}; | |
| 684 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | |
| 685 "Content-Length: 12\r\n\r\n"), | |
| 686 MockRead("Test Content")}; | |
| 687 StaticSocketDataProvider socket_data( | |
| 688 reads, arraysize(reads), accept_brotli_encoding_writes, | |
| 689 arraysize(accept_brotli_encoding_writes)); | |
| 690 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 691 RunRequest(GURL("https://www.example.com")); | |
| 692 } | |
| 693 | |
| 632 // This base class just serves to set up some things before the TestURLRequest | 694 // This base class just serves to set up some things before the TestURLRequest |
| 633 // constructor is called. | 695 // constructor is called. |
| 634 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test { | 696 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test { |
| 635 protected: | 697 protected: |
| 636 URLRequestHttpJobWebSocketTestBase() : socket_data_(nullptr, 0, nullptr, 0), | 698 URLRequestHttpJobWebSocketTestBase() : socket_data_(nullptr, 0, nullptr, 0), |
| 637 context_(true) { | 699 context_(true) { |
| 638 // A Network Delegate is required for the WebSocketHandshakeStreamBase | 700 // A Network Delegate is required for the WebSocketHandshakeStreamBase |
| 639 // object to be passed on to the HttpNetworkTransaction. | 701 // object to be passed on to the HttpNetworkTransaction. |
| 640 context_.set_network_delegate(&network_delegate_); | 702 context_.set_network_delegate(&network_delegate_); |
| 641 | 703 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 789 req_->SetLoadFlags(LOAD_DISABLE_CACHE); | 851 req_->SetLoadFlags(LOAD_DISABLE_CACHE); |
| 790 job->Start(); | 852 job->Start(); |
| 791 base::RunLoop().RunUntilIdle(); | 853 base::RunLoop().RunUntilIdle(); |
| 792 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); | 854 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); |
| 793 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 855 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
| 794 } | 856 } |
| 795 | 857 |
| 796 } // namespace | 858 } // namespace |
| 797 | 859 |
| 798 } // namespace net | 860 } // namespace net |
| OLD | NEW |