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

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 6684019: Reland rest of r77399. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 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/http/http_network_transaction.cc ('k') | net/http/http_response_info.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 6419 matching lines...) Expand 10 before | Expand all | Expand 10 after
6430 alternate_protocols.HasAlternateProtocolFor(http_host_port_pair)); 6430 alternate_protocols.HasAlternateProtocolFor(http_host_port_pair));
6431 6431
6432 EXPECT_EQ(OK, callback.WaitForResult()); 6432 EXPECT_EQ(OK, callback.WaitForResult());
6433 6433
6434 const HttpResponseInfo* response = trans->GetResponseInfo(); 6434 const HttpResponseInfo* response = trans->GetResponseInfo();
6435 ASSERT_TRUE(response != NULL); 6435 ASSERT_TRUE(response != NULL);
6436 ASSERT_TRUE(response->headers != NULL); 6436 ASSERT_TRUE(response->headers != NULL);
6437 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 6437 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
6438 EXPECT_FALSE(response->was_fetched_via_spdy); 6438 EXPECT_FALSE(response->was_fetched_via_spdy);
6439 EXPECT_FALSE(response->was_npn_negotiated); 6439 EXPECT_FALSE(response->was_npn_negotiated);
6440 EXPECT_FALSE(response->was_alternate_protocol_available);
6441 6440
6442 std::string response_data; 6441 std::string response_data;
6443 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 6442 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
6444 EXPECT_EQ("hello world", response_data); 6443 EXPECT_EQ("hello world", response_data);
6445 6444
6446 ASSERT_TRUE(alternate_protocols.HasAlternateProtocolFor(http_host_port_pair)); 6445 ASSERT_TRUE(alternate_protocols.HasAlternateProtocolFor(http_host_port_pair));
6447 const HttpAlternateProtocols::PortProtocolPair alternate = 6446 const HttpAlternateProtocols::PortProtocolPair alternate =
6448 alternate_protocols.GetAlternateProtocolFor(http_host_port_pair); 6447 alternate_protocols.GetAlternateProtocolFor(http_host_port_pair);
6449 HttpAlternateProtocols::PortProtocolPair expected_alternate; 6448 HttpAlternateProtocols::PortProtocolPair expected_alternate;
6450 expected_alternate.port = 443; 6449 expected_alternate.port = 443;
(...skipping 20 matching lines...) Expand all
6471 6470
6472 MockRead data_reads[] = { 6471 MockRead data_reads[] = {
6473 MockRead("HTTP/1.1 200 OK\r\n\r\n"), 6472 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
6474 MockRead("hello world"), 6473 MockRead("hello world"),
6475 MockRead(true, OK), 6474 MockRead(true, OK),
6476 }; 6475 };
6477 StaticSocketDataProvider second_data( 6476 StaticSocketDataProvider second_data(
6478 data_reads, arraysize(data_reads), NULL, 0); 6477 data_reads, arraysize(data_reads), NULL, 0);
6479 session_deps.socket_factory.AddSocketDataProvider(&second_data); 6478 session_deps.socket_factory.AddSocketDataProvider(&second_data);
6480 6479
6481 // TODO(willchan): Delete this extra data provider. It's necessary due to a
6482 // ClientSocketPoolBaseHelper bug that starts up too many ConnectJobs:
6483 // http://crbug.com/37454.
6484 session_deps.socket_factory.AddSocketDataProvider(&second_data);
6485
6486 TestCompletionCallback callback; 6480 TestCompletionCallback callback;
6487 6481
6488 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 6482 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
6489 6483
6490 HostPortPair http_host_port_pair("www.google.com", 80); 6484 HostPortPair http_host_port_pair("www.google.com", 80);
6491 HttpAlternateProtocols* alternate_protocols = 6485 HttpAlternateProtocols* alternate_protocols =
6492 session->mutable_alternate_protocols(); 6486 session->mutable_alternate_protocols();
6493 alternate_protocols->SetAlternateProtocolFor( 6487 alternate_protocols->SetAlternateProtocolFor(
6494 http_host_port_pair, 1234 /* port is ignored by MockConnect anyway */, 6488 http_host_port_pair, 1234 /* port is ignored by MockConnect anyway */,
6495 HttpAlternateProtocols::NPN_SPDY_2); 6489 HttpAlternateProtocols::NPN_SPDY_2);
(...skipping 14 matching lines...) Expand all
6510 EXPECT_EQ("hello world", response_data); 6504 EXPECT_EQ("hello world", response_data);
6511 6505
6512 ASSERT_TRUE( 6506 ASSERT_TRUE(
6513 alternate_protocols->HasAlternateProtocolFor(http_host_port_pair)); 6507 alternate_protocols->HasAlternateProtocolFor(http_host_port_pair));
6514 const HttpAlternateProtocols::PortProtocolPair alternate = 6508 const HttpAlternateProtocols::PortProtocolPair alternate =
6515 alternate_protocols->GetAlternateProtocolFor(http_host_port_pair); 6509 alternate_protocols->GetAlternateProtocolFor(http_host_port_pair);
6516 EXPECT_EQ(HttpAlternateProtocols::BROKEN, alternate.protocol); 6510 EXPECT_EQ(HttpAlternateProtocols::BROKEN, alternate.protocol);
6517 HttpStreamFactory::set_use_alternate_protocols(false); 6511 HttpStreamFactory::set_use_alternate_protocols(false);
6518 } 6512 }
6519 6513
6520 // TODO(willchan): Redo this test to use TLS/NPN=>SPDY. Currently, the code
6521 // says that it does SPDY, but it just does the TLS handshake, but the NPN
6522 // response does not indicate SPDY, so we just do standard HTTPS over the port.
6523 // We should add code such that we don't fallback to HTTPS, but fallback to HTTP
6524 // on the original port.
6525 // TEST_F(HttpNetworkTransactionTest, UseAlternateProtocol) {
6526 // SessionDependencies session_deps;
6527 //
6528 // HttpRequestInfo request;
6529 // request.method = "GET";
6530 // request.url = GURL("http://www.google.com/");
6531 // request.load_flags = 0;
6532 //
6533 // MockRead data_reads[] = {
6534 // MockRead("HTTP/1.1 200 OK\r\n\r\n"),
6535 // MockRead("hello world"),
6536 // MockRead(true, OK),
6537 // };
6538 // StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0);
6539 // session_deps.socket_factory.AddSocketDataProvider(&data);
6540 //
6541 // SSLSocketDataProvider ssl(true, OK);
6542 // session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
6543 //
6544 // TestCompletionCallback callback;
6545 //
6546 // scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
6547 //
6548 // HostPortPair http_host_port_pair;
6549 // http_host_port_pair.host = "www.google.com";
6550 // http_host_port_pair.port = 80;
6551 // HttpAlternateProtocols* alternate_protocols =
6552 // session->mutable_alternate_protocols();
6553 // alternate_protocols->SetAlternateProtocolFor(
6554 // http_host_port_pair, 1234 /* port is ignored */,
6555 // HttpAlternateProtocols::NPN_SPDY_1);
6556 //
6557 // scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
6558 //
6559 // int rv = trans->Start(&request, &callback, BoundNetLog());
6560 // EXPECT_EQ(ERR_IO_PENDING, rv);
6561 // EXPECT_EQ(OK, callback.WaitForResult());
6562 //
6563 // const HttpResponseInfo* response = trans->GetResponseInfo();
6564 // ASSERT_TRUE(response != NULL);
6565 // ASSERT_TRUE(response->headers != NULL);
6566 // EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
6567 //
6568 // std::string response_data;
6569 // ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
6570 // EXPECT_EQ("hello world", response_data);
6571 // }
6572
6573 TEST_F(HttpNetworkTransactionTest, FailNpnSpdyAndFallback) { 6514 TEST_F(HttpNetworkTransactionTest, FailNpnSpdyAndFallback) {
6574 HttpStreamFactory::set_use_alternate_protocols(true); 6515 HttpStreamFactory::set_use_alternate_protocols(true);
6575 HttpStreamFactory::set_next_protos(kExpectedNPNString); 6516 HttpStreamFactory::set_next_protos(kExpectedNPNString);
6576 SessionDependencies session_deps; 6517 SessionDependencies session_deps;
6577 6518
6578 HttpRequestInfo request; 6519 HttpRequestInfo request;
6579 request.method = "GET"; 6520 request.method = "GET";
6580 request.url = GURL("http://www.google.com/"); 6521 request.url = GURL("http://www.google.com/");
6581 request.load_flags = 0; 6522 request.load_flags = 0;
6582 6523
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
6662 MockRead(true, 0, 0), 6603 MockRead(true, 0, 0),
6663 }; 6604 };
6664 6605
6665 scoped_refptr<DelayedSocketData> spdy_data( 6606 scoped_refptr<DelayedSocketData> spdy_data(
6666 new DelayedSocketData( 6607 new DelayedSocketData(
6667 1, // wait for one write to finish before reading. 6608 1, // wait for one write to finish before reading.
6668 spdy_reads, arraysize(spdy_reads), 6609 spdy_reads, arraysize(spdy_reads),
6669 spdy_writes, arraysize(spdy_writes))); 6610 spdy_writes, arraysize(spdy_writes)));
6670 session_deps.socket_factory.AddSocketDataProvider(spdy_data); 6611 session_deps.socket_factory.AddSocketDataProvider(spdy_data);
6671 6612
6613 MockConnect never_finishing_connect(false, ERR_IO_PENDING);
6614 StaticSocketDataProvider hanging_non_alternate_protocol_socket(
6615 NULL, 0, NULL, 0);
6616 hanging_non_alternate_protocol_socket.set_connect_data(
6617 never_finishing_connect);
6618 session_deps.socket_factory.AddSocketDataProvider(
6619 &hanging_non_alternate_protocol_socket);
6620
6672 TestCompletionCallback callback; 6621 TestCompletionCallback callback;
6673 6622
6674 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 6623 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
6675 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); 6624 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
6676 6625
6677 int rv = trans->Start(&request, &callback, BoundNetLog()); 6626 int rv = trans->Start(&request, &callback, BoundNetLog());
6678 EXPECT_EQ(ERR_IO_PENDING, rv); 6627 EXPECT_EQ(ERR_IO_PENDING, rv);
6679 EXPECT_EQ(OK, callback.WaitForResult()); 6628 EXPECT_EQ(OK, callback.WaitForResult());
6680 6629
6681 const HttpResponseInfo* response = trans->GetResponseInfo(); 6630 const HttpResponseInfo* response = trans->GetResponseInfo();
(...skipping 10 matching lines...) Expand all
6692 rv = trans->Start(&request, &callback, BoundNetLog()); 6641 rv = trans->Start(&request, &callback, BoundNetLog());
6693 EXPECT_EQ(ERR_IO_PENDING, rv); 6642 EXPECT_EQ(ERR_IO_PENDING, rv);
6694 EXPECT_EQ(OK, callback.WaitForResult()); 6643 EXPECT_EQ(OK, callback.WaitForResult());
6695 6644
6696 response = trans->GetResponseInfo(); 6645 response = trans->GetResponseInfo();
6697 ASSERT_TRUE(response != NULL); 6646 ASSERT_TRUE(response != NULL);
6698 ASSERT_TRUE(response->headers != NULL); 6647 ASSERT_TRUE(response->headers != NULL);
6699 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 6648 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
6700 EXPECT_TRUE(response->was_fetched_via_spdy); 6649 EXPECT_TRUE(response->was_fetched_via_spdy);
6701 EXPECT_TRUE(response->was_npn_negotiated); 6650 EXPECT_TRUE(response->was_npn_negotiated);
6702 EXPECT_TRUE(response->was_alternate_protocol_available);
6703 6651
6704 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 6652 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
6705 EXPECT_EQ("hello!", response_data); 6653 EXPECT_EQ("hello!", response_data);
6706 6654
6707 HttpStreamFactory::set_next_protos(""); 6655 HttpStreamFactory::set_next_protos("");
6708 HttpStreamFactory::set_use_alternate_protocols(false); 6656 HttpStreamFactory::set_use_alternate_protocols(false);
6709 } 6657 }
6710 6658
6659 TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) {
6660 HttpStreamFactory::set_use_alternate_protocols(true);
6661 HttpStreamFactory::set_next_protos(kExpectedNPNString);
6662 SessionDependencies session_deps;
6663
6664 HttpRequestInfo request;
6665 request.method = "GET";
6666 request.url = GURL("http://www.google.com/");
6667 request.load_flags = 0;
6668
6669 MockRead data_reads[] = {
6670 MockRead("HTTP/1.1 200 OK\r\n"),
6671 MockRead(kAlternateProtocolHttpHeader),
6672 MockRead("hello world"),
6673 MockRead(true, OK),
6674 };
6675
6676 StaticSocketDataProvider first_transaction(
6677 data_reads, arraysize(data_reads), NULL, 0);
6678 // Socket 1 is the HTTP transaction with the Alternate-Protocol header.
6679 session_deps.socket_factory.AddSocketDataProvider(&first_transaction);
6680
6681 MockConnect never_finishing_connect(false, ERR_IO_PENDING);
6682 StaticSocketDataProvider hanging_socket(
6683 NULL, 0, NULL, 0);
6684 hanging_socket.set_connect_data(never_finishing_connect);
6685 // Socket 2 and 3 are the hanging Alternate-Protocol and
6686 // non-Alternate-Protocol jobs from the 2nd transaction.
6687 session_deps.socket_factory.AddSocketDataProvider(&hanging_socket);
6688 session_deps.socket_factory.AddSocketDataProvider(&hanging_socket);
6689
6690 SSLSocketDataProvider ssl(true, OK);
6691 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated;
6692 ssl.next_proto = "spdy/2";
6693 ssl.was_npn_negotiated = true;
6694 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
6695
6696 scoped_ptr<spdy::SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
6697 scoped_ptr<spdy::SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, LOWEST));
6698 MockWrite spdy_writes[] = {
6699 CreateMockWrite(*req1),
6700 CreateMockWrite(*req2),
6701 };
6702 scoped_ptr<spdy::SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1));
6703 scoped_ptr<spdy::SpdyFrame> data1(ConstructSpdyBodyFrame(1, true));
6704 scoped_ptr<spdy::SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3));
6705 scoped_ptr<spdy::SpdyFrame> data2(ConstructSpdyBodyFrame(3, true));
6706 MockRead spdy_reads[] = {
6707 CreateMockRead(*resp1),
6708 CreateMockRead(*data1),
6709 CreateMockRead(*resp2),
6710 CreateMockRead(*data2),
6711 MockRead(true, 0, 0),
6712 };
6713
6714 scoped_refptr<DelayedSocketData> spdy_data(
6715 new DelayedSocketData(
6716 2, // wait for writes to finish before reading.
6717 spdy_reads, arraysize(spdy_reads),
6718 spdy_writes, arraysize(spdy_writes)));
6719 // Socket 4 is the successful Alternate-Protocol for transaction 3.
6720 session_deps.socket_factory.AddSocketDataProvider(spdy_data);
6721
6722 // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3.
6723 session_deps.socket_factory.AddSocketDataProvider(&hanging_socket);
6724
6725 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
6726 TestCompletionCallback callback1;
6727 HttpNetworkTransaction trans1(session);
6728
6729 int rv = trans1.Start(&request, &callback1, BoundNetLog());
6730 EXPECT_EQ(ERR_IO_PENDING, rv);
6731 EXPECT_EQ(OK, callback1.WaitForResult());
6732
6733 const HttpResponseInfo* response = trans1.GetResponseInfo();
6734 ASSERT_TRUE(response != NULL);
6735 ASSERT_TRUE(response->headers != NULL);
6736 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
6737
6738 std::string response_data;
6739 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data));
6740 EXPECT_EQ("hello world", response_data);
6741
6742 TestCompletionCallback callback2;
6743 HttpNetworkTransaction trans2(session);
6744 rv = trans2.Start(&request, &callback2, BoundNetLog());
6745 EXPECT_EQ(ERR_IO_PENDING, rv);
6746
6747 TestCompletionCallback callback3;
6748 HttpNetworkTransaction trans3(session);
6749 rv = trans3.Start(&request, &callback3, BoundNetLog());
6750 EXPECT_EQ(ERR_IO_PENDING, rv);
6751
6752 EXPECT_EQ(OK, callback2.WaitForResult());
6753 EXPECT_EQ(OK, callback3.WaitForResult());
6754
6755 response = trans2.GetResponseInfo();
6756 ASSERT_TRUE(response != NULL);
6757 ASSERT_TRUE(response->headers != NULL);
6758 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
6759 EXPECT_TRUE(response->was_fetched_via_spdy);
6760 EXPECT_TRUE(response->was_npn_negotiated);
6761 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data));
6762 EXPECT_EQ("hello!", response_data);
6763
6764 response = trans3.GetResponseInfo();
6765 ASSERT_TRUE(response != NULL);
6766 ASSERT_TRUE(response->headers != NULL);
6767 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
6768 EXPECT_TRUE(response->was_fetched_via_spdy);
6769 EXPECT_TRUE(response->was_npn_negotiated);
6770 ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data));
6771 EXPECT_EQ("hello!", response_data);
6772
6773 HttpStreamFactory::set_next_protos("");
6774 HttpStreamFactory::set_use_alternate_protocols(false);
6775 }
6776
6777 TEST_F(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) {
6778 HttpStreamFactory::set_use_alternate_protocols(true);
6779 HttpStreamFactory::set_next_protos(kExpectedNPNString);
6780 SessionDependencies session_deps;
6781
6782 HttpRequestInfo request;
6783 request.method = "GET";
6784 request.url = GURL("http://www.google.com/");
6785 request.load_flags = 0;
6786
6787 MockRead data_reads[] = {
6788 MockRead("HTTP/1.1 200 OK\r\n"),
6789 MockRead(kAlternateProtocolHttpHeader),
6790 MockRead("hello world"),
6791 MockRead(true, OK),
6792 };
6793
6794 StaticSocketDataProvider first_transaction(
6795 data_reads, arraysize(data_reads), NULL, 0);
6796 session_deps.socket_factory.AddSocketDataProvider(&first_transaction);
6797
6798 SSLSocketDataProvider ssl(true, OK);
6799 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated;
6800 ssl.next_proto = "spdy/2";
6801 ssl.was_npn_negotiated = true;
6802 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
6803
6804 MockConnect never_finishing_connect(false, ERR_IO_PENDING);
6805 StaticSocketDataProvider hanging_alternate_protocol_socket(
6806 NULL, 0, NULL, 0);
6807 hanging_alternate_protocol_socket.set_connect_data(
6808 never_finishing_connect);
6809 session_deps.socket_factory.AddSocketDataProvider(
6810 &hanging_alternate_protocol_socket);
6811
6812 // 2nd request is just a copy of the first one, over HTTP again.
6813 session_deps.socket_factory.AddSocketDataProvider(&first_transaction);
6814
6815 TestCompletionCallback callback;
6816
6817 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
6818 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
6819
6820 int rv = trans->Start(&request, &callback, BoundNetLog());
6821 EXPECT_EQ(ERR_IO_PENDING, rv);
6822 EXPECT_EQ(OK, callback.WaitForResult());
6823
6824 const HttpResponseInfo* response = trans->GetResponseInfo();
6825 ASSERT_TRUE(response != NULL);
6826 ASSERT_TRUE(response->headers != NULL);
6827 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
6828
6829 std::string response_data;
6830 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
6831 EXPECT_EQ("hello world", response_data);
6832
6833 trans.reset(new HttpNetworkTransaction(session));
6834
6835 rv = trans->Start(&request, &callback, BoundNetLog());
6836 EXPECT_EQ(ERR_IO_PENDING, rv);
6837 EXPECT_EQ(OK, callback.WaitForResult());
6838
6839 response = trans->GetResponseInfo();
6840 ASSERT_TRUE(response != NULL);
6841 ASSERT_TRUE(response->headers != NULL);
6842 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
6843 EXPECT_FALSE(response->was_fetched_via_spdy);
6844 EXPECT_FALSE(response->was_npn_negotiated);
6845
6846 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
6847 EXPECT_EQ("hello world", response_data);
6848
6849 HttpStreamFactory::set_next_protos("");
6850 HttpStreamFactory::set_use_alternate_protocols(false);
6851 }
6852
6711 class CapturingProxyResolver : public ProxyResolver { 6853 class CapturingProxyResolver : public ProxyResolver {
6712 public: 6854 public:
6713 CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {} 6855 CapturingProxyResolver() : ProxyResolver(false /* expects_pac_bytes */) {}
6714 virtual ~CapturingProxyResolver() {} 6856 virtual ~CapturingProxyResolver() {}
6715 6857
6716 virtual int GetProxyForURL(const GURL& url, 6858 virtual int GetProxyForURL(const GURL& url,
6717 ProxyInfo* results, 6859 ProxyInfo* results,
6718 CompletionCallback* callback, 6860 CompletionCallback* callback,
6719 RequestHandle* request, 6861 RequestHandle* request,
6720 const BoundNetLog& net_log) { 6862 const BoundNetLog& net_log) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
6800 CreateMockRead(*data.get(), 4), // 5 6942 CreateMockRead(*data.get(), 4), // 5
6801 MockRead(true, 0, 0, 4), // 6 6943 MockRead(true, 0, 0, 4), // 6
6802 }; 6944 };
6803 6945
6804 scoped_refptr<OrderedSocketData> spdy_data( 6946 scoped_refptr<OrderedSocketData> spdy_data(
6805 new OrderedSocketData( 6947 new OrderedSocketData(
6806 spdy_reads, arraysize(spdy_reads), 6948 spdy_reads, arraysize(spdy_reads),
6807 spdy_writes, arraysize(spdy_writes))); 6949 spdy_writes, arraysize(spdy_writes)));
6808 session_deps.socket_factory.AddSocketDataProvider(spdy_data); 6950 session_deps.socket_factory.AddSocketDataProvider(spdy_data);
6809 6951
6952 MockConnect never_finishing_connect(false, ERR_IO_PENDING);
6953 StaticSocketDataProvider hanging_non_alternate_protocol_socket(
6954 NULL, 0, NULL, 0);
6955 hanging_non_alternate_protocol_socket.set_connect_data(
6956 never_finishing_connect);
6957 session_deps.socket_factory.AddSocketDataProvider(
6958 &hanging_non_alternate_protocol_socket);
6959
6810 TestCompletionCallback callback; 6960 TestCompletionCallback callback;
6811 6961
6812 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 6962 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
6813 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); 6963 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session));
6814 6964
6815 int rv = trans->Start(&request, &callback, BoundNetLog()); 6965 int rv = trans->Start(&request, &callback, BoundNetLog());
6816 EXPECT_EQ(ERR_IO_PENDING, rv); 6966 EXPECT_EQ(ERR_IO_PENDING, rv);
6817 EXPECT_EQ(OK, callback.WaitForResult()); 6967 EXPECT_EQ(OK, callback.WaitForResult());
6818 6968
6819 const HttpResponseInfo* response = trans->GetResponseInfo(); 6969 const HttpResponseInfo* response = trans->GetResponseInfo();
(...skipping 15 matching lines...) Expand all
6835 6985
6836 response = trans->GetResponseInfo(); 6986 response = trans->GetResponseInfo();
6837 ASSERT_TRUE(response != NULL); 6987 ASSERT_TRUE(response != NULL);
6838 ASSERT_TRUE(response->headers != NULL); 6988 ASSERT_TRUE(response->headers != NULL);
6839 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 6989 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
6840 EXPECT_TRUE(response->was_fetched_via_spdy); 6990 EXPECT_TRUE(response->was_fetched_via_spdy);
6841 EXPECT_TRUE(response->was_npn_negotiated); 6991 EXPECT_TRUE(response->was_npn_negotiated);
6842 6992
6843 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 6993 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
6844 EXPECT_EQ("hello!", response_data); 6994 EXPECT_EQ("hello!", response_data);
6845 ASSERT_EQ(2u, capturing_proxy_resolver->resolved().size()); 6995 ASSERT_EQ(3u, capturing_proxy_resolver->resolved().size());
6846 EXPECT_EQ("http://www.google.com/", 6996 EXPECT_EQ("http://www.google.com/",
6847 capturing_proxy_resolver->resolved()[0].spec()); 6997 capturing_proxy_resolver->resolved()[0].spec());
6848 EXPECT_EQ("https://www.google.com/", 6998 EXPECT_EQ("https://www.google.com/",
6849 capturing_proxy_resolver->resolved()[1].spec()); 6999 capturing_proxy_resolver->resolved()[1].spec());
6850 7000
6851 HttpStreamFactory::set_next_protos(""); 7001 HttpStreamFactory::set_next_protos("");
6852 HttpStreamFactory::set_use_alternate_protocols(false); 7002 HttpStreamFactory::set_use_alternate_protocols(false);
6853 } 7003 }
6854 7004
6855 TEST_F(HttpNetworkTransactionTest, 7005 TEST_F(HttpNetworkTransactionTest,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
6951 rv = trans->Start(&request, &callback, BoundNetLog()); 7101 rv = trans->Start(&request, &callback, BoundNetLog());
6952 EXPECT_EQ(ERR_IO_PENDING, rv); 7102 EXPECT_EQ(ERR_IO_PENDING, rv);
6953 EXPECT_EQ(OK, callback.WaitForResult()); 7103 EXPECT_EQ(OK, callback.WaitForResult());
6954 7104
6955 response = trans->GetResponseInfo(); 7105 response = trans->GetResponseInfo();
6956 ASSERT_TRUE(response != NULL); 7106 ASSERT_TRUE(response != NULL);
6957 ASSERT_TRUE(response->headers != NULL); 7107 ASSERT_TRUE(response->headers != NULL);
6958 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 7108 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
6959 EXPECT_TRUE(response->was_fetched_via_spdy); 7109 EXPECT_TRUE(response->was_fetched_via_spdy);
6960 EXPECT_TRUE(response->was_npn_negotiated); 7110 EXPECT_TRUE(response->was_npn_negotiated);
6961 EXPECT_TRUE(response->was_alternate_protocol_available);
6962 7111
6963 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 7112 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
6964 EXPECT_EQ("hello!", response_data); 7113 EXPECT_EQ("hello!", response_data);
6965 7114
6966 HttpStreamFactory::set_next_protos(""); 7115 HttpStreamFactory::set_next_protos("");
6967 HttpStreamFactory::set_use_alternate_protocols(false); 7116 HttpStreamFactory::set_use_alternate_protocols(false);
6968 } 7117 }
6969 7118
6970 // GenerateAuthToken is a mighty big test. 7119 // GenerateAuthToken is a mighty big test.
6971 // It tests all permutation of GenerateAuthToken behavior: 7120 // It tests all permutation of GenerateAuthToken behavior:
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
7722 ASSERT_TRUE(response != NULL); 7871 ASSERT_TRUE(response != NULL);
7723 ASSERT_TRUE(response->headers != NULL); 7872 ASSERT_TRUE(response->headers != NULL);
7724 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 7873 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
7725 7874
7726 std::string response_data; 7875 std::string response_data;
7727 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 7876 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
7728 EXPECT_EQ("hello world", response_data); 7877 EXPECT_EQ("hello world", response_data);
7729 7878
7730 EXPECT_FALSE(response->was_fetched_via_spdy); 7879 EXPECT_FALSE(response->was_fetched_via_spdy);
7731 EXPECT_TRUE(response->was_npn_negotiated); 7880 EXPECT_TRUE(response->was_npn_negotiated);
7732 EXPECT_FALSE(response->was_alternate_protocol_available);
7733 7881
7734 HttpStreamFactory::set_next_protos(""); 7882 HttpStreamFactory::set_next_protos("");
7735 HttpStreamFactory::set_use_alternate_protocols(false); 7883 HttpStreamFactory::set_use_alternate_protocols(false);
7736 } 7884 }
7737 7885
7738 TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { 7886 TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) {
7739 // Simulate the SSL handshake completing with an NPN negotiation 7887 // Simulate the SSL handshake completing with an NPN negotiation
7740 // followed by an immediate server closing of the socket. 7888 // followed by an immediate server closing of the socket.
7741 // Fix crash: http://crbug.com/46369 7889 // Fix crash: http://crbug.com/46369
7742 HttpStreamFactory::set_use_alternate_protocols(true); 7890 HttpStreamFactory::set_use_alternate_protocols(true);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
7878 }; 8026 };
7879 scoped_refptr<OrderedSocketData> data_2( 8027 scoped_refptr<OrderedSocketData> data_2(
7880 new OrderedSocketData(data_reads_2, arraysize(data_reads_2), 8028 new OrderedSocketData(data_reads_2, arraysize(data_reads_2),
7881 data_writes_2, arraysize(data_writes_2))); 8029 data_writes_2, arraysize(data_writes_2)));
7882 8030
7883 SSLSocketDataProvider ssl(true, OK); 8031 SSLSocketDataProvider ssl(true, OK);
7884 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; 8032 ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated;
7885 ssl.next_proto = "spdy/2"; 8033 ssl.next_proto = "spdy/2";
7886 ssl.was_npn_negotiated = true; 8034 ssl.was_npn_negotiated = true;
7887 8035
8036 MockConnect never_finishing_connect(false, ERR_IO_PENDING);
8037 StaticSocketDataProvider hanging_non_alternate_protocol_socket(
8038 NULL, 0, NULL, 0);
8039 hanging_non_alternate_protocol_socket.set_connect_data(
8040 never_finishing_connect);
8041
7888 session_deps.socket_factory.AddSocketDataProvider(&data_1); 8042 session_deps.socket_factory.AddSocketDataProvider(&data_1);
7889 session_deps.socket_factory.AddSocketDataProvider(data_2.get()); 8043 session_deps.socket_factory.AddSocketDataProvider(data_2.get());
7890 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); 8044 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
8045 session_deps.socket_factory.AddSocketDataProvider(
8046 &hanging_non_alternate_protocol_socket);
7891 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 8047 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
7892 8048
7893 // First round should work and provide the Alternate-Protocol state. 8049 // First round should work and provide the Alternate-Protocol state.
7894 TestCompletionCallback callback_1; 8050 TestCompletionCallback callback_1;
7895 scoped_ptr<HttpTransaction> trans_1(new HttpNetworkTransaction(session)); 8051 scoped_ptr<HttpTransaction> trans_1(new HttpNetworkTransaction(session));
7896 int rv = trans_1->Start(&request, &callback_1, BoundNetLog()); 8052 int rv = trans_1->Start(&request, &callback_1, BoundNetLog());
7897 EXPECT_EQ(ERR_IO_PENDING, rv); 8053 EXPECT_EQ(ERR_IO_PENDING, rv);
7898 EXPECT_EQ(OK, callback_1.WaitForResult()); 8054 EXPECT_EQ(OK, callback_1.WaitForResult());
7899 8055
7900 // Second round should attempt a tunnel connect and get an auth challenge. 8056 // Second round should attempt a tunnel connect and get an auth challenge.
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
8579 // Now that the new handshake has failed, ensure that the client 8735 // Now that the new handshake has failed, ensure that the client
8580 // certificate was removed from the client auth cache. 8736 // certificate was removed from the client auth cache.
8581 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("proxy:70", 8737 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("proxy:70",
8582 &client_cert)); 8738 &client_cert));
8583 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", 8739 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443",
8584 &client_cert)); 8740 &client_cert));
8585 } 8741 }
8586 } 8742 }
8587 8743
8588 } // namespace net 8744 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | net/http/http_response_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698