| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 SPDYNPN, | 38 SPDYNPN, |
| 39 SPDYNOSSL, | 39 SPDYNOSSL, |
| 40 SPDYSSL, | 40 SPDYSSL, |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 class SpdyNetworkTransactionSpdy3Test | 43 class SpdyNetworkTransactionSpdy3Test |
| 44 : public ::testing::TestWithParam<SpdyNetworkTransactionSpdy3TestTypes> { | 44 : public ::testing::TestWithParam<SpdyNetworkTransactionSpdy3TestTypes> { |
| 45 protected: | 45 protected: |
| 46 | 46 |
| 47 virtual void SetUp() { | 47 virtual void SetUp() { |
| 48 SpdySession::set_default_protocol(kProtoSPDY3); | |
| 49 google_get_request_initialized_ = false; | 48 google_get_request_initialized_ = false; |
| 50 google_post_request_initialized_ = false; | 49 google_post_request_initialized_ = false; |
| 51 google_chunked_post_request_initialized_ = false; | 50 google_chunked_post_request_initialized_ = false; |
| 52 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 51 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 53 } | 52 } |
| 54 | 53 |
| 55 virtual void TearDown() { | 54 virtual void TearDown() { |
| 56 UploadDataStream::ResetMergeChunks(); | 55 UploadDataStream::ResetMergeChunks(); |
| 57 // Empty the current queue. | 56 // Empty the current queue. |
| 58 MessageLoop::current()->RunUntilIdle(); | 57 MessageLoop::current()->RunUntilIdle(); |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 | 569 |
| 571 private: | 570 private: |
| 572 scoped_ptr<UploadDataStream> upload_data_stream_; | 571 scoped_ptr<UploadDataStream> upload_data_stream_; |
| 573 bool google_get_request_initialized_; | 572 bool google_get_request_initialized_; |
| 574 bool google_post_request_initialized_; | 573 bool google_post_request_initialized_; |
| 575 bool google_chunked_post_request_initialized_; | 574 bool google_chunked_post_request_initialized_; |
| 576 HttpRequestInfo google_get_request_; | 575 HttpRequestInfo google_get_request_; |
| 577 HttpRequestInfo google_post_request_; | 576 HttpRequestInfo google_post_request_; |
| 578 HttpRequestInfo google_chunked_post_request_; | 577 HttpRequestInfo google_chunked_post_request_; |
| 579 HttpRequestInfo google_get_push_request_; | 578 HttpRequestInfo google_get_push_request_; |
| 580 SpdyTestStateHelper spdy_state_; | |
| 581 base::ScopedTempDir temp_dir_; | 579 base::ScopedTempDir temp_dir_; |
| 582 }; | 580 }; |
| 583 | 581 |
| 584 //----------------------------------------------------------------------------- | 582 //----------------------------------------------------------------------------- |
| 585 // All tests are run with three different connection types: SPDY after NPN | 583 // All tests are run with three different connection types: SPDY after NPN |
| 586 // negotiation, SPDY without SSL, and SPDY with SSL. | 584 // negotiation, SPDY without SSL, and SPDY with SSL. |
| 587 INSTANTIATE_TEST_CASE_P(Spdy, | 585 INSTANTIATE_TEST_CASE_P(Spdy, |
| 588 SpdyNetworkTransactionSpdy3Test, | 586 SpdyNetworkTransactionSpdy3Test, |
| 589 ::testing::Values(SPDYNOSSL, SPDYSSL, SPDYNPN)); | 587 ::testing::Values(SPDYNOSSL, SPDYSSL, SPDYNPN)); |
| 590 | 588 |
| (...skipping 3506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4097 helper.RunToCompletion(&data); | 4095 helper.RunToCompletion(&data); |
| 4098 TransactionHelperResult out = helper.output(); | 4096 TransactionHelperResult out = helper.output(); |
| 4099 EXPECT_EQ(OK, out.rv); | 4097 EXPECT_EQ(OK, out.rv); |
| 4100 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 4098 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4101 EXPECT_EQ("hello!", out.response_data); | 4099 EXPECT_EQ("hello!", out.response_data); |
| 4102 } | 4100 } |
| 4103 | 4101 |
| 4104 // In this test, we enable compression, but get a uncompressed SynReply from | 4102 // In this test, we enable compression, but get a uncompressed SynReply from |
| 4105 // the server. Verify that teardown is all clean. | 4103 // the server. Verify that teardown is all clean. |
| 4106 TEST_P(SpdyNetworkTransactionSpdy3Test, DecompressFailureOnSynReply) { | 4104 TEST_P(SpdyNetworkTransactionSpdy3Test, DecompressFailureOnSynReply) { |
| 4107 // For this test, we turn on the normal compression. | |
| 4108 BufferedSpdyFramer::set_enable_compression_default(true); | |
| 4109 | |
| 4110 scoped_ptr<SpdyFrame> compressed( | 4105 scoped_ptr<SpdyFrame> compressed( |
| 4111 ConstructSpdyGet(NULL, 0, true, 1, LOWEST)); | 4106 ConstructSpdyGet(NULL, 0, true, 1, LOWEST)); |
| 4112 scoped_ptr<SpdyFrame> rst( | 4107 scoped_ptr<SpdyFrame> rst( |
| 4113 ConstructSpdyRstStream(1, PROTOCOL_ERROR)); | 4108 ConstructSpdyRstStream(1, PROTOCOL_ERROR)); |
| 4114 MockWrite writes[] = { | 4109 MockWrite writes[] = { |
| 4115 CreateMockWrite(*compressed), | 4110 CreateMockWrite(*compressed), |
| 4116 }; | 4111 }; |
| 4117 | 4112 |
| 4118 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 4113 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4119 scoped_ptr<SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); | 4114 scoped_ptr<SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); |
| 4120 MockRead reads[] = { | 4115 MockRead reads[] = { |
| 4121 CreateMockRead(*resp), | 4116 CreateMockRead(*resp), |
| 4122 }; | 4117 }; |
| 4123 | 4118 |
| 4124 DelayedSocketData data(1, reads, arraysize(reads), | 4119 DelayedSocketData data(1, reads, arraysize(reads), |
| 4125 writes, arraysize(writes)); | 4120 writes, arraysize(writes)); |
| 4121 SpdySessionDependencies* session_deps = new SpdySessionDependencies(); |
| 4122 session_deps->enable_compression = true; |
| 4126 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 4123 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 4127 BoundNetLog(), GetParam(), NULL); | 4124 BoundNetLog(), GetParam(), session_deps); |
| 4128 helper.RunToCompletion(&data); | 4125 helper.RunToCompletion(&data); |
| 4129 TransactionHelperResult out = helper.output(); | 4126 TransactionHelperResult out = helper.output(); |
| 4130 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | 4127 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 4131 data.Reset(); | 4128 data.Reset(); |
| 4132 } | 4129 } |
| 4133 | 4130 |
| 4134 // Test that the NetLog contains good data for a simple GET request. | 4131 // Test that the NetLog contains good data for a simple GET request. |
| 4135 TEST_P(SpdyNetworkTransactionSpdy3Test, NetLog) { | 4132 TEST_P(SpdyNetworkTransactionSpdy3Test, NetLog) { |
| 4136 static const char* const kExtraHeaders[] = { | 4133 static const char* const kExtraHeaders[] = { |
| 4137 "user-agent", "Chrome", | 4134 "user-agent", "Chrome", |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4213 EXPECT_NE(header_list->end(), header_list->Find(header)) << | 4210 EXPECT_NE(header_list->end(), header_list->Find(header)) << |
| 4214 "Header not found: " << *it; | 4211 "Header not found: " << *it; |
| 4215 } | 4212 } |
| 4216 } | 4213 } |
| 4217 | 4214 |
| 4218 // Since we buffer the IO from the stream to the renderer, this test verifies | 4215 // Since we buffer the IO from the stream to the renderer, this test verifies |
| 4219 // that when we read out the maximum amount of data (e.g. we received 50 bytes | 4216 // that when we read out the maximum amount of data (e.g. we received 50 bytes |
| 4220 // on the network, but issued a Read for only 5 of those bytes) that the data | 4217 // on the network, but issued a Read for only 5 of those bytes) that the data |
| 4221 // flow still works correctly. | 4218 // flow still works correctly. |
| 4222 TEST_P(SpdyNetworkTransactionSpdy3Test, BufferFull) { | 4219 TEST_P(SpdyNetworkTransactionSpdy3Test, BufferFull) { |
| 4223 BufferedSpdyFramer framer(3); | 4220 BufferedSpdyFramer framer(3, false); |
| 4224 | 4221 |
| 4225 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 4222 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 4226 MockWrite writes[] = { CreateMockWrite(*req) }; | 4223 MockWrite writes[] = { CreateMockWrite(*req) }; |
| 4227 | 4224 |
| 4228 // 2 data frames in a single read. | 4225 // 2 data frames in a single read. |
| 4229 scoped_ptr<SpdyFrame> data_frame_1( | 4226 scoped_ptr<SpdyFrame> data_frame_1( |
| 4230 framer.CreateDataFrame(1, "goodby", 6, DATA_FLAG_NONE)); | 4227 framer.CreateDataFrame(1, "goodby", 6, DATA_FLAG_NONE)); |
| 4231 scoped_ptr<SpdyFrame> data_frame_2( | 4228 scoped_ptr<SpdyFrame> data_frame_2( |
| 4232 framer.CreateDataFrame(1, "e worl", 6, DATA_FLAG_NONE)); | 4229 framer.CreateDataFrame(1, "e worl", 6, DATA_FLAG_NONE)); |
| 4233 const SpdyFrame* data_frames[2] = { | 4230 const SpdyFrame* data_frames[2] = { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4306 | 4303 |
| 4307 EXPECT_EQ(OK, out.rv); | 4304 EXPECT_EQ(OK, out.rv); |
| 4308 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 4305 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4309 EXPECT_EQ("goodbye world", out.response_data); | 4306 EXPECT_EQ("goodbye world", out.response_data); |
| 4310 } | 4307 } |
| 4311 | 4308 |
| 4312 // Verify that basic buffering works; when multiple data frames arrive | 4309 // Verify that basic buffering works; when multiple data frames arrive |
| 4313 // at the same time, ensure that we don't notify a read completion for | 4310 // at the same time, ensure that we don't notify a read completion for |
| 4314 // each data frame individually. | 4311 // each data frame individually. |
| 4315 TEST_P(SpdyNetworkTransactionSpdy3Test, Buffering) { | 4312 TEST_P(SpdyNetworkTransactionSpdy3Test, Buffering) { |
| 4316 BufferedSpdyFramer framer(3); | 4313 BufferedSpdyFramer framer(3, false); |
| 4317 | 4314 |
| 4318 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 4315 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 4319 MockWrite writes[] = { CreateMockWrite(*req) }; | 4316 MockWrite writes[] = { CreateMockWrite(*req) }; |
| 4320 | 4317 |
| 4321 // 4 data frames in a single read. | 4318 // 4 data frames in a single read. |
| 4322 scoped_ptr<SpdyFrame> data_frame( | 4319 scoped_ptr<SpdyFrame> data_frame( |
| 4323 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); | 4320 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 4324 scoped_ptr<SpdyFrame> data_frame_fin( | 4321 scoped_ptr<SpdyFrame> data_frame_fin( |
| 4325 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); | 4322 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); |
| 4326 const SpdyFrame* data_frames[4] = { | 4323 const SpdyFrame* data_frames[4] = { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4400 // Verify that we consumed all test data. | 4397 // Verify that we consumed all test data. |
| 4401 helper.VerifyDataConsumed(); | 4398 helper.VerifyDataConsumed(); |
| 4402 | 4399 |
| 4403 EXPECT_EQ(OK, out.rv); | 4400 EXPECT_EQ(OK, out.rv); |
| 4404 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 4401 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4405 EXPECT_EQ("messagemessagemessagemessage", out.response_data); | 4402 EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 4406 } | 4403 } |
| 4407 | 4404 |
| 4408 // Verify the case where we buffer data but read it after it has been buffered. | 4405 // Verify the case where we buffer data but read it after it has been buffered. |
| 4409 TEST_P(SpdyNetworkTransactionSpdy3Test, BufferedAll) { | 4406 TEST_P(SpdyNetworkTransactionSpdy3Test, BufferedAll) { |
| 4410 BufferedSpdyFramer framer(3); | 4407 BufferedSpdyFramer framer(3, false); |
| 4411 | 4408 |
| 4412 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 4409 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 4413 MockWrite writes[] = { CreateMockWrite(*req) }; | 4410 MockWrite writes[] = { CreateMockWrite(*req) }; |
| 4414 | 4411 |
| 4415 // 5 data frames in a single read. | 4412 // 5 data frames in a single read. |
| 4416 scoped_ptr<SpdyFrame> syn_reply( | 4413 scoped_ptr<SpdyFrame> syn_reply( |
| 4417 ConstructSpdyGetSynReply(NULL, 0, 1)); | 4414 ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4418 syn_reply->set_flags(CONTROL_FLAG_NONE); // turn off FIN bit | 4415 syn_reply->set_flags(CONTROL_FLAG_NONE); // turn off FIN bit |
| 4419 scoped_ptr<SpdyFrame> data_frame( | 4416 scoped_ptr<SpdyFrame> data_frame( |
| 4420 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); | 4417 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4491 // Verify that we consumed all test data. | 4488 // Verify that we consumed all test data. |
| 4492 helper.VerifyDataConsumed(); | 4489 helper.VerifyDataConsumed(); |
| 4493 | 4490 |
| 4494 EXPECT_EQ(OK, out.rv); | 4491 EXPECT_EQ(OK, out.rv); |
| 4495 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 4492 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4496 EXPECT_EQ("messagemessagemessagemessage", out.response_data); | 4493 EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 4497 } | 4494 } |
| 4498 | 4495 |
| 4499 // Verify the case where we buffer data and close the connection. | 4496 // Verify the case where we buffer data and close the connection. |
| 4500 TEST_P(SpdyNetworkTransactionSpdy3Test, BufferedClosed) { | 4497 TEST_P(SpdyNetworkTransactionSpdy3Test, BufferedClosed) { |
| 4501 BufferedSpdyFramer framer(3); | 4498 BufferedSpdyFramer framer(3, false); |
| 4502 | 4499 |
| 4503 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 4500 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 4504 MockWrite writes[] = { CreateMockWrite(*req) }; | 4501 MockWrite writes[] = { CreateMockWrite(*req) }; |
| 4505 | 4502 |
| 4506 // All data frames in a single read. | 4503 // All data frames in a single read. |
| 4507 // NOTE: We don't FIN the stream. | 4504 // NOTE: We don't FIN the stream. |
| 4508 scoped_ptr<SpdyFrame> data_frame( | 4505 scoped_ptr<SpdyFrame> data_frame( |
| 4509 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); | 4506 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 4510 const SpdyFrame* data_frames[4] = { | 4507 const SpdyFrame* data_frames[4] = { |
| 4511 data_frame.get(), | 4508 data_frame.get(), |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4581 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the | 4578 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
| 4582 // MockClientSocketFactory) are still alive. | 4579 // MockClientSocketFactory) are still alive. |
| 4583 MessageLoop::current()->RunUntilIdle(); | 4580 MessageLoop::current()->RunUntilIdle(); |
| 4584 | 4581 |
| 4585 // Verify that we consumed all test data. | 4582 // Verify that we consumed all test data. |
| 4586 helper.VerifyDataConsumed(); | 4583 helper.VerifyDataConsumed(); |
| 4587 } | 4584 } |
| 4588 | 4585 |
| 4589 // Verify the case where we buffer data and cancel the transaction. | 4586 // Verify the case where we buffer data and cancel the transaction. |
| 4590 TEST_P(SpdyNetworkTransactionSpdy3Test, BufferedCancelled) { | 4587 TEST_P(SpdyNetworkTransactionSpdy3Test, BufferedCancelled) { |
| 4591 BufferedSpdyFramer framer(3); | 4588 BufferedSpdyFramer framer(3, false); |
| 4592 | 4589 |
| 4593 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 4590 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 4594 MockWrite writes[] = { CreateMockWrite(*req) }; | 4591 MockWrite writes[] = { CreateMockWrite(*req) }; |
| 4595 | 4592 |
| 4596 // NOTE: We don't FIN the stream. | 4593 // NOTE: We don't FIN the stream. |
| 4597 scoped_ptr<SpdyFrame> data_frame( | 4594 scoped_ptr<SpdyFrame> data_frame( |
| 4598 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); | 4595 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 4599 | 4596 |
| 4600 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 4597 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4601 MockRead reads[] = { | 4598 MockRead reads[] = { |
| (...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6349 // And now we can allow everything else to run to completion. | 6346 // And now we can allow everything else to run to completion. |
| 6350 data.SetStop(10); | 6347 data.SetStop(10); |
| 6351 data.Run(); | 6348 data.Run(); |
| 6352 EXPECT_EQ(OK, callback2.WaitForResult()); | 6349 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 6353 EXPECT_EQ(OK, callback3.WaitForResult()); | 6350 EXPECT_EQ(OK, callback3.WaitForResult()); |
| 6354 | 6351 |
| 6355 helper.VerifyDataConsumed(); | 6352 helper.VerifyDataConsumed(); |
| 6356 } | 6353 } |
| 6357 | 6354 |
| 6358 } // namespace net | 6355 } // namespace net |
| OLD | NEW |