| 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/completion_callback.h" | 9 #include "net/base/completion_callback.h" |
| 10 #include "net/base/socket_test_util.h" | 10 #include "net/base/socket_test_util.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 return ProxyService::CreateNull(); | 29 return ProxyService::CreateNull(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 ProxyService* CreateFixedProxyService(const std::string& proxy) { | 32 ProxyService* CreateFixedProxyService(const std::string& proxy) { |
| 33 net::ProxyConfig proxy_config; | 33 net::ProxyConfig proxy_config; |
| 34 proxy_config.proxy_rules.ParseFromString(proxy); | 34 proxy_config.proxy_rules.ParseFromString(proxy); |
| 35 return ProxyService::CreateFixed(proxy_config); | 35 return ProxyService::CreateFixed(proxy_config); |
| 36 } | 36 } |
| 37 | 37 |
| 38 | 38 |
| 39 HttpNetworkSession* CreateSession(ProxyService* proxy_service) { | 39 HttpNetworkSession* CreateSession(ProxyService* proxy_service, |
| 40 return new HttpNetworkSession(proxy_service); | 40 ClientSocketFactory* client_socket_factory) { |
| 41 return new HttpNetworkSession(proxy_service, client_socket_factory); |
| 41 } | 42 } |
| 42 | 43 |
| 43 class HttpNetworkTransactionTest : public PlatformTest { | 44 class HttpNetworkTransactionTest : public PlatformTest { |
| 44 public: | 45 public: |
| 45 virtual void TearDown() { | 46 virtual void TearDown() { |
| 46 // Empty the current queue. | 47 // Empty the current queue. |
| 47 MessageLoop::current()->RunAllPending(); | 48 MessageLoop::current()->RunAllPending(); |
| 48 PlatformTest::TearDown(); | 49 PlatformTest::TearDown(); |
| 49 } | 50 } |
| 50 | 51 |
| 51 protected: | 52 protected: |
| 52 void KeepAliveConnectionResendRequestTest(const MockRead& read_failure); | 53 void KeepAliveConnectionResendRequestTest(const MockRead& read_failure); |
| 53 | 54 |
| 54 struct SimpleGetHelperResult { | 55 struct SimpleGetHelperResult { |
| 55 int rv; | 56 int rv; |
| 56 std::string status_line; | 57 std::string status_line; |
| 57 std::string response_data; | 58 std::string response_data; |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[]) { | 61 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[]) { |
| 61 SimpleGetHelperResult out; | 62 SimpleGetHelperResult out; |
| 62 | 63 |
| 63 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 64 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 64 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 65 scoped_ptr<HttpTransaction> trans( |
| 65 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 66 new HttpNetworkTransaction( |
| 67 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 68 &mock_socket_factory_)); |
| 66 | 69 |
| 67 HttpRequestInfo request; | 70 HttpRequestInfo request; |
| 68 request.method = "GET"; | 71 request.method = "GET"; |
| 69 request.url = GURL("http://www.google.com/"); | 72 request.url = GURL("http://www.google.com/"); |
| 70 request.load_flags = 0; | 73 request.load_flags = 0; |
| 71 | 74 |
| 72 MockSocket data; | 75 MockSocket data; |
| 73 data.reads = data_reads; | 76 data.reads = data_reads; |
| 74 mock_socket_factory_.AddMockSocket(&data); | 77 mock_socket_factory_.AddMockSocket(&data); |
| 75 | 78 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 } | 146 } |
| 144 | 147 |
| 145 std::string MockGetHostName() { | 148 std::string MockGetHostName() { |
| 146 return "WTC-WIN7"; | 149 return "WTC-WIN7"; |
| 147 } | 150 } |
| 148 | 151 |
| 149 //----------------------------------------------------------------------------- | 152 //----------------------------------------------------------------------------- |
| 150 | 153 |
| 151 TEST_F(HttpNetworkTransactionTest, Basic) { | 154 TEST_F(HttpNetworkTransactionTest, Basic) { |
| 152 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 155 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 153 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 156 scoped_ptr<HttpTransaction> trans( |
| 154 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 157 new HttpNetworkTransaction( |
| 158 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 159 &mock_socket_factory_)); |
| 155 } | 160 } |
| 156 | 161 |
| 157 TEST_F(HttpNetworkTransactionTest, SimpleGET) { | 162 TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
| 158 MockRead data_reads[] = { | 163 MockRead data_reads[] = { |
| 159 MockRead("HTTP/1.0 200 OK\r\n\r\n"), | 164 MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 160 MockRead("hello world"), | 165 MockRead("hello world"), |
| 161 MockRead(false, OK), | 166 MockRead(false, OK), |
| 162 }; | 167 }; |
| 163 SimpleGetHelperResult out = SimpleGetHelper(data_reads); | 168 SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
| 164 EXPECT_EQ(OK, out.rv); | 169 EXPECT_EQ(OK, out.rv); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 SimpleGetHelperResult out = SimpleGetHelper(data_reads); | 259 SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
| 255 EXPECT_EQ(OK, out.rv); | 260 EXPECT_EQ(OK, out.rv); |
| 256 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); | 261 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 257 EXPECT_EQ("", out.response_data); | 262 EXPECT_EQ("", out.response_data); |
| 258 } | 263 } |
| 259 | 264 |
| 260 // Do a request using the HEAD method. Verify that we don't try to read the | 265 // Do a request using the HEAD method. Verify that we don't try to read the |
| 261 // message body (since HEAD has none). | 266 // message body (since HEAD has none). |
| 262 TEST_F(HttpNetworkTransactionTest, Head) { | 267 TEST_F(HttpNetworkTransactionTest, Head) { |
| 263 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 268 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 264 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 269 scoped_ptr<HttpTransaction> trans( |
| 265 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 270 new HttpNetworkTransaction( |
| 271 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 272 &mock_socket_factory_)); |
| 266 | 273 |
| 267 HttpRequestInfo request; | 274 HttpRequestInfo request; |
| 268 request.method = "HEAD"; | 275 request.method = "HEAD"; |
| 269 request.url = GURL("http://www.google.com/"); | 276 request.url = GURL("http://www.google.com/"); |
| 270 request.load_flags = 0; | 277 request.load_flags = 0; |
| 271 | 278 |
| 272 MockWrite data_writes1[] = { | 279 MockWrite data_writes1[] = { |
| 273 MockWrite("HEAD / HTTP/1.1\r\n" | 280 MockWrite("HEAD / HTTP/1.1\r\n" |
| 274 "Host: www.google.com\r\n" | 281 "Host: www.google.com\r\n" |
| 275 "Connection: keep-alive\r\n" | 282 "Connection: keep-alive\r\n" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 // (despite non-zero content-length). | 323 // (despite non-zero content-length). |
| 317 std::string response_data; | 324 std::string response_data; |
| 318 rv = ReadTransaction(trans.get(), &response_data); | 325 rv = ReadTransaction(trans.get(), &response_data); |
| 319 EXPECT_EQ(OK, rv); | 326 EXPECT_EQ(OK, rv); |
| 320 EXPECT_EQ("", response_data); | 327 EXPECT_EQ("", response_data); |
| 321 } | 328 } |
| 322 | 329 |
| 323 TEST_F(HttpNetworkTransactionTest, ReuseConnection) { | 330 TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
| 324 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 331 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 325 scoped_refptr<HttpNetworkSession> session = | 332 scoped_refptr<HttpNetworkSession> session = |
| 326 CreateSession(proxy_service.get()); | 333 CreateSession(proxy_service.get(), &mock_socket_factory_); |
| 327 | 334 |
| 328 MockRead data_reads[] = { | 335 MockRead data_reads[] = { |
| 329 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | 336 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 330 MockRead("hello"), | 337 MockRead("hello"), |
| 331 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | 338 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 332 MockRead("world"), | 339 MockRead("world"), |
| 333 MockRead(false, OK), | 340 MockRead(false, OK), |
| 334 }; | 341 }; |
| 335 MockSocket data; | 342 MockSocket data; |
| 336 data.reads = data_reads; | 343 data.reads = data_reads; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 365 | 372 |
| 366 std::string response_data; | 373 std::string response_data; |
| 367 rv = ReadTransaction(trans.get(), &response_data); | 374 rv = ReadTransaction(trans.get(), &response_data); |
| 368 EXPECT_EQ(OK, rv); | 375 EXPECT_EQ(OK, rv); |
| 369 EXPECT_EQ(kExpectedResponseData[i], response_data); | 376 EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 370 } | 377 } |
| 371 } | 378 } |
| 372 | 379 |
| 373 TEST_F(HttpNetworkTransactionTest, Ignores100) { | 380 TEST_F(HttpNetworkTransactionTest, Ignores100) { |
| 374 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 381 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 375 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 382 scoped_ptr<HttpTransaction> trans( |
| 376 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 383 new HttpNetworkTransaction( |
| 384 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 385 &mock_socket_factory_)); |
| 377 | 386 |
| 378 HttpRequestInfo request; | 387 HttpRequestInfo request; |
| 379 request.method = "POST"; | 388 request.method = "POST"; |
| 380 request.url = GURL("http://www.foo.com/"); | 389 request.url = GURL("http://www.foo.com/"); |
| 381 request.upload_data = new UploadData; | 390 request.upload_data = new UploadData; |
| 382 request.upload_data->AppendBytes("foo", 3); | 391 request.upload_data->AppendBytes("foo", 3); |
| 383 request.load_flags = 0; | 392 request.load_flags = 0; |
| 384 | 393 |
| 385 MockRead data_reads[] = { | 394 MockRead data_reads[] = { |
| 386 MockRead("HTTP/1.0 100 Continue\r\n\r\n"), | 395 MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 410 rv = ReadTransaction(trans.get(), &response_data); | 419 rv = ReadTransaction(trans.get(), &response_data); |
| 411 EXPECT_EQ(OK, rv); | 420 EXPECT_EQ(OK, rv); |
| 412 EXPECT_EQ("hello world", response_data); | 421 EXPECT_EQ("hello world", response_data); |
| 413 } | 422 } |
| 414 | 423 |
| 415 // This test is almost the same as Ignores100 above, but the response contains | 424 // This test is almost the same as Ignores100 above, but the response contains |
| 416 // a 102 instead of a 100. Also, instead of HTTP/1.0 the response is | 425 // a 102 instead of a 100. Also, instead of HTTP/1.0 the response is |
| 417 // HTTP/1.1. | 426 // HTTP/1.1. |
| 418 TEST_F(HttpNetworkTransactionTest, Ignores1xx) { | 427 TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
| 419 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 428 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 420 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 429 scoped_ptr<HttpTransaction> trans( |
| 421 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 430 new HttpNetworkTransaction( |
| 431 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 432 &mock_socket_factory_)); |
| 422 | 433 |
| 423 HttpRequestInfo request; | 434 HttpRequestInfo request; |
| 424 request.method = "GET"; | 435 request.method = "GET"; |
| 425 request.url = GURL("http://www.foo.com/"); | 436 request.url = GURL("http://www.foo.com/"); |
| 426 request.load_flags = 0; | 437 request.load_flags = 0; |
| 427 | 438 |
| 428 MockRead data_reads[] = { | 439 MockRead data_reads[] = { |
| 429 MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n"), | 440 MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n"), |
| 430 MockRead("HTTP/1.1 200 OK\r\n\r\n"), | 441 MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 431 MockRead("hello world"), | 442 MockRead("hello world"), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 454 EXPECT_EQ(OK, rv); | 465 EXPECT_EQ(OK, rv); |
| 455 EXPECT_EQ("hello world", response_data); | 466 EXPECT_EQ("hello world", response_data); |
| 456 } | 467 } |
| 457 | 468 |
| 458 // read_failure specifies a read failure that should cause the network | 469 // read_failure specifies a read failure that should cause the network |
| 459 // transaction to resend the request. | 470 // transaction to resend the request. |
| 460 void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( | 471 void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
| 461 const MockRead& read_failure) { | 472 const MockRead& read_failure) { |
| 462 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 473 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 463 scoped_refptr<HttpNetworkSession> session = | 474 scoped_refptr<HttpNetworkSession> session = |
| 464 CreateSession(proxy_service.get()); | 475 CreateSession(proxy_service.get(), &mock_socket_factory_); |
| 465 | 476 |
| 466 HttpRequestInfo request; | 477 HttpRequestInfo request; |
| 467 request.method = "GET"; | 478 request.method = "GET"; |
| 468 request.url = GURL("http://www.foo.com/"); | 479 request.url = GURL("http://www.foo.com/"); |
| 469 request.load_flags = 0; | 480 request.load_flags = 0; |
| 470 | 481 |
| 471 MockRead data1_reads[] = { | 482 MockRead data1_reads[] = { |
| 472 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | 483 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 473 MockRead("hello"), | 484 MockRead("hello"), |
| 474 read_failure, // Now, we reuse the connection and fail the first read. | 485 read_failure, // Now, we reuse the connection and fail the first read. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 KeepAliveConnectionResendRequestTest(read_failure); | 531 KeepAliveConnectionResendRequestTest(read_failure); |
| 521 } | 532 } |
| 522 | 533 |
| 523 TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { | 534 TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
| 524 MockRead read_failure(false, OK); // EOF | 535 MockRead read_failure(false, OK); // EOF |
| 525 KeepAliveConnectionResendRequestTest(read_failure); | 536 KeepAliveConnectionResendRequestTest(read_failure); |
| 526 } | 537 } |
| 527 | 538 |
| 528 TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { | 539 TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
| 529 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 540 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 530 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 541 scoped_ptr<HttpTransaction> trans( |
| 531 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 542 new HttpNetworkTransaction( |
| 543 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 544 &mock_socket_factory_)); |
| 532 | 545 |
| 533 HttpRequestInfo request; | 546 HttpRequestInfo request; |
| 534 request.method = "GET"; | 547 request.method = "GET"; |
| 535 request.url = GURL("http://www.google.com/"); | 548 request.url = GURL("http://www.google.com/"); |
| 536 request.load_flags = 0; | 549 request.load_flags = 0; |
| 537 | 550 |
| 538 MockRead data_reads[] = { | 551 MockRead data_reads[] = { |
| 539 MockRead(true, ERR_CONNECTION_RESET), | 552 MockRead(true, ERR_CONNECTION_RESET), |
| 540 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used | 553 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 541 MockRead("hello world"), | 554 MockRead("hello world"), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 MockRead(false, OK), | 587 MockRead(false, OK), |
| 575 }; | 588 }; |
| 576 SimpleGetHelperResult out = SimpleGetHelper(data_reads); | 589 SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
| 577 EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); | 590 EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
| 578 } | 591 } |
| 579 | 592 |
| 580 // Test the request-challenge-retry sequence for basic auth. | 593 // Test the request-challenge-retry sequence for basic auth. |
| 581 // (basic auth is the easiest to mock, because it has no randomness). | 594 // (basic auth is the easiest to mock, because it has no randomness). |
| 582 TEST_F(HttpNetworkTransactionTest, BasicAuth) { | 595 TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
| 583 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 596 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 584 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 597 scoped_ptr<HttpTransaction> trans( |
| 585 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 598 new HttpNetworkTransaction( |
| 599 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 600 &mock_socket_factory_)); |
| 586 | 601 |
| 587 HttpRequestInfo request; | 602 HttpRequestInfo request; |
| 588 request.method = "GET"; | 603 request.method = "GET"; |
| 589 request.url = GURL("http://www.google.com/"); | 604 request.url = GURL("http://www.google.com/"); |
| 590 request.load_flags = 0; | 605 request.load_flags = 0; |
| 591 | 606 |
| 592 MockWrite data_writes1[] = { | 607 MockWrite data_writes1[] = { |
| 593 MockWrite("GET / HTTP/1.1\r\n" | 608 MockWrite("GET / HTTP/1.1\r\n" |
| 594 "Host: www.google.com\r\n" | 609 "Host: www.google.com\r\n" |
| 595 "Connection: keep-alive\r\n\r\n"), | 610 "Connection: keep-alive\r\n\r\n"), |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 response = trans->GetResponseInfo(); | 678 response = trans->GetResponseInfo(); |
| 664 EXPECT_FALSE(response == NULL); | 679 EXPECT_FALSE(response == NULL); |
| 665 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 680 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 666 EXPECT_EQ(100, response->headers->GetContentLength()); | 681 EXPECT_EQ(100, response->headers->GetContentLength()); |
| 667 } | 682 } |
| 668 | 683 |
| 669 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | 684 // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 670 // connection. | 685 // connection. |
| 671 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { | 686 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
| 672 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 687 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 673 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 688 scoped_ptr<HttpTransaction> trans( |
| 674 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 689 new HttpNetworkTransaction( |
| 690 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 691 &mock_socket_factory_)); |
| 675 | 692 |
| 676 HttpRequestInfo request; | 693 HttpRequestInfo request; |
| 677 request.method = "GET"; | 694 request.method = "GET"; |
| 678 request.url = GURL("http://www.google.com/"); | 695 request.url = GURL("http://www.google.com/"); |
| 679 request.load_flags = 0; | 696 request.load_flags = 0; |
| 680 | 697 |
| 681 MockWrite data_writes1[] = { | 698 MockWrite data_writes1[] = { |
| 682 MockWrite("GET / HTTP/1.1\r\n" | 699 MockWrite("GET / HTTP/1.1\r\n" |
| 683 "Host: www.google.com\r\n" | 700 "Host: www.google.com\r\n" |
| 684 "Connection: keep-alive\r\n\r\n"), | 701 "Connection: keep-alive\r\n\r\n"), |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 response = trans->GetResponseInfo(); | 756 response = trans->GetResponseInfo(); |
| 740 EXPECT_FALSE(response == NULL); | 757 EXPECT_FALSE(response == NULL); |
| 741 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 758 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 742 EXPECT_EQ(100, response->headers->GetContentLength()); | 759 EXPECT_EQ(100, response->headers->GetContentLength()); |
| 743 } | 760 } |
| 744 | 761 |
| 745 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | 762 // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 746 // connection and with no response body to drain. | 763 // connection and with no response body to drain. |
| 747 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { | 764 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
| 748 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 765 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 749 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 766 scoped_ptr<HttpTransaction> trans( |
| 750 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 767 new HttpNetworkTransaction( |
| 768 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 769 &mock_socket_factory_)); |
| 751 | 770 |
| 752 HttpRequestInfo request; | 771 HttpRequestInfo request; |
| 753 request.method = "GET"; | 772 request.method = "GET"; |
| 754 request.url = GURL("http://www.google.com/"); | 773 request.url = GURL("http://www.google.com/"); |
| 755 request.load_flags = 0; | 774 request.load_flags = 0; |
| 756 | 775 |
| 757 MockWrite data_writes1[] = { | 776 MockWrite data_writes1[] = { |
| 758 MockWrite("GET / HTTP/1.1\r\n" | 777 MockWrite("GET / HTTP/1.1\r\n" |
| 759 "Host: www.google.com\r\n" | 778 "Host: www.google.com\r\n" |
| 760 "Connection: keep-alive\r\n\r\n"), | 779 "Connection: keep-alive\r\n\r\n"), |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 response = trans->GetResponseInfo(); | 837 response = trans->GetResponseInfo(); |
| 819 EXPECT_FALSE(response == NULL); | 838 EXPECT_FALSE(response == NULL); |
| 820 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 839 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 821 EXPECT_EQ(100, response->headers->GetContentLength()); | 840 EXPECT_EQ(100, response->headers->GetContentLength()); |
| 822 } | 841 } |
| 823 | 842 |
| 824 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | 843 // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 825 // connection and with a large response body to drain. | 844 // connection and with a large response body to drain. |
| 826 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { | 845 TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
| 827 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 846 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 828 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 847 scoped_ptr<HttpTransaction> trans( |
| 829 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 848 new HttpNetworkTransaction( |
| 849 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 850 &mock_socket_factory_)); |
| 830 | 851 |
| 831 HttpRequestInfo request; | 852 HttpRequestInfo request; |
| 832 request.method = "GET"; | 853 request.method = "GET"; |
| 833 request.url = GURL("http://www.google.com/"); | 854 request.url = GURL("http://www.google.com/"); |
| 834 request.load_flags = 0; | 855 request.load_flags = 0; |
| 835 | 856 |
| 836 MockWrite data_writes1[] = { | 857 MockWrite data_writes1[] = { |
| 837 MockWrite("GET / HTTP/1.1\r\n" | 858 MockWrite("GET / HTTP/1.1\r\n" |
| 838 "Host: www.google.com\r\n" | 859 "Host: www.google.com\r\n" |
| 839 "Connection: keep-alive\r\n\r\n"), | 860 "Connection: keep-alive\r\n\r\n"), |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 } | 925 } |
| 905 | 926 |
| 906 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | 927 // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 907 // proxy connection, when setting up an SSL tunnel. | 928 // proxy connection, when setting up an SSL tunnel. |
| 908 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) { | 929 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) { |
| 909 // Configure against proxy server "myproxy:70". | 930 // Configure against proxy server "myproxy:70". |
| 910 scoped_ptr<ProxyService> proxy_service( | 931 scoped_ptr<ProxyService> proxy_service( |
| 911 CreateFixedProxyService("myproxy:70")); | 932 CreateFixedProxyService("myproxy:70")); |
| 912 | 933 |
| 913 scoped_refptr<HttpNetworkSession> session( | 934 scoped_refptr<HttpNetworkSession> session( |
| 914 CreateSession(proxy_service.get())); | 935 CreateSession(proxy_service.get(), &mock_socket_factory_)); |
| 915 | 936 |
| 916 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 937 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
| 917 session.get(), &mock_socket_factory_)); | 938 session.get(), &mock_socket_factory_)); |
| 918 | 939 |
| 919 HttpRequestInfo request; | 940 HttpRequestInfo request; |
| 920 request.method = "GET"; | 941 request.method = "GET"; |
| 921 request.url = GURL("https://www.google.com/"); | 942 request.url = GURL("https://www.google.com/"); |
| 922 request.load_flags = 0; | 943 request.load_flags = 0; |
| 923 | 944 |
| 924 // Since we have proxy, should try to establish tunnel. | 945 // Since we have proxy, should try to establish tunnel. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 } | 1025 } |
| 1005 | 1026 |
| 1006 // Test that we don't read the response body when we fail to establish a tunnel, | 1027 // Test that we don't read the response body when we fail to establish a tunnel, |
| 1007 // even if the user cancels the proxy's auth attempt. | 1028 // even if the user cancels the proxy's auth attempt. |
| 1008 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { | 1029 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
| 1009 // Configure against proxy server "myproxy:70". | 1030 // Configure against proxy server "myproxy:70". |
| 1010 scoped_ptr<ProxyService> proxy_service( | 1031 scoped_ptr<ProxyService> proxy_service( |
| 1011 CreateFixedProxyService("myproxy:70")); | 1032 CreateFixedProxyService("myproxy:70")); |
| 1012 | 1033 |
| 1013 scoped_refptr<HttpNetworkSession> session( | 1034 scoped_refptr<HttpNetworkSession> session( |
| 1014 CreateSession(proxy_service.get())); | 1035 CreateSession(proxy_service.get(), &mock_socket_factory_)); |
| 1015 | 1036 |
| 1016 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 1037 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
| 1017 session.get(), &mock_socket_factory_)); | 1038 session.get(), &mock_socket_factory_)); |
| 1018 | 1039 |
| 1019 HttpRequestInfo request; | 1040 HttpRequestInfo request; |
| 1020 request.method = "GET"; | 1041 request.method = "GET"; |
| 1021 request.url = GURL("https://www.google.com/"); | 1042 request.url = GURL("https://www.google.com/"); |
| 1022 request.load_flags = 0; | 1043 request.load_flags = 0; |
| 1023 | 1044 |
| 1024 // Since we have proxy, should try to establish tunnel. | 1045 // Since we have proxy, should try to establish tunnel. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); | 1082 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 1062 } | 1083 } |
| 1063 | 1084 |
| 1064 void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( | 1085 void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
| 1065 const MockRead& status, int expected_status) { | 1086 const MockRead& status, int expected_status) { |
| 1066 // Configure against proxy server "myproxy:70". | 1087 // Configure against proxy server "myproxy:70". |
| 1067 scoped_ptr<ProxyService> proxy_service( | 1088 scoped_ptr<ProxyService> proxy_service( |
| 1068 CreateFixedProxyService("myproxy:70")); | 1089 CreateFixedProxyService("myproxy:70")); |
| 1069 | 1090 |
| 1070 scoped_refptr<HttpNetworkSession> session( | 1091 scoped_refptr<HttpNetworkSession> session( |
| 1071 CreateSession(proxy_service.get())); | 1092 CreateSession(proxy_service.get(), &mock_socket_factory_)); |
| 1072 | 1093 |
| 1073 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 1094 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
| 1074 session.get(), &mock_socket_factory_)); | 1095 session.get(), &mock_socket_factory_)); |
| 1075 | 1096 |
| 1076 HttpRequestInfo request; | 1097 HttpRequestInfo request; |
| 1077 request.method = "GET"; | 1098 request.method = "GET"; |
| 1078 request.url = GURL("https://www.google.com/"); | 1099 request.url = GURL("https://www.google.com/"); |
| 1079 request.load_flags = 0; | 1100 request.load_flags = 0; |
| 1080 | 1101 |
| 1081 // Since we have proxy, should try to establish tunnel. | 1102 // Since we have proxy, should try to establish tunnel. |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1276 | 1297 |
| 1277 // Test the flow when both the proxy server AND origin server require | 1298 // Test the flow when both the proxy server AND origin server require |
| 1278 // authentication. Again, this uses basic auth for both since that is | 1299 // authentication. Again, this uses basic auth for both since that is |
| 1279 // the simplest to mock. | 1300 // the simplest to mock. |
| 1280 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { | 1301 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
| 1281 scoped_ptr<ProxyService> proxy_service( | 1302 scoped_ptr<ProxyService> proxy_service( |
| 1282 CreateFixedProxyService("myproxy:70")); | 1303 CreateFixedProxyService("myproxy:70")); |
| 1283 | 1304 |
| 1284 // Configure against proxy server "myproxy:70". | 1305 // Configure against proxy server "myproxy:70". |
| 1285 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 1306 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
| 1286 CreateSession(proxy_service.get()), | 1307 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 1287 &mock_socket_factory_)); | 1308 &mock_socket_factory_)); |
| 1288 | 1309 |
| 1289 HttpRequestInfo request; | 1310 HttpRequestInfo request; |
| 1290 request.method = "GET"; | 1311 request.method = "GET"; |
| 1291 request.url = GURL("http://www.google.com/"); | 1312 request.url = GURL("http://www.google.com/"); |
| 1292 request.load_flags = 0; | 1313 request.load_flags = 0; |
| 1293 | 1314 |
| 1294 MockWrite data_writes1[] = { | 1315 MockWrite data_writes1[] = { |
| 1295 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" | 1316 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" |
| 1296 "Host: www.google.com\r\n" | 1317 "Host: www.google.com\r\n" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 // The NTLM authentication unit tests were generated by capturing the HTTP | 1434 // The NTLM authentication unit tests were generated by capturing the HTTP |
| 1414 // requests and responses using Fiddler 2 and inspecting the generated random | 1435 // requests and responses using Fiddler 2 and inspecting the generated random |
| 1415 // bytes in the debugger. | 1436 // bytes in the debugger. |
| 1416 | 1437 |
| 1417 // Enter the correct password and authenticate successfully. | 1438 // Enter the correct password and authenticate successfully. |
| 1418 TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { | 1439 TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
| 1419 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, | 1440 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 1420 MockGetHostName); | 1441 MockGetHostName); |
| 1421 | 1442 |
| 1422 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 1443 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 1423 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 1444 scoped_ptr<HttpTransaction> trans( |
| 1424 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 1445 new HttpNetworkTransaction( |
| 1446 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 1447 &mock_socket_factory_)); |
| 1425 | 1448 |
| 1426 HttpRequestInfo request; | 1449 HttpRequestInfo request; |
| 1427 request.method = "GET"; | 1450 request.method = "GET"; |
| 1428 request.url = GURL("http://172.22.68.17/kids/login.aspx"); | 1451 request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 1429 request.load_flags = 0; | 1452 request.load_flags = 0; |
| 1430 | 1453 |
| 1431 MockWrite data_writes1[] = { | 1454 MockWrite data_writes1[] = { |
| 1432 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" | 1455 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 1433 "Host: 172.22.68.17\r\n" | 1456 "Host: 172.22.68.17\r\n" |
| 1434 "Connection: keep-alive\r\n\r\n"), | 1457 "Connection: keep-alive\r\n\r\n"), |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1539 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 1562 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1540 EXPECT_EQ(13, response->headers->GetContentLength()); | 1563 EXPECT_EQ(13, response->headers->GetContentLength()); |
| 1541 } | 1564 } |
| 1542 | 1565 |
| 1543 // Enter a wrong password, and then the correct one. | 1566 // Enter a wrong password, and then the correct one. |
| 1544 TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { | 1567 TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
| 1545 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, | 1568 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 1546 MockGetHostName); | 1569 MockGetHostName); |
| 1547 | 1570 |
| 1548 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 1571 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 1549 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 1572 scoped_ptr<HttpTransaction> trans( |
| 1550 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 1573 new HttpNetworkTransaction( |
| 1574 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 1575 &mock_socket_factory_)); |
| 1551 | 1576 |
| 1552 HttpRequestInfo request; | 1577 HttpRequestInfo request; |
| 1553 request.method = "GET"; | 1578 request.method = "GET"; |
| 1554 request.url = GURL("http://172.22.68.17/kids/login.aspx"); | 1579 request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 1555 request.load_flags = 0; | 1580 request.load_flags = 0; |
| 1556 | 1581 |
| 1557 MockWrite data_writes1[] = { | 1582 MockWrite data_writes1[] = { |
| 1558 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" | 1583 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 1559 "Host: 172.22.68.17\r\n" | 1584 "Host: 172.22.68.17\r\n" |
| 1560 "Connection: keep-alive\r\n\r\n"), | 1585 "Connection: keep-alive\r\n\r\n"), |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1745 response = trans->GetResponseInfo(); | 1770 response = trans->GetResponseInfo(); |
| 1746 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 1771 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1747 EXPECT_EQ(13, response->headers->GetContentLength()); | 1772 EXPECT_EQ(13, response->headers->GetContentLength()); |
| 1748 } | 1773 } |
| 1749 | 1774 |
| 1750 // Test reading a server response which has only headers, and no body. | 1775 // Test reading a server response which has only headers, and no body. |
| 1751 // After some maximum number of bytes is consumed, the transaction should | 1776 // After some maximum number of bytes is consumed, the transaction should |
| 1752 // fail with ERR_RESPONSE_HEADERS_TOO_BIG. | 1777 // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
| 1753 TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { | 1778 TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
| 1754 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 1779 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 1755 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 1780 scoped_ptr<HttpTransaction> trans( |
| 1756 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 1781 new HttpNetworkTransaction( |
| 1782 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 1783 &mock_socket_factory_)); |
| 1757 | 1784 |
| 1758 HttpRequestInfo request; | 1785 HttpRequestInfo request; |
| 1759 request.method = "GET"; | 1786 request.method = "GET"; |
| 1760 request.url = GURL("http://www.google.com/"); | 1787 request.url = GURL("http://www.google.com/"); |
| 1761 request.load_flags = 0; | 1788 request.load_flags = 0; |
| 1762 | 1789 |
| 1763 // Respond with 50 kb of headers (we should fail after 32 kb). | 1790 // Respond with 50 kb of headers (we should fail after 32 kb). |
| 1764 std::string large_headers_string; | 1791 std::string large_headers_string; |
| 1765 FillLargeHeadersString(&large_headers_string, 50 * 1024); | 1792 FillLargeHeadersString(&large_headers_string, 50 * 1024); |
| 1766 | 1793 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1788 | 1815 |
| 1789 // Make sure that we don't try to reuse a TCPClientSocket when failing to | 1816 // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 1790 // establish tunnel. | 1817 // establish tunnel. |
| 1791 // http://code.google.com/p/chromium/issues/detail?id=3772 | 1818 // http://code.google.com/p/chromium/issues/detail?id=3772 |
| 1792 TEST_F(HttpNetworkTransactionTest, DontRecycleTCPSocketForSSLTunnel) { | 1819 TEST_F(HttpNetworkTransactionTest, DontRecycleTCPSocketForSSLTunnel) { |
| 1793 // Configure against proxy server "myproxy:70". | 1820 // Configure against proxy server "myproxy:70". |
| 1794 scoped_ptr<ProxyService> proxy_service( | 1821 scoped_ptr<ProxyService> proxy_service( |
| 1795 CreateFixedProxyService("myproxy:70")); | 1822 CreateFixedProxyService("myproxy:70")); |
| 1796 | 1823 |
| 1797 scoped_refptr<HttpNetworkSession> session( | 1824 scoped_refptr<HttpNetworkSession> session( |
| 1798 CreateSession(proxy_service.get())); | 1825 CreateSession(proxy_service.get(), &mock_socket_factory_)); |
| 1799 | 1826 |
| 1800 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 1827 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
| 1801 session.get(), &mock_socket_factory_)); | 1828 session.get(), &mock_socket_factory_)); |
| 1802 | 1829 |
| 1803 HttpRequestInfo request; | 1830 HttpRequestInfo request; |
| 1804 request.method = "GET"; | 1831 request.method = "GET"; |
| 1805 request.url = GURL("https://www.google.com/"); | 1832 request.url = GURL("https://www.google.com/"); |
| 1806 request.load_flags = 0; | 1833 request.load_flags = 0; |
| 1807 | 1834 |
| 1808 // Since we have proxy, should try to establish tunnel. | 1835 // Since we have proxy, should try to establish tunnel. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1846 trans.reset(); | 1873 trans.reset(); |
| 1847 MessageLoop::current()->RunAllPending(); | 1874 MessageLoop::current()->RunAllPending(); |
| 1848 // Make sure that the socket didn't get recycled after calling the destructor. | 1875 // Make sure that the socket didn't get recycled after calling the destructor. |
| 1849 EXPECT_EQ(0, session->connection_pool()->idle_socket_count()); | 1876 EXPECT_EQ(0, session->connection_pool()->idle_socket_count()); |
| 1850 } | 1877 } |
| 1851 | 1878 |
| 1852 // Make sure that we recycle a socket after reading all of the response body. | 1879 // Make sure that we recycle a socket after reading all of the response body. |
| 1853 TEST_F(HttpNetworkTransactionTest, RecycleSocket) { | 1880 TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
| 1854 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 1881 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 1855 scoped_refptr<HttpNetworkSession> session( | 1882 scoped_refptr<HttpNetworkSession> session( |
| 1856 CreateSession(proxy_service.get())); | 1883 CreateSession(proxy_service.get(), &mock_socket_factory_)); |
| 1857 | 1884 |
| 1858 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 1885 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
| 1859 session.get(), &mock_socket_factory_)); | 1886 session.get(), &mock_socket_factory_)); |
| 1860 | 1887 |
| 1861 HttpRequestInfo request; | 1888 HttpRequestInfo request; |
| 1862 request.method = "GET"; | 1889 request.method = "GET"; |
| 1863 request.url = GURL("http://www.google.com/"); | 1890 request.url = GURL("http://www.google.com/"); |
| 1864 request.load_flags = 0; | 1891 request.load_flags = 0; |
| 1865 | 1892 |
| 1866 MockRead data_reads[] = { | 1893 MockRead data_reads[] = { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1905 | 1932 |
| 1906 // We now check to make sure the socket was added back to the pool. | 1933 // We now check to make sure the socket was added back to the pool. |
| 1907 EXPECT_EQ(1, session->connection_pool()->idle_socket_count()); | 1934 EXPECT_EQ(1, session->connection_pool()->idle_socket_count()); |
| 1908 } | 1935 } |
| 1909 | 1936 |
| 1910 // Make sure that we recycle a socket after a zero-length response. | 1937 // Make sure that we recycle a socket after a zero-length response. |
| 1911 // http://crbug.com/9880 | 1938 // http://crbug.com/9880 |
| 1912 TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { | 1939 TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
| 1913 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 1940 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 1914 scoped_refptr<HttpNetworkSession> session( | 1941 scoped_refptr<HttpNetworkSession> session( |
| 1915 CreateSession(proxy_service.get())); | 1942 CreateSession(proxy_service.get(), &mock_socket_factory_)); |
| 1916 | 1943 |
| 1917 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 1944 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
| 1918 session.get(), &mock_socket_factory_)); | 1945 session.get(), &mock_socket_factory_)); |
| 1919 | 1946 |
| 1920 HttpRequestInfo request; | 1947 HttpRequestInfo request; |
| 1921 request.method = "GET"; | 1948 request.method = "GET"; |
| 1922 request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&" | 1949 request.url = GURL("http://www.google.com/csi?v=3&s=web&action=&" |
| 1923 "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" | 1950 "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 1924 "e=17259,18167,19592,19773,19981,20133,20173,20233&" | 1951 "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 1925 "rt=prt.2642,ol.2649,xjs.2951"); | 1952 "rt=prt.2642,ol.2649,xjs.2951"); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1979 // This causes the transaction to retry with a new socket. The second | 2006 // This causes the transaction to retry with a new socket. The second |
| 1980 // attempt succeeds. | 2007 // attempt succeeds. |
| 1981 request[1].method = "POST"; | 2008 request[1].method = "POST"; |
| 1982 request[1].url = GURL("http://www.google.com/login.cgi"); | 2009 request[1].url = GURL("http://www.google.com/login.cgi"); |
| 1983 request[1].upload_data = new UploadData; | 2010 request[1].upload_data = new UploadData; |
| 1984 request[1].upload_data->AppendBytes("foo", 3); | 2011 request[1].upload_data->AppendBytes("foo", 3); |
| 1985 request[1].load_flags = 0; | 2012 request[1].load_flags = 0; |
| 1986 | 2013 |
| 1987 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2014 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 1988 scoped_refptr<HttpNetworkSession> session = | 2015 scoped_refptr<HttpNetworkSession> session = |
| 1989 CreateSession(proxy_service.get()); | 2016 CreateSession(proxy_service.get(), &mock_socket_factory_); |
| 1990 | 2017 |
| 1991 // The first socket is used for transaction 1 and the first attempt of | 2018 // The first socket is used for transaction 1 and the first attempt of |
| 1992 // transaction 2. | 2019 // transaction 2. |
| 1993 | 2020 |
| 1994 // The response of transaction 1. | 2021 // The response of transaction 1. |
| 1995 MockRead data_reads1[] = { | 2022 MockRead data_reads1[] = { |
| 1996 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), | 2023 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 1997 MockRead("hello world"), | 2024 MockRead("hello world"), |
| 1998 MockRead(false, OK), | 2025 MockRead(false, OK), |
| 1999 }; | 2026 }; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2055 EXPECT_EQ(OK, rv); | 2082 EXPECT_EQ(OK, rv); |
| 2056 EXPECT_EQ(kExpectedResponseData[i], response_data); | 2083 EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 2057 } | 2084 } |
| 2058 } | 2085 } |
| 2059 | 2086 |
| 2060 // Test the request-challenge-retry sequence for basic auth when there is | 2087 // Test the request-challenge-retry sequence for basic auth when there is |
| 2061 // an identity in the URL. The request should be sent as normal, but when | 2088 // an identity in the URL. The request should be sent as normal, but when |
| 2062 // it fails the identity from the URL is used to answer the challenge. | 2089 // it fails the identity from the URL is used to answer the challenge. |
| 2063 TEST_F(HttpNetworkTransactionTest, AuthIdentityInUrl) { | 2090 TEST_F(HttpNetworkTransactionTest, AuthIdentityInUrl) { |
| 2064 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2091 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 2065 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 2092 scoped_ptr<HttpTransaction> trans( |
| 2066 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 2093 new HttpNetworkTransaction( |
| 2094 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 2095 &mock_socket_factory_)); |
| 2067 | 2096 |
| 2068 HttpRequestInfo request; | 2097 HttpRequestInfo request; |
| 2069 request.method = "GET"; | 2098 request.method = "GET"; |
| 2070 // Note: the URL has a username:password in it. | 2099 // Note: the URL has a username:password in it. |
| 2071 request.url = GURL("http://foo:bar@www.google.com/"); | 2100 request.url = GURL("http://foo:bar@www.google.com/"); |
| 2072 request.load_flags = 0; | 2101 request.load_flags = 0; |
| 2073 | 2102 |
| 2074 MockWrite data_writes1[] = { | 2103 MockWrite data_writes1[] = { |
| 2075 MockWrite("GET / HTTP/1.1\r\n" | 2104 MockWrite("GET / HTTP/1.1\r\n" |
| 2076 "Host: www.google.com\r\n" | 2105 "Host: www.google.com\r\n" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2133 EXPECT_EQ(100, response->headers->GetContentLength()); | 2162 EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2134 | 2163 |
| 2135 // Empty the current queue. | 2164 // Empty the current queue. |
| 2136 MessageLoop::current()->RunAllPending(); | 2165 MessageLoop::current()->RunAllPending(); |
| 2137 } | 2166 } |
| 2138 | 2167 |
| 2139 // Test that previously tried username/passwords for a realm get re-used. | 2168 // Test that previously tried username/passwords for a realm get re-used. |
| 2140 TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { | 2169 TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
| 2141 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2170 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 2142 scoped_refptr<HttpNetworkSession> session = | 2171 scoped_refptr<HttpNetworkSession> session = |
| 2143 CreateSession(proxy_service.get()); | 2172 CreateSession(proxy_service.get(), &mock_socket_factory_); |
| 2144 | 2173 |
| 2145 // Transaction 1: authenticate (foo, bar) on MyRealm1 | 2174 // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 2146 { | 2175 { |
| 2147 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 2176 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( |
| 2148 session, &mock_socket_factory_)); | 2177 session, &mock_socket_factory_)); |
| 2149 | 2178 |
| 2150 HttpRequestInfo request; | 2179 HttpRequestInfo request; |
| 2151 request.method = "GET"; | 2180 request.method = "GET"; |
| 2152 request.url = GURL("http://www.google.com/x/y/z"); | 2181 request.url = GURL("http://www.google.com/x/y/z"); |
| 2153 request.load_flags = 0; | 2182 request.load_flags = 0; |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2542 EXPECT_FALSE(response == NULL); | 2571 EXPECT_FALSE(response == NULL); |
| 2543 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 2572 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2544 EXPECT_EQ(100, response->headers->GetContentLength()); | 2573 EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2545 } | 2574 } |
| 2546 } | 2575 } |
| 2547 | 2576 |
| 2548 // Test the ResetStateForRestart() private method. | 2577 // Test the ResetStateForRestart() private method. |
| 2549 TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { | 2578 TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
| 2550 // Create a transaction (the dependencies aren't important). | 2579 // Create a transaction (the dependencies aren't important). |
| 2551 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2580 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 2552 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction( | 2581 scoped_ptr<HttpNetworkTransaction> trans( |
| 2553 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 2582 new HttpNetworkTransaction( |
| 2583 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 2584 &mock_socket_factory_)); |
| 2554 | 2585 |
| 2555 // Setup some state (which we expect ResetStateForRestart() will clear). | 2586 // Setup some state (which we expect ResetStateForRestart() will clear). |
| 2556 trans->header_buf_->Realloc(10); | 2587 trans->header_buf_->Realloc(10); |
| 2557 trans->header_buf_capacity_ = 10; | 2588 trans->header_buf_capacity_ = 10; |
| 2558 trans->header_buf_len_ = 3; | 2589 trans->header_buf_len_ = 3; |
| 2559 trans->header_buf_body_offset_ = 11; | 2590 trans->header_buf_body_offset_ = 11; |
| 2560 trans->header_buf_http_offset_ = 0; | 2591 trans->header_buf_http_offset_ = 0; |
| 2561 trans->response_body_length_ = 100; | 2592 trans->response_body_length_ = 100; |
| 2562 trans->response_body_read_ = 1; | 2593 trans->response_body_read_ = 1; |
| 2563 trans->read_buf_ = new IOBuffer(15); | 2594 trans->read_buf_ = new IOBuffer(15); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2598 EXPECT_EQ(NULL, trans->response_.auth_challenge.get()); | 2629 EXPECT_EQ(NULL, trans->response_.auth_challenge.get()); |
| 2599 EXPECT_EQ(NULL, trans->response_.headers.get()); | 2630 EXPECT_EQ(NULL, trans->response_.headers.get()); |
| 2600 EXPECT_EQ(false, trans->response_.was_cached); | 2631 EXPECT_EQ(false, trans->response_.was_cached); |
| 2601 EXPECT_EQ(0, trans->response_.ssl_info.cert_status); | 2632 EXPECT_EQ(0, trans->response_.ssl_info.cert_status); |
| 2602 EXPECT_FALSE(trans->response_.vary_data.is_valid()); | 2633 EXPECT_FALSE(trans->response_.vary_data.is_valid()); |
| 2603 } | 2634 } |
| 2604 | 2635 |
| 2605 // Test HTTPS connections to a site with a bad certificate | 2636 // Test HTTPS connections to a site with a bad certificate |
| 2606 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { | 2637 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
| 2607 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2638 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 2608 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 2639 scoped_ptr<HttpTransaction> trans( |
| 2609 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 2640 new HttpNetworkTransaction( |
| 2641 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 2642 &mock_socket_factory_)); |
| 2610 | 2643 |
| 2611 HttpRequestInfo request; | 2644 HttpRequestInfo request; |
| 2612 request.method = "GET"; | 2645 request.method = "GET"; |
| 2613 request.url = GURL("https://www.google.com/"); | 2646 request.url = GURL("https://www.google.com/"); |
| 2614 request.load_flags = 0; | 2647 request.load_flags = 0; |
| 2615 | 2648 |
| 2616 MockWrite data_writes[] = { | 2649 MockWrite data_writes[] = { |
| 2617 MockWrite("GET / HTTP/1.1\r\n" | 2650 MockWrite("GET / HTTP/1.1\r\n" |
| 2618 "Host: www.google.com\r\n" | 2651 "Host: www.google.com\r\n" |
| 2619 "Connection: keep-alive\r\n\r\n"), | 2652 "Connection: keep-alive\r\n\r\n"), |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2701 mock_socket_factory_.AddMockSocket(&ssl_bad_certificate); | 2734 mock_socket_factory_.AddMockSocket(&ssl_bad_certificate); |
| 2702 mock_socket_factory_.AddMockSocket(&data); | 2735 mock_socket_factory_.AddMockSocket(&data); |
| 2703 mock_socket_factory_.AddMockSSLSocket(&ssl_bad); | 2736 mock_socket_factory_.AddMockSSLSocket(&ssl_bad); |
| 2704 mock_socket_factory_.AddMockSSLSocket(&ssl); | 2737 mock_socket_factory_.AddMockSSLSocket(&ssl); |
| 2705 | 2738 |
| 2706 TestCompletionCallback callback; | 2739 TestCompletionCallback callback; |
| 2707 | 2740 |
| 2708 for (int i = 0; i < 2; i++) { | 2741 for (int i = 0; i < 2; i++) { |
| 2709 mock_socket_factory_.ResetNextMockIndexes(); | 2742 mock_socket_factory_.ResetNextMockIndexes(); |
| 2710 | 2743 |
| 2711 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 2744 scoped_ptr<HttpTransaction> trans( |
| 2712 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 2745 new HttpNetworkTransaction( |
| 2746 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 2747 &mock_socket_factory_)); |
| 2713 | 2748 |
| 2714 int rv = trans->Start(&request, &callback); | 2749 int rv = trans->Start(&request, &callback); |
| 2715 EXPECT_EQ(ERR_IO_PENDING, rv); | 2750 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2716 | 2751 |
| 2717 rv = callback.WaitForResult(); | 2752 rv = callback.WaitForResult(); |
| 2718 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); | 2753 EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 2719 | 2754 |
| 2720 rv = trans->RestartIgnoringLastError(&callback); | 2755 rv = trans->RestartIgnoringLastError(&callback); |
| 2721 EXPECT_EQ(ERR_IO_PENDING, rv); | 2756 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2722 | 2757 |
| 2723 rv = callback.WaitForResult(); | 2758 rv = callback.WaitForResult(); |
| 2724 EXPECT_EQ(OK, rv); | 2759 EXPECT_EQ(OK, rv); |
| 2725 | 2760 |
| 2726 const HttpResponseInfo* response = trans->GetResponseInfo(); | 2761 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2727 | 2762 |
| 2728 EXPECT_FALSE(response == NULL); | 2763 EXPECT_FALSE(response == NULL); |
| 2729 EXPECT_EQ(100, response->headers->GetContentLength()); | 2764 EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2730 } | 2765 } |
| 2731 } | 2766 } |
| 2732 | 2767 |
| 2733 TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { | 2768 TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
| 2734 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2769 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 2735 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 2770 scoped_ptr<HttpTransaction> trans( |
| 2736 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 2771 new HttpNetworkTransaction( |
| 2772 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 2773 &mock_socket_factory_)); |
| 2737 | 2774 |
| 2738 HttpRequestInfo request; | 2775 HttpRequestInfo request; |
| 2739 request.method = "GET"; | 2776 request.method = "GET"; |
| 2740 request.url = GURL("http://www.google.com/"); | 2777 request.url = GURL("http://www.google.com/"); |
| 2741 request.user_agent = "Chromium Ultra Awesome X Edition"; | 2778 request.user_agent = "Chromium Ultra Awesome X Edition"; |
| 2742 | 2779 |
| 2743 MockWrite data_writes[] = { | 2780 MockWrite data_writes[] = { |
| 2744 MockWrite("GET / HTTP/1.1\r\n" | 2781 MockWrite("GET / HTTP/1.1\r\n" |
| 2745 "Host: www.google.com\r\n" | 2782 "Host: www.google.com\r\n" |
| 2746 "Connection: keep-alive\r\n" | 2783 "Connection: keep-alive\r\n" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2764 | 2801 |
| 2765 int rv = trans->Start(&request, &callback); | 2802 int rv = trans->Start(&request, &callback); |
| 2766 EXPECT_EQ(ERR_IO_PENDING, rv); | 2803 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2767 | 2804 |
| 2768 rv = callback.WaitForResult(); | 2805 rv = callback.WaitForResult(); |
| 2769 EXPECT_EQ(OK, rv); | 2806 EXPECT_EQ(OK, rv); |
| 2770 } | 2807 } |
| 2771 | 2808 |
| 2772 TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { | 2809 TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
| 2773 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2810 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 2774 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 2811 scoped_ptr<HttpTransaction> trans( |
| 2775 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 2812 new HttpNetworkTransaction( |
| 2813 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 2814 &mock_socket_factory_)); |
| 2776 | 2815 |
| 2777 HttpRequestInfo request; | 2816 HttpRequestInfo request; |
| 2778 request.method = "GET"; | 2817 request.method = "GET"; |
| 2779 request.url = GURL("http://www.google.com/"); | 2818 request.url = GURL("http://www.google.com/"); |
| 2780 request.load_flags = 0; | 2819 request.load_flags = 0; |
| 2781 request.referrer = GURL("http://the.previous.site.com/"); | 2820 request.referrer = GURL("http://the.previous.site.com/"); |
| 2782 | 2821 |
| 2783 MockWrite data_writes[] = { | 2822 MockWrite data_writes[] = { |
| 2784 MockWrite("GET / HTTP/1.1\r\n" | 2823 MockWrite("GET / HTTP/1.1\r\n" |
| 2785 "Host: www.google.com\r\n" | 2824 "Host: www.google.com\r\n" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2804 | 2843 |
| 2805 int rv = trans->Start(&request, &callback); | 2844 int rv = trans->Start(&request, &callback); |
| 2806 EXPECT_EQ(ERR_IO_PENDING, rv); | 2845 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2807 | 2846 |
| 2808 rv = callback.WaitForResult(); | 2847 rv = callback.WaitForResult(); |
| 2809 EXPECT_EQ(OK, rv); | 2848 EXPECT_EQ(OK, rv); |
| 2810 } | 2849 } |
| 2811 | 2850 |
| 2812 TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { | 2851 TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
| 2813 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2852 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 2814 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 2853 scoped_ptr<HttpTransaction> trans( |
| 2815 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 2854 new HttpNetworkTransaction( |
| 2855 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 2856 &mock_socket_factory_)); |
| 2816 | 2857 |
| 2817 HttpRequestInfo request; | 2858 HttpRequestInfo request; |
| 2818 request.method = "POST"; | 2859 request.method = "POST"; |
| 2819 request.url = GURL("http://www.google.com/"); | 2860 request.url = GURL("http://www.google.com/"); |
| 2820 | 2861 |
| 2821 MockWrite data_writes[] = { | 2862 MockWrite data_writes[] = { |
| 2822 MockWrite("POST / HTTP/1.1\r\n" | 2863 MockWrite("POST / HTTP/1.1\r\n" |
| 2823 "Host: www.google.com\r\n" | 2864 "Host: www.google.com\r\n" |
| 2824 "Connection: keep-alive\r\n" | 2865 "Connection: keep-alive\r\n" |
| 2825 "Content-Length: 0\r\n\r\n"), | 2866 "Content-Length: 0\r\n\r\n"), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2842 | 2883 |
| 2843 int rv = trans->Start(&request, &callback); | 2884 int rv = trans->Start(&request, &callback); |
| 2844 EXPECT_EQ(ERR_IO_PENDING, rv); | 2885 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2845 | 2886 |
| 2846 rv = callback.WaitForResult(); | 2887 rv = callback.WaitForResult(); |
| 2847 EXPECT_EQ(OK, rv); | 2888 EXPECT_EQ(OK, rv); |
| 2848 } | 2889 } |
| 2849 | 2890 |
| 2850 TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { | 2891 TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
| 2851 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2892 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 2852 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 2893 scoped_ptr<HttpTransaction> trans( |
| 2853 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 2894 new HttpNetworkTransaction( |
| 2895 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 2896 &mock_socket_factory_)); |
| 2854 | 2897 |
| 2855 HttpRequestInfo request; | 2898 HttpRequestInfo request; |
| 2856 request.method = "PUT"; | 2899 request.method = "PUT"; |
| 2857 request.url = GURL("http://www.google.com/"); | 2900 request.url = GURL("http://www.google.com/"); |
| 2858 | 2901 |
| 2859 MockWrite data_writes[] = { | 2902 MockWrite data_writes[] = { |
| 2860 MockWrite("PUT / HTTP/1.1\r\n" | 2903 MockWrite("PUT / HTTP/1.1\r\n" |
| 2861 "Host: www.google.com\r\n" | 2904 "Host: www.google.com\r\n" |
| 2862 "Connection: keep-alive\r\n" | 2905 "Connection: keep-alive\r\n" |
| 2863 "Content-Length: 0\r\n\r\n"), | 2906 "Content-Length: 0\r\n\r\n"), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2880 | 2923 |
| 2881 int rv = trans->Start(&request, &callback); | 2924 int rv = trans->Start(&request, &callback); |
| 2882 EXPECT_EQ(ERR_IO_PENDING, rv); | 2925 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2883 | 2926 |
| 2884 rv = callback.WaitForResult(); | 2927 rv = callback.WaitForResult(); |
| 2885 EXPECT_EQ(OK, rv); | 2928 EXPECT_EQ(OK, rv); |
| 2886 } | 2929 } |
| 2887 | 2930 |
| 2888 TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { | 2931 TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
| 2889 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2932 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 2890 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 2933 scoped_ptr<HttpTransaction> trans( |
| 2891 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 2934 new HttpNetworkTransaction( |
| 2935 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 2936 &mock_socket_factory_)); |
| 2892 | 2937 |
| 2893 HttpRequestInfo request; | 2938 HttpRequestInfo request; |
| 2894 request.method = "HEAD"; | 2939 request.method = "HEAD"; |
| 2895 request.url = GURL("http://www.google.com/"); | 2940 request.url = GURL("http://www.google.com/"); |
| 2896 | 2941 |
| 2897 MockWrite data_writes[] = { | 2942 MockWrite data_writes[] = { |
| 2898 MockWrite("HEAD / HTTP/1.1\r\n" | 2943 MockWrite("HEAD / HTTP/1.1\r\n" |
| 2899 "Host: www.google.com\r\n" | 2944 "Host: www.google.com\r\n" |
| 2900 "Connection: keep-alive\r\n" | 2945 "Connection: keep-alive\r\n" |
| 2901 "Content-Length: 0\r\n\r\n"), | 2946 "Content-Length: 0\r\n\r\n"), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2918 | 2963 |
| 2919 int rv = trans->Start(&request, &callback); | 2964 int rv = trans->Start(&request, &callback); |
| 2920 EXPECT_EQ(ERR_IO_PENDING, rv); | 2965 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2921 | 2966 |
| 2922 rv = callback.WaitForResult(); | 2967 rv = callback.WaitForResult(); |
| 2923 EXPECT_EQ(OK, rv); | 2968 EXPECT_EQ(OK, rv); |
| 2924 } | 2969 } |
| 2925 | 2970 |
| 2926 TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { | 2971 TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
| 2927 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 2972 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 2928 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 2973 scoped_ptr<HttpTransaction> trans( |
| 2929 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 2974 new HttpNetworkTransaction( |
| 2975 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 2976 &mock_socket_factory_)); |
| 2930 | 2977 |
| 2931 HttpRequestInfo request; | 2978 HttpRequestInfo request; |
| 2932 request.method = "GET"; | 2979 request.method = "GET"; |
| 2933 request.url = GURL("http://www.google.com/"); | 2980 request.url = GURL("http://www.google.com/"); |
| 2934 request.load_flags = LOAD_BYPASS_CACHE; | 2981 request.load_flags = LOAD_BYPASS_CACHE; |
| 2935 | 2982 |
| 2936 MockWrite data_writes[] = { | 2983 MockWrite data_writes[] = { |
| 2937 MockWrite("GET / HTTP/1.1\r\n" | 2984 MockWrite("GET / HTTP/1.1\r\n" |
| 2938 "Host: www.google.com\r\n" | 2985 "Host: www.google.com\r\n" |
| 2939 "Connection: keep-alive\r\n" | 2986 "Connection: keep-alive\r\n" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2959 int rv = trans->Start(&request, &callback); | 3006 int rv = trans->Start(&request, &callback); |
| 2960 EXPECT_EQ(ERR_IO_PENDING, rv); | 3007 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2961 | 3008 |
| 2962 rv = callback.WaitForResult(); | 3009 rv = callback.WaitForResult(); |
| 2963 EXPECT_EQ(OK, rv); | 3010 EXPECT_EQ(OK, rv); |
| 2964 } | 3011 } |
| 2965 | 3012 |
| 2966 TEST_F(HttpNetworkTransactionTest, | 3013 TEST_F(HttpNetworkTransactionTest, |
| 2967 BuildRequest_CacheControlValidateCache) { | 3014 BuildRequest_CacheControlValidateCache) { |
| 2968 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 3015 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 2969 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 3016 scoped_ptr<HttpTransaction> trans( |
| 2970 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 3017 new HttpNetworkTransaction( |
| 3018 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 3019 &mock_socket_factory_)); |
| 2971 | 3020 |
| 2972 HttpRequestInfo request; | 3021 HttpRequestInfo request; |
| 2973 request.method = "GET"; | 3022 request.method = "GET"; |
| 2974 request.url = GURL("http://www.google.com/"); | 3023 request.url = GURL("http://www.google.com/"); |
| 2975 request.load_flags = LOAD_VALIDATE_CACHE; | 3024 request.load_flags = LOAD_VALIDATE_CACHE; |
| 2976 | 3025 |
| 2977 MockWrite data_writes[] = { | 3026 MockWrite data_writes[] = { |
| 2978 MockWrite("GET / HTTP/1.1\r\n" | 3027 MockWrite("GET / HTTP/1.1\r\n" |
| 2979 "Host: www.google.com\r\n" | 3028 "Host: www.google.com\r\n" |
| 2980 "Connection: keep-alive\r\n" | 3029 "Connection: keep-alive\r\n" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2998 | 3047 |
| 2999 int rv = trans->Start(&request, &callback); | 3048 int rv = trans->Start(&request, &callback); |
| 3000 EXPECT_EQ(ERR_IO_PENDING, rv); | 3049 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3001 | 3050 |
| 3002 rv = callback.WaitForResult(); | 3051 rv = callback.WaitForResult(); |
| 3003 EXPECT_EQ(OK, rv); | 3052 EXPECT_EQ(OK, rv); |
| 3004 } | 3053 } |
| 3005 | 3054 |
| 3006 TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { | 3055 TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
| 3007 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); | 3056 scoped_ptr<ProxyService> proxy_service(CreateNullProxyService()); |
| 3008 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction( | 3057 scoped_ptr<HttpTransaction> trans( |
| 3009 CreateSession(proxy_service.get()), &mock_socket_factory_)); | 3058 new HttpNetworkTransaction( |
| 3059 CreateSession(proxy_service.get(), &mock_socket_factory_), |
| 3060 &mock_socket_factory_)); |
| 3010 | 3061 |
| 3011 HttpRequestInfo request; | 3062 HttpRequestInfo request; |
| 3012 request.method = "GET"; | 3063 request.method = "GET"; |
| 3013 request.url = GURL("http://www.google.com/"); | 3064 request.url = GURL("http://www.google.com/"); |
| 3014 request.extra_headers = "FooHeader: Bar\r\n"; | 3065 request.extra_headers = "FooHeader: Bar\r\n"; |
| 3015 | 3066 |
| 3016 MockWrite data_writes[] = { | 3067 MockWrite data_writes[] = { |
| 3017 MockWrite("GET / HTTP/1.1\r\n" | 3068 MockWrite("GET / HTTP/1.1\r\n" |
| 3018 "Host: www.google.com\r\n" | 3069 "Host: www.google.com\r\n" |
| 3019 "Connection: keep-alive\r\n" | 3070 "Connection: keep-alive\r\n" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3036 TestCompletionCallback callback; | 3087 TestCompletionCallback callback; |
| 3037 | 3088 |
| 3038 int rv = trans->Start(&request, &callback); | 3089 int rv = trans->Start(&request, &callback); |
| 3039 EXPECT_EQ(ERR_IO_PENDING, rv); | 3090 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3040 | 3091 |
| 3041 rv = callback.WaitForResult(); | 3092 rv = callback.WaitForResult(); |
| 3042 EXPECT_EQ(OK, rv); | 3093 EXPECT_EQ(OK, rv); |
| 3043 } | 3094 } |
| 3044 | 3095 |
| 3045 } // namespace net | 3096 } // namespace net |
| OLD | NEW |