| 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 "base/threading/simple_thread.h" | 12 #include "base/threading/simple_thread.h" |
| 13 #include "net/base/ip_endpoint.h" | 13 #include "net/base/ip_endpoint.h" |
| 14 // TODO(rtenneti): Delete this when NSS is supported. | |
| 15 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 14 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
| 16 #include "net/quic/crypto/null_encrypter.h" | 15 #include "net/quic/crypto/null_encrypter.h" |
| 17 #include "net/quic/quic_framer.h" | 16 #include "net/quic/quic_framer.h" |
| 18 #include "net/quic/quic_packet_creator.h" | 17 #include "net/quic/quic_packet_creator.h" |
| 19 #include "net/quic/quic_protocol.h" | 18 #include "net/quic/quic_protocol.h" |
| 20 #include "net/quic/test_tools/quic_connection_peer.h" | 19 #include "net/quic/test_tools/quic_connection_peer.h" |
| 21 #include "net/quic/test_tools/quic_session_peer.h" | 20 #include "net/quic/test_tools/quic_session_peer.h" |
| 22 #include "net/quic/test_tools/reliable_quic_stream_peer.h" | 21 #include "net/quic/test_tools/reliable_quic_stream_peer.h" |
| 23 #include "net/tools/quic/quic_epoll_connection_helper.h" | 22 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 24 #include "net/tools/quic/quic_in_memory_cache.h" | 23 #include "net/tools/quic/quic_in_memory_cache.h" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 } | 244 } |
| 246 | 245 |
| 247 ASSERT_TRUE(Initialize()); | 246 ASSERT_TRUE(Initialize()); |
| 248 | 247 |
| 249 HTTPMessage request(HttpConstants::HTTP_1_1, | 248 HTTPMessage request(HttpConstants::HTTP_1_1, |
| 250 HttpConstants::POST, "/foo"); | 249 HttpConstants::POST, "/foo"); |
| 251 request.set_has_complete_message(false); | 250 request.set_has_complete_message(false); |
| 252 | 251 |
| 253 client_->SendMessage(request); | 252 client_->SendMessage(request); |
| 254 | 253 |
| 255 client_->SendData(std::string(), true); | 254 client_->SendData(string(), true); |
| 256 | 255 |
| 257 client_->WaitForResponse(); | 256 client_->WaitForResponse(); |
| 258 EXPECT_EQ(kFooResponseBody, client_->response_body()); | 257 EXPECT_EQ(kFooResponseBody, client_->response_body()); |
| 259 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 258 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 260 | 259 |
| 261 request.AddBody("foo", true); | 260 request.AddBody("foo", true); |
| 262 | 261 |
| 263 client_->SendMessage(request); | 262 client_->SendMessage(request); |
| 264 client_->SendData(std::string(), true); | 263 client_->SendData(string(), true); |
| 265 client_->WaitForResponse(); | 264 client_->WaitForResponse(); |
| 266 EXPECT_EQ(kFooResponseBody, client_->response_body()); | 265 EXPECT_EQ(kFooResponseBody, client_->response_body()); |
| 267 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 266 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 268 } | 267 } |
| 269 | 268 |
| 270 TEST_F(EndToEndTest, MultipleRequestResponse) { | 269 TEST_F(EndToEndTest, MultipleRequestResponse) { |
| 271 // TODO(rtenneti): Delete this when NSS is supported. | 270 // TODO(rtenneti): Delete this when NSS is supported. |
| 272 if (!Aes128Gcm12Encrypter::IsSupported()) { | 271 if (!Aes128Gcm12Encrypter::IsSupported()) { |
| 273 LOG(INFO) << "AES GCM not supported. Test skipped."; | 272 LOG(INFO) << "AES GCM not supported. Test skipped."; |
| 274 return; | 273 return; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 325 |
| 327 // TODO(rch) handle this better when we have different encryption options. | 326 // TODO(rch) handle this better when we have different encryption options. |
| 328 size_t stream_data = 3; | 327 size_t stream_data = 3; |
| 329 size_t stream_payload_size = QuicFramer::GetMinStreamFrameSize() + | 328 size_t stream_payload_size = QuicFramer::GetMinStreamFrameSize() + |
| 330 stream_data; | 329 stream_data; |
| 331 size_t min_payload_size = | 330 size_t min_payload_size = |
| 332 std::max(kCongestionFeedbackFrameSize, stream_payload_size); | 331 std::max(kCongestionFeedbackFrameSize, stream_payload_size); |
| 333 size_t ciphertext_size = NullEncrypter().GetCiphertextSize(min_payload_size); | 332 size_t ciphertext_size = NullEncrypter().GetCiphertextSize(min_payload_size); |
| 334 // TODO(satyashekhar): Fix this when versioning is implemented. | 333 // TODO(satyashekhar): Fix this when versioning is implemented. |
| 335 client_->options()->max_packet_length = | 334 client_->options()->max_packet_length = |
| 336 GetPacketHeaderSize(!kIncludeVersion) + ciphertext_size; | 335 GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion, |
| 336 NOT_IN_FEC_GROUP) + |
| 337 ciphertext_size; |
| 337 | 338 |
| 338 // Make sure our request is too large to fit in one packet. | 339 // Make sure our request is too large to fit in one packet. |
| 339 EXPECT_GT(strlen(kLargeRequest), min_payload_size); | 340 EXPECT_GT(strlen(kLargeRequest), min_payload_size); |
| 340 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest(kLargeRequest)); | 341 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest(kLargeRequest)); |
| 341 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 342 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 342 } | 343 } |
| 343 | 344 |
| 344 TEST_F(EndToEndTest, MultipleFramesRandomOrder) { | 345 TEST_F(EndToEndTest, MultipleFramesRandomOrder) { |
| 345 // TODO(rtenneti): Delete this when NSS is supported. | 346 // TODO(rtenneti): Delete this when NSS is supported. |
| 346 if (!Aes128Gcm12Encrypter::IsSupported()) { | 347 if (!Aes128Gcm12Encrypter::IsSupported()) { |
| 347 LOG(INFO) << "AES GCM not supported. Test skipped."; | 348 LOG(INFO) << "AES GCM not supported. Test skipped."; |
| 348 return; | 349 return; |
| 349 } | 350 } |
| 350 | 351 |
| 351 ASSERT_TRUE(Initialize()); | 352 ASSERT_TRUE(Initialize()); |
| 352 // Set things up so we have a small payload, to guarantee fragmentation. | 353 // Set things up so we have a small payload, to guarantee fragmentation. |
| 353 // A congestion feedback frame can't be split into multiple packets, make sure | 354 // A congestion feedback frame can't be split into multiple packets, make sure |
| 354 // that our packet have room for at least this amount after the normal headers | 355 // that our packet have room for at least this amount after the normal headers |
| 355 // are added. | 356 // are added. |
| 356 | 357 |
| 357 // TODO(rch) handle this better when we have different encryption options. | 358 // TODO(rch) handle this better when we have different encryption options. |
| 358 size_t stream_data = 3; | 359 size_t stream_data = 3; |
| 359 size_t stream_payload_size = QuicFramer::GetMinStreamFrameSize() + | 360 size_t stream_payload_size = QuicFramer::GetMinStreamFrameSize() + |
| 360 stream_data; | 361 stream_data; |
| 361 size_t min_payload_size = | 362 size_t min_payload_size = |
| 362 std::max(kCongestionFeedbackFrameSize, stream_payload_size); | 363 std::max(kCongestionFeedbackFrameSize, stream_payload_size); |
| 363 size_t ciphertext_size = NullEncrypter().GetCiphertextSize(min_payload_size); | 364 size_t ciphertext_size = NullEncrypter().GetCiphertextSize(min_payload_size); |
| 364 // TODO(satyashekhar): Fix this when versioning is implemented. | 365 // TODO(satyashekhar): Fix this when versioning is implemented. |
| 365 client_->options()->max_packet_length = | 366 client_->options()->max_packet_length = |
| 366 GetPacketHeaderSize(!kIncludeVersion) + ciphertext_size; | 367 GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion, |
| 368 NOT_IN_FEC_GROUP) + |
| 369 ciphertext_size; |
| 367 client_->options()->random_reorder = true; | 370 client_->options()->random_reorder = true; |
| 368 | 371 |
| 369 // Make sure our request is too large to fit in one packet. | 372 // Make sure our request is too large to fit in one packet. |
| 370 EXPECT_GT(strlen(kLargeRequest), min_payload_size); | 373 EXPECT_GT(strlen(kLargeRequest), min_payload_size); |
| 371 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest(kLargeRequest)); | 374 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest(kLargeRequest)); |
| 372 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 375 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 373 } | 376 } |
| 374 | 377 |
| 375 TEST_F(EndToEndTest, PostMissingBytes) { | 378 TEST_F(EndToEndTest, PostMissingBytes) { |
| 376 // TODO(rtenneti): Delete this when NSS is supported. | 379 // TODO(rtenneti): Delete this when NSS is supported. |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 QuicEpollConnectionHelperPeer::SetWriter(helper, NULL); | 599 QuicEpollConnectionHelperPeer::SetWriter(helper, NULL); |
| 597 | 600 |
| 598 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); | 601 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); |
| 599 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); | 602 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); |
| 600 } | 603 } |
| 601 | 604 |
| 602 } // namespace | 605 } // namespace |
| 603 } // namespace test | 606 } // namespace test |
| 604 } // namespace tools | 607 } // namespace tools |
| 605 } // namespace net | 608 } // namespace net |
| OLD | NEW |