| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 13 #include "net/base/ip_endpoint.h" | 14 #include "net/base/ip_endpoint.h" |
| 14 #include "net/quic/congestion_control/tcp_cubic_sender.h" | 15 #include "net/quic/congestion_control/tcp_cubic_sender.h" |
| 15 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 16 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
| 16 #include "net/quic/crypto/null_encrypter.h" | 17 #include "net/quic/crypto/null_encrypter.h" |
| 17 #include "net/quic/quic_framer.h" | 18 #include "net/quic/quic_framer.h" |
| 18 #include "net/quic/quic_packet_creator.h" | 19 #include "net/quic/quic_packet_creator.h" |
| 19 #include "net/quic/quic_protocol.h" | 20 #include "net/quic/quic_protocol.h" |
| 20 #include "net/quic/quic_sent_packet_manager.h" | 21 #include "net/quic/quic_sent_packet_manager.h" |
| 21 #include "net/quic/test_tools/quic_connection_peer.h" | 22 #include "net/quic/test_tools/quic_connection_peer.h" |
| 22 #include "net/quic/test_tools/quic_session_peer.h" | 23 #include "net/quic/test_tools/quic_session_peer.h" |
| 23 #include "net/quic/test_tools/quic_test_utils.h" | 24 #include "net/quic/test_tools/quic_test_utils.h" |
| 24 #include "net/quic/test_tools/quic_test_writer.h" | |
| 25 #include "net/quic/test_tools/reliable_quic_stream_peer.h" | 25 #include "net/quic/test_tools/reliable_quic_stream_peer.h" |
| 26 #include "net/tools/quic/quic_epoll_connection_helper.h" | 26 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 27 #include "net/tools/quic/quic_in_memory_cache.h" | 27 #include "net/tools/quic/quic_in_memory_cache.h" |
| 28 #include "net/tools/quic/quic_packet_writer_wrapper.h" |
| 28 #include "net/tools/quic/quic_server.h" | 29 #include "net/tools/quic/quic_server.h" |
| 29 #include "net/tools/quic/quic_socket_utils.h" | 30 #include "net/tools/quic/quic_socket_utils.h" |
| 30 #include "net/tools/quic/quic_spdy_client_stream.h" | 31 #include "net/tools/quic/quic_spdy_client_stream.h" |
| 31 #include "net/tools/quic/test_tools/http_message_test_utils.h" | 32 #include "net/tools/quic/test_tools/http_message_test_utils.h" |
| 32 #include "net/tools/quic/test_tools/packet_dropping_test_writer.h" | 33 #include "net/tools/quic/test_tools/packet_dropping_test_writer.h" |
| 33 #include "net/tools/quic/test_tools/quic_client_peer.h" | 34 #include "net/tools/quic/test_tools/quic_client_peer.h" |
| 34 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" | 35 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" |
| 35 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" | 36 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" |
| 36 #include "net/tools/quic/test_tools/quic_server_peer.h" | 37 #include "net/tools/quic/test_tools/quic_server_peer.h" |
| 37 #include "net/tools/quic/test_tools/quic_test_client.h" | 38 #include "net/tools/quic/test_tools/quic_test_client.h" |
| 38 #include "net/tools/quic/test_tools/server_thread.h" | 39 #include "net/tools/quic/test_tools/server_thread.h" |
| 39 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
| 40 | 41 |
| 41 using base::StringPiece; | 42 using base::StringPiece; |
| 42 using base::WaitableEvent; | 43 using base::WaitableEvent; |
| 43 using net::test::QuicConnectionPeer; | 44 using net::test::QuicConnectionPeer; |
| 44 using net::test::QuicSessionPeer; | 45 using net::test::QuicSessionPeer; |
| 45 using net::test::QuicTestWriter; | |
| 46 using net::test::ReliableQuicStreamPeer; | 46 using net::test::ReliableQuicStreamPeer; |
| 47 using net::tools::test::PacketDroppingTestWriter; | 47 using net::tools::test::PacketDroppingTestWriter; |
| 48 using net::tools::test::QuicDispatcherPeer; | 48 using net::tools::test::QuicDispatcherPeer; |
| 49 using net::tools::test::QuicServerPeer; | 49 using net::tools::test::QuicServerPeer; |
| 50 using std::ostream; | 50 using std::ostream; |
| 51 using std::string; | 51 using std::string; |
| 52 using std::vector; | 52 using std::vector; |
| 53 | 53 |
| 54 namespace net { | 54 namespace net { |
| 55 namespace tools { | 55 namespace tools { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 AddToCache("GET", "https://www.google.com/bar", | 172 AddToCache("GET", "https://www.google.com/bar", |
| 173 "HTTP/1.1", "200", "OK", kBarResponseBody); | 173 "HTTP/1.1", "200", "OK", kBarResponseBody); |
| 174 } | 174 } |
| 175 | 175 |
| 176 virtual ~EndToEndTest() { | 176 virtual ~EndToEndTest() { |
| 177 // TODO(rtenneti): port RecycleUnusedPort if needed. | 177 // TODO(rtenneti): port RecycleUnusedPort if needed. |
| 178 // RecycleUnusedPort(server_address_.port()); | 178 // RecycleUnusedPort(server_address_.port()); |
| 179 QuicInMemoryCachePeer::ResetForTests(); | 179 QuicInMemoryCachePeer::ResetForTests(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 virtual QuicTestClient* CreateQuicClient(QuicTestWriter* writer) { | 182 virtual QuicTestClient* CreateQuicClient(QuicPacketWriterWrapper* writer) { |
| 183 QuicTestClient* client = new QuicTestClient(server_address_, | 183 QuicTestClient* client = new QuicTestClient(server_address_, |
| 184 server_hostname_, | 184 server_hostname_, |
| 185 false, // not secure | 185 false, // not secure |
| 186 client_config_, | 186 client_config_, |
| 187 client_supported_versions_); | 187 client_supported_versions_); |
| 188 client->UseWriter(writer); | 188 client->UseWriter(writer); |
| 189 client->Connect(); | 189 client->Connect(); |
| 190 return client; | 190 return client; |
| 191 } | 191 } |
| 192 | 192 |
| 193 virtual bool Initialize() { | 193 virtual bool Initialize() { |
| 194 // Start the server first, because CreateQuicClient() attempts | 194 // Start the server first, because CreateQuicClient() attempts |
| 195 // to connect to the server. | 195 // to connect to the server. |
| 196 StartServer(); | 196 StartServer(); |
| 197 client_.reset(CreateQuicClient(client_writer_)); | 197 client_.reset(CreateQuicClient(client_writer_)); |
| 198 QuicEpollConnectionHelper* helper = | 198 QuicEpollConnectionHelper* helper = |
| 199 reinterpret_cast<QuicEpollConnectionHelper*>( | 199 reinterpret_cast<QuicEpollConnectionHelper*>( |
| 200 QuicConnectionPeer::GetHelper( | 200 QuicConnectionPeer::GetHelper( |
| 201 client_->client()->session()->connection())); | 201 client_->client()->session()->connection())); |
| 202 client_writer_->SetConnectionHelper(helper); | 202 client_writer_->SetConnectionHelper(helper); |
| 203 return client_->client()->connected(); | 203 return client_->client()->connected(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 virtual void SetUp() { | 206 virtual void SetUp() { |
| 207 // The ownership of these gets transferred to the QuicTestWriter and | 207 // The ownership of these gets transferred to the QuicPacketWriterWrapper |
| 208 // QuicDispatcher when Initialize() is executed. | 208 // and QuicDispatcher when Initialize() is executed. |
| 209 client_writer_ = new PacketDroppingTestWriter(); | 209 client_writer_ = new PacketDroppingTestWriter(); |
| 210 server_writer_ = new PacketDroppingTestWriter(); | 210 server_writer_ = new PacketDroppingTestWriter(); |
| 211 } | 211 } |
| 212 | 212 |
| 213 virtual void TearDown() { | 213 virtual void TearDown() { |
| 214 StopServer(); | 214 StopServer(); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void StartServer() { | 217 void StartServer() { |
| 218 server_thread_.reset(new ServerThread(server_address_, server_config_, | 218 server_thread_.reset(new ServerThread(server_address_, server_config_, |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 // received for that stream. | 809 // received for that stream. |
| 810 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); | 810 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); |
| 811 } else { | 811 } else { |
| 812 // Check that the connection is always properly closed | 812 // Check that the connection is always properly closed |
| 813 // from a stream being RST before headers are decompressed. | 813 // from a stream being RST before headers are decompressed. |
| 814 EXPECT_EQ(QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED, | 814 EXPECT_EQ(QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED, |
| 815 client_->connection_error()); | 815 client_->connection_error()); |
| 816 } | 816 } |
| 817 } | 817 } |
| 818 | 818 |
| 819 class WrongAddressWriter : public QuicTestWriter { | 819 class WrongAddressWriter : public QuicPacketWriterWrapper { |
| 820 public: | 820 public: |
| 821 WrongAddressWriter() { | 821 WrongAddressWriter() { |
| 822 IPAddressNumber ip; | 822 IPAddressNumber ip; |
| 823 CHECK(net::ParseIPLiteralToNumber("127.0.0.2", &ip)); | 823 CHECK(net::ParseIPLiteralToNumber("127.0.0.2", &ip)); |
| 824 self_address_ = IPEndPoint(ip, 0); | 824 self_address_ = IPEndPoint(ip, 0); |
| 825 } | 825 } |
| 826 | 826 |
| 827 virtual WriteResult WritePacket( | 827 virtual WriteResult WritePacket( |
| 828 const char* buffer, size_t buf_len, | 828 const char* buffer, |
| 829 size_t buf_len, |
| 829 const IPAddressNumber& real_self_address, | 830 const IPAddressNumber& real_self_address, |
| 830 const IPEndPoint& peer_address, | 831 const IPEndPoint& peer_address, |
| 831 QuicBlockedWriterInterface* blocked_writer) OVERRIDE { | 832 QuicBlockedWriterInterface* blocked_writer) OVERRIDE { |
| 832 return writer()->WritePacket(buffer, buf_len, self_address_.address(), | 833 // Use wrong address! |
| 833 peer_address, blocked_writer); | 834 return QuicPacketWriterWrapper::WritePacket( |
| 835 buffer, buf_len, self_address_.address(), peer_address, blocked_writer); |
| 834 } | 836 } |
| 835 | 837 |
| 836 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { | 838 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { |
| 837 return false; | 839 return false; |
| 838 } | 840 } |
| 839 | 841 |
| 840 IPEndPoint self_address_; | 842 IPEndPoint self_address_; |
| 841 }; | 843 }; |
| 842 | 844 |
| 843 TEST_P(EndToEndTest, ConnectionMigration) { | 845 TEST_P(EndToEndTest, ConnectionMigration) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 856 client_->SendSynchronousRequest("/bar"); | 858 client_->SendSynchronousRequest("/bar"); |
| 857 | 859 |
| 858 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); | 860 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); |
| 859 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); | 861 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); |
| 860 } | 862 } |
| 861 | 863 |
| 862 } // namespace | 864 } // namespace |
| 863 } // namespace test | 865 } // namespace test |
| 864 } // namespace tools | 866 } // namespace tools |
| 865 } // namespace net | 867 } // namespace net |
| OLD | NEW |