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

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

Issue 4118004: Update NetLog to be thread safe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Final sync with trunk Created 10 years 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_cache_unittest.cc ('k') | net/net.gyp » ('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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 return out; 167 return out;
168 168
169 const HttpResponseInfo* response = trans->GetResponseInfo(); 169 const HttpResponseInfo* response = trans->GetResponseInfo();
170 EXPECT_TRUE(response != NULL); 170 EXPECT_TRUE(response != NULL);
171 171
172 EXPECT_TRUE(response->headers != NULL); 172 EXPECT_TRUE(response->headers != NULL);
173 out.status_line = response->headers->GetStatusLine(); 173 out.status_line = response->headers->GetStatusLine();
174 174
175 rv = ReadTransaction(trans.get(), &out.response_data); 175 rv = ReadTransaction(trans.get(), &out.response_data);
176 EXPECT_EQ(OK, rv); 176 EXPECT_EQ(OK, rv);
177
178 net::CapturingNetLog::EntryList entries;
179 log.GetEntries(&entries);
177 size_t pos = ExpectLogContainsSomewhere( 180 size_t pos = ExpectLogContainsSomewhere(
178 log.entries(), 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, 181 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS,
179 NetLog::PHASE_NONE); 182 NetLog::PHASE_NONE);
180 ExpectLogContainsSomewhere( 183 ExpectLogContainsSomewhere(
181 log.entries(), pos, 184 entries, pos,
182 NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, 185 NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS,
183 NetLog::PHASE_NONE); 186 NetLog::PHASE_NONE);
184 187
185 CapturingNetLog::Entry entry = log.entries()[pos]; 188 CapturingNetLog::Entry entry = entries[pos];
186 NetLogHttpRequestParameter* request_params = 189 NetLogHttpRequestParameter* request_params =
187 static_cast<NetLogHttpRequestParameter*>(entry.extra_parameters.get()); 190 static_cast<NetLogHttpRequestParameter*>(entry.extra_parameters.get());
188 EXPECT_EQ("GET / HTTP/1.1\r\n", request_params->GetLine()); 191 EXPECT_EQ("GET / HTTP/1.1\r\n", request_params->GetLine());
189 EXPECT_EQ("Host: www.google.com\r\n" 192 EXPECT_EQ("Host: www.google.com\r\n"
190 "Connection: keep-alive\r\n\r\n", 193 "Connection: keep-alive\r\n\r\n",
191 request_params->GetHeaders().ToString()); 194 request_params->GetHeaders().ToString());
192 195
193 return out; 196 return out;
194 } 197 }
195 198
(...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 1521
1519 TestCompletionCallback callback1; 1522 TestCompletionCallback callback1;
1520 1523
1521 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 1524 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
1522 1525
1523 int rv = trans->Start(&request, &callback1, log.bound()); 1526 int rv = trans->Start(&request, &callback1, log.bound());
1524 EXPECT_EQ(ERR_IO_PENDING, rv); 1527 EXPECT_EQ(ERR_IO_PENDING, rv);
1525 1528
1526 rv = callback1.WaitForResult(); 1529 rv = callback1.WaitForResult();
1527 EXPECT_EQ(OK, rv); 1530 EXPECT_EQ(OK, rv);
1531 net::CapturingNetLog::EntryList entries;
1532 log.GetEntries(&entries);
1528 size_t pos = ExpectLogContainsSomewhere( 1533 size_t pos = ExpectLogContainsSomewhere(
1529 log.entries(), 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, 1534 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
1530 NetLog::PHASE_NONE); 1535 NetLog::PHASE_NONE);
1531 ExpectLogContainsSomewhere( 1536 ExpectLogContainsSomewhere(
1532 log.entries(), pos, 1537 entries, pos,
1533 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, 1538 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
1534 NetLog::PHASE_NONE); 1539 NetLog::PHASE_NONE);
1535 1540
1536 const HttpResponseInfo* response = trans->GetResponseInfo(); 1541 const HttpResponseInfo* response = trans->GetResponseInfo();
1537 ASSERT_FALSE(response == NULL); 1542 ASSERT_FALSE(response == NULL);
1538 1543
1539 EXPECT_EQ(407, response->headers->response_code()); 1544 EXPECT_EQ(407, response->headers->response_code());
1540 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); 1545 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
1541 1546
1542 // The password prompt info should have been set in response->auth_challenge. 1547 // The password prompt info should have been set in response->auth_challenge.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1622 data_writes1, arraysize(data_writes1)); 1627 data_writes1, arraysize(data_writes1));
1623 session_deps.socket_factory.AddSocketDataProvider(&data1); 1628 session_deps.socket_factory.AddSocketDataProvider(&data1);
1624 1629
1625 TestCompletionCallback callback1; 1630 TestCompletionCallback callback1;
1626 1631
1627 int rv = trans->Start(&request, &callback1, log.bound()); 1632 int rv = trans->Start(&request, &callback1, log.bound());
1628 EXPECT_EQ(ERR_IO_PENDING, rv); 1633 EXPECT_EQ(ERR_IO_PENDING, rv);
1629 1634
1630 rv = callback1.WaitForResult(); 1635 rv = callback1.WaitForResult();
1631 EXPECT_EQ(OK, rv); 1636 EXPECT_EQ(OK, rv);
1637 net::CapturingNetLog::EntryList entries;
1638 log.GetEntries(&entries);
1632 size_t pos = ExpectLogContainsSomewhere( 1639 size_t pos = ExpectLogContainsSomewhere(
1633 log.entries(), 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, 1640 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
1634 NetLog::PHASE_NONE); 1641 NetLog::PHASE_NONE);
1635 ExpectLogContainsSomewhere( 1642 ExpectLogContainsSomewhere(
1636 log.entries(), pos, 1643 entries, pos,
1637 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, 1644 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
1638 NetLog::PHASE_NONE); 1645 NetLog::PHASE_NONE);
1639 1646
1640 const HttpResponseInfo* response = trans->GetResponseInfo(); 1647 const HttpResponseInfo* response = trans->GetResponseInfo();
1641 EXPECT_FALSE(response == NULL); 1648 EXPECT_FALSE(response == NULL);
1642 1649
1643 EXPECT_TRUE(response->headers->IsKeepAlive()); 1650 EXPECT_TRUE(response->headers->IsKeepAlive());
1644 EXPECT_EQ(407, response->headers->response_code()); 1651 EXPECT_EQ(407, response->headers->response_code());
1645 EXPECT_EQ(10, response->headers->GetContentLength()); 1652 EXPECT_EQ(10, response->headers->GetContentLength());
1646 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); 1653 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1824 1831
1825 TestCompletionCallback callback1; 1832 TestCompletionCallback callback1;
1826 1833
1827 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 1834 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
1828 1835
1829 int rv = trans->Start(&request, &callback1, log.bound()); 1836 int rv = trans->Start(&request, &callback1, log.bound());
1830 EXPECT_EQ(ERR_IO_PENDING, rv); 1837 EXPECT_EQ(ERR_IO_PENDING, rv);
1831 1838
1832 rv = callback1.WaitForResult(); 1839 rv = callback1.WaitForResult();
1833 EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); 1840 EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv);
1841 net::CapturingNetLog::EntryList entries;
1842 log.GetEntries(&entries);
1834 size_t pos = ExpectLogContainsSomewhere( 1843 size_t pos = ExpectLogContainsSomewhere(
1835 log.entries(), 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, 1844 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
1836 NetLog::PHASE_NONE); 1845 NetLog::PHASE_NONE);
1837 ExpectLogContainsSomewhere( 1846 ExpectLogContainsSomewhere(
1838 log.entries(), pos, 1847 entries, pos,
1839 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, 1848 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
1840 NetLog::PHASE_NONE); 1849 NetLog::PHASE_NONE);
1841 } 1850 }
1842 1851
1843 // Test a simple get through an HTTPS Proxy. 1852 // Test a simple get through an HTTPS Proxy.
1844 TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { 1853 TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) {
1845 // Configure against https proxy server "proxy:70". 1854 // Configure against https proxy server "proxy:70".
1846 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); 1855 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") );
1847 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 1856 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1848 session_deps.net_log = log.bound().net_log(); 1857 session_deps.net_log = log.bound().net_log();
(...skipping 5868 matching lines...) Expand 10 before | Expand all | Expand 10 after
7717 7726
7718 TestCompletionCallback callback1; 7727 TestCompletionCallback callback1;
7719 7728
7720 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 7729 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
7721 7730
7722 int rv = trans->Start(&request, &callback1, log.bound()); 7731 int rv = trans->Start(&request, &callback1, log.bound());
7723 EXPECT_EQ(ERR_IO_PENDING, rv); 7732 EXPECT_EQ(ERR_IO_PENDING, rv);
7724 7733
7725 rv = callback1.WaitForResult(); 7734 rv = callback1.WaitForResult();
7726 EXPECT_EQ(OK, rv); 7735 EXPECT_EQ(OK, rv);
7736 net::CapturingNetLog::EntryList entries;
7737 log.GetEntries(&entries);
7727 size_t pos = ExpectLogContainsSomewhere( 7738 size_t pos = ExpectLogContainsSomewhere(
7728 log.entries(), 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, 7739 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
7729 NetLog::PHASE_NONE); 7740 NetLog::PHASE_NONE);
7730 ExpectLogContainsSomewhere( 7741 ExpectLogContainsSomewhere(
7731 log.entries(), pos, 7742 entries, pos,
7732 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, 7743 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
7733 NetLog::PHASE_NONE); 7744 NetLog::PHASE_NONE);
7734 7745
7735 const HttpResponseInfo* response = trans->GetResponseInfo(); 7746 const HttpResponseInfo* response = trans->GetResponseInfo();
7736 ASSERT_FALSE(response == NULL); 7747 ASSERT_FALSE(response == NULL);
7737 7748
7738 EXPECT_TRUE(response->headers->IsKeepAlive()); 7749 EXPECT_TRUE(response->headers->IsKeepAlive());
7739 EXPECT_EQ(200, response->headers->response_code()); 7750 EXPECT_EQ(200, response->headers->response_code());
7740 EXPECT_EQ(100, response->headers->GetContentLength()); 7751 EXPECT_EQ(100, response->headers->GetContentLength());
7741 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); 7752 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
7779 7790
7780 TestCompletionCallback callback1; 7791 TestCompletionCallback callback1;
7781 7792
7782 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 7793 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
7783 7794
7784 int rv = trans->Start(&request, &callback1, log.bound()); 7795 int rv = trans->Start(&request, &callback1, log.bound());
7785 EXPECT_EQ(ERR_IO_PENDING, rv); 7796 EXPECT_EQ(ERR_IO_PENDING, rv);
7786 7797
7787 rv = callback1.WaitForResult(); 7798 rv = callback1.WaitForResult();
7788 EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); 7799 EXPECT_EQ(ERR_EMPTY_RESPONSE, rv);
7800 net::CapturingNetLog::EntryList entries;
7801 log.GetEntries(&entries);
7789 size_t pos = ExpectLogContainsSomewhere( 7802 size_t pos = ExpectLogContainsSomewhere(
7790 log.entries(), 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, 7803 entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
7791 NetLog::PHASE_NONE); 7804 NetLog::PHASE_NONE);
7792 ExpectLogContainsSomewhere( 7805 ExpectLogContainsSomewhere(
7793 log.entries(), pos, 7806 entries, pos,
7794 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, 7807 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
7795 NetLog::PHASE_NONE); 7808 NetLog::PHASE_NONE);
7796 } 7809 }
7797 7810
7798 // Test for crbug.com/55424. 7811 // Test for crbug.com/55424.
7799 TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { 7812 TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) {
7800 SessionDependencies session_deps; 7813 SessionDependencies session_deps;
7801 7814
7802 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet( 7815 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(
7803 "https://www.google.com", false, 1, LOWEST)); 7816 "https://www.google.com", false, 1, LOWEST));
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
7945 rv = callback.WaitForResult(); 7958 rv = callback.WaitForResult();
7946 ASSERT_EQ(OK, rv); 7959 ASSERT_EQ(OK, rv);
7947 7960
7948 std::string contents; 7961 std::string contents;
7949 rv = ReadTransaction(trans.get(), &contents); 7962 rv = ReadTransaction(trans.get(), &contents);
7950 EXPECT_EQ(net::OK, rv); 7963 EXPECT_EQ(net::OK, rv);
7951 EXPECT_EQ("hello world", contents); 7964 EXPECT_EQ("hello world", contents);
7952 } 7965 }
7953 7966
7954 } // namespace net 7967 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_cache_unittest.cc ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698