OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( | 258 old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
259 HttpNetworkSession::NORMAL_SOCKET_POOL)), | 259 HttpNetworkSession::NORMAL_SOCKET_POOL)), |
260 old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( | 260 old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
261 HttpNetworkSession::NORMAL_SOCKET_POOL)) { | 261 HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
262 } | 262 } |
263 | 263 |
264 struct SimpleGetHelperResult { | 264 struct SimpleGetHelperResult { |
265 int rv; | 265 int rv; |
266 std::string status_line; | 266 std::string status_line; |
267 std::string response_data; | 267 std::string response_data; |
268 int64 totalReceivedBytes; | 268 int64_t total_received_bytes; |
| 269 int64_t total_sent_bytes; |
269 LoadTimingInfo load_timing_info; | 270 LoadTimingInfo load_timing_info; |
270 ConnectionAttempts connection_attempts; | 271 ConnectionAttempts connection_attempts; |
271 }; | 272 }; |
272 | 273 |
273 void SetUp() override { | 274 void SetUp() override { |
274 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 275 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
275 base::MessageLoop::current()->RunUntilIdle(); | 276 base::MessageLoop::current()->RunUntilIdle(); |
276 } | 277 } |
277 | 278 |
278 void TearDown() override { | 279 void TearDown() override { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 session_deps_.socket_factory->AddSocketDataProvider(data[i]); | 335 session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
335 } | 336 } |
336 | 337 |
337 TestCompletionCallback callback; | 338 TestCompletionCallback callback; |
338 | 339 |
339 EXPECT_TRUE(log.bound().IsCapturing()); | 340 EXPECT_TRUE(log.bound().IsCapturing()); |
340 int rv = trans->Start(&request, callback.callback(), log.bound()); | 341 int rv = trans->Start(&request, callback.callback(), log.bound()); |
341 EXPECT_EQ(ERR_IO_PENDING, rv); | 342 EXPECT_EQ(ERR_IO_PENDING, rv); |
342 | 343 |
343 out.rv = callback.WaitForResult(); | 344 out.rv = callback.WaitForResult(); |
| 345 out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 346 out.total_sent_bytes = trans->GetTotalSentBytes(); |
344 | 347 |
345 // Even in the failure cases that use this function, connections are always | 348 // Even in the failure cases that use this function, connections are always |
346 // successfully established before the error. | 349 // successfully established before the error. |
347 EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); | 350 EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
348 TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 351 TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
349 | 352 |
350 if (out.rv != OK) | 353 if (out.rv != OK) |
351 return out; | 354 return out; |
352 | 355 |
353 const HttpResponseInfo* response = trans->GetResponseInfo(); | 356 const HttpResponseInfo* response = trans->GetResponseInfo(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 EXPECT_TRUE(request_headers.GetHeader("Host", &value)); | 388 EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
386 EXPECT_EQ("www.example.org", value); | 389 EXPECT_EQ("www.example.org", value); |
387 EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); | 390 EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
388 EXPECT_EQ("keep-alive", value); | 391 EXPECT_EQ("keep-alive", value); |
389 | 392 |
390 std::string response_headers; | 393 std::string response_headers; |
391 EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); | 394 EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
392 EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", | 395 EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
393 response_headers); | 396 response_headers); |
394 | 397 |
395 out.totalReceivedBytes = trans->GetTotalReceivedBytes(); | 398 out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 399 // The total number of sent bytes should not have changed. |
| 400 EXPECT_EQ(out.total_sent_bytes, trans->GetTotalSentBytes()); |
| 401 |
396 trans->GetConnectionAttempts(&out.connection_attempts); | 402 trans->GetConnectionAttempts(&out.connection_attempts); |
397 return out; | 403 return out; |
398 } | 404 } |
399 | 405 |
400 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], | 406 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
401 size_t reads_count) { | 407 size_t reads_count) { |
402 StaticSocketDataProvider reads(data_reads, reads_count, NULL, 0); | 408 MockWrite data_writes[] = { |
403 StaticSocketDataProvider* data[] = { &reads }; | 409 MockWrite("GET / HTTP/1.1\r\n" |
404 return SimpleGetHelperForData(data, 1); | 410 "Host: www.example.org\r\n" |
405 } | 411 "Connection: keep-alive\r\n\r\n"), |
| 412 }; |
406 | 413 |
407 int64 ReadsSize(MockRead data_reads[], size_t reads_count) { | 414 StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
408 int64 size = 0; | 415 arraysize(data_writes)); |
409 for (size_t i = 0; i < reads_count; ++i) | 416 StaticSocketDataProvider* data[] = {&reads}; |
410 size += data_reads[i].data_len; | 417 SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
411 return size; | 418 |
| 419 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 420 out.total_sent_bytes); |
| 421 return out; |
412 } | 422 } |
413 | 423 |
414 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, | 424 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
415 int expected_status); | 425 int expected_status); |
416 | 426 |
417 void ConnectStatusHelper(const MockRead& status); | 427 void ConnectStatusHelper(const MockRead& status); |
418 | 428 |
419 void BypassHostCacheOnRefreshHelper(int load_flags); | 429 void BypassHostCacheOnRefreshHelper(int load_flags); |
420 | 430 |
421 void CheckErrorIsPassedBack(int error, IoMode mode); | 431 void CheckErrorIsPassedBack(int error, IoMode mode); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 MockRead data_reads[] = { | 682 MockRead data_reads[] = { |
673 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | 683 MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
674 MockRead("hello world"), | 684 MockRead("hello world"), |
675 MockRead(SYNCHRONOUS, OK), | 685 MockRead(SYNCHRONOUS, OK), |
676 }; | 686 }; |
677 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 687 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
678 arraysize(data_reads)); | 688 arraysize(data_reads)); |
679 EXPECT_EQ(OK, out.rv); | 689 EXPECT_EQ(OK, out.rv); |
680 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); | 690 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
681 EXPECT_EQ("hello world", out.response_data); | 691 EXPECT_EQ("hello world", out.response_data); |
682 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); | 692 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
683 EXPECT_EQ(reads_size, out.totalReceivedBytes); | 693 EXPECT_EQ(reads_size, out.total_received_bytes); |
684 EXPECT_EQ(0u, out.connection_attempts.size()); | 694 EXPECT_EQ(0u, out.connection_attempts.size()); |
685 } | 695 } |
686 | 696 |
687 // Response with no status line. | 697 // Response with no status line. |
688 TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { | 698 TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
689 MockRead data_reads[] = { | 699 MockRead data_reads[] = { |
690 MockRead("hello world"), | 700 MockRead("hello world"), |
691 MockRead(SYNCHRONOUS, OK), | 701 MockRead(SYNCHRONOUS, OK), |
692 }; | 702 }; |
693 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 703 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
694 arraysize(data_reads)); | 704 arraysize(data_reads)); |
695 EXPECT_EQ(OK, out.rv); | 705 EXPECT_EQ(OK, out.rv); |
696 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); | 706 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
697 EXPECT_EQ("hello world", out.response_data); | 707 EXPECT_EQ("hello world", out.response_data); |
698 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); | 708 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
699 EXPECT_EQ(reads_size, out.totalReceivedBytes); | 709 EXPECT_EQ(reads_size, out.total_received_bytes); |
700 } | 710 } |
701 | 711 |
702 // Allow up to 4 bytes of junk to precede status line. | 712 // Allow up to 4 bytes of junk to precede status line. |
703 TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { | 713 TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
704 MockRead data_reads[] = { | 714 MockRead data_reads[] = { |
705 MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), | 715 MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
706 MockRead(SYNCHRONOUS, OK), | 716 MockRead(SYNCHRONOUS, OK), |
707 }; | 717 }; |
708 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 718 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
709 arraysize(data_reads)); | 719 arraysize(data_reads)); |
710 EXPECT_EQ(OK, out.rv); | 720 EXPECT_EQ(OK, out.rv); |
711 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); | 721 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
712 EXPECT_EQ("DATA", out.response_data); | 722 EXPECT_EQ("DATA", out.response_data); |
713 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); | 723 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
714 EXPECT_EQ(reads_size, out.totalReceivedBytes); | 724 EXPECT_EQ(reads_size, out.total_received_bytes); |
715 } | 725 } |
716 | 726 |
717 // Allow up to 4 bytes of junk to precede status line. | 727 // Allow up to 4 bytes of junk to precede status line. |
718 TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { | 728 TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
719 MockRead data_reads[] = { | 729 MockRead data_reads[] = { |
720 MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), | 730 MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
721 MockRead(SYNCHRONOUS, OK), | 731 MockRead(SYNCHRONOUS, OK), |
722 }; | 732 }; |
723 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 733 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
724 arraysize(data_reads)); | 734 arraysize(data_reads)); |
725 EXPECT_EQ(OK, out.rv); | 735 EXPECT_EQ(OK, out.rv); |
726 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); | 736 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
727 EXPECT_EQ("DATA", out.response_data); | 737 EXPECT_EQ("DATA", out.response_data); |
728 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); | 738 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
729 EXPECT_EQ(reads_size, out.totalReceivedBytes); | 739 EXPECT_EQ(reads_size, out.total_received_bytes); |
730 } | 740 } |
731 | 741 |
732 // Beyond 4 bytes of slop and it should fail to find a status line. | 742 // Beyond 4 bytes of slop and it should fail to find a status line. |
733 TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { | 743 TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
734 MockRead data_reads[] = { | 744 MockRead data_reads[] = { |
735 MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), | 745 MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
736 MockRead(SYNCHRONOUS, OK), | 746 MockRead(SYNCHRONOUS, OK), |
737 }; | 747 }; |
738 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 748 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
739 arraysize(data_reads)); | 749 arraysize(data_reads)); |
740 EXPECT_EQ(OK, out.rv); | 750 EXPECT_EQ(OK, out.rv); |
741 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); | 751 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
742 EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); | 752 EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
743 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); | 753 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
744 EXPECT_EQ(reads_size, out.totalReceivedBytes); | 754 EXPECT_EQ(reads_size, out.total_received_bytes); |
745 } | 755 } |
746 | 756 |
747 // Same as StatusLineJunk4Bytes, except the read chunks are smaller. | 757 // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
748 TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { | 758 TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
749 MockRead data_reads[] = { | 759 MockRead data_reads[] = { |
750 MockRead("\n"), | 760 MockRead("\n"), |
751 MockRead("\n"), | 761 MockRead("\n"), |
752 MockRead("Q"), | 762 MockRead("Q"), |
753 MockRead("J"), | 763 MockRead("J"), |
754 MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), | 764 MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
755 MockRead(SYNCHRONOUS, OK), | 765 MockRead(SYNCHRONOUS, OK), |
756 }; | 766 }; |
757 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 767 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
758 arraysize(data_reads)); | 768 arraysize(data_reads)); |
759 EXPECT_EQ(OK, out.rv); | 769 EXPECT_EQ(OK, out.rv); |
760 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); | 770 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
761 EXPECT_EQ("DATA", out.response_data); | 771 EXPECT_EQ("DATA", out.response_data); |
762 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); | 772 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
763 EXPECT_EQ(reads_size, out.totalReceivedBytes); | 773 EXPECT_EQ(reads_size, out.total_received_bytes); |
764 } | 774 } |
765 | 775 |
766 // Close the connection before enough bytes to have a status line. | 776 // Close the connection before enough bytes to have a status line. |
767 TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { | 777 TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
768 MockRead data_reads[] = { | 778 MockRead data_reads[] = { |
769 MockRead("HTT"), | 779 MockRead("HTT"), |
770 MockRead(SYNCHRONOUS, OK), | 780 MockRead(SYNCHRONOUS, OK), |
771 }; | 781 }; |
772 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 782 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
773 arraysize(data_reads)); | 783 arraysize(data_reads)); |
774 EXPECT_EQ(OK, out.rv); | 784 EXPECT_EQ(OK, out.rv); |
775 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); | 785 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
776 EXPECT_EQ("HTT", out.response_data); | 786 EXPECT_EQ("HTT", out.response_data); |
777 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); | 787 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
778 EXPECT_EQ(reads_size, out.totalReceivedBytes); | 788 EXPECT_EQ(reads_size, out.total_received_bytes); |
779 } | 789 } |
780 | 790 |
781 // Simulate a 204 response, lacking a Content-Length header, sent over a | 791 // Simulate a 204 response, lacking a Content-Length header, sent over a |
782 // persistent connection. The response should still terminate since a 204 | 792 // persistent connection. The response should still terminate since a 204 |
783 // cannot have a response body. | 793 // cannot have a response body. |
784 TEST_P(HttpNetworkTransactionTest, StopsReading204) { | 794 TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
785 char junk[] = "junk"; | 795 char junk[] = "junk"; |
786 MockRead data_reads[] = { | 796 MockRead data_reads[] = { |
787 MockRead("HTTP/1.1 204 No Content\r\n\r\n"), | 797 MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
788 MockRead(junk), // Should not be read!! | 798 MockRead(junk), // Should not be read!! |
789 MockRead(SYNCHRONOUS, OK), | 799 MockRead(SYNCHRONOUS, OK), |
790 }; | 800 }; |
791 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 801 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
792 arraysize(data_reads)); | 802 arraysize(data_reads)); |
793 EXPECT_EQ(OK, out.rv); | 803 EXPECT_EQ(OK, out.rv); |
794 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); | 804 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
795 EXPECT_EQ("", out.response_data); | 805 EXPECT_EQ("", out.response_data); |
796 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); | 806 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
797 int64 response_size = reads_size - strlen(junk); | 807 int64_t response_size = reads_size - strlen(junk); |
798 EXPECT_EQ(response_size, out.totalReceivedBytes); | 808 EXPECT_EQ(response_size, out.total_received_bytes); |
799 } | 809 } |
800 | 810 |
801 // A simple request using chunked encoding with some extra data after. | 811 // A simple request using chunked encoding with some extra data after. |
802 TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { | 812 TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
803 std::string final_chunk = "0\r\n\r\n"; | 813 std::string final_chunk = "0\r\n\r\n"; |
804 std::string extra_data = "HTTP/1.1 200 OK\r\n"; | 814 std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
805 std::string last_read = final_chunk + extra_data; | 815 std::string last_read = final_chunk + extra_data; |
806 MockRead data_reads[] = { | 816 MockRead data_reads[] = { |
807 MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), | 817 MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
808 MockRead("5\r\nHello\r\n"), | 818 MockRead("5\r\nHello\r\n"), |
809 MockRead("1\r\n"), | 819 MockRead("1\r\n"), |
810 MockRead(" \r\n"), | 820 MockRead(" \r\n"), |
811 MockRead("5\r\nworld\r\n"), | 821 MockRead("5\r\nworld\r\n"), |
812 MockRead(last_read.data()), | 822 MockRead(last_read.data()), |
813 MockRead(SYNCHRONOUS, OK), | 823 MockRead(SYNCHRONOUS, OK), |
814 }; | 824 }; |
815 SimpleGetHelperResult out = SimpleGetHelper(data_reads, | 825 SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
816 arraysize(data_reads)); | 826 arraysize(data_reads)); |
817 EXPECT_EQ(OK, out.rv); | 827 EXPECT_EQ(OK, out.rv); |
818 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 828 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
819 EXPECT_EQ("Hello world", out.response_data); | 829 EXPECT_EQ("Hello world", out.response_data); |
820 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); | 830 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
821 int64 response_size = reads_size - extra_data.size(); | 831 int64_t response_size = reads_size - extra_data.size(); |
822 EXPECT_EQ(response_size, out.totalReceivedBytes); | 832 EXPECT_EQ(response_size, out.total_received_bytes); |
823 } | 833 } |
824 | 834 |
825 // Next tests deal with http://crbug.com/56344. | 835 // Next tests deal with http://crbug.com/56344. |
826 | 836 |
827 TEST_P(HttpNetworkTransactionTest, | 837 TEST_P(HttpNetworkTransactionTest, |
828 MultipleContentLengthHeadersNoTransferEncoding) { | 838 MultipleContentLengthHeadersNoTransferEncoding) { |
829 MockRead data_reads[] = { | 839 MockRead data_reads[] = { |
830 MockRead("HTTP/1.1 200 OK\r\n"), | 840 MockRead("HTTP/1.1 200 OK\r\n"), |
831 MockRead("Content-Length: 10\r\n"), | 841 MockRead("Content-Length: 10\r\n"), |
832 MockRead("Content-Length: 5\r\n\r\n"), | 842 MockRead("Content-Length: 5\r\n\r\n"), |
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1948 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | 1958 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
1949 EXPECT_EQ(ERR_IO_PENDING, rv); | 1959 EXPECT_EQ(ERR_IO_PENDING, rv); |
1950 | 1960 |
1951 rv = callback1.WaitForResult(); | 1961 rv = callback1.WaitForResult(); |
1952 EXPECT_EQ(OK, rv); | 1962 EXPECT_EQ(OK, rv); |
1953 | 1963 |
1954 LoadTimingInfo load_timing_info1; | 1964 LoadTimingInfo load_timing_info1; |
1955 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); | 1965 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
1956 TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); | 1966 TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
1957 | 1967 |
1958 int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); | 1968 int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 1969 EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 1970 int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
1959 EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); | 1971 EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
1960 | 1972 |
1961 const HttpResponseInfo* response = trans->GetResponseInfo(); | 1973 const HttpResponseInfo* response = trans->GetResponseInfo(); |
1962 ASSERT_TRUE(response != NULL); | 1974 ASSERT_TRUE(response != NULL); |
1963 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); | 1975 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
1964 | 1976 |
1965 TestCompletionCallback callback2; | 1977 TestCompletionCallback callback2; |
1966 | 1978 |
1967 rv = trans->RestartWithAuth( | 1979 rv = trans->RestartWithAuth( |
1968 AuthCredentials(kFoo, kBar), callback2.callback()); | 1980 AuthCredentials(kFoo, kBar), callback2.callback()); |
1969 EXPECT_EQ(ERR_IO_PENDING, rv); | 1981 EXPECT_EQ(ERR_IO_PENDING, rv); |
1970 | 1982 |
1971 rv = callback2.WaitForResult(); | 1983 rv = callback2.WaitForResult(); |
1972 EXPECT_EQ(OK, rv); | 1984 EXPECT_EQ(OK, rv); |
1973 | 1985 |
1974 LoadTimingInfo load_timing_info2; | 1986 LoadTimingInfo load_timing_info2; |
1975 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); | 1987 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
1976 TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); | 1988 TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
1977 // The load timing after restart should have a new socket ID, and times after | 1989 // The load timing after restart should have a new socket ID, and times after |
1978 // those of the first load timing. | 1990 // those of the first load timing. |
1979 EXPECT_LE(load_timing_info1.receive_headers_end, | 1991 EXPECT_LE(load_timing_info1.receive_headers_end, |
1980 load_timing_info2.connect_timing.connect_start); | 1992 load_timing_info2.connect_timing.connect_start); |
1981 EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); | 1993 EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
1982 | 1994 |
1983 int64 reads_size2 = ReadsSize(data_reads2, arraysize(data_reads2)); | 1995 int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 1996 EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 1997 int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
1984 EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); | 1998 EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
1985 | 1999 |
1986 response = trans->GetResponseInfo(); | 2000 response = trans->GetResponseInfo(); |
1987 ASSERT_TRUE(response != NULL); | 2001 ASSERT_TRUE(response != NULL); |
1988 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 2002 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
1989 EXPECT_EQ(100, response->headers->GetContentLength()); | 2003 EXPECT_EQ(100, response->headers->GetContentLength()); |
1990 } | 2004 } |
1991 | 2005 |
1992 TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { | 2006 TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
1993 HttpRequestInfo request; | 2007 HttpRequestInfo request; |
(...skipping 25 matching lines...) Expand all Loading... |
2019 data_writes, arraysize(data_writes)); | 2033 data_writes, arraysize(data_writes)); |
2020 session_deps_.socket_factory->AddSocketDataProvider(&data); | 2034 session_deps_.socket_factory->AddSocketDataProvider(&data); |
2021 TestCompletionCallback callback; | 2035 TestCompletionCallback callback; |
2022 | 2036 |
2023 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 2037 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
2024 EXPECT_EQ(ERR_IO_PENDING, rv); | 2038 EXPECT_EQ(ERR_IO_PENDING, rv); |
2025 | 2039 |
2026 rv = callback.WaitForResult(); | 2040 rv = callback.WaitForResult(); |
2027 EXPECT_EQ(0, rv); | 2041 EXPECT_EQ(0, rv); |
2028 | 2042 |
2029 int64 reads_size = ReadsSize(data_reads, arraysize(data_reads)); | 2043 int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2044 EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2045 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
2030 EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); | 2046 EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
2031 | 2047 |
2032 const HttpResponseInfo* response = trans->GetResponseInfo(); | 2048 const HttpResponseInfo* response = trans->GetResponseInfo(); |
2033 ASSERT_TRUE(response != NULL); | 2049 ASSERT_TRUE(response != NULL); |
2034 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 2050 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
2035 } | 2051 } |
2036 | 2052 |
2037 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | 2053 // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
2038 // connection. | 2054 // connection. |
2039 TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { | 2055 TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2125 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); | 2141 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
2126 | 2142 |
2127 response = trans->GetResponseInfo(); | 2143 response = trans->GetResponseInfo(); |
2128 ASSERT_TRUE(response != NULL); | 2144 ASSERT_TRUE(response != NULL); |
2129 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 2145 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
2130 EXPECT_EQ(5, response->headers->GetContentLength()); | 2146 EXPECT_EQ(5, response->headers->GetContentLength()); |
2131 | 2147 |
2132 std::string response_data; | 2148 std::string response_data; |
2133 rv = ReadTransaction(trans.get(), &response_data); | 2149 rv = ReadTransaction(trans.get(), &response_data); |
2134 EXPECT_EQ(OK, rv); | 2150 EXPECT_EQ(OK, rv); |
2135 int64 reads_size1 = ReadsSize(data_reads1, arraysize(data_reads1)); | 2151 |
| 2152 int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2153 EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2154 int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
2136 EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); | 2155 EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
2137 } | 2156 } |
2138 | 2157 |
2139 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | 2158 // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
2140 // connection and with no response body to drain. | 2159 // connection and with no response body to drain. |
2141 TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { | 2160 TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
2142 HttpRequestInfo request; | 2161 HttpRequestInfo request; |
2143 request.method = "GET"; | 2162 request.method = "GET"; |
2144 request.url = GURL("http://www.example.org/"); | 2163 request.url = GURL("http://www.example.org/"); |
2145 request.load_flags = 0; | 2164 request.load_flags = 0; |
(...skipping 12431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14577 const HttpResponseInfo* response = trans->GetResponseInfo(); | 14596 const HttpResponseInfo* response = trans->GetResponseInfo(); |
14578 ASSERT_TRUE(response); | 14597 ASSERT_TRUE(response); |
14579 ASSERT_TRUE(response->headers.get()); | 14598 ASSERT_TRUE(response->headers.get()); |
14580 | 14599 |
14581 EXPECT_EQ(101, response->headers->response_code()); | 14600 EXPECT_EQ(101, response->headers->response_code()); |
14582 | 14601 |
14583 trans.reset(); | 14602 trans.reset(); |
14584 session->CloseAllConnections(); | 14603 session->CloseAllConnections(); |
14585 } | 14604 } |
14586 | 14605 |
| 14606 TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
| 14607 ScopedVector<UploadElementReader> element_readers; |
| 14608 element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 14609 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 14610 |
| 14611 HttpRequestInfo request; |
| 14612 request.method = "POST"; |
| 14613 request.url = GURL("http://www.foo.com/"); |
| 14614 request.upload_data_stream = &upload_data_stream; |
| 14615 |
| 14616 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14617 scoped_ptr<HttpTransaction> trans( |
| 14618 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14619 MockWrite data_writes[] = { |
| 14620 MockWrite("POST / HTTP/1.1\r\n" |
| 14621 "Host: www.foo.com\r\n" |
| 14622 "Connection: keep-alive\r\n" |
| 14623 "Content-Length: 3\r\n\r\n"), |
| 14624 MockWrite("foo"), |
| 14625 }; |
| 14626 |
| 14627 MockRead data_reads[] = { |
| 14628 MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 14629 MockRead(SYNCHRONOUS, OK), |
| 14630 }; |
| 14631 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14632 arraysize(data_writes)); |
| 14633 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14634 |
| 14635 TestCompletionCallback callback; |
| 14636 |
| 14637 EXPECT_EQ(ERR_IO_PENDING, |
| 14638 trans->Start(&request, callback.callback(), BoundNetLog())); |
| 14639 EXPECT_EQ(OK, callback.WaitForResult()); |
| 14640 |
| 14641 std::string response_data; |
| 14642 EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14643 |
| 14644 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 14645 trans->GetTotalSentBytes()); |
| 14646 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 14647 trans->GetTotalReceivedBytes()); |
| 14648 } |
| 14649 |
| 14650 TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
| 14651 ScopedVector<UploadElementReader> element_readers; |
| 14652 element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 14653 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 14654 |
| 14655 HttpRequestInfo request; |
| 14656 request.method = "POST"; |
| 14657 request.url = GURL("http://www.foo.com/"); |
| 14658 request.upload_data_stream = &upload_data_stream; |
| 14659 |
| 14660 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14661 scoped_ptr<HttpTransaction> trans( |
| 14662 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14663 MockWrite data_writes[] = { |
| 14664 MockWrite("POST / HTTP/1.1\r\n" |
| 14665 "Host: www.foo.com\r\n" |
| 14666 "Connection: keep-alive\r\n" |
| 14667 "Content-Length: 3\r\n\r\n"), |
| 14668 MockWrite("foo"), |
| 14669 }; |
| 14670 |
| 14671 MockRead data_reads[] = { |
| 14672 MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 14673 MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 14674 MockRead(SYNCHRONOUS, OK), |
| 14675 }; |
| 14676 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14677 arraysize(data_writes)); |
| 14678 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14679 |
| 14680 TestCompletionCallback callback; |
| 14681 |
| 14682 EXPECT_EQ(ERR_IO_PENDING, |
| 14683 trans->Start(&request, callback.callback(), BoundNetLog())); |
| 14684 EXPECT_EQ(OK, callback.WaitForResult()); |
| 14685 |
| 14686 std::string response_data; |
| 14687 EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14688 |
| 14689 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 14690 trans->GetTotalSentBytes()); |
| 14691 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 14692 trans->GetTotalReceivedBytes()); |
| 14693 } |
| 14694 |
| 14695 TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
| 14696 ScopedVector<UploadElementReader> element_readers; |
| 14697 element_readers.push_back(new UploadBytesElementReader("foo", 3)); |
| 14698 ChunkedUploadDataStream upload_data_stream(0); |
| 14699 |
| 14700 HttpRequestInfo request; |
| 14701 request.method = "POST"; |
| 14702 request.url = GURL("http://www.foo.com/"); |
| 14703 request.upload_data_stream = &upload_data_stream; |
| 14704 |
| 14705 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14706 scoped_ptr<HttpTransaction> trans( |
| 14707 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14708 // Send headers successfully, but get an error while sending the body. |
| 14709 MockWrite data_writes[] = { |
| 14710 MockWrite("POST / HTTP/1.1\r\n" |
| 14711 "Host: www.foo.com\r\n" |
| 14712 "Connection: keep-alive\r\n" |
| 14713 "Transfer-Encoding: chunked\r\n\r\n"), |
| 14714 MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 14715 }; |
| 14716 |
| 14717 MockRead data_reads[] = { |
| 14718 MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 14719 MockRead(SYNCHRONOUS, OK), |
| 14720 }; |
| 14721 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14722 arraysize(data_writes)); |
| 14723 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14724 |
| 14725 TestCompletionCallback callback; |
| 14726 |
| 14727 EXPECT_EQ(ERR_IO_PENDING, |
| 14728 trans->Start(&request, callback.callback(), BoundNetLog())); |
| 14729 |
| 14730 base::RunLoop().RunUntilIdle(); |
| 14731 upload_data_stream.AppendData("f", 1, false); |
| 14732 |
| 14733 base::RunLoop().RunUntilIdle(); |
| 14734 upload_data_stream.AppendData("oo", 2, true); |
| 14735 |
| 14736 EXPECT_EQ(OK, callback.WaitForResult()); |
| 14737 |
| 14738 std::string response_data; |
| 14739 EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14740 |
| 14741 EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 14742 trans->GetTotalSentBytes()); |
| 14743 EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 14744 trans->GetTotalReceivedBytes()); |
| 14745 } |
| 14746 |
14587 } // namespace net | 14747 } // namespace net |
OLD | NEW |