| 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), | 352 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 353 request->GetTotalSentBytes()); | 353 request->GetTotalSentBytes()); |
| 354 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 354 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 355 request->GetTotalReceivedBytes()); | 355 request->GetTotalReceivedBytes()); |
| 356 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), | 356 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 357 network_delegate_.total_network_bytes_sent()); | 357 network_delegate_.total_network_bytes_sent()); |
| 358 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 358 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 359 network_delegate_.total_network_bytes_received()); | 359 network_delegate_.total_network_bytes_received()); |
| 360 } | 360 } |
| 361 | 361 |
| 362 // Similar to the test above except it creates multiple URL Requests so that |
| 363 // when one fails, the other is in the validation stage due to Shared Writing. |
| 364 TEST_F(URLRequestHttpJobWithMockSocketsTest, TestContentLengthFailedRequest2) { |
| 365 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 366 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 367 "Content-Length: 20\r\n\r\n"), |
| 368 MockRead("Test Content"), |
| 369 MockRead(net::SYNCHRONOUS, net::ERR_FAILED)}; |
| 370 |
| 371 int kNumRequests = 3; |
| 372 |
| 373 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 374 arraysize(writes)); |
| 375 StaticSocketDataProvider socket_data1(reads, arraysize(reads), writes, |
| 376 arraysize(writes)); |
| 377 |
| 378 StaticSocketDataProvider socket_data2(reads, arraysize(reads), writes, |
| 379 arraysize(writes)); |
| 380 |
| 381 socket_factory_.AddSocketDataProvider(&socket_data); |
| 382 socket_factory_.AddSocketDataProvider(&socket_data1); |
| 383 socket_factory_.AddSocketDataProvider(&socket_data2); |
| 384 |
| 385 std::vector<TestDelegate> delegates(kNumRequests); |
| 386 std::vector<std::unique_ptr<URLRequest>> requests(kNumRequests); |
| 387 |
| 388 for (int i = 0; i < kNumRequests; i++) { |
| 389 requests[i] = context_->CreateRequest(GURL("http://www.example.com"), |
| 390 DEFAULT_PRIORITY, &delegates[i]); |
| 391 requests[i]->Start(); |
| 392 ASSERT_TRUE(requests[i]->is_pending()); |
| 393 } |
| 394 |
| 395 base::RunLoop().Run(); |
| 396 |
| 397 EXPECT_THAT(delegates[0].request_status(), IsError(ERR_FAILED)); |
| 398 EXPECT_EQ(12, requests[0]->received_response_content_length()); |
| 399 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
| 400 requests[0]->GetTotalSentBytes()); |
| 401 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 402 requests[0]->GetTotalReceivedBytes()); |
| 403 // [1] request does not read the response body since its failed when current |
| 404 // writer transaction receives a network failure. [2] has not yet started so |
| 405 // it goes ahead and reads the response body. |
| 406 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 407 requests[2]->GetTotalReceivedBytes()); |
| 408 EXPECT_EQ(3 * CountWriteBytes(writes, arraysize(writes)), |
| 409 network_delegate_.total_network_bytes_sent()); |
| 410 // Hardcoding this number since [1] only receives the headers. |
| 411 EXPECT_EQ(2 * CountReadBytes(reads, arraysize(reads)) + 39, |
| 412 network_delegate_.total_network_bytes_received()); |
| 413 } |
| 414 |
| 362 TEST_F(URLRequestHttpJobWithMockSocketsTest, | 415 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 363 TestContentLengthCancelledRequest) { | 416 TestContentLengthCancelledRequest) { |
| 364 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; | 417 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 365 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" | 418 MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n" |
| 366 "Content-Length: 20\r\n\r\n"), | 419 "Content-Length: 20\r\n\r\n"), |
| 367 MockRead("Test Content"), | 420 MockRead("Test Content"), |
| 368 MockRead(net::SYNCHRONOUS, net::ERR_IO_PENDING)}; | 421 MockRead(net::SYNCHRONOUS, net::ERR_IO_PENDING)}; |
| 369 | 422 |
| 370 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | 423 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 371 arraysize(writes)); | 424 arraysize(writes)); |
| (...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 base::RunLoop().RunUntilIdle(); | 1195 base::RunLoop().RunUntilIdle(); |
| 1143 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING)); | 1196 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING)); |
| 1144 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 1197 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
| 1145 } | 1198 } |
| 1146 | 1199 |
| 1147 #endif // BUILDFLAG(ENABLE_WEBSOCKETS) | 1200 #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 1148 | 1201 |
| 1149 } // namespace | 1202 } // namespace |
| 1150 | 1203 |
| 1151 } // namespace net | 1204 } // namespace net |
| OLD | NEW |