| 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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), | 346 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 347 request->GetTotalSentBytes()); | 347 request->GetTotalSentBytes()); |
| 348 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 348 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 349 request->GetTotalReceivedBytes()); | 349 request->GetTotalReceivedBytes()); |
| 350 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), | 350 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 351 network_delegate_.total_network_bytes_sent()); | 351 network_delegate_.total_network_bytes_sent()); |
| 352 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 352 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 353 network_delegate_.total_network_bytes_received()); | 353 network_delegate_.total_network_bytes_received()); |
| 354 } | 354 } |
| 355 | 355 |
| 356 // Similar to the test above except it creates 2 URL Requests so that one fails |
| 357 // the other is in the validation stage due to Shared Writing. |
| 358 TEST_F(URLRequestHttpJobWithMockSocketsTest, TestContentLengthFailedRequest2) { |
| 359 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 360 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 361 "Content-Length: 20\r\n\r\n"), |
| 362 MockRead("Test Content"), |
| 363 MockRead(net::SYNCHRONOUS, net::ERR_FAILED)}; |
| 364 |
| 365 int kNumRequests = 3; |
| 366 |
| 367 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 368 arraysize(writes)); |
| 369 StaticSocketDataProvider socket_data1(reads, arraysize(reads), writes, |
| 370 arraysize(writes)); |
| 371 |
| 372 StaticSocketDataProvider socket_data2(reads, arraysize(reads), writes, |
| 373 arraysize(writes)); |
| 374 |
| 375 socket_factory_.AddSocketDataProvider(&socket_data); |
| 376 socket_factory_.AddSocketDataProvider(&socket_data1); |
| 377 socket_factory_.AddSocketDataProvider(&socket_data2); |
| 378 |
| 379 std::vector<TestDelegate> delegates(kNumRequests); |
| 380 std::vector<std::unique_ptr<URLRequest>> requests(kNumRequests); |
| 381 |
| 382 for (int i = 0; i < kNumRequests; i++) { |
| 383 requests[i] = context_->CreateRequest(GURL("http://www.example.com"), |
| 384 DEFAULT_PRIORITY, &delegates[i]); |
| 385 requests[i]->Start(); |
| 386 ASSERT_TRUE(requests[i]->is_pending()); |
| 387 } |
| 388 |
| 389 base::RunLoop().Run(); |
| 390 |
| 391 EXPECT_THAT(delegates[0].request_status(), IsError(ERR_FAILED)); |
| 392 EXPECT_EQ(12, requests[0]->received_response_content_length()); |
| 393 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 394 requests[0]->GetTotalSentBytes()); |
| 395 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 396 requests[0]->GetTotalReceivedBytes()); |
| 397 EXPECT_EQ(3 * CountWriteBytes(writes, arraysize(writes)), |
| 398 network_delegate_.total_network_bytes_sent()); |
| 399 EXPECT_EQ(3 * CountReadBytes(reads, arraysize(reads)), |
| 400 network_delegate_.total_network_bytes_received()); |
| 401 } |
| 402 |
| 356 TEST_F(URLRequestHttpJobWithMockSocketsTest, | 403 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 357 TestContentLengthCancelledRequest) { | 404 TestContentLengthCancelledRequest) { |
| 358 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | 405 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 359 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 406 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 360 "Content-Length: 20\r\n\r\n"), | 407 "Content-Length: 20\r\n\r\n"), |
| 361 MockRead("Test Content"), | 408 MockRead("Test Content"), |
| 362 MockRead(net::SYNCHRONOUS, net::ERR_IO_PENDING)}; | 409 MockRead(net::SYNCHRONOUS, net::ERR_IO_PENDING)}; |
| 363 | 410 |
| 364 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 411 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 365 arraysize(writes)); | 412 arraysize(writes)); |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 base::RunLoop().RunUntilIdle(); | 1143 base::RunLoop().RunUntilIdle(); |
| 1097 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING)); | 1144 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING)); |
| 1098 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 1145 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
| 1099 } | 1146 } |
| 1100 | 1147 |
| 1101 #endif // BUILDFLAG(ENABLE_WEBSOCKETS) | 1148 #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 1102 | 1149 |
| 1103 } // namespace | 1150 } // namespace |
| 1104 | 1151 |
| 1105 } // namespace net | 1152 } // namespace net |
| OLD | NEW |