| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <sys/epoll.h> | 7 #include <sys/epoll.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "net/base/ip_endpoint.h" | 17 #include "net/base/ip_endpoint.h" |
| 18 #include "net/quic/congestion_control/tcp_cubic_sender.h" | 18 #include "net/quic/congestion_control/tcp_cubic_sender.h" |
| 19 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 19 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
| 20 #include "net/quic/crypto/null_encrypter.h" | 20 #include "net/quic/crypto/null_encrypter.h" |
| 21 #include "net/quic/quic_flags.h" | 21 #include "net/quic/quic_flags.h" |
| 22 #include "net/quic/quic_framer.h" | 22 #include "net/quic/quic_framer.h" |
| 23 #include "net/quic/quic_packet_creator.h" | 23 #include "net/quic/quic_packet_creator.h" |
| 24 #include "net/quic/quic_protocol.h" | 24 #include "net/quic/quic_protocol.h" |
| 25 #include "net/quic/quic_server_id.h" | 25 #include "net/quic/quic_server_id.h" |
| 26 #include "net/quic/quic_session.h" |
| 26 #include "net/quic/quic_utils.h" | 27 #include "net/quic/quic_utils.h" |
| 27 #include "net/quic/test_tools/crypto_test_utils.h" | 28 #include "net/quic/test_tools/crypto_test_utils.h" |
| 28 #include "net/quic/test_tools/quic_connection_peer.h" | 29 #include "net/quic/test_tools/quic_connection_peer.h" |
| 29 #include "net/quic/test_tools/quic_flow_controller_peer.h" | 30 #include "net/quic/test_tools/quic_flow_controller_peer.h" |
| 30 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" | 31 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" |
| 31 #include "net/quic/test_tools/quic_session_peer.h" | 32 #include "net/quic/test_tools/quic_session_peer.h" |
| 32 #include "net/quic/test_tools/quic_spdy_session_peer.h" | 33 #include "net/quic/test_tools/quic_spdy_session_peer.h" |
| 33 #include "net/quic/test_tools/quic_test_utils.h" | 34 #include "net/quic/test_tools/quic_test_utils.h" |
| 34 #include "net/quic/test_tools/reliable_quic_stream_peer.h" | 35 #include "net/quic/test_tools/reliable_quic_stream_peer.h" |
| 35 #include "net/test/gtest_util.h" | 36 #include "net/test/gtest_util.h" |
| 36 #include "net/tools/epoll_server/epoll_server.h" | 37 #include "net/tools/epoll_server/epoll_server.h" |
| 37 #include "net/tools/quic/quic_epoll_connection_helper.h" | 38 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 38 #include "net/tools/quic/quic_in_memory_cache.h" | 39 #include "net/tools/quic/quic_in_memory_cache.h" |
| 39 #include "net/tools/quic/quic_packet_writer_wrapper.h" | 40 #include "net/tools/quic/quic_packet_writer_wrapper.h" |
| 40 #include "net/tools/quic/quic_server.h" | 41 #include "net/tools/quic/quic_server.h" |
| 42 #include "net/tools/quic/quic_simple_server_stream.h" |
| 41 #include "net/tools/quic/quic_socket_utils.h" | 43 #include "net/tools/quic/quic_socket_utils.h" |
| 42 #include "net/tools/quic/quic_spdy_client_stream.h" | 44 #include "net/tools/quic/quic_spdy_client_stream.h" |
| 43 #include "net/tools/quic/quic_spdy_server_stream.h" | |
| 44 #include "net/tools/quic/test_tools/http_message.h" | 45 #include "net/tools/quic/test_tools/http_message.h" |
| 45 #include "net/tools/quic/test_tools/packet_dropping_test_writer.h" | 46 #include "net/tools/quic/test_tools/packet_dropping_test_writer.h" |
| 46 #include "net/tools/quic/test_tools/quic_client_peer.h" | 47 #include "net/tools/quic/test_tools/quic_client_peer.h" |
| 47 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" | 48 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" |
| 48 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" | 49 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" |
| 49 #include "net/tools/quic/test_tools/quic_server_peer.h" | 50 #include "net/tools/quic/test_tools/quic_server_peer.h" |
| 50 #include "net/tools/quic/test_tools/quic_test_client.h" | 51 #include "net/tools/quic/test_tools/quic_test_client.h" |
| 51 #include "net/tools/quic/test_tools/quic_test_server.h" | 52 #include "net/tools/quic/test_tools/quic_test_server.h" |
| 52 #include "net/tools/quic/test_tools/server_thread.h" | 53 #include "net/tools/quic/test_tools/server_thread.h" |
| 53 #include "testing/gtest/include/gtest/gtest.h" | 54 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 ASSERT_TRUE(Initialize()); | 666 ASSERT_TRUE(Initialize()); |
| 666 | 667 |
| 667 // Add a content length header with no body. | 668 // Add a content length header with no body. |
| 668 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 669 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
| 669 request.AddHeader("content-length", "3"); | 670 request.AddHeader("content-length", "3"); |
| 670 request.set_skip_message_validation(true); | 671 request.set_skip_message_validation(true); |
| 671 | 672 |
| 672 // This should be detected as stream fin without complete request, | 673 // This should be detected as stream fin without complete request, |
| 673 // triggering an error response. | 674 // triggering an error response. |
| 674 client_->SendCustomSynchronousRequest(request); | 675 client_->SendCustomSynchronousRequest(request); |
| 675 EXPECT_EQ(QuicSpdyServerStream::kErrorResponseBody, client_->response_body()); | 676 EXPECT_EQ(QuicSimpleServerStream::kErrorResponseBody, |
| 677 client_->response_body()); |
| 676 EXPECT_EQ(500u, client_->response_headers()->parsed_response_code()); | 678 EXPECT_EQ(500u, client_->response_headers()->parsed_response_code()); |
| 677 } | 679 } |
| 678 | 680 |
| 679 TEST_P(EndToEndTest, LargePostNoPacketLoss) { | 681 TEST_P(EndToEndTest, LargePostNoPacketLoss) { |
| 680 ASSERT_TRUE(Initialize()); | 682 ASSERT_TRUE(Initialize()); |
| 681 | 683 |
| 682 client_->client()->WaitForCryptoHandshakeConfirmed(); | 684 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 683 | 685 |
| 684 // 1 MB body. | 686 // 1 MB body. |
| 685 string body; | 687 string body; |
| (...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1969 EXPECT_EQ(QUIC_NO_ERROR, | 1971 EXPECT_EQ(QUIC_NO_ERROR, |
| 1970 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); | 1972 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); |
| 1971 server_thread_->Resume(); | 1973 server_thread_->Resume(); |
| 1972 | 1974 |
| 1973 // The connection should not be terminated. | 1975 // The connection should not be terminated. |
| 1974 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1976 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 1975 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1977 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 1976 } | 1978 } |
| 1977 | 1979 |
| 1978 // A test stream that gives |response_body_| as an error response body. | 1980 // A test stream that gives |response_body_| as an error response body. |
| 1979 class ServerStreamWithErrorResponseBody : public QuicSpdyServerStream { | 1981 class ServerStreamWithErrorResponseBody : public QuicSimpleServerStream { |
| 1980 public: | 1982 public: |
| 1981 ServerStreamWithErrorResponseBody(QuicStreamId id, | 1983 ServerStreamWithErrorResponseBody(QuicStreamId id, |
| 1982 QuicSpdySession* session, | 1984 QuicSpdySession* session, |
| 1983 string response_body) | 1985 string response_body) |
| 1984 : QuicSpdyServerStream(id, session), response_body_(response_body) {} | 1986 : QuicSimpleServerStream(id, session), response_body_(response_body) {} |
| 1985 | 1987 |
| 1986 ~ServerStreamWithErrorResponseBody() override {} | 1988 ~ServerStreamWithErrorResponseBody() override {} |
| 1987 | 1989 |
| 1988 protected: | 1990 protected: |
| 1989 void SendErrorResponse() override { | 1991 void SendErrorResponse() override { |
| 1990 DVLOG(1) << "Sending error response for stream " << id(); | 1992 DVLOG(1) << "Sending error response for stream " << id(); |
| 1991 SpdyHeaderBlock headers; | 1993 SpdyHeaderBlock headers; |
| 1992 headers[":status"] = "500"; | 1994 headers[":status"] = "500"; |
| 1993 headers["content-length"] = base::UintToString(response_body_.size()); | 1995 headers["content-length"] = base::UintToString(response_body_.size()); |
| 1994 // This method must call CloseReadSide to cause the test case, StopReading | 1996 // This method must call CloseReadSide to cause the test case, StopReading |
| 1995 // is not sufficient. | 1997 // is not sufficient. |
| 1996 ReliableQuicStreamPeer::CloseReadSide(this); | 1998 ReliableQuicStreamPeer::CloseReadSide(this); |
| 1997 SendHeadersAndBody(headers, response_body_); | 1999 SendHeadersAndBody(headers, response_body_); |
| 1998 } | 2000 } |
| 1999 | 2001 |
| 2000 string response_body_; | 2002 string response_body_; |
| 2001 }; | 2003 }; |
| 2002 | 2004 |
| 2003 class StreamWithErrorFactory : public QuicTestServer::StreamFactory { | 2005 class StreamWithErrorFactory : public QuicTestServer::StreamFactory { |
| 2004 public: | 2006 public: |
| 2005 explicit StreamWithErrorFactory(string response_body) | 2007 explicit StreamWithErrorFactory(string response_body) |
| 2006 : response_body_(response_body) {} | 2008 : response_body_(response_body) {} |
| 2007 | 2009 |
| 2008 ~StreamWithErrorFactory() override {} | 2010 ~StreamWithErrorFactory() override {} |
| 2009 | 2011 |
| 2010 QuicSpdyServerStream* CreateStream(QuicStreamId id, | 2012 QuicSimpleServerStream* CreateStream(QuicStreamId id, |
| 2011 QuicSpdySession* session) override { | 2013 QuicSpdySession* session) override { |
| 2012 return new ServerStreamWithErrorResponseBody(id, session, response_body_); | 2014 return new ServerStreamWithErrorResponseBody(id, session, response_body_); |
| 2013 } | 2015 } |
| 2014 | 2016 |
| 2015 private: | 2017 private: |
| 2016 string response_body_; | 2018 string response_body_; |
| 2017 }; | 2019 }; |
| 2018 | 2020 |
| 2019 TEST_P(EndToEndTest, EarlyResponseFinRecording) { | 2021 TEST_P(EndToEndTest, EarlyResponseFinRecording) { |
| 2020 set_smaller_flow_control_receive_window(); | 2022 set_smaller_flow_control_receive_window(); |
| 2021 | 2023 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2161 | 2163 |
| 2162 EXPECT_EQ(kBody, client_->SendSynchronousRequest("/trailer_url")); | 2164 EXPECT_EQ(kBody, client_->SendSynchronousRequest("/trailer_url")); |
| 2163 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 2165 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 2164 EXPECT_EQ(trailers, client_->response_trailers()); | 2166 EXPECT_EQ(trailers, client_->response_trailers()); |
| 2165 } | 2167 } |
| 2166 | 2168 |
| 2167 } // namespace | 2169 } // namespace |
| 2168 } // namespace test | 2170 } // namespace test |
| 2169 } // namespace tools | 2171 } // namespace tools |
| 2170 } // namespace net | 2172 } // namespace net |
| OLD | NEW |