| 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 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "net/base/ip_endpoint.h" | 12 #include "net/base/ip_endpoint.h" |
| 13 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 13 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
| 14 #include "net/quic/crypto/null_encrypter.h" | 14 #include "net/quic/crypto/null_encrypter.h" |
| 15 #include "net/quic/quic_framer.h" | 15 #include "net/quic/quic_framer.h" |
| 16 #include "net/quic/quic_packet_creator.h" | 16 #include "net/quic/quic_packet_creator.h" |
| 17 #include "net/quic/quic_protocol.h" | 17 #include "net/quic/quic_protocol.h" |
| 18 #include "net/quic/test_tools/quic_connection_peer.h" | 18 #include "net/quic/test_tools/quic_connection_peer.h" |
| 19 #include "net/quic/test_tools/quic_session_peer.h" | 19 #include "net/quic/test_tools/quic_session_peer.h" |
| 20 #include "net/quic/test_tools/reliable_quic_stream_peer.h" | 20 #include "net/quic/test_tools/reliable_quic_stream_peer.h" |
| 21 #include "net/tools/quic/quic_epoll_connection_helper.h" | 21 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 22 #include "net/tools/quic/quic_in_memory_cache.h" | 22 #include "net/tools/quic/quic_in_memory_cache.h" |
| 23 #include "net/tools/quic/quic_server.h" | 23 #include "net/tools/quic/quic_server.h" |
| 24 #include "net/tools/quic/quic_socket_utils.h" | 24 #include "net/tools/quic/quic_socket_utils.h" |
| 25 #include "net/tools/quic/test_tools/http_message_test_utils.h" | 25 #include "net/tools/quic/test_tools/http_message_test_utils.h" |
| 26 #include "net/tools/quic/test_tools/quic_client_peer.h" | 26 #include "net/tools/quic/test_tools/quic_client_peer.h" |
| 27 #include "net/tools/quic/test_tools/quic_epoll_connection_helper_peer.h" | 27 #include "net/tools/quic/test_tools/quic_epoll_connection_helper_peer.h" |
| 28 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" |
| 28 #include "net/tools/quic/test_tools/quic_test_client.h" | 29 #include "net/tools/quic/test_tools/quic_test_client.h" |
| 29 #include "net/tools/quic/test_tools/server_thread.h" | 30 #include "net/tools/quic/test_tools/server_thread.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 32 |
| 32 using base::StringPiece; | 33 using base::StringPiece; |
| 33 using base::WaitableEvent; | 34 using base::WaitableEvent; |
| 34 using net::test::QuicConnectionPeer; | 35 using net::test::QuicConnectionPeer; |
| 35 using net::test::QuicSessionPeer; | 36 using net::test::QuicSessionPeer; |
| 36 using net::test::ReliableQuicStreamPeer; | 37 using net::test::ReliableQuicStreamPeer; |
| 37 using std::string; | 38 using std::string; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 51 | 52 |
| 52 void GenerateBody(string* body, int length) { | 53 void GenerateBody(string* body, int length) { |
| 53 body->clear(); | 54 body->clear(); |
| 54 body->reserve(length); | 55 body->reserve(length); |
| 55 for (int i = 0; i < length; ++i) { | 56 for (int i = 0; i < length; ++i) { |
| 56 body->append(1, static_cast<char>(32 + i % (126 - 32))); | 57 body->append(1, static_cast<char>(32 + i % (126 - 32))); |
| 57 } | 58 } |
| 58 } | 59 } |
| 59 | 60 |
| 60 class EndToEndTest : public ::testing::TestWithParam<QuicVersion> { | 61 class EndToEndTest : public ::testing::TestWithParam<QuicVersion> { |
| 61 public: | |
| 62 static void SetUpTestCase() { | |
| 63 QuicInMemoryCache::GetInstance()->ResetForTests(); | |
| 64 } | |
| 65 | |
| 66 protected: | 62 protected: |
| 67 EndToEndTest() | 63 EndToEndTest() |
| 68 : server_hostname_("example.com"), | 64 : server_hostname_("example.com"), |
| 69 server_started_(false), | 65 server_started_(false), |
| 70 strike_register_no_startup_period_(false) { | 66 strike_register_no_startup_period_(false) { |
| 71 net::IPAddressNumber ip; | 67 net::IPAddressNumber ip; |
| 72 CHECK(net::ParseIPLiteralToNumber("127.0.0.1", &ip)); | 68 CHECK(net::ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 73 server_address_ = IPEndPoint(ip, 0); | 69 server_address_ = IPEndPoint(ip, 0); |
| 74 QuicConnection::g_acks_do_not_instigate_acks = true; | 70 QuicConnection::g_acks_do_not_instigate_acks = true; |
| 75 FLAGS_track_retransmission_history = true; | 71 FLAGS_track_retransmission_history = true; |
| 76 client_config_.SetDefaults(); | 72 client_config_.SetDefaults(); |
| 77 server_config_.SetDefaults(); | 73 server_config_.SetDefaults(); |
| 78 | 74 |
| 75 QuicInMemoryCachePeer::ResetForTests(); |
| 79 AddToCache("GET", kLargeRequest, "HTTP/1.1", "200", "OK", kFooResponseBody); | 76 AddToCache("GET", kLargeRequest, "HTTP/1.1", "200", "OK", kFooResponseBody); |
| 80 AddToCache("GET", "https://www.google.com/foo", | 77 AddToCache("GET", "https://www.google.com/foo", |
| 81 "HTTP/1.1", "200", "OK", kFooResponseBody); | 78 "HTTP/1.1", "200", "OK", kFooResponseBody); |
| 82 AddToCache("GET", "https://www.google.com/bar", | 79 AddToCache("GET", "https://www.google.com/bar", |
| 83 "HTTP/1.1", "200", "OK", kBarResponseBody); | 80 "HTTP/1.1", "200", "OK", kBarResponseBody); |
| 84 version_ = GetParam(); | 81 version_ = GetParam(); |
| 85 } | 82 } |
| 86 | 83 |
| 84 virtual ~EndToEndTest() { |
| 85 QuicInMemoryCachePeer::ResetForTests(); |
| 86 } |
| 87 |
| 87 virtual QuicTestClient* CreateQuicClient() { | 88 virtual QuicTestClient* CreateQuicClient() { |
| 88 QuicTestClient* client = new QuicTestClient(server_address_, | 89 QuicTestClient* client = new QuicTestClient(server_address_, |
| 89 server_hostname_, | 90 server_hostname_, |
| 90 false, // not secure | 91 false, // not secure |
| 91 client_config_, | 92 client_config_, |
| 92 version_); | 93 version_); |
| 93 client->Connect(); | 94 client->Connect(); |
| 94 return client; | 95 return client; |
| 95 } | 96 } |
| 96 | 97 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 124 server_thread_->Join(); | 125 server_thread_->Join(); |
| 125 } | 126 } |
| 126 } | 127 } |
| 127 | 128 |
| 128 void AddToCache(StringPiece method, | 129 void AddToCache(StringPiece method, |
| 129 StringPiece path, | 130 StringPiece path, |
| 130 StringPiece version, | 131 StringPiece version, |
| 131 StringPiece response_code, | 132 StringPiece response_code, |
| 132 StringPiece response_detail, | 133 StringPiece response_detail, |
| 133 StringPiece body) { | 134 StringPiece body) { |
| 134 QuicInMemoryCache::GetInstance()->AddOrVerifyResponse( | 135 QuicInMemoryCache::GetInstance()->AddSimpleResponse( |
| 135 method, path, version, response_code, response_detail, body); | 136 method, path, version, response_code, response_detail, body); |
| 136 } | 137 } |
| 137 | 138 |
| 138 IPEndPoint server_address_; | 139 IPEndPoint server_address_; |
| 139 string server_hostname_; | 140 string server_hostname_; |
| 140 scoped_ptr<ServerThread> server_thread_; | 141 scoped_ptr<ServerThread> server_thread_; |
| 141 scoped_ptr<QuicTestClient> client_; | 142 scoped_ptr<QuicTestClient> client_; |
| 142 bool server_started_; | 143 bool server_started_; |
| 143 QuicConfig client_config_; | 144 QuicConfig client_config_; |
| 144 QuicConfig server_config_; | 145 QuicConfig server_config_; |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 QuicEpollConnectionHelperPeer::SetWriter(helper, NULL); | 660 QuicEpollConnectionHelperPeer::SetWriter(helper, NULL); |
| 660 | 661 |
| 661 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); | 662 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); |
| 662 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); | 663 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); |
| 663 } | 664 } |
| 664 | 665 |
| 665 } // namespace | 666 } // namespace |
| 666 } // namespace test | 667 } // namespace test |
| 667 } // namespace tools | 668 } // namespace tools |
| 668 } // namespace net | 669 } // namespace net |
| OLD | NEW |