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 |
| 273 const std::string& response_header = |
| 274 "HTTP/1.1 200 OK\r\n" |
| 275 "Content-Length: 12\r\n\r\n"; |
| 276 const std::string& content_data = "Test Content"; |
| 277 |
| 278 MockRead reads[] = {MockRead(response_header.c_str()), |
| 279 MockRead(content_data.c_str()), |
| 280 MockRead(net::SYNCHRONOUS, net::OK)}; |
| 281 |
| 282 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 283 arraysize(writes)); |
| 284 socket_factory_.AddSocketDataProvider(&socket_data); |
| 285 |
| 286 TestDelegate delegate; |
| 287 std::unique_ptr<URLRequest> request = context_->CreateRequest( |
| 288 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); |
| 289 |
| 290 request->Start(); |
| 291 ASSERT_TRUE(request->is_pending()); |
| 292 base::RunLoop().Run(); |
| 293 |
| 294 EXPECT_EQ(net::OK, request->status().error()); |
| 295 EXPECT_EQ(static_cast<int>(content_data.size()), |
| 296 request->received_response_content_length()); |
| 297 EXPECT_EQ(static_cast<int>(response_header.size()), |
| 298 request->raw_header_size()); |
| 299 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 300 request->GetTotalReceivedBytes()); |
| 301 } |
| 302 |
| 303 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 304 TestRawHeaderSizeSuccessfull100ContinueRequest) { |
| 305 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 306 |
| 307 const std::string& continue_header = "HTTP/1.1 100 Continue\r\n\r\n"; |
| 308 const std::string& response_header = |
| 309 "HTTP/1.1 200 OK\r\n" |
| 310 "Content-Length: 12\r\n\r\n"; |
| 311 const std::string& content_data = "Test Content"; |
| 312 |
| 313 MockRead reads[] = { |
| 314 MockRead(continue_header.c_str()), MockRead(response_header.c_str()), |
| 315 MockRead(content_data.c_str()), MockRead(net::SYNCHRONOUS, net::OK)}; |
| 316 |
| 317 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 318 arraysize(writes)); |
| 319 socket_factory_.AddSocketDataProvider(&socket_data); |
| 320 |
| 321 TestDelegate delegate; |
| 322 std::unique_ptr<URLRequest> request = context_->CreateRequest( |
| 323 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); |
| 324 |
| 325 request->Start(); |
| 326 ASSERT_TRUE(request->is_pending()); |
| 327 base::RunLoop().Run(); |
| 328 |
| 329 EXPECT_EQ(net::OK, request->status().error()); |
| 330 EXPECT_EQ(static_cast<int>(content_data.size()), |
| 331 request->received_response_content_length()); |
| 332 EXPECT_EQ(static_cast<int>(continue_header.size() + response_header.size()), |
| 333 request->raw_header_size()); |
| 334 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 335 request->GetTotalReceivedBytes()); |
| 336 } |
| 337 |
| 338 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 339 TestRawHeaderSizeFailureTruncatedHeaders) { |
| 340 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 341 MockRead reads[] = {MockRead("HTTP/1.0 200 OK\r\n" |
| 342 "Content-Len"), |
| 343 MockRead(net::SYNCHRONOUS, net::OK)}; |
| 344 |
| 345 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 346 arraysize(writes)); |
| 347 socket_factory_.AddSocketDataProvider(&socket_data); |
| 348 |
| 349 TestDelegate delegate; |
| 350 std::unique_ptr<URLRequest> request = context_->CreateRequest( |
| 351 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); |
| 352 |
| 353 delegate.set_cancel_in_response_started(true); |
| 354 request->Start(); |
| 355 base::RunLoop().RunUntilIdle(); |
| 356 |
| 357 EXPECT_EQ(ERR_ABORTED, request->status().error()); |
| 358 EXPECT_EQ(0, request->received_response_content_length()); |
| 359 EXPECT_EQ(28, request->raw_header_size()); |
| 360 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 361 request->GetTotalReceivedBytes()); |
| 362 } |
| 363 |
| 364 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
| 365 TestRawHeaderSizeSuccessfullContinuiousRead) { |
| 366 MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)}; |
| 367 const std::string& header_data = |
| 368 "HTTP/1.1 200 OK\r\n" |
| 369 "Content-Length: 12\r\n\r\n"; |
| 370 const std::string& content_data = "Test Content"; |
| 371 std::string single_read_content = header_data; |
| 372 single_read_content.append(content_data); |
| 373 MockRead reads[] = {MockRead(single_read_content.c_str())}; |
| 374 |
| 375 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, |
| 376 arraysize(writes)); |
| 377 socket_factory_.AddSocketDataProvider(&socket_data); |
| 378 |
| 379 TestDelegate delegate; |
| 380 std::unique_ptr<URLRequest> request = context_->CreateRequest( |
| 381 GURL("http://www.example.com"), DEFAULT_PRIORITY, &delegate); |
| 382 |
| 383 request->Start(); |
| 384 base::RunLoop().Run(); |
| 385 |
| 386 EXPECT_EQ(net::OK, request->status().error()); |
| 387 EXPECT_EQ(static_cast<int>(content_data.size()), |
| 388 request->received_response_content_length()); |
| 389 EXPECT_EQ(static_cast<int>(header_data.size()), request->raw_header_size()); |
| 390 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
| 391 request->GetTotalReceivedBytes()); |
| 392 } |
| 393 |
| 394 TEST_F(URLRequestHttpJobWithMockSocketsTest, |
270 TestNetworkBytesRedirectedRequest) { | 395 TestNetworkBytesRedirectedRequest) { |
271 MockWrite redirect_writes[] = { | 396 MockWrite redirect_writes[] = { |
272 MockWrite("GET / HTTP/1.1\r\n" | 397 MockWrite("GET / HTTP/1.1\r\n" |
273 "Host: www.redirect.com\r\n" | 398 "Host: www.redirect.com\r\n" |
274 "Connection: keep-alive\r\n" | 399 "Connection: keep-alive\r\n" |
275 "User-Agent:\r\n" | 400 "User-Agent:\r\n" |
276 "Accept-Encoding: gzip, deflate\r\n" | 401 "Accept-Encoding: gzip, deflate\r\n" |
277 "Accept-Language: en-us,fr\r\n\r\n")}; | 402 "Accept-Language: en-us,fr\r\n\r\n")}; |
278 | 403 |
279 MockRead redirect_reads[] = { | 404 MockRead redirect_reads[] = { |
(...skipping 15 matching lines...) Expand all Loading... |
295 socket_factory_.AddSocketDataProvider(&final_socket_data); | 420 socket_factory_.AddSocketDataProvider(&final_socket_data); |
296 | 421 |
297 TestDelegate delegate; | 422 TestDelegate delegate; |
298 std::unique_ptr<URLRequest> request = context_->CreateRequest( | 423 std::unique_ptr<URLRequest> request = context_->CreateRequest( |
299 GURL("http://www.redirect.com"), DEFAULT_PRIORITY, &delegate); | 424 GURL("http://www.redirect.com"), DEFAULT_PRIORITY, &delegate); |
300 | 425 |
301 request->Start(); | 426 request->Start(); |
302 ASSERT_TRUE(request->is_pending()); | 427 ASSERT_TRUE(request->is_pending()); |
303 base::RunLoop().RunUntilIdle(); | 428 base::RunLoop().RunUntilIdle(); |
304 | 429 |
305 EXPECT_TRUE(request->status().is_success()); | 430 EXPECT_EQ(OK, request->status().error()); |
306 EXPECT_EQ(12, request->received_response_content_length()); | 431 EXPECT_EQ(12, request->received_response_content_length()); |
307 // Should not include the redirect. | 432 // Should not include the redirect. |
308 EXPECT_EQ(CountWriteBytes(final_writes, arraysize(final_writes)), | 433 EXPECT_EQ(CountWriteBytes(final_writes, arraysize(final_writes)), |
309 request->GetTotalSentBytes()); | 434 request->GetTotalSentBytes()); |
310 EXPECT_EQ(CountReadBytes(final_reads, arraysize(final_reads)), | 435 EXPECT_EQ(CountReadBytes(final_reads, arraysize(final_reads)), |
311 request->GetTotalReceivedBytes()); | 436 request->GetTotalReceivedBytes()); |
312 // Should include the redirect as well as the final response. | 437 // Should include the redirect as well as the final response. |
313 EXPECT_EQ(CountWriteBytes(redirect_writes, arraysize(redirect_writes)) + | 438 EXPECT_EQ(CountWriteBytes(redirect_writes, arraysize(redirect_writes)) + |
314 CountWriteBytes(final_writes, arraysize(final_writes)), | 439 CountWriteBytes(final_writes, arraysize(final_writes)), |
315 network_delegate_.total_network_bytes_sent()); | 440 network_delegate_.total_network_bytes_sent()); |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 base::RunLoop().RunUntilIdle(); | 943 base::RunLoop().RunUntilIdle(); |
819 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); | 944 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); |
820 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 945 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
821 } | 946 } |
822 | 947 |
823 #endif // defined(ENABLE_WEBSOCKETS) | 948 #endif // defined(ENABLE_WEBSOCKETS) |
824 | 949 |
825 } // namespace | 950 } // namespace |
826 | 951 |
827 } // namespace net | 952 } // namespace net |
OLD | NEW |