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

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

Issue 2753453003: Reject unadvertised encodings (Closed)
Patch Set: Reject unadvertised encodings. Created 3 years, 9 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 #include <memory> 10 #include <memory>
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 std::unique_ptr<TestURLRequestHttpJob> job( 135 std::unique_ptr<TestURLRequestHttpJob> job(
136 new TestURLRequestHttpJob(request.get())); 136 new TestURLRequestHttpJob(request.get()));
137 job->set_use_null_source_stream(true); 137 job->set_use_null_source_stream(true);
138 test_job_interceptor_->set_main_intercept_job(std::move(job)); 138 test_job_interceptor_->set_main_intercept_job(std::move(job));
139 request->Start(); 139 request->Start();
140 140
141 base::RunLoop().Run(); 141 base::RunLoop().Run();
142 EXPECT_EQ(ERR_CONTENT_DECODING_INIT_FAILED, delegate_.request_status()); 142 EXPECT_EQ(ERR_CONTENT_DECODING_INIT_FAILED, delegate_.request_status());
143 } 143 }
144 144
145 // Tests that if there is an unknown content-encoding type, the raw response 145 // Tests that if there is an unknown content-encoding type.
146 // body is passed through.
147 TEST_F(URLRequestHttpJobSetUpSourceTest, UnknownEncoding) { 146 TEST_F(URLRequestHttpJobSetUpSourceTest, UnknownEncoding) {
148 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; 147 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)};
149 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" 148 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
150 "Content-Encoding: foo, gzip\r\n" 149 "Content-Encoding: foo, gzip\r\n"
151 "Content-Length: 12\r\n\r\n"), 150 "Content-Length: 12\r\n\r\n"),
152 MockRead("Test Content")}; 151 MockRead("Test Content")};
153 152
154 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, 153 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
155 arraysize(writes)); 154 arraysize(writes));
156 socket_factory_.AddSocketDataProvider(&socket_data); 155 socket_factory_.AddSocketDataProvider(&socket_data);
157 156
158 std::unique_ptr<URLRequest> request = context_.CreateRequest( 157 std::unique_ptr<URLRequest> request = context_.CreateRequest(
159 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate_); 158 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate_);
160 std::unique_ptr<TestURLRequestHttpJob> job( 159 std::unique_ptr<TestURLRequestHttpJob> job(
161 new TestURLRequestHttpJob(request.get())); 160 new TestURLRequestHttpJob(request.get()));
162 test_job_interceptor_->set_main_intercept_job(std::move(job)); 161 test_job_interceptor_->set_main_intercept_job(std::move(job));
163 request->Start(); 162 request->Start();
164 163
165 base::RunLoop().Run(); 164 base::RunLoop().Run();
166 EXPECT_EQ(OK, delegate_.request_status()); 165 EXPECT_EQ(ERR_INVALID_CONTENT_ENCODING, delegate_.request_status());
167 EXPECT_EQ("Test Content", delegate_.data_received());
168 } 166 }
169 167
170 // Received a malformed SDCH encoded response when there is no SdchManager. 168 // Received a malformed SDCH encoded response when there is no SdchManager.
171 TEST_F(URLRequestHttpJobSetUpSourceTest, SdchNotAdvertisedGotSdchResponse) { 169 TEST_F(URLRequestHttpJobSetUpSourceTest, SdchNotAdvertisedGotSdchResponse) {
172 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; 170 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)};
173 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" 171 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
174 "Content-Encoding: sdch\r\n" 172 "Content-Encoding: sdch\r\n"
175 "Content-Length: 12\r\n\r\n"), 173 "Content-Length: 12\r\n\r\n"),
176 MockRead("Test Content")}; 174 MockRead("Test Content")};
177 175
178 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, 176 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
179 arraysize(writes)); 177 arraysize(writes));
180 socket_factory_.AddSocketDataProvider(&socket_data); 178 socket_factory_.AddSocketDataProvider(&socket_data);
181 179
182 // This test expects TestURLRequestContexts to have no SdchManager. 180 // This test expects TestURLRequestContexts to have no SdchManager.
183 DCHECK(!context_.sdch_manager()); 181 DCHECK(!context_.sdch_manager());
184 182
185 std::unique_ptr<URLRequest> request = context_.CreateRequest( 183 std::unique_ptr<URLRequest> request = context_.CreateRequest(
186 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate_); 184 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate_);
187 std::unique_ptr<TestURLRequestHttpJob> job( 185 std::unique_ptr<TestURLRequestHttpJob> job(
188 new TestURLRequestHttpJob(request.get())); 186 new TestURLRequestHttpJob(request.get()));
189 test_job_interceptor_->set_main_intercept_job(std::move(job)); 187 test_job_interceptor_->set_main_intercept_job(std::move(job));
190 request->Start(); 188 request->Start();
191 189
192 base::RunLoop().Run(); 190 base::RunLoop().Run();
193 // Pass through the raw response the same way as if received unknown encoding. 191 EXPECT_EQ(ERR_INVALID_CONTENT_ENCODING, delegate_.request_status());
194 EXPECT_EQ(OK, delegate_.request_status());
195 EXPECT_EQ("Test Content", delegate_.data_received());
196 } 192 }
197 193
198 class URLRequestHttpJobTest : public ::testing::Test { 194 class URLRequestHttpJobTest : public ::testing::Test {
199 protected: 195 protected:
200 URLRequestHttpJobTest() : context_(true) { 196 URLRequestHttpJobTest() : context_(true) {
201 context_.set_http_transaction_factory(&network_layer_); 197 context_.set_http_transaction_factory(&network_layer_);
202 198
203 // The |test_job_factory_| takes ownership of the interceptor. 199 // The |test_job_factory_| takes ownership of the interceptor.
204 test_job_interceptor_ = new TestJobInterceptor(); 200 test_job_interceptor_ = new TestJobInterceptor();
205 EXPECT_TRUE(test_job_factory_.SetProtocolHandler( 201 EXPECT_TRUE(test_job_factory_.SetProtocolHandler(
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 base::RunLoop().RunUntilIdle(); 1186 base::RunLoop().RunUntilIdle();
1191 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING)); 1187 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING));
1192 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); 1188 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called());
1193 } 1189 }
1194 1190
1195 #endif // BUILDFLAG(ENABLE_WEBSOCKETS) 1191 #endif // BUILDFLAG(ENABLE_WEBSOCKETS)
1196 1192
1197 } // namespace 1193 } // namespace
1198 1194
1199 } // namespace net 1195 } // namespace net
OLDNEW
« net/http/http_network_transaction.cc ('K') | « net/http/http_network_transaction_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698