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 #include <memory> | 10 #include <memory> |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 request->GetTotalSentBytes()); | 260 request->GetTotalSentBytes()); |
| 261 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 261 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 262 request->GetTotalReceivedBytes()); | 262 request->GetTotalReceivedBytes()); |
| 263 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), | 263 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 264 network_delegate_.total_network_bytes_sent()); | 264 network_delegate_.total_network_bytes_sent()); |
| 265 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 265 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 266 network_delegate_.total_network_bytes_received()); | 266 network_delegate_.total_network_bytes_received()); |
| 267 } | 267 } |
| 268 | 268 |
| 269 TEST_F(URLRequestHttpJobWithMockSocketsTest, | 269 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 270 TestRawHeaderSizeSuccessfullRequest) { | |
| 271 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | |
| 272 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | |
| 273 "Content-Length: 12\r\n\r\n"), | |
| 274 MockRead("Test Content"), | |
| 275 MockRead(net::SYNCHRONOUS, net::OK)}; | |
| 276 | |
| 277 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | |
| 278 arraysize(writes)); | |
| 279 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 280 | |
| 281 TestDelegate delegate; | |
| 282 std::unique_ptr<URLRequest> request = context_->CreateRequest( | |
| 283 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | |
| 284 | |
| 285 request->Start(); | |
| 286 ASSERT_TRUE(request->is_pending()); | |
| 287 base::RunLoop().Run(); | |
| 288 | |
| 289 EXPECT_TRUE(request->status().is_success()); | |
| 290 EXPECT_EQ(12, request->received_response_content_length()); | |
| 291 EXPECT_EQ(39, request->raw_header_size()); | |
| 292 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | |
| 293 request->GetTotalReceivedBytes()); | |
| 294 } | |
| 295 | |
| 296 TEST_F(URLRequestHttpJobWithMockSocketsTest, | |
| 297 TestRawHeaderSizeSuccessfull100ContinueRequest) { | |
| 298 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | |
| 299 MockRead reads[] = {MockRead("HTTP/1.1 100 Continue\r\n\r\n"), | |
| 300 MockRead("HTTP/1.1 200 OK\r\n" | |
| 301 "Content-Length: 12\r\n\r\n"), | |
| 302 MockRead("Test Content"), | |
| 303 MockRead(net::SYNCHRONOUS, net::OK)}; | |
| 304 | |
| 305 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | |
| 306 arraysize(writes)); | |
| 307 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 308 | |
| 309 TestDelegate delegate; | |
| 310 std::unique_ptr<URLRequest> request = context_->CreateRequest( | |
| 311 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | |
| 312 | |
| 313 request->Start(); | |
| 314 ASSERT_TRUE(request->is_pending()); | |
| 315 base::RunLoop().Run(); | |
| 316 | |
| 317 EXPECT_TRUE(request->status().is_success()); | |
| 318 EXPECT_EQ(12, request->received_response_content_length()); | |
| 319 EXPECT_EQ(64, request->raw_header_size()); | |
| 320 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | |
| 321 request->GetTotalReceivedBytes()); | |
| 322 } | |
| 323 | |
| 324 TEST_F(URLRequestHttpJobWithMockSocketsTest, | |
| 325 TestRawHeaderSizeFailureTruncatedHeaders) { | |
| 326 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | |
| 327 MockRead reads[] = {MockRead("HTTP/1.0 200 OK\r\n" | |
| 328 "Content-Len"), | |
| 329 MockRead(net::SYNCHRONOUS, net::OK)}; | |
| 330 | |
| 331 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | |
| 332 arraysize(writes)); | |
| 333 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 334 | |
| 335 TestDelegate delegate; | |
| 336 std::unique_ptr<URLRequest> request = context_->CreateRequest( | |
| 337 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | |
| 338 | |
| 339 delegate.set_cancel_in_response_started(true); | |
| 340 request->Start(); | |
| 341 base::RunLoop().RunUntilIdle(); | |
| 342 | |
| 343 EXPECT_FALSE(request->status().is_success()); | |
|
mmenke
2016/09/06 18:55:00
Should expect on the error here, too (We're workin
allada
2016/09/07 06:01:12
Done.
| |
| 344 EXPECT_EQ(0, request->received_response_content_length()); | |
| 345 EXPECT_EQ(28, request->raw_header_size()); | |
| 346 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | |
| 347 request->GetTotalReceivedBytes()); | |
| 348 } | |
| 349 | |
| 350 TEST_F(URLRequestHttpJobWithMockSocketsTest, | |
| 351 TestRawHeaderSizeSuccessfullContinuiousRead) { | |
| 352 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | |
| 353 MockRead reads[] = { | |
| 354 MockRead("HTTP/1.1 200 OK\r\n" | |
| 355 "Content-Length: 12\r\n\r\n" | |
| 356 "Test Content")}; | |
| 357 | |
| 358 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | |
| 359 arraysize(writes)); | |
| 360 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 361 | |
| 362 TestDelegate delegate; | |
| 363 std::unique_ptr<URLRequest> request = context_->CreateRequest( | |
| 364 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); | |
| 365 | |
| 366 request->Start(); | |
| 367 base::RunLoop().Run(); | |
| 368 | |
| 369 EXPECT_TRUE(request->status().is_success()); | |
| 370 EXPECT_EQ(12, request->received_response_content_length()); | |
| 371 EXPECT_EQ(39, request->raw_header_size()); | |
| 372 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | |
| 373 request->GetTotalReceivedBytes()); | |
| 374 } | |
| 375 | |
|
mmenke
2016/09/06 18:55:00
Also, should we make sure the header size is reada
mmenke
2016/09/06 18:55:00
Should we have a test for the cached path? That w
mmenke
2016/09/06 18:55:00
Suggest an HTTP/0.9 test. (i.e., just a response
allada
2016/09/07 06:01:12
We have this kind of test in our tests: third_part
allada
2016/09/07 06:01:12
I can do a cached path, however, in our case it's
allada
2016/09/07 06:01:12
I was opting out of doing this kind of test since
mmenke
2016/09/07 15:18:21
My concern is just that we don't return nonsense.
mmenke
2016/09/07 15:18:21
Unfortunately, I don't think we'll be able to comp
allada
2016/09/07 18:14:56
What if we refuse to set the header size if the ve
| |
| 376 TEST_F(URLRequestHttpJobWithMockSocketsTest, | |
| 270 TestNetworkBytesRedirectedRequest) { | 377 TestNetworkBytesRedirectedRequest) { |
| 271 MockWrite redirect_writes[] = { | 378 MockWrite redirect_writes[] = { |
| 272 MockWrite("GET / HTTP/1.1\r\n" | 379 MockWrite("GET / HTTP/1.1\r\n" |
| 273 "Host: www.redirect.com\r\n" | 380 "Host: www.redirect.com\r\n" |
| 274 "Connection: keep-alive\r\n" | 381 "Connection: keep-alive\r\n" |
| 275 "User-Agent:\r\n" | 382 "User-Agent:\r\n" |
| 276 "Accept-Encoding: gzip, deflate\r\n" | 383 "Accept-Encoding: gzip, deflate\r\n" |
| 277 "Accept-Language: en-us,fr\r\n\r\n")}; | 384 "Accept-Language: en-us,fr\r\n\r\n")}; |
| 278 | 385 |
| 279 MockRead redirect_reads[] = { | 386 MockRead redirect_reads[] = { |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 818 base::RunLoop().RunUntilIdle(); | 925 base::RunLoop().RunUntilIdle(); |
| 819 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); | 926 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); |
| 820 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 927 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
| 821 } | 928 } |
| 822 | 929 |
| 823 #endif // defined(ENABLE_WEBSOCKETS) | 930 #endif // defined(ENABLE_WEBSOCKETS) |
| 824 | 931 |
| 825 } // namespace | 932 } // namespace |
| 826 | 933 |
| 827 } // namespace net | 934 } // namespace net |
| OLD | NEW |