Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(482)

Side by Side Diff: net/tools/quic/end_to_end_test.cc

Issue 15074007: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix for windows Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/socket/socket_test_util.cc ('k') | net/tools/quic/quic_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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. 14 // TODO(rtenneti): Delete this when NSS is supported.
15 #include "net/quic/crypto/aes_128_gcm_encrypter.h" 15 #include "net/quic/crypto/aes_128_gcm_encrypter.h"
16 #include "net/quic/crypto/null_encrypter.h" 16 #include "net/quic/crypto/null_encrypter.h"
17 #include "net/quic/quic_framer.h" 17 #include "net/quic/quic_framer.h"
18 #include "net/quic/quic_packet_creator.h" 18 #include "net/quic/quic_packet_creator.h"
19 #include "net/quic/quic_protocol.h" 19 #include "net/quic/quic_protocol.h"
20 #include "net/quic/test_tools/quic_connection_peer.h"
20 #include "net/quic/test_tools/quic_session_peer.h" 21 #include "net/quic/test_tools/quic_session_peer.h"
21 #include "net/quic/test_tools/reliable_quic_stream_peer.h" 22 #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_in_memory_cache.h" 24 #include "net/tools/quic/quic_in_memory_cache.h"
23 #include "net/tools/quic/quic_server.h" 25 #include "net/tools/quic/quic_server.h"
26 #include "net/tools/quic/quic_socket_utils.h"
24 #include "net/tools/quic/test_tools/http_message_test_utils.h" 27 #include "net/tools/quic/test_tools/http_message_test_utils.h"
28 #include "net/tools/quic/test_tools/quic_client_peer.h"
29 #include "net/tools/quic/test_tools/quic_epoll_connection_helper_peer.h"
25 #include "net/tools/quic/test_tools/quic_test_client.h" 30 #include "net/tools/quic/test_tools/quic_test_client.h"
26 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
27 32
28 using base::StringPiece; 33 using base::StringPiece;
29 using base::WaitableEvent; 34 using base::WaitableEvent;
35 using net::test::QuicConnectionPeer;
30 using net::test::QuicSessionPeer; 36 using net::test::QuicSessionPeer;
31 using net::test::ReliableQuicStreamPeer; 37 using net::test::ReliableQuicStreamPeer;
32 using std::string; 38 using std::string;
33 39
34 namespace net { 40 namespace net {
35 namespace tools { 41 namespace tools {
36 namespace test { 42 namespace test {
37 namespace { 43 namespace {
38 44
39 const char* kFooResponseBody = "Artichoke hearts make me happy."; 45 const char* kFooResponseBody = "Artichoke hearts make me happy.";
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 TEST_F(EndToEndTest, SimpleRequestResponse) { 208 TEST_F(EndToEndTest, SimpleRequestResponse) {
203 // TODO(rtenneti): Delete this when NSS is supported. 209 // TODO(rtenneti): Delete this when NSS is supported.
204 if (!Aes128GcmEncrypter::IsSupported()) { 210 if (!Aes128GcmEncrypter::IsSupported()) {
205 LOG(INFO) << "AES GCM not supported. Test skipped."; 211 LOG(INFO) << "AES GCM not supported. Test skipped.";
206 return; 212 return;
207 } 213 }
208 214
209 ASSERT_TRUE(Initialize()); 215 ASSERT_TRUE(Initialize());
210 216
211 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); 217 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo"));
212 EXPECT_EQ(200ul, client_->response_headers()->parsed_response_code()); 218 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
213 } 219 }
214 220
215 TEST_F(EndToEndTest, SimpleRequestResponsev6) { 221 TEST_F(EndToEndTest, SimpleRequestResponsev6) {
216 // TODO(rtenneti): Delete this when NSS is supported. 222 // TODO(rtenneti): Delete this when NSS is supported.
217 if (!Aes128GcmEncrypter::IsSupported()) { 223 if (!Aes128GcmEncrypter::IsSupported()) {
218 LOG(INFO) << "AES GCM not supported. Test skipped."; 224 LOG(INFO) << "AES GCM not supported. Test skipped.";
219 return; 225 return;
220 } 226 }
221 227
222 IPAddressNumber ip; 228 IPAddressNumber ip;
223 CHECK(net::ParseIPLiteralToNumber("::", &ip)); 229 CHECK(net::ParseIPLiteralToNumber("::1", &ip));
224 server_address_ = IPEndPoint(ip, server_address_.port()); 230 server_address_ = IPEndPoint(ip, server_address_.port());
225 ASSERT_TRUE(Initialize()); 231 ASSERT_TRUE(Initialize());
226 232
227 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); 233 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo"));
228 EXPECT_EQ(200ul, client_->response_headers()->parsed_response_code()); 234 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
229 } 235 }
230 236
231 TEST_F(EndToEndTest, SeparateFinPacket) { 237 TEST_F(EndToEndTest, SeparateFinPacket) {
232 // TODO(rtenneti): Delete this when NSS is supported. 238 // TODO(rtenneti): Delete this when NSS is supported.
233 if (!Aes128GcmEncrypter::IsSupported()) { 239 if (!Aes128GcmEncrypter::IsSupported()) {
234 LOG(INFO) << "AES GCM not supported. Test skipped."; 240 LOG(INFO) << "AES GCM not supported. Test skipped.";
235 return; 241 return;
236 } 242 }
237 243
238 ASSERT_TRUE(Initialize()); 244 ASSERT_TRUE(Initialize());
239 245
240 HTTPMessage request(HttpConstants::HTTP_1_1, 246 HTTPMessage request(HttpConstants::HTTP_1_1,
241 HttpConstants::POST, "/foo"); 247 HttpConstants::POST, "/foo");
242 request.set_has_complete_message(false); 248 request.set_has_complete_message(false);
243 249
244 client_->SendMessage(request); 250 client_->SendMessage(request);
245 251
246 client_->SendData(std::string(), true); 252 client_->SendData(std::string(), true);
247 253
248 client_->WaitForResponse(); 254 client_->WaitForResponse();
249 EXPECT_EQ(kFooResponseBody, client_->response_body()); 255 EXPECT_EQ(kFooResponseBody, client_->response_body());
250 EXPECT_EQ(200ul, client_->response_headers()->parsed_response_code()); 256 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
251 257
252 request.AddBody("foo", true); 258 request.AddBody("foo", true);
253 259
254 client_->SendMessage(request); 260 client_->SendMessage(request);
255 client_->SendData(std::string(), true); 261 client_->SendData(std::string(), true);
256 client_->WaitForResponse(); 262 client_->WaitForResponse();
257 EXPECT_EQ(kFooResponseBody, client_->response_body()); 263 EXPECT_EQ(kFooResponseBody, client_->response_body());
258 EXPECT_EQ(200ul, client_->response_headers()->parsed_response_code()); 264 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
259 } 265 }
260 266
261 TEST_F(EndToEndTest, MultipleRequestResponse) { 267 TEST_F(EndToEndTest, MultipleRequestResponse) {
262 // TODO(rtenneti): Delete this when NSS is supported. 268 // TODO(rtenneti): Delete this when NSS is supported.
263 if (!Aes128GcmEncrypter::IsSupported()) { 269 if (!Aes128GcmEncrypter::IsSupported()) {
264 LOG(INFO) << "AES GCM not supported. Test skipped."; 270 LOG(INFO) << "AES GCM not supported. Test skipped.";
265 return; 271 return;
266 } 272 }
267 273
268 ASSERT_TRUE(Initialize()); 274 ASSERT_TRUE(Initialize());
269 275
270 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); 276 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo"));
271 EXPECT_EQ(200ul, client_->response_headers()->parsed_response_code()); 277 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
272 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); 278 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar"));
273 EXPECT_EQ(200ul, client_->response_headers()->parsed_response_code()); 279 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
274 } 280 }
275 281
276 TEST_F(EndToEndTest, MultipleClients) { 282 TEST_F(EndToEndTest, MultipleClients) {
277 // TODO(rtenneti): Delete this when NSS is supported. 283 // TODO(rtenneti): Delete this when NSS is supported.
278 if (!Aes128GcmEncrypter::IsSupported()) { 284 if (!Aes128GcmEncrypter::IsSupported()) {
279 LOG(INFO) << "AES GCM not supported. Test skipped."; 285 LOG(INFO) << "AES GCM not supported. Test skipped.";
280 return; 286 return;
281 } 287 }
282 288
283 ASSERT_TRUE(Initialize()); 289 ASSERT_TRUE(Initialize());
284 scoped_ptr<QuicTestClient> client2(CreateQuicClient()); 290 scoped_ptr<QuicTestClient> client2(CreateQuicClient());
285 291
286 HTTPMessage request(HttpConstants::HTTP_1_1, 292 HTTPMessage request(HttpConstants::HTTP_1_1,
287 HttpConstants::POST, "/foo"); 293 HttpConstants::POST, "/foo");
288 request.AddHeader("content-length", "3"); 294 request.AddHeader("content-length", "3");
289 request.set_has_complete_message(false); 295 request.set_has_complete_message(false);
290 296
291 client_->SendMessage(request); 297 client_->SendMessage(request);
292 client2->SendMessage(request); 298 client2->SendMessage(request);
293 299
294 client_->SendData("bar", true); 300 client_->SendData("bar", true);
295 client_->WaitForResponse(); 301 client_->WaitForResponse();
296 EXPECT_EQ(kFooResponseBody, client_->response_body()); 302 EXPECT_EQ(kFooResponseBody, client_->response_body());
297 EXPECT_EQ(200ul, client_->response_headers()->parsed_response_code()); 303 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
298 304
299 client2->SendData("eep", true); 305 client2->SendData("eep", true);
300 client2->WaitForResponse(); 306 client2->WaitForResponse();
301 EXPECT_EQ(kFooResponseBody, client2->response_body()); 307 EXPECT_EQ(kFooResponseBody, client2->response_body());
302 EXPECT_EQ(200ul, client2->response_headers()->parsed_response_code()); 308 EXPECT_EQ(200u, client2->response_headers()->parsed_response_code());
303 } 309 }
304 310
305 TEST_F(EndToEndTest, RequestOverMultiplePackets) { 311 TEST_F(EndToEndTest, RequestOverMultiplePackets) {
306 // TODO(rtenneti): Delete this when NSS is supported. 312 // TODO(rtenneti): Delete this when NSS is supported.
307 if (!Aes128GcmEncrypter::IsSupported()) { 313 if (!Aes128GcmEncrypter::IsSupported()) {
308 LOG(INFO) << "AES GCM not supported. Test skipped."; 314 LOG(INFO) << "AES GCM not supported. Test skipped.";
309 return; 315 return;
310 } 316 }
311 317
312 ASSERT_TRUE(Initialize()); 318 ASSERT_TRUE(Initialize());
313 // Set things up so we have a small payload, to guarantee fragmentation. 319 // Set things up so we have a small payload, to guarantee fragmentation.
314 // A congestion feedback frame can't be split into multiple packets, make sure 320 // A congestion feedback frame can't be split into multiple packets, make sure
315 // that our packet have room for at least this amount after the normal headers 321 // that our packet have room for at least this amount after the normal headers
316 // are added. 322 // are added.
317 323
318 // TODO(rch) handle this better when we have different encryption options. 324 // TODO(rch) handle this better when we have different encryption options.
319 size_t stream_data = 3; 325 size_t stream_data = 3;
320 size_t stream_payload_size = QuicFramer::GetMinStreamFrameSize() + 326 size_t stream_payload_size = QuicFramer::GetMinStreamFrameSize() +
321 stream_data; 327 stream_data;
322 size_t min_payload_size = 328 size_t min_payload_size =
323 std::max(kCongestionFeedbackFrameSize, stream_payload_size); 329 std::max(kCongestionFeedbackFrameSize, stream_payload_size);
324 size_t ciphertext_size = NullEncrypter().GetCiphertextSize(min_payload_size); 330 size_t ciphertext_size = NullEncrypter().GetCiphertextSize(min_payload_size);
325 // TODO(satyashekhar): Fix this when versioning is implemented. 331 // TODO(satyashekhar): Fix this when versioning is implemented.
326 client_->options()->max_packet_length = 332 client_->options()->max_packet_length =
327 GetPacketHeaderSize(!kIncludeVersion) + ciphertext_size; 333 GetPacketHeaderSize(!kIncludeVersion) + ciphertext_size;
328 334
329 // Make sure our request is too large to fit in one packet. 335 // Make sure our request is too large to fit in one packet.
330 EXPECT_GT(strlen(kLargeRequest), min_payload_size); 336 EXPECT_GT(strlen(kLargeRequest), min_payload_size);
331 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest(kLargeRequest)); 337 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest(kLargeRequest));
332 EXPECT_EQ(200ul, client_->response_headers()->parsed_response_code()); 338 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
333 } 339 }
334 340
335 TEST_F(EndToEndTest, MultipleFramesRandomOrder) { 341 TEST_F(EndToEndTest, MultipleFramesRandomOrder) {
336 // TODO(rtenneti): Delete this when NSS is supported. 342 // TODO(rtenneti): Delete this when NSS is supported.
337 if (!Aes128GcmEncrypter::IsSupported()) { 343 if (!Aes128GcmEncrypter::IsSupported()) {
338 LOG(INFO) << "AES GCM not supported. Test skipped."; 344 LOG(INFO) << "AES GCM not supported. Test skipped.";
339 return; 345 return;
340 } 346 }
341 347
342 ASSERT_TRUE(Initialize()); 348 ASSERT_TRUE(Initialize());
(...skipping 10 matching lines...) Expand all
353 std::max(kCongestionFeedbackFrameSize, stream_payload_size); 359 std::max(kCongestionFeedbackFrameSize, stream_payload_size);
354 size_t ciphertext_size = NullEncrypter().GetCiphertextSize(min_payload_size); 360 size_t ciphertext_size = NullEncrypter().GetCiphertextSize(min_payload_size);
355 // TODO(satyashekhar): Fix this when versioning is implemented. 361 // TODO(satyashekhar): Fix this when versioning is implemented.
356 client_->options()->max_packet_length = 362 client_->options()->max_packet_length =
357 GetPacketHeaderSize(!kIncludeVersion) + ciphertext_size; 363 GetPacketHeaderSize(!kIncludeVersion) + ciphertext_size;
358 client_->options()->random_reorder = true; 364 client_->options()->random_reorder = true;
359 365
360 // Make sure our request is too large to fit in one packet. 366 // Make sure our request is too large to fit in one packet.
361 EXPECT_GT(strlen(kLargeRequest), min_payload_size); 367 EXPECT_GT(strlen(kLargeRequest), min_payload_size);
362 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest(kLargeRequest)); 368 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest(kLargeRequest));
363 EXPECT_EQ(200ul, client_->response_headers()->parsed_response_code()); 369 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
364 } 370 }
365 371
366 TEST_F(EndToEndTest, PostMissingBytes) { 372 TEST_F(EndToEndTest, PostMissingBytes) {
367 // TODO(rtenneti): Delete this when NSS is supported. 373 // TODO(rtenneti): Delete this when NSS is supported.
368 if (!Aes128GcmEncrypter::IsSupported()) { 374 if (!Aes128GcmEncrypter::IsSupported()) {
369 LOG(INFO) << "AES GCM not supported. Test skipped."; 375 LOG(INFO) << "AES GCM not supported. Test skipped.";
370 return; 376 return;
371 } 377 }
372 378
373 ASSERT_TRUE(Initialize()); 379 ASSERT_TRUE(Initialize());
374 380
375 // Add a content length header with no body. 381 // Add a content length header with no body.
376 HTTPMessage request(HttpConstants::HTTP_1_1, 382 HTTPMessage request(HttpConstants::HTTP_1_1,
377 HttpConstants::POST, "/foo"); 383 HttpConstants::POST, "/foo");
378 request.AddHeader("content-length", "3"); 384 request.AddHeader("content-length", "3");
379 request.set_skip_message_validation(true); 385 request.set_skip_message_validation(true);
380 386
381 // This should be detected as stream fin without complete request, 387 // This should be detected as stream fin without complete request,
382 // triggering an error response. 388 // triggering an error response.
383 client_->SendCustomSynchronousRequest(request); 389 client_->SendCustomSynchronousRequest(request);
384 EXPECT_EQ("bad", client_->response_body()); 390 EXPECT_EQ("bad", client_->response_body());
385 EXPECT_EQ(500ul, client_->response_headers()->parsed_response_code()); 391 EXPECT_EQ(500u, client_->response_headers()->parsed_response_code());
386 } 392 }
387 393
388 TEST_F(EndToEndTest, LargePost) { 394 TEST_F(EndToEndTest, LargePost) {
389 // TODO(rtenneti): Delete this when NSS is supported. 395 // TODO(rtenneti): Delete this when NSS is supported.
390 if (!Aes128GcmEncrypter::IsSupported()) { 396 if (!Aes128GcmEncrypter::IsSupported()) {
391 LOG(INFO) << "AES GCM not supported. Test skipped."; 397 LOG(INFO) << "AES GCM not supported. Test skipped.";
392 return; 398 return;
393 } 399 }
394 400
395 // FLAGS_fake_packet_loss_percentage = 30; 401 // FLAGS_fake_packet_loss_percentage = 30;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 ASSERT_TRUE(Initialize()); 459 ASSERT_TRUE(Initialize());
454 460
455 string body; 461 string body;
456 GenerateBody(&body, kMaxPacketSize); 462 GenerateBody(&body, kMaxPacketSize);
457 463
458 HTTPMessage request(HttpConstants::HTTP_1_1, 464 HTTPMessage request(HttpConstants::HTTP_1_1,
459 HttpConstants::POST, "/foo"); 465 HttpConstants::POST, "/foo");
460 request.AddBody(body, true); 466 request.AddBody(body, true);
461 // Force the client to write with a stream ID belonging to a nonexistant 467 // Force the client to write with a stream ID belonging to a nonexistant
462 // server-side stream. 468 // server-side stream.
463 QuicSessionPeer::SetNextStreamId(2, client_->client()->session()); 469 QuicSessionPeer::SetNextStreamId(client_->client()->session(), 2);
464 470
465 client_->SendCustomSynchronousRequest(request); 471 client_->SendCustomSynchronousRequest(request);
466 // EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); 472 // EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error());
467 EXPECT_EQ(QUIC_PACKET_FOR_NONEXISTENT_STREAM, client_->connection_error()); 473 EXPECT_EQ(QUIC_PACKET_FOR_NONEXISTENT_STREAM, client_->connection_error());
468 } 474 }
469 475
470 TEST_F(EndToEndTest, MultipleTermination) { 476 TEST_F(EndToEndTest, MultipleTermination) {
471 // TODO(rtenneti): Delete this when NSS is supported. 477 // TODO(rtenneti): Delete this when NSS is supported.
472 if (!Aes128GcmEncrypter::IsSupported()) { 478 if (!Aes128GcmEncrypter::IsSupported()) {
473 LOG(INFO) << "AES GCM not supported. Test skipped."; 479 LOG(INFO) << "AES GCM not supported. Test skipped.";
(...skipping 24 matching lines...) Expand all
498 EXPECT_DEBUG_DEATH({ 504 EXPECT_DEBUG_DEATH({
499 client_->SendData("eep", true); 505 client_->SendData("eep", true);
500 client_->WaitForResponse(); 506 client_->WaitForResponse();
501 EXPECT_EQ(QUIC_MULTIPLE_TERMINATION_OFFSETS, client_->stream_error()); 507 EXPECT_EQ(QUIC_MULTIPLE_TERMINATION_OFFSETS, client_->stream_error());
502 }, 508 },
503 "Check failed: !fin_buffered_"); 509 "Check failed: !fin_buffered_");
504 } 510 }
505 511
506 /*TEST_F(EndToEndTest, Timeout) { 512 /*TEST_F(EndToEndTest, Timeout) {
507 config_.set_idle_connection_state_lifetime( 513 config_.set_idle_connection_state_lifetime(
514 QuicTime::Delta::FromMicroseconds(500),
508 QuicTime::Delta::FromMicroseconds(500)); 515 QuicTime::Delta::FromMicroseconds(500));
509 // Note: we do NOT ASSERT_TRUE: we may time out during initial handshake: 516 // Note: we do NOT ASSERT_TRUE: we may time out during initial handshake:
510 // that's enough to validate timeout in this case. 517 // that's enough to validate timeout in this case.
511 Initialize(); 518 Initialize();
512 while (client_->client()->connected()) { 519 while (client_->client()->connected()) {
513 client_->client()->WaitForEvents(); 520 client_->client()->WaitForEvents();
514 } 521 }
515 }*/ 522 }*/
516 523
517 TEST_F(EndToEndTest, ResetConnection) { 524 TEST_F(EndToEndTest, ResetConnection) {
518 // TODO(rtenneti): Delete this when NSS is supported. 525 // TODO(rtenneti): Delete this when NSS is supported.
519 if (!Aes128GcmEncrypter::IsSupported()) { 526 if (!Aes128GcmEncrypter::IsSupported()) {
520 LOG(INFO) << "AES GCM not supported. Test skipped."; 527 LOG(INFO) << "AES GCM not supported. Test skipped.";
521 return; 528 return;
522 } 529 }
523 530
524 ASSERT_TRUE(Initialize()); 531 ASSERT_TRUE(Initialize());
525 532
526 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); 533 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo"));
527 EXPECT_EQ(200ul, client_->response_headers()->parsed_response_code()); 534 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
528 client_->ResetConnection(); 535 client_->ResetConnection();
529 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); 536 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar"));
530 EXPECT_EQ(200ul, client_->response_headers()->parsed_response_code()); 537 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
538 }
539
540 class WrongAddressWriter : public QuicPacketWriter {
541 public:
542 explicit WrongAddressWriter(int fd) : fd_(fd) {
543 IPAddressNumber ip;
544 CHECK(net::ParseIPLiteralToNumber("127.0.0.2", &ip));
545 self_address_ = IPEndPoint(ip, 0);
546 }
547
548 virtual int WritePacket(const char* buffer, size_t buf_len,
549 const IPAddressNumber& real_self_address,
550 const IPEndPoint& peer_address,
551 QuicBlockedWriterInterface* blocked_writer,
552 int* error) OVERRIDE {
553 return QuicSocketUtils::WritePacket(fd_, buffer, buf_len,
554 self_address_.address(), peer_address,
555 error);
556 }
557
558 IPEndPoint self_address_;
559 int fd_;
560 };
561
562 TEST_F(EndToEndTest, ConnectionMigration) {
563 // TODO(rtenneti): Delete this when NSS is supported.
564 if (!Aes128GcmEncrypter::IsSupported()) {
565 LOG(INFO) << "AES GCM not supported. Test skipped.";
566 return;
567 }
568
569 ASSERT_TRUE(Initialize());
570
571 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo"));
572 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
573
574 WrongAddressWriter writer(QuicClientPeer::GetFd(client_->client()));
575 QuicEpollConnectionHelper* helper =
576 reinterpret_cast<QuicEpollConnectionHelper*>(
577 QuicConnectionPeer::GetHelper(
578 client_->client()->session()->connection()));
579 QuicEpollConnectionHelperPeer::SetWriter(helper, &writer);
580
581 client_->SendSynchronousRequest("/bar");
582 QuicEpollConnectionHelperPeer::SetWriter(helper, NULL);
583
584 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error());
585 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error());
531 } 586 }
532 587
533 } // namespace 588 } // namespace
534 } // namespace test 589 } // namespace test
535 } // namespace tools 590 } // namespace tools
536 } // namespace net 591 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/socket_test_util.cc ('k') | net/tools/quic/quic_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698