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 "net/quic/quic_http_stream.h" | 5 #include "net/quic/quic_http_stream.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 stream_->ReadResponseHeaders(callback_.callback())); | 344 stream_->ReadResponseHeaders(callback_.callback())); |
345 | 345 |
346 // Send the response without a body. | 346 // Send the response without a body. |
347 SetResponseString("404 Not Found", std::string()); | 347 SetResponseString("404 Not Found", std::string()); |
348 scoped_ptr<QuicEncryptedPacket> resp( | 348 scoped_ptr<QuicEncryptedPacket> resp( |
349 ConstructDataPacket(2, false, kFin, 0, response_data_)); | 349 ConstructDataPacket(2, false, kFin, 0, response_data_)); |
350 ProcessPacket(*resp); | 350 ProcessPacket(*resp); |
351 | 351 |
352 // Now that the headers have been processed, the callback will return. | 352 // Now that the headers have been processed, the callback will return. |
353 EXPECT_EQ(OK, callback_.WaitForResult()); | 353 EXPECT_EQ(OK, callback_.WaitForResult()); |
354 ASSERT_TRUE(response_.headers != NULL); | 354 ASSERT_TRUE(response_.headers.get() != NULL); |
355 EXPECT_EQ(404, response_.headers->response_code()); | 355 EXPECT_EQ(404, response_.headers->response_code()); |
356 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); | 356 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
357 | 357 |
358 // There is no body, so this should return immediately. | 358 // There is no body, so this should return immediately. |
359 EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(), | 359 EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(), |
360 read_buffer_->size(), | 360 read_buffer_->size(), |
361 callback_.callback())); | 361 callback_.callback())); |
362 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | 362 EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
363 EXPECT_TRUE(AtEof()); | 363 EXPECT_TRUE(AtEof()); |
364 } | 364 } |
(...skipping 21 matching lines...) Expand all Loading... |
386 stream_->ReadResponseHeaders(callback_.callback())); | 386 stream_->ReadResponseHeaders(callback_.callback())); |
387 | 387 |
388 // Send the response with a body. | 388 // Send the response with a body. |
389 SetResponseString("200 OK", "hello world!"); | 389 SetResponseString("200 OK", "hello world!"); |
390 scoped_ptr<QuicEncryptedPacket> resp( | 390 scoped_ptr<QuicEncryptedPacket> resp( |
391 ConstructDataPacket(2, false, kFin, 0, response_data_)); | 391 ConstructDataPacket(2, false, kFin, 0, response_data_)); |
392 ProcessPacket(*resp); | 392 ProcessPacket(*resp); |
393 | 393 |
394 // Now that the headers have been processed, the callback will return. | 394 // Now that the headers have been processed, the callback will return. |
395 EXPECT_EQ(OK, callback_.WaitForResult()); | 395 EXPECT_EQ(OK, callback_.WaitForResult()); |
396 ASSERT_TRUE(response_.headers != NULL); | 396 ASSERT_TRUE(response_.headers.get() != NULL); |
397 EXPECT_EQ(200, response_.headers->response_code()); | 397 EXPECT_EQ(200, response_.headers->response_code()); |
398 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); | 398 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
399 | 399 |
400 // There is no body, so this should return immediately. | 400 // There is no body, so this should return immediately. |
401 // Since the body has already arrived, this should return immediately. | 401 // Since the body has already arrived, this should return immediately. |
402 EXPECT_EQ(12, stream_->ReadResponseBody(read_buffer_.get(), | 402 EXPECT_EQ(12, stream_->ReadResponseBody(read_buffer_.get(), |
403 read_buffer_->size(), | 403 read_buffer_->size(), |
404 callback_.callback())); | 404 callback_.callback())); |
405 EXPECT_TRUE(stream_->IsResponseBodyComplete()); | 405 EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
406 EXPECT_TRUE(AtEof()); | 406 EXPECT_TRUE(AtEof()); |
(...skipping 29 matching lines...) Expand all Loading... |
436 ProcessPacket(*ack); | 436 ProcessPacket(*ack); |
437 | 437 |
438 // Send the response headers (but not the body). | 438 // Send the response headers (but not the body). |
439 SetResponseString("200 OK", std::string()); | 439 SetResponseString("200 OK", std::string()); |
440 scoped_ptr<QuicEncryptedPacket> resp( | 440 scoped_ptr<QuicEncryptedPacket> resp( |
441 ConstructDataPacket(2, false, !kFin, 0, response_data_)); | 441 ConstructDataPacket(2, false, !kFin, 0, response_data_)); |
442 ProcessPacket(*resp); | 442 ProcessPacket(*resp); |
443 | 443 |
444 // Since the headers have already arrived, this should return immediately. | 444 // Since the headers have already arrived, this should return immediately. |
445 EXPECT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); | 445 EXPECT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); |
446 ASSERT_TRUE(response_.headers != NULL); | 446 ASSERT_TRUE(response_.headers.get() != NULL); |
447 EXPECT_EQ(200, response_.headers->response_code()); | 447 EXPECT_EQ(200, response_.headers->response_code()); |
448 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); | 448 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
449 | 449 |
450 // Send the response body. | 450 // Send the response body. |
451 const char kResponseBody[] = "Hello world!"; | 451 const char kResponseBody[] = "Hello world!"; |
452 scoped_ptr<QuicEncryptedPacket> resp_body( | 452 scoped_ptr<QuicEncryptedPacket> resp_body( |
453 ConstructDataPacket(3, false, kFin, response_data_.length(), | 453 ConstructDataPacket(3, false, kFin, response_data_.length(), |
454 kResponseBody)); | 454 kResponseBody)); |
455 ProcessPacket(*resp_body); | 455 ProcessPacket(*resp_body); |
456 | 456 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 ProcessPacket(*ack); | 498 ProcessPacket(*ack); |
499 | 499 |
500 // Send the response headers (but not the body). | 500 // Send the response headers (but not the body). |
501 SetResponseString("200 OK", std::string()); | 501 SetResponseString("200 OK", std::string()); |
502 scoped_ptr<QuicEncryptedPacket> resp( | 502 scoped_ptr<QuicEncryptedPacket> resp( |
503 ConstructDataPacket(2, false, !kFin, 0, response_data_)); | 503 ConstructDataPacket(2, false, !kFin, 0, response_data_)); |
504 ProcessPacket(*resp); | 504 ProcessPacket(*resp); |
505 | 505 |
506 // Since the headers have already arrived, this should return immediately. | 506 // Since the headers have already arrived, this should return immediately. |
507 ASSERT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); | 507 ASSERT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); |
508 ASSERT_TRUE(response_.headers != NULL); | 508 ASSERT_TRUE(response_.headers.get() != NULL); |
509 EXPECT_EQ(200, response_.headers->response_code()); | 509 EXPECT_EQ(200, response_.headers->response_code()); |
510 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); | 510 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
511 | 511 |
512 // Send the response body. | 512 // Send the response body. |
513 const char kResponseBody[] = "Hello world!"; | 513 const char kResponseBody[] = "Hello world!"; |
514 scoped_ptr<QuicEncryptedPacket> resp_body( | 514 scoped_ptr<QuicEncryptedPacket> resp_body( |
515 ConstructDataPacket(3, false, kFin, response_data_.length(), | 515 ConstructDataPacket(3, false, kFin, response_data_.length(), |
516 kResponseBody)); | 516 kResponseBody)); |
517 ProcessPacket(*resp_body); | 517 ProcessPacket(*resp_body); |
518 | 518 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 | 555 |
556 // In the course of processing this packet, the QuicHttpStream close itself. | 556 // In the course of processing this packet, the QuicHttpStream close itself. |
557 ProcessPacket(*resp); | 557 ProcessPacket(*resp); |
558 | 558 |
559 EXPECT_TRUE(AtEof()); | 559 EXPECT_TRUE(AtEof()); |
560 } | 560 } |
561 | 561 |
562 } // namespace test | 562 } // namespace test |
563 | 563 |
564 } // namespace net | 564 } // namespace net |
OLD | NEW |