| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/base/client_socket_factory.h" | 5 #include "net/base/client_socket_factory.h" |
| 6 #include "net/base/test_completion_callback.h" | 6 #include "net/base/test_completion_callback.h" |
| 7 #include "net/base/upload_data.h" | 7 #include "net/base/upload_data.h" |
| 8 #include "net/http/http_network_session.h" | 8 #include "net/http/http_network_session.h" |
| 9 #include "net/http/http_network_transaction.h" | 9 #include "net/http/http_network_transaction.h" |
| 10 #include "net/http/http_transaction_unittest.h" | 10 #include "net/http/http_transaction_unittest.h" |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 rv = ReadTransaction(trans, &response_data); | 484 rv = ReadTransaction(trans, &response_data); |
| 485 EXPECT_EQ(net::OK, rv); | 485 EXPECT_EQ(net::OK, rv); |
| 486 EXPECT_TRUE(response_data == kExpectedResponseData[i]); | 486 EXPECT_TRUE(response_data == kExpectedResponseData[i]); |
| 487 | 487 |
| 488 trans->Destroy(); | 488 trans->Destroy(); |
| 489 | 489 |
| 490 // Empty the current queue. | 490 // Empty the current queue. |
| 491 MessageLoop::current()->RunAllPending(); | 491 MessageLoop::current()->RunAllPending(); |
| 492 } | 492 } |
| 493 } | 493 } |
| 494 |
| 495 // TODO(wtc): share code with KeepAliveConnectionReset. These two tests |
| 496 // differ only in data1_reads[2]. |
| 497 TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
| 498 scoped_refptr<net::HttpNetworkSession> session = CreateSession(); |
| 499 |
| 500 net::HttpRequestInfo request; |
| 501 request.method = "GET"; |
| 502 request.url = GURL("http://www.foo.com/"); |
| 503 request.load_flags = 0; |
| 504 |
| 505 MockRead data1_reads[] = { |
| 506 { true, 0, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n", -1 }, |
| 507 { true, 0, "hello", -1 }, |
| 508 { false, net::OK, NULL, 0 }, |
| 509 }; |
| 510 MockSocket data1; |
| 511 data1.connect.async = true; |
| 512 data1.connect.result = net::OK; |
| 513 data1.reads = data1_reads; |
| 514 mock_sockets[0] = &data1; |
| 515 |
| 516 MockRead data2_reads[] = { |
| 517 { true, 0, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n", -1 }, |
| 518 { true, 0, "world", -1 }, |
| 519 { true, net::OK, NULL, 0 }, |
| 520 }; |
| 521 MockSocket data2; |
| 522 data2.connect.async = true; |
| 523 data2.connect.result = net::OK; |
| 524 data2.reads = data2_reads; |
| 525 mock_sockets[1] = &data2; |
| 526 |
| 527 const char* kExpectedResponseData[] = { |
| 528 "hello", "world" |
| 529 }; |
| 530 |
| 531 for (int i = 0; i < 2; ++i) { |
| 532 TestCompletionCallback callback; |
| 533 |
| 534 net::HttpTransaction* trans = |
| 535 new net::HttpNetworkTransaction(session, &mock_socket_factory); |
| 536 |
| 537 int rv = trans->Start(&request, &callback); |
| 538 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 539 |
| 540 rv = callback.WaitForResult(); |
| 541 EXPECT_EQ(net::OK, rv); |
| 542 |
| 543 const net::HttpResponseInfo* response = trans->GetResponseInfo(); |
| 544 EXPECT_TRUE(response != NULL); |
| 545 |
| 546 EXPECT_TRUE(response->headers != NULL); |
| 547 EXPECT_TRUE(response->headers->GetStatusLine() == "HTTP/1.1 200 OK"); |
| 548 |
| 549 std::string response_data; |
| 550 rv = ReadTransaction(trans, &response_data); |
| 551 EXPECT_EQ(net::OK, rv); |
| 552 EXPECT_TRUE(response_data == kExpectedResponseData[i]); |
| 553 |
| 554 trans->Destroy(); |
| 555 |
| 556 // Empty the current queue. |
| 557 MessageLoop::current()->RunAllPending(); |
| 558 } |
| 559 } |
| OLD | NEW |