1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
9 #include "base/bind_helpers.h"
10 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/run_loop.h"
14 #include "base/stl_util.h"
15 #include "base/strings/string_piece.h"
16 #include "base/test/test_file_util.h"
17 #include "net/base/auth.h"
18 #include "net/base/chunked_upload_data_stream.h"
19 #include "net/base/elements_upload_data_stream.h"
20 #include "net/base/net_log_unittest.h"
21 #include "net/base/request_priority.h"
22 #include "net/base/upload_bytes_element_reader.h"
23 #include "net/base/upload_file_element_reader.h"
24 #include "net/http/http_network_session_peer.h"
25 #include "net/http/http_network_transaction.h"
26 #include "net/http/http_server_properties.h"
27 #include "net/http/http_transaction_test_util.h"
28 #include "net/socket/client_socket_pool_base.h"
29 #include "net/socket/next_proto.h"
30 #include "net/spdy/buffered_spdy_framer.h"
31 #include "net/spdy/spdy_http_stream.h"
32 #include "net/spdy/spdy_http_utils.h"
33 #include "net/spdy/spdy_session.h"
34 #include "net/spdy/spdy_session_pool.h"
35 #include "net/spdy/spdy_test_util_common.h"
36 #include "net/spdy/spdy_test_utils.h"
37 #include "net/ssl/ssl_connection_status_flags.h"
38 #include "net/url_request/url_request_test_util.h"
39 #include "testing/gmock/include/gmock/gmock.h"
40 #include "testing/platform_test.h"
42 //-----------------------------------------------------------------------------
51 const char kRequestUrl
[] = "http://www.google.com/";
53 enum SpdyNetworkTransactionTestSSLType
{
59 struct SpdyNetworkTransactionTestParams
{
60 SpdyNetworkTransactionTestParams()
61 : protocol(kProtoSPDY31
),
64 SpdyNetworkTransactionTestParams(
66 SpdyNetworkTransactionTestSSLType ssl_type
)
71 SpdyNetworkTransactionTestSSLType ssl_type
;
74 void UpdateSpdySessionDependencies(
75 SpdyNetworkTransactionTestParams test_params
,
76 SpdySessionDependencies
* session_deps
) {
77 switch (test_params
.ssl_type
) {
79 session_deps
->http_server_properties
.SetAlternativeService(
80 HostPortPair("www.google.com", 80),
82 AlternateProtocolFromNextProto(test_params
.protocol
),
83 "www.google.com", 443),
85 session_deps
->use_alternate_protocols
= true;
86 session_deps
->next_protos
= SpdyNextProtos();
89 session_deps
->force_spdy_over_ssl
= false;
90 session_deps
->force_spdy_always
= true;
93 session_deps
->force_spdy_over_ssl
= true;
94 session_deps
->force_spdy_always
= true;
101 SpdySessionDependencies
* CreateSpdySessionDependencies(
102 SpdyNetworkTransactionTestParams test_params
) {
103 SpdySessionDependencies
* session_deps
=
104 new SpdySessionDependencies(test_params
.protocol
);
105 UpdateSpdySessionDependencies(test_params
, session_deps
);
109 SpdySessionDependencies
* CreateSpdySessionDependencies(
110 SpdyNetworkTransactionTestParams test_params
,
111 ProxyService
* proxy_service
) {
112 SpdySessionDependencies
* session_deps
=
113 new SpdySessionDependencies(test_params
.protocol
, proxy_service
);
114 UpdateSpdySessionDependencies(test_params
, session_deps
);
120 class SpdyNetworkTransactionTest
121 : public ::testing::TestWithParam
<SpdyNetworkTransactionTestParams
> {
123 SpdyNetworkTransactionTest() : spdy_util_(GetParam().protocol
) {
126 virtual ~SpdyNetworkTransactionTest() {
127 // UploadDataStream may post a deletion tasks back to the message loop on
129 upload_data_stream_
.reset();
130 base::RunLoop().RunUntilIdle();
133 void SetUp() override
{
134 google_get_request_initialized_
= false;
135 google_post_request_initialized_
= false;
136 google_chunked_post_request_initialized_
= false;
137 ASSERT_TRUE(temp_dir_
.CreateUniqueTempDir());
140 struct TransactionHelperResult
{
142 std::string status_line
;
143 std::string response_data
;
144 HttpResponseInfo response_info
;
147 // A helper class that handles all the initial npn/ssl setup.
148 class NormalSpdyTransactionHelper
{
150 NormalSpdyTransactionHelper(const HttpRequestInfo
& request
,
151 RequestPriority priority
,
152 const BoundNetLog
& log
,
153 SpdyNetworkTransactionTestParams test_params
,
154 SpdySessionDependencies
* session_deps
)
157 session_deps_(session_deps
== NULL
?
158 CreateSpdySessionDependencies(test_params
) :
160 session_(SpdySessionDependencies::SpdyCreateSession(
161 session_deps_
.get())),
163 test_params_(test_params
),
164 deterministic_(false),
165 spdy_enabled_(true) {
166 switch (test_params_
.ssl_type
) {
179 ~NormalSpdyTransactionHelper() {
180 // Any test which doesn't close the socket by sending it an EOF will
181 // have a valid session left open, which leaks the entire session pool.
182 // This is just fine - in fact, some of our tests intentionally do this
183 // so that we can check consistency of the SpdySessionPool as the test
184 // finishes. If we had put an EOF on the socket, the SpdySession would
185 // have closed and we wouldn't be able to check the consistency.
187 // Forcefully close existing sessions here.
188 session()->spdy_session_pool()->CloseAllSessions();
191 void SetDeterministic() {
192 session_
= SpdySessionDependencies::SpdyCreateSessionDeterministic(
193 session_deps_
.get());
194 deterministic_
= true;
197 void SetSpdyDisabled() {
198 spdy_enabled_
= false;
202 void RunPreTestSetup() {
203 if (!session_deps_
.get())
204 session_deps_
.reset(CreateSpdySessionDependencies(test_params_
));
205 if (!session_
.get()) {
206 session_
= SpdySessionDependencies::SpdyCreateSession(
207 session_deps_
.get());
210 // We're now ready to use SSL-npn SPDY.
211 trans_
.reset(new HttpNetworkTransaction(priority_
, session_
.get()));
214 // Start the transaction, read some data, finish.
215 void RunDefaultTest() {
216 if (!StartDefaultTest())
221 bool StartDefaultTest() {
222 output_
.rv
= trans_
->Start(&request_
, callback_
.callback(), log_
);
224 // We expect an IO Pending or some sort of error.
225 EXPECT_LT(output_
.rv
, 0);
226 return output_
.rv
== ERR_IO_PENDING
;
229 void FinishDefaultTest() {
230 output_
.rv
= callback_
.WaitForResult();
231 if (output_
.rv
!= OK
) {
232 session_
->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED
);
237 const HttpResponseInfo
* response
= trans_
->GetResponseInfo();
238 ASSERT_TRUE(response
!= NULL
);
239 ASSERT_TRUE(response
->headers
.get() != NULL
);
240 EXPECT_EQ("HTTP/1.1 200 OK", response
->headers
->GetStatusLine());
241 EXPECT_EQ(spdy_enabled_
, response
->was_fetched_via_spdy
);
242 if (HttpStreamFactory::spdy_enabled()) {
244 HttpResponseInfo::ConnectionInfoFromNextProto(
245 test_params_
.protocol
),
246 response
->connection_info
);
248 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1
,
249 response
->connection_info
);
251 if (test_params_
.ssl_type
== SPDYNPN
&& spdy_enabled_
) {
252 EXPECT_TRUE(response
->was_npn_negotiated
);
254 EXPECT_TRUE(!response
->was_npn_negotiated
);
256 // If SPDY is not enabled, a HTTP request should not be diverted
257 // over a SSL session.
258 if (!spdy_enabled_
) {
259 EXPECT_EQ(request_
.url
.SchemeIs("https"),
260 response
->was_npn_negotiated
);
262 EXPECT_EQ("127.0.0.1", response
->socket_address
.host());
263 EXPECT_EQ(port_
, response
->socket_address
.port());
264 output_
.status_line
= response
->headers
->GetStatusLine();
265 output_
.response_info
= *response
; // Make a copy so we can verify.
266 output_
.rv
= ReadTransaction(trans_
.get(), &output_
.response_data
);
269 void FinishDefaultTestWithoutVerification() {
270 output_
.rv
= callback_
.WaitForResult();
271 if (output_
.rv
!= OK
)
272 session_
->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED
);
275 // Most tests will want to call this function. In particular, the MockReads
276 // should end with an empty read, and that read needs to be processed to
277 // ensure proper deletion of the spdy_session_pool.
278 void VerifyDataConsumed() {
279 for (DataVector::iterator it
= data_vector_
.begin();
280 it
!= data_vector_
.end(); ++it
) {
281 EXPECT_TRUE((*it
)->at_read_eof()) << "Read count: "
282 << (*it
)->read_count()
284 << (*it
)->read_index();
285 EXPECT_TRUE((*it
)->at_write_eof()) << "Write count: "
286 << (*it
)->write_count()
288 << (*it
)->write_index();
292 // Occasionally a test will expect to error out before certain reads are
293 // processed. In that case we want to explicitly ensure that the reads were
295 void VerifyDataNotConsumed() {
296 for (DataVector::iterator it
= data_vector_
.begin();
297 it
!= data_vector_
.end(); ++it
) {
298 EXPECT_TRUE(!(*it
)->at_read_eof()) << "Read count: "
299 << (*it
)->read_count()
301 << (*it
)->read_index();
302 EXPECT_TRUE(!(*it
)->at_write_eof()) << "Write count: "
303 << (*it
)->write_count()
305 << (*it
)->write_index();
309 void RunToCompletion(StaticSocketDataProvider
* data
) {
313 VerifyDataConsumed();
316 void RunToCompletionWithSSLData(
317 StaticSocketDataProvider
* data
,
318 scoped_ptr
<SSLSocketDataProvider
> ssl_provider
) {
320 AddDataWithSSLSocketDataProvider(data
, ssl_provider
.Pass());
322 VerifyDataConsumed();
325 void AddData(StaticSocketDataProvider
* data
) {
326 scoped_ptr
<SSLSocketDataProvider
> ssl_provider(
327 new SSLSocketDataProvider(ASYNC
, OK
));
328 AddDataWithSSLSocketDataProvider(data
, ssl_provider
.Pass());
331 void AddDataWithSSLSocketDataProvider(
332 StaticSocketDataProvider
* data
,
333 scoped_ptr
<SSLSocketDataProvider
> ssl_provider
) {
334 DCHECK(!deterministic_
);
335 data_vector_
.push_back(data
);
336 if (test_params_
.ssl_type
== SPDYNPN
)
337 ssl_provider
->SetNextProto(test_params_
.protocol
);
339 if (test_params_
.ssl_type
== SPDYNPN
||
340 test_params_
.ssl_type
== SPDYSSL
) {
341 session_deps_
->socket_factory
->AddSSLSocketDataProvider(
344 ssl_vector_
.push_back(ssl_provider
.release());
346 session_deps_
->socket_factory
->AddSocketDataProvider(data
);
347 if (test_params_
.ssl_type
== SPDYNPN
) {
348 MockConnect
never_finishing_connect(SYNCHRONOUS
, ERR_IO_PENDING
);
349 StaticSocketDataProvider
* hanging_non_alternate_protocol_socket
=
350 new StaticSocketDataProvider(NULL
, 0, NULL
, 0);
351 hanging_non_alternate_protocol_socket
->set_connect_data(
352 never_finishing_connect
);
353 session_deps_
->socket_factory
->AddSocketDataProvider(
354 hanging_non_alternate_protocol_socket
);
355 alternate_vector_
.push_back(hanging_non_alternate_protocol_socket
);
359 void AddDeterministicData(DeterministicSocketData
* data
) {
360 DCHECK(deterministic_
);
361 data_vector_
.push_back(data
);
362 SSLSocketDataProvider
* ssl_provider
=
363 new SSLSocketDataProvider(ASYNC
, OK
);
364 if (test_params_
.ssl_type
== SPDYNPN
)
365 ssl_provider
->SetNextProto(test_params_
.protocol
);
367 ssl_vector_
.push_back(ssl_provider
);
368 if (test_params_
.ssl_type
== SPDYNPN
||
369 test_params_
.ssl_type
== SPDYSSL
) {
370 session_deps_
->deterministic_socket_factory
->
371 AddSSLSocketDataProvider(ssl_provider
);
373 session_deps_
->deterministic_socket_factory
->AddSocketDataProvider(data
);
374 if (test_params_
.ssl_type
== SPDYNPN
) {
375 MockConnect
never_finishing_connect(SYNCHRONOUS
, ERR_IO_PENDING
);
376 DeterministicSocketData
* hanging_non_alternate_protocol_socket
=
377 new DeterministicSocketData(NULL
, 0, NULL
, 0);
378 hanging_non_alternate_protocol_socket
->set_connect_data(
379 never_finishing_connect
);
380 session_deps_
->deterministic_socket_factory
->AddSocketDataProvider(
381 hanging_non_alternate_protocol_socket
);
382 alternate_deterministic_vector_
.push_back(
383 hanging_non_alternate_protocol_socket
);
387 void SetSession(const scoped_refptr
<HttpNetworkSession
>& session
) {
390 HttpNetworkTransaction
* trans() { return trans_
.get(); }
391 void ResetTrans() { trans_
.reset(); }
392 TransactionHelperResult
& output() { return output_
; }
393 const HttpRequestInfo
& request() const { return request_
; }
394 const scoped_refptr
<HttpNetworkSession
>& session() const {
397 scoped_ptr
<SpdySessionDependencies
>& session_deps() {
398 return session_deps_
;
400 int port() const { return port_
; }
401 SpdyNetworkTransactionTestParams
test_params() const {
406 typedef std::vector
<StaticSocketDataProvider
*> DataVector
;
407 typedef ScopedVector
<SSLSocketDataProvider
> SSLVector
;
408 typedef ScopedVector
<StaticSocketDataProvider
> AlternateVector
;
409 typedef ScopedVector
<DeterministicSocketData
> AlternateDeterministicVector
;
410 HttpRequestInfo request_
;
411 RequestPriority priority_
;
412 scoped_ptr
<SpdySessionDependencies
> session_deps_
;
413 scoped_refptr
<HttpNetworkSession
> session_
;
414 TransactionHelperResult output_
;
415 scoped_ptr
<StaticSocketDataProvider
> first_transaction_
;
416 SSLVector ssl_vector_
;
417 TestCompletionCallback callback_
;
418 scoped_ptr
<HttpNetworkTransaction
> trans_
;
419 scoped_ptr
<HttpNetworkTransaction
> trans_http_
;
420 DataVector data_vector_
;
421 AlternateVector alternate_vector_
;
422 AlternateDeterministicVector alternate_deterministic_vector_
;
423 const BoundNetLog log_
;
424 SpdyNetworkTransactionTestParams test_params_
;
430 void ConnectStatusHelperWithExpectedStatus(const MockRead
& status
,
431 int expected_status
);
433 void ConnectStatusHelper(const MockRead
& status
);
435 const HttpRequestInfo
& CreateGetPushRequest() {
436 google_get_push_request_
.method
= "GET";
437 google_get_push_request_
.url
= GURL("http://www.google.com/foo.dat");
438 google_get_push_request_
.load_flags
= 0;
439 return google_get_push_request_
;
442 const HttpRequestInfo
& CreateGetRequest() {
443 if (!google_get_request_initialized_
) {
444 google_get_request_
.method
= "GET";
445 google_get_request_
.url
= GURL(kDefaultURL
);
446 google_get_request_
.load_flags
= 0;
447 google_get_request_initialized_
= true;
449 return google_get_request_
;
452 const HttpRequestInfo
& CreateGetRequestWithUserAgent() {
453 if (!google_get_request_initialized_
) {
454 google_get_request_
.method
= "GET";
455 google_get_request_
.url
= GURL(kDefaultURL
);
456 google_get_request_
.load_flags
= 0;
457 google_get_request_
.extra_headers
.SetHeader("User-Agent", "Chrome");
458 google_get_request_initialized_
= true;
460 return google_get_request_
;
463 const HttpRequestInfo
& CreatePostRequest() {
464 if (!google_post_request_initialized_
) {
465 ScopedVector
<UploadElementReader
> element_readers
;
466 element_readers
.push_back(
467 new UploadBytesElementReader(kUploadData
, kUploadDataSize
));
468 upload_data_stream_
.reset(
469 new ElementsUploadDataStream(element_readers
.Pass(), 0));
471 google_post_request_
.method
= "POST";
472 google_post_request_
.url
= GURL(kDefaultURL
);
473 google_post_request_
.upload_data_stream
= upload_data_stream_
.get();
474 google_post_request_initialized_
= true;
476 return google_post_request_
;
479 const HttpRequestInfo
& CreateFilePostRequest() {
480 if (!google_post_request_initialized_
) {
481 base::FilePath file_path
;
482 CHECK(base::CreateTemporaryFileInDir(temp_dir_
.path(), &file_path
));
483 CHECK_EQ(static_cast<int>(kUploadDataSize
),
484 base::WriteFile(file_path
, kUploadData
, kUploadDataSize
));
486 ScopedVector
<UploadElementReader
> element_readers
;
487 element_readers
.push_back(
488 new UploadFileElementReader(base::MessageLoopProxy::current().get(),
493 upload_data_stream_
.reset(
494 new ElementsUploadDataStream(element_readers
.Pass(), 0));
496 google_post_request_
.method
= "POST";
497 google_post_request_
.url
= GURL(kDefaultURL
);
498 google_post_request_
.upload_data_stream
= upload_data_stream_
.get();
499 google_post_request_initialized_
= true;
501 return google_post_request_
;
504 const HttpRequestInfo
& CreateUnreadableFilePostRequest() {
505 if (google_post_request_initialized_
)
506 return google_post_request_
;
508 base::FilePath file_path
;
509 CHECK(base::CreateTemporaryFileInDir(temp_dir_
.path(), &file_path
));
510 CHECK_EQ(static_cast<int>(kUploadDataSize
),
511 base::WriteFile(file_path
, kUploadData
, kUploadDataSize
));
512 CHECK(base::MakeFileUnreadable(file_path
));
514 ScopedVector
<UploadElementReader
> element_readers
;
515 element_readers
.push_back(
516 new UploadFileElementReader(base::MessageLoopProxy::current().get(),
521 upload_data_stream_
.reset(
522 new ElementsUploadDataStream(element_readers
.Pass(), 0));
524 google_post_request_
.method
= "POST";
525 google_post_request_
.url
= GURL(kDefaultURL
);
526 google_post_request_
.upload_data_stream
= upload_data_stream_
.get();
527 google_post_request_initialized_
= true;
528 return google_post_request_
;
531 const HttpRequestInfo
& CreateComplexPostRequest() {
532 if (!google_post_request_initialized_
) {
533 const int kFileRangeOffset
= 1;
534 const int kFileRangeLength
= 3;
535 CHECK_LT(kFileRangeOffset
+ kFileRangeLength
, kUploadDataSize
);
537 base::FilePath file_path
;
538 CHECK(base::CreateTemporaryFileInDir(temp_dir_
.path(), &file_path
));
539 CHECK_EQ(static_cast<int>(kUploadDataSize
),
540 base::WriteFile(file_path
, kUploadData
, kUploadDataSize
));
542 ScopedVector
<UploadElementReader
> element_readers
;
543 element_readers
.push_back(
544 new UploadBytesElementReader(kUploadData
, kFileRangeOffset
));
545 element_readers
.push_back(
546 new UploadFileElementReader(base::MessageLoopProxy::current().get(),
551 element_readers
.push_back(new UploadBytesElementReader(
552 kUploadData
+ kFileRangeOffset
+ kFileRangeLength
,
553 kUploadDataSize
- (kFileRangeOffset
+ kFileRangeLength
)));
554 upload_data_stream_
.reset(
555 new ElementsUploadDataStream(element_readers
.Pass(), 0));
557 google_post_request_
.method
= "POST";
558 google_post_request_
.url
= GURL(kDefaultURL
);
559 google_post_request_
.upload_data_stream
= upload_data_stream_
.get();
560 google_post_request_initialized_
= true;
562 return google_post_request_
;
565 const HttpRequestInfo
& CreateChunkedPostRequest() {
566 if (!google_chunked_post_request_initialized_
) {
567 upload_chunked_data_stream_
.reset(new ChunkedUploadDataStream(0));
568 google_chunked_post_request_
.method
= "POST";
569 google_chunked_post_request_
.url
= GURL(kDefaultURL
);
570 google_chunked_post_request_
.upload_data_stream
=
571 upload_chunked_data_stream_
.get();
572 google_chunked_post_request_initialized_
= true;
574 return google_chunked_post_request_
;
577 // Read the result of a particular transaction, knowing that we've got
578 // multiple transactions in the read pipeline; so as we read, we may have
579 // to skip over data destined for other transactions while we consume
580 // the data for |trans|.
581 int ReadResult(HttpNetworkTransaction
* trans
,
582 StaticSocketDataProvider
* data
,
583 std::string
* result
) {
584 const int kSize
= 3000;
587 scoped_refptr
<IOBufferWithSize
> buf(new IOBufferWithSize(kSize
));
588 TestCompletionCallback callback
;
590 int rv
= trans
->Read(buf
.get(), kSize
, callback
.callback());
591 if (rv
== ERR_IO_PENDING
) {
592 // Multiple transactions may be in the data set. Keep pulling off
593 // reads until we complete our callback.
594 while (!callback
.have_result()) {
595 data
->CompleteRead();
596 base::RunLoop().RunUntilIdle();
598 rv
= callback
.WaitForResult();
599 } else if (rv
<= 0) {
602 result
->append(buf
->data(), rv
);
608 void VerifyStreamsClosed(const NormalSpdyTransactionHelper
& helper
) {
609 // This lengthy block is reaching into the pool to dig out the active
610 // session. Once we have the session, we verify that the streams are
611 // all closed and not leaked at this point.
612 const GURL
& url
= helper
.request().url
;
613 int port
= helper
.test_params().ssl_type
== SPDYNPN
? 443 : 80;
614 HostPortPair
host_port_pair(url
.host(), port
);
615 SpdySessionKey
key(host_port_pair
, ProxyServer::Direct(),
616 PRIVACY_MODE_DISABLED
);
618 const scoped_refptr
<HttpNetworkSession
>& session
= helper
.session();
619 base::WeakPtr
<SpdySession
> spdy_session
=
620 session
->spdy_session_pool()->FindAvailableSession(key
, log
);
621 ASSERT_TRUE(spdy_session
!= NULL
);
622 EXPECT_EQ(0u, spdy_session
->num_active_streams());
623 EXPECT_EQ(0u, spdy_session
->num_unclaimed_pushed_streams());
626 void RunServerPushTest(OrderedSocketData
* data
,
627 HttpResponseInfo
* response
,
628 HttpResponseInfo
* push_response
,
629 const std::string
& expected
) {
630 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
631 BoundNetLog(), GetParam(), NULL
);
632 helper
.RunPreTestSetup();
633 helper
.AddData(data
);
635 HttpNetworkTransaction
* trans
= helper
.trans();
637 // Start the transaction with basic parameters.
638 TestCompletionCallback callback
;
639 int rv
= trans
->Start(
640 &CreateGetRequest(), callback
.callback(), BoundNetLog());
641 EXPECT_EQ(ERR_IO_PENDING
, rv
);
642 rv
= callback
.WaitForResult();
644 // Request the pushed path.
645 scoped_ptr
<HttpNetworkTransaction
> trans2(
646 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
648 &CreateGetPushRequest(), callback
.callback(), BoundNetLog());
649 EXPECT_EQ(ERR_IO_PENDING
, rv
);
650 base::RunLoop().RunUntilIdle();
652 // The data for the pushed path may be coming in more than 1 frame. Compile
653 // the results into a single string.
655 // Read the server push body.
657 ReadResult(trans2
.get(), data
, &result2
);
658 // Read the response body.
660 ReadResult(trans
, data
, &result
);
662 // Verify that we consumed all test data.
663 EXPECT_TRUE(data
->at_read_eof());
664 EXPECT_TRUE(data
->at_write_eof());
666 // Verify that the received push data is same as the expected push data.
667 EXPECT_EQ(result2
.compare(expected
), 0) << "Received data: "
669 << "||||| Expected data: "
672 // Verify the SYN_REPLY.
673 // Copy the response info, because trans goes away.
674 *response
= *trans
->GetResponseInfo();
675 *push_response
= *trans2
->GetResponseInfo();
677 VerifyStreamsClosed(helper
);
680 static void DeleteSessionCallback(NormalSpdyTransactionHelper
* helper
,
682 helper
->ResetTrans();
685 static void StartTransactionCallback(
686 const scoped_refptr
<HttpNetworkSession
>& session
,
688 scoped_ptr
<HttpNetworkTransaction
> trans(
689 new HttpNetworkTransaction(DEFAULT_PRIORITY
, session
.get()));
690 TestCompletionCallback callback
;
691 HttpRequestInfo request
;
692 request
.method
= "GET";
693 request
.url
= GURL("http://www.google.com/");
694 request
.load_flags
= 0;
695 int rv
= trans
->Start(&request
, callback
.callback(), BoundNetLog());
696 EXPECT_EQ(ERR_IO_PENDING
, rv
);
697 callback
.WaitForResult();
700 ChunkedUploadDataStream
* upload_chunked_data_stream() const {
701 return upload_chunked_data_stream_
.get();
704 SpdyTestUtil spdy_util_
;
707 scoped_ptr
<ChunkedUploadDataStream
> upload_chunked_data_stream_
;
708 scoped_ptr
<UploadDataStream
> upload_data_stream_
;
709 bool google_get_request_initialized_
;
710 bool google_post_request_initialized_
;
711 bool google_chunked_post_request_initialized_
;
712 HttpRequestInfo google_get_request_
;
713 HttpRequestInfo google_post_request_
;
714 HttpRequestInfo google_chunked_post_request_
;
715 HttpRequestInfo google_get_push_request_
;
716 base::ScopedTempDir temp_dir_
;
719 //-----------------------------------------------------------------------------
720 // All tests are run with three different connection types: SPDY after NPN
721 // negotiation, SPDY without SSL, and SPDY with SSL.
723 // TODO(akalin): Use ::testing::Combine() when we are able to use
725 INSTANTIATE_TEST_CASE_P(
727 SpdyNetworkTransactionTest
,
729 SpdyNetworkTransactionTestParams(kProtoSPDY31
, SPDYNOSSL
),
730 SpdyNetworkTransactionTestParams(kProtoSPDY31
, SPDYSSL
),
731 SpdyNetworkTransactionTestParams(kProtoSPDY31
, SPDYNPN
),
732 SpdyNetworkTransactionTestParams(kProtoSPDY4_14
, SPDYNOSSL
),
733 SpdyNetworkTransactionTestParams(kProtoSPDY4_14
, SPDYSSL
),
734 SpdyNetworkTransactionTestParams(kProtoSPDY4_14
, SPDYNPN
),
735 SpdyNetworkTransactionTestParams(kProtoSPDY4
, SPDYNOSSL
),
736 SpdyNetworkTransactionTestParams(kProtoSPDY4
, SPDYSSL
),
737 SpdyNetworkTransactionTestParams(kProtoSPDY4
, SPDYNPN
)));
739 // Verify HttpNetworkTransaction constructor.
740 TEST_P(SpdyNetworkTransactionTest
, Constructor
) {
741 scoped_ptr
<SpdySessionDependencies
> session_deps(
742 CreateSpdySessionDependencies(GetParam()));
743 scoped_refptr
<HttpNetworkSession
> session(
744 SpdySessionDependencies::SpdyCreateSession(session_deps
.get()));
745 scoped_ptr
<HttpTransaction
> trans(
746 new HttpNetworkTransaction(DEFAULT_PRIORITY
, session
.get()));
749 TEST_P(SpdyNetworkTransactionTest
, Get
) {
750 // Construct the request.
751 scoped_ptr
<SpdyFrame
> req(
752 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
753 MockWrite writes
[] = { CreateMockWrite(*req
) };
755 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
756 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
758 CreateMockRead(*resp
),
759 CreateMockRead(*body
),
760 MockRead(ASYNC
, 0, 0) // EOF
763 DelayedSocketData
data(1, reads
, arraysize(reads
),
764 writes
, arraysize(writes
));
765 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
766 BoundNetLog(), GetParam(), NULL
);
767 helper
.RunToCompletion(&data
);
768 TransactionHelperResult out
= helper
.output();
769 EXPECT_EQ(OK
, out
.rv
);
770 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
771 EXPECT_EQ("hello!", out
.response_data
);
774 TEST_P(SpdyNetworkTransactionTest
, GetAtEachPriority
) {
775 for (RequestPriority p
= MINIMUM_PRIORITY
; p
<= MAXIMUM_PRIORITY
;
776 p
= RequestPriority(p
+ 1)) {
777 // Construct the request.
778 scoped_ptr
<SpdyFrame
> req(
779 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, p
, true));
780 MockWrite writes
[] = { CreateMockWrite(*req
) };
782 SpdyPriority spdy_prio
= 0;
783 EXPECT_TRUE(GetSpdyPriority(spdy_util_
.spdy_version(), *req
, &spdy_prio
));
784 // this repeats the RequestPriority-->SpdyPriority mapping from
785 // SpdyFramer::ConvertRequestPriorityToSpdyPriority to make
786 // sure it's being done right.
787 if (spdy_util_
.spdy_version() < SPDY3
) {
790 EXPECT_EQ(0, spdy_prio
);
793 EXPECT_EQ(1, spdy_prio
);
797 EXPECT_EQ(2, spdy_prio
);
800 EXPECT_EQ(3, spdy_prio
);
808 EXPECT_EQ(0, spdy_prio
);
811 EXPECT_EQ(1, spdy_prio
);
814 EXPECT_EQ(2, spdy_prio
);
817 EXPECT_EQ(3, spdy_prio
);
820 EXPECT_EQ(4, spdy_prio
);
827 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
828 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
830 CreateMockRead(*resp
),
831 CreateMockRead(*body
),
832 MockRead(ASYNC
, 0, 0) // EOF
835 DelayedSocketData
data(1, reads
, arraysize(reads
),
836 writes
, arraysize(writes
));
837 HttpRequestInfo http_req
= CreateGetRequest();
839 NormalSpdyTransactionHelper
helper(http_req
, p
, BoundNetLog(),
841 helper
.RunToCompletion(&data
);
842 TransactionHelperResult out
= helper
.output();
843 EXPECT_EQ(OK
, out
.rv
);
844 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
845 EXPECT_EQ("hello!", out
.response_data
);
849 // Start three gets simultaniously; making sure that multiplexed
850 // streams work properly.
852 // This can't use the TransactionHelper method, since it only
853 // handles a single transaction, and finishes them as soon
854 // as it launches them.
856 // TODO(gavinp): create a working generalized TransactionHelper that
857 // can allow multiple streams in flight.
859 TEST_P(SpdyNetworkTransactionTest
, ThreeGets
) {
860 scoped_ptr
<SpdyFrame
> req(
861 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
862 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
863 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, false));
864 scoped_ptr
<SpdyFrame
> fbody(spdy_util_
.ConstructSpdyBodyFrame(1, true));
866 scoped_ptr
<SpdyFrame
> req2(
867 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 3, LOWEST
, true));
868 scoped_ptr
<SpdyFrame
> resp2(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 3));
869 scoped_ptr
<SpdyFrame
> body2(spdy_util_
.ConstructSpdyBodyFrame(3, false));
870 scoped_ptr
<SpdyFrame
> fbody2(spdy_util_
.ConstructSpdyBodyFrame(3, true));
872 scoped_ptr
<SpdyFrame
> req3(
873 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 5, LOWEST
, true));
874 scoped_ptr
<SpdyFrame
> resp3(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 5));
875 scoped_ptr
<SpdyFrame
> body3(spdy_util_
.ConstructSpdyBodyFrame(5, false));
876 scoped_ptr
<SpdyFrame
> fbody3(spdy_util_
.ConstructSpdyBodyFrame(5, true));
878 MockWrite writes
[] = {
879 CreateMockWrite(*req
),
880 CreateMockWrite(*req2
),
881 CreateMockWrite(*req3
),
884 CreateMockRead(*resp
, 1),
885 CreateMockRead(*body
),
886 CreateMockRead(*resp2
, 4),
887 CreateMockRead(*body2
),
888 CreateMockRead(*resp3
, 7),
889 CreateMockRead(*body3
),
891 CreateMockRead(*fbody
),
892 CreateMockRead(*fbody2
),
893 CreateMockRead(*fbody3
),
895 MockRead(ASYNC
, 0, 0), // EOF
897 OrderedSocketData
data(reads
, arraysize(reads
),
898 writes
, arraysize(writes
));
899 OrderedSocketData
data_placeholder(NULL
, 0, NULL
, 0);
902 TransactionHelperResult out
;
903 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
904 BoundNetLog(), GetParam(), NULL
);
905 helper
.RunPreTestSetup();
906 helper
.AddData(&data
);
907 // We require placeholder data because three get requests are sent out, so
908 // there needs to be three sets of SSL connection data.
909 helper
.AddData(&data_placeholder
);
910 helper
.AddData(&data_placeholder
);
911 scoped_ptr
<HttpNetworkTransaction
> trans1(
912 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
913 scoped_ptr
<HttpNetworkTransaction
> trans2(
914 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
915 scoped_ptr
<HttpNetworkTransaction
> trans3(
916 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
918 TestCompletionCallback callback1
;
919 TestCompletionCallback callback2
;
920 TestCompletionCallback callback3
;
922 HttpRequestInfo httpreq1
= CreateGetRequest();
923 HttpRequestInfo httpreq2
= CreateGetRequest();
924 HttpRequestInfo httpreq3
= CreateGetRequest();
926 out
.rv
= trans1
->Start(&httpreq1
, callback1
.callback(), log
);
927 ASSERT_EQ(ERR_IO_PENDING
, out
.rv
);
928 out
.rv
= trans2
->Start(&httpreq2
, callback2
.callback(), log
);
929 ASSERT_EQ(ERR_IO_PENDING
, out
.rv
);
930 out
.rv
= trans3
->Start(&httpreq3
, callback3
.callback(), log
);
931 ASSERT_EQ(ERR_IO_PENDING
, out
.rv
);
933 out
.rv
= callback1
.WaitForResult();
934 ASSERT_EQ(OK
, out
.rv
);
935 out
.rv
= callback3
.WaitForResult();
936 ASSERT_EQ(OK
, out
.rv
);
938 const HttpResponseInfo
* response1
= trans1
->GetResponseInfo();
939 EXPECT_TRUE(response1
->headers
.get() != NULL
);
940 EXPECT_TRUE(response1
->was_fetched_via_spdy
);
941 out
.status_line
= response1
->headers
->GetStatusLine();
942 out
.response_info
= *response1
;
944 trans2
->GetResponseInfo();
946 out
.rv
= ReadTransaction(trans1
.get(), &out
.response_data
);
947 helper
.VerifyDataConsumed();
948 EXPECT_EQ(OK
, out
.rv
);
950 EXPECT_EQ(OK
, out
.rv
);
951 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
952 EXPECT_EQ("hello!hello!", out
.response_data
);
955 TEST_P(SpdyNetworkTransactionTest
, TwoGetsLateBinding
) {
956 scoped_ptr
<SpdyFrame
> req(
957 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
958 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
959 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, false));
960 scoped_ptr
<SpdyFrame
> fbody(spdy_util_
.ConstructSpdyBodyFrame(1, true));
962 scoped_ptr
<SpdyFrame
> req2(
963 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 3, LOWEST
, true));
964 scoped_ptr
<SpdyFrame
> resp2(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 3));
965 scoped_ptr
<SpdyFrame
> body2(spdy_util_
.ConstructSpdyBodyFrame(3, false));
966 scoped_ptr
<SpdyFrame
> fbody2(spdy_util_
.ConstructSpdyBodyFrame(3, true));
968 MockWrite writes
[] = {
969 CreateMockWrite(*req
),
970 CreateMockWrite(*req2
),
973 CreateMockRead(*resp
, 1),
974 CreateMockRead(*body
),
975 CreateMockRead(*resp2
, 4),
976 CreateMockRead(*body2
),
977 CreateMockRead(*fbody
),
978 CreateMockRead(*fbody2
),
979 MockRead(ASYNC
, 0, 0), // EOF
981 OrderedSocketData
data(reads
, arraysize(reads
),
982 writes
, arraysize(writes
));
984 MockConnect
never_finishing_connect(SYNCHRONOUS
, ERR_IO_PENDING
);
986 OrderedSocketData
data_placeholder(NULL
, 0, NULL
, 0);
987 data_placeholder
.set_connect_data(never_finishing_connect
);
990 TransactionHelperResult out
;
991 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
992 BoundNetLog(), GetParam(), NULL
);
993 helper
.RunPreTestSetup();
994 helper
.AddData(&data
);
995 // We require placeholder data because two get requests are sent out, so
996 // there needs to be two sets of SSL connection data.
997 helper
.AddData(&data_placeholder
);
998 scoped_ptr
<HttpNetworkTransaction
> trans1(
999 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
1000 scoped_ptr
<HttpNetworkTransaction
> trans2(
1001 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
1003 TestCompletionCallback callback1
;
1004 TestCompletionCallback callback2
;
1006 HttpRequestInfo httpreq1
= CreateGetRequest();
1007 HttpRequestInfo httpreq2
= CreateGetRequest();
1009 out
.rv
= trans1
->Start(&httpreq1
, callback1
.callback(), log
);
1010 ASSERT_EQ(ERR_IO_PENDING
, out
.rv
);
1011 out
.rv
= trans2
->Start(&httpreq2
, callback2
.callback(), log
);
1012 ASSERT_EQ(ERR_IO_PENDING
, out
.rv
);
1014 out
.rv
= callback1
.WaitForResult();
1015 ASSERT_EQ(OK
, out
.rv
);
1016 out
.rv
= callback2
.WaitForResult();
1017 ASSERT_EQ(OK
, out
.rv
);
1019 const HttpResponseInfo
* response1
= trans1
->GetResponseInfo();
1020 EXPECT_TRUE(response1
->headers
.get() != NULL
);
1021 EXPECT_TRUE(response1
->was_fetched_via_spdy
);
1022 out
.status_line
= response1
->headers
->GetStatusLine();
1023 out
.response_info
= *response1
;
1024 out
.rv
= ReadTransaction(trans1
.get(), &out
.response_data
);
1025 EXPECT_EQ(OK
, out
.rv
);
1026 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1027 EXPECT_EQ("hello!hello!", out
.response_data
);
1029 const HttpResponseInfo
* response2
= trans2
->GetResponseInfo();
1030 EXPECT_TRUE(response2
->headers
.get() != NULL
);
1031 EXPECT_TRUE(response2
->was_fetched_via_spdy
);
1032 out
.status_line
= response2
->headers
->GetStatusLine();
1033 out
.response_info
= *response2
;
1034 out
.rv
= ReadTransaction(trans2
.get(), &out
.response_data
);
1035 EXPECT_EQ(OK
, out
.rv
);
1036 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1037 EXPECT_EQ("hello!hello!", out
.response_data
);
1039 helper
.VerifyDataConsumed();
1042 TEST_P(SpdyNetworkTransactionTest
, TwoGetsLateBindingFromPreconnect
) {
1043 scoped_ptr
<SpdyFrame
> req(
1044 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
1045 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
1046 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, false));
1047 scoped_ptr
<SpdyFrame
> fbody(spdy_util_
.ConstructSpdyBodyFrame(1, true));
1049 scoped_ptr
<SpdyFrame
> req2(
1050 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 3, LOWEST
, true));
1051 scoped_ptr
<SpdyFrame
> resp2(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 3));
1052 scoped_ptr
<SpdyFrame
> body2(spdy_util_
.ConstructSpdyBodyFrame(3, false));
1053 scoped_ptr
<SpdyFrame
> fbody2(spdy_util_
.ConstructSpdyBodyFrame(3, true));
1055 MockWrite writes
[] = {
1056 CreateMockWrite(*req
),
1057 CreateMockWrite(*req2
),
1059 MockRead reads
[] = {
1060 CreateMockRead(*resp
, 1),
1061 CreateMockRead(*body
),
1062 CreateMockRead(*resp2
, 4),
1063 CreateMockRead(*body2
),
1064 CreateMockRead(*fbody
),
1065 CreateMockRead(*fbody2
),
1066 MockRead(ASYNC
, 0, 0), // EOF
1068 OrderedSocketData
preconnect_data(reads
, arraysize(reads
),
1069 writes
, arraysize(writes
));
1071 MockConnect
never_finishing_connect(ASYNC
, ERR_IO_PENDING
);
1073 OrderedSocketData
data_placeholder(NULL
, 0, NULL
, 0);
1074 data_placeholder
.set_connect_data(never_finishing_connect
);
1077 TransactionHelperResult out
;
1078 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
1079 BoundNetLog(), GetParam(), NULL
);
1080 helper
.RunPreTestSetup();
1081 helper
.AddData(&preconnect_data
);
1082 // We require placeholder data because 3 connections are attempted (first is
1083 // the preconnect, 2nd and 3rd are the never finished connections.
1084 helper
.AddData(&data_placeholder
);
1085 helper
.AddData(&data_placeholder
);
1087 scoped_ptr
<HttpNetworkTransaction
> trans1(
1088 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
1089 scoped_ptr
<HttpNetworkTransaction
> trans2(
1090 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
1092 TestCompletionCallback callback1
;
1093 TestCompletionCallback callback2
;
1095 HttpRequestInfo httpreq
= CreateGetRequest();
1097 // Preconnect the first.
1098 SSLConfig preconnect_ssl_config
;
1099 helper
.session()->ssl_config_service()->GetSSLConfig(&preconnect_ssl_config
);
1100 HttpStreamFactory
* http_stream_factory
=
1101 helper
.session()->http_stream_factory();
1102 helper
.session()->GetNextProtos(&preconnect_ssl_config
.next_protos
);
1104 http_stream_factory
->PreconnectStreams(
1105 1, httpreq
, DEFAULT_PRIORITY
,
1106 preconnect_ssl_config
, preconnect_ssl_config
);
1108 out
.rv
= trans1
->Start(&httpreq
, callback1
.callback(), log
);
1109 ASSERT_EQ(ERR_IO_PENDING
, out
.rv
);
1110 out
.rv
= trans2
->Start(&httpreq
, callback2
.callback(), log
);
1111 ASSERT_EQ(ERR_IO_PENDING
, out
.rv
);
1113 out
.rv
= callback1
.WaitForResult();
1114 ASSERT_EQ(OK
, out
.rv
);
1115 out
.rv
= callback2
.WaitForResult();
1116 ASSERT_EQ(OK
, out
.rv
);
1118 const HttpResponseInfo
* response1
= trans1
->GetResponseInfo();
1119 EXPECT_TRUE(response1
->headers
.get() != NULL
);
1120 EXPECT_TRUE(response1
->was_fetched_via_spdy
);
1121 out
.status_line
= response1
->headers
->GetStatusLine();
1122 out
.response_info
= *response1
;
1123 out
.rv
= ReadTransaction(trans1
.get(), &out
.response_data
);
1124 EXPECT_EQ(OK
, out
.rv
);
1125 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1126 EXPECT_EQ("hello!hello!", out
.response_data
);
1128 const HttpResponseInfo
* response2
= trans2
->GetResponseInfo();
1129 EXPECT_TRUE(response2
->headers
.get() != NULL
);
1130 EXPECT_TRUE(response2
->was_fetched_via_spdy
);
1131 out
.status_line
= response2
->headers
->GetStatusLine();
1132 out
.response_info
= *response2
;
1133 out
.rv
= ReadTransaction(trans2
.get(), &out
.response_data
);
1134 EXPECT_EQ(OK
, out
.rv
);
1135 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1136 EXPECT_EQ("hello!hello!", out
.response_data
);
1138 helper
.VerifyDataConsumed();
1141 // Similar to ThreeGets above, however this test adds a SETTINGS
1142 // frame. The SETTINGS frame is read during the IO loop waiting on
1143 // the first transaction completion, and sets a maximum concurrent
1144 // stream limit of 1. This means that our IO loop exists after the
1145 // second transaction completes, so we can assert on read_index().
1146 TEST_P(SpdyNetworkTransactionTest
, ThreeGetsWithMaxConcurrent
) {
1147 // Construct the request.
1148 scoped_ptr
<SpdyFrame
> req(
1149 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
1150 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
1151 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, false));
1152 scoped_ptr
<SpdyFrame
> fbody(spdy_util_
.ConstructSpdyBodyFrame(1, true));
1154 scoped_ptr
<SpdyFrame
> req2(
1155 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 3, LOWEST
, true));
1156 scoped_ptr
<SpdyFrame
> resp2(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 3));
1157 scoped_ptr
<SpdyFrame
> body2(spdy_util_
.ConstructSpdyBodyFrame(3, false));
1158 scoped_ptr
<SpdyFrame
> fbody2(spdy_util_
.ConstructSpdyBodyFrame(3, true));
1160 scoped_ptr
<SpdyFrame
> req3(
1161 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 5, LOWEST
, true));
1162 scoped_ptr
<SpdyFrame
> resp3(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 5));
1163 scoped_ptr
<SpdyFrame
> body3(spdy_util_
.ConstructSpdyBodyFrame(5, false));
1164 scoped_ptr
<SpdyFrame
> fbody3(spdy_util_
.ConstructSpdyBodyFrame(5, true));
1166 SettingsMap settings
;
1167 const uint32 max_concurrent_streams
= 1;
1168 settings
[SETTINGS_MAX_CONCURRENT_STREAMS
] =
1169 SettingsFlagsAndValue(SETTINGS_FLAG_NONE
, max_concurrent_streams
);
1170 scoped_ptr
<SpdyFrame
> settings_frame(
1171 spdy_util_
.ConstructSpdySettings(settings
));
1172 scoped_ptr
<SpdyFrame
> settings_ack(spdy_util_
.ConstructSpdySettingsAck());
1174 MockWrite writes
[] = {
1175 CreateMockWrite(*req
),
1176 CreateMockWrite(*settings_ack
, 2),
1177 CreateMockWrite(*req2
),
1178 CreateMockWrite(*req3
),
1181 MockRead reads
[] = {
1182 CreateMockRead(*settings_frame
, 1),
1183 CreateMockRead(*resp
),
1184 CreateMockRead(*body
),
1185 CreateMockRead(*fbody
),
1186 CreateMockRead(*resp2
, 8),
1187 CreateMockRead(*body2
),
1188 CreateMockRead(*fbody2
),
1189 CreateMockRead(*resp3
, 13),
1190 CreateMockRead(*body3
),
1191 CreateMockRead(*fbody3
),
1193 MockRead(ASYNC
, 0, 0), // EOF
1196 OrderedSocketData
data(reads
, arraysize(reads
),
1197 writes
, arraysize(writes
));
1198 OrderedSocketData
data_placeholder(NULL
, 0, NULL
, 0);
1201 TransactionHelperResult out
;
1203 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
1204 BoundNetLog(), GetParam(), NULL
);
1205 helper
.RunPreTestSetup();
1206 helper
.AddData(&data
);
1207 // We require placeholder data because three get requests are sent out, so
1208 // there needs to be three sets of SSL connection data.
1209 helper
.AddData(&data_placeholder
);
1210 helper
.AddData(&data_placeholder
);
1211 scoped_ptr
<HttpNetworkTransaction
> trans1(
1212 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
1213 scoped_ptr
<HttpNetworkTransaction
> trans2(
1214 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
1215 scoped_ptr
<HttpNetworkTransaction
> trans3(
1216 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
1218 TestCompletionCallback callback1
;
1219 TestCompletionCallback callback2
;
1220 TestCompletionCallback callback3
;
1222 HttpRequestInfo httpreq1
= CreateGetRequest();
1223 HttpRequestInfo httpreq2
= CreateGetRequest();
1224 HttpRequestInfo httpreq3
= CreateGetRequest();
1226 out
.rv
= trans1
->Start(&httpreq1
, callback1
.callback(), log
);
1227 ASSERT_EQ(out
.rv
, ERR_IO_PENDING
);
1228 // Run transaction 1 through quickly to force a read of our SETTINGS
1230 out
.rv
= callback1
.WaitForResult();
1231 ASSERT_EQ(OK
, out
.rv
);
1233 out
.rv
= trans2
->Start(&httpreq2
, callback2
.callback(), log
);
1234 ASSERT_EQ(out
.rv
, ERR_IO_PENDING
);
1235 out
.rv
= trans3
->Start(&httpreq3
, callback3
.callback(), log
);
1236 ASSERT_EQ(out
.rv
, ERR_IO_PENDING
);
1237 out
.rv
= callback2
.WaitForResult();
1238 ASSERT_EQ(OK
, out
.rv
);
1239 EXPECT_EQ(7U, data
.read_index()); // i.e. the third trans was queued
1241 out
.rv
= callback3
.WaitForResult();
1242 ASSERT_EQ(OK
, out
.rv
);
1244 const HttpResponseInfo
* response1
= trans1
->GetResponseInfo();
1245 ASSERT_TRUE(response1
!= NULL
);
1246 EXPECT_TRUE(response1
->headers
.get() != NULL
);
1247 EXPECT_TRUE(response1
->was_fetched_via_spdy
);
1248 out
.status_line
= response1
->headers
->GetStatusLine();
1249 out
.response_info
= *response1
;
1250 out
.rv
= ReadTransaction(trans1
.get(), &out
.response_data
);
1251 EXPECT_EQ(OK
, out
.rv
);
1252 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1253 EXPECT_EQ("hello!hello!", out
.response_data
);
1255 const HttpResponseInfo
* response2
= trans2
->GetResponseInfo();
1256 out
.status_line
= response2
->headers
->GetStatusLine();
1257 out
.response_info
= *response2
;
1258 out
.rv
= ReadTransaction(trans2
.get(), &out
.response_data
);
1259 EXPECT_EQ(OK
, out
.rv
);
1260 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1261 EXPECT_EQ("hello!hello!", out
.response_data
);
1263 const HttpResponseInfo
* response3
= trans3
->GetResponseInfo();
1264 out
.status_line
= response3
->headers
->GetStatusLine();
1265 out
.response_info
= *response3
;
1266 out
.rv
= ReadTransaction(trans3
.get(), &out
.response_data
);
1267 EXPECT_EQ(OK
, out
.rv
);
1268 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1269 EXPECT_EQ("hello!hello!", out
.response_data
);
1271 helper
.VerifyDataConsumed();
1273 EXPECT_EQ(OK
, out
.rv
);
1276 // Similar to ThreeGetsWithMaxConcurrent above, however this test adds
1277 // a fourth transaction. The third and fourth transactions have
1278 // different data ("hello!" vs "hello!hello!") and because of the
1279 // user specified priority, we expect to see them inverted in
1280 // the response from the server.
1281 TEST_P(SpdyNetworkTransactionTest
, FourGetsWithMaxConcurrentPriority
) {
1282 // Construct the request.
1283 scoped_ptr
<SpdyFrame
> req(
1284 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
1285 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
1286 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, false));
1287 scoped_ptr
<SpdyFrame
> fbody(spdy_util_
.ConstructSpdyBodyFrame(1, true));
1289 scoped_ptr
<SpdyFrame
> req2(
1290 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 3, LOWEST
, true));
1291 scoped_ptr
<SpdyFrame
> resp2(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 3));
1292 scoped_ptr
<SpdyFrame
> body2(spdy_util_
.ConstructSpdyBodyFrame(3, false));
1293 scoped_ptr
<SpdyFrame
> fbody2(spdy_util_
.ConstructSpdyBodyFrame(3, true));
1295 scoped_ptr
<SpdyFrame
> req4(
1296 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 5, HIGHEST
, true));
1297 scoped_ptr
<SpdyFrame
> resp4(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 5));
1298 scoped_ptr
<SpdyFrame
> fbody4(spdy_util_
.ConstructSpdyBodyFrame(5, true));
1300 scoped_ptr
<SpdyFrame
> req3(
1301 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 7, LOWEST
, true));
1302 scoped_ptr
<SpdyFrame
> resp3(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 7));
1303 scoped_ptr
<SpdyFrame
> body3(spdy_util_
.ConstructSpdyBodyFrame(7, false));
1304 scoped_ptr
<SpdyFrame
> fbody3(spdy_util_
.ConstructSpdyBodyFrame(7, true));
1306 SettingsMap settings
;
1307 const uint32 max_concurrent_streams
= 1;
1308 settings
[SETTINGS_MAX_CONCURRENT_STREAMS
] =
1309 SettingsFlagsAndValue(SETTINGS_FLAG_NONE
, max_concurrent_streams
);
1310 scoped_ptr
<SpdyFrame
> settings_frame(
1311 spdy_util_
.ConstructSpdySettings(settings
));
1312 scoped_ptr
<SpdyFrame
> settings_ack(spdy_util_
.ConstructSpdySettingsAck());
1314 MockWrite writes
[] = { CreateMockWrite(*req
),
1315 CreateMockWrite(*settings_ack
, 2),
1316 CreateMockWrite(*req2
),
1317 CreateMockWrite(*req4
),
1318 CreateMockWrite(*req3
),
1320 MockRead reads
[] = {
1321 CreateMockRead(*settings_frame
, 1),
1322 CreateMockRead(*resp
),
1323 CreateMockRead(*body
),
1324 CreateMockRead(*fbody
),
1325 CreateMockRead(*resp2
, 8),
1326 CreateMockRead(*body2
),
1327 CreateMockRead(*fbody2
),
1328 CreateMockRead(*resp4
, 14),
1329 CreateMockRead(*fbody4
),
1330 CreateMockRead(*resp3
, 17),
1331 CreateMockRead(*body3
),
1332 CreateMockRead(*fbody3
),
1334 MockRead(ASYNC
, 0, 0), // EOF
1337 OrderedSocketData
data(reads
, arraysize(reads
),
1338 writes
, arraysize(writes
));
1339 OrderedSocketData
data_placeholder(NULL
, 0, NULL
, 0);
1342 TransactionHelperResult out
;
1343 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
1344 BoundNetLog(), GetParam(), NULL
);
1345 helper
.RunPreTestSetup();
1346 helper
.AddData(&data
);
1347 // We require placeholder data because four get requests are sent out, so
1348 // there needs to be four sets of SSL connection data.
1349 helper
.AddData(&data_placeholder
);
1350 helper
.AddData(&data_placeholder
);
1351 helper
.AddData(&data_placeholder
);
1352 scoped_ptr
<HttpNetworkTransaction
> trans1(
1353 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
1354 scoped_ptr
<HttpNetworkTransaction
> trans2(
1355 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
1356 scoped_ptr
<HttpNetworkTransaction
> trans3(
1357 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
1358 scoped_ptr
<HttpNetworkTransaction
> trans4(
1359 new HttpNetworkTransaction(HIGHEST
, helper
.session().get()));
1361 TestCompletionCallback callback1
;
1362 TestCompletionCallback callback2
;
1363 TestCompletionCallback callback3
;
1364 TestCompletionCallback callback4
;
1366 HttpRequestInfo httpreq1
= CreateGetRequest();
1367 HttpRequestInfo httpreq2
= CreateGetRequest();
1368 HttpRequestInfo httpreq3
= CreateGetRequest();
1369 HttpRequestInfo httpreq4
= CreateGetRequest();
1371 out
.rv
= trans1
->Start(&httpreq1
, callback1
.callback(), log
);
1372 ASSERT_EQ(ERR_IO_PENDING
, out
.rv
);
1373 // Run transaction 1 through quickly to force a read of our SETTINGS frame.
1374 out
.rv
= callback1
.WaitForResult();
1375 ASSERT_EQ(OK
, out
.rv
);
1377 out
.rv
= trans2
->Start(&httpreq2
, callback2
.callback(), log
);
1378 ASSERT_EQ(ERR_IO_PENDING
, out
.rv
);
1379 out
.rv
= trans3
->Start(&httpreq3
, callback3
.callback(), log
);
1380 ASSERT_EQ(ERR_IO_PENDING
, out
.rv
);
1381 out
.rv
= trans4
->Start(&httpreq4
, callback4
.callback(), log
);
1382 ASSERT_EQ(ERR_IO_PENDING
, out
.rv
);
1384 out
.rv
= callback2
.WaitForResult();
1385 ASSERT_EQ(OK
, out
.rv
);
1386 EXPECT_EQ(data
.read_index(), 7U); // i.e. the third & fourth trans queued
1388 out
.rv
= callback3
.WaitForResult();
1389 ASSERT_EQ(OK
, out
.rv
);
1391 const HttpResponseInfo
* response1
= trans1
->GetResponseInfo();
1392 EXPECT_TRUE(response1
->headers
.get() != NULL
);
1393 EXPECT_TRUE(response1
->was_fetched_via_spdy
);
1394 out
.status_line
= response1
->headers
->GetStatusLine();
1395 out
.response_info
= *response1
;
1396 out
.rv
= ReadTransaction(trans1
.get(), &out
.response_data
);
1397 EXPECT_EQ(OK
, out
.rv
);
1398 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1399 EXPECT_EQ("hello!hello!", out
.response_data
);
1401 const HttpResponseInfo
* response2
= trans2
->GetResponseInfo();
1402 out
.status_line
= response2
->headers
->GetStatusLine();
1403 out
.response_info
= *response2
;
1404 out
.rv
= ReadTransaction(trans2
.get(), &out
.response_data
);
1405 EXPECT_EQ(OK
, out
.rv
);
1406 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1407 EXPECT_EQ("hello!hello!", out
.response_data
);
1409 // notice: response3 gets two hellos, response4 gets one
1410 // hello, so we know dequeuing priority was respected.
1411 const HttpResponseInfo
* response3
= trans3
->GetResponseInfo();
1412 out
.status_line
= response3
->headers
->GetStatusLine();
1413 out
.response_info
= *response3
;
1414 out
.rv
= ReadTransaction(trans3
.get(), &out
.response_data
);
1415 EXPECT_EQ(OK
, out
.rv
);
1416 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1417 EXPECT_EQ("hello!hello!", out
.response_data
);
1419 out
.rv
= callback4
.WaitForResult();
1420 EXPECT_EQ(OK
, out
.rv
);
1421 const HttpResponseInfo
* response4
= trans4
->GetResponseInfo();
1422 out
.status_line
= response4
->headers
->GetStatusLine();
1423 out
.response_info
= *response4
;
1424 out
.rv
= ReadTransaction(trans4
.get(), &out
.response_data
);
1425 EXPECT_EQ(OK
, out
.rv
);
1426 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1427 EXPECT_EQ("hello!", out
.response_data
);
1428 helper
.VerifyDataConsumed();
1429 EXPECT_EQ(OK
, out
.rv
);
1432 // Similar to ThreeGetsMaxConcurrrent above, however, this test
1433 // deletes a session in the middle of the transaction to insure
1434 // that we properly remove pendingcreatestream objects from
1436 TEST_P(SpdyNetworkTransactionTest
, ThreeGetsWithMaxConcurrentDelete
) {
1437 // Construct the request.
1438 scoped_ptr
<SpdyFrame
> req(
1439 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
1440 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
1441 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, false));
1442 scoped_ptr
<SpdyFrame
> fbody(spdy_util_
.ConstructSpdyBodyFrame(1, true));
1444 scoped_ptr
<SpdyFrame
> req2(
1445 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 3, LOWEST
, true));
1446 scoped_ptr
<SpdyFrame
> resp2(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 3));
1447 scoped_ptr
<SpdyFrame
> body2(spdy_util_
.ConstructSpdyBodyFrame(3, false));
1448 scoped_ptr
<SpdyFrame
> fbody2(spdy_util_
.ConstructSpdyBodyFrame(3, true));
1450 SettingsMap settings
;
1451 const uint32 max_concurrent_streams
= 1;
1452 settings
[SETTINGS_MAX_CONCURRENT_STREAMS
] =
1453 SettingsFlagsAndValue(SETTINGS_FLAG_NONE
, max_concurrent_streams
);
1454 scoped_ptr
<SpdyFrame
> settings_frame(
1455 spdy_util_
.ConstructSpdySettings(settings
));
1456 scoped_ptr
<SpdyFrame
> settings_ack(spdy_util_
.ConstructSpdySettingsAck());
1458 MockWrite writes
[] = {
1459 CreateMockWrite(*req
),
1460 CreateMockWrite(*settings_ack
, 2),
1461 CreateMockWrite(*req2
),
1463 MockRead reads
[] = {
1464 CreateMockRead(*settings_frame
, 1),
1465 CreateMockRead(*resp
),
1466 CreateMockRead(*body
),
1467 CreateMockRead(*fbody
),
1468 CreateMockRead(*resp2
, 8),
1469 CreateMockRead(*body2
),
1470 CreateMockRead(*fbody2
),
1471 MockRead(ASYNC
, 0, 0), // EOF
1474 OrderedSocketData
data(reads
, arraysize(reads
),
1475 writes
, arraysize(writes
));
1476 OrderedSocketData
data_placeholder(NULL
, 0, NULL
, 0);
1479 TransactionHelperResult out
;
1480 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
1481 BoundNetLog(), GetParam(), NULL
);
1482 helper
.RunPreTestSetup();
1483 helper
.AddData(&data
);
1484 // We require placeholder data because three get requests are sent out, so
1485 // there needs to be three sets of SSL connection data.
1486 helper
.AddData(&data_placeholder
);
1487 helper
.AddData(&data_placeholder
);
1488 scoped_ptr
<HttpNetworkTransaction
> trans1(
1489 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
1490 scoped_ptr
<HttpNetworkTransaction
> trans2(
1491 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
1492 scoped_ptr
<HttpNetworkTransaction
> trans3(
1493 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
1495 TestCompletionCallback callback1
;
1496 TestCompletionCallback callback2
;
1497 TestCompletionCallback callback3
;
1499 HttpRequestInfo httpreq1
= CreateGetRequest();
1500 HttpRequestInfo httpreq2
= CreateGetRequest();
1501 HttpRequestInfo httpreq3
= CreateGetRequest();
1503 out
.rv
= trans1
->Start(&httpreq1
, callback1
.callback(), log
);
1504 ASSERT_EQ(out
.rv
, ERR_IO_PENDING
);
1505 // Run transaction 1 through quickly to force a read of our SETTINGS frame.
1506 out
.rv
= callback1
.WaitForResult();
1507 ASSERT_EQ(OK
, out
.rv
);
1509 out
.rv
= trans2
->Start(&httpreq2
, callback2
.callback(), log
);
1510 ASSERT_EQ(out
.rv
, ERR_IO_PENDING
);
1511 out
.rv
= trans3
->Start(&httpreq3
, callback3
.callback(), log
);
1512 delete trans3
.release();
1513 ASSERT_EQ(out
.rv
, ERR_IO_PENDING
);
1514 out
.rv
= callback2
.WaitForResult();
1515 ASSERT_EQ(OK
, out
.rv
);
1517 EXPECT_EQ(8U, data
.read_index());
1519 const HttpResponseInfo
* response1
= trans1
->GetResponseInfo();
1520 ASSERT_TRUE(response1
!= NULL
);
1521 EXPECT_TRUE(response1
->headers
.get() != NULL
);
1522 EXPECT_TRUE(response1
->was_fetched_via_spdy
);
1523 out
.status_line
= response1
->headers
->GetStatusLine();
1524 out
.response_info
= *response1
;
1525 out
.rv
= ReadTransaction(trans1
.get(), &out
.response_data
);
1526 EXPECT_EQ(OK
, out
.rv
);
1527 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1528 EXPECT_EQ("hello!hello!", out
.response_data
);
1530 const HttpResponseInfo
* response2
= trans2
->GetResponseInfo();
1531 ASSERT_TRUE(response2
!= NULL
);
1532 out
.status_line
= response2
->headers
->GetStatusLine();
1533 out
.response_info
= *response2
;
1534 out
.rv
= ReadTransaction(trans2
.get(), &out
.response_data
);
1535 EXPECT_EQ(OK
, out
.rv
);
1536 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1537 EXPECT_EQ("hello!hello!", out
.response_data
);
1538 helper
.VerifyDataConsumed();
1539 EXPECT_EQ(OK
, out
.rv
);
1544 // The KillerCallback will delete the transaction on error as part of the
1546 class KillerCallback
: public TestCompletionCallbackBase
{
1548 explicit KillerCallback(HttpNetworkTransaction
* transaction
)
1549 : transaction_(transaction
),
1550 callback_(base::Bind(&KillerCallback::OnComplete
,
1551 base::Unretained(this))) {
1554 ~KillerCallback() override
{}
1556 const CompletionCallback
& callback() const { return callback_
; }
1559 void OnComplete(int result
) {
1561 delete transaction_
;
1566 HttpNetworkTransaction
* transaction_
;
1567 CompletionCallback callback_
;
1572 // Similar to ThreeGetsMaxConcurrrentDelete above, however, this test
1573 // closes the socket while we have a pending transaction waiting for
1574 // a pending stream creation. http://crbug.com/52901
1575 TEST_P(SpdyNetworkTransactionTest
, ThreeGetsWithMaxConcurrentSocketClose
) {
1576 // Construct the request.
1577 scoped_ptr
<SpdyFrame
> req(
1578 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
1579 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
1580 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, false));
1581 scoped_ptr
<SpdyFrame
> fin_body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
1583 scoped_ptr
<SpdyFrame
> req2(
1584 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 3, LOWEST
, true));
1585 scoped_ptr
<SpdyFrame
> resp2(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 3));
1587 SettingsMap settings
;
1588 const uint32 max_concurrent_streams
= 1;
1589 settings
[SETTINGS_MAX_CONCURRENT_STREAMS
] =
1590 SettingsFlagsAndValue(SETTINGS_FLAG_NONE
, max_concurrent_streams
);
1591 scoped_ptr
<SpdyFrame
> settings_frame(
1592 spdy_util_
.ConstructSpdySettings(settings
));
1593 scoped_ptr
<SpdyFrame
> settings_ack(spdy_util_
.ConstructSpdySettingsAck());
1595 MockWrite writes
[] = {
1596 CreateMockWrite(*req
),
1597 CreateMockWrite(*settings_ack
, 2),
1598 CreateMockWrite(*req2
),
1600 MockRead reads
[] = {
1601 CreateMockRead(*settings_frame
, 1),
1602 CreateMockRead(*resp
),
1603 CreateMockRead(*body
),
1604 CreateMockRead(*fin_body
),
1605 CreateMockRead(*resp2
, 8),
1606 MockRead(ASYNC
, ERR_CONNECTION_RESET
, 0), // Abort!
1609 OrderedSocketData
data(reads
, arraysize(reads
),
1610 writes
, arraysize(writes
));
1611 OrderedSocketData
data_placeholder(NULL
, 0, NULL
, 0);
1614 TransactionHelperResult out
;
1615 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
1616 BoundNetLog(), GetParam(), NULL
);
1617 helper
.RunPreTestSetup();
1618 helper
.AddData(&data
);
1619 // We require placeholder data because three get requests are sent out, so
1620 // there needs to be three sets of SSL connection data.
1621 helper
.AddData(&data_placeholder
);
1622 helper
.AddData(&data_placeholder
);
1623 HttpNetworkTransaction
trans1(DEFAULT_PRIORITY
, helper
.session().get());
1624 HttpNetworkTransaction
trans2(DEFAULT_PRIORITY
, helper
.session().get());
1625 HttpNetworkTransaction
* trans3(
1626 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
1628 TestCompletionCallback callback1
;
1629 TestCompletionCallback callback2
;
1630 KillerCallback
callback3(trans3
);
1632 HttpRequestInfo httpreq1
= CreateGetRequest();
1633 HttpRequestInfo httpreq2
= CreateGetRequest();
1634 HttpRequestInfo httpreq3
= CreateGetRequest();
1636 out
.rv
= trans1
.Start(&httpreq1
, callback1
.callback(), log
);
1637 ASSERT_EQ(out
.rv
, ERR_IO_PENDING
);
1638 // Run transaction 1 through quickly to force a read of our SETTINGS frame.
1639 out
.rv
= callback1
.WaitForResult();
1640 ASSERT_EQ(OK
, out
.rv
);
1642 out
.rv
= trans2
.Start(&httpreq2
, callback2
.callback(), log
);
1643 ASSERT_EQ(out
.rv
, ERR_IO_PENDING
);
1644 out
.rv
= trans3
->Start(&httpreq3
, callback3
.callback(), log
);
1645 ASSERT_EQ(out
.rv
, ERR_IO_PENDING
);
1646 out
.rv
= callback3
.WaitForResult();
1647 ASSERT_EQ(ERR_ABORTED
, out
.rv
);
1649 EXPECT_EQ(6U, data
.read_index());
1651 const HttpResponseInfo
* response1
= trans1
.GetResponseInfo();
1652 ASSERT_TRUE(response1
!= NULL
);
1653 EXPECT_TRUE(response1
->headers
.get() != NULL
);
1654 EXPECT_TRUE(response1
->was_fetched_via_spdy
);
1655 out
.status_line
= response1
->headers
->GetStatusLine();
1656 out
.response_info
= *response1
;
1657 out
.rv
= ReadTransaction(&trans1
, &out
.response_data
);
1658 EXPECT_EQ(OK
, out
.rv
);
1660 const HttpResponseInfo
* response2
= trans2
.GetResponseInfo();
1661 ASSERT_TRUE(response2
!= NULL
);
1662 out
.status_line
= response2
->headers
->GetStatusLine();
1663 out
.response_info
= *response2
;
1664 out
.rv
= ReadTransaction(&trans2
, &out
.response_data
);
1665 EXPECT_EQ(ERR_CONNECTION_RESET
, out
.rv
);
1667 helper
.VerifyDataConsumed();
1670 // Test that a simple PUT request works.
1671 TEST_P(SpdyNetworkTransactionTest
, Put
) {
1672 // Setup the request
1673 HttpRequestInfo request
;
1674 request
.method
= "PUT";
1675 request
.url
= GURL("http://www.google.com/");
1677 scoped_ptr
<SpdyHeaderBlock
> put_headers(
1678 spdy_util_
.ConstructPutHeaderBlock("http://www.google.com", 0));
1679 scoped_ptr
<SpdyFrame
> req(
1680 spdy_util_
.ConstructSpdySyn(1, *put_headers
, LOWEST
, false, true));
1681 MockWrite writes
[] = {
1682 CreateMockWrite(*req
),
1685 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
1686 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
1687 MockRead reads
[] = {
1688 CreateMockRead(*resp
),
1689 CreateMockRead(*body
),
1690 MockRead(ASYNC
, 0, 0) // EOF
1693 DelayedSocketData
data(1, reads
, arraysize(reads
),
1694 writes
, arraysize(writes
));
1695 NormalSpdyTransactionHelper
helper(request
, DEFAULT_PRIORITY
,
1696 BoundNetLog(), GetParam(), NULL
);
1697 helper
.RunToCompletion(&data
);
1698 TransactionHelperResult out
= helper
.output();
1700 EXPECT_EQ(OK
, out
.rv
);
1701 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1704 // Test that a simple HEAD request works.
1705 TEST_P(SpdyNetworkTransactionTest
, Head
) {
1706 // Setup the request
1707 HttpRequestInfo request
;
1708 request
.method
= "HEAD";
1709 request
.url
= GURL("http://www.google.com/");
1711 scoped_ptr
<SpdyHeaderBlock
> head_headers(
1712 spdy_util_
.ConstructHeadHeaderBlock("http://www.google.com", 0));
1713 scoped_ptr
<SpdyFrame
> req(
1714 spdy_util_
.ConstructSpdySyn(1, *head_headers
, LOWEST
, false, true));
1715 MockWrite writes
[] = {
1716 CreateMockWrite(*req
),
1719 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
1720 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
1721 MockRead reads
[] = {
1722 CreateMockRead(*resp
),
1723 CreateMockRead(*body
),
1724 MockRead(ASYNC
, 0, 0) // EOF
1727 DelayedSocketData
data(1, reads
, arraysize(reads
),
1728 writes
, arraysize(writes
));
1729 NormalSpdyTransactionHelper
helper(request
, DEFAULT_PRIORITY
,
1730 BoundNetLog(), GetParam(), NULL
);
1731 helper
.RunToCompletion(&data
);
1732 TransactionHelperResult out
= helper
.output();
1734 EXPECT_EQ(OK
, out
.rv
);
1735 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1738 // Test that a simple POST works.
1739 TEST_P(SpdyNetworkTransactionTest
, Post
) {
1740 scoped_ptr
<SpdyFrame
> req(
1741 spdy_util_
.ConstructSpdyPost(
1742 kRequestUrl
, 1, kUploadDataSize
, LOWEST
, NULL
, 0));
1743 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
1744 MockWrite writes
[] = {
1745 CreateMockWrite(*req
),
1746 CreateMockWrite(*body
), // POST upload frame
1749 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyPostSynReply(NULL
, 0));
1750 MockRead reads
[] = {
1751 CreateMockRead(*resp
),
1752 CreateMockRead(*body
),
1753 MockRead(ASYNC
, 0, 0) // EOF
1756 DelayedSocketData
data(2, reads
, arraysize(reads
),
1757 writes
, arraysize(writes
));
1758 NormalSpdyTransactionHelper
helper(CreatePostRequest(), DEFAULT_PRIORITY
,
1759 BoundNetLog(), GetParam(), NULL
);
1760 helper
.RunToCompletion(&data
);
1761 TransactionHelperResult out
= helper
.output();
1762 EXPECT_EQ(OK
, out
.rv
);
1763 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1764 EXPECT_EQ("hello!", out
.response_data
);
1767 // Test that a POST with a file works.
1768 TEST_P(SpdyNetworkTransactionTest
, FilePost
) {
1769 scoped_ptr
<SpdyFrame
> req(
1770 spdy_util_
.ConstructSpdyPost(
1771 kRequestUrl
, 1, kUploadDataSize
, LOWEST
, NULL
, 0));
1772 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
1773 MockWrite writes
[] = {
1774 CreateMockWrite(*req
),
1775 CreateMockWrite(*body
), // POST upload frame
1778 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyPostSynReply(NULL
, 0));
1779 MockRead reads
[] = {
1780 CreateMockRead(*resp
),
1781 CreateMockRead(*body
),
1782 MockRead(ASYNC
, 0, 0) // EOF
1785 DelayedSocketData
data(2, reads
, arraysize(reads
),
1786 writes
, arraysize(writes
));
1787 NormalSpdyTransactionHelper
helper(CreateFilePostRequest(), DEFAULT_PRIORITY
,
1788 BoundNetLog(), GetParam(), NULL
);
1789 helper
.RunToCompletion(&data
);
1790 TransactionHelperResult out
= helper
.output();
1791 EXPECT_EQ(OK
, out
.rv
);
1792 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1793 EXPECT_EQ("hello!", out
.response_data
);
1796 // Test that a POST with a unreadable file fails.
1797 TEST_P(SpdyNetworkTransactionTest
, UnreadableFilePost
) {
1798 MockWrite writes
[] = {
1799 MockWrite(ASYNC
, 0, 0) // EOF
1801 MockRead reads
[] = {
1802 MockRead(ASYNC
, 0, 0) // EOF
1805 DelayedSocketData
data(1, reads
, arraysize(reads
), writes
, arraysize(writes
));
1806 NormalSpdyTransactionHelper
helper(CreateUnreadableFilePostRequest(),
1808 BoundNetLog(), GetParam(), NULL
);
1809 helper
.RunPreTestSetup();
1810 helper
.AddData(&data
);
1811 helper
.RunDefaultTest();
1813 base::RunLoop().RunUntilIdle();
1814 helper
.VerifyDataNotConsumed();
1815 EXPECT_EQ(ERR_ACCESS_DENIED
, helper
.output().rv
);
1818 // Test that a complex POST works.
1819 TEST_P(SpdyNetworkTransactionTest
, ComplexPost
) {
1820 scoped_ptr
<SpdyFrame
> req(
1821 spdy_util_
.ConstructSpdyPost(
1822 kRequestUrl
, 1, kUploadDataSize
, LOWEST
, NULL
, 0));
1823 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
1824 MockWrite writes
[] = {
1825 CreateMockWrite(*req
),
1826 CreateMockWrite(*body
), // POST upload frame
1829 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyPostSynReply(NULL
, 0));
1830 MockRead reads
[] = {
1831 CreateMockRead(*resp
),
1832 CreateMockRead(*body
),
1833 MockRead(ASYNC
, 0, 0) // EOF
1836 DelayedSocketData
data(2, reads
, arraysize(reads
),
1837 writes
, arraysize(writes
));
1838 NormalSpdyTransactionHelper
helper(CreateComplexPostRequest(),
1840 BoundNetLog(), GetParam(), NULL
);
1841 helper
.RunToCompletion(&data
);
1842 TransactionHelperResult out
= helper
.output();
1843 EXPECT_EQ(OK
, out
.rv
);
1844 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1845 EXPECT_EQ("hello!", out
.response_data
);
1848 // Test that a chunked POST works.
1849 TEST_P(SpdyNetworkTransactionTest
, ChunkedPost
) {
1850 scoped_ptr
<SpdyFrame
> req(spdy_util_
.ConstructChunkedSpdyPost(NULL
, 0));
1851 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
1852 MockWrite writes
[] = {
1853 CreateMockWrite(*req
),
1854 CreateMockWrite(*body
),
1857 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyPostSynReply(NULL
, 0));
1858 MockRead reads
[] = {
1859 CreateMockRead(*resp
),
1860 CreateMockRead(*body
),
1861 MockRead(ASYNC
, 0, 0) // EOF
1864 DelayedSocketData
data(2, reads
, arraysize(reads
),
1865 writes
, arraysize(writes
));
1866 NormalSpdyTransactionHelper
helper(CreateChunkedPostRequest(),
1868 BoundNetLog(), GetParam(), NULL
);
1870 // These chunks get merged into a single frame when being sent.
1871 const int kFirstChunkSize
= kUploadDataSize
/2;
1872 upload_chunked_data_stream()->AppendData(kUploadData
, kFirstChunkSize
, false);
1873 upload_chunked_data_stream()->AppendData(
1874 kUploadData
+ kFirstChunkSize
, kUploadDataSize
- kFirstChunkSize
, true);
1876 helper
.RunToCompletion(&data
);
1877 TransactionHelperResult out
= helper
.output();
1878 EXPECT_EQ(OK
, out
.rv
);
1879 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1880 EXPECT_EQ(kUploadData
, out
.response_data
);
1883 // Test that a chunked POST works with chunks appended after transaction starts.
1884 TEST_P(SpdyNetworkTransactionTest
, DelayedChunkedPost
) {
1885 scoped_ptr
<SpdyFrame
> req(spdy_util_
.ConstructChunkedSpdyPost(NULL
, 0));
1886 scoped_ptr
<SpdyFrame
> chunk1(spdy_util_
.ConstructSpdyBodyFrame(1, false));
1887 scoped_ptr
<SpdyFrame
> chunk2(spdy_util_
.ConstructSpdyBodyFrame(1, false));
1888 scoped_ptr
<SpdyFrame
> chunk3(spdy_util_
.ConstructSpdyBodyFrame(1, true));
1889 MockWrite writes
[] = {
1890 CreateMockWrite(*req
),
1891 CreateMockWrite(*chunk1
),
1892 CreateMockWrite(*chunk2
),
1893 CreateMockWrite(*chunk3
),
1896 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyPostSynReply(NULL
, 0));
1897 MockRead reads
[] = {
1898 CreateMockRead(*resp
),
1899 CreateMockRead(*chunk1
),
1900 CreateMockRead(*chunk2
),
1901 CreateMockRead(*chunk3
),
1902 MockRead(ASYNC
, 0, 0) // EOF
1905 DelayedSocketData
data(4, reads
, arraysize(reads
),
1906 writes
, arraysize(writes
));
1907 NormalSpdyTransactionHelper
helper(CreateChunkedPostRequest(),
1909 BoundNetLog(), GetParam(), NULL
);
1911 upload_chunked_data_stream()->AppendData(kUploadData
, kUploadDataSize
, false);
1913 helper
.RunPreTestSetup();
1914 helper
.AddData(&data
);
1915 ASSERT_TRUE(helper
.StartDefaultTest());
1917 base::RunLoop().RunUntilIdle();
1918 upload_chunked_data_stream()->AppendData(kUploadData
, kUploadDataSize
, false);
1919 base::RunLoop().RunUntilIdle();
1920 upload_chunked_data_stream()->AppendData(kUploadData
, kUploadDataSize
, true);
1922 helper
.FinishDefaultTest();
1923 helper
.VerifyDataConsumed();
1925 std::string expected_response
;
1926 expected_response
+= kUploadData
;
1927 expected_response
+= kUploadData
;
1928 expected_response
+= kUploadData
;
1930 TransactionHelperResult out
= helper
.output();
1931 EXPECT_EQ(OK
, out
.rv
);
1932 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1933 EXPECT_EQ(expected_response
, out
.response_data
);
1936 // Test that a POST without any post data works.
1937 TEST_P(SpdyNetworkTransactionTest
, NullPost
) {
1938 BufferedSpdyFramer
framer(spdy_util_
.spdy_version(), false);
1939 // Setup the request
1940 HttpRequestInfo request
;
1941 request
.method
= "POST";
1942 request
.url
= GURL(kRequestUrl
);
1943 // Create an empty UploadData.
1944 request
.upload_data_stream
= NULL
;
1946 // When request.upload_data_stream is NULL for post, content-length is
1947 // expected to be 0.
1948 scoped_ptr
<SpdyHeaderBlock
> req_block(
1949 spdy_util_
.ConstructPostHeaderBlock(kRequestUrl
, 0));
1950 scoped_ptr
<SpdyFrame
> req(
1951 spdy_util_
.ConstructSpdySyn(1, *req_block
, LOWEST
, false, true));
1953 MockWrite writes
[] = {
1954 CreateMockWrite(*req
),
1957 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyPostSynReply(NULL
, 0));
1958 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
1959 MockRead reads
[] = {
1960 CreateMockRead(*resp
),
1961 CreateMockRead(*body
),
1962 MockRead(ASYNC
, 0, 0) // EOF
1965 DelayedSocketData
data(1, reads
, arraysize(reads
),
1966 writes
, arraysize(writes
));
1968 NormalSpdyTransactionHelper
helper(request
, DEFAULT_PRIORITY
,
1969 BoundNetLog(), GetParam(), NULL
);
1970 helper
.RunToCompletion(&data
);
1971 TransactionHelperResult out
= helper
.output();
1972 EXPECT_EQ(OK
, out
.rv
);
1973 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
1974 EXPECT_EQ("hello!", out
.response_data
);
1977 // Test that a simple POST works.
1978 TEST_P(SpdyNetworkTransactionTest
, EmptyPost
) {
1979 BufferedSpdyFramer
framer(spdy_util_
.spdy_version(), false);
1980 // Create an empty UploadDataStream.
1981 ScopedVector
<UploadElementReader
> element_readers
;
1982 ElementsUploadDataStream
stream(element_readers
.Pass(), 0);
1984 // Setup the request
1985 HttpRequestInfo request
;
1986 request
.method
= "POST";
1987 request
.url
= GURL(kRequestUrl
);
1988 request
.upload_data_stream
= &stream
;
1990 const uint64 kContentLength
= 0;
1992 scoped_ptr
<SpdyHeaderBlock
> req_block(
1993 spdy_util_
.ConstructPostHeaderBlock(kRequestUrl
, kContentLength
));
1994 scoped_ptr
<SpdyFrame
> req(
1995 spdy_util_
.ConstructSpdySyn(1, *req_block
, LOWEST
, false, true));
1997 MockWrite writes
[] = {
1998 CreateMockWrite(*req
),
2001 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyPostSynReply(NULL
, 0));
2002 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
2003 MockRead reads
[] = {
2004 CreateMockRead(*resp
),
2005 CreateMockRead(*body
),
2006 MockRead(ASYNC
, 0, 0) // EOF
2009 DelayedSocketData
data(1, reads
, arraysize(reads
), writes
, arraysize(writes
));
2011 NormalSpdyTransactionHelper
helper(request
, DEFAULT_PRIORITY
,
2012 BoundNetLog(), GetParam(), NULL
);
2013 helper
.RunToCompletion(&data
);
2014 TransactionHelperResult out
= helper
.output();
2015 EXPECT_EQ(OK
, out
.rv
);
2016 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
2017 EXPECT_EQ("hello!", out
.response_data
);
2020 // While we're doing a post, the server sends the reply before upload completes.
2021 TEST_P(SpdyNetworkTransactionTest
, ResponseBeforePostCompletes
) {
2022 scoped_ptr
<SpdyFrame
> req(spdy_util_
.ConstructChunkedSpdyPost(NULL
, 0));
2023 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
2024 MockWrite writes
[] = {
2025 CreateMockWrite(*req
, 0),
2026 CreateMockWrite(*body
, 3),
2028 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyPostSynReply(NULL
, 0));
2029 MockRead reads
[] = {
2030 CreateMockRead(*resp
, 1),
2031 CreateMockRead(*body
, 2),
2032 MockRead(ASYNC
, 0, 4) // EOF
2035 // Write the request headers, and read the complete response
2036 // while still waiting for chunked request data.
2037 DeterministicSocketData
data(reads
, arraysize(reads
),
2038 writes
, arraysize(writes
));
2039 NormalSpdyTransactionHelper
helper(CreateChunkedPostRequest(),
2041 BoundNetLog(), GetParam(), NULL
);
2042 helper
.SetDeterministic();
2043 helper
.RunPreTestSetup();
2044 helper
.AddDeterministicData(&data
);
2046 ASSERT_TRUE(helper
.StartDefaultTest());
2048 // Process the request headers, SYN_REPLY, and response body.
2049 // The request body is still in flight.
2052 const HttpResponseInfo
* response
= helper
.trans()->GetResponseInfo();
2053 EXPECT_EQ("HTTP/1.1 200 OK", response
->headers
->GetStatusLine());
2055 // Finish sending the request body.
2056 upload_chunked_data_stream()->AppendData(kUploadData
, kUploadDataSize
, true);
2059 std::string response_body
;
2060 EXPECT_EQ(OK
, ReadTransaction(helper
.trans(), &response_body
));
2061 EXPECT_EQ(kUploadData
, response_body
);
2062 helper
.VerifyDataConsumed();
2065 // The client upon cancellation tries to send a RST_STREAM frame. The mock
2066 // socket causes the TCP write to return zero. This test checks that the client
2067 // tries to queue up the RST_STREAM frame again.
2068 TEST_P(SpdyNetworkTransactionTest
, SocketWriteReturnsZero
) {
2069 scoped_ptr
<SpdyFrame
> req(
2070 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
2071 scoped_ptr
<SpdyFrame
> rst(
2072 spdy_util_
.ConstructSpdyRstStream(1, RST_STREAM_CANCEL
));
2073 MockWrite writes
[] = {
2074 CreateMockWrite(*req
.get(), 0, SYNCHRONOUS
),
2075 MockWrite(SYNCHRONOUS
, 0, 0, 2),
2076 CreateMockWrite(*rst
.get(), 3, SYNCHRONOUS
),
2079 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2080 MockRead reads
[] = {
2081 CreateMockRead(*resp
.get(), 1, ASYNC
),
2082 MockRead(ASYNC
, 0, 0, 4) // EOF
2085 DeterministicSocketData
data(reads
, arraysize(reads
),
2086 writes
, arraysize(writes
));
2087 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
2088 BoundNetLog(), GetParam(), NULL
);
2089 helper
.SetDeterministic();
2090 helper
.RunPreTestSetup();
2091 helper
.AddDeterministicData(&data
);
2092 HttpNetworkTransaction
* trans
= helper
.trans();
2094 TestCompletionCallback callback
;
2095 int rv
= trans
->Start(
2096 &CreateGetRequest(), callback
.callback(), BoundNetLog());
2097 EXPECT_EQ(ERR_IO_PENDING
, rv
);
2101 helper
.ResetTrans();
2105 helper
.VerifyDataConsumed();
2108 // Test that the transaction doesn't crash when we don't have a reply.
2109 TEST_P(SpdyNetworkTransactionTest
, ResponseWithoutSynReply
) {
2110 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
2111 MockRead reads
[] = {
2112 CreateMockRead(*body
),
2113 MockRead(ASYNC
, 0, 0) // EOF
2116 DelayedSocketData
data(1, reads
, arraysize(reads
), NULL
, 0);
2117 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
2118 BoundNetLog(), GetParam(), NULL
);
2119 helper
.RunToCompletion(&data
);
2120 TransactionHelperResult out
= helper
.output();
2121 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR
, out
.rv
);
2124 // Test that the transaction doesn't crash when we get two replies on the same
2125 // stream ID. See http://crbug.com/45639.
2126 TEST_P(SpdyNetworkTransactionTest
, ResponseWithTwoSynReplies
) {
2127 scoped_ptr
<SpdyFrame
> req(
2128 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
2129 scoped_ptr
<SpdyFrame
> rst(
2130 spdy_util_
.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR
));
2131 MockWrite writes
[] = {
2132 CreateMockWrite(*req
),
2133 CreateMockWrite(*rst
),
2136 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2137 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
2138 MockRead reads
[] = {
2139 CreateMockRead(*resp
),
2140 CreateMockRead(*resp
),
2141 CreateMockRead(*body
),
2142 MockRead(ASYNC
, 0, 0) // EOF
2145 DelayedSocketData
data(1, reads
, arraysize(reads
),
2146 writes
, arraysize(writes
));
2148 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
2149 BoundNetLog(), GetParam(), NULL
);
2150 helper
.RunPreTestSetup();
2151 helper
.AddData(&data
);
2153 HttpNetworkTransaction
* trans
= helper
.trans();
2155 TestCompletionCallback callback
;
2156 int rv
= trans
->Start(&helper
.request(), callback
.callback(), BoundNetLog());
2157 EXPECT_EQ(ERR_IO_PENDING
, rv
);
2158 rv
= callback
.WaitForResult();
2161 const HttpResponseInfo
* response
= trans
->GetResponseInfo();
2162 ASSERT_TRUE(response
!= NULL
);
2163 EXPECT_TRUE(response
->headers
.get() != NULL
);
2164 EXPECT_TRUE(response
->was_fetched_via_spdy
);
2165 std::string response_data
;
2166 rv
= ReadTransaction(trans
, &response_data
);
2167 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR
, rv
);
2169 helper
.VerifyDataConsumed();
2172 TEST_P(SpdyNetworkTransactionTest
, ResetReplyWithTransferEncoding
) {
2173 // Construct the request.
2174 scoped_ptr
<SpdyFrame
> req(
2175 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
2176 scoped_ptr
<SpdyFrame
> rst(
2177 spdy_util_
.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR
));
2178 MockWrite writes
[] = {
2179 CreateMockWrite(*req
),
2180 CreateMockWrite(*rst
),
2183 const char* const headers
[] = {
2184 "transfer-encoding", "chunked"
2186 scoped_ptr
<SpdyFrame
> resp(
2187 spdy_util_
.ConstructSpdyGetSynReply(headers
, 1, 1));
2188 scoped_ptr
<SpdyFrame
> body(
2189 spdy_util_
.ConstructSpdyBodyFrame(1, true));
2190 MockRead reads
[] = {
2191 CreateMockRead(*resp
),
2192 CreateMockRead(*body
),
2193 MockRead(ASYNC
, 0, 0) // EOF
2196 DelayedSocketData
data(1, reads
, arraysize(reads
),
2197 writes
, arraysize(writes
));
2198 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
2199 BoundNetLog(), GetParam(), NULL
);
2200 helper
.RunToCompletion(&data
);
2201 TransactionHelperResult out
= helper
.output();
2202 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR
, out
.rv
);
2204 helper
.session()->spdy_session_pool()->CloseAllSessions();
2205 helper
.VerifyDataConsumed();
2208 TEST_P(SpdyNetworkTransactionTest
, ResetPushWithTransferEncoding
) {
2209 // Construct the request.
2210 scoped_ptr
<SpdyFrame
> req(
2211 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
2212 scoped_ptr
<SpdyFrame
> rst(
2213 spdy_util_
.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR
));
2214 MockWrite writes
[] = {
2215 CreateMockWrite(*req
),
2216 CreateMockWrite(*rst
),
2219 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2220 const char* const headers
[] = {
2221 "transfer-encoding", "chunked"
2223 scoped_ptr
<SpdyFrame
> push(
2224 spdy_util_
.ConstructSpdyPush(headers
, arraysize(headers
) / 2,
2225 2, 1, "http://www.google.com/1"));
2226 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
2227 MockRead reads
[] = {
2228 CreateMockRead(*resp
),
2229 CreateMockRead(*push
),
2230 CreateMockRead(*body
),
2231 MockRead(ASYNC
, 0, 0) // EOF
2234 DelayedSocketData
data(1, reads
, arraysize(reads
),
2235 writes
, arraysize(writes
));
2236 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
2237 BoundNetLog(), GetParam(), NULL
);
2238 helper
.RunToCompletion(&data
);
2239 TransactionHelperResult out
= helper
.output();
2240 EXPECT_EQ(OK
, out
.rv
);
2241 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
2242 EXPECT_EQ("hello!", out
.response_data
);
2244 helper
.session()->spdy_session_pool()->CloseAllSessions();
2245 helper
.VerifyDataConsumed();
2248 TEST_P(SpdyNetworkTransactionTest
, CancelledTransaction
) {
2249 // Construct the request.
2250 scoped_ptr
<SpdyFrame
> req(
2251 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
2252 MockWrite writes
[] = {
2253 CreateMockWrite(*req
),
2256 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2257 MockRead reads
[] = {
2258 CreateMockRead(*resp
),
2259 // This following read isn't used by the test, except during the
2260 // RunUntilIdle() call at the end since the SpdySession survives the
2261 // HttpNetworkTransaction and still tries to continue Read()'ing. Any
2262 // MockRead will do here.
2263 MockRead(ASYNC
, 0, 0) // EOF
2266 StaticSocketDataProvider
data(reads
, arraysize(reads
),
2267 writes
, arraysize(writes
));
2269 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
2270 BoundNetLog(), GetParam(), NULL
);
2271 helper
.RunPreTestSetup();
2272 helper
.AddData(&data
);
2273 HttpNetworkTransaction
* trans
= helper
.trans();
2275 TestCompletionCallback callback
;
2276 int rv
= trans
->Start(
2277 &CreateGetRequest(), callback
.callback(), BoundNetLog());
2278 EXPECT_EQ(ERR_IO_PENDING
, rv
);
2279 helper
.ResetTrans(); // Cancel the transaction.
2281 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the
2282 // MockClientSocketFactory) are still alive.
2283 base::RunLoop().RunUntilIdle();
2284 helper
.VerifyDataNotConsumed();
2287 // Verify that the client sends a Rst Frame upon cancelling the stream.
2288 TEST_P(SpdyNetworkTransactionTest
, CancelledTransactionSendRst
) {
2289 scoped_ptr
<SpdyFrame
> req(
2290 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
2291 scoped_ptr
<SpdyFrame
> rst(
2292 spdy_util_
.ConstructSpdyRstStream(1, RST_STREAM_CANCEL
));
2293 MockWrite writes
[] = {
2294 CreateMockWrite(*req
, 0, SYNCHRONOUS
),
2295 CreateMockWrite(*rst
, 2, SYNCHRONOUS
),
2298 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2299 MockRead reads
[] = {
2300 CreateMockRead(*resp
, 1, ASYNC
),
2301 MockRead(ASYNC
, 0, 0, 3) // EOF
2304 DeterministicSocketData
data(reads
, arraysize(reads
),
2305 writes
, arraysize(writes
));
2307 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
2310 helper
.SetDeterministic();
2311 helper
.RunPreTestSetup();
2312 helper
.AddDeterministicData(&data
);
2313 HttpNetworkTransaction
* trans
= helper
.trans();
2315 TestCompletionCallback callback
;
2317 int rv
= trans
->Start(
2318 &CreateGetRequest(), callback
.callback(), BoundNetLog());
2319 EXPECT_EQ(ERR_IO_PENDING
, rv
);
2323 helper
.ResetTrans();
2327 helper
.VerifyDataConsumed();
2330 // Verify that the client can correctly deal with the user callback attempting
2331 // to start another transaction on a session that is closing down. See
2332 // http://crbug.com/47455
2333 TEST_P(SpdyNetworkTransactionTest
, StartTransactionOnReadCallback
) {
2334 scoped_ptr
<SpdyFrame
> req(
2335 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
2336 MockWrite writes
[] = { CreateMockWrite(*req
) };
2337 MockWrite writes2
[] = { CreateMockWrite(*req
) };
2339 // The indicated length of this frame is longer than its actual length. When
2340 // the session receives an empty frame after this one, it shuts down the
2341 // session, and calls the read callback with the incomplete data.
2342 const uint8 kGetBodyFrame2
[] = {
2343 0x00, 0x00, 0x00, 0x01,
2344 0x01, 0x00, 0x00, 0x07,
2345 'h', 'e', 'l', 'l', 'o', '!',
2348 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2349 MockRead reads
[] = {
2350 CreateMockRead(*resp
, 2),
2351 MockRead(ASYNC
, ERR_IO_PENDING
, 3), // Force a pause
2352 MockRead(ASYNC
, reinterpret_cast<const char*>(kGetBodyFrame2
),
2353 arraysize(kGetBodyFrame2
), 4),
2354 MockRead(ASYNC
, ERR_IO_PENDING
, 5), // Force a pause
2355 MockRead(ASYNC
, 0, 0, 6), // EOF
2357 MockRead reads2
[] = {
2358 CreateMockRead(*resp
, 2),
2359 MockRead(ASYNC
, 0, 0, 3), // EOF
2362 OrderedSocketData
data(reads
, arraysize(reads
),
2363 writes
, arraysize(writes
));
2364 DelayedSocketData
data2(1, reads2
, arraysize(reads2
),
2365 writes2
, arraysize(writes2
));
2367 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
2368 BoundNetLog(), GetParam(), NULL
);
2369 helper
.RunPreTestSetup();
2370 helper
.AddData(&data
);
2371 helper
.AddData(&data2
);
2372 HttpNetworkTransaction
* trans
= helper
.trans();
2374 // Start the transaction with basic parameters.
2375 TestCompletionCallback callback
;
2376 int rv
= trans
->Start(&helper
.request(), callback
.callback(), BoundNetLog());
2377 EXPECT_EQ(ERR_IO_PENDING
, rv
);
2378 rv
= callback
.WaitForResult();
2380 const int kSize
= 3000;
2381 scoped_refptr
<IOBuffer
> buf(new IOBuffer(kSize
));
2385 base::Bind(&SpdyNetworkTransactionTest::StartTransactionCallback
,
2387 // This forces an err_IO_pending, which sets the callback.
2388 data
.CompleteRead();
2389 // This finishes the read.
2390 data
.CompleteRead();
2391 helper
.VerifyDataConsumed();
2394 // Verify that the client can correctly deal with the user callback deleting the
2395 // transaction. Failures will usually be valgrind errors. See
2396 // http://crbug.com/46925
2397 TEST_P(SpdyNetworkTransactionTest
, DeleteSessionOnReadCallback
) {
2398 scoped_ptr
<SpdyFrame
> req(
2399 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
2400 MockWrite writes
[] = { CreateMockWrite(*req
) };
2402 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2403 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
2404 MockRead reads
[] = {
2405 CreateMockRead(*resp
.get(), 2),
2406 MockRead(ASYNC
, ERR_IO_PENDING
, 3), // Force a pause
2407 CreateMockRead(*body
.get(), 4),
2408 MockRead(ASYNC
, 0, 0, 5), // EOF
2411 OrderedSocketData
data(reads
, arraysize(reads
),
2412 writes
, arraysize(writes
));
2414 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
2415 BoundNetLog(), GetParam(), NULL
);
2416 helper
.RunPreTestSetup();
2417 helper
.AddData(&data
);
2418 HttpNetworkTransaction
* trans
= helper
.trans();
2420 // Start the transaction with basic parameters.
2421 TestCompletionCallback callback
;
2422 int rv
= trans
->Start(&helper
.request(), callback
.callback(), BoundNetLog());
2423 EXPECT_EQ(ERR_IO_PENDING
, rv
);
2424 rv
= callback
.WaitForResult();
2426 // Setup a user callback which will delete the session, and clear out the
2427 // memory holding the stream object. Note that the callback deletes trans.
2428 const int kSize
= 3000;
2429 scoped_refptr
<IOBuffer
> buf(new IOBuffer(kSize
));
2433 base::Bind(&SpdyNetworkTransactionTest::DeleteSessionCallback
,
2434 base::Unretained(&helper
)));
2435 ASSERT_EQ(ERR_IO_PENDING
, rv
);
2436 data
.CompleteRead();
2438 // Finish running rest of tasks.
2439 base::RunLoop().RunUntilIdle();
2440 helper
.VerifyDataConsumed();
2443 // Send a spdy request to www.google.com that gets redirected to www.foo.com.
2444 TEST_P(SpdyNetworkTransactionTest
, RedirectGetRequest
) {
2445 scoped_ptr
<SpdyHeaderBlock
> headers(
2446 spdy_util_
.ConstructGetHeaderBlock("http://www.google.com/"));
2447 (*headers
)["user-agent"] = "";
2448 (*headers
)["accept-encoding"] = "gzip, deflate";
2449 scoped_ptr
<SpdyHeaderBlock
> headers2(
2450 spdy_util_
.ConstructGetHeaderBlock("http://www.foo.com/index.php"));
2451 (*headers2
)["user-agent"] = "";
2452 (*headers2
)["accept-encoding"] = "gzip, deflate";
2454 // Setup writes/reads to www.google.com
2455 scoped_ptr
<SpdyFrame
> req(
2456 spdy_util_
.ConstructSpdySyn(1, *headers
, LOWEST
, false, true));
2457 scoped_ptr
<SpdyFrame
> req2(
2458 spdy_util_
.ConstructSpdySyn(1, *headers2
, LOWEST
, false, true));
2459 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReplyRedirect(1));
2460 MockWrite writes
[] = {
2461 CreateMockWrite(*req
, 1),
2463 MockRead reads
[] = {
2464 CreateMockRead(*resp
, 2),
2465 MockRead(ASYNC
, 0, 0, 3) // EOF
2468 // Setup writes/reads to www.foo.com
2469 scoped_ptr
<SpdyFrame
> resp2(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2470 scoped_ptr
<SpdyFrame
> body2(spdy_util_
.ConstructSpdyBodyFrame(1, true));
2471 MockWrite writes2
[] = {
2472 CreateMockWrite(*req2
, 1),
2474 MockRead reads2
[] = {
2475 CreateMockRead(*resp2
, 2),
2476 CreateMockRead(*body2
, 3),
2477 MockRead(ASYNC
, 0, 0, 4) // EOF
2479 OrderedSocketData
data(reads
, arraysize(reads
),
2480 writes
, arraysize(writes
));
2481 OrderedSocketData
data2(reads2
, arraysize(reads2
),
2482 writes2
, arraysize(writes2
));
2484 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN
2487 SpdyURLRequestContext
spdy_url_request_context(
2488 GetParam().protocol
,
2489 false /* force_spdy_over_ssl*/,
2490 true /* force_spdy_always */);
2491 scoped_ptr
<URLRequest
> r(
2492 spdy_url_request_context
.CreateRequest(GURL("http://www.google.com/"),
2496 spdy_url_request_context
.socket_factory().
2497 AddSocketDataProvider(&data
);
2498 spdy_url_request_context
.socket_factory().
2499 AddSocketDataProvider(&data2
);
2501 d
.set_quit_on_redirect(true);
2503 base::RunLoop().Run();
2505 EXPECT_EQ(1, d
.received_redirect_count());
2507 r
->FollowDeferredRedirect();
2508 base::RunLoop().Run();
2509 EXPECT_EQ(1, d
.response_started_count());
2510 EXPECT_FALSE(d
.received_data_before_response());
2511 EXPECT_EQ(URLRequestStatus::SUCCESS
, r
->status().status());
2512 std::string
contents("hello!");
2513 EXPECT_EQ(contents
, d
.data_received());
2515 EXPECT_TRUE(data
.at_read_eof());
2516 EXPECT_TRUE(data
.at_write_eof());
2517 EXPECT_TRUE(data2
.at_read_eof());
2518 EXPECT_TRUE(data2
.at_write_eof());
2521 // Send a spdy request to www.google.com. Get a pushed stream that redirects to
2523 TEST_P(SpdyNetworkTransactionTest
, RedirectServerPush
) {
2524 scoped_ptr
<SpdyHeaderBlock
> headers(
2525 spdy_util_
.ConstructGetHeaderBlock("http://www.google.com/"));
2526 (*headers
)["user-agent"] = "";
2527 (*headers
)["accept-encoding"] = "gzip, deflate";
2529 // Setup writes/reads to www.google.com
2530 scoped_ptr
<SpdyFrame
> req(
2531 spdy_util_
.ConstructSpdySyn(1, *headers
, LOWEST
, false, true));
2532 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2533 scoped_ptr
<SpdyFrame
> rep(
2534 spdy_util_
.ConstructSpdyPush(NULL
,
2538 "http://www.google.com/foo.dat",
2539 "301 Moved Permanently",
2540 "http://www.foo.com/index.php"));
2541 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
2542 scoped_ptr
<SpdyFrame
> rst(
2543 spdy_util_
.ConstructSpdyRstStream(2, RST_STREAM_CANCEL
));
2544 MockWrite writes
[] = {
2545 CreateMockWrite(*req
, 1),
2546 CreateMockWrite(*rst
, 6),
2548 MockRead reads
[] = {
2549 CreateMockRead(*resp
, 2),
2550 CreateMockRead(*rep
, 3),
2551 CreateMockRead(*body
, 4),
2552 MockRead(ASYNC
, ERR_IO_PENDING
, 5), // Force a pause
2553 MockRead(ASYNC
, 0, 0, 7) // EOF
2556 // Setup writes/reads to www.foo.com
2557 scoped_ptr
<SpdyHeaderBlock
> headers2(
2558 spdy_util_
.ConstructGetHeaderBlock("http://www.foo.com/index.php"));
2559 (*headers2
)["user-agent"] = "";
2560 (*headers2
)["accept-encoding"] = "gzip, deflate";
2561 scoped_ptr
<SpdyFrame
> req2(
2562 spdy_util_
.ConstructSpdySyn(1, *headers2
, LOWEST
, false, true));
2563 scoped_ptr
<SpdyFrame
> resp2(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2564 scoped_ptr
<SpdyFrame
> body2(spdy_util_
.ConstructSpdyBodyFrame(1, true));
2565 MockWrite writes2
[] = {
2566 CreateMockWrite(*req2
, 1),
2568 MockRead reads2
[] = {
2569 CreateMockRead(*resp2
, 2),
2570 CreateMockRead(*body2
, 3),
2571 MockRead(ASYNC
, 0, 0, 5) // EOF
2573 OrderedSocketData
data(reads
, arraysize(reads
),
2574 writes
, arraysize(writes
));
2575 OrderedSocketData
data2(reads2
, arraysize(reads2
),
2576 writes2
, arraysize(writes2
));
2578 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN
2581 SpdyURLRequestContext
spdy_url_request_context(
2582 GetParam().protocol
,
2583 false /* force_spdy_over_ssl*/,
2584 true /* force_spdy_always */);
2586 scoped_ptr
<URLRequest
> r(
2587 spdy_url_request_context
.CreateRequest(GURL("http://www.google.com/"),
2591 spdy_url_request_context
.socket_factory().
2592 AddSocketDataProvider(&data
);
2595 base::RunLoop().Run();
2597 EXPECT_EQ(0, d
.received_redirect_count());
2598 std::string
contents("hello!");
2599 EXPECT_EQ(contents
, d
.data_received());
2601 scoped_ptr
<URLRequest
> r2(
2602 spdy_url_request_context
.CreateRequest(
2603 GURL("http://www.google.com/foo.dat"),
2607 spdy_url_request_context
.socket_factory().
2608 AddSocketDataProvider(&data2
);
2610 d2
.set_quit_on_redirect(true);
2612 base::RunLoop().Run();
2613 EXPECT_EQ(1, d2
.received_redirect_count());
2615 r2
->FollowDeferredRedirect();
2616 base::RunLoop().Run();
2617 EXPECT_EQ(1, d2
.response_started_count());
2618 EXPECT_FALSE(d2
.received_data_before_response());
2619 EXPECT_EQ(URLRequestStatus::SUCCESS
, r2
->status().status());
2620 std::string
contents2("hello!");
2621 EXPECT_EQ(contents2
, d2
.data_received());
2623 data
.CompleteRead();
2624 data2
.CompleteRead();
2625 EXPECT_TRUE(data
.at_read_eof());
2626 EXPECT_TRUE(data
.at_write_eof());
2627 EXPECT_TRUE(data2
.at_read_eof());
2628 EXPECT_TRUE(data2
.at_write_eof());
2631 TEST_P(SpdyNetworkTransactionTest
, ServerPushSingleDataFrame
) {
2632 scoped_ptr
<SpdyFrame
> stream1_syn(
2633 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
2634 scoped_ptr
<SpdyFrame
> stream1_body(
2635 spdy_util_
.ConstructSpdyBodyFrame(1, true));
2636 MockWrite writes
[] = {
2637 CreateMockWrite(*stream1_syn
, 1),
2640 scoped_ptr
<SpdyFrame
>
2641 stream1_reply(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2642 scoped_ptr
<SpdyFrame
>
2643 stream2_syn(spdy_util_
.ConstructSpdyPush(NULL
,
2647 "http://www.google.com/foo.dat"));
2648 const char kPushedData
[] = "pushed";
2649 scoped_ptr
<SpdyFrame
> stream2_body(
2650 spdy_util_
.ConstructSpdyBodyFrame(
2651 2, kPushedData
, strlen(kPushedData
), true));
2652 MockRead reads
[] = {
2653 CreateMockRead(*stream1_reply
, 2),
2654 CreateMockRead(*stream2_syn
, 3),
2655 CreateMockRead(*stream1_body
, 4, SYNCHRONOUS
),
2656 CreateMockRead(*stream2_body
, 5),
2657 MockRead(ASYNC
, ERR_IO_PENDING
, 6), // Force a pause
2660 HttpResponseInfo response
;
2661 HttpResponseInfo response2
;
2662 std::string
expected_push_result("pushed");
2663 OrderedSocketData
data(reads
, arraysize(reads
),
2664 writes
, arraysize(writes
));
2665 RunServerPushTest(&data
,
2668 expected_push_result
);
2670 // Verify the SYN_REPLY.
2671 EXPECT_TRUE(response
.headers
.get() != NULL
);
2672 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
2674 // Verify the pushed stream.
2675 EXPECT_TRUE(response2
.headers
.get() != NULL
);
2676 EXPECT_EQ("HTTP/1.1 200 OK", response2
.headers
->GetStatusLine());
2679 TEST_P(SpdyNetworkTransactionTest
, ServerPushBeforeSynReply
) {
2680 scoped_ptr
<SpdyFrame
> stream1_syn(
2681 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
2682 scoped_ptr
<SpdyFrame
> stream1_body(
2683 spdy_util_
.ConstructSpdyBodyFrame(1, true));
2684 MockWrite writes
[] = {
2685 CreateMockWrite(*stream1_syn
, 1),
2688 scoped_ptr
<SpdyFrame
>
2689 stream1_reply(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2690 scoped_ptr
<SpdyFrame
>
2691 stream2_syn(spdy_util_
.ConstructSpdyPush(NULL
,
2695 "http://www.google.com/foo.dat"));
2696 const char kPushedData
[] = "pushed";
2697 scoped_ptr
<SpdyFrame
> stream2_body(
2698 spdy_util_
.ConstructSpdyBodyFrame(
2699 2, kPushedData
, strlen(kPushedData
), true));
2700 MockRead reads
[] = {
2701 CreateMockRead(*stream2_syn
, 2),
2702 CreateMockRead(*stream1_reply
, 3),
2703 CreateMockRead(*stream1_body
, 4, SYNCHRONOUS
),
2704 CreateMockRead(*stream2_body
, 5),
2705 MockRead(ASYNC
, ERR_IO_PENDING
, 6), // Force a pause
2708 HttpResponseInfo response
;
2709 HttpResponseInfo response2
;
2710 std::string
expected_push_result("pushed");
2711 OrderedSocketData
data(reads
, arraysize(reads
),
2712 writes
, arraysize(writes
));
2713 RunServerPushTest(&data
,
2716 expected_push_result
);
2718 // Verify the SYN_REPLY.
2719 EXPECT_TRUE(response
.headers
.get() != NULL
);
2720 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
2722 // Verify the pushed stream.
2723 EXPECT_TRUE(response2
.headers
.get() != NULL
);
2724 EXPECT_EQ("HTTP/1.1 200 OK", response2
.headers
->GetStatusLine());
2727 TEST_P(SpdyNetworkTransactionTest
, ServerPushSingleDataFrame2
) {
2728 scoped_ptr
<SpdyFrame
> stream1_syn(
2729 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
2730 MockWrite writes
[] = { CreateMockWrite(*stream1_syn
, 1), };
2732 scoped_ptr
<SpdyFrame
>
2733 stream1_reply(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2734 scoped_ptr
<SpdyFrame
>
2735 stream2_syn(spdy_util_
.ConstructSpdyPush(NULL
,
2739 "http://www.google.com/foo.dat"));
2740 const char kPushedData
[] = "pushed";
2741 scoped_ptr
<SpdyFrame
> stream2_body(
2742 spdy_util_
.ConstructSpdyBodyFrame(
2743 2, kPushedData
, strlen(kPushedData
), true));
2744 scoped_ptr
<SpdyFrame
>
2745 stream1_body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
2746 MockRead reads
[] = {
2747 CreateMockRead(*stream1_reply
, 2),
2748 CreateMockRead(*stream2_syn
, 3),
2749 CreateMockRead(*stream2_body
, 4),
2750 CreateMockRead(*stream1_body
, 5, SYNCHRONOUS
),
2751 MockRead(ASYNC
, ERR_IO_PENDING
, 6), // Force a pause
2754 HttpResponseInfo response
;
2755 HttpResponseInfo response2
;
2756 std::string
expected_push_result("pushed");
2757 OrderedSocketData
data(reads
, arraysize(reads
),
2758 writes
, arraysize(writes
));
2759 RunServerPushTest(&data
,
2762 expected_push_result
);
2764 // Verify the SYN_REPLY.
2765 EXPECT_TRUE(response
.headers
.get() != NULL
);
2766 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
2768 // Verify the pushed stream.
2769 EXPECT_TRUE(response2
.headers
.get() != NULL
);
2770 EXPECT_EQ("HTTP/1.1 200 OK", response2
.headers
->GetStatusLine());
2773 TEST_P(SpdyNetworkTransactionTest
, ServerPushServerAborted
) {
2774 scoped_ptr
<SpdyFrame
> stream1_syn(
2775 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
2776 scoped_ptr
<SpdyFrame
> stream1_body(
2777 spdy_util_
.ConstructSpdyBodyFrame(1, true));
2778 MockWrite writes
[] = {
2779 CreateMockWrite(*stream1_syn
, 1),
2782 scoped_ptr
<SpdyFrame
>
2783 stream1_reply(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2784 scoped_ptr
<SpdyFrame
>
2785 stream2_syn(spdy_util_
.ConstructSpdyPush(NULL
,
2789 "http://www.google.com/foo.dat"));
2790 scoped_ptr
<SpdyFrame
> stream2_rst(
2791 spdy_util_
.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR
));
2792 MockRead reads
[] = {
2793 CreateMockRead(*stream1_reply
, 2),
2794 CreateMockRead(*stream2_syn
, 3),
2795 CreateMockRead(*stream2_rst
, 4),
2796 CreateMockRead(*stream1_body
, 5, SYNCHRONOUS
),
2797 MockRead(ASYNC
, ERR_IO_PENDING
, 6), // Force a pause
2800 OrderedSocketData
data(reads
, arraysize(reads
),
2801 writes
, arraysize(writes
));
2802 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
2803 BoundNetLog(), GetParam(), NULL
);
2805 helper
.RunPreTestSetup();
2806 helper
.AddData(&data
);
2808 HttpNetworkTransaction
* trans
= helper
.trans();
2810 // Start the transaction with basic parameters.
2811 TestCompletionCallback callback
;
2812 int rv
= trans
->Start(
2813 &CreateGetRequest(), callback
.callback(), BoundNetLog());
2814 EXPECT_EQ(ERR_IO_PENDING
, rv
);
2815 rv
= callback
.WaitForResult();
2818 // Verify that we consumed all test data.
2819 EXPECT_TRUE(data
.at_read_eof()) << "Read count: "
2820 << data
.read_count()
2822 << data
.read_index();
2823 EXPECT_TRUE(data
.at_write_eof()) << "Write count: "
2824 << data
.write_count()
2826 << data
.write_index();
2828 // Verify the SYN_REPLY.
2829 HttpResponseInfo response
= *trans
->GetResponseInfo();
2830 EXPECT_TRUE(response
.headers
.get() != NULL
);
2831 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
2834 // Verify that we don't leak streams and that we properly send a reset
2835 // if the server pushes the same stream twice.
2836 TEST_P(SpdyNetworkTransactionTest
, ServerPushDuplicate
) {
2837 scoped_ptr
<SpdyFrame
> stream1_syn(
2838 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
2839 scoped_ptr
<SpdyFrame
> stream1_body(
2840 spdy_util_
.ConstructSpdyBodyFrame(1, true));
2841 scoped_ptr
<SpdyFrame
> stream3_rst(
2842 spdy_util_
.ConstructSpdyRstStream(4, RST_STREAM_PROTOCOL_ERROR
));
2843 MockWrite writes
[] = {
2844 CreateMockWrite(*stream1_syn
, 1),
2845 CreateMockWrite(*stream3_rst
, 5),
2848 scoped_ptr
<SpdyFrame
>
2849 stream1_reply(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2850 scoped_ptr
<SpdyFrame
>
2851 stream2_syn(spdy_util_
.ConstructSpdyPush(NULL
,
2855 "http://www.google.com/foo.dat"));
2856 const char kPushedData
[] = "pushed";
2857 scoped_ptr
<SpdyFrame
> stream2_body(
2858 spdy_util_
.ConstructSpdyBodyFrame(
2859 2, kPushedData
, strlen(kPushedData
), true));
2860 scoped_ptr
<SpdyFrame
>
2861 stream3_syn(spdy_util_
.ConstructSpdyPush(NULL
,
2865 "http://www.google.com/foo.dat"));
2866 MockRead reads
[] = {
2867 CreateMockRead(*stream1_reply
, 2),
2868 CreateMockRead(*stream2_syn
, 3),
2869 CreateMockRead(*stream3_syn
, 4),
2870 CreateMockRead(*stream1_body
, 6, SYNCHRONOUS
),
2871 CreateMockRead(*stream2_body
, 7),
2872 MockRead(ASYNC
, ERR_IO_PENDING
, 8), // Force a pause
2875 HttpResponseInfo response
;
2876 HttpResponseInfo response2
;
2877 std::string
expected_push_result("pushed");
2878 OrderedSocketData
data(reads
, arraysize(reads
),
2879 writes
, arraysize(writes
));
2880 RunServerPushTest(&data
,
2883 expected_push_result
);
2885 // Verify the SYN_REPLY.
2886 EXPECT_TRUE(response
.headers
.get() != NULL
);
2887 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
2889 // Verify the pushed stream.
2890 EXPECT_TRUE(response2
.headers
.get() != NULL
);
2891 EXPECT_EQ("HTTP/1.1 200 OK", response2
.headers
->GetStatusLine());
2894 TEST_P(SpdyNetworkTransactionTest
, ServerPushMultipleDataFrame
) {
2895 scoped_ptr
<SpdyFrame
> stream1_syn(
2896 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
2897 scoped_ptr
<SpdyFrame
> stream1_body(
2898 spdy_util_
.ConstructSpdyBodyFrame(1, true));
2899 MockWrite writes
[] = {
2900 CreateMockWrite(*stream1_syn
, 1),
2903 scoped_ptr
<SpdyFrame
>
2904 stream1_reply(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2905 scoped_ptr
<SpdyFrame
>
2906 stream2_syn(spdy_util_
.ConstructSpdyPush(NULL
,
2910 "http://www.google.com/foo.dat"));
2911 static const char kPushedData
[] = "pushed my darling hello my baby";
2912 scoped_ptr
<SpdyFrame
> stream2_body_base(
2913 spdy_util_
.ConstructSpdyBodyFrame(
2914 2, kPushedData
, strlen(kPushedData
), true));
2915 const size_t kChunkSize
= strlen(kPushedData
) / 4;
2916 scoped_ptr
<SpdyFrame
> stream2_body1(
2917 new SpdyFrame(stream2_body_base
->data(), kChunkSize
, false));
2918 scoped_ptr
<SpdyFrame
> stream2_body2(
2919 new SpdyFrame(stream2_body_base
->data() + kChunkSize
, kChunkSize
, false));
2920 scoped_ptr
<SpdyFrame
> stream2_body3(
2921 new SpdyFrame(stream2_body_base
->data() + 2 * kChunkSize
,
2922 kChunkSize
, false));
2923 scoped_ptr
<SpdyFrame
> stream2_body4(
2924 new SpdyFrame(stream2_body_base
->data() + 3 * kChunkSize
,
2925 stream2_body_base
->size() - 3 * kChunkSize
, false));
2926 MockRead reads
[] = {
2927 CreateMockRead(*stream1_reply
, 2),
2928 CreateMockRead(*stream2_syn
, 3),
2929 CreateMockRead(*stream2_body1
, 4),
2930 CreateMockRead(*stream2_body2
, 5),
2931 CreateMockRead(*stream2_body3
, 6),
2932 CreateMockRead(*stream2_body4
, 7),
2933 CreateMockRead(*stream1_body
, 8, SYNCHRONOUS
),
2934 MockRead(ASYNC
, ERR_IO_PENDING
, 9), // Force a pause
2937 HttpResponseInfo response
;
2938 HttpResponseInfo response2
;
2939 std::string
expected_push_result("pushed my darling hello my baby");
2940 OrderedSocketData
data(reads
, arraysize(reads
),
2941 writes
, arraysize(writes
));
2942 RunServerPushTest(&data
, &response
, &response2
, kPushedData
);
2944 // Verify the SYN_REPLY.
2945 EXPECT_TRUE(response
.headers
.get() != NULL
);
2946 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
2948 // Verify the pushed stream.
2949 EXPECT_TRUE(response2
.headers
.get() != NULL
);
2950 EXPECT_EQ("HTTP/1.1 200 OK", response2
.headers
->GetStatusLine());
2953 TEST_P(SpdyNetworkTransactionTest
, ServerPushMultipleDataFrameInterrupted
) {
2954 scoped_ptr
<SpdyFrame
> stream1_syn(
2955 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
2956 scoped_ptr
<SpdyFrame
> stream1_body(
2957 spdy_util_
.ConstructSpdyBodyFrame(1, true));
2958 MockWrite writes
[] = {
2959 CreateMockWrite(*stream1_syn
, 1),
2962 scoped_ptr
<SpdyFrame
>
2963 stream1_reply(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
2964 scoped_ptr
<SpdyFrame
>
2965 stream2_syn(spdy_util_
.ConstructSpdyPush(NULL
,
2969 "http://www.google.com/foo.dat"));
2970 static const char kPushedData
[] = "pushed my darling hello my baby";
2971 scoped_ptr
<SpdyFrame
> stream2_body_base(
2972 spdy_util_
.ConstructSpdyBodyFrame(
2973 2, kPushedData
, strlen(kPushedData
), true));
2974 const size_t kChunkSize
= strlen(kPushedData
) / 4;
2975 scoped_ptr
<SpdyFrame
> stream2_body1(
2976 new SpdyFrame(stream2_body_base
->data(), kChunkSize
, false));
2977 scoped_ptr
<SpdyFrame
> stream2_body2(
2978 new SpdyFrame(stream2_body_base
->data() + kChunkSize
, kChunkSize
, false));
2979 scoped_ptr
<SpdyFrame
> stream2_body3(
2980 new SpdyFrame(stream2_body_base
->data() + 2 * kChunkSize
,
2981 kChunkSize
, false));
2982 scoped_ptr
<SpdyFrame
> stream2_body4(
2983 new SpdyFrame(stream2_body_base
->data() + 3 * kChunkSize
,
2984 stream2_body_base
->size() - 3 * kChunkSize
, false));
2985 MockRead reads
[] = {
2986 CreateMockRead(*stream1_reply
, 2),
2987 CreateMockRead(*stream2_syn
, 3),
2988 CreateMockRead(*stream2_body1
, 4),
2989 CreateMockRead(*stream2_body2
, 5),
2990 MockRead(ASYNC
, ERR_IO_PENDING
, 6), // Force a pause
2991 CreateMockRead(*stream2_body3
, 7),
2992 CreateMockRead(*stream2_body4
, 8),
2993 CreateMockRead(*stream1_body
.get(), 9, SYNCHRONOUS
),
2994 MockRead(ASYNC
, ERR_IO_PENDING
, 10) // Force a pause.
2997 HttpResponseInfo response
;
2998 HttpResponseInfo response2
;
2999 OrderedSocketData
data(reads
, arraysize(reads
),
3000 writes
, arraysize(writes
));
3001 RunServerPushTest(&data
, &response
, &response2
, kPushedData
);
3003 // Verify the SYN_REPLY.
3004 EXPECT_TRUE(response
.headers
.get() != NULL
);
3005 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
3007 // Verify the pushed stream.
3008 EXPECT_TRUE(response2
.headers
.get() != NULL
);
3009 EXPECT_EQ("HTTP/1.1 200 OK", response2
.headers
->GetStatusLine());
3012 TEST_P(SpdyNetworkTransactionTest
, ServerPushInvalidAssociatedStreamID0
) {
3013 if (spdy_util_
.spdy_version() == SPDY4
) {
3014 // PUSH_PROMISE with stream id 0 is connection-level error.
3015 // TODO(baranovich): Test session going away.
3019 scoped_ptr
<SpdyFrame
> stream1_syn(
3020 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
3021 scoped_ptr
<SpdyFrame
> stream1_body(
3022 spdy_util_
.ConstructSpdyBodyFrame(1, true));
3023 scoped_ptr
<SpdyFrame
> stream2_rst(
3024 spdy_util_
.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM
));
3025 MockWrite writes
[] = {
3026 CreateMockWrite(*stream1_syn
, 1),
3027 CreateMockWrite(*stream2_rst
, 4),
3030 scoped_ptr
<SpdyFrame
>
3031 stream1_reply(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
3032 scoped_ptr
<SpdyFrame
>
3033 stream2_syn(spdy_util_
.ConstructSpdyPush(NULL
,
3037 "http://www.google.com/foo.dat"));
3038 MockRead reads
[] = {
3039 CreateMockRead(*stream1_reply
, 2),
3040 CreateMockRead(*stream2_syn
, 3),
3041 CreateMockRead(*stream1_body
, 4),
3042 MockRead(ASYNC
, ERR_IO_PENDING
, 5) // Force a pause
3045 OrderedSocketData
data(reads
, arraysize(reads
),
3046 writes
, arraysize(writes
));
3047 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
3048 BoundNetLog(), GetParam(), NULL
);
3050 helper
.RunPreTestSetup();
3051 helper
.AddData(&data
);
3053 HttpNetworkTransaction
* trans
= helper
.trans();
3055 // Start the transaction with basic parameters.
3056 TestCompletionCallback callback
;
3057 int rv
= trans
->Start(
3058 &CreateGetRequest(), callback
.callback(), BoundNetLog());
3059 EXPECT_EQ(ERR_IO_PENDING
, rv
);
3060 rv
= callback
.WaitForResult();
3063 // Verify that we consumed all test data.
3064 EXPECT_TRUE(data
.at_read_eof()) << "Read count: "
3065 << data
.read_count()
3067 << data
.read_index();
3068 EXPECT_TRUE(data
.at_write_eof()) << "Write count: "
3069 << data
.write_count()
3071 << data
.write_index();
3073 // Verify the SYN_REPLY.
3074 HttpResponseInfo response
= *trans
->GetResponseInfo();
3075 EXPECT_TRUE(response
.headers
.get() != NULL
);
3076 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
3079 TEST_P(SpdyNetworkTransactionTest
, ServerPushInvalidAssociatedStreamID9
) {
3080 scoped_ptr
<SpdyFrame
> stream1_syn(
3081 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
3082 scoped_ptr
<SpdyFrame
> stream1_body(
3083 spdy_util_
.ConstructSpdyBodyFrame(1, true));
3084 scoped_ptr
<SpdyFrame
> stream2_rst(
3085 spdy_util_
.ConstructSpdyRstStream(2, RST_STREAM_INVALID_STREAM
));
3086 MockWrite writes
[] = {
3087 CreateMockWrite(*stream1_syn
, 1),
3088 CreateMockWrite(*stream2_rst
, 4),
3091 scoped_ptr
<SpdyFrame
>
3092 stream1_reply(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
3093 scoped_ptr
<SpdyFrame
>
3094 stream2_syn(spdy_util_
.ConstructSpdyPush(NULL
,
3098 "http://www.google.com/foo.dat"));
3099 MockRead reads
[] = {
3100 CreateMockRead(*stream1_reply
, 2),
3101 CreateMockRead(*stream2_syn
, 3),
3102 CreateMockRead(*stream1_body
, 4),
3103 MockRead(ASYNC
, ERR_IO_PENDING
, 5), // Force a pause
3106 OrderedSocketData
data(reads
, arraysize(reads
),
3107 writes
, arraysize(writes
));
3108 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
3109 BoundNetLog(), GetParam(), NULL
);
3111 helper
.RunPreTestSetup();
3112 helper
.AddData(&data
);
3114 HttpNetworkTransaction
* trans
= helper
.trans();
3116 // Start the transaction with basic parameters.
3117 TestCompletionCallback callback
;
3118 int rv
= trans
->Start(
3119 &CreateGetRequest(), callback
.callback(), BoundNetLog());
3120 EXPECT_EQ(ERR_IO_PENDING
, rv
);
3121 rv
= callback
.WaitForResult();
3124 // Verify that we consumed all test data.
3125 EXPECT_TRUE(data
.at_read_eof()) << "Read count: "
3126 << data
.read_count()
3128 << data
.read_index();
3129 EXPECT_TRUE(data
.at_write_eof()) << "Write count: "
3130 << data
.write_count()
3132 << data
.write_index();
3134 // Verify the SYN_REPLY.
3135 HttpResponseInfo response
= *trans
->GetResponseInfo();
3136 EXPECT_TRUE(response
.headers
.get() != NULL
);
3137 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
3140 TEST_P(SpdyNetworkTransactionTest
, ServerPushNoURL
) {
3141 scoped_ptr
<SpdyFrame
> stream1_syn(
3142 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
3143 scoped_ptr
<SpdyFrame
> stream1_body(
3144 spdy_util_
.ConstructSpdyBodyFrame(1, true));
3145 scoped_ptr
<SpdyFrame
> stream2_rst(
3146 spdy_util_
.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR
));
3147 MockWrite writes
[] = {
3148 CreateMockWrite(*stream1_syn
, 1),
3149 CreateMockWrite(*stream2_rst
, 4),
3152 scoped_ptr
<SpdyFrame
>
3153 stream1_reply(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
3154 scoped_ptr
<SpdyHeaderBlock
> incomplete_headers(new SpdyHeaderBlock());
3155 (*incomplete_headers
)["hello"] = "bye";
3156 (*incomplete_headers
)[spdy_util_
.GetStatusKey()] = "200 OK";
3157 (*incomplete_headers
)[spdy_util_
.GetVersionKey()] = "HTTP/1.1";
3158 scoped_ptr
<SpdyFrame
> stream2_syn(spdy_util_
.ConstructInitialSpdyPushFrame(
3159 incomplete_headers
.Pass(), 2, 1));
3160 MockRead reads
[] = {
3161 CreateMockRead(*stream1_reply
, 2),
3162 CreateMockRead(*stream2_syn
, 3),
3163 CreateMockRead(*stream1_body
, 4),
3164 MockRead(ASYNC
, ERR_IO_PENDING
, 5) // Force a pause
3167 OrderedSocketData
data(reads
, arraysize(reads
),
3168 writes
, arraysize(writes
));
3169 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
3170 BoundNetLog(), GetParam(), NULL
);
3172 helper
.RunPreTestSetup();
3173 helper
.AddData(&data
);
3175 HttpNetworkTransaction
* trans
= helper
.trans();
3177 // Start the transaction with basic parameters.
3178 TestCompletionCallback callback
;
3179 int rv
= trans
->Start(
3180 &CreateGetRequest(), callback
.callback(), BoundNetLog());
3181 EXPECT_EQ(ERR_IO_PENDING
, rv
);
3182 rv
= callback
.WaitForResult();
3184 // Verify that we consumed all test data.
3185 EXPECT_TRUE(data
.at_read_eof()) << "Read count: "
3186 << data
.read_count()
3188 << data
.read_index();
3189 EXPECT_TRUE(data
.at_write_eof()) << "Write count: "
3190 << data
.write_count()
3192 << data
.write_index();
3194 // Verify the SYN_REPLY.
3195 HttpResponseInfo response
= *trans
->GetResponseInfo();
3196 EXPECT_TRUE(response
.headers
.get() != NULL
);
3197 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
3200 // Verify that various SynReply headers parse correctly through the
3202 TEST_P(SpdyNetworkTransactionTest
, SynReplyHeaders
) {
3203 struct SynReplyHeadersTests
{
3205 const char* extra_headers
[5];
3206 SpdyHeaderBlock expected_headers
;
3208 // This uses a multi-valued cookie header.
3211 "cookie", "val2", // will get appended separated by NULL
3215 // This is the minimalist set of headers.
3219 // Headers with a comma separated list.
3221 { "cookie", "val1,val2",
3227 test_cases
[0].expected_headers
["cookie"] = "val1";
3228 test_cases
[0].expected_headers
["cookie"] += '\0';
3229 test_cases
[0].expected_headers
["cookie"] += "val2";
3230 test_cases
[0].expected_headers
["hello"] = "bye";
3231 test_cases
[0].expected_headers
["status"] = "200";
3233 test_cases
[1].expected_headers
["hello"] = "bye";
3234 test_cases
[1].expected_headers
["status"] = "200";
3236 test_cases
[2].expected_headers
["cookie"] = "val1,val2";
3237 test_cases
[2].expected_headers
["hello"] = "bye";
3238 test_cases
[2].expected_headers
["status"] = "200";
3240 if (spdy_util_
.spdy_version() < SPDY4
) {
3241 // SPDY4/HTTP2 eliminates use of the :version header.
3242 test_cases
[0].expected_headers
["version"] = "HTTP/1.1";
3243 test_cases
[1].expected_headers
["version"] = "HTTP/1.1";
3244 test_cases
[2].expected_headers
["version"] = "HTTP/1.1";
3247 for (size_t i
= 0; i
< arraysize(test_cases
); ++i
) {
3248 scoped_ptr
<SpdyFrame
> req(
3249 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
3250 MockWrite writes
[] = { CreateMockWrite(*req
) };
3252 scoped_ptr
<SpdyFrame
> resp(
3253 spdy_util_
.ConstructSpdyGetSynReply(test_cases
[i
].extra_headers
,
3254 test_cases
[i
].num_headers
,
3256 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
3257 MockRead reads
[] = {
3258 CreateMockRead(*resp
),
3259 CreateMockRead(*body
),
3260 MockRead(ASYNC
, 0, 0) // EOF
3263 DelayedSocketData
data(1, reads
, arraysize(reads
),
3264 writes
, arraysize(writes
));
3265 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
3266 BoundNetLog(), GetParam(), NULL
);
3267 helper
.RunToCompletion(&data
);
3268 TransactionHelperResult out
= helper
.output();
3270 EXPECT_EQ(OK
, out
.rv
);
3271 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
3272 EXPECT_EQ("hello!", out
.response_data
);
3274 scoped_refptr
<HttpResponseHeaders
> headers
= out
.response_info
.headers
;
3275 EXPECT_TRUE(headers
.get() != NULL
);
3277 std::string name
, value
;
3278 SpdyHeaderBlock header_block
;
3279 while (headers
->EnumerateHeaderLines(&iter
, &name
, &value
)) {
3280 if (header_block
[name
].empty()) {
3281 header_block
[name
] = value
;
3283 header_block
[name
] += '\0';
3284 header_block
[name
] += value
;
3287 EXPECT_EQ(test_cases
[i
].expected_headers
, header_block
);
3291 // Verify that various SynReply headers parse vary fields correctly
3292 // through the HTTP layer, and the response matches the request.
3293 TEST_P(SpdyNetworkTransactionTest
, SynReplyHeadersVary
) {
3294 // Modify the following data to change/add test cases:
3295 struct SynReplyTests
{
3298 const char* extra_headers
[2][16];
3300 // Test the case of a multi-valued cookie. When the value is delimited
3301 // with NUL characters, it needs to be unfolded into multiple headers.
3305 { { "cookie", "val1,val2",
3309 spdy_util_
.GetStatusKey(), "200",
3310 spdy_util_
.GetPathKey(), "/index.php",
3311 spdy_util_
.GetVersionKey(), "HTTP/1.1",
3315 }, { // Multiple vary fields.
3318 { { "friend", "barney",
3319 "enemy", "snaggletooth",
3324 spdy_util_
.GetStatusKey(), "200",
3325 spdy_util_
.GetPathKey(), "/index.php",
3326 spdy_util_
.GetVersionKey(), "HTTP/1.1",
3330 }, { // Test a '*' vary field.
3333 { { "cookie", "val1,val2",
3337 spdy_util_
.GetStatusKey(), "200",
3338 spdy_util_
.GetPathKey(), "/index.php",
3339 spdy_util_
.GetVersionKey(), "HTTP/1.1",
3343 }, { // Multiple comma-separated vary fields.
3346 { { "friend", "barney",
3347 "enemy", "snaggletooth",
3350 { "vary", "friend,enemy",
3351 spdy_util_
.GetStatusKey(), "200",
3352 spdy_util_
.GetPathKey(), "/index.php",
3353 spdy_util_
.GetVersionKey(), "HTTP/1.1",
3360 for (size_t i
= 0; i
< arraysize(test_cases
); ++i
) {
3361 // Construct the request.
3362 scoped_ptr
<SpdyFrame
> frame_req(
3363 spdy_util_
.ConstructSpdyGet(test_cases
[i
].extra_headers
[0],
3364 test_cases
[i
].num_headers
[0],
3365 false, 1, LOWEST
, true));
3367 MockWrite writes
[] = {
3368 CreateMockWrite(*frame_req
),
3371 // Construct the reply.
3372 SpdyHeaderBlock reply_headers
;
3373 AppendToHeaderBlock(test_cases
[i
].extra_headers
[1],
3374 test_cases
[i
].num_headers
[1],
3376 scoped_ptr
<SpdyFrame
> frame_reply(
3377 spdy_util_
.ConstructSpdyReply(1, reply_headers
));
3379 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
3380 MockRead reads
[] = {
3381 CreateMockRead(*frame_reply
),
3382 CreateMockRead(*body
),
3383 MockRead(ASYNC
, 0, 0) // EOF
3386 // Attach the headers to the request.
3387 int header_count
= test_cases
[i
].num_headers
[0];
3389 HttpRequestInfo request
= CreateGetRequest();
3390 for (int ct
= 0; ct
< header_count
; ct
++) {
3391 const char* header_key
= test_cases
[i
].extra_headers
[0][ct
* 2];
3392 const char* header_value
= test_cases
[i
].extra_headers
[0][ct
* 2 + 1];
3393 request
.extra_headers
.SetHeader(header_key
, header_value
);
3396 DelayedSocketData
data(1, reads
, arraysize(reads
),
3397 writes
, arraysize(writes
));
3398 NormalSpdyTransactionHelper
helper(request
, DEFAULT_PRIORITY
,
3399 BoundNetLog(), GetParam(), NULL
);
3400 helper
.RunToCompletion(&data
);
3401 TransactionHelperResult out
= helper
.output();
3403 EXPECT_EQ(OK
, out
.rv
) << i
;
3404 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
) << i
;
3405 EXPECT_EQ("hello!", out
.response_data
) << i
;
3407 // Test the response information.
3408 EXPECT_TRUE(out
.response_info
.response_time
>
3409 out
.response_info
.request_time
) << i
;
3410 base::TimeDelta test_delay
= out
.response_info
.response_time
-
3411 out
.response_info
.request_time
;
3412 base::TimeDelta min_expected_delay
;
3413 min_expected_delay
.FromMilliseconds(10);
3414 EXPECT_GT(test_delay
.InMillisecondsF(),
3415 min_expected_delay
.InMillisecondsF()) << i
;
3416 EXPECT_EQ(out
.response_info
.vary_data
.is_valid(),
3417 test_cases
[i
].vary_matches
) << i
;
3419 // Check the headers.
3420 scoped_refptr
<HttpResponseHeaders
> headers
= out
.response_info
.headers
;
3421 ASSERT_TRUE(headers
.get() != NULL
) << i
;
3423 std::string name
, value
, lines
;
3424 while (headers
->EnumerateHeaderLines(&iter
, &name
, &value
)) {
3427 lines
.append(value
);
3431 // Construct the expected header reply string.
3432 std::string expected_reply
=
3433 spdy_util_
.ConstructSpdyReplyString(reply_headers
);
3434 EXPECT_EQ(expected_reply
, lines
) << i
;
3438 // Verify that we don't crash on invalid SynReply responses.
3439 TEST_P(SpdyNetworkTransactionTest
, InvalidSynReply
) {
3440 struct InvalidSynReplyTests
{
3442 const char* headers
[10];
3444 // SYN_REPLY missing status header
3448 spdy_util_
.GetPathKey(), "/index.php",
3449 spdy_util_
.GetVersionKey(), "HTTP/1.1",
3453 // SYN_REPLY missing version header
3456 spdy_util_
.GetPathKey(), "/index.php",
3460 // SYN_REPLY with no headers
3464 for (size_t i
= 0; i
< arraysize(test_cases
); ++i
) {
3465 scoped_ptr
<SpdyFrame
> req(
3466 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
3467 scoped_ptr
<SpdyFrame
> rst(
3468 spdy_util_
.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR
));
3469 MockWrite writes
[] = {
3470 CreateMockWrite(*req
),
3471 CreateMockWrite(*rst
),
3474 // Construct the reply.
3475 SpdyHeaderBlock reply_headers
;
3476 AppendToHeaderBlock(
3477 test_cases
[i
].headers
, test_cases
[i
].num_headers
, &reply_headers
);
3478 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyReply(1, reply_headers
));
3479 MockRead reads
[] = {
3480 CreateMockRead(*resp
),
3481 MockRead(ASYNC
, 0, 0) // EOF
3484 DelayedSocketData
data(1, reads
, arraysize(reads
),
3485 writes
, arraysize(writes
));
3486 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
3487 BoundNetLog(), GetParam(), NULL
);
3488 helper
.RunToCompletion(&data
);
3489 TransactionHelperResult out
= helper
.output();
3490 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR
, out
.rv
);
3494 // Verify that we don't crash on some corrupt frames.
3495 // TODO(jgraettinger): SPDY4 and up treats a header decompression failure as a
3496 // connection error. I'd like to backport this behavior to SPDY3 as well.
3497 TEST_P(SpdyNetworkTransactionTest
, CorruptFrameSessionError
) {
3498 if (spdy_util_
.spdy_version() >= SPDY4
) {
3501 // This is the length field that's too short.
3502 scoped_ptr
<SpdyFrame
> syn_reply_wrong_length(
3503 spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
3504 BufferedSpdyFramer
framer(spdy_util_
.spdy_version(), false);
3506 (spdy_util_
.spdy_version() < SPDY4
) ?
3507 syn_reply_wrong_length
->size() - framer
.GetControlFrameHeaderSize() :
3508 syn_reply_wrong_length
->size();
3509 size_t wrong_size
= right_size
- 4;
3510 test::SetFrameLength(syn_reply_wrong_length
.get(),
3512 spdy_util_
.spdy_version());
3514 struct SynReplyTests
{
3515 const SpdyFrame
* syn_reply
;
3517 { syn_reply_wrong_length
.get(), },
3520 for (size_t i
= 0; i
< arraysize(test_cases
); ++i
) {
3521 scoped_ptr
<SpdyFrame
> req(
3522 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
3523 scoped_ptr
<SpdyFrame
> rst(
3524 spdy_util_
.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR
));
3525 MockWrite writes
[] = {
3526 CreateMockWrite(*req
),
3527 CreateMockWrite(*rst
),
3530 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
3531 MockRead reads
[] = {
3532 MockRead(ASYNC
, test_cases
[i
].syn_reply
->data(), wrong_size
),
3533 CreateMockRead(*body
),
3534 MockRead(ASYNC
, 0, 0) // EOF
3537 DelayedSocketData
data(1, reads
, arraysize(reads
),
3538 writes
, arraysize(writes
));
3539 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
3540 BoundNetLog(), GetParam(), NULL
);
3541 helper
.RunToCompletion(&data
);
3542 TransactionHelperResult out
= helper
.output();
3543 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR
, out
.rv
);
3547 // SPDY4 treats a header decompression failure as a connection-level error.
3548 TEST_P(SpdyNetworkTransactionTest
, CorruptFrameSessionErrorSpdy4
) {
3549 if (spdy_util_
.spdy_version() < SPDY4
) {
3552 // This is the length field that's too short.
3553 scoped_ptr
<SpdyFrame
> syn_reply_wrong_length(
3554 spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
3555 BufferedSpdyFramer
framer(spdy_util_
.spdy_version(), false);
3557 syn_reply_wrong_length
->size() - framer
.GetControlFrameHeaderSize();
3558 size_t wrong_size
= right_size
- 4;
3559 test::SetFrameLength(syn_reply_wrong_length
.get(),
3561 spdy_util_
.spdy_version());
3563 scoped_ptr
<SpdyFrame
> req(
3564 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
3565 scoped_ptr
<SpdyFrame
> goaway(spdy_util_
.ConstructSpdyGoAway(
3566 0, GOAWAY_COMPRESSION_ERROR
, "Framer error: 5 (DECOMPRESS_FAILURE)."));
3567 MockWrite writes
[] = {CreateMockWrite(*req
), CreateMockWrite(*goaway
)};
3569 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
3570 MockRead reads
[] = {
3571 MockRead(ASYNC
, syn_reply_wrong_length
->data(),
3572 syn_reply_wrong_length
->size() - 4),
3575 DelayedSocketData
data(1, reads
, arraysize(reads
),
3576 writes
, arraysize(writes
));
3577 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
3578 BoundNetLog(), GetParam(), NULL
);
3579 helper
.RunToCompletion(&data
);
3580 TransactionHelperResult out
= helper
.output();
3581 EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR
, out
.rv
);
3584 TEST_P(SpdyNetworkTransactionTest
, GoAwayOnDecompressionFailure
) {
3585 if (GetParam().protocol
< kProtoSPDY4MinimumVersion
) {
3586 // Decompression failures are a stream error in SPDY3 and above.
3589 scoped_ptr
<SpdyFrame
> req(
3590 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
3591 scoped_ptr
<SpdyFrame
> goaway(spdy_util_
.ConstructSpdyGoAway(
3592 0, GOAWAY_COMPRESSION_ERROR
, "Framer error: 5 (DECOMPRESS_FAILURE)."));
3593 MockWrite writes
[] = {CreateMockWrite(*req
), CreateMockWrite(*goaway
)};
3595 // Read HEADERS with corrupted payload.
3596 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
3597 memset(resp
->data() + 12, 0xff, resp
->size() - 12);
3598 MockRead reads
[] = {CreateMockRead(*resp
)};
3600 DelayedSocketData
data(1, reads
, arraysize(reads
), writes
, arraysize(writes
));
3601 NormalSpdyTransactionHelper
helper(
3602 CreateGetRequest(), DEFAULT_PRIORITY
, BoundNetLog(), GetParam(), NULL
);
3603 helper
.RunToCompletion(&data
);
3604 TransactionHelperResult out
= helper
.output();
3605 EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR
, out
.rv
);
3608 TEST_P(SpdyNetworkTransactionTest
, GoAwayOnFrameSizeError
) {
3609 scoped_ptr
<SpdyFrame
> req(
3610 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
3611 scoped_ptr
<SpdyFrame
> goaway(spdy_util_
.ConstructSpdyGoAway(
3612 0, GOAWAY_PROTOCOL_ERROR
, "Framer error: 1 (INVALID_CONTROL_FRAME)."));
3613 MockWrite writes
[] = {CreateMockWrite(*req
), CreateMockWrite(*goaway
)};
3615 // Read WINDOW_UPDATE with incorrectly-sized payload.
3616 // TODO(jgraettinger): SpdyFramer signals this as an INVALID_CONTROL_FRAME,
3617 // which is mapped to a protocol error, and not a frame size error.
3618 scoped_ptr
<SpdyFrame
> bad_window_update(
3619 spdy_util_
.ConstructSpdyWindowUpdate(1, 1));
3620 test::SetFrameLength(bad_window_update
.get(),
3621 bad_window_update
->size() - 1,
3622 spdy_util_
.spdy_version());
3623 MockRead reads
[] = {CreateMockRead(*bad_window_update
)};
3625 DelayedSocketData
data(1, reads
, arraysize(reads
), writes
, arraysize(writes
));
3626 NormalSpdyTransactionHelper
helper(
3627 CreateGetRequest(), DEFAULT_PRIORITY
, BoundNetLog(), GetParam(), NULL
);
3628 helper
.RunToCompletion(&data
);
3629 TransactionHelperResult out
= helper
.output();
3630 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR
, out
.rv
);
3633 // Test that we shutdown correctly on write errors.
3634 TEST_P(SpdyNetworkTransactionTest
, WriteError
) {
3635 scoped_ptr
<SpdyFrame
> req(
3636 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
3637 MockWrite writes
[] = {
3638 // We'll write 10 bytes successfully
3639 MockWrite(ASYNC
, req
->data(), 10, 0),
3640 // Followed by ERROR!
3641 MockWrite(ASYNC
, ERR_FAILED
, 1),
3642 // Session drains and attempts to write a GOAWAY: Another ERROR!
3643 MockWrite(ASYNC
, ERR_FAILED
, 2),
3646 MockRead reads
[] = {
3647 MockRead(ASYNC
, 0, 3) // EOF
3650 DeterministicSocketData
data(reads
, arraysize(reads
),
3651 writes
, arraysize(writes
));
3653 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
3654 BoundNetLog(), GetParam(), NULL
);
3655 helper
.SetDeterministic();
3656 helper
.RunPreTestSetup();
3657 helper
.AddDeterministicData(&data
);
3658 EXPECT_TRUE(helper
.StartDefaultTest());
3660 helper
.FinishDefaultTest();
3661 EXPECT_TRUE(data
.at_write_eof());
3662 EXPECT_TRUE(!data
.at_read_eof());
3663 TransactionHelperResult out
= helper
.output();
3664 EXPECT_EQ(ERR_FAILED
, out
.rv
);
3667 // Test that partial writes work.
3668 TEST_P(SpdyNetworkTransactionTest
, PartialWrite
) {
3669 // Chop the SYN_STREAM frame into 5 chunks.
3670 scoped_ptr
<SpdyFrame
> req(
3671 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
3672 const int kChunks
= 5;
3673 scoped_ptr
<MockWrite
[]> writes(ChopWriteFrame(*req
.get(), kChunks
));
3675 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
3676 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
3677 MockRead reads
[] = {
3678 CreateMockRead(*resp
),
3679 CreateMockRead(*body
),
3680 MockRead(ASYNC
, 0, 0) // EOF
3683 DelayedSocketData
data(kChunks
, reads
, arraysize(reads
),
3684 writes
.get(), kChunks
);
3685 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
3686 BoundNetLog(), GetParam(), NULL
);
3687 helper
.RunToCompletion(&data
);
3688 TransactionHelperResult out
= helper
.output();
3689 EXPECT_EQ(OK
, out
.rv
);
3690 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
3691 EXPECT_EQ("hello!", out
.response_data
);
3694 // In this test, we enable compression, but get a uncompressed SynReply from
3695 // the server. Verify that teardown is all clean.
3696 TEST_P(SpdyNetworkTransactionTest
, DecompressFailureOnSynReply
) {
3697 if (spdy_util_
.spdy_version() >= SPDY4
) {
3698 // HPACK doesn't use deflate compression.
3701 scoped_ptr
<SpdyFrame
> compressed(
3702 spdy_util_
.ConstructSpdyGet(NULL
, 0, true, 1, LOWEST
, true));
3703 scoped_ptr
<SpdyFrame
> goaway(spdy_util_
.ConstructSpdyGoAway(
3704 0, GOAWAY_COMPRESSION_ERROR
, "Framer error: 5 (DECOMPRESS_FAILURE)."));
3705 MockWrite writes
[] = {CreateMockWrite(*compressed
), CreateMockWrite(*goaway
)};
3707 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
3708 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
3709 MockRead reads
[] = {
3710 CreateMockRead(*resp
),
3713 DelayedSocketData
data(1, reads
, arraysize(reads
),
3714 writes
, arraysize(writes
));
3715 SpdySessionDependencies
* session_deps
=
3716 CreateSpdySessionDependencies(GetParam());
3717 session_deps
->enable_compression
= true;
3718 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
3719 BoundNetLog(), GetParam(), session_deps
);
3720 helper
.RunToCompletion(&data
);
3721 TransactionHelperResult out
= helper
.output();
3722 EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR
, out
.rv
);
3726 // Test that the NetLog contains good data for a simple GET request.
3727 TEST_P(SpdyNetworkTransactionTest
, NetLog
) {
3728 static const char* const kExtraHeaders
[] = {
3729 "user-agent", "Chrome",
3731 scoped_ptr
<SpdyFrame
> req(
3732 spdy_util_
.ConstructSpdyGet(kExtraHeaders
, 1, false, 1, LOWEST
, true));
3733 MockWrite writes
[] = { CreateMockWrite(*req
) };
3735 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
3736 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
3737 MockRead reads
[] = {
3738 CreateMockRead(*resp
),
3739 CreateMockRead(*body
),
3740 MockRead(ASYNC
, 0, 0) // EOF
3743 CapturingBoundNetLog log
;
3745 DelayedSocketData
data(1, reads
, arraysize(reads
),
3746 writes
, arraysize(writes
));
3747 NormalSpdyTransactionHelper
helper(CreateGetRequestWithUserAgent(),
3749 log
.bound(), GetParam(), NULL
);
3750 helper
.RunToCompletion(&data
);
3751 TransactionHelperResult out
= helper
.output();
3752 EXPECT_EQ(OK
, out
.rv
);
3753 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
3754 EXPECT_EQ("hello!", out
.response_data
);
3756 // Check that the NetLog was filled reasonably.
3757 // This test is intentionally non-specific about the exact ordering of the
3758 // log; instead we just check to make sure that certain events exist, and that
3759 // they are in the right order.
3760 CapturingNetLog::CapturedEntryList entries
;
3761 log
.GetEntries(&entries
);
3763 EXPECT_LT(0u, entries
.size());
3765 pos
= ExpectLogContainsSomewhere(entries
, 0,
3766 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST
,
3767 NetLog::PHASE_BEGIN
);
3768 pos
= ExpectLogContainsSomewhere(entries
, pos
+ 1,
3769 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST
,
3771 pos
= ExpectLogContainsSomewhere(entries
, pos
+ 1,
3772 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS
,
3773 NetLog::PHASE_BEGIN
);
3774 pos
= ExpectLogContainsSomewhere(entries
, pos
+ 1,
3775 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS
,
3777 pos
= ExpectLogContainsSomewhere(entries
, pos
+ 1,
3778 NetLog::TYPE_HTTP_TRANSACTION_READ_BODY
,
3779 NetLog::PHASE_BEGIN
);
3780 pos
= ExpectLogContainsSomewhere(entries
, pos
+ 1,
3781 NetLog::TYPE_HTTP_TRANSACTION_READ_BODY
,
3784 // Check that we logged all the headers correctly
3785 const NetLog::EventType type
= (GetParam().protocol
<= kProtoSPDY31
)
3786 ? NetLog::TYPE_HTTP2_SESSION_SYN_STREAM
3787 : NetLog::TYPE_HTTP2_SESSION_SEND_HEADERS
;
3788 pos
= ExpectLogContainsSomewhere(entries
, 0, type
, NetLog::PHASE_NONE
);
3790 base::ListValue
* header_list
;
3791 ASSERT_TRUE(entries
[pos
].params
.get());
3792 ASSERT_TRUE(entries
[pos
].params
->GetList("headers", &header_list
));
3794 std::vector
<std::string
> expected
;
3795 expected
.push_back(std::string(spdy_util_
.GetHostKey()) + ": www.google.com");
3796 expected
.push_back(std::string(spdy_util_
.GetPathKey()) + ": /");
3797 expected
.push_back(std::string(spdy_util_
.GetSchemeKey()) + ": http");
3798 expected
.push_back(std::string(spdy_util_
.GetMethodKey()) + ": GET");
3799 expected
.push_back("user-agent: Chrome");
3800 if (spdy_util_
.spdy_version() < SPDY4
) {
3801 // SPDY4/HTTP2 eliminates use of the :version header.
3802 expected
.push_back(std::string(spdy_util_
.GetVersionKey()) + ": HTTP/1.1");
3804 EXPECT_EQ(expected
.size(), header_list
->GetSize());
3805 for (std::vector
<std::string
>::const_iterator it
= expected
.begin();
3806 it
!= expected
.end();
3808 base::StringValue
header(*it
);
3809 EXPECT_NE(header_list
->end(), header_list
->Find(header
)) <<
3810 "Header not found: " << *it
;
3814 // Since we buffer the IO from the stream to the renderer, this test verifies
3815 // that when we read out the maximum amount of data (e.g. we received 50 bytes
3816 // on the network, but issued a Read for only 5 of those bytes) that the data
3817 // flow still works correctly.
3818 TEST_P(SpdyNetworkTransactionTest
, BufferFull
) {
3819 BufferedSpdyFramer
framer(spdy_util_
.spdy_version(), false);
3821 scoped_ptr
<SpdyFrame
> req(
3822 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
3823 MockWrite writes
[] = { CreateMockWrite(*req
) };
3825 // 2 data frames in a single read.
3826 scoped_ptr
<SpdyFrame
> data_frame_1(
3827 framer
.CreateDataFrame(1, "goodby", 6, DATA_FLAG_NONE
));
3828 scoped_ptr
<SpdyFrame
> data_frame_2(
3829 framer
.CreateDataFrame(1, "e worl", 6, DATA_FLAG_NONE
));
3830 const SpdyFrame
* data_frames
[2] = {
3834 char combined_data_frames
[100];
3835 int combined_data_frames_len
=
3836 CombineFrames(data_frames
, arraysize(data_frames
),
3837 combined_data_frames
, arraysize(combined_data_frames
));
3838 scoped_ptr
<SpdyFrame
> last_frame(
3839 framer
.CreateDataFrame(1, "d", 1, DATA_FLAG_FIN
));
3841 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
3842 MockRead reads
[] = {
3843 CreateMockRead(*resp
),
3844 MockRead(ASYNC
, ERR_IO_PENDING
), // Force a pause
3845 MockRead(ASYNC
, combined_data_frames
, combined_data_frames_len
),
3846 MockRead(ASYNC
, ERR_IO_PENDING
), // Force a pause
3847 CreateMockRead(*last_frame
),
3848 MockRead(ASYNC
, 0, 0) // EOF
3851 DelayedSocketData
data(1, reads
, arraysize(reads
),
3852 writes
, arraysize(writes
));
3854 TestCompletionCallback callback
;
3856 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
3857 BoundNetLog(), GetParam(), NULL
);
3858 helper
.RunPreTestSetup();
3859 helper
.AddData(&data
);
3860 HttpNetworkTransaction
* trans
= helper
.trans();
3861 int rv
= trans
->Start(
3862 &CreateGetRequest(), callback
.callback(), BoundNetLog());
3863 EXPECT_EQ(ERR_IO_PENDING
, rv
);
3865 TransactionHelperResult out
= helper
.output();
3866 out
.rv
= callback
.WaitForResult();
3867 EXPECT_EQ(out
.rv
, OK
);
3869 const HttpResponseInfo
* response
= trans
->GetResponseInfo();
3870 EXPECT_TRUE(response
->headers
.get() != NULL
);
3871 EXPECT_TRUE(response
->was_fetched_via_spdy
);
3872 out
.status_line
= response
->headers
->GetStatusLine();
3873 out
.response_info
= *response
; // Make a copy so we can verify.
3876 TestCompletionCallback read_callback
;
3878 std::string content
;
3880 // Read small chunks at a time.
3881 const int kSmallReadSize
= 3;
3882 scoped_refptr
<IOBuffer
> buf(new IOBuffer(kSmallReadSize
));
3883 rv
= trans
->Read(buf
.get(), kSmallReadSize
, read_callback
.callback());
3884 if (rv
== ERR_IO_PENDING
) {
3885 data
.CompleteRead();
3886 rv
= read_callback
.WaitForResult();
3889 content
.append(buf
->data(), rv
);
3890 } else if (rv
< 0) {
3895 out
.response_data
.swap(content
);
3897 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the
3898 // MockClientSocketFactory) are still alive.
3899 base::RunLoop().RunUntilIdle();
3901 // Verify that we consumed all test data.
3902 helper
.VerifyDataConsumed();
3904 EXPECT_EQ(OK
, out
.rv
);
3905 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
3906 EXPECT_EQ("goodbye world", out
.response_data
);
3909 // Verify that basic buffering works; when multiple data frames arrive
3910 // at the same time, ensure that we don't notify a read completion for
3911 // each data frame individually.
3912 TEST_P(SpdyNetworkTransactionTest
, Buffering
) {
3913 BufferedSpdyFramer
framer(spdy_util_
.spdy_version(), false);
3915 scoped_ptr
<SpdyFrame
> req(
3916 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
3917 MockWrite writes
[] = { CreateMockWrite(*req
) };
3919 // 4 data frames in a single read.
3920 scoped_ptr
<SpdyFrame
> data_frame(
3921 framer
.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE
));
3922 scoped_ptr
<SpdyFrame
> data_frame_fin(
3923 framer
.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN
));
3924 const SpdyFrame
* data_frames
[4] = {
3928 data_frame_fin
.get()
3930 char combined_data_frames
[100];
3931 int combined_data_frames_len
=
3932 CombineFrames(data_frames
, arraysize(data_frames
),
3933 combined_data_frames
, arraysize(combined_data_frames
));
3935 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
3936 MockRead reads
[] = {
3937 CreateMockRead(*resp
),
3938 MockRead(ASYNC
, ERR_IO_PENDING
), // Force a pause
3939 MockRead(ASYNC
, combined_data_frames
, combined_data_frames_len
),
3940 MockRead(ASYNC
, 0, 0) // EOF
3943 DelayedSocketData
data(1, reads
, arraysize(reads
),
3944 writes
, arraysize(writes
));
3946 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
3947 BoundNetLog(), GetParam(), NULL
);
3948 helper
.RunPreTestSetup();
3949 helper
.AddData(&data
);
3950 HttpNetworkTransaction
* trans
= helper
.trans();
3952 TestCompletionCallback callback
;
3953 int rv
= trans
->Start(
3954 &CreateGetRequest(), callback
.callback(), BoundNetLog());
3955 EXPECT_EQ(ERR_IO_PENDING
, rv
);
3957 TransactionHelperResult out
= helper
.output();
3958 out
.rv
= callback
.WaitForResult();
3959 EXPECT_EQ(out
.rv
, OK
);
3961 const HttpResponseInfo
* response
= trans
->GetResponseInfo();
3962 EXPECT_TRUE(response
->headers
.get() != NULL
);
3963 EXPECT_TRUE(response
->was_fetched_via_spdy
);
3964 out
.status_line
= response
->headers
->GetStatusLine();
3965 out
.response_info
= *response
; // Make a copy so we can verify.
3968 TestCompletionCallback read_callback
;
3970 std::string content
;
3971 int reads_completed
= 0;
3973 // Read small chunks at a time.
3974 const int kSmallReadSize
= 14;
3975 scoped_refptr
<IOBuffer
> buf(new IOBuffer(kSmallReadSize
));
3976 rv
= trans
->Read(buf
.get(), kSmallReadSize
, read_callback
.callback());
3977 if (rv
== ERR_IO_PENDING
) {
3978 data
.CompleteRead();
3979 rv
= read_callback
.WaitForResult();
3982 EXPECT_EQ(kSmallReadSize
, rv
);
3983 content
.append(buf
->data(), rv
);
3984 } else if (rv
< 0) {
3985 FAIL() << "Unexpected read error: " << rv
;
3990 EXPECT_EQ(3, reads_completed
); // Reads are: 14 bytes, 14 bytes, 0 bytes.
3992 out
.response_data
.swap(content
);
3994 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the
3995 // MockClientSocketFactory) are still alive.
3996 base::RunLoop().RunUntilIdle();
3998 // Verify that we consumed all test data.
3999 helper
.VerifyDataConsumed();
4001 EXPECT_EQ(OK
, out
.rv
);
4002 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
4003 EXPECT_EQ("messagemessagemessagemessage", out
.response_data
);
4006 // Verify the case where we buffer data but read it after it has been buffered.
4007 TEST_P(SpdyNetworkTransactionTest
, BufferedAll
) {
4008 BufferedSpdyFramer
framer(spdy_util_
.spdy_version(), false);
4010 scoped_ptr
<SpdyFrame
> req(
4011 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
4012 MockWrite writes
[] = { CreateMockWrite(*req
) };
4014 // 5 data frames in a single read.
4015 scoped_ptr
<SpdyFrame
> reply(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
4016 scoped_ptr
<SpdyFrame
> data_frame(
4017 framer
.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE
));
4018 scoped_ptr
<SpdyFrame
> data_frame_fin(
4019 framer
.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN
));
4020 const SpdyFrame
* frames
[5] = {reply
.get(), data_frame
.get(), data_frame
.get(),
4021 data_frame
.get(), data_frame_fin
.get()};
4022 char combined_frames
[200];
4023 int combined_frames_len
=
4024 CombineFrames(frames
, arraysize(frames
),
4025 combined_frames
, arraysize(combined_frames
));
4027 MockRead reads
[] = {
4028 MockRead(ASYNC
, combined_frames
, combined_frames_len
),
4029 MockRead(ASYNC
, 0, 0) // EOF
4032 DelayedSocketData
data(1, reads
, arraysize(reads
),
4033 writes
, arraysize(writes
));
4035 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
4036 BoundNetLog(), GetParam(), NULL
);
4037 helper
.RunPreTestSetup();
4038 helper
.AddData(&data
);
4039 HttpNetworkTransaction
* trans
= helper
.trans();
4041 TestCompletionCallback callback
;
4042 int rv
= trans
->Start(
4043 &CreateGetRequest(), callback
.callback(), BoundNetLog());
4044 EXPECT_EQ(ERR_IO_PENDING
, rv
);
4046 TransactionHelperResult out
= helper
.output();
4047 out
.rv
= callback
.WaitForResult();
4048 EXPECT_EQ(out
.rv
, OK
);
4050 const HttpResponseInfo
* response
= trans
->GetResponseInfo();
4051 EXPECT_TRUE(response
->headers
.get() != NULL
);
4052 EXPECT_TRUE(response
->was_fetched_via_spdy
);
4053 out
.status_line
= response
->headers
->GetStatusLine();
4054 out
.response_info
= *response
; // Make a copy so we can verify.
4057 TestCompletionCallback read_callback
;
4059 std::string content
;
4060 int reads_completed
= 0;
4062 // Read small chunks at a time.
4063 const int kSmallReadSize
= 14;
4064 scoped_refptr
<IOBuffer
> buf(new IOBuffer(kSmallReadSize
));
4065 rv
= trans
->Read(buf
.get(), kSmallReadSize
, read_callback
.callback());
4067 EXPECT_EQ(kSmallReadSize
, rv
);
4068 content
.append(buf
->data(), rv
);
4069 } else if (rv
< 0) {
4070 FAIL() << "Unexpected read error: " << rv
;
4075 EXPECT_EQ(3, reads_completed
);
4077 out
.response_data
.swap(content
);
4079 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the
4080 // MockClientSocketFactory) are still alive.
4081 base::RunLoop().RunUntilIdle();
4083 // Verify that we consumed all test data.
4084 helper
.VerifyDataConsumed();
4086 EXPECT_EQ(OK
, out
.rv
);
4087 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
4088 EXPECT_EQ("messagemessagemessagemessage", out
.response_data
);
4091 // Verify the case where we buffer data and close the connection.
4092 TEST_P(SpdyNetworkTransactionTest
, BufferedClosed
) {
4093 BufferedSpdyFramer
framer(spdy_util_
.spdy_version(), false);
4095 scoped_ptr
<SpdyFrame
> req(
4096 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
4097 MockWrite writes
[] = { CreateMockWrite(*req
) };
4099 // All data frames in a single read.
4100 // NOTE: We don't FIN the stream.
4101 scoped_ptr
<SpdyFrame
> data_frame(
4102 framer
.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE
));
4103 const SpdyFrame
* data_frames
[4] = {
4109 char combined_data_frames
[100];
4110 int combined_data_frames_len
=
4111 CombineFrames(data_frames
, arraysize(data_frames
),
4112 combined_data_frames
, arraysize(combined_data_frames
));
4113 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
4114 MockRead reads
[] = {
4115 CreateMockRead(*resp
),
4116 MockRead(ASYNC
, ERR_IO_PENDING
), // Force a wait
4117 MockRead(ASYNC
, combined_data_frames
, combined_data_frames_len
),
4118 MockRead(ASYNC
, 0, 0) // EOF
4121 DelayedSocketData
data(1, reads
, arraysize(reads
),
4122 writes
, arraysize(writes
));
4124 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
4125 BoundNetLog(), GetParam(), NULL
);
4126 helper
.RunPreTestSetup();
4127 helper
.AddData(&data
);
4128 HttpNetworkTransaction
* trans
= helper
.trans();
4130 TestCompletionCallback callback
;
4132 int rv
= trans
->Start(
4133 &CreateGetRequest(), callback
.callback(), BoundNetLog());
4134 EXPECT_EQ(ERR_IO_PENDING
, rv
);
4136 TransactionHelperResult out
= helper
.output();
4137 out
.rv
= callback
.WaitForResult();
4138 EXPECT_EQ(out
.rv
, OK
);
4140 const HttpResponseInfo
* response
= trans
->GetResponseInfo();
4141 EXPECT_TRUE(response
->headers
.get() != NULL
);
4142 EXPECT_TRUE(response
->was_fetched_via_spdy
);
4143 out
.status_line
= response
->headers
->GetStatusLine();
4144 out
.response_info
= *response
; // Make a copy so we can verify.
4147 TestCompletionCallback read_callback
;
4149 std::string content
;
4150 int reads_completed
= 0;
4152 // Read small chunks at a time.
4153 const int kSmallReadSize
= 14;
4154 scoped_refptr
<IOBuffer
> buf(new IOBuffer(kSmallReadSize
));
4155 rv
= trans
->Read(buf
.get(), kSmallReadSize
, read_callback
.callback());
4156 if (rv
== ERR_IO_PENDING
) {
4157 data
.CompleteRead();
4158 rv
= read_callback
.WaitForResult();
4161 content
.append(buf
->data(), rv
);
4162 } else if (rv
< 0) {
4163 // This test intentionally closes the connection, and will get an error.
4164 EXPECT_EQ(ERR_CONNECTION_CLOSED
, rv
);
4170 EXPECT_EQ(0, reads_completed
);
4172 out
.response_data
.swap(content
);
4174 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the
4175 // MockClientSocketFactory) are still alive.
4176 base::RunLoop().RunUntilIdle();
4178 // Verify that we consumed all test data.
4179 helper
.VerifyDataConsumed();
4182 // Verify the case where we buffer data and cancel the transaction.
4183 TEST_P(SpdyNetworkTransactionTest
, BufferedCancelled
) {
4184 BufferedSpdyFramer
framer(spdy_util_
.spdy_version(), false);
4186 scoped_ptr
<SpdyFrame
> req(
4187 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
4188 scoped_ptr
<SpdyFrame
> rst(
4189 spdy_util_
.ConstructSpdyRstStream(1, RST_STREAM_CANCEL
));
4190 MockWrite writes
[] = {CreateMockWrite(*req
), CreateMockWrite(*rst
)};
4192 // NOTE: We don't FIN the stream.
4193 scoped_ptr
<SpdyFrame
> data_frame(
4194 framer
.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE
));
4196 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
4197 MockRead reads
[] = {
4198 CreateMockRead(*resp
),
4199 MockRead(ASYNC
, ERR_IO_PENDING
), // Force a wait
4200 CreateMockRead(*data_frame
),
4201 MockRead(ASYNC
, 0, 0) // EOF
4204 DelayedSocketData
data(1, reads
, arraysize(reads
),
4205 writes
, arraysize(writes
));
4207 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
4208 BoundNetLog(), GetParam(), NULL
);
4209 helper
.RunPreTestSetup();
4210 helper
.AddData(&data
);
4211 HttpNetworkTransaction
* trans
= helper
.trans();
4212 TestCompletionCallback callback
;
4214 int rv
= trans
->Start(
4215 &CreateGetRequest(), callback
.callback(), BoundNetLog());
4216 EXPECT_EQ(ERR_IO_PENDING
, rv
);
4218 TransactionHelperResult out
= helper
.output();
4219 out
.rv
= callback
.WaitForResult();
4220 EXPECT_EQ(out
.rv
, OK
);
4222 const HttpResponseInfo
* response
= trans
->GetResponseInfo();
4223 EXPECT_TRUE(response
->headers
.get() != NULL
);
4224 EXPECT_TRUE(response
->was_fetched_via_spdy
);
4225 out
.status_line
= response
->headers
->GetStatusLine();
4226 out
.response_info
= *response
; // Make a copy so we can verify.
4229 TestCompletionCallback read_callback
;
4231 const int kReadSize
= 256;
4232 scoped_refptr
<IOBuffer
> buf(new IOBuffer(kReadSize
));
4233 rv
= trans
->Read(buf
.get(), kReadSize
, read_callback
.callback());
4234 ASSERT_EQ(ERR_IO_PENDING
, rv
) << "Unexpected read: " << rv
;
4236 // Complete the read now, which causes buffering to start.
4237 data
.CompleteRead();
4238 // Destroy the transaction, causing the stream to get cancelled
4239 // and orphaning the buffered IO task.
4240 helper
.ResetTrans();
4242 // Flush the MessageLoop; this will cause the buffered IO task
4243 // to run for the final time.
4244 base::RunLoop().RunUntilIdle();
4246 // Verify that we consumed all test data.
4247 helper
.VerifyDataConsumed();
4250 // Test that if the server requests persistence of settings, that we save
4251 // the settings in the HttpServerProperties.
4252 TEST_P(SpdyNetworkTransactionTest
, SettingsSaved
) {
4253 if (spdy_util_
.spdy_version() >= SPDY4
) {
4254 // SPDY4 doesn't support settings persistence.
4257 static const SpdyHeaderInfo kSynReplyInfo
= {
4258 SYN_REPLY
, // Syn Reply
4260 0, // Associated Stream ID
4261 ConvertRequestPriorityToSpdyPriority(
4262 LOWEST
, spdy_util_
.spdy_version()),
4263 kSpdyCredentialSlotUnused
,
4264 CONTROL_FLAG_NONE
, // Control Flags
4265 false, // Compressed
4266 RST_STREAM_INVALID
, // Status
4269 DATA_FLAG_NONE
// Data Flags
4272 BoundNetLog net_log
;
4273 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
4274 net_log
, GetParam(), NULL
);
4275 helper
.RunPreTestSetup();
4277 // Verify that no settings exist initially.
4278 HostPortPair
host_port_pair("www.google.com", helper
.port());
4279 SpdySessionPool
* spdy_session_pool
= helper
.session()->spdy_session_pool();
4280 EXPECT_TRUE(spdy_session_pool
->http_server_properties()->GetSpdySettings(
4281 host_port_pair
).empty());
4283 // Construct the request.
4284 scoped_ptr
<SpdyFrame
> req(
4285 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
4286 MockWrite writes
[] = { CreateMockWrite(*req
) };
4288 // Construct the reply.
4289 scoped_ptr
<SpdyHeaderBlock
> reply_headers(new SpdyHeaderBlock());
4290 (*reply_headers
)[spdy_util_
.GetStatusKey()] = "200";
4291 (*reply_headers
)[spdy_util_
.GetVersionKey()] = "HTTP/1.1";
4292 scoped_ptr
<SpdyFrame
> reply(
4293 spdy_util_
.ConstructSpdyFrame(kSynReplyInfo
, reply_headers
.Pass()));
4295 const SpdySettingsIds kSampleId1
= SETTINGS_UPLOAD_BANDWIDTH
;
4296 unsigned int kSampleValue1
= 0x0a0a0a0a;
4297 const SpdySettingsIds kSampleId2
= SETTINGS_DOWNLOAD_BANDWIDTH
;
4298 unsigned int kSampleValue2
= 0x0b0b0b0b;
4299 const SpdySettingsIds kSampleId3
= SETTINGS_ROUND_TRIP_TIME
;
4300 unsigned int kSampleValue3
= 0x0c0c0c0c;
4301 scoped_ptr
<SpdyFrame
> settings_frame
;
4303 // Construct the SETTINGS frame.
4304 SettingsMap settings
;
4305 // First add a persisted setting.
4306 settings
[kSampleId1
] =
4307 SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST
, kSampleValue1
);
4308 // Next add a non-persisted setting.
4309 settings
[kSampleId2
] =
4310 SettingsFlagsAndValue(SETTINGS_FLAG_NONE
, kSampleValue2
);
4311 // Next add another persisted setting.
4312 settings
[kSampleId3
] =
4313 SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST
, kSampleValue3
);
4314 settings_frame
.reset(spdy_util_
.ConstructSpdySettings(settings
));
4317 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
4318 MockRead reads
[] = {
4319 CreateMockRead(*reply
),
4320 CreateMockRead(*body
),
4321 CreateMockRead(*settings_frame
),
4322 MockRead(ASYNC
, 0, 0) // EOF
4325 DelayedSocketData
data(1, reads
, arraysize(reads
),
4326 writes
, arraysize(writes
));
4327 helper
.AddData(&data
);
4328 helper
.RunDefaultTest();
4329 helper
.VerifyDataConsumed();
4330 TransactionHelperResult out
= helper
.output();
4331 EXPECT_EQ(OK
, out
.rv
);
4332 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
4333 EXPECT_EQ("hello!", out
.response_data
);
4336 // Verify we had two persisted settings.
4337 const SettingsMap
& settings_map
=
4338 spdy_session_pool
->http_server_properties()->GetSpdySettings(
4340 ASSERT_EQ(2u, settings_map
.size());
4342 // Verify the first persisted setting.
4343 SettingsMap::const_iterator it1
= settings_map
.find(kSampleId1
);
4344 EXPECT_TRUE(it1
!= settings_map
.end());
4345 SettingsFlagsAndValue flags_and_value1
= it1
->second
;
4346 EXPECT_EQ(SETTINGS_FLAG_PERSISTED
, flags_and_value1
.first
);
4347 EXPECT_EQ(kSampleValue1
, flags_and_value1
.second
);
4349 // Verify the second persisted setting.
4350 SettingsMap::const_iterator it3
= settings_map
.find(kSampleId3
);
4351 EXPECT_TRUE(it3
!= settings_map
.end());
4352 SettingsFlagsAndValue flags_and_value3
= it3
->second
;
4353 EXPECT_EQ(SETTINGS_FLAG_PERSISTED
, flags_and_value3
.first
);
4354 EXPECT_EQ(kSampleValue3
, flags_and_value3
.second
);
4358 // Test that when there are settings saved that they are sent back to the
4359 // server upon session establishment.
4360 TEST_P(SpdyNetworkTransactionTest
, SettingsPlayback
) {
4361 if (spdy_util_
.spdy_version() >= SPDY4
) {
4362 // SPDY4 doesn't support settings persistence.
4365 static const SpdyHeaderInfo kSynReplyInfo
= {
4366 SYN_REPLY
, // Syn Reply
4368 0, // Associated Stream ID
4369 ConvertRequestPriorityToSpdyPriority(
4370 LOWEST
, spdy_util_
.spdy_version()),
4371 kSpdyCredentialSlotUnused
,
4372 CONTROL_FLAG_NONE
, // Control Flags
4373 false, // Compressed
4374 RST_STREAM_INVALID
, // Status
4377 DATA_FLAG_NONE
// Data Flags
4380 BoundNetLog net_log
;
4381 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
4382 net_log
, GetParam(), NULL
);
4383 helper
.RunPreTestSetup();
4385 SpdySessionPool
* spdy_session_pool
= helper
.session()->spdy_session_pool();
4387 SpdySessionPoolPeer
pool_peer(spdy_session_pool
);
4388 pool_peer
.SetEnableSendingInitialData(true);
4390 // Verify that no settings exist initially.
4391 HostPortPair
host_port_pair("www.google.com", helper
.port());
4392 EXPECT_TRUE(spdy_session_pool
->http_server_properties()->GetSpdySettings(
4393 host_port_pair
).empty());
4395 const SpdySettingsIds kSampleId1
= SETTINGS_MAX_CONCURRENT_STREAMS
;
4396 unsigned int kSampleValue1
= 0x0a0a0a0a;
4397 const SpdySettingsIds kSampleId2
= SETTINGS_INITIAL_WINDOW_SIZE
;
4398 unsigned int kSampleValue2
= 0x0c0c0c0c;
4400 // First add a persisted setting.
4401 spdy_session_pool
->http_server_properties()->SetSpdySetting(
4404 SETTINGS_FLAG_PLEASE_PERSIST
,
4407 // Next add another persisted setting.
4408 spdy_session_pool
->http_server_properties()->SetSpdySetting(
4411 SETTINGS_FLAG_PLEASE_PERSIST
,
4414 EXPECT_EQ(2u, spdy_session_pool
->http_server_properties()->GetSpdySettings(
4415 host_port_pair
).size());
4417 // Construct the initial SETTINGS frame.
4418 SettingsMap initial_settings
;
4419 initial_settings
[SETTINGS_MAX_CONCURRENT_STREAMS
] =
4420 SettingsFlagsAndValue(SETTINGS_FLAG_NONE
, kMaxConcurrentPushedStreams
);
4421 scoped_ptr
<SpdyFrame
> initial_settings_frame(
4422 spdy_util_
.ConstructSpdySettings(initial_settings
));
4424 // Construct the initial window update.
4425 scoped_ptr
<SpdyFrame
> initial_window_update(
4426 spdy_util_
.ConstructSpdyWindowUpdate(
4427 kSessionFlowControlStreamId
,
4428 kDefaultInitialRecvWindowSize
-
4429 SpdySession::GetInitialWindowSize(GetParam().protocol
)));
4431 // Construct the persisted SETTINGS frame.
4432 const SettingsMap
& settings
=
4433 spdy_session_pool
->http_server_properties()->GetSpdySettings(
4435 scoped_ptr
<SpdyFrame
> settings_frame(
4436 spdy_util_
.ConstructSpdySettings(settings
));
4438 // Construct the request.
4439 scoped_ptr
<SpdyFrame
> req(
4440 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
4442 std::vector
<MockWrite
> writes
;
4443 if ((GetParam().protocol
>= kProtoSPDY4MinimumVersion
) &&
4444 (GetParam().protocol
<= kProtoSPDY4MaximumVersion
)) {
4447 kHttp2ConnectionHeaderPrefix
,
4448 kHttp2ConnectionHeaderPrefixSize
));
4450 writes
.push_back(CreateMockWrite(*initial_settings_frame
));
4451 if (GetParam().protocol
>= kProtoSPDY31
) {
4452 writes
.push_back(CreateMockWrite(*initial_window_update
));
4454 writes
.push_back(CreateMockWrite(*settings_frame
));
4455 writes
.push_back(CreateMockWrite(*req
));
4457 // Construct the reply.
4458 scoped_ptr
<SpdyHeaderBlock
> reply_headers(new SpdyHeaderBlock());
4459 (*reply_headers
)[spdy_util_
.GetStatusKey()] = "200";
4460 (*reply_headers
)[spdy_util_
.GetVersionKey()] = "HTTP/1.1";
4461 scoped_ptr
<SpdyFrame
> reply(
4462 spdy_util_
.ConstructSpdyFrame(kSynReplyInfo
, reply_headers
.Pass()));
4464 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
4465 MockRead reads
[] = {
4466 CreateMockRead(*reply
),
4467 CreateMockRead(*body
),
4468 MockRead(ASYNC
, 0, 0) // EOF
4471 DelayedSocketData
data(2, reads
, arraysize(reads
),
4472 vector_as_array(&writes
), writes
.size());
4473 helper
.AddData(&data
);
4474 helper
.RunDefaultTest();
4475 helper
.VerifyDataConsumed();
4476 TransactionHelperResult out
= helper
.output();
4477 EXPECT_EQ(OK
, out
.rv
);
4478 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
4479 EXPECT_EQ("hello!", out
.response_data
);
4482 // Verify we had two persisted settings.
4483 const SettingsMap
& settings_map
=
4484 spdy_session_pool
->http_server_properties()->GetSpdySettings(
4486 ASSERT_EQ(2u, settings_map
.size());
4488 // Verify the first persisted setting.
4489 SettingsMap::const_iterator it1
= settings_map
.find(kSampleId1
);
4490 EXPECT_TRUE(it1
!= settings_map
.end());
4491 SettingsFlagsAndValue flags_and_value1
= it1
->second
;
4492 EXPECT_EQ(SETTINGS_FLAG_PERSISTED
, flags_and_value1
.first
);
4493 EXPECT_EQ(kSampleValue1
, flags_and_value1
.second
);
4495 // Verify the second persisted setting.
4496 SettingsMap::const_iterator it2
= settings_map
.find(kSampleId2
);
4497 EXPECT_TRUE(it2
!= settings_map
.end());
4498 SettingsFlagsAndValue flags_and_value2
= it2
->second
;
4499 EXPECT_EQ(SETTINGS_FLAG_PERSISTED
, flags_and_value2
.first
);
4500 EXPECT_EQ(kSampleValue2
, flags_and_value2
.second
);
4504 TEST_P(SpdyNetworkTransactionTest
, GoAwayWithActiveStream
) {
4505 scoped_ptr
<SpdyFrame
> req(
4506 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
4507 MockWrite writes
[] = { CreateMockWrite(*req
) };
4509 scoped_ptr
<SpdyFrame
> go_away(spdy_util_
.ConstructSpdyGoAway());
4510 MockRead reads
[] = {
4511 CreateMockRead(*go_away
),
4514 DelayedSocketData
data(1, reads
, arraysize(reads
),
4515 writes
, arraysize(writes
));
4516 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
4517 BoundNetLog(), GetParam(), NULL
);
4518 helper
.AddData(&data
);
4519 helper
.RunToCompletion(&data
);
4520 TransactionHelperResult out
= helper
.output();
4521 EXPECT_EQ(ERR_ABORTED
, out
.rv
);
4524 TEST_P(SpdyNetworkTransactionTest
, CloseWithActiveStream
) {
4525 scoped_ptr
<SpdyFrame
> req(
4526 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
4527 MockWrite writes
[] = { CreateMockWrite(*req
) };
4529 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
4530 MockRead reads
[] = {
4531 CreateMockRead(*resp
),
4532 MockRead(SYNCHRONOUS
, 0, 0) // EOF
4535 DelayedSocketData
data(1, reads
, arraysize(reads
),
4536 writes
, arraysize(writes
));
4538 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
4539 log
, GetParam(), NULL
);
4540 helper
.RunPreTestSetup();
4541 helper
.AddData(&data
);
4542 HttpNetworkTransaction
* trans
= helper
.trans();
4544 TestCompletionCallback callback
;
4545 TransactionHelperResult out
;
4546 out
.rv
= trans
->Start(&CreateGetRequest(), callback
.callback(), log
);
4548 EXPECT_EQ(out
.rv
, ERR_IO_PENDING
);
4549 out
.rv
= callback
.WaitForResult();
4550 EXPECT_EQ(out
.rv
, OK
);
4552 const HttpResponseInfo
* response
= trans
->GetResponseInfo();
4553 EXPECT_TRUE(response
->headers
.get() != NULL
);
4554 EXPECT_TRUE(response
->was_fetched_via_spdy
);
4555 out
.rv
= ReadTransaction(trans
, &out
.response_data
);
4556 EXPECT_EQ(ERR_CONNECTION_CLOSED
, out
.rv
);
4558 // Verify that we consumed all test data.
4559 helper
.VerifyDataConsumed();
4562 // HTTP_1_1_REQUIRED results in ERR_HTTP_1_1_REQUIRED.
4563 TEST_P(SpdyNetworkTransactionTest
, HTTP11RequiredError
) {
4564 // HTTP_1_1_REQUIRED is only supported by SPDY4.
4565 if (spdy_util_
.spdy_version() < SPDY4
)
4568 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
4569 BoundNetLog(), GetParam(), nullptr);
4571 scoped_ptr
<SpdyFrame
> go_away(spdy_util_
.ConstructSpdyGoAway(
4572 0, GOAWAY_HTTP_1_1_REQUIRED
, "Try again using HTTP/1.1 please."));
4573 MockRead reads
[] = {
4574 CreateMockRead(*go_away
),
4576 DelayedSocketData
data(0, reads
, arraysize(reads
), nullptr, 0);
4578 helper
.RunToCompletion(&data
);
4579 TransactionHelperResult out
= helper
.output();
4580 EXPECT_EQ(ERR_HTTP_1_1_REQUIRED
, out
.rv
);
4583 // Retry with HTTP/1.1 when receiving HTTP_1_1_REQUIRED. Note that no actual
4584 // protocol negotiation happens, instead this test forces protocols for both
4586 TEST_P(SpdyNetworkTransactionTest
, HTTP11RequiredRetry
) {
4587 // HTTP_1_1_REQUIRED is only supported by SPDY4.
4588 if (spdy_util_
.spdy_version() < SPDY4
)
4590 // HTTP_1_1_REQUIRED implementation relies on the assumption that HTTP/2 is
4591 // only spoken over SSL.
4592 if (GetParam().ssl_type
!= SPDYSSL
)
4595 HttpRequestInfo request
;
4596 request
.method
= "GET";
4597 request
.url
= GURL("https://www.google.com/");
4598 scoped_ptr
<SpdySessionDependencies
> session_deps(
4599 CreateSpdySessionDependencies(GetParam()));
4600 // Do not force SPDY so that second socket can negotiate HTTP/1.1.
4601 session_deps
->force_spdy_over_ssl
= false;
4602 session_deps
->force_spdy_always
= false;
4603 session_deps
->next_protos
= SpdyNextProtos();
4604 NormalSpdyTransactionHelper
helper(request
, DEFAULT_PRIORITY
, BoundNetLog(),
4605 GetParam(), session_deps
.release());
4607 // First socket: HTTP/2 request rejected with HTTP_1_1_REQUIRED.
4608 const char* url
= "https://www.google.com/";
4609 scoped_ptr
<SpdyHeaderBlock
> headers(spdy_util_
.ConstructGetHeaderBlock(url
));
4610 scoped_ptr
<SpdyFrame
> req(
4611 spdy_util_
.ConstructSpdySyn(1, *headers
, LOWEST
, false, true));
4612 MockWrite writes0
[] = {CreateMockWrite(*req
)};
4613 scoped_ptr
<SpdyFrame
> go_away(spdy_util_
.ConstructSpdyGoAway(
4614 0, GOAWAY_HTTP_1_1_REQUIRED
, "Try again using HTTP/1.1 please."));
4615 MockRead reads0
[] = {CreateMockRead(*go_away
)};
4616 DelayedSocketData
data0(1, reads0
, arraysize(reads0
), writes0
,
4617 arraysize(writes0
));
4619 scoped_ptr
<SSLSocketDataProvider
> ssl_provider0(
4620 new SSLSocketDataProvider(ASYNC
, OK
));
4621 // Expect HTTP/2 protocols too in SSLConfig.
4622 ssl_provider0
->next_protos_expected_in_ssl_config
.push_back(kProtoHTTP11
);
4623 ssl_provider0
->next_protos_expected_in_ssl_config
.push_back(kProtoSPDY31
);
4624 ssl_provider0
->next_protos_expected_in_ssl_config
.push_back(kProtoSPDY4_14
);
4625 ssl_provider0
->next_protos_expected_in_ssl_config
.push_back(kProtoSPDY4
);
4627 ssl_provider0
->SetNextProto(GetParam().protocol
);
4628 helper
.AddDataWithSSLSocketDataProvider(&data0
, ssl_provider0
.Pass());
4630 // Second socket: falling back to HTTP/1.1.
4631 MockWrite writes1
[] = {MockWrite(
4632 "GET / HTTP/1.1\r\n"
4633 "Host: www.google.com\r\n"
4634 "Connection: keep-alive\r\n\r\n")};
4635 MockRead reads1
[] = {MockRead(
4636 "HTTP/1.1 200 OK\r\n"
4637 "Content-Length: 5\r\n\r\n"
4639 DelayedSocketData
data1(1, reads1
, arraysize(reads1
), writes1
,
4640 arraysize(writes1
));
4642 scoped_ptr
<SSLSocketDataProvider
> ssl_provider1(
4643 new SSLSocketDataProvider(ASYNC
, OK
));
4644 // Expect only HTTP/1.1 protocol in SSLConfig.
4645 ssl_provider1
->next_protos_expected_in_ssl_config
.push_back(kProtoHTTP11
);
4647 ssl_provider1
->SetNextProto(kProtoHTTP11
);
4648 helper
.AddDataWithSSLSocketDataProvider(&data1
, ssl_provider1
.Pass());
4650 base::WeakPtr
<HttpServerProperties
> http_server_properties
=
4651 helper
.session()->spdy_session_pool()->http_server_properties();
4652 const HostPortPair host_port_pair
= HostPortPair::FromURL(GURL(url
));
4653 EXPECT_FALSE(http_server_properties
->RequiresHTTP11(host_port_pair
));
4655 helper
.RunPreTestSetup();
4656 helper
.StartDefaultTest();
4657 helper
.FinishDefaultTestWithoutVerification();
4658 helper
.VerifyDataConsumed();
4659 EXPECT_TRUE(http_server_properties
->RequiresHTTP11(host_port_pair
));
4661 const HttpResponseInfo
* response
= helper
.trans()->GetResponseInfo();
4662 ASSERT_TRUE(response
!= nullptr);
4663 ASSERT_TRUE(response
->headers
.get() != nullptr);
4664 EXPECT_EQ("HTTP/1.1 200 OK", response
->headers
->GetStatusLine());
4665 EXPECT_FALSE(response
->was_fetched_via_spdy
);
4666 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1
, response
->connection_info
);
4667 EXPECT_TRUE(response
->was_npn_negotiated
);
4668 EXPECT_TRUE(request
.url
.SchemeIs("https"));
4669 EXPECT_EQ("127.0.0.1", response
->socket_address
.host());
4670 EXPECT_EQ(443, response
->socket_address
.port());
4671 std::string response_data
;
4672 ASSERT_EQ(OK
, ReadTransaction(helper
.trans(), &response_data
));
4673 EXPECT_EQ("hello", response_data
);
4676 // Retry with HTTP/1.1 to the proxy when receiving HTTP_1_1_REQUIRED from the
4677 // proxy. Note that no actual protocol negotiation happens, instead this test
4678 // forces protocols for both sockets.
4679 TEST_P(SpdyNetworkTransactionTest
, HTTP11RequiredProxyRetry
) {
4680 // HTTP_1_1_REQUIRED is only supported by SPDY4.
4681 if (spdy_util_
.spdy_version() < SPDY4
)
4683 // HTTP_1_1_REQUIRED implementation relies on the assumption that HTTP/2 is
4684 // only spoken over SSL.
4685 if (GetParam().ssl_type
!= SPDYSSL
)
4688 HttpRequestInfo request
;
4689 request
.method
= "GET";
4690 request
.url
= GURL("https://www.google.com/");
4691 scoped_ptr
<SpdySessionDependencies
> session_deps(
4692 CreateSpdySessionDependencies(
4694 ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")));
4695 // Do not force SPDY so that second socket can negotiate HTTP/1.1.
4696 session_deps
->force_spdy_over_ssl
= false;
4697 session_deps
->force_spdy_always
= false;
4698 session_deps
->next_protos
= SpdyNextProtos();
4699 NormalSpdyTransactionHelper
helper(request
, DEFAULT_PRIORITY
, BoundNetLog(),
4700 GetParam(), session_deps
.release());
4702 // First socket: HTTP/2 CONNECT rejected with HTTP_1_1_REQUIRED.
4703 scoped_ptr
<SpdyFrame
> req(spdy_util_
.ConstructSpdyConnect(
4704 nullptr, 0, 1, LOWEST
, HostPortPair("www.google.com", 443)));
4705 MockWrite writes0
[] = {CreateMockWrite(*req
)};
4706 scoped_ptr
<SpdyFrame
> go_away(spdy_util_
.ConstructSpdyGoAway(
4707 0, GOAWAY_HTTP_1_1_REQUIRED
, "Try again using HTTP/1.1 please."));
4708 MockRead reads0
[] = {CreateMockRead(*go_away
)};
4709 DelayedSocketData
data0(1, reads0
, arraysize(reads0
), writes0
,
4710 arraysize(writes0
));
4712 scoped_ptr
<SSLSocketDataProvider
> ssl_provider0(
4713 new SSLSocketDataProvider(ASYNC
, OK
));
4714 // Expect HTTP/2 protocols too in SSLConfig.
4715 ssl_provider0
->next_protos_expected_in_ssl_config
.push_back(kProtoHTTP11
);
4716 ssl_provider0
->next_protos_expected_in_ssl_config
.push_back(kProtoSPDY31
);
4717 ssl_provider0
->next_protos_expected_in_ssl_config
.push_back(kProtoSPDY4_14
);
4718 ssl_provider0
->next_protos_expected_in_ssl_config
.push_back(kProtoSPDY4
);
4720 ssl_provider0
->SetNextProto(GetParam().protocol
);
4721 helper
.AddDataWithSSLSocketDataProvider(&data0
, ssl_provider0
.Pass());
4723 // Second socket: retry using HTTP/1.1.
4724 MockWrite writes1
[] = {
4726 "CONNECT www.google.com:443 HTTP/1.1\r\n"
4727 "Host: www.google.com\r\n"
4728 "Proxy-Connection: keep-alive\r\n\r\n"),
4730 "GET / HTTP/1.1\r\n"
4731 "Host: www.google.com\r\n"
4732 "Connection: keep-alive\r\n\r\n"),
4735 MockRead reads1
[] = {
4736 MockRead(ASYNC
, 2, "HTTP/1.1 200 OK\r\n\r\n"),
4738 "HTTP/1.1 200 OK\r\n"
4739 "Content-Length: 5\r\n\r\n"
4742 DelayedSocketData
data1(1, reads1
, arraysize(reads1
), writes1
,
4743 arraysize(writes1
));
4745 scoped_ptr
<SSLSocketDataProvider
> ssl_provider1(
4746 new SSLSocketDataProvider(ASYNC
, OK
));
4747 // Expect only HTTP/1.1 protocol in SSLConfig.
4748 ssl_provider1
->next_protos_expected_in_ssl_config
.push_back(kProtoHTTP11
);
4750 ssl_provider1
->SetNextProto(kProtoHTTP11
);
4751 helper
.AddDataWithSSLSocketDataProvider(&data1
, ssl_provider1
.Pass());
4753 // A third socket is needed for the tunnelled connection.
4754 scoped_ptr
<SSLSocketDataProvider
> ssl_provider2(
4755 new SSLSocketDataProvider(ASYNC
, OK
));
4756 helper
.session_deps()->socket_factory
->AddSSLSocketDataProvider(
4757 ssl_provider2
.get());
4759 base::WeakPtr
<HttpServerProperties
> http_server_properties
=
4760 helper
.session()->spdy_session_pool()->http_server_properties();
4761 const HostPortPair proxy_host_port_pair
= HostPortPair("myproxy", 70);
4762 EXPECT_FALSE(http_server_properties
->RequiresHTTP11(proxy_host_port_pair
));
4764 helper
.RunPreTestSetup();
4765 helper
.StartDefaultTest();
4766 helper
.FinishDefaultTestWithoutVerification();
4767 helper
.VerifyDataConsumed();
4768 EXPECT_TRUE(http_server_properties
->RequiresHTTP11(proxy_host_port_pair
));
4770 const HttpResponseInfo
* response
= helper
.trans()->GetResponseInfo();
4771 ASSERT_TRUE(response
!= nullptr);
4772 ASSERT_TRUE(response
->headers
.get() != nullptr);
4773 EXPECT_EQ("HTTP/1.1 200 OK", response
->headers
->GetStatusLine());
4774 EXPECT_FALSE(response
->was_fetched_via_spdy
);
4775 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1
, response
->connection_info
);
4776 EXPECT_FALSE(response
->was_npn_negotiated
);
4777 EXPECT_TRUE(request
.url
.SchemeIs("https"));
4778 EXPECT_EQ("127.0.0.1", response
->socket_address
.host());
4779 EXPECT_EQ(70, response
->socket_address
.port());
4780 std::string response_data
;
4781 ASSERT_EQ(OK
, ReadTransaction(helper
.trans(), &response_data
));
4782 EXPECT_EQ("hello", response_data
);
4785 // Test to make sure we can correctly connect through a proxy.
4786 TEST_P(SpdyNetworkTransactionTest
, ProxyConnect
) {
4787 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
4788 BoundNetLog(), GetParam(), NULL
);
4789 helper
.session_deps().reset(CreateSpdySessionDependencies(
4791 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")));
4792 helper
.SetSession(make_scoped_refptr(
4793 SpdySessionDependencies::SpdyCreateSession(helper
.session_deps().get())));
4794 helper
.RunPreTestSetup();
4795 HttpNetworkTransaction
* trans
= helper
.trans();
4797 const char kConnect443
[] = {"CONNECT www.google.com:443 HTTP/1.1\r\n"
4798 "Host: www.google.com\r\n"
4799 "Proxy-Connection: keep-alive\r\n\r\n"};
4800 const char kConnect80
[] = {"CONNECT www.google.com:80 HTTP/1.1\r\n"
4801 "Host: www.google.com\r\n"
4802 "Proxy-Connection: keep-alive\r\n\r\n"};
4803 const char kHTTP200
[] = {"HTTP/1.1 200 OK\r\n\r\n"};
4804 scoped_ptr
<SpdyFrame
> req(
4805 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
4806 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
4807 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
4809 MockWrite writes_SPDYNPN
[] = {
4810 MockWrite(SYNCHRONOUS
, kConnect443
, arraysize(kConnect443
) - 1, 0),
4811 CreateMockWrite(*req
, 2),
4813 MockRead reads_SPDYNPN
[] = {
4814 MockRead(SYNCHRONOUS
, kHTTP200
, arraysize(kHTTP200
) - 1, 1),
4815 CreateMockRead(*resp
, 3),
4816 CreateMockRead(*body
.get(), 4),
4817 MockRead(ASYNC
, 0, 0, 5),
4820 MockWrite writes_SPDYSSL
[] = {
4821 MockWrite(SYNCHRONOUS
, kConnect80
, arraysize(kConnect80
) - 1, 0),
4822 CreateMockWrite(*req
, 2),
4824 MockRead reads_SPDYSSL
[] = {
4825 MockRead(SYNCHRONOUS
, kHTTP200
, arraysize(kHTTP200
) - 1, 1),
4826 CreateMockRead(*resp
, 3),
4827 CreateMockRead(*body
.get(), 4),
4828 MockRead(ASYNC
, 0, 0, 5),
4831 MockWrite writes_SPDYNOSSL
[] = {
4832 CreateMockWrite(*req
, 0),
4835 MockRead reads_SPDYNOSSL
[] = {
4836 CreateMockRead(*resp
, 1),
4837 CreateMockRead(*body
.get(), 2),
4838 MockRead(ASYNC
, 0, 0, 3),
4841 scoped_ptr
<OrderedSocketData
> data
;
4842 switch (GetParam().ssl_type
) {
4844 data
.reset(new OrderedSocketData(reads_SPDYNOSSL
,
4845 arraysize(reads_SPDYNOSSL
),
4847 arraysize(writes_SPDYNOSSL
)));
4850 data
.reset(new OrderedSocketData(reads_SPDYSSL
,
4851 arraysize(reads_SPDYSSL
),
4853 arraysize(writes_SPDYSSL
)));
4856 data
.reset(new OrderedSocketData(reads_SPDYNPN
,
4857 arraysize(reads_SPDYNPN
),
4859 arraysize(writes_SPDYNPN
)));
4865 helper
.AddData(data
.get());
4866 TestCompletionCallback callback
;
4868 int rv
= trans
->Start(
4869 &CreateGetRequest(), callback
.callback(), BoundNetLog());
4870 EXPECT_EQ(ERR_IO_PENDING
, rv
);
4872 rv
= callback
.WaitForResult();
4875 // Verify the SYN_REPLY.
4876 HttpResponseInfo response
= *trans
->GetResponseInfo();
4877 EXPECT_TRUE(response
.headers
.get() != NULL
);
4878 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
4880 std::string response_data
;
4881 ASSERT_EQ(OK
, ReadTransaction(trans
, &response_data
));
4882 EXPECT_EQ("hello!", response_data
);
4883 helper
.VerifyDataConsumed();
4886 // Test to make sure we can correctly connect through a proxy to www.google.com,
4887 // if there already exists a direct spdy connection to www.google.com. See
4888 // http://crbug.com/49874
4889 TEST_P(SpdyNetworkTransactionTest
, DirectConnectProxyReconnect
) {
4890 // When setting up the first transaction, we store the SpdySessionPool so that
4891 // we can use the same pool in the second transaction.
4892 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
4893 BoundNetLog(), GetParam(), NULL
);
4895 // Use a proxy service which returns a proxy fallback list from DIRECT to
4896 // myproxy:70. For this test there will be no fallback, so it is equivalent
4897 // to simply DIRECT. The reason for appending the second proxy is to verify
4898 // that the session pool key used does is just "DIRECT".
4899 helper
.session_deps().reset(CreateSpdySessionDependencies(
4901 ProxyService::CreateFixedFromPacResult("DIRECT; PROXY myproxy:70")));
4902 helper
.SetSession(make_scoped_refptr(
4903 SpdySessionDependencies::SpdyCreateSession(helper
.session_deps().get())));
4905 SpdySessionPool
* spdy_session_pool
= helper
.session()->spdy_session_pool();
4906 helper
.RunPreTestSetup();
4908 // Construct and send a simple GET request.
4909 scoped_ptr
<SpdyFrame
> req(
4910 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
4911 MockWrite writes
[] = {
4912 CreateMockWrite(*req
, 1),
4915 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
4916 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
4917 MockRead reads
[] = {
4918 CreateMockRead(*resp
, 2),
4919 CreateMockRead(*body
, 3),
4920 MockRead(ASYNC
, ERR_IO_PENDING
, 4), // Force a pause
4921 MockRead(ASYNC
, 0, 5) // EOF
4923 OrderedSocketData
data(reads
, arraysize(reads
),
4924 writes
, arraysize(writes
));
4925 helper
.AddData(&data
);
4926 HttpNetworkTransaction
* trans
= helper
.trans();
4928 TestCompletionCallback callback
;
4929 TransactionHelperResult out
;
4930 out
.rv
= trans
->Start(
4931 &CreateGetRequest(), callback
.callback(), BoundNetLog());
4933 EXPECT_EQ(out
.rv
, ERR_IO_PENDING
);
4934 out
.rv
= callback
.WaitForResult();
4935 EXPECT_EQ(out
.rv
, OK
);
4937 const HttpResponseInfo
* response
= trans
->GetResponseInfo();
4938 EXPECT_TRUE(response
->headers
.get() != NULL
);
4939 EXPECT_TRUE(response
->was_fetched_via_spdy
);
4940 out
.rv
= ReadTransaction(trans
, &out
.response_data
);
4941 EXPECT_EQ(OK
, out
.rv
);
4942 out
.status_line
= response
->headers
->GetStatusLine();
4943 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
4944 EXPECT_EQ("hello!", out
.response_data
);
4946 // Check that the SpdySession is still in the SpdySessionPool.
4947 HostPortPair
host_port_pair("www.google.com", helper
.port());
4948 SpdySessionKey
session_pool_key_direct(
4949 host_port_pair
, ProxyServer::Direct(), PRIVACY_MODE_DISABLED
);
4950 EXPECT_TRUE(HasSpdySession(spdy_session_pool
, session_pool_key_direct
));
4951 SpdySessionKey
session_pool_key_proxy(
4953 ProxyServer::FromURI("www.foo.com", ProxyServer::SCHEME_HTTP
),
4954 PRIVACY_MODE_DISABLED
);
4955 EXPECT_FALSE(HasSpdySession(spdy_session_pool
, session_pool_key_proxy
));
4957 // Set up data for the proxy connection.
4958 const char kConnect443
[] = {"CONNECT www.google.com:443 HTTP/1.1\r\n"
4959 "Host: www.google.com\r\n"
4960 "Proxy-Connection: keep-alive\r\n\r\n"};
4961 const char kConnect80
[] = {"CONNECT www.google.com:80 HTTP/1.1\r\n"
4962 "Host: www.google.com\r\n"
4963 "Proxy-Connection: keep-alive\r\n\r\n"};
4964 const char kHTTP200
[] = {"HTTP/1.1 200 OK\r\n\r\n"};
4965 scoped_ptr
<SpdyFrame
> req2(spdy_util_
.ConstructSpdyGet(
4966 "http://www.google.com/foo.dat", false, 1, LOWEST
));
4967 scoped_ptr
<SpdyFrame
> resp2(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
4968 scoped_ptr
<SpdyFrame
> body2(spdy_util_
.ConstructSpdyBodyFrame(1, true));
4970 MockWrite writes_SPDYNPN
[] = {
4971 MockWrite(SYNCHRONOUS
, kConnect443
, arraysize(kConnect443
) - 1, 0),
4972 CreateMockWrite(*req2
, 2),
4974 MockRead reads_SPDYNPN
[] = {
4975 MockRead(SYNCHRONOUS
, kHTTP200
, arraysize(kHTTP200
) - 1, 1),
4976 CreateMockRead(*resp2
, 3),
4977 CreateMockRead(*body2
, 4),
4978 MockRead(ASYNC
, 0, 5) // EOF
4981 MockWrite writes_SPDYNOSSL
[] = {
4982 CreateMockWrite(*req2
, 0),
4984 MockRead reads_SPDYNOSSL
[] = {
4985 CreateMockRead(*resp2
, 1),
4986 CreateMockRead(*body2
, 2),
4987 MockRead(ASYNC
, 0, 3) // EOF
4990 MockWrite writes_SPDYSSL
[] = {
4991 MockWrite(SYNCHRONOUS
, kConnect80
, arraysize(kConnect80
) - 1, 0),
4992 CreateMockWrite(*req2
, 2),
4994 MockRead reads_SPDYSSL
[] = {
4995 MockRead(SYNCHRONOUS
, kHTTP200
, arraysize(kHTTP200
) - 1, 1),
4996 CreateMockRead(*resp2
, 3),
4997 CreateMockRead(*body2
, 4),
4998 MockRead(ASYNC
, 0, 0, 5),
5001 scoped_ptr
<OrderedSocketData
> data_proxy
;
5002 switch (GetParam().ssl_type
) {
5004 data_proxy
.reset(new OrderedSocketData(reads_SPDYNPN
,
5005 arraysize(reads_SPDYNPN
),
5007 arraysize(writes_SPDYNPN
)));
5010 data_proxy
.reset(new OrderedSocketData(reads_SPDYNOSSL
,
5011 arraysize(reads_SPDYNOSSL
),
5013 arraysize(writes_SPDYNOSSL
)));
5016 data_proxy
.reset(new OrderedSocketData(reads_SPDYSSL
,
5017 arraysize(reads_SPDYSSL
),
5019 arraysize(writes_SPDYSSL
)));
5025 // Create another request to www.google.com, but this time through a proxy.
5026 HttpRequestInfo request_proxy
;
5027 request_proxy
.method
= "GET";
5028 request_proxy
.url
= GURL("http://www.google.com/foo.dat");
5029 request_proxy
.load_flags
= 0;
5030 scoped_ptr
<SpdySessionDependencies
> ssd_proxy(
5031 CreateSpdySessionDependencies(GetParam()));
5032 // Ensure that this transaction uses the same SpdySessionPool.
5033 scoped_refptr
<HttpNetworkSession
> session_proxy(
5034 SpdySessionDependencies::SpdyCreateSession(ssd_proxy
.get()));
5035 NormalSpdyTransactionHelper
helper_proxy(request_proxy
, DEFAULT_PRIORITY
,
5036 BoundNetLog(), GetParam(), NULL
);
5037 HttpNetworkSessionPeer
session_peer(session_proxy
);
5038 scoped_ptr
<ProxyService
> proxy_service(
5039 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"));
5040 session_peer
.SetProxyService(proxy_service
.get());
5041 helper_proxy
.session_deps().swap(ssd_proxy
);
5042 helper_proxy
.SetSession(session_proxy
);
5043 helper_proxy
.RunPreTestSetup();
5044 helper_proxy
.AddData(data_proxy
.get());
5046 HttpNetworkTransaction
* trans_proxy
= helper_proxy
.trans();
5047 TestCompletionCallback callback_proxy
;
5048 int rv
= trans_proxy
->Start(
5049 &request_proxy
, callback_proxy
.callback(), BoundNetLog());
5050 EXPECT_EQ(ERR_IO_PENDING
, rv
);
5051 rv
= callback_proxy
.WaitForResult();
5054 HttpResponseInfo response_proxy
= *trans_proxy
->GetResponseInfo();
5055 EXPECT_TRUE(response_proxy
.headers
.get() != NULL
);
5056 EXPECT_EQ("HTTP/1.1 200 OK", response_proxy
.headers
->GetStatusLine());
5058 std::string response_data
;
5059 ASSERT_EQ(OK
, ReadTransaction(trans_proxy
, &response_data
));
5060 EXPECT_EQ("hello!", response_data
);
5062 data
.CompleteRead();
5063 helper_proxy
.VerifyDataConsumed();
5066 // When we get a TCP-level RST, we need to retry a HttpNetworkTransaction
5067 // on a new connection, if the connection was previously known to be good.
5068 // This can happen when a server reboots without saying goodbye, or when
5069 // we're behind a NAT that masked the RST.
5070 TEST_P(SpdyNetworkTransactionTest
, VerifyRetryOnConnectionReset
) {
5071 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
5072 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
5073 MockRead reads
[] = {
5074 CreateMockRead(*resp
),
5075 CreateMockRead(*body
),
5076 MockRead(ASYNC
, ERR_IO_PENDING
),
5077 MockRead(ASYNC
, ERR_CONNECTION_RESET
),
5080 MockRead reads2
[] = {
5081 CreateMockRead(*resp
),
5082 CreateMockRead(*body
),
5083 MockRead(ASYNC
, 0, 0) // EOF
5086 // This test has a couple of variants.
5088 // Induce the RST while waiting for our transaction to send.
5089 VARIANT_RST_DURING_SEND_COMPLETION
,
5090 // Induce the RST while waiting for our transaction to read.
5091 // In this case, the send completed - everything copied into the SNDBUF.
5092 VARIANT_RST_DURING_READ_COMPLETION
5095 for (int variant
= VARIANT_RST_DURING_SEND_COMPLETION
;
5096 variant
<= VARIANT_RST_DURING_READ_COMPLETION
;
5098 DelayedSocketData
data1(1, reads
, arraysize(reads
), NULL
, 0);
5100 DelayedSocketData
data2(1, reads2
, arraysize(reads2
), NULL
, 0);
5102 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
5103 BoundNetLog(), GetParam(), NULL
);
5104 helper
.AddData(&data1
);
5105 helper
.AddData(&data2
);
5106 helper
.RunPreTestSetup();
5108 for (int i
= 0; i
< 2; ++i
) {
5109 scoped_ptr
<HttpNetworkTransaction
> trans(
5110 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
5112 TestCompletionCallback callback
;
5113 int rv
= trans
->Start(
5114 &helper
.request(), callback
.callback(), BoundNetLog());
5115 EXPECT_EQ(ERR_IO_PENDING
, rv
);
5116 // On the second transaction, we trigger the RST.
5118 if (variant
== VARIANT_RST_DURING_READ_COMPLETION
) {
5119 // Writes to the socket complete asynchronously on SPDY by running
5120 // through the message loop. Complete the write here.
5121 base::RunLoop().RunUntilIdle();
5124 // Now schedule the ERR_CONNECTION_RESET.
5125 EXPECT_EQ(3u, data1
.read_index());
5126 data1
.CompleteRead();
5127 EXPECT_EQ(4u, data1
.read_index());
5129 rv
= callback
.WaitForResult();
5132 const HttpResponseInfo
* response
= trans
->GetResponseInfo();
5133 ASSERT_TRUE(response
!= NULL
);
5134 EXPECT_TRUE(response
->headers
.get() != NULL
);
5135 EXPECT_TRUE(response
->was_fetched_via_spdy
);
5136 std::string response_data
;
5137 rv
= ReadTransaction(trans
.get(), &response_data
);
5139 EXPECT_EQ("HTTP/1.1 200 OK", response
->headers
->GetStatusLine());
5140 EXPECT_EQ("hello!", response_data
);
5143 helper
.VerifyDataConsumed();
5147 // Test that turning SPDY on and off works properly.
5148 TEST_P(SpdyNetworkTransactionTest
, SpdyOnOffToggle
) {
5149 HttpStreamFactory::set_spdy_enabled(true);
5150 scoped_ptr
<SpdyFrame
> req(
5151 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
5152 MockWrite spdy_writes
[] = { CreateMockWrite(*req
) };
5154 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
5155 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
5156 MockRead spdy_reads
[] = {
5157 CreateMockRead(*resp
),
5158 CreateMockRead(*body
),
5159 MockRead(ASYNC
, 0, 0) // EOF
5162 DelayedSocketData
data(1, spdy_reads
, arraysize(spdy_reads
),
5163 spdy_writes
, arraysize(spdy_writes
));
5164 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
5165 BoundNetLog(), GetParam(), NULL
);
5166 helper
.RunToCompletion(&data
);
5167 TransactionHelperResult out
= helper
.output();
5168 EXPECT_EQ(OK
, out
.rv
);
5169 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
5170 EXPECT_EQ("hello!", out
.response_data
);
5172 HttpStreamFactory::set_spdy_enabled(false);
5173 MockRead http_reads
[] = {
5174 MockRead("HTTP/1.1 200 OK\r\n\r\n"),
5175 MockRead("hello from http"),
5176 MockRead(SYNCHRONOUS
, OK
),
5178 DelayedSocketData
data2(1, http_reads
, arraysize(http_reads
), NULL
, 0);
5179 NormalSpdyTransactionHelper
helper2(CreateGetRequest(), DEFAULT_PRIORITY
,
5180 BoundNetLog(), GetParam(), NULL
);
5181 helper2
.SetSpdyDisabled();
5182 helper2
.RunToCompletion(&data2
);
5183 TransactionHelperResult out2
= helper2
.output();
5184 EXPECT_EQ(OK
, out2
.rv
);
5185 EXPECT_EQ("HTTP/1.1 200 OK", out2
.status_line
);
5186 EXPECT_EQ("hello from http", out2
.response_data
);
5188 HttpStreamFactory::set_spdy_enabled(true);
5191 // Tests that Basic authentication works over SPDY
5192 TEST_P(SpdyNetworkTransactionTest
, SpdyBasicAuth
) {
5193 HttpStreamFactory::set_spdy_enabled(true);
5195 // The first request will be a bare GET, the second request will be a
5196 // GET with an Authorization header.
5197 scoped_ptr
<SpdyFrame
> req_get(
5198 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
5199 const char* const kExtraAuthorizationHeaders
[] = {
5200 "authorization", "Basic Zm9vOmJhcg=="
5202 scoped_ptr
<SpdyFrame
> req_get_authorization(
5203 spdy_util_
.ConstructSpdyGet(kExtraAuthorizationHeaders
,
5204 arraysize(kExtraAuthorizationHeaders
) / 2,
5205 false, 3, LOWEST
, true));
5206 MockWrite spdy_writes
[] = {
5207 CreateMockWrite(*req_get
, 1),
5208 CreateMockWrite(*req_get_authorization
, 4),
5211 // The first response is a 401 authentication challenge, and the second
5212 // response will be a 200 response since the second request includes a valid
5213 // Authorization header.
5214 const char* const kExtraAuthenticationHeaders
[] = {
5216 "Basic realm=\"MyRealm\""
5218 scoped_ptr
<SpdyFrame
> resp_authentication(
5219 spdy_util_
.ConstructSpdySynReplyError(
5220 "401 Authentication Required",
5221 kExtraAuthenticationHeaders
,
5222 arraysize(kExtraAuthenticationHeaders
) / 2,
5224 scoped_ptr
<SpdyFrame
> body_authentication(
5225 spdy_util_
.ConstructSpdyBodyFrame(1, true));
5226 scoped_ptr
<SpdyFrame
> resp_data(
5227 spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 3));
5228 scoped_ptr
<SpdyFrame
> body_data(spdy_util_
.ConstructSpdyBodyFrame(3, true));
5229 MockRead spdy_reads
[] = {
5230 CreateMockRead(*resp_authentication
, 2),
5231 CreateMockRead(*body_authentication
, 3),
5232 CreateMockRead(*resp_data
, 5),
5233 CreateMockRead(*body_data
, 6),
5234 MockRead(ASYNC
, 0, 7),
5237 OrderedSocketData
data(spdy_reads
, arraysize(spdy_reads
),
5238 spdy_writes
, arraysize(spdy_writes
));
5239 HttpRequestInfo
request(CreateGetRequest());
5240 BoundNetLog net_log
;
5241 NormalSpdyTransactionHelper
helper(request
, DEFAULT_PRIORITY
,
5242 net_log
, GetParam(), NULL
);
5244 helper
.RunPreTestSetup();
5245 helper
.AddData(&data
);
5246 HttpNetworkTransaction
* trans
= helper
.trans();
5247 TestCompletionCallback callback
;
5248 const int rv_start
= trans
->Start(&request
, callback
.callback(), net_log
);
5249 EXPECT_EQ(ERR_IO_PENDING
, rv_start
);
5250 const int rv_start_complete
= callback
.WaitForResult();
5251 EXPECT_EQ(OK
, rv_start_complete
);
5253 // Make sure the response has an auth challenge.
5254 const HttpResponseInfo
* const response_start
= trans
->GetResponseInfo();
5255 ASSERT_TRUE(response_start
!= NULL
);
5256 ASSERT_TRUE(response_start
->headers
.get() != NULL
);
5257 EXPECT_EQ(401, response_start
->headers
->response_code());
5258 EXPECT_TRUE(response_start
->was_fetched_via_spdy
);
5259 AuthChallengeInfo
* auth_challenge
= response_start
->auth_challenge
.get();
5260 ASSERT_TRUE(auth_challenge
!= NULL
);
5261 EXPECT_FALSE(auth_challenge
->is_proxy
);
5262 EXPECT_EQ("basic", auth_challenge
->scheme
);
5263 EXPECT_EQ("MyRealm", auth_challenge
->realm
);
5265 // Restart with a username/password.
5266 AuthCredentials
credentials(base::ASCIIToUTF16("foo"),
5267 base::ASCIIToUTF16("bar"));
5268 TestCompletionCallback callback_restart
;
5269 const int rv_restart
= trans
->RestartWithAuth(
5270 credentials
, callback_restart
.callback());
5271 EXPECT_EQ(ERR_IO_PENDING
, rv_restart
);
5272 const int rv_restart_complete
= callback_restart
.WaitForResult();
5273 EXPECT_EQ(OK
, rv_restart_complete
);
5274 // TODO(cbentzel): This is actually the same response object as before, but
5275 // data has changed.
5276 const HttpResponseInfo
* const response_restart
= trans
->GetResponseInfo();
5277 ASSERT_TRUE(response_restart
!= NULL
);
5278 ASSERT_TRUE(response_restart
->headers
.get() != NULL
);
5279 EXPECT_EQ(200, response_restart
->headers
->response_code());
5280 EXPECT_TRUE(response_restart
->auth_challenge
.get() == NULL
);
5283 TEST_P(SpdyNetworkTransactionTest
, ServerPushWithHeaders
) {
5284 scoped_ptr
<SpdyFrame
> stream1_syn(
5285 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
5286 scoped_ptr
<SpdyFrame
> stream1_body(
5287 spdy_util_
.ConstructSpdyBodyFrame(1, true));
5288 MockWrite writes
[] = {
5289 CreateMockWrite(*stream1_syn
, 1),
5292 scoped_ptr
<SpdyHeaderBlock
> initial_headers(new SpdyHeaderBlock());
5293 spdy_util_
.AddUrlToHeaderBlock(
5294 "http://www.google.com/foo.dat", initial_headers
.get());
5295 scoped_ptr
<SpdyFrame
> stream2_syn(
5296 spdy_util_
.ConstructInitialSpdyPushFrame(initial_headers
.Pass(), 2, 1));
5298 scoped_ptr
<SpdyHeaderBlock
> late_headers(new SpdyHeaderBlock());
5299 (*late_headers
)["hello"] = "bye";
5300 (*late_headers
)[spdy_util_
.GetStatusKey()] = "200";
5301 (*late_headers
)[spdy_util_
.GetVersionKey()] = "HTTP/1.1";
5302 scoped_ptr
<SpdyFrame
> stream2_headers(
5303 spdy_util_
.ConstructSpdyControlFrame(late_headers
.Pass(),
5311 scoped_ptr
<SpdyFrame
>
5312 stream1_reply(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
5313 const char kPushedData
[] = "pushed";
5314 scoped_ptr
<SpdyFrame
> stream2_body(
5315 spdy_util_
.ConstructSpdyBodyFrame(
5316 2, kPushedData
, strlen(kPushedData
), true));
5317 MockRead reads
[] = {
5318 CreateMockRead(*stream1_reply
, 2),
5319 CreateMockRead(*stream2_syn
, 3),
5320 CreateMockRead(*stream2_headers
, 4),
5321 CreateMockRead(*stream1_body
, 5, SYNCHRONOUS
),
5322 CreateMockRead(*stream2_body
, 5),
5323 MockRead(ASYNC
, ERR_IO_PENDING
, 7), // Force a pause
5326 HttpResponseInfo response
;
5327 HttpResponseInfo response2
;
5328 std::string
expected_push_result("pushed");
5329 OrderedSocketData
data(reads
, arraysize(reads
),
5330 writes
, arraysize(writes
));
5331 RunServerPushTest(&data
,
5334 expected_push_result
);
5336 // Verify the SYN_REPLY.
5337 EXPECT_TRUE(response
.headers
.get() != NULL
);
5338 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
5340 // Verify the pushed stream.
5341 EXPECT_TRUE(response2
.headers
.get() != NULL
);
5342 EXPECT_EQ("HTTP/1.1 200 OK", response2
.headers
->GetStatusLine());
5345 TEST_P(SpdyNetworkTransactionTest
, ServerPushClaimBeforeHeaders
) {
5346 // We push a stream and attempt to claim it before the headers come down.
5347 scoped_ptr
<SpdyFrame
> stream1_syn(
5348 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
5349 scoped_ptr
<SpdyFrame
> stream1_body(
5350 spdy_util_
.ConstructSpdyBodyFrame(1, true));
5351 MockWrite writes
[] = {
5352 CreateMockWrite(*stream1_syn
, 0, SYNCHRONOUS
),
5355 scoped_ptr
<SpdyHeaderBlock
> initial_headers(new SpdyHeaderBlock());
5356 spdy_util_
.AddUrlToHeaderBlock(
5357 "http://www.google.com/foo.dat", initial_headers
.get());
5358 scoped_ptr
<SpdyFrame
> stream2_syn(
5359 spdy_util_
.ConstructInitialSpdyPushFrame(initial_headers
.Pass(), 2, 1));
5361 scoped_ptr
<SpdyHeaderBlock
> late_headers(new SpdyHeaderBlock());
5362 (*late_headers
)["hello"] = "bye";
5363 (*late_headers
)[spdy_util_
.GetStatusKey()] = "200";
5364 (*late_headers
)[spdy_util_
.GetVersionKey()] = "HTTP/1.1";
5365 scoped_ptr
<SpdyFrame
> stream2_headers(
5366 spdy_util_
.ConstructSpdyControlFrame(late_headers
.Pass(),
5374 scoped_ptr
<SpdyFrame
>
5375 stream1_reply(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
5376 const char kPushedData
[] = "pushed";
5377 scoped_ptr
<SpdyFrame
> stream2_body(
5378 spdy_util_
.ConstructSpdyBodyFrame(
5379 2, kPushedData
, strlen(kPushedData
), true));
5380 MockRead reads
[] = {
5381 CreateMockRead(*stream1_reply
, 1),
5382 CreateMockRead(*stream2_syn
, 2),
5383 CreateMockRead(*stream1_body
, 3),
5384 CreateMockRead(*stream2_headers
, 4),
5385 CreateMockRead(*stream2_body
, 5),
5386 MockRead(ASYNC
, 0, 6), // EOF
5389 HttpResponseInfo response
;
5390 HttpResponseInfo response2
;
5391 std::string
expected_push_result("pushed");
5392 DeterministicSocketData
data(reads
, arraysize(reads
),
5393 writes
, arraysize(writes
));
5395 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
5396 BoundNetLog(), GetParam(), NULL
);
5397 helper
.SetDeterministic();
5398 helper
.AddDeterministicData(&data
);
5399 helper
.RunPreTestSetup();
5401 HttpNetworkTransaction
* trans
= helper
.trans();
5403 // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM,
5404 // and the body of the primary stream, but before we've received the HEADERS
5405 // for the pushed stream.
5408 // Start the transaction.
5409 TestCompletionCallback callback
;
5410 int rv
= trans
->Start(
5411 &CreateGetRequest(), callback
.callback(), BoundNetLog());
5412 EXPECT_EQ(ERR_IO_PENDING
, rv
);
5414 rv
= callback
.WaitForResult();
5417 // Request the pushed path. At this point, we've received the push, but the
5418 // headers are not yet complete.
5419 scoped_ptr
<HttpNetworkTransaction
> trans2(
5420 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
5422 &CreateGetPushRequest(), callback
.callback(), BoundNetLog());
5423 EXPECT_EQ(ERR_IO_PENDING
, rv
);
5425 base::RunLoop().RunUntilIdle();
5427 // Read the server push body.
5428 std::string result2
;
5429 ReadResult(trans2
.get(), &data
, &result2
);
5430 // Read the response body.
5432 ReadResult(trans
, &data
, &result
);
5434 // Verify that the received push data is same as the expected push data.
5435 EXPECT_EQ(result2
.compare(expected_push_result
), 0)
5436 << "Received data: "
5438 << "||||| Expected data: "
5439 << expected_push_result
;
5441 // Verify the SYN_REPLY.
5442 // Copy the response info, because trans goes away.
5443 response
= *trans
->GetResponseInfo();
5444 response2
= *trans2
->GetResponseInfo();
5446 VerifyStreamsClosed(helper
);
5448 // Verify the SYN_REPLY.
5449 EXPECT_TRUE(response
.headers
.get() != NULL
);
5450 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
5452 // Verify the pushed stream.
5453 EXPECT_TRUE(response2
.headers
.get() != NULL
);
5454 EXPECT_EQ("HTTP/1.1 200 OK", response2
.headers
->GetStatusLine());
5456 // Read the final EOF (which will close the session)
5459 // Verify that we consumed all test data.
5460 EXPECT_TRUE(data
.at_read_eof());
5461 EXPECT_TRUE(data
.at_write_eof());
5464 // TODO(baranovich): HTTP 2 does not allow multiple HEADERS frames
5465 TEST_P(SpdyNetworkTransactionTest
, ServerPushWithTwoHeaderFrames
) {
5466 // We push a stream and attempt to claim it before the headers come down.
5467 scoped_ptr
<SpdyFrame
> stream1_syn(
5468 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
5469 scoped_ptr
<SpdyFrame
> stream1_body(
5470 spdy_util_
.ConstructSpdyBodyFrame(1, true));
5471 MockWrite writes
[] = {
5472 CreateMockWrite(*stream1_syn
, 0, SYNCHRONOUS
),
5475 scoped_ptr
<SpdyHeaderBlock
> initial_headers(new SpdyHeaderBlock());
5476 if (spdy_util_
.spdy_version() < SPDY4
) {
5477 // In SPDY4 PUSH_PROMISE headers won't show up in the response headers.
5478 (*initial_headers
)["alpha"] = "beta";
5480 spdy_util_
.AddUrlToHeaderBlock(
5481 "http://www.google.com/foo.dat", initial_headers
.get());
5482 scoped_ptr
<SpdyFrame
> stream2_syn(
5483 spdy_util_
.ConstructInitialSpdyPushFrame(initial_headers
.Pass(), 2, 1));
5485 scoped_ptr
<SpdyHeaderBlock
> middle_headers(new SpdyHeaderBlock());
5486 (*middle_headers
)["hello"] = "bye";
5487 scoped_ptr
<SpdyFrame
> stream2_headers1(
5488 spdy_util_
.ConstructSpdyControlFrame(middle_headers
.Pass(),
5496 scoped_ptr
<SpdyHeaderBlock
> late_headers(new SpdyHeaderBlock());
5497 (*late_headers
)[spdy_util_
.GetStatusKey()] = "200";
5498 if (spdy_util_
.spdy_version() < SPDY4
) {
5499 // SPDY4/HTTP2 eliminates use of the :version header.
5500 (*late_headers
)[spdy_util_
.GetVersionKey()] = "HTTP/1.1";
5502 scoped_ptr
<SpdyFrame
> stream2_headers2(
5503 spdy_util_
.ConstructSpdyControlFrame(late_headers
.Pass(),
5511 scoped_ptr
<SpdyFrame
>
5512 stream1_reply(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
5513 const char kPushedData
[] = "pushed";
5514 scoped_ptr
<SpdyFrame
> stream2_body(
5515 spdy_util_
.ConstructSpdyBodyFrame(
5516 2, kPushedData
, strlen(kPushedData
), true));
5517 MockRead reads
[] = {
5518 CreateMockRead(*stream1_reply
, 1),
5519 CreateMockRead(*stream2_syn
, 2),
5520 CreateMockRead(*stream1_body
, 3),
5521 CreateMockRead(*stream2_headers1
, 4),
5522 CreateMockRead(*stream2_headers2
, 5),
5523 CreateMockRead(*stream2_body
, 6),
5524 MockRead(ASYNC
, 0, 7), // EOF
5527 HttpResponseInfo response
;
5528 HttpResponseInfo response2
;
5529 std::string
expected_push_result("pushed");
5530 DeterministicSocketData
data(reads
, arraysize(reads
),
5531 writes
, arraysize(writes
));
5533 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
5534 BoundNetLog(), GetParam(), NULL
);
5535 helper
.SetDeterministic();
5536 helper
.AddDeterministicData(&data
);
5537 helper
.RunPreTestSetup();
5539 HttpNetworkTransaction
* trans
= helper
.trans();
5541 // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM,
5542 // the first HEADERS frame, and the body of the primary stream, but before
5543 // we've received the final HEADERS for the pushed stream.
5546 // Start the transaction.
5547 TestCompletionCallback callback
;
5548 int rv
= trans
->Start(
5549 &CreateGetRequest(), callback
.callback(), BoundNetLog());
5550 EXPECT_EQ(ERR_IO_PENDING
, rv
);
5552 rv
= callback
.WaitForResult();
5555 // Request the pushed path. At this point, we've received the push, but the
5556 // headers are not yet complete.
5557 scoped_ptr
<HttpNetworkTransaction
> trans2(
5558 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
5560 &CreateGetPushRequest(), callback
.callback(), BoundNetLog());
5561 EXPECT_EQ(ERR_IO_PENDING
, rv
);
5563 base::RunLoop().RunUntilIdle();
5565 // Read the server push body.
5566 std::string result2
;
5567 ReadResult(trans2
.get(), &data
, &result2
);
5568 // Read the response body.
5570 ReadResult(trans
, &data
, &result
);
5572 // Verify that the received push data is same as the expected push data.
5573 EXPECT_EQ(expected_push_result
, result2
);
5575 // Verify the SYN_REPLY.
5576 // Copy the response info, because trans goes away.
5577 response
= *trans
->GetResponseInfo();
5578 response2
= *trans2
->GetResponseInfo();
5580 VerifyStreamsClosed(helper
);
5582 // Verify the SYN_REPLY.
5583 EXPECT_TRUE(response
.headers
.get() != NULL
);
5584 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
5586 // Verify the pushed stream.
5587 EXPECT_TRUE(response2
.headers
.get() != NULL
);
5588 EXPECT_EQ("HTTP/1.1 200 OK", response2
.headers
->GetStatusLine());
5590 // Verify we got all the headers from all header blocks.
5591 if (spdy_util_
.spdy_version() < SPDY4
)
5592 EXPECT_TRUE(response2
.headers
->HasHeaderValue("alpha", "beta"));
5593 EXPECT_TRUE(response2
.headers
->HasHeaderValue("hello", "bye"));
5594 EXPECT_TRUE(response2
.headers
->HasHeaderValue("status", "200"));
5596 // Read the final EOF (which will close the session)
5599 // Verify that we consumed all test data.
5600 EXPECT_TRUE(data
.at_read_eof());
5601 EXPECT_TRUE(data
.at_write_eof());
5604 TEST_P(SpdyNetworkTransactionTest
, ServerPushWithNoStatusHeaderFrames
) {
5605 // We push a stream and attempt to claim it before the headers come down.
5606 scoped_ptr
<SpdyFrame
> stream1_syn(
5607 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
5608 scoped_ptr
<SpdyFrame
> stream1_body(
5609 spdy_util_
.ConstructSpdyBodyFrame(1, true));
5610 MockWrite writes
[] = {
5611 CreateMockWrite(*stream1_syn
, 0, SYNCHRONOUS
),
5614 scoped_ptr
<SpdyHeaderBlock
> initial_headers(new SpdyHeaderBlock());
5615 spdy_util_
.AddUrlToHeaderBlock(
5616 "http://www.google.com/foo.dat", initial_headers
.get());
5617 scoped_ptr
<SpdyFrame
> stream2_syn(
5618 spdy_util_
.ConstructInitialSpdyPushFrame(initial_headers
.Pass(), 2, 1));
5620 scoped_ptr
<SpdyHeaderBlock
> middle_headers(new SpdyHeaderBlock());
5621 (*middle_headers
)["hello"] = "bye";
5622 scoped_ptr
<SpdyFrame
> stream2_headers1(
5623 spdy_util_
.ConstructSpdyControlFrame(middle_headers
.Pass(),
5631 scoped_ptr
<SpdyFrame
>
5632 stream1_reply(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
5633 const char kPushedData
[] = "pushed";
5634 scoped_ptr
<SpdyFrame
> stream2_body(
5635 spdy_util_
.ConstructSpdyBodyFrame(
5636 2, kPushedData
, strlen(kPushedData
), true));
5637 MockRead reads
[] = {
5638 CreateMockRead(*stream1_reply
, 1),
5639 CreateMockRead(*stream2_syn
, 2),
5640 CreateMockRead(*stream1_body
, 3),
5641 CreateMockRead(*stream2_headers1
, 4),
5642 CreateMockRead(*stream2_body
, 5),
5643 MockRead(ASYNC
, 0, 6), // EOF
5646 DeterministicSocketData
data(reads
, arraysize(reads
),
5647 writes
, arraysize(writes
));
5649 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
5650 BoundNetLog(), GetParam(), NULL
);
5651 helper
.SetDeterministic();
5652 helper
.AddDeterministicData(&data
);
5653 helper
.RunPreTestSetup();
5655 HttpNetworkTransaction
* trans
= helper
.trans();
5657 // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM,
5658 // the first HEADERS frame, and the body of the primary stream, but before
5659 // we've received the final HEADERS for the pushed stream.
5662 // Start the transaction.
5663 TestCompletionCallback callback
;
5664 int rv
= trans
->Start(
5665 &CreateGetRequest(), callback
.callback(), BoundNetLog());
5666 EXPECT_EQ(ERR_IO_PENDING
, rv
);
5668 rv
= callback
.WaitForResult();
5671 // Request the pushed path. At this point, we've received the push, but the
5672 // headers are not yet complete.
5673 scoped_ptr
<HttpNetworkTransaction
> trans2(
5674 new HttpNetworkTransaction(DEFAULT_PRIORITY
, helper
.session().get()));
5676 &CreateGetPushRequest(), callback
.callback(), BoundNetLog());
5677 EXPECT_EQ(ERR_IO_PENDING
, rv
);
5679 base::RunLoop().RunUntilIdle();
5681 // Read the server push body.
5682 std::string result2
;
5683 ReadResult(trans2
.get(), &data
, &result2
);
5684 // Read the response body.
5686 ReadResult(trans
, &data
, &result
);
5687 EXPECT_EQ("hello!", result
);
5689 // Verify that we haven't received any push data.
5690 EXPECT_EQ("", result2
);
5692 // Verify the SYN_REPLY.
5693 // Copy the response info, because trans goes away.
5694 HttpResponseInfo response
= *trans
->GetResponseInfo();
5695 ASSERT_TRUE(trans2
->GetResponseInfo() == NULL
);
5697 VerifyStreamsClosed(helper
);
5699 // Verify the SYN_REPLY.
5700 EXPECT_TRUE(response
.headers
.get() != NULL
);
5701 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
5703 // Read the final EOF (which will close the session).
5706 // Verify that we consumed all test data.
5707 EXPECT_TRUE(data
.at_read_eof());
5708 EXPECT_TRUE(data
.at_write_eof());
5711 TEST_P(SpdyNetworkTransactionTest
, SynReplyWithHeaders
) {
5712 scoped_ptr
<SpdyFrame
> req(
5713 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
5714 scoped_ptr
<SpdyFrame
> rst(
5715 spdy_util_
.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR
));
5716 MockWrite writes
[] = {
5717 CreateMockWrite(*req
), CreateMockWrite(*rst
),
5720 scoped_ptr
<SpdyFrame
> stream1_reply(
5721 spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
5723 scoped_ptr
<SpdyHeaderBlock
> late_headers(new SpdyHeaderBlock());
5724 (*late_headers
)["hello"] = "bye";
5725 scoped_ptr
<SpdyFrame
> stream1_headers(
5726 spdy_util_
.ConstructSpdyControlFrame(late_headers
.Pass(),
5733 scoped_ptr
<SpdyFrame
> stream1_body(
5734 spdy_util_
.ConstructSpdyBodyFrame(1, true));
5735 MockRead reads
[] = {
5736 CreateMockRead(*stream1_reply
),
5737 CreateMockRead(*stream1_headers
),
5738 CreateMockRead(*stream1_body
),
5739 MockRead(ASYNC
, 0, 0) // EOF
5742 DelayedSocketData
data(1, reads
, arraysize(reads
),
5743 writes
, arraysize(writes
));
5744 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
5745 BoundNetLog(), GetParam(), NULL
);
5746 helper
.RunToCompletion(&data
);
5747 TransactionHelperResult out
= helper
.output();
5748 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR
, out
.rv
);
5751 TEST_P(SpdyNetworkTransactionTest
, SynReplyWithLateHeaders
) {
5752 scoped_ptr
<SpdyFrame
> req(
5753 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
5754 scoped_ptr
<SpdyFrame
> rst(
5755 spdy_util_
.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR
));
5756 MockWrite writes
[] = {
5757 CreateMockWrite(*req
),
5758 CreateMockWrite(*rst
),
5761 scoped_ptr
<SpdyFrame
> stream1_reply(
5762 spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
5764 scoped_ptr
<SpdyHeaderBlock
> late_headers(new SpdyHeaderBlock());
5765 (*late_headers
)["hello"] = "bye";
5766 scoped_ptr
<SpdyFrame
> stream1_headers(
5767 spdy_util_
.ConstructSpdyControlFrame(late_headers
.Pass(),
5774 scoped_ptr
<SpdyFrame
> stream1_body(
5775 spdy_util_
.ConstructSpdyBodyFrame(1, false));
5776 scoped_ptr
<SpdyFrame
> stream1_body2(
5777 spdy_util_
.ConstructSpdyBodyFrame(1, true));
5778 MockRead reads
[] = {
5779 CreateMockRead(*stream1_reply
),
5780 CreateMockRead(*stream1_body
),
5781 CreateMockRead(*stream1_headers
),
5782 CreateMockRead(*stream1_body2
),
5783 MockRead(ASYNC
, 0, 0) // EOF
5786 DelayedSocketData
data(1, reads
, arraysize(reads
),
5787 writes
, arraysize(writes
));
5788 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
5789 BoundNetLog(), GetParam(), NULL
);
5790 helper
.RunToCompletion(&data
);
5791 TransactionHelperResult out
= helper
.output();
5792 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR
, out
.rv
);
5795 TEST_P(SpdyNetworkTransactionTest
, ServerPushCrossOriginCorrectness
) {
5796 // In this test we want to verify that we can't accidentally push content
5797 // which can't be pushed by this content server.
5798 // This test assumes that:
5799 // - if we're requesting http://www.foo.com/barbaz
5800 // - the browser has made a connection to "www.foo.com".
5802 // A list of the URL to fetch, followed by the URL being pushed.
5803 static const char* const kTestCases
[] = {
5804 "http://www.google.com/foo.html",
5805 "http://www.google.com:81/foo.js", // Bad port
5807 "http://www.google.com/foo.html",
5808 "https://www.google.com/foo.js", // Bad protocol
5810 "http://www.google.com/foo.html",
5811 "ftp://www.google.com/foo.js", // Invalid Protocol
5813 "http://www.google.com/foo.html",
5814 "http://blat.www.google.com/foo.js", // Cross subdomain
5816 "http://www.google.com/foo.html",
5817 "http://www.foo.com/foo.js", // Cross domain
5820 for (size_t index
= 0; index
< arraysize(kTestCases
); index
+= 2) {
5821 const char* url_to_fetch
= kTestCases
[index
];
5822 const char* url_to_push
= kTestCases
[index
+ 1];
5824 scoped_ptr
<SpdyFrame
> stream1_syn(
5825 spdy_util_
.ConstructSpdyGet(url_to_fetch
, false, 1, LOWEST
));
5826 scoped_ptr
<SpdyFrame
> stream1_body(
5827 spdy_util_
.ConstructSpdyBodyFrame(1, true));
5828 scoped_ptr
<SpdyFrame
> push_rst(
5829 spdy_util_
.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM
));
5830 MockWrite writes
[] = {
5831 CreateMockWrite(*stream1_syn
, 1),
5832 CreateMockWrite(*push_rst
, 4),
5835 scoped_ptr
<SpdyFrame
>
5836 stream1_reply(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
5837 scoped_ptr
<SpdyFrame
>
5838 stream2_syn(spdy_util_
.ConstructSpdyPush(NULL
,
5843 const char kPushedData
[] = "pushed";
5844 scoped_ptr
<SpdyFrame
> stream2_body(
5845 spdy_util_
.ConstructSpdyBodyFrame(
5846 2, kPushedData
, strlen(kPushedData
), true));
5847 scoped_ptr
<SpdyFrame
> rst(
5848 spdy_util_
.ConstructSpdyRstStream(2, RST_STREAM_CANCEL
));
5850 MockRead reads
[] = {
5851 CreateMockRead(*stream1_reply
, 2),
5852 CreateMockRead(*stream2_syn
, 3),
5853 CreateMockRead(*stream1_body
, 5, SYNCHRONOUS
),
5854 CreateMockRead(*stream2_body
, 6),
5855 MockRead(ASYNC
, ERR_IO_PENDING
, 7), // Force a pause
5858 HttpResponseInfo response
;
5859 OrderedSocketData
data(reads
, arraysize(reads
),
5860 writes
, arraysize(writes
));
5862 HttpRequestInfo request
;
5863 request
.method
= "GET";
5864 request
.url
= GURL(url_to_fetch
);
5865 request
.load_flags
= 0;
5867 // Enable cross-origin push. Since we are not using a proxy, this should
5868 // not actually enable cross-origin SPDY push.
5869 scoped_ptr
<SpdySessionDependencies
> session_deps(
5870 CreateSpdySessionDependencies(GetParam()));
5871 session_deps
->trusted_spdy_proxy
= "123.45.67.89:8080";
5872 NormalSpdyTransactionHelper
helper(request
, DEFAULT_PRIORITY
,
5873 BoundNetLog(), GetParam(),
5874 session_deps
.release());
5875 helper
.RunPreTestSetup();
5876 helper
.AddData(&data
);
5878 HttpNetworkTransaction
* trans
= helper
.trans();
5880 // Start the transaction with basic parameters.
5881 TestCompletionCallback callback
;
5883 int rv
= trans
->Start(&request
, callback
.callback(), BoundNetLog());
5884 EXPECT_EQ(ERR_IO_PENDING
, rv
);
5885 rv
= callback
.WaitForResult();
5887 // Read the response body.
5889 ReadResult(trans
, &data
, &result
);
5891 // Verify that we consumed all test data.
5892 EXPECT_TRUE(data
.at_read_eof());
5893 EXPECT_TRUE(data
.at_write_eof());
5895 // Verify the SYN_REPLY.
5896 // Copy the response info, because trans goes away.
5897 response
= *trans
->GetResponseInfo();
5899 VerifyStreamsClosed(helper
);
5901 // Verify the SYN_REPLY.
5902 EXPECT_TRUE(response
.headers
.get() != NULL
);
5903 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
5907 TEST_P(SpdyNetworkTransactionTest
, RetryAfterRefused
) {
5908 // Construct the request.
5909 scoped_ptr
<SpdyFrame
> req(
5910 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
5911 scoped_ptr
<SpdyFrame
> req2(
5912 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 3, LOWEST
, true));
5913 MockWrite writes
[] = {
5914 CreateMockWrite(*req
, 1),
5915 CreateMockWrite(*req2
, 3),
5918 scoped_ptr
<SpdyFrame
> refused(
5919 spdy_util_
.ConstructSpdyRstStream(1, RST_STREAM_REFUSED_STREAM
));
5920 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 3));
5921 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(3, true));
5922 MockRead reads
[] = {
5923 CreateMockRead(*refused
, 2),
5924 CreateMockRead(*resp
, 4),
5925 CreateMockRead(*body
, 5),
5926 MockRead(ASYNC
, 0, 6) // EOF
5929 OrderedSocketData
data(reads
, arraysize(reads
),
5930 writes
, arraysize(writes
));
5931 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
5932 BoundNetLog(), GetParam(), NULL
);
5934 helper
.RunPreTestSetup();
5935 helper
.AddData(&data
);
5937 HttpNetworkTransaction
* trans
= helper
.trans();
5939 // Start the transaction with basic parameters.
5940 TestCompletionCallback callback
;
5941 int rv
= trans
->Start(
5942 &CreateGetRequest(), callback
.callback(), BoundNetLog());
5943 EXPECT_EQ(ERR_IO_PENDING
, rv
);
5944 rv
= callback
.WaitForResult();
5947 // Verify that we consumed all test data.
5948 EXPECT_TRUE(data
.at_read_eof()) << "Read count: "
5949 << data
.read_count()
5951 << data
.read_index();
5952 EXPECT_TRUE(data
.at_write_eof()) << "Write count: "
5953 << data
.write_count()
5955 << data
.write_index();
5957 // Verify the SYN_REPLY.
5958 HttpResponseInfo response
= *trans
->GetResponseInfo();
5959 EXPECT_TRUE(response
.headers
.get() != NULL
);
5960 EXPECT_EQ("HTTP/1.1 200 OK", response
.headers
->GetStatusLine());
5963 TEST_P(SpdyNetworkTransactionTest
, OutOfOrderSynStream
) {
5964 // This first request will start to establish the SpdySession.
5965 // Then we will start the second (MEDIUM priority) and then third
5966 // (HIGHEST priority) request in such a way that the third will actually
5967 // start before the second, causing the second to be numbered differently
5968 // than the order they were created.
5969 scoped_ptr
<SpdyFrame
> req1(
5970 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
5971 scoped_ptr
<SpdyFrame
> req2(
5972 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 3, HIGHEST
, true));
5973 scoped_ptr
<SpdyFrame
> req3(
5974 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 5, MEDIUM
, true));
5975 MockWrite writes
[] = {
5976 CreateMockWrite(*req1
, 0),
5977 CreateMockWrite(*req2
, 3),
5978 CreateMockWrite(*req3
, 4),
5981 scoped_ptr
<SpdyFrame
> resp1(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
5982 scoped_ptr
<SpdyFrame
> body1(spdy_util_
.ConstructSpdyBodyFrame(1, true));
5983 scoped_ptr
<SpdyFrame
> resp2(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 3));
5984 scoped_ptr
<SpdyFrame
> body2(spdy_util_
.ConstructSpdyBodyFrame(3, true));
5985 scoped_ptr
<SpdyFrame
> resp3(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 5));
5986 scoped_ptr
<SpdyFrame
> body3(spdy_util_
.ConstructSpdyBodyFrame(5, true));
5987 MockRead reads
[] = {
5988 CreateMockRead(*resp1
, 1),
5989 CreateMockRead(*body1
, 2),
5990 CreateMockRead(*resp2
, 5),
5991 CreateMockRead(*body2
, 6),
5992 CreateMockRead(*resp3
, 7),
5993 CreateMockRead(*body3
, 8),
5994 MockRead(ASYNC
, 0, 9) // EOF
5997 DeterministicSocketData
data(reads
, arraysize(reads
),
5998 writes
, arraysize(writes
));
5999 NormalSpdyTransactionHelper
helper(CreateGetRequest(), LOWEST
,
6000 BoundNetLog(), GetParam(), NULL
);
6001 helper
.SetDeterministic();
6002 helper
.RunPreTestSetup();
6003 helper
.AddDeterministicData(&data
);
6005 // Start the first transaction to set up the SpdySession
6006 HttpNetworkTransaction
* trans
= helper
.trans();
6007 TestCompletionCallback callback
;
6008 HttpRequestInfo info1
= CreateGetRequest();
6009 int rv
= trans
->Start(&info1
, callback
.callback(), BoundNetLog());
6010 EXPECT_EQ(ERR_IO_PENDING
, rv
);
6012 // Run the message loop, but do not allow the write to complete.
6013 // This leaves the SpdySession with a write pending, which prevents
6014 // SpdySession from attempting subsequent writes until this write completes.
6015 base::RunLoop().RunUntilIdle();
6017 // Now, start both new transactions
6018 HttpRequestInfo info2
= CreateGetRequest();
6019 TestCompletionCallback callback2
;
6020 scoped_ptr
<HttpNetworkTransaction
> trans2(
6021 new HttpNetworkTransaction(MEDIUM
, helper
.session().get()));
6022 rv
= trans2
->Start(&info2
, callback2
.callback(), BoundNetLog());
6023 EXPECT_EQ(ERR_IO_PENDING
, rv
);
6024 base::RunLoop().RunUntilIdle();
6026 HttpRequestInfo info3
= CreateGetRequest();
6027 TestCompletionCallback callback3
;
6028 scoped_ptr
<HttpNetworkTransaction
> trans3(
6029 new HttpNetworkTransaction(HIGHEST
, helper
.session().get()));
6030 rv
= trans3
->Start(&info3
, callback3
.callback(), BoundNetLog());
6031 EXPECT_EQ(ERR_IO_PENDING
, rv
);
6032 base::RunLoop().RunUntilIdle();
6034 // We now have two SYN_STREAM frames queued up which will be
6035 // dequeued only once the first write completes, which we
6036 // now allow to happen.
6038 EXPECT_EQ(OK
, callback
.WaitForResult());
6040 // And now we can allow everything else to run to completion.
6043 EXPECT_EQ(OK
, callback2
.WaitForResult());
6044 EXPECT_EQ(OK
, callback3
.WaitForResult());
6046 helper
.VerifyDataConsumed();
6049 // The tests below are only for SPDY/3 and above.
6051 // Test that sent data frames and received WINDOW_UPDATE frames change
6052 // the send_window_size_ correctly.
6054 // WINDOW_UPDATE is different than most other frames in that it can arrive
6055 // while the client is still sending the request body. In order to enforce
6056 // this scenario, we feed a couple of dummy frames and give a delay of 0 to
6057 // socket data provider, so that initial read that is done as soon as the
6058 // stream is created, succeeds and schedules another read. This way reads
6059 // and writes are interleaved; after doing a full frame write, SpdyStream
6060 // will break out of DoLoop and will read and process a WINDOW_UPDATE.
6061 // Once our WINDOW_UPDATE is read, we cannot send SYN_REPLY right away
6062 // since request has not been completely written, therefore we feed
6063 // enough number of WINDOW_UPDATEs to finish the first read and cause a
6064 // write, leading to a complete write of request body; after that we send
6065 // a reply with a body, to cause a graceful shutdown.
6067 // TODO(agayev): develop a socket data provider where both, reads and
6068 // writes are ordered so that writing tests like these are easy and rewrite
6069 // all these tests using it. Right now we are working around the
6070 // limitations as described above and it's not deterministic, tests may
6071 // fail under specific circumstances.
6072 TEST_P(SpdyNetworkTransactionTest
, WindowUpdateReceived
) {
6073 static int kFrameCount
= 2;
6074 scoped_ptr
<std::string
> content(
6075 new std::string(kMaxSpdyFrameChunkSize
, 'a'));
6076 scoped_ptr
<SpdyFrame
> req(spdy_util_
.ConstructSpdyPost(
6077 kRequestUrl
, 1, kMaxSpdyFrameChunkSize
* kFrameCount
, LOWEST
, NULL
, 0));
6078 scoped_ptr
<SpdyFrame
> body(
6079 spdy_util_
.ConstructSpdyBodyFrame(
6080 1, content
->c_str(), content
->size(), false));
6081 scoped_ptr
<SpdyFrame
> body_end(
6082 spdy_util_
.ConstructSpdyBodyFrame(
6083 1, content
->c_str(), content
->size(), true));
6085 MockWrite writes
[] = {
6086 CreateMockWrite(*req
, 0),
6087 CreateMockWrite(*body
, 1),
6088 CreateMockWrite(*body_end
, 2),
6091 static const int32 kDeltaWindowSize
= 0xff;
6092 static const int kDeltaCount
= 4;
6093 scoped_ptr
<SpdyFrame
> window_update(
6094 spdy_util_
.ConstructSpdyWindowUpdate(1, kDeltaWindowSize
));
6095 scoped_ptr
<SpdyFrame
> window_update_dummy(
6096 spdy_util_
.ConstructSpdyWindowUpdate(2, kDeltaWindowSize
));
6097 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyPostSynReply(NULL
, 0));
6098 MockRead reads
[] = {
6099 CreateMockRead(*window_update_dummy
, 3),
6100 CreateMockRead(*window_update_dummy
, 4),
6101 CreateMockRead(*window_update_dummy
, 5),
6102 CreateMockRead(*window_update
, 6), // Four updates, therefore window
6103 CreateMockRead(*window_update
, 7), // size should increase by
6104 CreateMockRead(*window_update
, 8), // kDeltaWindowSize * 4
6105 CreateMockRead(*window_update
, 9),
6106 CreateMockRead(*resp
, 10),
6107 CreateMockRead(*body_end
, 11),
6108 MockRead(ASYNC
, 0, 0, 12) // EOF
6111 DeterministicSocketData
data(reads
, arraysize(reads
),
6112 writes
, arraysize(writes
));
6114 ScopedVector
<UploadElementReader
> element_readers
;
6115 for (int i
= 0; i
< kFrameCount
; ++i
) {
6116 element_readers
.push_back(
6117 new UploadBytesElementReader(content
->c_str(), content
->size()));
6119 ElementsUploadDataStream
upload_data_stream(element_readers
.Pass(), 0);
6121 // Setup the request
6122 HttpRequestInfo request
;
6123 request
.method
= "POST";
6124 request
.url
= GURL(kDefaultURL
);
6125 request
.upload_data_stream
= &upload_data_stream
;
6127 NormalSpdyTransactionHelper
helper(request
, DEFAULT_PRIORITY
,
6128 BoundNetLog(), GetParam(), NULL
);
6129 helper
.SetDeterministic();
6130 helper
.AddDeterministicData(&data
);
6131 helper
.RunPreTestSetup();
6133 HttpNetworkTransaction
* trans
= helper
.trans();
6135 TestCompletionCallback callback
;
6136 int rv
= trans
->Start(&helper
.request(), callback
.callback(), BoundNetLog());
6138 EXPECT_EQ(ERR_IO_PENDING
, rv
);
6142 SpdyHttpStream
* stream
= static_cast<SpdyHttpStream
*>(trans
->stream_
.get());
6143 ASSERT_TRUE(stream
!= NULL
);
6144 ASSERT_TRUE(stream
->stream() != NULL
);
6146 static_cast<int>(SpdySession::GetInitialWindowSize(GetParam().protocol
)) +
6147 kDeltaWindowSize
* kDeltaCount
- kMaxSpdyFrameChunkSize
* kFrameCount
,
6148 stream
->stream()->send_window_size());
6152 rv
= callback
.WaitForResult();
6155 helper
.VerifyDataConsumed();
6158 // Test that received data frames and sent WINDOW_UPDATE frames change
6159 // the recv_window_size_ correctly.
6160 TEST_P(SpdyNetworkTransactionTest
, WindowUpdateSent
) {
6161 const int32 initial_window_size
=
6162 SpdySession::GetInitialWindowSize(GetParam().protocol
);
6163 // Amount of body required to trigger a sent window update.
6164 const size_t kTargetSize
= initial_window_size
/ 2 + 1;
6166 scoped_ptr
<SpdyFrame
> req(
6167 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
6168 scoped_ptr
<SpdyFrame
> session_window_update(
6169 spdy_util_
.ConstructSpdyWindowUpdate(0, kTargetSize
));
6170 scoped_ptr
<SpdyFrame
> window_update(
6171 spdy_util_
.ConstructSpdyWindowUpdate(1, kTargetSize
));
6173 std::vector
<MockWrite
> writes
;
6174 writes
.push_back(CreateMockWrite(*req
));
6175 if (GetParam().protocol
>= kProtoSPDY31
)
6176 writes
.push_back(CreateMockWrite(*session_window_update
));
6177 writes
.push_back(CreateMockWrite(*window_update
));
6179 std::vector
<MockRead
> reads
;
6180 scoped_ptr
<SpdyFrame
> resp(
6181 spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
6182 reads
.push_back(CreateMockRead(*resp
));
6184 ScopedVector
<SpdyFrame
> body_frames
;
6185 const std::string
body_data(4096, 'x');
6186 for (size_t remaining
= kTargetSize
; remaining
!= 0;) {
6187 size_t frame_size
= std::min(remaining
, body_data
.size());
6188 body_frames
.push_back(spdy_util_
.ConstructSpdyBodyFrame(
6189 1, body_data
.data(), frame_size
, false));
6190 reads
.push_back(CreateMockRead(*body_frames
.back()));
6191 remaining
-= frame_size
;
6193 reads
.push_back(MockRead(ASYNC
, ERR_IO_PENDING
, 0)); // Yield.
6195 DelayedSocketData
data(1, vector_as_array(&reads
), reads
.size(),
6196 vector_as_array(&writes
), writes
.size());
6198 NormalSpdyTransactionHelper
helper(CreateGetRequest(), DEFAULT_PRIORITY
,
6199 BoundNetLog(), GetParam(), NULL
);
6200 helper
.AddData(&data
);
6201 helper
.RunPreTestSetup();
6202 HttpNetworkTransaction
* trans
= helper
.trans();
6204 TestCompletionCallback callback
;
6205 int rv
= trans
->Start(&helper
.request(), callback
.callback(), BoundNetLog());
6207 EXPECT_EQ(ERR_IO_PENDING
, rv
);
6208 rv
= callback
.WaitForResult();
6211 SpdyHttpStream
* stream
=
6212 static_cast<SpdyHttpStream
*>(trans
->stream_
.get());
6213 ASSERT_TRUE(stream
!= NULL
);
6214 ASSERT_TRUE(stream
->stream() != NULL
);
6216 // All data has been read, but not consumed. The window reflects this.
6217 EXPECT_EQ(static_cast<int>(initial_window_size
- kTargetSize
),
6218 stream
->stream()->recv_window_size());
6220 const HttpResponseInfo
* response
= trans
->GetResponseInfo();
6221 ASSERT_TRUE(response
!= NULL
);
6222 ASSERT_TRUE(response
->headers
.get() != NULL
);
6223 EXPECT_EQ("HTTP/1.1 200 OK", response
->headers
->GetStatusLine());
6224 EXPECT_TRUE(response
->was_fetched_via_spdy
);
6226 // Issue a read which will cause a WINDOW_UPDATE to be sent and window
6227 // size increased to default.
6228 scoped_refptr
<IOBuffer
> buf(new IOBuffer(kTargetSize
));
6229 EXPECT_EQ(static_cast<int>(kTargetSize
),
6230 trans
->Read(buf
.get(), kTargetSize
, CompletionCallback()));
6231 EXPECT_EQ(static_cast<int>(initial_window_size
),
6232 stream
->stream()->recv_window_size());
6233 EXPECT_THAT(base::StringPiece(buf
->data(), kTargetSize
), Each(Eq('x')));
6235 // Allow scheduled WINDOW_UPDATE frames to write.
6236 base::RunLoop().RunUntilIdle();
6237 helper
.VerifyDataConsumed();
6240 // Test that WINDOW_UPDATE frame causing overflow is handled correctly.
6241 TEST_P(SpdyNetworkTransactionTest
, WindowUpdateOverflow
) {
6242 // Number of full frames we hope to write (but will not, used to
6243 // set content-length header correctly)
6244 static int kFrameCount
= 3;
6246 scoped_ptr
<std::string
> content(
6247 new std::string(kMaxSpdyFrameChunkSize
, 'a'));
6248 scoped_ptr
<SpdyFrame
> req(spdy_util_
.ConstructSpdyPost(
6249 kRequestUrl
, 1, kMaxSpdyFrameChunkSize
* kFrameCount
, LOWEST
, NULL
, 0));
6250 scoped_ptr
<SpdyFrame
> body(
6251 spdy_util_
.ConstructSpdyBodyFrame(
6252 1, content
->c_str(), content
->size(), false));
6253 scoped_ptr
<SpdyFrame
> rst(
6254 spdy_util_
.ConstructSpdyRstStream(1, RST_STREAM_FLOW_CONTROL_ERROR
));
6256 // We're not going to write a data frame with FIN, we'll receive a bad
6257 // WINDOW_UPDATE while sending a request and will send a RST_STREAM frame.
6258 MockWrite writes
[] = {
6259 CreateMockWrite(*req
, 0),
6260 CreateMockWrite(*body
, 2),
6261 CreateMockWrite(*rst
, 3),
6264 static const int32 kDeltaWindowSize
= 0x7fffffff; // cause an overflow
6265 scoped_ptr
<SpdyFrame
> window_update(
6266 spdy_util_
.ConstructSpdyWindowUpdate(1, kDeltaWindowSize
));
6267 MockRead reads
[] = {
6268 CreateMockRead(*window_update
, 1),
6269 MockRead(ASYNC
, 0, 4) // EOF
6272 DeterministicSocketData
data(reads
, arraysize(reads
),
6273 writes
, arraysize(writes
));
6275 ScopedVector
<UploadElementReader
> element_readers
;
6276 for (int i
= 0; i
< kFrameCount
; ++i
) {
6277 element_readers
.push_back(
6278 new UploadBytesElementReader(content
->c_str(), content
->size()));
6280 ElementsUploadDataStream
upload_data_stream(element_readers
.Pass(), 0);
6282 // Setup the request
6283 HttpRequestInfo request
;
6284 request
.method
= "POST";
6285 request
.url
= GURL("http://www.google.com/");
6286 request
.upload_data_stream
= &upload_data_stream
;
6288 NormalSpdyTransactionHelper
helper(request
, DEFAULT_PRIORITY
,
6289 BoundNetLog(), GetParam(), NULL
);
6290 helper
.SetDeterministic();
6291 helper
.RunPreTestSetup();
6292 helper
.AddDeterministicData(&data
);
6293 HttpNetworkTransaction
* trans
= helper
.trans();
6295 TestCompletionCallback callback
;
6296 int rv
= trans
->Start(&helper
.request(), callback
.callback(), BoundNetLog());
6297 ASSERT_EQ(ERR_IO_PENDING
, rv
);
6300 ASSERT_TRUE(callback
.have_result());
6301 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR
, callback
.WaitForResult());
6302 helper
.VerifyDataConsumed();
6305 // Test that after hitting a send window size of 0, the write process
6306 // stalls and upon receiving WINDOW_UPDATE frame write resumes.
6308 // This test constructs a POST request followed by enough data frames
6309 // containing 'a' that would make the window size 0, followed by another
6310 // data frame containing default content (which is "hello!") and this frame
6311 // also contains a FIN flag. DelayedSocketData is used to enforce all
6312 // writes go through before a read could happen. However, the last frame
6313 // ("hello!") is not supposed to go through since by the time its turn
6314 // arrives, window size is 0. At this point MessageLoop::Run() called via
6315 // callback would block. Therefore we call MessageLoop::RunUntilIdle()
6316 // which returns after performing all possible writes. We use DCHECKS to
6317 // ensure that last data frame is still there and stream has stalled.
6318 // After that, next read is artifically enforced, which causes a
6319 // WINDOW_UPDATE to be read and I/O process resumes.
6320 TEST_P(SpdyNetworkTransactionTest
, FlowControlStallResume
) {
6321 const int32 initial_window_size
=
6322 SpdySession::GetInitialWindowSize(GetParam().protocol
);
6323 // Number of frames we need to send to zero out the window size: data
6324 // frames plus SYN_STREAM plus the last data frame; also we need another
6325 // data frame that we will send once the WINDOW_UPDATE is received,
6327 size_t num_writes
= initial_window_size
/ kMaxSpdyFrameChunkSize
+ 3;
6329 // Calculate last frame's size; 0 size data frame is legal.
6330 size_t last_frame_size
= initial_window_size
% kMaxSpdyFrameChunkSize
;
6332 // Construct content for a data frame of maximum size.
6333 std::string
content(kMaxSpdyFrameChunkSize
, 'a');
6335 scoped_ptr
<SpdyFrame
> req(spdy_util_
.ConstructSpdyPost(
6336 kRequestUrl
, 1, initial_window_size
+ kUploadDataSize
, LOWEST
, NULL
, 0));
6339 scoped_ptr
<SpdyFrame
> body1(
6340 spdy_util_
.ConstructSpdyBodyFrame(
6341 1, content
.c_str(), content
.size(), false));
6343 // Last frame to zero out the window size.
6344 scoped_ptr
<SpdyFrame
> body2(
6345 spdy_util_
.ConstructSpdyBodyFrame(
6346 1, content
.c_str(), last_frame_size
, false));
6348 // Data frame to be sent once WINDOW_UPDATE frame is received.
6349 scoped_ptr
<SpdyFrame
> body3(spdy_util_
.ConstructSpdyBodyFrame(1, true));
6351 // Fill in mock writes.
6352 scoped_ptr
<MockWrite
[]> writes(new MockWrite
[num_writes
]);
6354 writes
[i
] = CreateMockWrite(*req
);
6355 for (i
= 1; i
< num_writes
- 2; i
++)
6356 writes
[i
] = CreateMockWrite(*body1
);
6357 writes
[i
++] = CreateMockWrite(*body2
);
6358 writes
[i
] = CreateMockWrite(*body3
);
6360 // Construct read frame, give enough space to upload the rest of the
6362 scoped_ptr
<SpdyFrame
> session_window_update(
6363 spdy_util_
.ConstructSpdyWindowUpdate(0, kUploadDataSize
));
6364 scoped_ptr
<SpdyFrame
> window_update(
6365 spdy_util_
.ConstructSpdyWindowUpdate(1, kUploadDataSize
));
6366 scoped_ptr
<SpdyFrame
> reply(spdy_util_
.ConstructSpdyPostSynReply(NULL
, 0));
6367 MockRead reads
[] = {
6368 CreateMockRead(*session_window_update
),
6369 CreateMockRead(*session_window_update
),
6370 CreateMockRead(*window_update
),
6371 CreateMockRead(*window_update
),
6372 CreateMockRead(*reply
),
6373 CreateMockRead(*body2
),
6374 CreateMockRead(*body3
),
6375 MockRead(ASYNC
, 0, 0) // EOF
6378 // Skip the session window updates unless we're using SPDY/3.1 and
6380 size_t read_offset
= (GetParam().protocol
>= kProtoSPDY31
) ? 0 : 2;
6381 size_t num_reads
= arraysize(reads
) - read_offset
;
6383 // Force all writes to happen before any read, last write will not
6384 // actually queue a frame, due to window size being 0.
6385 DelayedSocketData
data(num_writes
, reads
+ read_offset
, num_reads
,
6386 writes
.get(), num_writes
);
6388 ScopedVector
<UploadElementReader
> element_readers
;
6389 std::string
upload_data_string(initial_window_size
, 'a');
6390 upload_data_string
.append(kUploadData
, kUploadDataSize
);
6391 element_readers
.push_back(new UploadBytesElementReader(
6392 upload_data_string
.c_str(), upload_data_string
.size()));
6393 ElementsUploadDataStream
upload_data_stream(element_readers
.Pass(), 0);
6395 HttpRequestInfo request
;
6396 request
.method
= "POST";
6397 request
.url
= GURL("http://www.google.com/");
6398 request
.upload_data_stream
= &upload_data_stream
;
6399 NormalSpdyTransactionHelper
helper(request
, DEFAULT_PRIORITY
,
6400 BoundNetLog(), GetParam(), NULL
);
6401 helper
.AddData(&data
);
6402 helper
.RunPreTestSetup();
6404 HttpNetworkTransaction
* trans
= helper
.trans();
6406 TestCompletionCallback callback
;
6407 int rv
= trans
->Start(&helper
.request(), callback
.callback(), BoundNetLog());
6408 EXPECT_EQ(ERR_IO_PENDING
, rv
);
6410 base::RunLoop().RunUntilIdle(); // Write as much as we can.
6412 SpdyHttpStream
* stream
= static_cast<SpdyHttpStream
*>(trans
->stream_
.get());
6413 ASSERT_TRUE(stream
!= NULL
);
6414 ASSERT_TRUE(stream
->stream() != NULL
);
6415 EXPECT_EQ(0, stream
->stream()->send_window_size());
6416 // All the body data should have been read.
6417 // TODO(satorux): This is because of the weirdness in reading the request
6418 // body in OnSendBodyComplete(). See crbug.com/113107.
6419 EXPECT_TRUE(upload_data_stream
.IsEOF());
6420 // But the body is not yet fully sent (kUploadData is not yet sent)
6421 // since we're send-stalled.
6422 EXPECT_TRUE(stream
->stream()->send_stalled_by_flow_control());
6424 data
.ForceNextRead(); // Read in WINDOW_UPDATE frame.
6425 rv
= callback
.WaitForResult();
6426 helper
.VerifyDataConsumed();
6429 // Test we correctly handle the case where the SETTINGS frame results in
6430 // unstalling the send window.
6431 TEST_P(SpdyNetworkTransactionTest
, FlowControlStallResumeAfterSettings
) {
6432 const int32 initial_window_size
=
6433 SpdySession::GetInitialWindowSize(GetParam().protocol
);
6435 // Number of frames we need to send to zero out the window size: data
6436 // frames plus SYN_STREAM plus the last data frame; also we need another
6437 // data frame that we will send once the SETTING is received, therefore +3.
6438 size_t num_writes
= initial_window_size
/ kMaxSpdyFrameChunkSize
+ 3;
6440 // Calculate last frame's size; 0 size data frame is legal.
6441 size_t last_frame_size
= initial_window_size
% kMaxSpdyFrameChunkSize
;
6443 // Construct content for a data frame of maximum size.
6444 std::string
content(kMaxSpdyFrameChunkSize
, 'a');
6446 scoped_ptr
<SpdyFrame
> req(spdy_util_
.ConstructSpdyPost(
6447 kRequestUrl
, 1, initial_window_size
+ kUploadDataSize
, LOWEST
, NULL
, 0));
6450 scoped_ptr
<SpdyFrame
> body1(
6451 spdy_util_
.ConstructSpdyBodyFrame(
6452 1, content
.c_str(), content
.size(), false));
6454 // Last frame to zero out the window size.
6455 scoped_ptr
<SpdyFrame
> body2(
6456 spdy_util_
.ConstructSpdyBodyFrame(
6457 1, content
.c_str(), last_frame_size
, false));
6459 // Data frame to be sent once SETTINGS frame is received.
6460 scoped_ptr
<SpdyFrame
> body3(spdy_util_
.ConstructSpdyBodyFrame(1, true));
6462 // Fill in mock reads/writes.
6463 std::vector
<MockRead
> reads
;
6464 std::vector
<MockWrite
> writes
;
6466 writes
.push_back(CreateMockWrite(*req
, i
++));
6467 while (i
< num_writes
- 2)
6468 writes
.push_back(CreateMockWrite(*body1
, i
++));
6469 writes
.push_back(CreateMockWrite(*body2
, i
++));
6471 // Construct read frame for SETTINGS that gives enough space to upload the
6472 // rest of the data.
6473 SettingsMap settings
;
6474 settings
[SETTINGS_INITIAL_WINDOW_SIZE
] =
6475 SettingsFlagsAndValue(SETTINGS_FLAG_NONE
, initial_window_size
* 2);
6476 scoped_ptr
<SpdyFrame
> settings_frame_large(
6477 spdy_util_
.ConstructSpdySettings(settings
));
6479 reads
.push_back(CreateMockRead(*settings_frame_large
, i
++));
6481 scoped_ptr
<SpdyFrame
> session_window_update(
6482 spdy_util_
.ConstructSpdyWindowUpdate(0, kUploadDataSize
));
6483 if (GetParam().protocol
>= kProtoSPDY31
)
6484 reads
.push_back(CreateMockRead(*session_window_update
, i
++));
6486 scoped_ptr
<SpdyFrame
> settings_ack(spdy_util_
.ConstructSpdySettingsAck());
6487 writes
.push_back(CreateMockWrite(*settings_ack
, i
++));
6489 writes
.push_back(CreateMockWrite(*body3
, i
++));
6491 scoped_ptr
<SpdyFrame
> reply(spdy_util_
.ConstructSpdyPostSynReply(NULL
, 0));
6492 reads
.push_back(CreateMockRead(*reply
, i
++));
6493 reads
.push_back(CreateMockRead(*body2
, i
++));
6494 reads
.push_back(CreateMockRead(*body3
, i
++));
6495 reads
.push_back(MockRead(ASYNC
, 0, i
++)); // EOF
6497 // Force all writes to happen before any read, last write will not
6498 // actually queue a frame, due to window size being 0.
6499 DeterministicSocketData
data(vector_as_array(&reads
), reads
.size(),
6500 vector_as_array(&writes
), writes
.size());
6502 ScopedVector
<UploadElementReader
> element_readers
;
6503 std::string
upload_data_string(initial_window_size
, 'a');
6504 upload_data_string
.append(kUploadData
, kUploadDataSize
);
6505 element_readers
.push_back(new UploadBytesElementReader(
6506 upload_data_string
.c_str(), upload_data_string
.size()));
6507 ElementsUploadDataStream
upload_data_stream(element_readers
.Pass(), 0);
6509 HttpRequestInfo request
;
6510 request
.method
= "POST";
6511 request
.url
= GURL("http://www.google.com/");
6512 request
.upload_data_stream
= &upload_data_stream
;
6513 NormalSpdyTransactionHelper
helper(request
, DEFAULT_PRIORITY
,
6514 BoundNetLog(), GetParam(), NULL
);
6515 helper
.SetDeterministic();
6516 helper
.RunPreTestSetup();
6517 helper
.AddDeterministicData(&data
);
6519 HttpNetworkTransaction
* trans
= helper
.trans();
6521 TestCompletionCallback callback
;
6522 int rv
= trans
->Start(&helper
.request(), callback
.callback(), BoundNetLog());
6523 EXPECT_EQ(ERR_IO_PENDING
, rv
);
6525 data
.RunFor(num_writes
- 1); // Write as much as we can.
6527 SpdyHttpStream
* stream
= static_cast<SpdyHttpStream
*>(trans
->stream_
.get());
6528 ASSERT_TRUE(stream
!= NULL
);
6529 ASSERT_TRUE(stream
->stream() != NULL
);
6530 EXPECT_EQ(0, stream
->stream()->send_window_size());
6532 // All the body data should have been read.
6533 // TODO(satorux): This is because of the weirdness in reading the request
6534 // body in OnSendBodyComplete(). See crbug.com/113107.
6535 EXPECT_TRUE(upload_data_stream
.IsEOF());
6536 // But the body is not yet fully sent (kUploadData is not yet sent)
6537 // since we're send-stalled.
6538 EXPECT_TRUE(stream
->stream()->send_stalled_by_flow_control());
6540 data
.RunFor(7); // Read in SETTINGS frame to unstall.
6541 rv
= callback
.WaitForResult();
6542 helper
.VerifyDataConsumed();
6543 // If stream is NULL, that means it was unstalled and closed.
6544 EXPECT_TRUE(stream
->stream() == NULL
);
6547 // Test we correctly handle the case where the SETTINGS frame results in a
6548 // negative send window size.
6549 TEST_P(SpdyNetworkTransactionTest
, FlowControlNegativeSendWindowSize
) {
6550 const int32 initial_window_size
=
6551 SpdySession::GetInitialWindowSize(GetParam().protocol
);
6552 // Number of frames we need to send to zero out the window size: data
6553 // frames plus SYN_STREAM plus the last data frame; also we need another
6554 // data frame that we will send once the SETTING is received, therefore +3.
6555 size_t num_writes
= initial_window_size
/ kMaxSpdyFrameChunkSize
+ 3;
6557 // Calculate last frame's size; 0 size data frame is legal.
6558 size_t last_frame_size
= initial_window_size
% kMaxSpdyFrameChunkSize
;
6560 // Construct content for a data frame of maximum size.
6561 std::string
content(kMaxSpdyFrameChunkSize
, 'a');
6563 scoped_ptr
<SpdyFrame
> req(spdy_util_
.ConstructSpdyPost(
6564 kRequestUrl
, 1, initial_window_size
+ kUploadDataSize
, LOWEST
, NULL
, 0));
6567 scoped_ptr
<SpdyFrame
> body1(
6568 spdy_util_
.ConstructSpdyBodyFrame(
6569 1, content
.c_str(), content
.size(), false));
6571 // Last frame to zero out the window size.
6572 scoped_ptr
<SpdyFrame
> body2(
6573 spdy_util_
.ConstructSpdyBodyFrame(
6574 1, content
.c_str(), last_frame_size
, false));
6576 // Data frame to be sent once SETTINGS frame is received.
6577 scoped_ptr
<SpdyFrame
> body3(spdy_util_
.ConstructSpdyBodyFrame(1, true));
6579 // Fill in mock reads/writes.
6580 std::vector
<MockRead
> reads
;
6581 std::vector
<MockWrite
> writes
;
6583 writes
.push_back(CreateMockWrite(*req
, i
++));
6584 while (i
< num_writes
- 2)
6585 writes
.push_back(CreateMockWrite(*body1
, i
++));
6586 writes
.push_back(CreateMockWrite(*body2
, i
++));
6588 // Construct read frame for SETTINGS that makes the send_window_size
6590 SettingsMap new_settings
;
6591 new_settings
[SETTINGS_INITIAL_WINDOW_SIZE
] =
6592 SettingsFlagsAndValue(SETTINGS_FLAG_NONE
, initial_window_size
/ 2);
6593 scoped_ptr
<SpdyFrame
> settings_frame_small(
6594 spdy_util_
.ConstructSpdySettings(new_settings
));
6595 // Construct read frames for WINDOW_UPDATE that makes the send_window_size
6597 scoped_ptr
<SpdyFrame
> session_window_update_init_size(
6598 spdy_util_
.ConstructSpdyWindowUpdate(0, initial_window_size
));
6599 scoped_ptr
<SpdyFrame
> window_update_init_size(
6600 spdy_util_
.ConstructSpdyWindowUpdate(1, initial_window_size
));
6602 reads
.push_back(CreateMockRead(*settings_frame_small
, i
++));
6603 reads
.push_back(CreateMockRead(*session_window_update_init_size
, i
++));
6604 reads
.push_back(CreateMockRead(*window_update_init_size
, i
++));
6606 scoped_ptr
<SpdyFrame
> settings_ack(spdy_util_
.ConstructSpdySettingsAck());
6607 writes
.push_back(CreateMockWrite(*settings_ack
, i
++));
6609 writes
.push_back(CreateMockWrite(*body3
, i
++));
6611 scoped_ptr
<SpdyFrame
> reply(spdy_util_
.ConstructSpdyPostSynReply(NULL
, 0));
6612 reads
.push_back(CreateMockRead(*reply
, i
++));
6613 reads
.push_back(CreateMockRead(*body2
, i
++));
6614 reads
.push_back(CreateMockRead(*body3
, i
++));
6615 reads
.push_back(MockRead(ASYNC
, 0, i
++)); // EOF
6617 // Force all writes to happen before any read, last write will not
6618 // actually queue a frame, due to window size being 0.
6619 DeterministicSocketData
data(vector_as_array(&reads
), reads
.size(),
6620 vector_as_array(&writes
), writes
.size());
6622 ScopedVector
<UploadElementReader
> element_readers
;
6623 std::string
upload_data_string(initial_window_size
, 'a');
6624 upload_data_string
.append(kUploadData
, kUploadDataSize
);
6625 element_readers
.push_back(new UploadBytesElementReader(
6626 upload_data_string
.c_str(), upload_data_string
.size()));
6627 ElementsUploadDataStream
upload_data_stream(element_readers
.Pass(), 0);
6629 HttpRequestInfo request
;
6630 request
.method
= "POST";
6631 request
.url
= GURL("http://www.google.com/");
6632 request
.upload_data_stream
= &upload_data_stream
;
6633 NormalSpdyTransactionHelper
helper(request
, DEFAULT_PRIORITY
,
6634 BoundNetLog(), GetParam(), NULL
);
6635 helper
.SetDeterministic();
6636 helper
.RunPreTestSetup();
6637 helper
.AddDeterministicData(&data
);
6639 HttpNetworkTransaction
* trans
= helper
.trans();
6641 TestCompletionCallback callback
;
6642 int rv
= trans
->Start(&helper
.request(), callback
.callback(), BoundNetLog());
6643 EXPECT_EQ(ERR_IO_PENDING
, rv
);
6645 data
.RunFor(num_writes
- 1); // Write as much as we can.
6647 SpdyHttpStream
* stream
= static_cast<SpdyHttpStream
*>(trans
->stream_
.get());
6648 ASSERT_TRUE(stream
!= NULL
);
6649 ASSERT_TRUE(stream
->stream() != NULL
);
6650 EXPECT_EQ(0, stream
->stream()->send_window_size());
6652 // All the body data should have been read.
6653 // TODO(satorux): This is because of the weirdness in reading the request
6654 // body in OnSendBodyComplete(). See crbug.com/113107.
6655 EXPECT_TRUE(upload_data_stream
.IsEOF());
6656 // But the body is not yet fully sent (kUploadData is not yet sent)
6657 // since we're send-stalled.
6658 EXPECT_TRUE(stream
->stream()->send_stalled_by_flow_control());
6660 // Read in WINDOW_UPDATE or SETTINGS frame.
6661 data
.RunFor((GetParam().protocol
>= kProtoSPDY31
) ? 9 : 8);
6662 rv
= callback
.WaitForResult();
6663 helper
.VerifyDataConsumed();
6666 TEST_P(SpdyNetworkTransactionTest
, GoAwayOnOddPushStreamId
) {
6667 if (spdy_util_
.spdy_version() < SPDY3
)
6670 scoped_ptr
<SpdyHeaderBlock
> push_headers(new SpdyHeaderBlock
);
6671 spdy_util_
.AddUrlToHeaderBlock("http://www.google.com/a.dat",
6672 push_headers
.get());
6673 scoped_ptr
<SpdyFrame
> push(
6674 spdy_util_
.ConstructInitialSpdyPushFrame(push_headers
.Pass(), 3, 1));
6675 MockRead reads
[] = {CreateMockRead(*push
, 1)};
6677 scoped_ptr
<SpdyFrame
> req(
6678 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
6679 scoped_ptr
<SpdyFrame
> goaway(spdy_util_
.ConstructSpdyGoAway(
6680 0, GOAWAY_PROTOCOL_ERROR
, "Odd push stream id."));
6681 MockWrite writes
[] = {
6682 CreateMockWrite(*req
, 0), CreateMockWrite(*goaway
, 2),
6685 DelayedSocketData
data(1, reads
, arraysize(reads
), writes
, arraysize(writes
));
6686 NormalSpdyTransactionHelper
helper(
6687 CreateGetRequest(), DEFAULT_PRIORITY
, BoundNetLog(), GetParam(), NULL
);
6688 helper
.RunToCompletion(&data
);
6689 TransactionHelperResult out
= helper
.output();
6690 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR
, out
.rv
);
6693 TEST_P(SpdyNetworkTransactionTest
,
6694 GoAwayOnPushStreamIdLesserOrEqualThanLastAccepted
) {
6695 if (spdy_util_
.spdy_version() < SPDY3
)
6698 scoped_ptr
<SpdyFrame
> push_a(spdy_util_
.ConstructSpdyPush(
6699 NULL
, 0, 4, 1, "http://www.google.com/a.dat"));
6700 scoped_ptr
<SpdyHeaderBlock
> push_b_headers(new SpdyHeaderBlock
);
6701 spdy_util_
.AddUrlToHeaderBlock("http://www.google.com/b.dat",
6702 push_b_headers
.get());
6703 scoped_ptr
<SpdyFrame
> push_b(
6704 spdy_util_
.ConstructInitialSpdyPushFrame(push_b_headers
.Pass(), 2, 1));
6705 MockRead reads
[] = {
6706 CreateMockRead(*push_a
, 1), CreateMockRead(*push_b
, 2),
6709 scoped_ptr
<SpdyFrame
> req(
6710 spdy_util_
.ConstructSpdyGet(NULL
, 0, false, 1, LOWEST
, true));
6711 scoped_ptr
<SpdyFrame
> goaway(spdy_util_
.ConstructSpdyGoAway(
6713 GOAWAY_PROTOCOL_ERROR
,
6714 "New push stream id must be greater than the last accepted."));
6715 MockWrite writes
[] = {
6716 CreateMockWrite(*req
, 0), CreateMockWrite(*goaway
, 3),
6719 DelayedSocketData
data(1, reads
, arraysize(reads
), writes
, arraysize(writes
));
6720 NormalSpdyTransactionHelper
helper(
6721 CreateGetRequest(), DEFAULT_PRIORITY
, BoundNetLog(), GetParam(), NULL
);
6722 helper
.RunToCompletion(&data
);
6723 TransactionHelperResult out
= helper
.output();
6724 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR
, out
.rv
);
6727 class SpdyNetworkTransactionNoTLSUsageCheckTest
6728 : public SpdyNetworkTransactionTest
{
6730 void RunNoTLSUsageCheckTest(scoped_ptr
<SSLSocketDataProvider
> ssl_provider
) {
6731 // Construct the request.
6732 scoped_ptr
<SpdyFrame
> req(spdy_util_
.ConstructSpdyGet(
6733 "https://www.google.com/", false, 1, LOWEST
));
6734 MockWrite writes
[] = {CreateMockWrite(*req
)};
6736 scoped_ptr
<SpdyFrame
> resp(spdy_util_
.ConstructSpdyGetSynReply(NULL
, 0, 1));
6737 scoped_ptr
<SpdyFrame
> body(spdy_util_
.ConstructSpdyBodyFrame(1, true));
6738 MockRead reads
[] = {
6739 CreateMockRead(*resp
), CreateMockRead(*body
),
6740 MockRead(ASYNC
, 0, 0) // EOF
6743 DelayedSocketData
data(
6744 1, reads
, arraysize(reads
), writes
, arraysize(writes
));
6745 HttpRequestInfo request
;
6746 request
.method
= "GET";
6747 request
.url
= GURL("https://www.google.com/");
6748 NormalSpdyTransactionHelper
helper(
6749 request
, DEFAULT_PRIORITY
, BoundNetLog(), GetParam(), NULL
);
6750 helper
.RunToCompletionWithSSLData(&data
, ssl_provider
.Pass());
6751 TransactionHelperResult out
= helper
.output();
6752 EXPECT_EQ(OK
, out
.rv
);
6753 EXPECT_EQ("HTTP/1.1 200 OK", out
.status_line
);
6754 EXPECT_EQ("hello!", out
.response_data
);
6758 //-----------------------------------------------------------------------------
6759 // All tests are run with three different connection types: SPDY after NPN
6760 // negotiation, SPDY without SSL, and SPDY with SSL.
6762 // TODO(akalin): Use ::testing::Combine() when we are able to use
6764 INSTANTIATE_TEST_CASE_P(
6766 SpdyNetworkTransactionNoTLSUsageCheckTest
,
6767 ::testing::Values(SpdyNetworkTransactionTestParams(kProtoSPDY31
, SPDYNPN
)));
6769 TEST_P(SpdyNetworkTransactionNoTLSUsageCheckTest
, TLSVersionTooOld
) {
6770 scoped_ptr
<SSLSocketDataProvider
> ssl_provider(
6771 new SSLSocketDataProvider(ASYNC
, OK
));
6772 SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3
,
6773 &ssl_provider
->connection_status
);
6775 RunNoTLSUsageCheckTest(ssl_provider
.Pass());
6778 TEST_P(SpdyNetworkTransactionNoTLSUsageCheckTest
, TLSCipherSuiteSucky
) {
6779 scoped_ptr
<SSLSocketDataProvider
> ssl_provider(
6780 new SSLSocketDataProvider(ASYNC
, OK
));
6781 // Set to TLS_RSA_WITH_NULL_MD5
6782 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider
->connection_status
);
6784 RunNoTLSUsageCheckTest(ssl_provider
.Pass());
6787 class SpdyNetworkTransactionTLSUsageCheckTest
6788 : public SpdyNetworkTransactionTest
{
6790 void RunTLSUsageCheckTest(scoped_ptr
<SSLSocketDataProvider
> ssl_provider
) {
6791 scoped_ptr
<SpdyFrame
> goaway(
6792 spdy_util_
.ConstructSpdyGoAway(0, GOAWAY_INADEQUATE_SECURITY
, ""));
6793 MockWrite writes
[] = {CreateMockWrite(*goaway
)};
6795 DelayedSocketData
data(1, NULL
, 0, writes
, arraysize(writes
));
6796 HttpRequestInfo request
;
6797 request
.method
= "GET";
6798 request
.url
= GURL("https://www.google.com/");
6799 NormalSpdyTransactionHelper
helper(
6800 request
, DEFAULT_PRIORITY
, BoundNetLog(), GetParam(), NULL
);
6801 helper
.RunToCompletionWithSSLData(&data
, ssl_provider
.Pass());
6802 TransactionHelperResult out
= helper
.output();
6803 EXPECT_EQ(ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY
, out
.rv
);
6807 INSTANTIATE_TEST_CASE_P(
6809 SpdyNetworkTransactionTLSUsageCheckTest
,
6810 ::testing::Values(SpdyNetworkTransactionTestParams(kProtoSPDY4_14
, SPDYNPN
),
6811 SpdyNetworkTransactionTestParams(kProtoSPDY4
, SPDYNPN
)));
6813 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest
, TLSVersionTooOld
) {
6814 scoped_ptr
<SSLSocketDataProvider
> ssl_provider(
6815 new SSLSocketDataProvider(ASYNC
, OK
));
6816 SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3
,
6817 &ssl_provider
->connection_status
);
6819 RunTLSUsageCheckTest(ssl_provider
.Pass());
6822 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest
, TLSCipherSuiteSucky
) {
6823 scoped_ptr
<SSLSocketDataProvider
> ssl_provider(
6824 new SSLSocketDataProvider(ASYNC
, OK
));
6825 // Set to TLS_RSA_WITH_NULL_MD5
6826 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider
->connection_status
);
6828 RunTLSUsageCheckTest(ssl_provider
.Pass());