OLD | NEW |
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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "net/base/net_log_unittest.h" | 8 #include "net/base/net_log_unittest.h" |
9 #include "net/http/http_stream_handle.h" | 9 #include "net/http/http_stream_handle.h" |
10 #include "net/http/http_transaction_unittest.h" | 10 #include "net/http/http_transaction_unittest.h" |
11 #include "net/spdy/spdy_http_stream.h" | 11 #include "net/spdy/spdy_http_stream.h" |
12 #include "net/spdy/spdy_session.h" | 12 #include "net/spdy/spdy_session.h" |
| 13 #include "net/spdy/spdy_session_pool.h" |
13 #include "net/spdy/spdy_test_util.h" | 14 #include "net/spdy/spdy_test_util.h" |
14 #include "net/url_request/url_request_unittest.h" | 15 #include "net/url_request/url_request_unittest.h" |
15 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
16 | 17 |
17 //----------------------------------------------------------------------------- | 18 //----------------------------------------------------------------------------- |
18 | 19 |
19 namespace net { | 20 namespace net { |
20 | 21 |
21 // This is the expected list of advertised protocols from the browser's NPN | 22 // This is the expected list of advertised protocols from the browser's NPN |
22 // list. | 23 // list. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 port_ = 80; | 76 port_ = 80; |
76 break; | 77 break; |
77 case SPDYNPN: | 78 case SPDYNPN: |
78 port_ = 443; | 79 port_ = 443; |
79 break; | 80 break; |
80 default: | 81 default: |
81 NOTREACHED(); | 82 NOTREACHED(); |
82 } | 83 } |
83 } | 84 } |
84 | 85 |
| 86 ~NormalSpdyTransactionHelper() { |
| 87 // Any test which doesn't close the socket by sending it an EOF will |
| 88 // have a valid session left open, which leaks the entire session pool. |
| 89 // This is just fine - in fact, some of our tests intentionally do this |
| 90 // so that we can check consistency of the SpdySessionPool as the test |
| 91 // finishes. If we had put an EOF on the socket, the SpdySession would |
| 92 // have closed and we wouldn't be able to check the consistency. |
| 93 |
| 94 // Forcefully close existing sessions here. |
| 95 session()->spdy_session_pool()->CloseAllSessions(); |
| 96 } |
| 97 |
85 void SetDeterministic() { | 98 void SetDeterministic() { |
86 session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic( | 99 session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic( |
87 session_deps_.get()); | 100 session_deps_.get()); |
88 deterministic_ = true; | 101 deterministic_ = true; |
89 } | 102 } |
90 | 103 |
91 void RunPreTestSetup() { | 104 void RunPreTestSetup() { |
92 if (!session_deps_.get()) | 105 if (!session_deps_.get()) |
93 session_deps_.reset(new SpdySessionDependencies()); | 106 session_deps_.reset(new SpdySessionDependencies()); |
94 if (!session_.get()) | 107 if (!session_.get()) |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 DCHECK(deterministic_); | 253 DCHECK(deterministic_); |
241 session_deps_->deterministic_socket_factory->AddSocketDataProvider(data); | 254 session_deps_->deterministic_socket_factory->AddSocketDataProvider(data); |
242 } | 255 } |
243 | 256 |
244 void SetSession(const scoped_refptr<HttpNetworkSession>& session) { | 257 void SetSession(const scoped_refptr<HttpNetworkSession>& session) { |
245 session_ = session; | 258 session_ = session; |
246 } | 259 } |
247 HttpNetworkTransaction* trans() { return trans_.get(); } | 260 HttpNetworkTransaction* trans() { return trans_.get(); } |
248 void ResetTrans() { trans_.reset(); } | 261 void ResetTrans() { trans_.reset(); } |
249 TransactionHelperResult& output() { return output_; } | 262 TransactionHelperResult& output() { return output_; } |
250 HttpRequestInfo& request() { return request_; } | 263 const HttpRequestInfo& request() const { return request_; } |
251 scoped_refptr<HttpNetworkSession>& session() { return session_; } | 264 const scoped_refptr<HttpNetworkSession>& session() const { |
| 265 return session_; |
| 266 } |
252 scoped_ptr<SpdySessionDependencies>& session_deps() { | 267 scoped_ptr<SpdySessionDependencies>& session_deps() { |
253 return session_deps_; | 268 return session_deps_; |
254 } | 269 } |
255 int port() { return port_; } | 270 int port() const { return port_; } |
| 271 SpdyNetworkTransactionTestTypes test_type() const { return test_type_; } |
256 | 272 |
257 private: | 273 private: |
258 typedef std::vector<StaticSocketDataProvider*> DataVector; | 274 typedef std::vector<StaticSocketDataProvider*> DataVector; |
259 typedef std::vector<linked_ptr<SSLSocketDataProvider> > SSLVector; | 275 typedef std::vector<linked_ptr<SSLSocketDataProvider> > SSLVector; |
260 HttpRequestInfo request_; | 276 HttpRequestInfo request_; |
261 scoped_ptr<SpdySessionDependencies> session_deps_; | 277 scoped_ptr<SpdySessionDependencies> session_deps_; |
262 scoped_refptr<HttpNetworkSession> session_; | 278 scoped_refptr<HttpNetworkSession> session_; |
263 TransactionHelperResult output_; | 279 TransactionHelperResult output_; |
264 scoped_ptr<StaticSocketDataProvider> first_transaction_; | 280 scoped_ptr<StaticSocketDataProvider> first_transaction_; |
265 SSLVector ssl_vector_; | 281 SSLVector ssl_vector_; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 google_post_request_.method = "POST"; | 316 google_post_request_.method = "POST"; |
301 google_post_request_.url = GURL(kDefaultURL); | 317 google_post_request_.url = GURL(kDefaultURL); |
302 google_post_request_.upload_data = new UploadData(); | 318 google_post_request_.upload_data = new UploadData(); |
303 google_post_request_.upload_data->AppendBytes(kUploadData, | 319 google_post_request_.upload_data->AppendBytes(kUploadData, |
304 kUploadDataSize); | 320 kUploadDataSize); |
305 google_post_request_initialized_ = true; | 321 google_post_request_initialized_ = true; |
306 } | 322 } |
307 return google_post_request_; | 323 return google_post_request_; |
308 } | 324 } |
309 | 325 |
310 class RunServerPushTestCallback : public CallbackRunner< Tuple1<int> > { | 326 // Read the result of a particular transaction, knowing that we've got |
311 public: | 327 // multiple transactions in the read pipeline; so as we read, we may have |
312 RunServerPushTestCallback(scoped_refptr<net::IOBufferWithSize> buffer, | 328 // to skip over data destined for other transactions while we consume |
313 std::string& result, bool& need_read_callback) | 329 // the data for |trans|. |
314 : buffer_(buffer), result_(result), | 330 int ReadResult(HttpNetworkTransaction* trans, |
315 need_read_callback_(need_read_callback) {} | 331 OrderedSocketData* data, |
| 332 std::string* result) { |
| 333 const int kSize = 3000; |
316 | 334 |
317 virtual void RunWithParams(const Tuple1<int>& params) { | 335 int bytes_read = 0; |
318 // Indicates some type of error. | 336 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(kSize); |
319 if(params.a <= 0) | 337 TestCompletionCallback callback; |
320 return; | 338 while (true) { |
| 339 int rv = trans->Read(buf, kSize, &callback); |
| 340 if (rv == ERR_IO_PENDING) { |
| 341 // Multiple transactions may be in the data set. Keep pulling off |
| 342 // reads until we complete our callback. |
| 343 while (!callback.have_result()) { |
| 344 data->CompleteRead(); |
| 345 MessageLoop::current()->RunAllPending(); |
| 346 } |
| 347 rv = callback.WaitForResult(); |
| 348 } else if (rv <= 0) { |
| 349 break; |
| 350 } |
| 351 result->append(buf->data(), rv); |
| 352 bytes_read += rv; |
| 353 } |
| 354 return bytes_read; |
| 355 } |
321 | 356 |
322 std::string temp(buffer_->data(), params.a); | 357 void VerifyStreamsClosed(const NormalSpdyTransactionHelper& helper) { |
323 result_.append(temp); | 358 // This lengthy block is reaching into the pool to dig out the active |
324 need_read_callback_ = true; | 359 // session. Once we have the session, we verify that the streams are |
325 } | 360 // all closed and not leaked at this point. |
326 | 361 const GURL& url = helper.request().url; |
327 private: | 362 int port = helper.test_type() == SPDYNPN ? 443 : 80; |
328 scoped_refptr<net::IOBufferWithSize> buffer_; | 363 HostPortPair host_port_pair(url.host(), port); |
329 std::string& result_; | 364 HostPortProxyPair pair(host_port_pair, "DIRECT"); |
330 bool need_read_callback_; | 365 BoundNetLog log; |
331 }; | 366 const scoped_refptr<HttpNetworkSession>& session = helper.session(); |
| 367 scoped_refptr<SpdySessionPool> pool(session->spdy_session_pool()); |
| 368 EXPECT_TRUE(pool->HasSession(pair)); |
| 369 scoped_refptr<SpdySession> spdy_session(pool->Get(pair, session, log)); |
| 370 ASSERT_TRUE(spdy_session.get() != NULL); |
| 371 EXPECT_EQ(0u, spdy_session->num_active_streams()); |
| 372 EXPECT_EQ(0u, spdy_session->num_unclaimed_pushed_streams()); |
| 373 } |
332 | 374 |
333 void RunServerPushTest(MockWrite writes[], int writes_length, | 375 void RunServerPushTest(MockWrite writes[], int writes_length, |
334 MockRead reads[], int reads_length, | 376 MockRead reads[], int reads_length, |
335 HttpResponseInfo* response, | 377 HttpResponseInfo* response, |
336 HttpResponseInfo* response2, | 378 HttpResponseInfo* response2, |
337 std::string& expected) { | 379 std::string& expected) { |
338 scoped_refptr<OrderedSocketData> data( | 380 scoped_refptr<OrderedSocketData> data( |
339 new OrderedSocketData(reads, reads_length, | 381 new OrderedSocketData(reads, reads_length, |
340 writes, writes_length)); | 382 writes, writes_length)); |
341 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 383 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
342 BoundNetLog(), GetParam()); | 384 BoundNetLog(), GetParam()); |
343 | 385 |
344 helper.RunPreTestSetup(); | 386 helper.RunPreTestSetup(); |
345 helper.AddData(data.get()); | 387 helper.AddData(data.get()); |
346 | 388 |
347 HttpNetworkTransaction* trans = helper.trans(); | 389 HttpNetworkTransaction* trans = helper.trans(); |
348 | 390 |
349 // Start the transaction with basic parameters. | 391 // Start the transaction with basic parameters. |
350 TestCompletionCallback callback; | 392 TestCompletionCallback callback; |
351 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); | 393 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
352 EXPECT_EQ(ERR_IO_PENDING, rv); | 394 EXPECT_EQ(ERR_IO_PENDING, rv); |
353 rv = callback.WaitForResult(); | 395 rv = callback.WaitForResult(); |
354 | 396 |
355 // Request the pushed path. | 397 // Request the pushed path. |
356 const int kSize = 3000; | |
357 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(kSize); | |
358 scoped_ptr<HttpNetworkTransaction> trans2( | 398 scoped_ptr<HttpNetworkTransaction> trans2( |
359 new HttpNetworkTransaction(helper.session())); | 399 new HttpNetworkTransaction(helper.session())); |
360 rv = trans2->Start(&CreateGetPushRequest(), &callback, BoundNetLog()); | 400 rv = trans2->Start(&CreateGetPushRequest(), &callback, BoundNetLog()); |
361 EXPECT_EQ(ERR_IO_PENDING, rv); | 401 EXPECT_EQ(ERR_IO_PENDING, rv); |
362 MessageLoop::current()->RunAllPending(); | 402 MessageLoop::current()->RunAllPending(); |
363 | 403 |
364 // The data for the pushed path may be coming in more than 1 packet. Compile | 404 // The data for the pushed path may be coming in more than 1 packet. Compile |
365 // the results into a single string. | 405 // the results into a single string. |
| 406 |
| 407 // Read the server push body. |
| 408 std::string result2; |
| 409 ReadResult(trans2.get(), data, &result2); |
| 410 // Read the response body. |
366 std::string result; | 411 std::string result; |
367 bool need_read_callback = true; | 412 ReadResult(trans, data, &result); |
368 RunServerPushTestCallback callback2(buf, result, need_read_callback); | |
369 while(!data->at_read_eof()) | |
370 { | |
371 if(need_read_callback) { | |
372 while((rv = trans2->Read(buf, kSize, &callback2)) > 0) { | |
373 std::string result1(buf->data(),rv); | |
374 result.append(result1); | |
375 } | |
376 need_read_callback = false; | |
377 } | |
378 else | |
379 data->CompleteRead(); | |
380 MessageLoop::current()->RunAllPending(); | |
381 } | |
382 | 413 |
383 // Verify that we consumed all test data. | 414 // Verify that we consumed all test data. |
384 EXPECT_TRUE(data->at_read_eof()); | 415 EXPECT_TRUE(data->at_read_eof()); |
385 EXPECT_TRUE(data->at_write_eof()); | 416 EXPECT_TRUE(data->at_write_eof()); |
386 | 417 |
387 // Verify that the received push data is same as the expected push data. | 418 // Verify that the received push data is same as the expected push data. |
388 EXPECT_EQ(result.compare(expected),0) << "Received data: " | 419 EXPECT_EQ(result2.compare(expected), 0) << "Received data: " |
389 << result | 420 << result2 |
390 << "||||| Expected data: " | 421 << "||||| Expected data: " |
391 << expected; | 422 << expected; |
392 | 423 |
393 // Verify the SYN_REPLY. | 424 // Verify the SYN_REPLY. |
394 // Copy the response info, because trans goes away. | 425 // Copy the response info, because trans goes away. |
395 *response = *trans->GetResponseInfo(); | 426 *response = *trans->GetResponseInfo(); |
396 *response2 = *trans2->GetResponseInfo(); | 427 *response2 = *trans2->GetResponseInfo(); |
| 428 |
| 429 VerifyStreamsClosed(helper); |
397 } | 430 } |
398 | 431 |
399 private: | 432 private: |
400 bool google_get_request_initialized_; | 433 bool google_get_request_initialized_; |
401 bool google_post_request_initialized_; | 434 bool google_post_request_initialized_; |
402 HttpRequestInfo google_get_request_; | 435 HttpRequestInfo google_get_request_; |
403 HttpRequestInfo google_post_request_; | 436 HttpRequestInfo google_post_request_; |
404 HttpRequestInfo google_get_push_request_; | 437 HttpRequestInfo google_get_push_request_; |
405 }; | 438 }; |
406 | 439 |
(...skipping 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1759 data->SetStop(20); | 1792 data->SetStop(20); |
1760 data->Run(); | 1793 data->Run(); |
1761 | 1794 |
1762 helper.VerifyDataConsumed(); | 1795 helper.VerifyDataConsumed(); |
1763 } | 1796 } |
1764 | 1797 |
1765 class SpdyNetworkTransactionTest::StartTransactionCallback | 1798 class SpdyNetworkTransactionTest::StartTransactionCallback |
1766 : public CallbackRunner< Tuple1<int> > { | 1799 : public CallbackRunner< Tuple1<int> > { |
1767 public: | 1800 public: |
1768 explicit StartTransactionCallback( | 1801 explicit StartTransactionCallback( |
1769 scoped_refptr<HttpNetworkSession>& session, | 1802 const scoped_refptr<HttpNetworkSession>& session, |
1770 NormalSpdyTransactionHelper& helper) | 1803 NormalSpdyTransactionHelper& helper) |
1771 : session_(session), helper_(helper) {} | 1804 : session_(session), helper_(helper) {} |
1772 | 1805 |
1773 // We try to start another transaction, which should succeed. | 1806 // We try to start another transaction, which should succeed. |
1774 virtual void RunWithParams(const Tuple1<int>& params) { | 1807 virtual void RunWithParams(const Tuple1<int>& params) { |
1775 scoped_ptr<HttpNetworkTransaction> trans( | 1808 scoped_ptr<HttpNetworkTransaction> trans( |
1776 new HttpNetworkTransaction(session_)); | 1809 new HttpNetworkTransaction(session_)); |
1777 TestCompletionCallback callback; | 1810 TestCompletionCallback callback; |
1778 HttpRequestInfo request; | 1811 HttpRequestInfo request; |
1779 request.method = "GET"; | 1812 request.method = "GET"; |
1780 request.url = GURL("http://www.google.com/"); | 1813 request.url = GURL("http://www.google.com/"); |
1781 request.load_flags = 0; | 1814 request.load_flags = 0; |
1782 int rv = trans->Start(&request, &callback, BoundNetLog()); | 1815 int rv = trans->Start(&request, &callback, BoundNetLog()); |
1783 EXPECT_EQ(ERR_IO_PENDING, rv); | 1816 EXPECT_EQ(ERR_IO_PENDING, rv); |
1784 rv = callback.WaitForResult(); | 1817 rv = callback.WaitForResult(); |
1785 } | 1818 } |
1786 | 1819 |
1787 private: | 1820 private: |
1788 scoped_refptr<HttpNetworkSession>& session_; | 1821 const scoped_refptr<HttpNetworkSession>& session_; |
1789 NormalSpdyTransactionHelper& helper_; | 1822 NormalSpdyTransactionHelper& helper_; |
1790 }; | 1823 }; |
1791 | 1824 |
1792 // Verify that the client can correctly deal with the user callback attempting | 1825 // Verify that the client can correctly deal with the user callback attempting |
1793 // to start another transaction on a session that is closing down. See | 1826 // to start another transaction on a session that is closing down. See |
1794 // http://crbug.com/47455 | 1827 // http://crbug.com/47455 |
1795 TEST_P(SpdyNetworkTransactionTest, StartTransactionOnReadCallback) { | 1828 TEST_P(SpdyNetworkTransactionTest, StartTransactionOnReadCallback) { |
1796 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 1829 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
1797 MockWrite writes[] = { CreateMockWrite(*req) }; | 1830 MockWrite writes[] = { CreateMockWrite(*req) }; |
1798 MockWrite writes2[] = { CreateMockWrite(*req) }; | 1831 MockWrite writes2[] = { CreateMockWrite(*req) }; |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2149 data2->CompleteRead(); | 2182 data2->CompleteRead(); |
2150 EXPECT_TRUE(data->at_read_eof()); | 2183 EXPECT_TRUE(data->at_read_eof()); |
2151 EXPECT_TRUE(data->at_write_eof()); | 2184 EXPECT_TRUE(data->at_write_eof()); |
2152 EXPECT_TRUE(data2->at_read_eof()); | 2185 EXPECT_TRUE(data2->at_read_eof()); |
2153 EXPECT_TRUE(data2->at_write_eof()); | 2186 EXPECT_TRUE(data2->at_write_eof()); |
2154 } | 2187 } |
2155 | 2188 |
2156 TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame) { | 2189 TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame) { |
2157 static const unsigned char kPushBodyFrame[] = { | 2190 static const unsigned char kPushBodyFrame[] = { |
2158 0x00, 0x00, 0x00, 0x02, // header, ID | 2191 0x00, 0x00, 0x00, 0x02, // header, ID |
2159 0x01, 0x00, 0x00, 0x05, // FIN, length | 2192 0x01, 0x00, 0x00, 0x06, // FIN, length |
2160 'h', 'e', 'l', 'l', 'o', // "hello" | 2193 'p', 'u', 's', 'h', 'e', 'd' // "pushed" |
| 2194 }; |
| 2195 scoped_ptr<spdy::SpdyFrame> |
| 2196 stream1_syn(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 2197 scoped_ptr<spdy::SpdyFrame> |
| 2198 stream1_body(ConstructSpdyBodyFrame(1, true)); |
| 2199 MockWrite writes[] = { |
| 2200 CreateMockWrite(*stream1_syn, 1), |
2161 }; | 2201 }; |
2162 | 2202 |
2163 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 2203 scoped_ptr<spdy::SpdyFrame> |
2164 MockWrite writes[] = { | 2204 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); |
2165 CreateMockWrite(*req, 1), | 2205 scoped_ptr<spdy::SpdyFrame> |
2166 }; | 2206 stream2_syn(ConstructSpdyPush(NULL, 0, 2, 1, "/foo.dat")); |
2167 | |
2168 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
2169 scoped_ptr<spdy::SpdyFrame> rep(ConstructSpdyPush(NULL, 0, 2, 1, "/foo.dat")); | |
2170 MockRead reads[] = { | 2207 MockRead reads[] = { |
2171 CreateMockRead(*resp, 2), | 2208 CreateMockRead(*stream1_reply, 2), |
2172 CreateMockRead(*rep, 3), | 2209 CreateMockRead(*stream2_syn, 3), |
| 2210 CreateMockRead(*stream1_body, 4, false), |
2173 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame), | 2211 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame), |
2174 arraysize(kPushBodyFrame), 4), | 2212 arraysize(kPushBodyFrame), 5), |
2175 MockRead(true, ERR_IO_PENDING, 5), // Force a pause | 2213 MockRead(true, ERR_IO_PENDING, 6), // Force a pause |
2176 MockRead(true, 0, 0, 6) // EOF | |
2177 }; | 2214 }; |
2178 | 2215 |
2179 HttpResponseInfo response; | 2216 HttpResponseInfo response; |
2180 HttpResponseInfo response2; | 2217 HttpResponseInfo response2; |
2181 std::string expected_push_result("hello"); | 2218 std::string expected_push_result("pushed"); |
2182 RunServerPushTest(writes, arraysize(writes), reads, arraysize(reads), | 2219 RunServerPushTest(writes, arraysize(writes), reads, arraysize(reads), |
2183 &response, &response2, expected_push_result); | 2220 &response, &response2, expected_push_result); |
2184 | 2221 |
2185 // Verify the SYN_REPLY. | 2222 // Verify the SYN_REPLY. |
2186 EXPECT_TRUE(response.headers != NULL); | 2223 EXPECT_TRUE(response.headers != NULL); |
2187 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 2224 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
2188 | 2225 |
2189 // Verify the pushed stream. | 2226 // Verify the pushed stream. |
2190 EXPECT_TRUE(response2.headers != NULL); | 2227 EXPECT_TRUE(response2.headers != NULL); |
2191 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); | 2228 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
2192 } | 2229 } |
2193 | 2230 |
| 2231 TEST_P(SpdyNetworkTransactionTest, ServerPushServerAborted) { |
| 2232 scoped_ptr<spdy::SpdyFrame> |
| 2233 stream1_syn(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 2234 scoped_ptr<spdy::SpdyFrame> |
| 2235 stream1_body(ConstructSpdyBodyFrame(1, true)); |
| 2236 MockWrite writes[] = { |
| 2237 CreateMockWrite(*stream1_syn, 1), |
| 2238 }; |
| 2239 |
| 2240 scoped_ptr<spdy::SpdyFrame> |
| 2241 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2242 scoped_ptr<spdy::SpdyFrame> |
| 2243 stream2_syn(ConstructSpdyPush(NULL, 0, 2, 1, "/foo.dat")); |
| 2244 scoped_ptr<spdy::SpdyFrame> |
| 2245 stream2_rst(ConstructSpdyRstStream(2, spdy::PROTOCOL_ERROR)); |
| 2246 MockRead reads[] = { |
| 2247 CreateMockRead(*stream1_reply, 2), |
| 2248 CreateMockRead(*stream2_syn, 3), |
| 2249 CreateMockRead(*stream2_rst, 4), |
| 2250 CreateMockRead(*stream1_body, 5, false), |
| 2251 MockRead(true, ERR_IO_PENDING, 6), // Force a pause |
| 2252 }; |
| 2253 |
| 2254 scoped_refptr<OrderedSocketData> data( |
| 2255 new OrderedSocketData(reads, arraysize(reads), |
| 2256 writes, arraysize(writes))); |
| 2257 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 2258 BoundNetLog(), GetParam()); |
| 2259 |
| 2260 helper.RunPreTestSetup(); |
| 2261 helper.AddData(data.get()); |
| 2262 |
| 2263 HttpNetworkTransaction* trans = helper.trans(); |
| 2264 |
| 2265 // Start the transaction with basic parameters. |
| 2266 TestCompletionCallback callback; |
| 2267 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
| 2268 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2269 rv = callback.WaitForResult(); |
| 2270 EXPECT_EQ(OK, rv); |
| 2271 |
| 2272 // Verify that we consumed all test data. |
| 2273 EXPECT_TRUE(data->at_read_eof()) << "Read count: " |
| 2274 << data->read_count() |
| 2275 << " Read index: " |
| 2276 << data->read_index(); |
| 2277 EXPECT_TRUE(data->at_write_eof()) << "Write count: " |
| 2278 << data->write_count() |
| 2279 << " Write index: " |
| 2280 << data->write_index(); |
| 2281 |
| 2282 // Verify the SYN_REPLY. |
| 2283 HttpResponseInfo response = *trans->GetResponseInfo(); |
| 2284 EXPECT_TRUE(response.headers != NULL); |
| 2285 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2286 } |
| 2287 |
2194 TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrame) { | 2288 TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrame) { |
2195 static const unsigned char kPushBodyFrame1[] = { | 2289 static const unsigned char kPushBodyFrame1[] = { |
2196 0x00, 0x00, 0x00, 0x02, // header, ID | 2290 0x00, 0x00, 0x00, 0x02, // header, ID |
2197 0x01, 0x00, 0x00, 0x1E, // FIN, length | 2291 0x01, 0x00, 0x00, 0x1F, // FIN, length |
2198 'h', 'e', 'l', 'l', 'o', // "hello" | 2292 'p', 'u', 's', 'h', 'e', 'd' // "pushed" |
2199 }; | 2293 }; |
2200 static const char kPushBodyFrame2[] = " my darling"; | 2294 static const char kPushBodyFrame2[] = " my darling"; |
2201 static const char kPushBodyFrame3[] = " hello"; | 2295 static const char kPushBodyFrame3[] = " hello"; |
2202 static const char kPushBodyFrame4[] = " my baby"; | 2296 static const char kPushBodyFrame4[] = " my baby"; |
2203 | 2297 |
2204 scoped_ptr<spdy::SpdyFrame> req( | 2298 scoped_ptr<spdy::SpdyFrame> |
2205 ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 2299 stream1_syn(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 2300 scoped_ptr<spdy::SpdyFrame> |
| 2301 stream1_body(ConstructSpdyBodyFrame(1, true)); |
2206 MockWrite writes[] = { | 2302 MockWrite writes[] = { |
2207 CreateMockWrite(*req, 1), | 2303 CreateMockWrite(*stream1_syn, 1), |
2208 }; | 2304 }; |
2209 | 2305 |
2210 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 2306 scoped_ptr<spdy::SpdyFrame> |
2211 scoped_ptr<spdy::SpdyFrame> rep(ConstructSpdyPush(NULL, 0, 2, 1, "/foo.dat")); | 2307 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2308 scoped_ptr<spdy::SpdyFrame> |
| 2309 stream2_syn(ConstructSpdyPush(NULL, 0, 2, 1, "/foo.dat")); |
2212 MockRead reads[] = { | 2310 MockRead reads[] = { |
2213 CreateMockRead(*resp, 2), | 2311 CreateMockRead(*stream1_reply, 2), |
2214 CreateMockRead(*rep, 3), | 2312 CreateMockRead(*stream2_syn, 3), |
2215 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame1), | 2313 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame1), |
2216 arraysize(kPushBodyFrame1), 4), | 2314 arraysize(kPushBodyFrame1), 4), |
2217 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame2), | 2315 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame2), |
2218 arraysize(kPushBodyFrame2) - 1, 5), | 2316 arraysize(kPushBodyFrame2) - 1, 5), |
2219 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame3), | 2317 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame3), |
2220 arraysize(kPushBodyFrame3) - 1, 6), | 2318 arraysize(kPushBodyFrame3) - 1, 6), |
2221 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame4), | 2319 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame4), |
2222 arraysize(kPushBodyFrame4) - 1, 7), | 2320 arraysize(kPushBodyFrame4) - 1, 7), |
2223 MockRead(true, ERR_IO_PENDING, 8), // Force a pause | 2321 CreateMockRead(*stream1_body, 8, false), |
2224 MockRead(true, 0, 0, 9) // EOF | 2322 MockRead(true, ERR_IO_PENDING, 9), // Force a pause |
2225 }; | 2323 }; |
2226 | 2324 |
2227 HttpResponseInfo response; | 2325 HttpResponseInfo response; |
2228 HttpResponseInfo response2; | 2326 HttpResponseInfo response2; |
2229 std::string expected_push_result("hello my darling hello my baby"); | 2327 std::string expected_push_result("pushed my darling hello my baby"); |
2230 RunServerPushTest(writes, arraysize(writes), reads, arraysize(reads), | 2328 RunServerPushTest(writes, arraysize(writes), reads, arraysize(reads), |
2231 &response, &response2, expected_push_result); | 2329 &response, &response2, expected_push_result); |
2232 | 2330 |
2233 // Verify the SYN_REPLY. | 2331 // Verify the SYN_REPLY. |
2234 EXPECT_TRUE(response.headers != NULL); | 2332 EXPECT_TRUE(response.headers != NULL); |
2235 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 2333 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
2236 | 2334 |
2237 // Verify the pushed stream. | 2335 // Verify the pushed stream. |
2238 EXPECT_TRUE(response2.headers != NULL); | 2336 EXPECT_TRUE(response2.headers != NULL); |
2239 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); | 2337 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
2240 } | 2338 } |
2241 | 2339 |
2242 TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrameInterrupted) { | 2340 TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrameInterrupted) { |
2243 static const unsigned char kPushBodyFrame1[] = { | 2341 static const unsigned char kPushBodyFrame1[] = { |
2244 0x00, 0x00, 0x00, 0x02, // header, ID | 2342 0x00, 0x00, 0x00, 0x02, // header, ID |
2245 0x01, 0x00, 0x00, 0x1E, // FIN, length | 2343 0x01, 0x00, 0x00, 0x1F, // FIN, length |
2246 'h', 'e', 'l', 'l', 'o', // "hello" | 2344 'p', 'u', 's', 'h', 'e', 'd' // "pushed" |
2247 }; | 2345 }; |
2248 static const char kPushBodyFrame2[] = " my darling"; | 2346 static const char kPushBodyFrame2[] = " my darling"; |
2249 static const char kPushBodyFrame3[] = " hello"; | 2347 static const char kPushBodyFrame3[] = " hello"; |
2250 static const char kPushBodyFrame4[] = " my baby"; | 2348 static const char kPushBodyFrame4[] = " my baby"; |
2251 | 2349 |
2252 scoped_ptr<spdy::SpdyFrame> req( | 2350 scoped_ptr<spdy::SpdyFrame> |
2253 ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 2351 stream1_syn(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 2352 scoped_ptr<spdy::SpdyFrame> |
| 2353 stream1_body(ConstructSpdyBodyFrame(1, true)); |
2254 MockWrite writes[] = { | 2354 MockWrite writes[] = { |
2255 CreateMockWrite(*req, 1), | 2355 CreateMockWrite(*stream1_syn, 1), |
2256 }; | 2356 }; |
2257 | 2357 |
2258 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 2358 scoped_ptr<spdy::SpdyFrame> |
2259 scoped_ptr<spdy::SpdyFrame> rep(ConstructSpdyPush(NULL, 0, 2, 1, "/foo.dat")); | 2359 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2360 scoped_ptr<spdy::SpdyFrame> |
| 2361 stream2_syn(ConstructSpdyPush(NULL, 0, 2, 1, "/foo.dat")); |
2260 MockRead reads[] = { | 2362 MockRead reads[] = { |
2261 CreateMockRead(*resp, 2), | 2363 CreateMockRead(*stream1_reply, 2), |
2262 CreateMockRead(*rep, 3), | 2364 CreateMockRead(*stream2_syn, 3), |
2263 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame1), | 2365 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame1), |
2264 arraysize(kPushBodyFrame1), 4), | 2366 arraysize(kPushBodyFrame1), 4), |
2265 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame2), | 2367 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame2), |
2266 arraysize(kPushBodyFrame2) - 1, 5), | 2368 arraysize(kPushBodyFrame2) - 1, 5), |
2267 MockRead(true, ERR_IO_PENDING, 6), // Force a pause | 2369 MockRead(true, ERR_IO_PENDING, 6), // Force a pause |
2268 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame3), | 2370 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame3), |
2269 arraysize(kPushBodyFrame3) - 1, 7), | 2371 arraysize(kPushBodyFrame3) - 1, 7), |
2270 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame4), | 2372 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame4), |
2271 arraysize(kPushBodyFrame4) - 1, 8), | 2373 arraysize(kPushBodyFrame4) - 1, 8), |
2272 MockRead(true, 0, 0, 9) // EOF | 2374 CreateMockRead(*stream1_body.get(), 9, false), |
| 2375 MockRead(true, ERR_IO_PENDING, 10) // Force a pause. |
2273 }; | 2376 }; |
2274 | 2377 |
2275 HttpResponseInfo response; | 2378 HttpResponseInfo response; |
2276 HttpResponseInfo response2; | 2379 HttpResponseInfo response2; |
2277 std::string expected_push_result("hello my darling hello my baby"); | 2380 std::string expected_push_result("pushed my darling hello my baby"); |
2278 RunServerPushTest(writes, arraysize(writes), reads, arraysize(reads), | 2381 RunServerPushTest(writes, arraysize(writes), reads, arraysize(reads), |
2279 &response, &response2, expected_push_result); | 2382 &response, &response2, expected_push_result); |
2280 | 2383 |
2281 // Verify the SYN_REPLY. | 2384 // Verify the SYN_REPLY. |
2282 EXPECT_TRUE(response.headers != NULL); | 2385 EXPECT_TRUE(response.headers != NULL); |
2283 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 2386 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
2284 | 2387 |
2285 // Verify the pushed stream. | 2388 // Verify the pushed stream. |
2286 EXPECT_TRUE(response2.headers != NULL); | 2389 EXPECT_TRUE(response2.headers != NULL); |
2287 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); | 2390 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
2288 } | 2391 } |
2289 | 2392 |
2290 TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) { | 2393 TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) { |
2291 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 2394 scoped_ptr<spdy::SpdyFrame> |
2292 scoped_ptr<spdy::SpdyFrame> res( | 2395 stream1_syn(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
2293 ConstructSpdyRstStream(2, spdy::INVALID_STREAM)); | 2396 scoped_ptr<spdy::SpdyFrame> |
| 2397 stream1_body(ConstructSpdyBodyFrame(1, true)); |
| 2398 scoped_ptr<spdy::SpdyFrame> |
| 2399 stream2_rst(ConstructSpdyRstStream(2, spdy::INVALID_STREAM)); |
2294 MockWrite writes[] = { | 2400 MockWrite writes[] = { |
2295 CreateMockWrite(*req, 1), | 2401 CreateMockWrite(*stream1_syn, 1), |
2296 CreateMockWrite(*res, 4), | 2402 CreateMockWrite(*stream2_rst, 4), |
2297 }; | 2403 }; |
2298 | 2404 |
2299 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 2405 scoped_ptr<spdy::SpdyFrame> |
2300 scoped_ptr<spdy::SpdyFrame> rep(ConstructSpdyPush(NULL, 0, 2, 0, "/foo.dat")); | 2406 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2407 scoped_ptr<spdy::SpdyFrame> |
| 2408 stream2_syn(ConstructSpdyPush(NULL, 0, 2, 0, "/foo.dat")); |
2301 MockRead reads[] = { | 2409 MockRead reads[] = { |
2302 CreateMockRead(*resp, 2), | 2410 CreateMockRead(*stream1_reply, 2), |
2303 CreateMockRead(*rep, 3), | 2411 CreateMockRead(*stream2_syn, 3), |
2304 MockRead(true, 0, 0, 5) // EOF | 2412 CreateMockRead(*stream1_body, 4), |
| 2413 MockRead(true, ERR_IO_PENDING, 5) // Force a pause |
2305 }; | 2414 }; |
2306 | 2415 |
2307 scoped_refptr<OrderedSocketData> data( | 2416 scoped_refptr<OrderedSocketData> data( |
2308 new OrderedSocketData(reads, arraysize(reads), | 2417 new OrderedSocketData(reads, arraysize(reads), |
2309 writes, arraysize(writes))); | 2418 writes, arraysize(writes))); |
2310 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 2419 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
2311 BoundNetLog(), GetParam()); | 2420 BoundNetLog(), GetParam()); |
2312 | 2421 |
2313 helper.RunPreTestSetup(); | 2422 helper.RunPreTestSetup(); |
2314 helper.AddData(data.get()); | 2423 helper.AddData(data.get()); |
2315 | 2424 |
2316 HttpNetworkTransaction* trans = helper.trans(); | 2425 HttpNetworkTransaction* trans = helper.trans(); |
2317 | 2426 |
2318 // Start the transaction with basic parameters. | 2427 // Start the transaction with basic parameters. |
2319 TestCompletionCallback callback; | 2428 TestCompletionCallback callback; |
2320 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); | 2429 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
2321 EXPECT_EQ(ERR_IO_PENDING, rv); | 2430 EXPECT_EQ(ERR_IO_PENDING, rv); |
2322 rv = callback.WaitForResult(); | 2431 rv = callback.WaitForResult(); |
2323 data->CompleteRead(); | |
2324 EXPECT_EQ(OK, rv); | 2432 EXPECT_EQ(OK, rv); |
2325 | 2433 |
2326 // Verify that we consumed all test data. | 2434 // Verify that we consumed all test data. |
2327 EXPECT_TRUE(data->at_read_eof()) << "Read count: " | 2435 EXPECT_TRUE(data->at_read_eof()) << "Read count: " |
2328 << data->read_count() | 2436 << data->read_count() |
2329 << " Read index: " | 2437 << " Read index: " |
2330 << data->read_index(); | 2438 << data->read_index(); |
2331 EXPECT_TRUE(data->at_write_eof()) << "Write count: " | 2439 EXPECT_TRUE(data->at_write_eof()) << "Write count: " |
2332 << data->write_count() | 2440 << data->write_count() |
2333 << " Write index: " | 2441 << " Write index: " |
2334 << data->write_index(); | 2442 << data->write_index(); |
2335 | 2443 |
2336 // Verify the SYN_REPLY. | 2444 // Verify the SYN_REPLY. |
2337 HttpResponseInfo response = *trans->GetResponseInfo(); | 2445 HttpResponseInfo response = *trans->GetResponseInfo(); |
2338 EXPECT_TRUE(response.headers != NULL); | 2446 EXPECT_TRUE(response.headers != NULL); |
2339 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 2447 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
2340 } | 2448 } |
2341 | 2449 |
2342 TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID9) { | 2450 TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID9) { |
2343 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 2451 scoped_ptr<spdy::SpdyFrame> |
2344 scoped_ptr<spdy::SpdyFrame> res( | 2452 stream1_syn(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
2345 ConstructSpdyRstStream(2, spdy::INVALID_ASSOCIATED_STREAM)); | 2453 scoped_ptr<spdy::SpdyFrame> |
| 2454 stream1_body(ConstructSpdyBodyFrame(1, true)); |
| 2455 scoped_ptr<spdy::SpdyFrame> |
| 2456 stream2_rst(ConstructSpdyRstStream(2, spdy::INVALID_ASSOCIATED_STREAM)); |
2346 MockWrite writes[] = { | 2457 MockWrite writes[] = { |
2347 CreateMockWrite(*req, 1), | 2458 CreateMockWrite(*stream1_syn, 1), |
2348 CreateMockWrite(*res, 4), | 2459 CreateMockWrite(*stream2_rst, 4), |
2349 }; | 2460 }; |
2350 | 2461 |
2351 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 2462 scoped_ptr<spdy::SpdyFrame> |
2352 scoped_ptr<spdy::SpdyFrame> rep(ConstructSpdyPush(NULL, 0, 2, 9, "/foo.dat")); | 2463 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2464 scoped_ptr<spdy::SpdyFrame> |
| 2465 stream2_syn(ConstructSpdyPush(NULL, 0, 2, 9, "/foo.dat")); |
2353 MockRead reads[] = { | 2466 MockRead reads[] = { |
2354 CreateMockRead(*resp, 2), | 2467 CreateMockRead(*stream1_reply, 2), |
2355 CreateMockRead(*rep, 3), | 2468 CreateMockRead(*stream2_syn, 3), |
2356 MockRead(true, 0, 0, 5) // EOF | 2469 CreateMockRead(*stream1_body, 4), |
| 2470 MockRead(true, ERR_IO_PENDING, 5), // Force a pause |
2357 }; | 2471 }; |
2358 | 2472 |
2359 scoped_refptr<OrderedSocketData> data( | 2473 scoped_refptr<OrderedSocketData> data( |
2360 new OrderedSocketData(reads, arraysize(reads), | 2474 new OrderedSocketData(reads, arraysize(reads), |
2361 writes, arraysize(writes))); | 2475 writes, arraysize(writes))); |
2362 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 2476 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
2363 BoundNetLog(), GetParam()); | 2477 BoundNetLog(), GetParam()); |
2364 | 2478 |
2365 helper.RunPreTestSetup(); | 2479 helper.RunPreTestSetup(); |
2366 helper.AddData(data.get()); | 2480 helper.AddData(data.get()); |
2367 | 2481 |
2368 HttpNetworkTransaction* trans = helper.trans(); | 2482 HttpNetworkTransaction* trans = helper.trans(); |
2369 | 2483 |
2370 // Start the transaction with basic parameters. | 2484 // Start the transaction with basic parameters. |
2371 TestCompletionCallback callback; | 2485 TestCompletionCallback callback; |
2372 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); | 2486 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
2373 EXPECT_EQ(ERR_IO_PENDING, rv); | 2487 EXPECT_EQ(ERR_IO_PENDING, rv); |
2374 rv = callback.WaitForResult(); | 2488 rv = callback.WaitForResult(); |
2375 data->CompleteRead(); | |
2376 EXPECT_EQ(OK, rv); | 2489 EXPECT_EQ(OK, rv); |
2377 | 2490 |
2378 // Verify that we consumed all test data. | 2491 // Verify that we consumed all test data. |
2379 EXPECT_TRUE(data->at_read_eof()) << "Read count: " | 2492 EXPECT_TRUE(data->at_read_eof()) << "Read count: " |
2380 << data->read_count() | 2493 << data->read_count() |
2381 << " Read index: " | 2494 << " Read index: " |
2382 << data->read_index(); | 2495 << data->read_index(); |
2383 EXPECT_TRUE(data->at_write_eof()) << "Write count: " | 2496 EXPECT_TRUE(data->at_write_eof()) << "Write count: " |
2384 << data->write_count() | 2497 << data->write_count() |
2385 << " Write index: " | 2498 << " Write index: " |
2386 << data->write_index(); | 2499 << data->write_index(); |
2387 | 2500 |
2388 // Verify the SYN_REPLY. | 2501 // Verify the SYN_REPLY. |
2389 HttpResponseInfo response = *trans->GetResponseInfo(); | 2502 HttpResponseInfo response = *trans->GetResponseInfo(); |
2390 EXPECT_TRUE(response.headers != NULL); | 2503 EXPECT_TRUE(response.headers != NULL); |
2391 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 2504 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
2392 } | 2505 } |
2393 | 2506 |
2394 TEST_P(SpdyNetworkTransactionTest, ServerPushNoURL) { | 2507 TEST_P(SpdyNetworkTransactionTest, ServerPushNoURL) { |
2395 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 2508 scoped_ptr<spdy::SpdyFrame> |
2396 scoped_ptr<spdy::SpdyFrame> res( | 2509 stream1_syn(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
2397 ConstructSpdyRstStream(2, spdy::PROTOCOL_ERROR)); | 2510 scoped_ptr<spdy::SpdyFrame> |
| 2511 stream1_body(ConstructSpdyBodyFrame(1, true)); |
| 2512 scoped_ptr<spdy::SpdyFrame> |
| 2513 stream2_rst(ConstructSpdyRstStream(2, spdy::PROTOCOL_ERROR)); |
2398 MockWrite writes[] = { | 2514 MockWrite writes[] = { |
2399 CreateMockWrite(*req, 1), | 2515 CreateMockWrite(*stream1_syn, 1), |
2400 CreateMockWrite(*res, 4), | 2516 CreateMockWrite(*stream2_rst, 4), |
2401 }; | 2517 }; |
2402 | 2518 |
2403 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 2519 scoped_ptr<spdy::SpdyFrame> |
2404 scoped_ptr<spdy::SpdyFrame> rep(ConstructSpdyPush(NULL, 0, 2, 1)); | 2520 stream1_reply(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2521 scoped_ptr<spdy::SpdyFrame> |
| 2522 stream2_syn(ConstructSpdyPush(NULL, 0, 2, 1)); |
2405 MockRead reads[] = { | 2523 MockRead reads[] = { |
2406 CreateMockRead(*resp, 2), | 2524 CreateMockRead(*stream1_reply, 2), |
2407 CreateMockRead(*rep, 3), | 2525 CreateMockRead(*stream2_syn, 3), |
2408 MockRead(true, 0, 0, 5) // EOF | 2526 CreateMockRead(*stream1_body, 4), |
| 2527 MockRead(true, ERR_IO_PENDING, 5) // Force a pause |
2409 }; | 2528 }; |
2410 | 2529 |
2411 scoped_refptr<OrderedSocketData> data( | 2530 scoped_refptr<OrderedSocketData> data( |
2412 new OrderedSocketData(reads, arraysize(reads), | 2531 new OrderedSocketData(reads, arraysize(reads), |
2413 writes, arraysize(writes))); | 2532 writes, arraysize(writes))); |
2414 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 2533 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
2415 BoundNetLog(), GetParam()); | 2534 BoundNetLog(), GetParam()); |
2416 | 2535 |
2417 helper.RunPreTestSetup(); | 2536 helper.RunPreTestSetup(); |
2418 helper.AddData(data.get()); | 2537 helper.AddData(data.get()); |
2419 | 2538 |
2420 HttpNetworkTransaction* trans = helper.trans(); | 2539 HttpNetworkTransaction* trans = helper.trans(); |
2421 | 2540 |
2422 // Start the transaction with basic parameters. | 2541 // Start the transaction with basic parameters. |
2423 TestCompletionCallback callback; | 2542 TestCompletionCallback callback; |
2424 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); | 2543 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
2425 EXPECT_EQ(ERR_IO_PENDING, rv); | 2544 EXPECT_EQ(ERR_IO_PENDING, rv); |
2426 rv = callback.WaitForResult(); | 2545 rv = callback.WaitForResult(); |
2427 data->CompleteRead(); | |
2428 EXPECT_EQ(OK, rv); | 2546 EXPECT_EQ(OK, rv); |
2429 // Verify that we consumed all test data. | 2547 // Verify that we consumed all test data. |
2430 EXPECT_TRUE(data->at_read_eof()) << "Read count: " | 2548 EXPECT_TRUE(data->at_read_eof()) << "Read count: " |
2431 << data->read_count() | 2549 << data->read_count() |
2432 << " Read index: " | 2550 << " Read index: " |
2433 << data->read_index(); | 2551 << data->read_index(); |
2434 EXPECT_TRUE(data->at_write_eof()) << "Write count: " | 2552 EXPECT_TRUE(data->at_write_eof()) << "Write count: " |
2435 << data->write_count() | 2553 << data->write_count() |
2436 << " Write index: " | 2554 << " Write index: " |
2437 << data->write_index(); | 2555 << data->write_index(); |
(...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3736 // Verify that we consumed all test data. | 3854 // Verify that we consumed all test data. |
3737 helper.VerifyDataConsumed(); | 3855 helper.VerifyDataConsumed(); |
3738 } | 3856 } |
3739 | 3857 |
3740 // Test to make sure we can correctly connect through a proxy. | 3858 // Test to make sure we can correctly connect through a proxy. |
3741 TEST_P(SpdyNetworkTransactionTest, ProxyConnect) { | 3859 TEST_P(SpdyNetworkTransactionTest, ProxyConnect) { |
3742 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 3860 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
3743 BoundNetLog(), GetParam()); | 3861 BoundNetLog(), GetParam()); |
3744 helper.session_deps().reset(new SpdySessionDependencies( | 3862 helper.session_deps().reset(new SpdySessionDependencies( |
3745 net::SpdyCreateFixedProxyService("myproxy:70"))); | 3863 net::SpdyCreateFixedProxyService("myproxy:70"))); |
3746 helper.session() = SpdySessionDependencies::SpdyCreateSession( | 3864 helper.SetSession(SpdySessionDependencies::SpdyCreateSession( |
3747 helper.session_deps().get()); | 3865 helper.session_deps().get())); |
3748 helper.RunPreTestSetup(); | 3866 helper.RunPreTestSetup(); |
3749 HttpNetworkTransaction* trans = helper.trans(); | 3867 HttpNetworkTransaction* trans = helper.trans(); |
3750 | 3868 |
3751 const char kConnect443[] = {"CONNECT www.google.com:443 HTTP/1.1\r\n" | 3869 const char kConnect443[] = {"CONNECT www.google.com:443 HTTP/1.1\r\n" |
3752 "Host: www.google.com\r\n" | 3870 "Host: www.google.com\r\n" |
3753 "Proxy-Connection: keep-alive\r\n\r\n"}; | 3871 "Proxy-Connection: keep-alive\r\n\r\n"}; |
3754 const char kConnect80[] = {"CONNECT www.google.com:80 HTTP/1.1\r\n" | 3872 const char kConnect80[] = {"CONNECT www.google.com:80 HTTP/1.1\r\n" |
3755 "Host: www.google.com\r\n" | 3873 "Host: www.google.com\r\n" |
3756 "Proxy-Connection: keep-alive\r\n\r\n"}; | 3874 "Proxy-Connection: keep-alive\r\n\r\n"}; |
3757 const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; | 3875 const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3963 scoped_ptr<SpdySessionDependencies> ssd_proxy( | 4081 scoped_ptr<SpdySessionDependencies> ssd_proxy( |
3964 new SpdySessionDependencies(net::SpdyCreateFixedProxyService( | 4082 new SpdySessionDependencies(net::SpdyCreateFixedProxyService( |
3965 "myproxy:70"))); | 4083 "myproxy:70"))); |
3966 // Ensure that this transaction uses the same SpdySessionPool. | 4084 // Ensure that this transaction uses the same SpdySessionPool. |
3967 ssd_proxy->spdy_session_pool = spdy_session_pool; | 4085 ssd_proxy->spdy_session_pool = spdy_session_pool; |
3968 scoped_refptr<HttpNetworkSession> session_proxy = | 4086 scoped_refptr<HttpNetworkSession> session_proxy = |
3969 SpdySessionDependencies::SpdyCreateSession(ssd_proxy.get()); | 4087 SpdySessionDependencies::SpdyCreateSession(ssd_proxy.get()); |
3970 NormalSpdyTransactionHelper helper_proxy(request_proxy, | 4088 NormalSpdyTransactionHelper helper_proxy(request_proxy, |
3971 BoundNetLog(), GetParam()); | 4089 BoundNetLog(), GetParam()); |
3972 helper_proxy.session_deps().swap(ssd_proxy); | 4090 helper_proxy.session_deps().swap(ssd_proxy); |
3973 helper_proxy.session() = session_proxy; | 4091 helper_proxy.SetSession(session_proxy); |
3974 helper_proxy.RunPreTestSetup(); | 4092 helper_proxy.RunPreTestSetup(); |
3975 helper_proxy.AddData(data_proxy.get()); | 4093 helper_proxy.AddData(data_proxy.get()); |
3976 | 4094 |
3977 HttpNetworkTransaction* trans_proxy = helper_proxy.trans(); | 4095 HttpNetworkTransaction* trans_proxy = helper_proxy.trans(); |
3978 TestCompletionCallback callback_proxy; | 4096 TestCompletionCallback callback_proxy; |
3979 int rv = trans_proxy->Start(&request_proxy, &callback_proxy, BoundNetLog()); | 4097 int rv = trans_proxy->Start(&request_proxy, &callback_proxy, BoundNetLog()); |
3980 EXPECT_EQ(ERR_IO_PENDING, rv); | 4098 EXPECT_EQ(ERR_IO_PENDING, rv); |
3981 rv = callback_proxy.WaitForResult(); | 4099 rv = callback_proxy.WaitForResult(); |
3982 EXPECT_EQ(0, rv); | 4100 EXPECT_EQ(0, rv); |
3983 | 4101 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4070 rv = ReadTransaction(trans.get(), &response_data); | 4188 rv = ReadTransaction(trans.get(), &response_data); |
4071 EXPECT_EQ(OK, rv); | 4189 EXPECT_EQ(OK, rv); |
4072 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 4190 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
4073 EXPECT_EQ("hello!", response_data); | 4191 EXPECT_EQ("hello!", response_data); |
4074 } | 4192 } |
4075 | 4193 |
4076 helper.VerifyDataConsumed(); | 4194 helper.VerifyDataConsumed(); |
4077 } | 4195 } |
4078 } | 4196 } |
4079 } // namespace net | 4197 } // namespace net |
OLD | NEW |