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

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: Rebaseline Created 4 years, 11 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
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 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 599
600 // Confirm we don't advertise SDCH encoding in the case of a POST. 600 // Confirm we don't advertise SDCH encoding in the case of a POST.
601 TEST_F(URLRequestHttpJobTest, SdchAdvertisementPost) { 601 TEST_F(URLRequestHttpJobTest, SdchAdvertisementPost) {
602 EnableSdch(); 602 EnableSdch();
603 req_->set_method("POST"); 603 req_->set_method("POST");
604 scoped_ptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(req_.get())); 604 scoped_ptr<TestURLRequestHttpJob> job(new TestURLRequestHttpJob(req_.get()));
605 job->Start(); 605 job->Start();
606 EXPECT_FALSE(TransactionAcceptsSdchEncoding()); 606 EXPECT_FALSE(TransactionAcceptsSdchEncoding());
607 } 607 }
608 608
609 class URLRequestHttpJobWithBrotliSupportTest : public ::testing::Test {
610 protected:
611 URLRequestHttpJobWithBrotliSupportTest()
612 : context_(new TestURLRequestContext(true)) {
613 scoped_ptr<HttpNetworkSession::Params> params(
614 new HttpNetworkSession::Params);
615 params->enable_brotli = true;
616 context_->set_http_network_session_params(std::move(params));
617 context_->set_client_socket_factory(&socket_factory_);
618 context_->Init();
619 }
620
621 MockClientSocketFactory socket_factory_;
622 scoped_ptr<TestURLRequestContext> context_;
623 };
624
625 TEST_F(URLRequestHttpJobWithBrotliSupportTest, NoBrotliAdvertisementOverHttp) {
626 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)};
627 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
628 "Content-Length: 12\r\n\r\n"),
629 MockRead("Test Content")};
630 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
631 arraysize(writes));
632 socket_factory_.AddSocketDataProvider(&socket_data);
633
634 TestDelegate delegate;
635 scoped_ptr<URLRequest> request =
636 context_->CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY,
637 &delegate)
638 .Pass();
639 request->Start();
640 base::RunLoop().RunUntilIdle();
641
642 EXPECT_TRUE(request->status().is_success());
643 EXPECT_EQ(12, request->received_response_content_length());
644 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
645 request->GetTotalSentBytes());
646 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
647 request->GetTotalReceivedBytes());
648 }
649
650 TEST_F(URLRequestHttpJobWithBrotliSupportTest, BrotliAdvertisement) {
651 net::SSLSocketDataProvider ssl_socket_data_provider(net::ASYNC, net::OK);
652 ssl_socket_data_provider.SetNextProto(kProtoHTTP11);
653 ssl_socket_data_provider.cert =
654 ImportCertFromFile(GetTestCertsDirectory(), "unittest.selfsigned.der");
655 socket_factory_.AddSSLSocketDataProvider(&ssl_socket_data_provider);
656
657 MockWrite writes[] = {
658 MockWrite("GET / HTTP/1.1\r\n"
659 "Host: www.example.com\r\n"
660 "Connection: keep-alive\r\n"
661 "User-Agent:\r\n"
662 "Accept-Encoding: gzip, deflate, br\r\n"
663 "Accept-Language: en-us,fr\r\n\r\n")};
664 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
665 "Content-Length: 12\r\n\r\n"),
666 MockRead("Test Content")};
667 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
668 arraysize(writes));
669 socket_factory_.AddSocketDataProvider(&socket_data);
670
671 TestDelegate delegate;
672 scoped_ptr<URLRequest> request =
673 context_->CreateRequest(GURL("https://www.example.com"), DEFAULT_PRIORITY,
674 &delegate)
675 .Pass();
676 request->Start();
677 base::RunLoop().RunUntilIdle();
678
679 EXPECT_TRUE(request->status().is_success());
680 EXPECT_EQ(12, request->received_response_content_length());
681 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
682 request->GetTotalSentBytes());
683 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
684 request->GetTotalReceivedBytes());
685 }
686
609 // This base class just serves to set up some things before the TestURLRequest 687 // This base class just serves to set up some things before the TestURLRequest
610 // constructor is called. 688 // constructor is called.
611 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test { 689 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test {
612 protected: 690 protected:
613 URLRequestHttpJobWebSocketTestBase() : socket_data_(nullptr, 0, nullptr, 0), 691 URLRequestHttpJobWebSocketTestBase() : socket_data_(nullptr, 0, nullptr, 0),
614 context_(true) { 692 context_(true) {
615 // A Network Delegate is required for the WebSocketHandshakeStreamBase 693 // A Network Delegate is required for the WebSocketHandshakeStreamBase
616 // object to be passed on to the HttpNetworkTransaction. 694 // object to be passed on to the HttpNetworkTransaction.
617 context_.set_network_delegate(&network_delegate_); 695 context_.set_network_delegate(&network_delegate_);
618 696
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 req_->SetLoadFlags(LOAD_DISABLE_CACHE); 844 req_->SetLoadFlags(LOAD_DISABLE_CACHE);
767 job->Start(); 845 job->Start();
768 base::RunLoop().RunUntilIdle(); 846 base::RunLoop().RunUntilIdle();
769 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); 847 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status());
770 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); 848 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called());
771 } 849 }
772 850
773 } // namespace 851 } // namespace
774 852
775 } // namespace net 853 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698