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

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

Issue 2512263002: Pass raw response with Context-Encoding sdch if support is not configured. (Closed)
Patch Set: Address Helen's comments. Created 4 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
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | no next file » | 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) 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 #include <memory> 10 #include <memory>
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 new TestURLRequestHttpJob(request.get())); 154 new TestURLRequestHttpJob(request.get()));
155 test_job_interceptor_->set_main_intercept_job(std::move(job)); 155 test_job_interceptor_->set_main_intercept_job(std::move(job));
156 request->Start(); 156 request->Start();
157 157
158 base::RunLoop().Run(); 158 base::RunLoop().Run();
159 EXPECT_EQ(OK, delegate_.request_status()); 159 EXPECT_EQ(OK, delegate_.request_status());
160 EXPECT_EQ("Test Content", delegate_.data_received()); 160 EXPECT_EQ("Test Content", delegate_.data_received());
161 } 161 }
162 162
163 // Received a malformed SDCH encoded response when there is no SdchManager. 163 // Received a malformed SDCH encoded response when there is no SdchManager.
164 TEST_F(URLRequestHttpJobSetUpSourceTest, 164 TEST_F(URLRequestHttpJobSetUpSourceTest, SdchNotAdvertisedGotSdchResponse) {
165 SdchNotAdvertisedGotMalformedSdchResponse) {
166 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; 165 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)};
167 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" 166 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
168 "Content-Encoding: sdch\r\n" 167 "Content-Encoding: sdch\r\n"
169 "Content-Length: 12\r\n\r\n"), 168 "Content-Length: 12\r\n\r\n"),
170 MockRead("Test Content")}; 169 MockRead("Test Content")};
171 170
172 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, 171 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
173 arraysize(writes)); 172 arraysize(writes));
174 socket_factory_.AddSocketDataProvider(&socket_data); 173 socket_factory_.AddSocketDataProvider(&socket_data);
175 174
176 // This test expects TestURLRequestContexts to have no SdchManager. 175 // This test expects TestURLRequestContexts to have no SdchManager.
177 DCHECK(!context_.sdch_manager()); 176 DCHECK(!context_.sdch_manager());
178 177
179 std::unique_ptr<URLRequest> request = context_.CreateRequest( 178 std::unique_ptr<URLRequest> request = context_.CreateRequest(
180 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate_); 179 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate_);
181 std::unique_ptr<TestURLRequestHttpJob> job( 180 std::unique_ptr<TestURLRequestHttpJob> job(
182 new TestURLRequestHttpJob(request.get())); 181 new TestURLRequestHttpJob(request.get()));
183 test_job_interceptor_->set_main_intercept_job(std::move(job)); 182 test_job_interceptor_->set_main_intercept_job(std::move(job));
184 request->Start(); 183 request->Start();
185 184
186 base::RunLoop().Run(); 185 base::RunLoop().Run();
187 EXPECT_EQ(ERR_CONTENT_DECODING_INIT_FAILED, delegate_.request_status()); 186 // Pass through the raw response the same way as if received unknown encoding.
187 EXPECT_EQ(OK, delegate_.request_status());
188 EXPECT_EQ("Test Content", delegate_.data_received());
188 } 189 }
189 190
190 class URLRequestHttpJobTest : public ::testing::Test { 191 class URLRequestHttpJobTest : public ::testing::Test {
191 protected: 192 protected:
192 URLRequestHttpJobTest() : context_(true) { 193 URLRequestHttpJobTest() : context_(true) {
193 context_.set_http_transaction_factory(&network_layer_); 194 context_.set_http_transaction_factory(&network_layer_);
194 195
195 // The |test_job_factory_| takes ownership of the interceptor. 196 // The |test_job_factory_| takes ownership of the interceptor.
196 test_job_interceptor_ = new TestJobInterceptor(); 197 test_job_interceptor_ = new TestJobInterceptor();
197 EXPECT_TRUE(test_job_factory_.SetProtocolHandler( 198 EXPECT_TRUE(test_job_factory_.SetProtocolHandler(
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 new HttpNetworkSession::Params); 770 new HttpNetworkSession::Params);
770 context_.set_http_network_session_params(std::move(params)); 771 context_.set_http_network_session_params(std::move(params));
771 context_.set_client_socket_factory(&socket_factory_); 772 context_.set_client_socket_factory(&socket_factory_);
772 context_.Init(); 773 context_.Init();
773 } 774 }
774 775
775 MockClientSocketFactory socket_factory_; 776 MockClientSocketFactory socket_factory_;
776 TestURLRequestContext context_; 777 TestURLRequestContext context_;
777 }; 778 };
778 779
780 // Received a malformed SDCH encoded response that has no valid dictionary id.
781 TEST_F(URLRequestHttpJobWithSdchSupportTest,
782 SdchAdvertisedGotMalformedSdchResponse) {
783 MockWrite writes[] = {
784 MockWrite("GET / HTTP/1.1\r\n"
785 "Host: www.example.com\r\n"
786 "Connection: keep-alive\r\n"
787 "User-Agent:\r\n"
788 "Accept-Encoding: gzip, deflate, sdch\r\n"
789 "Accept-Language: en-us,fr\r\n\r\n")};
790 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
791 "Content-Encoding: sdch\r\n"
792 "Content-Length: 12\r\n\r\n"),
793 MockRead("Test Content")};
794
795 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
796 arraysize(writes));
797 socket_factory_.AddSocketDataProvider(&socket_data);
798
799 MockSdchObserver sdch_observer;
800 SdchManager sdch_manager;
801 sdch_manager.AddObserver(&sdch_observer);
802 context_.set_sdch_manager(&sdch_manager);
803 TestDelegate delegate;
804 std::unique_ptr<URLRequest> request = context_.CreateRequest(
805 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate);
806 request->Start();
807
808 base::RunLoop().Run();
809 // SdchPolicyDelegate::OnDictionaryIdError() detects that the response is
810 // malformed (missing dictionary), and will issue a pass-through of the raw
811 // response.
812 EXPECT_EQ(OK, delegate.request_status());
813 EXPECT_EQ("Test Content", delegate.data_received());
814 // Cleanup manager.
815 sdch_manager.RemoveObserver(&sdch_observer);
816 }
817
779 TEST_F(URLRequestHttpJobWithSdchSupportTest, GetDictionary) { 818 TEST_F(URLRequestHttpJobWithSdchSupportTest, GetDictionary) {
780 MockWrite writes[] = { 819 MockWrite writes[] = {
781 MockWrite("GET / HTTP/1.1\r\n" 820 MockWrite("GET / HTTP/1.1\r\n"
782 "Host: example.com\r\n" 821 "Host: example.com\r\n"
783 "Connection: keep-alive\r\n" 822 "Connection: keep-alive\r\n"
784 "User-Agent:\r\n" 823 "User-Agent:\r\n"
785 "Accept-Encoding: gzip, deflate, sdch\r\n" 824 "Accept-Encoding: gzip, deflate, sdch\r\n"
786 "Accept-Language: en-us,fr\r\n\r\n")}; 825 "Accept-Language: en-us,fr\r\n\r\n")};
787 826
788 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" 827 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 base::RunLoop().RunUntilIdle(); 1096 base::RunLoop().RunUntilIdle();
1058 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING)); 1097 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING));
1059 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); 1098 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called());
1060 } 1099 }
1061 1100
1062 #endif // BUILDFLAG(ENABLE_WEBSOCKETS) 1101 #endif // BUILDFLAG(ENABLE_WEBSOCKETS)
1063 1102
1064 } // namespace 1103 } // namespace
1065 1104
1066 } // namespace net 1105 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698