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 <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 1824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1835 TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { | 1835 TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
1836 HttpRequestInfo request; | 1836 HttpRequestInfo request; |
1837 request.method = "GET"; | 1837 request.method = "GET"; |
1838 request.url = GURL("http://www.foo.com/"); | 1838 request.url = GURL("http://www.foo.com/"); |
1839 request.load_flags = 0; | 1839 request.load_flags = 0; |
1840 | 1840 |
1841 TestNetLog net_log; | 1841 TestNetLog net_log; |
1842 session_deps_.net_log = &net_log; | 1842 session_deps_.net_log = &net_log; |
1843 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 1843 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
1844 | 1844 |
1845 const char* request_data = | |
1846 "GET / HTTP/1.1\r\n" | |
1847 "Host: www.foo.com\r\n" | |
1848 "Connection: keep-alive\r\n\r\n"; | |
1849 MockWrite data_writes[] = { | |
1850 MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), | |
1851 MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), | |
1852 MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), | |
1853 MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), | |
1854 MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), | |
1855 }; | |
1856 | |
1845 // Note that because all these reads happen in the same | 1857 // Note that because all these reads happen in the same |
1846 // StaticSocketDataProvider, it shows that the same socket is being reused for | 1858 // StaticSocketDataProvider, it shows that the same socket is being reused for |
1847 // all transactions. | 1859 // all transactions. |
1848 MockRead data1_reads[] = { | 1860 MockRead data_reads[] = { |
1849 MockRead("HTTP/1.1 204 No Content\r\n\r\n"), | 1861 MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
1850 MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), | 1862 MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
1851 MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), | 1863 MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
1852 MockRead("HTTP/1.1 302 Found\r\n" | 1864 MockRead(ASYNC, 7, |
1853 "Content-Length: 0\r\n\r\n"), | 1865 "HTTP/1.1 302 Found\r\n" |
1854 MockRead("HTTP/1.1 302 Found\r\n" | 1866 "Content-Length: 0\r\n\r\n"), |
1855 "Content-Length: 5\r\n\r\n" | 1867 MockRead(ASYNC, 9, |
1856 "hello"), | 1868 "HTTP/1.1 302 Found\r\n" |
1857 MockRead("HTTP/1.1 301 Moved Permanently\r\n" | 1869 "Content-Length: 5\r\n\r\n" |
1858 "Content-Length: 0\r\n\r\n"), | 1870 "hello"), |
1859 MockRead("HTTP/1.1 301 Moved Permanently\r\n" | 1871 MockRead(ASYNC, 11, |
1860 "Content-Length: 5\r\n\r\n" | 1872 "HTTP/1.1 301 Moved Permanently\r\n" |
1861 "hello"), | 1873 "Content-Length: 0\r\n\r\n"), |
1862 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | 1874 MockRead(ASYNC, 13, |
1863 MockRead("hello"), | 1875 "HTTP/1.1 301 Moved Permanently\r\n" |
1876 "Content-Length: 5\r\n\r\n" | |
1877 "hello"), | |
1878 | |
1879 // In the next two rounds, IsConnectedAndIdle returns false, due to | |
1880 // the set_busy_before_sync_reads(true) call, while the | |
1881 // HttpNetworkTransaction is being shut down, but the socket is still | |
1882 // reuseable. See http://crbug.com/544255. | |
1883 MockRead(ASYNC, 15, | |
1884 "HTTP/1.1 200 Hunky-Dory\r\n" | |
1885 "Content-Length: 5\r\n\r\n"), | |
1886 MockRead(SYNCHRONOUS, 16, "hello"), | |
1887 | |
1888 MockRead(ASYNC, 18, | |
1889 "HTTP/1.1 200 Hunky-Dory\r\n" | |
1890 "Content-Length: 5\r\n\r\n" | |
1891 "he"), | |
1892 MockRead(SYNCHRONOUS, 19, "llo"), | |
1893 | |
1894 // The body of the final request is actually read. | |
1895 MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), | |
1896 MockRead(ASYNC, 22, "hello"), | |
1864 }; | 1897 }; |
1865 StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); | 1898 SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
1866 session_deps_.socket_factory->AddSocketDataProvider(&data1); | 1899 arraysize(data_writes)); |
1900 data.set_busy_before_sync_reads(true); | |
1901 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
1867 | 1902 |
1868 MockRead data2_reads[] = { | 1903 const int kNumUnreadBodies = arraysize(data_writes) - 1; |
1869 MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. | |
1870 }; | |
1871 StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); | |
1872 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
1873 | |
1874 const int kNumUnreadBodies = arraysize(data1_reads) - 2; | |
1875 std::string response_lines[kNumUnreadBodies]; | 1904 std::string response_lines[kNumUnreadBodies]; |
1876 | 1905 |
1877 uint32 first_socket_log_id = NetLog::Source::kInvalidId; | 1906 uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
1878 for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { | 1907 for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
1879 TestCompletionCallback callback; | 1908 TestCompletionCallback callback; |
1880 | 1909 |
1881 scoped_ptr<HttpTransaction> trans( | 1910 scoped_ptr<HttpTransaction> trans( |
1882 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 1911 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
1883 | 1912 |
1884 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 1913 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
1885 EXPECT_EQ(ERR_IO_PENDING, rv); | 1914 EXPECT_EQ(OK, callback.GetResult(rv)); |
1886 | |
1887 rv = callback.WaitForResult(); | |
1888 EXPECT_EQ(OK, rv); | |
1889 | 1915 |
1890 LoadTimingInfo load_timing_info; | 1916 LoadTimingInfo load_timing_info; |
1891 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); | 1917 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
1892 if (i == 0) { | 1918 if (i == 0) { |
1893 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 1919 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
1894 first_socket_log_id = load_timing_info.socket_log_id; | 1920 first_socket_log_id = load_timing_info.socket_log_id; |
1895 } else { | 1921 } else { |
1896 TestLoadTimingReused(load_timing_info); | 1922 TestLoadTimingReused(load_timing_info); |
1897 EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); | 1923 EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
1898 } | 1924 } |
1899 | 1925 |
1900 const HttpResponseInfo* response = trans->GetResponseInfo(); | 1926 const HttpResponseInfo* response = trans->GetResponseInfo(); |
1901 ASSERT_TRUE(response != NULL); | 1927 ASSERT_TRUE(response); |
1902 | 1928 |
1903 ASSERT_TRUE(response->headers.get() != NULL); | 1929 ASSERT_TRUE(response->headers); |
1904 response_lines[i] = response->headers->GetStatusLine(); | 1930 response_lines[i] = response->headers->GetStatusLine(); |
1905 | 1931 |
1906 // We intentionally don't read the response bodies. | 1932 // Delete the transaction without reading the response bodies. Then spin |
1933 // the message loop, so the response bodies are drained. | |
1934 trans.reset(); | |
1935 base::RunLoop().RunUntilIdle(); | |
1907 } | 1936 } |
1908 | 1937 |
1909 const char* const kStatusLines[] = { | 1938 const char* const kStatusLines[] = { |
1910 "HTTP/1.1 204 No Content", | 1939 "HTTP/1.1 204 No Content", |
1911 "HTTP/1.1 205 Reset Content", | 1940 "HTTP/1.1 205 Reset Content", |
1912 "HTTP/1.1 304 Not Modified", | 1941 "HTTP/1.1 304 Not Modified", |
1913 "HTTP/1.1 302 Found", | 1942 "HTTP/1.1 302 Found", |
1914 "HTTP/1.1 302 Found", | 1943 "HTTP/1.1 302 Found", |
1915 "HTTP/1.1 301 Moved Permanently", | 1944 "HTTP/1.1 301 Moved Permanently", |
1916 "HTTP/1.1 301 Moved Permanently", | 1945 "HTTP/1.1 301 Moved Permanently", |
1946 "HTTP/1.1 200 Hunky-Dory", | |
1947 "HTTP/1.1 200 Hunky-Dory", | |
1917 }; | 1948 }; |
1918 | 1949 |
1919 static_assert(kNumUnreadBodies == arraysize(kStatusLines), | 1950 static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
1920 "forgot to update kStatusLines"); | 1951 "forgot to update kStatusLines"); |
1921 | 1952 |
1922 for (int i = 0; i < kNumUnreadBodies; ++i) | 1953 for (int i = 0; i < kNumUnreadBodies; ++i) |
1923 EXPECT_EQ(kStatusLines[i], response_lines[i]); | 1954 EXPECT_EQ(kStatusLines[i], response_lines[i]); |
1924 | 1955 |
1925 TestCompletionCallback callback; | 1956 TestCompletionCallback callback; |
1926 scoped_ptr<HttpTransaction> trans( | 1957 scoped_ptr<HttpTransaction> trans( |
1927 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 1958 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
1928 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 1959 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
1929 EXPECT_EQ(ERR_IO_PENDING, rv); | 1960 EXPECT_EQ(OK, callback.GetResult(rv)); |
1930 rv = callback.WaitForResult(); | |
1931 EXPECT_EQ(OK, rv); | |
1932 const HttpResponseInfo* response = trans->GetResponseInfo(); | 1961 const HttpResponseInfo* response = trans->GetResponseInfo(); |
1933 ASSERT_TRUE(response != NULL); | 1962 ASSERT_TRUE(response); |
1934 ASSERT_TRUE(response->headers.get() != NULL); | 1963 ASSERT_TRUE(response->headers); |
1935 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 1964 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
1936 std::string response_data; | 1965 std::string response_data; |
1937 rv = ReadTransaction(trans.get(), &response_data); | 1966 rv = ReadTransaction(trans.get(), &response_data); |
1938 EXPECT_EQ(OK, rv); | 1967 EXPECT_EQ(OK, rv); |
1939 EXPECT_EQ("hello", response_data); | 1968 EXPECT_EQ("hello", response_data); |
1940 } | 1969 } |
1941 | 1970 |
1942 // Test the request-challenge-retry sequence for basic auth. | 1971 // Test the request-challenge-retry sequence for basic auth. |
1943 // (basic auth is the easiest to mock, because it has no randomness). | 1972 // (basic auth is the easiest to mock, because it has no randomness). |
1944 TEST_P(HttpNetworkTransactionTest, BasicAuth) { | 1973 TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2207 EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); | 2236 EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
2208 | 2237 |
2209 const HttpResponseInfo* response = trans->GetResponseInfo(); | 2238 const HttpResponseInfo* response = trans->GetResponseInfo(); |
2210 ASSERT_TRUE(response != NULL); | 2239 ASSERT_TRUE(response != NULL); |
2211 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 2240 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
2212 } | 2241 } |
2213 | 2242 |
2214 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | 2243 // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
2215 // connection. | 2244 // connection. |
2216 TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { | 2245 TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
2217 HttpRequestInfo request; | 2246 // On the second pass, the body read of the auth challenge is synchronous, so |
2218 request.method = "GET"; | 2247 // IsConnectedAndIdle returns false. The socket should still be drained and |
2219 request.url = GURL("http://www.example.org/"); | 2248 // reused. See http://crbug.com/544255. |
2220 request.load_flags = 0; | 2249 for (int i = 0; i < 2; ++i) { |
2250 HttpRequestInfo request; | |
2251 request.method = "GET"; | |
2252 request.url = GURL("http://www.example.org/"); | |
2253 request.load_flags = 0; | |
2221 | 2254 |
2222 TestNetLog log; | 2255 TestNetLog log; |
2223 session_deps_.net_log = &log; | 2256 session_deps_.net_log = &log; |
2224 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 2257 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
2225 | 2258 |
2226 MockWrite data_writes1[] = { | 2259 MockWrite data_writes[] = { |
2227 MockWrite( | 2260 MockWrite(ASYNC, 0, |
2228 "GET / HTTP/1.1\r\n" | 2261 "GET / HTTP/1.1\r\n" |
2229 "Host: www.example.org\r\n" | 2262 "Host: www.example.org\r\n" |
2230 "Connection: keep-alive\r\n\r\n"), | 2263 "Connection: keep-alive\r\n\r\n"), |
2231 | 2264 |
2232 // After calling trans->RestartWithAuth(), this is the request we should | 2265 // After calling trans->RestartWithAuth(), this is the request we should |
2233 // be issuing -- the final header line contains the credentials. | 2266 // be issuing -- the final header line contains the credentials. |
2234 MockWrite( | 2267 MockWrite(ASYNC, 6, |
2235 "GET / HTTP/1.1\r\n" | 2268 "GET / HTTP/1.1\r\n" |
2236 "Host: www.example.org\r\n" | 2269 "Host: www.example.org\r\n" |
2237 "Connection: keep-alive\r\n" | 2270 "Connection: keep-alive\r\n" |
2238 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | 2271 "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
2239 }; | 2272 }; |
2240 | 2273 |
2241 MockRead data_reads1[] = { | 2274 MockRead data_reads[] = { |
2242 MockRead("HTTP/1.1 401 Unauthorized\r\n"), | 2275 MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
2243 MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | 2276 MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
2244 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | 2277 MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
2245 MockRead("Content-Length: 14\r\n\r\n"), | 2278 MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
2246 MockRead("Unauthorized\r\n"), | 2279 MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
2247 | 2280 |
2248 // Lastly, the server responds with the actual content. | 2281 // Lastly, the server responds with the actual content. |
2249 MockRead("HTTP/1.1 200 OK\r\n"), | 2282 MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
2250 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), | 2283 MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
2251 MockRead("Content-Length: 5\r\n\r\n"), | 2284 MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
2252 MockRead("Hello"), | 2285 MockRead(ASYNC, 10, "Hello"), |
2253 }; | 2286 }; |
2254 | 2287 |
2255 // If there is a regression where we disconnect a Keep-Alive | 2288 SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
2256 // connection during an auth roundtrip, we'll end up reading this. | 2289 arraysize(data_writes)); |
2257 MockRead data_reads2[] = { | 2290 data.set_busy_before_sync_reads(true); |
2258 MockRead(SYNCHRONOUS, ERR_FAILED), | 2291 session_deps_.socket_factory->AddSocketDataProvider(&data); |
2259 }; | |
2260 | 2292 |
2261 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), | 2293 TestCompletionCallback callback1; |
2262 data_writes1, arraysize(data_writes1)); | |
2263 StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), | |
2264 NULL, 0); | |
2265 session_deps_.socket_factory->AddSocketDataProvider(&data1); | |
2266 session_deps_.socket_factory->AddSocketDataProvider(&data2); | |
2267 | 2294 |
2268 TestCompletionCallback callback1; | 2295 scoped_ptr<HttpTransaction> trans( |
2296 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
2297 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | |
2298 ASSERT_EQ(OK, callback1.GetResult(rv)); | |
2269 | 2299 |
2270 scoped_ptr<HttpTransaction> trans( | 2300 LoadTimingInfo load_timing_info1; |
2271 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 2301 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
2272 int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); | 2302 TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
2273 EXPECT_EQ(ERR_IO_PENDING, rv); | |
2274 | 2303 |
2275 rv = callback1.WaitForResult(); | 2304 const HttpResponseInfo* response = trans->GetResponseInfo(); |
2276 EXPECT_EQ(OK, rv); | 2305 ASSERT_TRUE(response); |
2306 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); | |
2277 | 2307 |
2278 LoadTimingInfo load_timing_info1; | 2308 TestCompletionCallback callback2; |
2279 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); | |
2280 TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); | |
2281 | 2309 |
2282 const HttpResponseInfo* response = trans->GetResponseInfo(); | 2310 rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
2283 ASSERT_TRUE(response != NULL); | 2311 callback2.callback()); |
2284 EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); | 2312 ASSERT_EQ(OK, callback2.GetResult(rv)); |
2285 | 2313 |
2286 TestCompletionCallback callback2; | 2314 LoadTimingInfo load_timing_info2; |
2315 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); | |
2316 TestLoadTimingReused(load_timing_info2); | |
2317 // The load timing after restart should have the same socket ID, and times | |
2318 // those of the first load timing. | |
2319 EXPECT_LE(load_timing_info1.receive_headers_end, | |
2320 load_timing_info2.send_start); | |
2321 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); | |
2287 | 2322 |
2288 rv = trans->RestartWithAuth( | 2323 response = trans->GetResponseInfo(); |
2289 AuthCredentials(kFoo, kBar), callback2.callback()); | 2324 ASSERT_TRUE(response); |
2290 EXPECT_EQ(ERR_IO_PENDING, rv); | 2325 EXPECT_FALSE(response->auth_challenge); |
2326 EXPECT_EQ(5, response->headers->GetContentLength()); | |
2291 | 2327 |
2292 rv = callback2.WaitForResult(); | 2328 std::string response_data; |
2293 EXPECT_EQ(OK, rv); | 2329 EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
2294 | 2330 |
2295 LoadTimingInfo load_timing_info2; | 2331 int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
2296 EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); | 2332 EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
2297 TestLoadTimingReused(load_timing_info2); | 2333 int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
2298 // The load timing after restart should have the same socket ID, and times | 2334 EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
2299 // those of the first load timing. | 2335 } |
2300 EXPECT_LE(load_timing_info1.receive_headers_end, | |
2301 load_timing_info2.send_start); | |
2302 EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); | |
2303 | |
2304 response = trans->GetResponseInfo(); | |
2305 ASSERT_TRUE(response != NULL); | |
2306 EXPECT_TRUE(response->auth_challenge.get() == NULL); | |
2307 EXPECT_EQ(5, response->headers->GetContentLength()); | |
2308 | |
2309 std::string response_data; | |
2310 rv = ReadTransaction(trans.get(), &response_data); | |
2311 EXPECT_EQ(OK, rv); | |
2312 | |
2313 int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); | |
2314 EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); | |
2315 int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); | |
2316 EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); | |
2317 } | 2336 } |
2318 | 2337 |
2319 // Test the request-challenge-retry sequence for basic auth, over a keep-alive | 2338 // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
2320 // connection and with no response body to drain. | 2339 // connection and with no response body to drain. |
2321 TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { | 2340 TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
2322 HttpRequestInfo request; | 2341 HttpRequestInfo request; |
2323 request.method = "GET"; | 2342 request.method = "GET"; |
2324 request.url = GURL("http://www.example.org/"); | 2343 request.url = GURL("http://www.example.org/"); |
2325 request.load_flags = 0; | 2344 request.load_flags = 0; |
2326 | 2345 |
(...skipping 3547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5874 "GET / HTTP/1.1\r\n" | 5893 "GET / HTTP/1.1\r\n" |
5875 "Host: www.example.org\r\n" | 5894 "Host: www.example.org\r\n" |
5876 "Connection: keep-alive\r\n\r\n"), | 5895 "Connection: keep-alive\r\n\r\n"), |
5877 MockWrite( | 5896 MockWrite( |
5878 "GET / HTTP/1.1\r\n" | 5897 "GET / HTTP/1.1\r\n" |
5879 "Host: www.example.org\r\n" | 5898 "Host: www.example.org\r\n" |
5880 "Connection: keep-alive\r\n\r\n"), | 5899 "Connection: keep-alive\r\n\r\n"), |
5881 }; | 5900 }; |
5882 | 5901 |
5883 MockRead data_reads[] = { | 5902 MockRead data_reads[] = { |
5884 MockRead("HTTP/1.1 200 OK\r\n"), | 5903 MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
5885 MockRead("Content-Length: 11\r\n\r\n"), | 5904 MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED) // EOF |
mmenke
2015/12/03 16:15:34
Note that this test depended on MockSSLWhateverSoc
| |
5886 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | |
5887 MockRead("hello world"), | |
5888 MockRead(ASYNC, 0, 0) // EOF | |
5889 }; | 5905 }; |
5890 | 5906 |
5891 SSLSocketDataProvider ssl(ASYNC, OK); | 5907 SSLSocketDataProvider ssl(ASYNC, OK); |
5892 SSLSocketDataProvider ssl2(ASYNC, OK); | 5908 SSLSocketDataProvider ssl2(ASYNC, OK); |
5893 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 5909 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
5894 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); | 5910 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
5895 | 5911 |
5896 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | 5912 StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
5897 data_writes, arraysize(data_writes)); | 5913 data_writes, arraysize(data_writes)); |
5898 StaticSocketDataProvider data2(data_reads, arraysize(data_reads), | 5914 StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5965 request.method = "GET"; | 5981 request.method = "GET"; |
5966 request.url = GURL( | 5982 request.url = GURL( |
5967 "http://www.example.org/csi?v=3&s=web&action=&" | 5983 "http://www.example.org/csi?v=3&s=web&action=&" |
5968 "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" | 5984 "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
5969 "e=17259,18167,19592,19773,19981,20133,20173,20233&" | 5985 "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
5970 "rt=prt.2642,ol.2649,xjs.2951"); | 5986 "rt=prt.2642,ol.2649,xjs.2951"); |
5971 request.load_flags = 0; | 5987 request.load_flags = 0; |
5972 | 5988 |
5973 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 5989 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
5974 | 5990 |
5975 scoped_ptr<HttpTransaction> trans( | |
5976 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
5977 | |
5978 MockRead data_reads[] = { | 5991 MockRead data_reads[] = { |
5979 MockRead("HTTP/1.1 204 No Content\r\n" | 5992 MockRead("HTTP/1.1 204 No Content\r\n" |
5980 "Content-Length: 0\r\n" | 5993 "Content-Length: 0\r\n" |
5981 "Content-Type: text/html\r\n\r\n"), | 5994 "Content-Type: text/html\r\n\r\n"), |
5982 MockRead("junk"), // Should not be read!! | 5995 MockRead("junk"), // Should not be read!! |
5983 MockRead(SYNCHRONOUS, OK), | 5996 MockRead(SYNCHRONOUS, OK), |
5984 }; | 5997 }; |
5985 | 5998 |
5986 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); | 5999 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
5987 session_deps_.socket_factory->AddSocketDataProvider(&data); | 6000 session_deps_.socket_factory->AddSocketDataProvider(&data); |
5988 | 6001 |
6002 // Transaction must be created after the MockReads, so it's destroyed before | |
6003 // them. | |
6004 scoped_ptr<HttpTransaction> trans( | |
6005 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | |
6006 | |
5989 TestCompletionCallback callback; | 6007 TestCompletionCallback callback; |
5990 | 6008 |
5991 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 6009 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
5992 EXPECT_EQ(ERR_IO_PENDING, rv); | 6010 EXPECT_EQ(ERR_IO_PENDING, rv); |
5993 | 6011 |
5994 rv = callback.WaitForResult(); | 6012 rv = callback.WaitForResult(); |
5995 EXPECT_EQ(OK, rv); | 6013 EXPECT_EQ(OK, rv); |
5996 | 6014 |
5997 const HttpResponseInfo* response = trans->GetResponseInfo(); | 6015 const HttpResponseInfo* response = trans->GetResponseInfo(); |
5998 ASSERT_TRUE(response != NULL); | 6016 ASSERT_TRUE(response != NULL); |
(...skipping 5149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11148 } else { | 11166 } else { |
11149 session_deps_.proxy_service = ProxyService::CreateDirect(); | 11167 session_deps_.proxy_service = ProxyService::CreateDirect(); |
11150 } | 11168 } |
11151 | 11169 |
11152 HttpRequestInfo request; | 11170 HttpRequestInfo request; |
11153 request.method = "GET"; | 11171 request.method = "GET"; |
11154 request.url = GURL(test_config.server_url); | 11172 request.url = GURL(test_config.server_url); |
11155 request.load_flags = 0; | 11173 request.load_flags = 0; |
11156 | 11174 |
11157 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 11175 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
11158 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); | |
11159 | 11176 |
11160 SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); | 11177 SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
11161 | 11178 |
11162 std::vector<std::vector<MockRead>> mock_reads(1); | 11179 std::vector<std::vector<MockRead>> mock_reads(1); |
11163 std::vector<std::vector<MockWrite>> mock_writes(1); | 11180 std::vector<std::vector<MockWrite>> mock_writes(1); |
11164 for (int round = 0; round < test_config.num_auth_rounds; ++round) { | 11181 for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
11165 const TestRound& read_write_round = test_config.rounds[round]; | 11182 const TestRound& read_write_round = test_config.rounds[round]; |
11166 | 11183 |
11167 // Set up expected reads and writes. | 11184 // Set up expected reads and writes. |
11168 mock_reads.back().push_back(read_write_round.read); | 11185 mock_reads.back().push_back(read_write_round.read); |
(...skipping 21 matching lines...) Expand all Loading... | |
11190 | 11207 |
11191 ScopedVector<StaticSocketDataProvider> data_providers; | 11208 ScopedVector<StaticSocketDataProvider> data_providers; |
11192 for (size_t i = 0; i < mock_reads.size(); ++i) { | 11209 for (size_t i = 0; i < mock_reads.size(); ++i) { |
11193 data_providers.push_back(new StaticSocketDataProvider( | 11210 data_providers.push_back(new StaticSocketDataProvider( |
11194 mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), | 11211 mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
11195 mock_writes[i].size())); | 11212 mock_writes[i].size())); |
11196 session_deps_.socket_factory->AddSocketDataProvider( | 11213 session_deps_.socket_factory->AddSocketDataProvider( |
11197 data_providers.back()); | 11214 data_providers.back()); |
11198 } | 11215 } |
11199 | 11216 |
11217 // Transaction must be created after DataProviders, so it's destroyed before | |
11218 // they are as well. | |
11219 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); | |
11220 | |
11200 for (int round = 0; round < test_config.num_auth_rounds; ++round) { | 11221 for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
11201 const TestRound& read_write_round = test_config.rounds[round]; | 11222 const TestRound& read_write_round = test_config.rounds[round]; |
11202 // Start or restart the transaction. | 11223 // Start or restart the transaction. |
11203 TestCompletionCallback callback; | 11224 TestCompletionCallback callback; |
11204 int rv; | 11225 int rv; |
11205 if (round == 0) { | 11226 if (round == 0) { |
11206 rv = trans.Start(&request, callback.callback(), BoundNetLog()); | 11227 rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
11207 } else { | 11228 } else { |
11208 rv = trans.RestartWithAuth( | 11229 rv = trans.RestartWithAuth( |
11209 AuthCredentials(kFoo, kBar), callback.callback()); | 11230 AuthCredentials(kFoo, kBar), callback.callback()); |
(...skipping 4287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
15497 | 15518 |
15498 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 15519 scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
15499 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); | 15520 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
15500 | 15521 |
15501 EXPECT_THAT(trans.server_ssl_config_.alpn_protos, | 15522 EXPECT_THAT(trans.server_ssl_config_.alpn_protos, |
15502 testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); | 15523 testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
15503 EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty()); | 15524 EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty()); |
15504 } | 15525 } |
15505 | 15526 |
15506 } // namespace net | 15527 } // namespace net |
OLD | NEW |