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 <math.h> // ceil | 5 #include <math.h> // ceil |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "net/base/client_socket_factory.h" | 8 #include "net/base/client_socket_factory.h" |
9 #include "net/base/test_completion_callback.h" | 9 #include "net/base/test_completion_callback.h" |
10 #include "net/base/upload_data.h" | 10 #include "net/base/upload_data.h" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 MockRead("HTTP/1.1 204 No Content\r\n\r\n"), | 399 MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
400 MockRead("junk"), // Should not be read!! | 400 MockRead("junk"), // Should not be read!! |
401 MockRead(false, net::OK), | 401 MockRead(false, net::OK), |
402 }; | 402 }; |
403 SimpleGetHelperResult out = SimpleGetHelper(data_reads); | 403 SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
404 EXPECT_EQ(net::OK, out.rv); | 404 EXPECT_EQ(net::OK, out.rv); |
405 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); | 405 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
406 EXPECT_EQ("", out.response_data); | 406 EXPECT_EQ("", out.response_data); |
407 } | 407 } |
408 | 408 |
| 409 // Do a request using the HEAD method. Verify that we don't try to read the |
| 410 // message body (since HEAD has none). |
| 411 TEST_F(HttpNetworkTransactionTest, Head) { |
| 412 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); |
| 413 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( |
| 414 CreateSession(proxy_service.get()), &mock_socket_factory)); |
| 415 |
| 416 net::HttpRequestInfo request; |
| 417 request.method = "HEAD"; |
| 418 request.url = GURL("http://www.google.com/"); |
| 419 request.load_flags = 0; |
| 420 |
| 421 MockWrite data_writes1[] = { |
| 422 MockWrite("HEAD / HTTP/1.1\r\n" |
| 423 "Host: www.google.com\r\n" |
| 424 "Connection: keep-alive\r\n" |
| 425 "Content-Length: 0\r\n\r\n"), |
| 426 }; |
| 427 MockRead data_reads1[] = { |
| 428 MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 429 MockRead("Server: Blah\r\n"), |
| 430 MockRead("Content-Length: 1234\r\n\r\n"), |
| 431 |
| 432 // No response body because the test stops reading here. |
| 433 MockRead(false, net::ERR_UNEXPECTED), // Should not be reached. |
| 434 }; |
| 435 |
| 436 MockSocket data1; |
| 437 data1.reads = data_reads1; |
| 438 data1.writes = data_writes1; |
| 439 mock_sockets[0] = &data1; |
| 440 mock_sockets[1] = NULL; |
| 441 |
| 442 TestCompletionCallback callback1; |
| 443 |
| 444 int rv = trans->Start(&request, &callback1); |
| 445 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 446 |
| 447 rv = callback1.WaitForResult(); |
| 448 EXPECT_EQ(net::OK, rv); |
| 449 |
| 450 const net::HttpResponseInfo* response = trans->GetResponseInfo(); |
| 451 EXPECT_FALSE(response == NULL); |
| 452 |
| 453 // Check that the headers got parsed. |
| 454 EXPECT_TRUE(response->headers != NULL); |
| 455 EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 456 EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
| 457 |
| 458 std::string server_header; |
| 459 void* iter = NULL; |
| 460 bool has_server_header = response->headers->EnumerateHeader( |
| 461 &iter, "Server", &server_header); |
| 462 EXPECT_TRUE(has_server_header); |
| 463 EXPECT_EQ("Blah", server_header); |
| 464 |
| 465 // Reading should give EOF right away, since there is no message body |
| 466 // (despite non-zero content-length). |
| 467 std::string response_data; |
| 468 rv = ReadTransaction(trans.get(), &response_data); |
| 469 EXPECT_EQ(net::OK, rv); |
| 470 EXPECT_EQ("", response_data); |
| 471 } |
| 472 |
409 TEST_F(HttpNetworkTransactionTest, ReuseConnection) { | 473 TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
410 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); | 474 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); |
411 scoped_refptr<net::HttpNetworkSession> session = | 475 scoped_refptr<net::HttpNetworkSession> session = |
412 CreateSession(proxy_service.get()); | 476 CreateSession(proxy_service.get()); |
413 | 477 |
414 MockRead data_reads[] = { | 478 MockRead data_reads[] = { |
415 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | 479 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
416 MockRead("hello"), | 480 MockRead("hello"), |
417 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | 481 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
418 MockRead("world"), | 482 MockRead("world"), |
(...skipping 1777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2196 | 2260 |
2197 rv = callback2.WaitForResult(); | 2261 rv = callback2.WaitForResult(); |
2198 EXPECT_EQ(net::OK, rv); | 2262 EXPECT_EQ(net::OK, rv); |
2199 | 2263 |
2200 response = trans->GetResponseInfo(); | 2264 response = trans->GetResponseInfo(); |
2201 EXPECT_FALSE(response == NULL); | 2265 EXPECT_FALSE(response == NULL); |
2202 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 2266 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
2203 EXPECT_EQ(100, response->headers->GetContentLength()); | 2267 EXPECT_EQ(100, response->headers->GetContentLength()); |
2204 } | 2268 } |
2205 } | 2269 } |
OLD | NEW |