OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdarg.h> | 8 #include <stdarg.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 9200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9211 ASSERT_TRUE(response->headers.get() != NULL); | 9211 ASSERT_TRUE(response->headers.get() != NULL); |
9212 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 9212 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
9213 | 9213 |
9214 std::string response_data; | 9214 std::string response_data; |
9215 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 9215 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
9216 EXPECT_EQ("hello world", response_data); | 9216 EXPECT_EQ("hello world", response_data); |
9217 | 9217 |
9218 // Set up an initial SpdySession in the pool to reuse. | 9218 // Set up an initial SpdySession in the pool to reuse. |
9219 HostPortPair host_port_pair("www.google.com", 443); | 9219 HostPortPair host_port_pair("www.google.com", 443); |
9220 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 9220 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
9221 PRIVACY_MODE_DISABLED); | 9221 kPrivacyModeDisabled); |
9222 base::WeakPtr<SpdySession> spdy_session = | 9222 base::WeakPtr<SpdySession> spdy_session = |
9223 CreateSecureSpdySession(session, key, BoundNetLog()); | 9223 CreateSecureSpdySession(session, key, BoundNetLog()); |
9224 | 9224 |
9225 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 9225 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
9226 | 9226 |
9227 rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 9227 rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
9228 EXPECT_EQ(ERR_IO_PENDING, rv); | 9228 EXPECT_EQ(ERR_IO_PENDING, rv); |
9229 EXPECT_EQ(OK, callback.WaitForResult()); | 9229 EXPECT_EQ(OK, callback.WaitForResult()); |
9230 | 9230 |
9231 response = trans->GetResponseInfo(); | 9231 response = trans->GetResponseInfo(); |
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10370 | 10370 |
10371 SSLSocketDataProvider ssl(ASYNC, OK); | 10371 SSLSocketDataProvider ssl(ASYNC, OK); |
10372 ssl.SetNextProto(GetParam()); | 10372 ssl.SetNextProto(GetParam()); |
10373 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 10373 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
10374 | 10374 |
10375 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 10375 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
10376 | 10376 |
10377 // Set up an initial SpdySession in the pool to reuse. | 10377 // Set up an initial SpdySession in the pool to reuse. |
10378 HostPortPair host_port_pair("www.google.com", 443); | 10378 HostPortPair host_port_pair("www.google.com", 443); |
10379 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 10379 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
10380 PRIVACY_MODE_DISABLED); | 10380 kPrivacyModeDisabled); |
10381 base::WeakPtr<SpdySession> spdy_session = | 10381 base::WeakPtr<SpdySession> spdy_session = |
10382 CreateInsecureSpdySession(session, key, BoundNetLog()); | 10382 CreateInsecureSpdySession(session, key, BoundNetLog()); |
10383 | 10383 |
10384 HttpRequestInfo request; | 10384 HttpRequestInfo request; |
10385 request.method = "GET"; | 10385 request.method = "GET"; |
10386 request.url = GURL("https://www.google.com/"); | 10386 request.url = GURL("https://www.google.com/"); |
10387 request.load_flags = 0; | 10387 request.load_flags = 0; |
10388 | 10388 |
10389 // This is the important line that marks this as a preconnect. | 10389 // This is the important line that marks this as a preconnect. |
10390 request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; | 10390 request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11728 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | 11728 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
11729 MockRead("Content-Length: 6\r\n\r\n"), | 11729 MockRead("Content-Length: 6\r\n\r\n"), |
11730 MockRead("hello!"), | 11730 MockRead("hello!"), |
11731 }; | 11731 }; |
11732 StaticSocketDataProvider http_data(http_read, arraysize(http_read), | 11732 StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
11733 http_write, arraysize(http_write)); | 11733 http_write, arraysize(http_write)); |
11734 session_deps_.socket_factory->AddSocketDataProvider(&http_data); | 11734 session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
11735 | 11735 |
11736 HostPortPair host_port_pair_a("www.a.com", 443); | 11736 HostPortPair host_port_pair_a("www.a.com", 443); |
11737 SpdySessionKey spdy_session_key_a( | 11737 SpdySessionKey spdy_session_key_a( |
11738 host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); | 11738 host_port_pair_a, ProxyServer::Direct(), kPrivacyModeDisabled); |
11739 EXPECT_FALSE( | 11739 EXPECT_FALSE( |
11740 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); | 11740 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
11741 | 11741 |
11742 TestCompletionCallback callback; | 11742 TestCompletionCallback callback; |
11743 HttpRequestInfo request1; | 11743 HttpRequestInfo request1; |
11744 request1.method = "GET"; | 11744 request1.method = "GET"; |
11745 request1.url = GURL("https://www.a.com/"); | 11745 request1.url = GURL("https://www.a.com/"); |
11746 request1.load_flags = 0; | 11746 request1.load_flags = 0; |
11747 scoped_ptr<HttpNetworkTransaction> trans( | 11747 scoped_ptr<HttpNetworkTransaction> trans( |
11748 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 11748 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
(...skipping 11 matching lines...) Expand all Loading... |
11760 | 11760 |
11761 std::string response_data; | 11761 std::string response_data; |
11762 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 11762 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
11763 EXPECT_EQ("hello!", response_data); | 11763 EXPECT_EQ("hello!", response_data); |
11764 trans.reset(); | 11764 trans.reset(); |
11765 EXPECT_TRUE( | 11765 EXPECT_TRUE( |
11766 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); | 11766 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
11767 | 11767 |
11768 HostPortPair host_port_pair_b("www.b.com", 443); | 11768 HostPortPair host_port_pair_b("www.b.com", 443); |
11769 SpdySessionKey spdy_session_key_b( | 11769 SpdySessionKey spdy_session_key_b( |
11770 host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); | 11770 host_port_pair_b, ProxyServer::Direct(), kPrivacyModeDisabled); |
11771 EXPECT_FALSE( | 11771 EXPECT_FALSE( |
11772 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); | 11772 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
11773 HttpRequestInfo request2; | 11773 HttpRequestInfo request2; |
11774 request2.method = "GET"; | 11774 request2.method = "GET"; |
11775 request2.url = GURL("https://www.b.com/"); | 11775 request2.url = GURL("https://www.b.com/"); |
11776 request2.load_flags = 0; | 11776 request2.load_flags = 0; |
11777 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 11777 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
11778 | 11778 |
11779 rv = trans->Start(&request2, callback.callback(), BoundNetLog()); | 11779 rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
11780 EXPECT_EQ(ERR_IO_PENDING, rv); | 11780 EXPECT_EQ(ERR_IO_PENDING, rv); |
11781 EXPECT_EQ(OK, callback.WaitForResult()); | 11781 EXPECT_EQ(OK, callback.WaitForResult()); |
11782 | 11782 |
11783 response = trans->GetResponseInfo(); | 11783 response = trans->GetResponseInfo(); |
11784 ASSERT_TRUE(response != NULL); | 11784 ASSERT_TRUE(response != NULL); |
11785 ASSERT_TRUE(response->headers.get() != NULL); | 11785 ASSERT_TRUE(response->headers.get() != NULL); |
11786 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 11786 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
11787 EXPECT_TRUE(response->was_fetched_via_spdy); | 11787 EXPECT_TRUE(response->was_fetched_via_spdy); |
11788 EXPECT_TRUE(response->was_npn_negotiated); | 11788 EXPECT_TRUE(response->was_npn_negotiated); |
11789 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 11789 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
11790 EXPECT_EQ("hello!", response_data); | 11790 EXPECT_EQ("hello!", response_data); |
11791 EXPECT_FALSE( | 11791 EXPECT_FALSE( |
11792 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); | 11792 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
11793 EXPECT_TRUE( | 11793 EXPECT_TRUE( |
11794 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); | 11794 HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
11795 | 11795 |
11796 HostPortPair host_port_pair_a1("www.a.com", 80); | 11796 HostPortPair host_port_pair_a1("www.a.com", 80); |
11797 SpdySessionKey spdy_session_key_a1( | 11797 SpdySessionKey spdy_session_key_a1( |
11798 host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); | 11798 host_port_pair_a1, ProxyServer::Direct(), kPrivacyModeDisabled); |
11799 EXPECT_FALSE( | 11799 EXPECT_FALSE( |
11800 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); | 11800 HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
11801 HttpRequestInfo request3; | 11801 HttpRequestInfo request3; |
11802 request3.method = "GET"; | 11802 request3.method = "GET"; |
11803 request3.url = GURL("http://www.a.com/"); | 11803 request3.url = GURL("http://www.a.com/"); |
11804 request3.load_flags = 0; | 11804 request3.load_flags = 0; |
11805 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 11805 trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
11806 | 11806 |
11807 rv = trans->Start(&request3, callback.callback(), BoundNetLog()); | 11807 rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
11808 EXPECT_EQ(ERR_IO_PENDING, rv); | 11808 EXPECT_EQ(ERR_IO_PENDING, rv); |
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12607 // established, to let the HTTP request start. | 12607 // established, to let the HTTP request start. |
12608 ASSERT_EQ(OK, http_callback.WaitForResult()); | 12608 ASSERT_EQ(OK, http_callback.WaitForResult()); |
12609 std::string response_data; | 12609 std::string response_data; |
12610 ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); | 12610 ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
12611 EXPECT_EQ("falafel", response_data); | 12611 EXPECT_EQ("falafel", response_data); |
12612 | 12612 |
12613 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session)); | 12613 EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session)); |
12614 } | 12614 } |
12615 | 12615 |
12616 } // namespace net | 12616 } // namespace net |
OLD | NEW |