diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-12 01:39:55 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-12 01:39:55 +0000 |
commit | 2d67286973ae47301854b37eb1f142ac25d5e132 (patch) | |
tree | 468c5dfd91b57d6192cf87c34bc197ea415eca2c /net/spdy | |
parent | c942d18826443fe7ebdde476265ab0cf026d7527 (diff) | |
download | chromium_src-2d67286973ae47301854b37eb1f142ac25d5e132.zip chromium_src-2d67286973ae47301854b37eb1f142ac25d5e132.tar.gz chromium_src-2d67286973ae47301854b37eb1f142ac25d5e132.tar.bz2 |
Reland rest of r77399.
I had temporarily reverted it so I could break it up into 2 commits, so the first could be merged to 696. This is part 2.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6684019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77908 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy')
-rw-r--r-- | net/spdy/spdy_network_transaction_unittest.cc | 148 |
1 files changed, 57 insertions, 91 deletions
diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc index acfb7ea..9f4e1fe 100644 --- a/net/spdy/spdy_network_transaction_unittest.cc +++ b/net/spdy/spdy_network_transaction_unittest.cc @@ -11,6 +11,7 @@ #include "net/base/net_log_unittest.h" #include "net/http/http_network_session_peer.h" #include "net/http/http_transaction_unittest.h" +#include "net/socket/client_socket_pool_base.h" #include "net/spdy/spdy_http_stream.h" #include "net/spdy/spdy_http_utils.h" #include "net/spdy/spdy_session.h" @@ -35,17 +36,25 @@ enum SpdyNetworkTransactionTestTypes { class SpdyNetworkTransactionTest : public ::testing::TestWithParam<SpdyNetworkTransactionTestTypes> { protected: + virtual void SetUp() { // By default, all tests turn off compression. EnableCompression(false); google_get_request_initialized_ = false; google_post_request_initialized_ = false; google_chunked_post_request_initialized_ = false; + + backup_jobs_prev_value_ = + internal::ClientSocketPoolBaseHelper::connect_backup_jobs_enabled(); + internal::ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled( + false); } virtual void TearDown() { // Empty the current queue. MessageLoop::current()->RunAllPending(); + internal::ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled( + backup_jobs_prev_value_); } struct TransactionHelperResult { @@ -167,10 +176,8 @@ class SpdyNetworkTransactionTest EXPECT_EQ(spdy_enabled_, response->was_fetched_via_spdy); if (test_type_ == SPDYNPN && spdy_enabled_) { EXPECT_TRUE(response->was_npn_negotiated); - EXPECT_TRUE(response->was_alternate_protocol_available); } else { EXPECT_TRUE(!response->was_npn_negotiated); - EXPECT_TRUE(!response->was_alternate_protocol_available); } // If SPDY is not enabled, a HTTP request should not be diverted // over a SSL session. @@ -237,9 +244,20 @@ class SpdyNetworkTransactionTest ssl_->was_npn_negotiated = true; } ssl_vector_.push_back(ssl_); - if(test_type_ == SPDYNPN || test_type_ == SPDYSSL) + if (test_type_ == SPDYNPN || test_type_ == SPDYSSL) session_deps_->socket_factory->AddSSLSocketDataProvider(ssl_.get()); session_deps_->socket_factory->AddSocketDataProvider(data); + if (test_type_ == SPDYNPN) { + MockConnect never_finishing_connect(false, ERR_IO_PENDING); + linked_ptr<StaticSocketDataProvider> + hanging_non_alternate_protocol_socket( + new StaticSocketDataProvider(NULL, 0, NULL, 0)); + hanging_non_alternate_protocol_socket->set_connect_data( + never_finishing_connect); + session_deps_->socket_factory->AddSocketDataProvider( + hanging_non_alternate_protocol_socket.get()); + alternate_vector_.push_back(hanging_non_alternate_protocol_socket); + } } void AddDeterministicData(DeterministicSocketData* data) { @@ -253,10 +271,23 @@ class SpdyNetworkTransactionTest ssl_->was_npn_negotiated = true; } ssl_vector_.push_back(ssl_); - if(test_type_ == SPDYNPN || test_type_ == SPDYSSL) + if (test_type_ == SPDYNPN || test_type_ == SPDYSSL) { session_deps_->deterministic_socket_factory-> AddSSLSocketDataProvider(ssl_.get()); + } session_deps_->deterministic_socket_factory->AddSocketDataProvider(data); + if (test_type_ == SPDYNPN) { + MockConnect never_finishing_connect(false, ERR_IO_PENDING); + scoped_refptr<DeterministicSocketData> + hanging_non_alternate_protocol_socket( + new DeterministicSocketData(NULL, 0, NULL, 0)); + hanging_non_alternate_protocol_socket->set_connect_data( + never_finishing_connect); + session_deps_->deterministic_socket_factory->AddSocketDataProvider( + hanging_non_alternate_protocol_socket); + alternate_deterministic_vector_.push_back( + hanging_non_alternate_protocol_socket); + } } // This can only be called after RunPreTestSetup. It adds a Data Provider, @@ -289,6 +320,9 @@ class SpdyNetworkTransactionTest private: typedef std::vector<StaticSocketDataProvider*> DataVector; typedef std::vector<linked_ptr<SSLSocketDataProvider> > SSLVector; + typedef std::vector<linked_ptr<StaticSocketDataProvider> > AlternateVector; + typedef std::vector<scoped_refptr<DeterministicSocketData> > + AlternateDeterministicVector; HttpRequestInfo request_; scoped_ptr<SpdySessionDependencies> session_deps_; scoped_refptr<HttpNetworkSession> session_; @@ -299,6 +333,8 @@ class SpdyNetworkTransactionTest scoped_ptr<HttpNetworkTransaction> trans_; scoped_ptr<HttpNetworkTransaction> trans_http_; DataVector data_vector_; + AlternateVector alternate_vector_; + AlternateDeterministicVector alternate_deterministic_vector_; const BoundNetLog& log_; SpdyNetworkTransactionTestTypes test_type_; int port_; @@ -475,6 +511,8 @@ class SpdyNetworkTransactionTest HttpRequestInfo google_post_request_; HttpRequestInfo google_chunked_post_request_; HttpRequestInfo google_get_push_request_; + + bool backup_jobs_prev_value_; }; //----------------------------------------------------------------------------- @@ -704,7 +742,7 @@ TEST_P(SpdyNetworkTransactionTest, TwoGetsLateBinding) { new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); - MockConnect never_finishing_connect(true, ERR_IO_PENDING); + MockConnect never_finishing_connect(false, ERR_IO_PENDING); scoped_refptr<OrderedSocketData> data_placeholder( new OrderedSocketData(NULL, 0, NULL, 0)); @@ -893,10 +931,12 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { settings.push_back(spdy::SpdySetting(id, max_concurrent_streams)); scoped_ptr<spdy::SpdyFrame> settings_frame(ConstructSpdySettings(settings)); - MockWrite writes[] = { CreateMockWrite(*req), - CreateMockWrite(*req2), - CreateMockWrite(*req3), + MockWrite writes[] = { + CreateMockWrite(*req), + CreateMockWrite(*req2), + CreateMockWrite(*req3), }; + MockRead reads[] = { CreateMockRead(*settings_frame, 1), CreateMockRead(*resp), @@ -921,14 +961,14 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { BoundNetLog log; TransactionHelperResult out; { - NormalSpdyTransactionHelper helper(CreateGetRequest(), - BoundNetLog(), GetParam()); - helper.RunPreTestSetup(); - helper.AddData(data.get()); - // We require placeholder data because three get requests are sent out, so - // there needs to be three sets of SSL connection data. - helper.AddData(data_placeholder.get()); - helper.AddData(data_placeholder.get()); + NormalSpdyTransactionHelper helper(CreateGetRequest(), + BoundNetLog(), GetParam()); + helper.RunPreTestSetup(); + helper.AddData(data.get()); + // We require placeholder data because three get requests are sent out, so + // there needs to be three sets of SSL connection data. + helper.AddData(data_placeholder.get()); + helper.AddData(data_placeholder.get()); scoped_ptr<HttpNetworkTransaction> trans1( new HttpNetworkTransaction(helper.session())); scoped_ptr<HttpNetworkTransaction> trans2( @@ -1716,7 +1756,7 @@ TEST_P(SpdyNetworkTransactionTest, SocketWriteReturnsZero) { scoped_refptr<DeterministicSocketData> data( new DeterministicSocketData(reads, arraysize(reads), - writes, arraysize(writes))); + writes, arraysize(writes))); NormalSpdyTransactionHelper helper(CreateGetRequest(), BoundNetLog(), GetParam()); helper.SetDeterministic(); @@ -3807,80 +3847,6 @@ TEST_P(SpdyNetworkTransactionTest, BufferFull) { EXPECT_EQ("goodbye world", out.response_data); } -TEST_P(SpdyNetworkTransactionTest, ConnectFailureFallbackToHttp) { - MockConnect connects[] = { - MockConnect(true, ERR_NAME_NOT_RESOLVED), - MockConnect(false, ERR_NAME_NOT_RESOLVED), - MockConnect(true, ERR_INTERNET_DISCONNECTED), - MockConnect(false, ERR_INTERNET_DISCONNECTED) - }; - - for (size_t index = 0; index < arraysize(connects); ++index) { - scoped_ptr<spdy::SpdyFrame> req( - ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); - MockWrite writes[] = { - CreateMockWrite(*req), - MockWrite(true, 0, 0) // EOF - }; - - scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); - scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); - MockRead reads[] = { - CreateMockRead(*resp), - CreateMockRead(*body), - MockRead(true, 0, 0) // EOF - }; - - scoped_refptr<DelayedSocketData> data( - new DelayedSocketData(connects[index], 1, reads, arraysize(reads), - writes, arraysize(writes))); - NormalSpdyTransactionHelper helper(CreateGetRequest(), - BoundNetLog(), GetParam()); - helper.RunPreTestSetup(); - helper.AddData(data.get()); - - // Set up http fallback data. - MockRead http_fallback_data[] = { - MockRead("HTTP/1.1 200 OK\r\n\r\n"), - MockRead("hello world!!!"), - MockRead(true, OK), - }; - - scoped_ptr<StaticSocketDataProvider> http_fallback( - new StaticSocketDataProvider(http_fallback_data, - arraysize(http_fallback_data), - NULL, 0)); - helper.AddDataNoSSL(http_fallback.get()); - HttpNetworkTransaction* trans = helper.trans(); - TestCompletionCallback callback; - - int rv = trans->Start(&helper.request(), &callback, BoundNetLog()); - EXPECT_EQ(rv, ERR_IO_PENDING); - rv = callback.WaitForResult(); - const HttpResponseInfo* response = trans->GetResponseInfo(); - if (GetParam() == SPDYNOSSL || GetParam() == SPDYSSL) { - ASSERT_TRUE(response == NULL); - return; - } - if (GetParam() != SPDYNPN) - NOTREACHED(); - ASSERT_TRUE(response != NULL); - ASSERT_TRUE(response->headers != NULL); - EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); - std::string response_data; - rv = ReadTransaction(trans, &response_data); - EXPECT_EQ(OK, rv); - - EXPECT_TRUE(!response->was_fetched_via_spdy); - EXPECT_TRUE(!response->was_npn_negotiated); - EXPECT_TRUE(response->was_alternate_protocol_available); - EXPECT_TRUE(http_fallback->at_read_eof()); - EXPECT_EQ(0u, data->read_index()); - EXPECT_EQ(0u, data->write_index()); - EXPECT_EQ("hello world!!!", response_data); - } -} - // Verify that basic buffering works; when multiple data frames arrive // at the same time, ensure that we don't notify a read completion for // each data frame individually. |