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

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

Issue 1431723002: Add brotli content-encoding filter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Use SchemeIsCryptographic Created 5 years 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
OLDNEW
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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 // Confirm we don't advertise SDCH encoding in the case of a POST. 631 // Confirm we don't advertise SDCH encoding in the case of a POST.
632 TEST_F(URLRequestHttpJobTest, SdchAdvertisementPost) { 632 TEST_F(URLRequestHttpJobTest, SdchAdvertisementPost) {
633 EnableSdch(); 633 EnableSdch();
634 req_->set_method("POST"); 634 req_->set_method("POST");
635 scoped_refptr<TestURLRequestHttpJob> job( 635 scoped_refptr<TestURLRequestHttpJob> job(
636 new TestURLRequestHttpJob(req_.get())); 636 new TestURLRequestHttpJob(req_.get()));
637 job->Start(); 637 job->Start();
638 EXPECT_FALSE(TransactionAcceptsSdchEncoding()); 638 EXPECT_FALSE(TransactionAcceptsSdchEncoding());
639 } 639 }
640 640
641 class URLRequestHttpJobWithBrotliSupportTest : public ::testing::Test {
642 protected:
643 URLRequestHttpJobWithBrotliSupportTest()
644 : context_(new TestURLRequestContext(true)) {
645 scoped_ptr<HttpNetworkSession::Params> params(
646 new HttpNetworkSession::Params);
647 params->enable_brotli = true;
648 context_->set_http_network_session_params(params.Pass());
649 context_->set_client_socket_factory(&socket_factory_);
650 context_->Init();
651 }
652
653 MockClientSocketFactory socket_factory_;
654 scoped_ptr<TestURLRequestContext> context_;
655 };
656
657 TEST_F(URLRequestHttpJobWithBrotliSupportTest, NoBrotliAdvertisementOverHttp) {
658 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)};
659 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
660 "Content-Length: 12\r\n\r\n"),
661 MockRead("Test Content")};
662 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
663 arraysize(writes));
664 socket_factory_.AddSocketDataProvider(&socket_data);
665
666 TestDelegate delegate;
667 scoped_ptr<URLRequest> request =
668 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY,
669 &delegate)
670 .Pass();
671 request->Start();
672 base::RunLoop().RunUntilIdle();
673
674 EXPECT_TRUE(request->status().is_success());
675 EXPECT_EQ(12, request->received_response_content_length());
676 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
677 request->GetTotalSentBytes());
678 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
679 request->GetTotalReceivedBytes());
680 }
681
682 TEST_F(URLRequestHttpJobWithBrotliSupportTest, BrotliAdvertisement) {
683 net::SSLSocketDataProvider ssl_socket_data_provider(net::ASYNC, net::OK);
684 ssl_socket_data_provider.SetNextProto(kProtoHTTP11);
685 ssl_socket_data_provider.cert =
686 ImportCertFromFile(GetTestCertsDirectory(), "unittest.selfsigned.der");
687 socket_factory_.AddSSLSocketDataProvider(&ssl_socket_data_provider);
688
689 MockWrite writes[] = {
690 MockWrite("GET / HTTP/1.1\r\n"
691 "Host: www.example.com\r\n"
692 "Connection: keep-alive\r\n"
693 "User-Agent:\r\n"
694 "Accept-Encoding: gzip, deflate, br\r\n"
695 "Accept-Language: en-us,fr\r\n\r\n")};
696 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
697 "Content-Length: 12\r\n\r\n"),
698 MockRead("Test Content")};
699 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
700 arraysize(writes));
701 socket_factory_.AddSocketDataProvider(&socket_data);
702
703 TestDelegate delegate;
704 scoped_ptr<URLRequest> request =
705 context_->CreateRequest(GURL("https://www.example.com"), DEFAULT_PRIORITY,
706 &delegate)
707 .Pass();
708 request->Start();
709 base::RunLoop().RunUntilIdle();
710
711 EXPECT_TRUE(request->status().is_success());
712 EXPECT_EQ(12, request->received_response_content_length());
713 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
714 request->GetTotalSentBytes());
715 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
716 request->GetTotalReceivedBytes());
717 }
718
641 // This base class just serves to set up some things before the TestURLRequest 719 // This base class just serves to set up some things before the TestURLRequest
642 // constructor is called. 720 // constructor is called.
643 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test { 721 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test {
644 protected: 722 protected:
645 URLRequestHttpJobWebSocketTestBase() : socket_data_(nullptr, 0, nullptr, 0), 723 URLRequestHttpJobWebSocketTestBase() : socket_data_(nullptr, 0, nullptr, 0),
646 context_(true) { 724 context_(true) {
647 // A Network Delegate is required for the WebSocketHandshakeStreamBase 725 // A Network Delegate is required for the WebSocketHandshakeStreamBase
648 // object to be passed on to the HttpNetworkTransaction. 726 // object to be passed on to the HttpNetworkTransaction.
649 context_.set_network_delegate(&network_delegate_); 727 context_.set_network_delegate(&network_delegate_);
650 728
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 req_->SetLoadFlags(LOAD_DISABLE_CACHE); 876 req_->SetLoadFlags(LOAD_DISABLE_CACHE);
799 job->Start(); 877 job->Start();
800 base::RunLoop().RunUntilIdle(); 878 base::RunLoop().RunUntilIdle();
801 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); 879 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status());
802 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); 880 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called());
803 } 881 }
804 882
805 } // namespace 883 } // namespace
806 884
807 } // namespace net 885 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698