diff options
author | erikchen@google.com <erikchen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-09 20:18:08 +0000 |
---|---|---|
committer | erikchen@google.com <erikchen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-09 20:18:08 +0000 |
commit | bdebd1b999bbbd07eb44f2f7116d4e2f3302170d (patch) | |
tree | 5ba1ca1b93608371ea932879f9189e34686dfac2 /net/spdy | |
parent | 023226b8ebaee8599c10e261dc1993638853c6f0 (diff) | |
download | chromium_src-bdebd1b999bbbd07eb44f2f7116d4e2f3302170d.zip chromium_src-bdebd1b999bbbd07eb44f2f7116d4e2f3302170d.tar.gz chromium_src-bdebd1b999bbbd07eb44f2f7116d4e2f3302170d.tar.bz2 |
Removed spdy_network_transaction.h file.
Finished migrating last unit tests to use http_network_transaction.
BUG=43330
TEST=net_unittests
Review URL: http://codereview.chromium.org/3091019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55454 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy')
-rw-r--r-- | net/spdy/spdy_network_transaction.cc | 329 | ||||
-rw-r--r-- | net/spdy/spdy_network_transaction.h | 122 | ||||
-rw-r--r-- | net/spdy/spdy_network_transaction_unittest.cc | 452 | ||||
-rw-r--r-- | net/spdy/spdy_session.cc | 1 | ||||
-rw-r--r-- | net/spdy/spdy_transaction_factory.h | 37 |
5 files changed, 231 insertions, 710 deletions
diff --git a/net/spdy/spdy_network_transaction.cc b/net/spdy/spdy_network_transaction.cc deleted file mode 100644 index cdfd216..0000000 --- a/net/spdy/spdy_network_transaction.cc +++ /dev/null @@ -1,329 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "net/spdy/spdy_network_transaction.h" - -#include <string> - -#include "base/compiler_specific.h" -#include "base/logging.h" -#include "base/scoped_ptr.h" -#include "base/stats_counters.h" -#include "net/base/host_resolver.h" -#include "net/base/io_buffer.h" -#include "net/base/load_flags.h" -#include "net/base/net_errors.h" -#include "net/base/net_log.h" -#include "net/base/net_util.h" -#include "net/base/upload_data_stream.h" -#include "net/http/http_network_session.h" -#include "net/http/http_request_info.h" -#include "net/http/http_response_info.h" -#include "net/socket/tcp_client_socket_pool.h" -#include "net/spdy/spdy_http_stream.h" - -using base::Time; - -namespace net { - -//----------------------------------------------------------------------------- - -SpdyNetworkTransaction::SpdyNetworkTransaction(HttpNetworkSession* session) - : ALLOW_THIS_IN_INITIALIZER_LIST( - io_callback_(this, &SpdyNetworkTransaction::OnIOComplete)), - user_callback_(NULL), - user_buffer_len_(0), - session_(session), - request_(NULL), - next_state_(STATE_NONE), - stream_(NULL) { -} - -SpdyNetworkTransaction::~SpdyNetworkTransaction() { - LOG(INFO) << "SpdyNetworkTransaction dead. " << this; - if (stream_.get()) - stream_->Cancel(); -} - -int SpdyNetworkTransaction::Start(const HttpRequestInfo* request_info, - CompletionCallback* callback, - const BoundNetLog& net_log) { - CHECK(request_info); - CHECK(callback); - - SIMPLE_STATS_COUNTER("SpdyNetworkTransaction.Count"); - - net_log_ = net_log; - request_ = request_info; - start_time_ = base::TimeTicks::Now(); - - next_state_ = STATE_INIT_CONNECTION; - int rv = DoLoop(OK); - if (rv == ERR_IO_PENDING) - user_callback_ = callback; - return rv; -} - -int SpdyNetworkTransaction::RestartIgnoringLastError( - CompletionCallback* callback) { - // TODO(mbelshe): implement me. - NOTIMPLEMENTED(); - return ERR_NOT_IMPLEMENTED; -} - -int SpdyNetworkTransaction::RestartWithCertificate( - X509Certificate* client_cert, CompletionCallback* callback) { - // TODO(mbelshe): implement me. - NOTIMPLEMENTED(); - return ERR_NOT_IMPLEMENTED; -} - -int SpdyNetworkTransaction::RestartWithAuth( - const string16& username, - const string16& password, - CompletionCallback* callback) { - // TODO(mbelshe): implement me. - NOTIMPLEMENTED(); - return 0; -} - -int SpdyNetworkTransaction::Read(IOBuffer* buf, int buf_len, - CompletionCallback* callback) { - DCHECK(buf); - DCHECK_GT(buf_len, 0); - DCHECK(callback); - - user_buffer_ = buf; - user_buffer_len_ = buf_len; - - next_state_ = STATE_READ_BODY; - int rv = DoLoop(OK); - if (rv == ERR_IO_PENDING) - user_callback_ = callback; - return rv; -} - -const HttpResponseInfo* SpdyNetworkTransaction::GetResponseInfo() const { - return (response_.headers || response_.ssl_info.cert) ? &response_ : NULL; -} - -LoadState SpdyNetworkTransaction::GetLoadState() const { - switch (next_state_) { - case STATE_INIT_CONNECTION_COMPLETE: - if (spdy_.get()) - return spdy_->GetLoadState(); - return LOAD_STATE_CONNECTING; - case STATE_GET_STREAM_COMPLETE: - case STATE_SEND_REQUEST_COMPLETE: - return LOAD_STATE_SENDING_REQUEST; - case STATE_READ_HEADERS_COMPLETE: - return LOAD_STATE_WAITING_FOR_RESPONSE; - case STATE_READ_BODY_COMPLETE: - return LOAD_STATE_READING_RESPONSE; - default: - return LOAD_STATE_IDLE; - } -} - -uint64 SpdyNetworkTransaction::GetUploadProgress() const { - if (!stream_.get()) - return 0; - - return stream_->GetUploadProgress(); -} - -void SpdyNetworkTransaction::DoCallback(int rv) { - CHECK_NE(rv, ERR_IO_PENDING); - CHECK(user_callback_); - - // Since Run may result in Read being called, clear user_callback_ up front. - CompletionCallback* c = user_callback_; - user_callback_ = NULL; - c->Run(rv); -} - -void SpdyNetworkTransaction::OnIOComplete(int result) { - int rv = DoLoop(result); - if (rv != ERR_IO_PENDING) - DoCallback(rv); -} - -int SpdyNetworkTransaction::DoLoop(int result) { - DCHECK(next_state_ != STATE_NONE); - DCHECK(request_); - - if (!request_) - return 0; - - int rv = result; - do { - State state = next_state_; - next_state_ = STATE_NONE; - switch (state) { - case STATE_INIT_CONNECTION: - DCHECK_EQ(OK, rv); - net_log_.BeginEvent(NetLog::TYPE_SPDY_TRANSACTION_INIT_CONNECTION, - NULL); - rv = DoInitConnection(); - break; - case STATE_INIT_CONNECTION_COMPLETE: - net_log_.EndEvent(NetLog::TYPE_SPDY_TRANSACTION_INIT_CONNECTION, NULL); - rv = DoInitConnectionComplete(rv); - break; - case STATE_GET_STREAM: - DCHECK_EQ(OK, rv); - rv = DoGetStream(); - break; - case STATE_GET_STREAM_COMPLETE: - rv = DoGetStreamComplete(rv); - case STATE_SEND_REQUEST: - DCHECK_EQ(OK, rv); - net_log_.BeginEvent(NetLog::TYPE_SPDY_TRANSACTION_SEND_REQUEST, NULL); - rv = DoSendRequest(); - break; - case STATE_SEND_REQUEST_COMPLETE: - net_log_.EndEvent(NetLog::TYPE_SPDY_TRANSACTION_SEND_REQUEST, NULL); - rv = DoSendRequestComplete(rv); - break; - case STATE_READ_HEADERS: - DCHECK_EQ(OK, rv); - net_log_.BeginEvent(NetLog::TYPE_SPDY_TRANSACTION_READ_HEADERS, NULL); - rv = DoReadHeaders(); - break; - case STATE_READ_HEADERS_COMPLETE: - net_log_.EndEvent(NetLog::TYPE_SPDY_TRANSACTION_READ_HEADERS, NULL); - rv = DoReadHeadersComplete(rv); - break; - case STATE_READ_BODY: - DCHECK_EQ(OK, rv); - net_log_.BeginEvent(NetLog::TYPE_SPDY_TRANSACTION_READ_BODY, NULL); - rv = DoReadBody(); - break; - case STATE_READ_BODY_COMPLETE: - net_log_.EndEvent(NetLog::TYPE_SPDY_TRANSACTION_READ_BODY, NULL); - rv = DoReadBodyComplete(rv); - break; - case STATE_NONE: - rv = ERR_FAILED; - break; - default: - NOTREACHED() << "bad state"; - rv = ERR_FAILED; - break; - } - } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); - - return rv; -} - -int SpdyNetworkTransaction::DoInitConnection() { - next_state_ = STATE_INIT_CONNECTION_COMPLETE; - - std::string host = request_->url.HostNoBrackets(); - int port = request_->url.EffectiveIntPort(); - - std::string connection_group = "spdy."; - HostPortPair host_port_pair(host, port); - connection_group.append(host_port_pair.ToString()); - scoped_refptr<TCPSocketParams> tcp_params = - new TCPSocketParams(host_port_pair, request_->priority, - request_->referrer, false); - - HostPortProxyPair pair(host_port_pair, ""); - spdy_ = session_->spdy_session_pool()->Get( - pair, session_, net_log_); - DCHECK(spdy_); - - return spdy_->Connect( - connection_group, tcp_params, request_->priority); -} - -int SpdyNetworkTransaction::DoInitConnectionComplete(int result) { - if (result < 0) - return result; - - next_state_ = STATE_GET_STREAM; - return OK; -} - -int SpdyNetworkTransaction::DoGetStream() { - next_state_ = STATE_GET_STREAM_COMPLETE; - - // It is possible that the spdy session was shut down while it was - // asynchronously waiting to connect. - if (spdy_->IsClosed()) - return ERR_CONNECTION_CLOSED; - - CHECK(!stream_.get()); - - stream_.reset(new SpdyHttpStream(spdy_)); - return stream_->InitializeStream(request_, net_log_, &io_callback_); -} - -int SpdyNetworkTransaction::DoGetStreamComplete(int result) { - if (result < 0) { - return result; - } - - next_state_ = STATE_SEND_REQUEST; - return OK; -} - -int SpdyNetworkTransaction::DoSendRequest() { - next_state_ = STATE_SEND_REQUEST_COMPLETE; - - UploadDataStream* upload_data_stream = NULL; - if (request_->upload_data) { - int error_code; - upload_data_stream = UploadDataStream::Create(request_->upload_data, - &error_code); - if (!upload_data_stream) - return error_code; - } - spdy_ = NULL; - - return stream_->SendRequest("", - upload_data_stream, - &response_, - &io_callback_); -} - -int SpdyNetworkTransaction::DoSendRequestComplete(int result) { - if (result < 0) { - stream_.reset(); - return result; - } - - next_state_ = STATE_READ_HEADERS; - return OK; -} - -int SpdyNetworkTransaction::DoReadHeaders() { - next_state_ = STATE_READ_HEADERS_COMPLETE; - return stream_->ReadResponseHeaders(&io_callback_); -} - -int SpdyNetworkTransaction::DoReadHeadersComplete(int result) { - // TODO(willchan): Flesh out the support for HTTP authentication here. - return result; -} - -int SpdyNetworkTransaction::DoReadBody() { - next_state_ = STATE_READ_BODY_COMPLETE; - - return stream_->ReadResponseBody( - user_buffer_, user_buffer_len_, &io_callback_); -} - -int SpdyNetworkTransaction::DoReadBodyComplete(int result) { - user_buffer_ = NULL; - user_buffer_len_ = 0; - - if (result <= 0) - stream_.reset(); - - return result; -} - -} // namespace net diff --git a/net/spdy/spdy_network_transaction.h b/net/spdy/spdy_network_transaction.h deleted file mode 100644 index 1323932..0000000 --- a/net/spdy/spdy_network_transaction.h +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef NET_SPDY_SPDY_NETWORK_TRANSACTION_H_ -#define NET_SPDY_SPDY_NETWORK_TRANSACTION_H_ -#pragma once - -#include <deque> - -#include "base/basictypes.h" -#include "base/gtest_prod_util.h" -#include "base/ref_counted.h" -#include "base/scoped_ptr.h" -#include "base/string16.h" -#include "base/time.h" -#include "net/base/completion_callback.h" -#include "net/base/load_states.h" -#include "net/base/net_log.h" -#include "net/http/http_response_info.h" -#include "net/http/http_transaction.h" -#include "net/spdy/spdy_session.h" - -namespace net { - -class SpdySession; -class SpdyHttpStream; -class HttpNetworkSession; -class HttpResponseInfo; -class IOBuffer; -class UploadDataStream; - -// A SpdyNetworkTransaction can be used to fetch HTTP conent. -// The SpdyDelegate is the consumer of events from the SpdySession. -class SpdyNetworkTransaction : public HttpTransaction { - public: - explicit SpdyNetworkTransaction(HttpNetworkSession* session); - virtual ~SpdyNetworkTransaction(); - - // HttpTransaction methods: - virtual int Start(const HttpRequestInfo* request_info, - CompletionCallback* callback, - const BoundNetLog& net_log); - virtual int RestartIgnoringLastError(CompletionCallback* callback); - virtual int RestartWithCertificate(X509Certificate* client_cert, - CompletionCallback* callback); - virtual int RestartWithAuth(const string16& username, - const string16& password, - CompletionCallback* callback); - virtual bool IsReadyToRestartForAuth() { return false; } - virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); - virtual void StopCaching() {} - virtual const HttpResponseInfo* GetResponseInfo() const; - virtual LoadState GetLoadState() const; - virtual uint64 GetUploadProgress() const; - - private: - enum State { - STATE_INIT_CONNECTION, - STATE_INIT_CONNECTION_COMPLETE, - STATE_GET_STREAM, - STATE_GET_STREAM_COMPLETE, - STATE_SEND_REQUEST, - STATE_SEND_REQUEST_COMPLETE, - STATE_READ_HEADERS, - STATE_READ_HEADERS_COMPLETE, - STATE_READ_BODY, - STATE_READ_BODY_COMPLETE, - STATE_NONE - }; - - void DoCallback(int result); - void OnIOComplete(int result); - - // Runs the state transition loop. - int DoLoop(int result); - - // Each of these methods corresponds to a State value. Those with an input - // argument receive the result from the previous state. If a method returns - // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the - // next state method as the result arg. - int DoInitConnection(); - int DoInitConnectionComplete(int result); - int DoGetStream(); - int DoGetStreamComplete(int result); - int DoSendRequest(); - int DoSendRequestComplete(int result); - int DoReadHeaders(); - int DoReadHeadersComplete(int result); - int DoReadBody(); - int DoReadBodyComplete(int result); - - BoundNetLog net_log_; - - scoped_refptr<SpdySession> spdy_; - - CompletionCallbackImpl<SpdyNetworkTransaction> io_callback_; - CompletionCallback* user_callback_; - - // Used to pass onto the SpdyStream - scoped_refptr<IOBuffer> user_buffer_; - int user_buffer_len_; - - scoped_refptr<HttpNetworkSession> session_; - - const HttpRequestInfo* request_; - HttpResponseInfo response_; - - // The time the Start method was called. - base::TimeTicks start_time_; - - // The next state in the state machine. - State next_state_; - - scoped_ptr<SpdyHttpStream> stream_; - - DISALLOW_COPY_AND_ASSIGN(SpdyNetworkTransaction); -}; - -} // namespace net - -#endif // NET_SPDY_SPDY_NETWORK_TRANSACTION_H_ diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc index 8072ce2..8ffa81d 100644 --- a/net/spdy/spdy_network_transaction_unittest.cc +++ b/net/spdy/spdy_network_transaction_unittest.cc @@ -8,7 +8,7 @@ #include "net/base/net_log_unittest.h" #include "net/http/http_transaction_unittest.h" #include "net/spdy/spdy_http_stream.h" -#include "net/spdy/spdy_network_transaction.h" +#include "net/spdy/spdy_session.h" #include "net/spdy/spdy_test_util.h" #include "net/url_request/url_request_unittest.h" #include "testing/platform_test.h" @@ -510,62 +510,61 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGets) { MockRead(true, 0, 0), // EOF }; - scoped_refptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); + scoped_refptr<OrderedSocketData> data_placeholder( + new OrderedSocketData(NULL, 0, NULL, 0)); BoundNetLog log; TransactionHelperResult out; - { - SpdySessionDependencies session_deps; - HttpNetworkSession* session = - SpdySessionDependencies::SpdyCreateSession(&session_deps); - SpdySession::SetSSLMode(false); - scoped_ptr<SpdyNetworkTransaction> trans1( - new SpdyNetworkTransaction(session)); - scoped_ptr<SpdyNetworkTransaction> trans2( - new SpdyNetworkTransaction(session)); - scoped_ptr<SpdyNetworkTransaction> trans3( - new SpdyNetworkTransaction(session)); - - session_deps.socket_factory.AddSocketDataProvider(data); - - TestCompletionCallback callback1; - TestCompletionCallback callback2; - TestCompletionCallback callback3; - - HttpRequestInfo httpreq1 = CreateGetRequest(); - HttpRequestInfo httpreq2 = CreateGetRequest(); - HttpRequestInfo httpreq3 = CreateGetRequest(); - - out.rv = trans1->Start(&httpreq1, &callback1, log); - ASSERT_EQ(ERR_IO_PENDING, out.rv); - out.rv = trans2->Start(&httpreq2, &callback2, log); - ASSERT_EQ(ERR_IO_PENDING, out.rv); - out.rv = trans3->Start(&httpreq3, &callback3, log); - ASSERT_EQ(ERR_IO_PENDING, out.rv); - - out.rv = callback1.WaitForResult(); - ASSERT_EQ(OK, out.rv); - out.rv = callback3.WaitForResult(); - ASSERT_EQ(OK, out.rv); - - const HttpResponseInfo* response1 = trans1->GetResponseInfo(); - EXPECT_TRUE(response1->headers != NULL); - EXPECT_TRUE(response1->was_fetched_via_spdy); - out.status_line = response1->headers->GetStatusLine(); - out.response_info = *response1; - - trans2->GetResponseInfo(); - - out.rv = ReadTransaction(trans1.get(), &out.response_data); - } + 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( + new HttpNetworkTransaction(helper.session())); + scoped_ptr<HttpNetworkTransaction> trans3( + new HttpNetworkTransaction(helper.session())); + + TestCompletionCallback callback1; + TestCompletionCallback callback2; + TestCompletionCallback callback3; + + HttpRequestInfo httpreq1 = CreateGetRequest(); + HttpRequestInfo httpreq2 = CreateGetRequest(); + HttpRequestInfo httpreq3 = CreateGetRequest(); + + out.rv = trans1->Start(&httpreq1, &callback1, log); + ASSERT_EQ(ERR_IO_PENDING, out.rv); + out.rv = trans2->Start(&httpreq2, &callback2, log); + ASSERT_EQ(ERR_IO_PENDING, out.rv); + out.rv = trans3->Start(&httpreq3, &callback3, log); + ASSERT_EQ(ERR_IO_PENDING, out.rv); + + out.rv = callback1.WaitForResult(); + ASSERT_EQ(OK, out.rv); + out.rv = callback3.WaitForResult(); + ASSERT_EQ(OK, out.rv); + + const HttpResponseInfo* response1 = trans1->GetResponseInfo(); + EXPECT_TRUE(response1->headers != NULL); + EXPECT_TRUE(response1->was_fetched_via_spdy); + out.status_line = response1->headers->GetStatusLine(); + out.response_info = *response1; + + trans2->GetResponseInfo(); + + out.rv = ReadTransaction(trans1.get(), &out.response_data); + helper.VerifyDataConsumed(); EXPECT_EQ(OK, out.rv); - EXPECT_TRUE(data->at_read_eof()); - EXPECT_TRUE(data->at_write_eof()); - EXPECT_EQ(OK, out.rv); EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); EXPECT_EQ("hello!hello!", out.response_data); @@ -606,14 +605,14 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { CreateMockWrite(*req3), }; MockRead reads[] = { - CreateMockRead(*settings_frame, 0), + CreateMockRead(*settings_frame, 1), CreateMockRead(*resp), CreateMockRead(*body), CreateMockRead(*fbody), - CreateMockRead(*resp2, 6), + CreateMockRead(*resp2, 7), CreateMockRead(*body2), CreateMockRead(*fbody2), - CreateMockRead(*resp3, 11), + CreateMockRead(*resp3, 12), CreateMockRead(*body3), CreateMockRead(*fbody3), @@ -623,22 +622,26 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { scoped_refptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), writes, arraysize(writes))); + scoped_refptr<OrderedSocketData> data_placeholder( + new OrderedSocketData(NULL, 0, NULL, 0)); BoundNetLog log; TransactionHelperResult out; { - SpdySessionDependencies session_deps; - HttpNetworkSession* session = - SpdySessionDependencies::SpdyCreateSession(&session_deps); - SpdySession::SetSSLMode(false); - scoped_ptr<SpdyNetworkTransaction> trans1( - new SpdyNetworkTransaction(session)); - scoped_ptr<SpdyNetworkTransaction> trans2( - new SpdyNetworkTransaction(session)); - scoped_ptr<SpdyNetworkTransaction> trans3( - new SpdyNetworkTransaction(session)); - - session_deps.socket_factory.AddSocketDataProvider(data); + 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( + new HttpNetworkTransaction(helper.session())); + scoped_ptr<HttpNetworkTransaction> trans3( + new HttpNetworkTransaction(helper.session())); TestCompletionCallback callback1; TestCompletionCallback callback2; @@ -653,6 +656,7 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { // run transaction 1 through quickly to force a read of our SETTINGS // frame out.rv = callback1.WaitForResult(); + ASSERT_EQ(OK, out.rv); out.rv = trans2->Start(&httpreq2, &callback2, log); ASSERT_EQ(out.rv, ERR_IO_PENDING); @@ -666,6 +670,7 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { ASSERT_EQ(OK, out.rv); const HttpResponseInfo* response1 = trans1->GetResponseInfo(); + ASSERT_TRUE(response1 != NULL); EXPECT_TRUE(response1->headers != NULL); EXPECT_TRUE(response1->was_fetched_via_spdy); out.status_line = response1->headers->GetStatusLine(); @@ -690,11 +695,9 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { EXPECT_EQ(OK, out.rv); EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); EXPECT_EQ("hello!hello!", out.response_data); + helper.VerifyDataConsumed(); } EXPECT_EQ(OK, out.rv); - - EXPECT_TRUE(data->at_read_eof()); - EXPECT_TRUE(data->at_write_eof()); } // Similar to ThreeGetsWithMaxConcurrent above, however this test adds @@ -734,21 +737,21 @@ TEST_P(SpdyNetworkTransactionTest, FourGetsWithMaxConcurrentPriority) { scoped_ptr<spdy::SpdyFrame> settings_frame(ConstructSpdySettings(settings)); MockWrite writes[] = { CreateMockWrite(*req), - CreateMockWrite(*req2), - CreateMockWrite(*req4), - CreateMockWrite(*req3), + CreateMockWrite(*req2), + CreateMockWrite(*req4), + CreateMockWrite(*req3), }; MockRead reads[] = { - CreateMockRead(*settings_frame, 0), + CreateMockRead(*settings_frame, 1), CreateMockRead(*resp), CreateMockRead(*body), CreateMockRead(*fbody), - CreateMockRead(*resp2, 6), + CreateMockRead(*resp2, 7), CreateMockRead(*body2), CreateMockRead(*fbody2), - CreateMockRead(*resp4, 12), + CreateMockRead(*resp4, 13), CreateMockRead(*fbody4), - CreateMockRead(*resp3, 15), + CreateMockRead(*resp3, 16), CreateMockRead(*body3), CreateMockRead(*fbody3), @@ -757,100 +760,102 @@ TEST_P(SpdyNetworkTransactionTest, FourGetsWithMaxConcurrentPriority) { scoped_refptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), - writes, arraysize(writes))); + writes, arraysize(writes))); + scoped_refptr<OrderedSocketData> data_placeholder( + new OrderedSocketData(NULL, 0, NULL, 0)); BoundNetLog log; TransactionHelperResult out; - { - SpdySessionDependencies session_deps; - HttpNetworkSession* session = - SpdySessionDependencies::SpdyCreateSession(&session_deps); - SpdySession::SetSSLMode(false); - scoped_ptr<SpdyNetworkTransaction> trans1( - new SpdyNetworkTransaction(session)); - scoped_ptr<SpdyNetworkTransaction> trans2( - new SpdyNetworkTransaction(session)); - scoped_ptr<SpdyNetworkTransaction> trans3( - new SpdyNetworkTransaction(session)); - scoped_ptr<SpdyNetworkTransaction> trans4( - new SpdyNetworkTransaction(session)); - - session_deps.socket_factory.AddSocketDataProvider(data); - - TestCompletionCallback callback1; - TestCompletionCallback callback2; - TestCompletionCallback callback3; - TestCompletionCallback callback4; - - HttpRequestInfo httpreq1 = CreateGetRequest(); - HttpRequestInfo httpreq2 = CreateGetRequest(); - HttpRequestInfo httpreq3 = CreateGetRequest(); - HttpRequestInfo httpreq4 = CreateGetRequest(); - httpreq4.priority = HIGHEST; - - out.rv = trans1->Start(&httpreq1, &callback1, log); - ASSERT_EQ(ERR_IO_PENDING, out.rv); - // run transaction 1 through quickly to force a read of our SETTINGS - // frame - out.rv = callback1.WaitForResult(); - ASSERT_EQ(OK, out.rv); - - out.rv = trans2->Start(&httpreq2, &callback2, log); - ASSERT_EQ(ERR_IO_PENDING, out.rv); - out.rv = trans3->Start(&httpreq3, &callback3, log); - ASSERT_EQ(ERR_IO_PENDING, out.rv); - out.rv = trans4->Start(&httpreq4, &callback4, log); - ASSERT_EQ(ERR_IO_PENDING, out.rv); - - out.rv = callback2.WaitForResult(); - ASSERT_EQ(OK, out.rv); - EXPECT_EQ(data->read_index(), 7U); // i.e. the third & fourth trans queued - - out.rv = callback3.WaitForResult(); - ASSERT_EQ(OK, out.rv); - - const HttpResponseInfo* response1 = trans1->GetResponseInfo(); - EXPECT_TRUE(response1->headers != NULL); - EXPECT_TRUE(response1->was_fetched_via_spdy); - out.status_line = response1->headers->GetStatusLine(); - out.response_info = *response1; - out.rv = ReadTransaction(trans1.get(), &out.response_data); - EXPECT_EQ(OK, out.rv); - EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); - EXPECT_EQ("hello!hello!", out.response_data); + NormalSpdyTransactionHelper helper(CreateGetRequest(), + BoundNetLog(), GetParam()); + helper.RunPreTestSetup(); + helper.AddData(data.get()); + // We require placeholder data because four get requests are sent out, so + // there needs to be four sets of SSL connection data. + helper.AddData(data_placeholder.get()); + helper.AddData(data_placeholder.get()); + helper.AddData(data_placeholder.get()); + scoped_ptr<HttpNetworkTransaction> trans1( + new HttpNetworkTransaction(helper.session())); + scoped_ptr<HttpNetworkTransaction> trans2( + new HttpNetworkTransaction(helper.session())); + scoped_ptr<HttpNetworkTransaction> trans3( + new HttpNetworkTransaction(helper.session())); + scoped_ptr<HttpNetworkTransaction> trans4( + new HttpNetworkTransaction(helper.session())); + + TestCompletionCallback callback1; + TestCompletionCallback callback2; + TestCompletionCallback callback3; + TestCompletionCallback callback4; + + HttpRequestInfo httpreq1 = CreateGetRequest(); + HttpRequestInfo httpreq2 = CreateGetRequest(); + HttpRequestInfo httpreq3 = CreateGetRequest(); + HttpRequestInfo httpreq4 = CreateGetRequest(); + httpreq4.priority = HIGHEST; + + out.rv = trans1->Start(&httpreq1, &callback1, log); + ASSERT_EQ(ERR_IO_PENDING, out.rv); + // run transaction 1 through quickly to force a read of our SETTINGS + // frame + out.rv = callback1.WaitForResult(); + ASSERT_EQ(OK, out.rv); + + out.rv = trans2->Start(&httpreq2, &callback2, log); + ASSERT_EQ(ERR_IO_PENDING, out.rv); + out.rv = trans3->Start(&httpreq3, &callback3, log); + ASSERT_EQ(ERR_IO_PENDING, out.rv); + out.rv = trans4->Start(&httpreq4, &callback4, log); + ASSERT_EQ(ERR_IO_PENDING, out.rv); + + out.rv = callback2.WaitForResult(); + ASSERT_EQ(OK, out.rv); + EXPECT_EQ(data->read_index(), 7U); // i.e. the third & fourth trans queued + + out.rv = callback3.WaitForResult(); + ASSERT_EQ(OK, out.rv); + + const HttpResponseInfo* response1 = trans1->GetResponseInfo(); + EXPECT_TRUE(response1->headers != NULL); + EXPECT_TRUE(response1->was_fetched_via_spdy); + out.status_line = response1->headers->GetStatusLine(); + out.response_info = *response1; + out.rv = ReadTransaction(trans1.get(), &out.response_data); + EXPECT_EQ(OK, out.rv); + EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); + EXPECT_EQ("hello!hello!", out.response_data); - const HttpResponseInfo* response2 = trans2->GetResponseInfo(); - out.status_line = response2->headers->GetStatusLine(); - out.response_info = *response2; - out.rv = ReadTransaction(trans2.get(), &out.response_data); - EXPECT_EQ(OK, out.rv); - EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); - EXPECT_EQ("hello!hello!", out.response_data); + const HttpResponseInfo* response2 = trans2->GetResponseInfo(); + out.status_line = response2->headers->GetStatusLine(); + out.response_info = *response2; + out.rv = ReadTransaction(trans2.get(), &out.response_data); + EXPECT_EQ(OK, out.rv); + EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); + EXPECT_EQ("hello!hello!", out.response_data); - // notice: response3 gets two hellos, response4 gets one - // hello, so we know dequeuing priority was respected. - const HttpResponseInfo* response3 = trans3->GetResponseInfo(); - out.status_line = response3->headers->GetStatusLine(); - out.response_info = *response3; - out.rv = ReadTransaction(trans3.get(), &out.response_data); - EXPECT_EQ(OK, out.rv); - EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); - EXPECT_EQ("hello!hello!", out.response_data); + // notice: response3 gets two hellos, response4 gets one + // hello, so we know dequeuing priority was respected. + const HttpResponseInfo* response3 = trans3->GetResponseInfo(); + out.status_line = response3->headers->GetStatusLine(); + out.response_info = *response3; + out.rv = ReadTransaction(trans3.get(), &out.response_data); + EXPECT_EQ(OK, out.rv); + EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); + EXPECT_EQ("hello!hello!", out.response_data); - out.rv = callback4.WaitForResult(); - EXPECT_EQ(OK, out.rv); - const HttpResponseInfo* response4 = trans4->GetResponseInfo(); - out.status_line = response4->headers->GetStatusLine(); - out.response_info = *response4; - out.rv = ReadTransaction(trans4.get(), &out.response_data); - EXPECT_EQ(OK, out.rv); - EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); - EXPECT_EQ("hello!", out.response_data); - } + out.rv = callback4.WaitForResult(); + EXPECT_EQ(OK, out.rv); + const HttpResponseInfo* response4 = trans4->GetResponseInfo(); + out.status_line = response4->headers->GetStatusLine(); + out.response_info = *response4; + out.rv = ReadTransaction(trans4.get(), &out.response_data); + EXPECT_EQ(OK, out.rv); + EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); + EXPECT_EQ("hello!", out.response_data); + helper.VerifyDataConsumed(); EXPECT_EQ(OK, out.rv); - EXPECT_TRUE(data->at_read_eof()); - EXPECT_TRUE(data->at_write_eof()); } // Similar to ThreeGetsMaxConcurrrent above, however, this test @@ -883,14 +888,14 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentDelete) { scoped_ptr<spdy::SpdyFrame> settings_frame(ConstructSpdySettings(settings)); MockWrite writes[] = { CreateMockWrite(*req), - CreateMockWrite(*req2), + CreateMockWrite(*req2), }; MockRead reads[] = { - CreateMockRead(*settings_frame, 0), + CreateMockRead(*settings_frame, 1), CreateMockRead(*resp), CreateMockRead(*body), CreateMockRead(*fbody), - CreateMockRead(*resp2, 6), + CreateMockRead(*resp2, 7), CreateMockRead(*body2), CreateMockRead(*fbody2), MockRead(true, 0, 0), // EOF @@ -898,71 +903,74 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentDelete) { scoped_refptr<OrderedSocketData> data( new OrderedSocketData(reads, arraysize(reads), - writes, arraysize(writes))); + writes, arraysize(writes))); + scoped_refptr<OrderedSocketData> data_placeholder( + new OrderedSocketData(NULL, 0, NULL, 0)); BoundNetLog log; TransactionHelperResult out; - { - SpdySessionDependencies session_deps; - HttpNetworkSession* session = - SpdySessionDependencies::SpdyCreateSession(&session_deps); - SpdySession::SetSSLMode(false); - scoped_ptr<SpdyNetworkTransaction> trans1( - new SpdyNetworkTransaction(session)); - scoped_ptr<SpdyNetworkTransaction> trans2( - new SpdyNetworkTransaction(session)); - scoped_ptr<SpdyNetworkTransaction> trans3( - new SpdyNetworkTransaction(session)); - - session_deps.socket_factory.AddSocketDataProvider(data); - - TestCompletionCallback callback1; - TestCompletionCallback callback2; - TestCompletionCallback callback3; - - HttpRequestInfo httpreq1 = CreateGetRequest(); - HttpRequestInfo httpreq2 = CreateGetRequest(); - HttpRequestInfo httpreq3 = CreateGetRequest(); - - out.rv = trans1->Start(&httpreq1, &callback1, log); - ASSERT_EQ(out.rv, ERR_IO_PENDING); - // run transaction 1 through quickly to force a read of our SETTINGS - // frame - out.rv = callback1.WaitForResult(); - - out.rv = trans2->Start(&httpreq2, &callback2, log); - ASSERT_EQ(out.rv, ERR_IO_PENDING); - out.rv = trans3->Start(&httpreq3, &callback3, log); - delete trans3.release(); - ASSERT_EQ(out.rv, ERR_IO_PENDING); - out.rv = callback2.WaitForResult(); - - EXPECT_EQ(8U, data->read_index()); - - const HttpResponseInfo* response1 = trans1->GetResponseInfo(); - ASSERT_TRUE(response1 != NULL); - EXPECT_TRUE(response1->headers != NULL); - EXPECT_TRUE(response1->was_fetched_via_spdy); - out.status_line = response1->headers->GetStatusLine(); - out.response_info = *response1; - out.rv = ReadTransaction(trans1.get(), &out.response_data); - EXPECT_EQ(OK, out.rv); - EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); - EXPECT_EQ("hello!hello!", out.response_data); + 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( + new HttpNetworkTransaction(helper.session())); + scoped_ptr<HttpNetworkTransaction> trans3( + new HttpNetworkTransaction(helper.session())); + + TestCompletionCallback callback1; + TestCompletionCallback callback2; + TestCompletionCallback callback3; + + HttpRequestInfo httpreq1 = CreateGetRequest(); + HttpRequestInfo httpreq2 = CreateGetRequest(); + HttpRequestInfo httpreq3 = CreateGetRequest(); + + out.rv = trans1->Start(&httpreq1, &callback1, log); + ASSERT_EQ(out.rv, ERR_IO_PENDING); + // run transaction 1 through quickly to force a read of our SETTINGS + // frame + out.rv = callback1.WaitForResult(); + ASSERT_EQ(OK, out.rv); + + out.rv = trans2->Start(&httpreq2, &callback2, log); + ASSERT_EQ(out.rv, ERR_IO_PENDING); + out.rv = trans3->Start(&httpreq3, &callback3, log); + delete trans3.release(); + ASSERT_EQ(out.rv, ERR_IO_PENDING); + out.rv = callback2.WaitForResult(); + ASSERT_EQ(OK, out.rv); + + EXPECT_EQ(8U, data->read_index()); + + const HttpResponseInfo* response1 = trans1->GetResponseInfo(); + ASSERT_TRUE(response1 != NULL); + EXPECT_TRUE(response1->headers != NULL); + EXPECT_TRUE(response1->was_fetched_via_spdy); + out.status_line = response1->headers->GetStatusLine(); + out.response_info = *response1; + out.rv = ReadTransaction(trans1.get(), &out.response_data); + EXPECT_EQ(OK, out.rv); + EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); + EXPECT_EQ("hello!hello!", out.response_data); - const HttpResponseInfo* response2 = trans2->GetResponseInfo(); - ASSERT_TRUE(response2 != NULL); - out.status_line = response2->headers->GetStatusLine(); - out.response_info = *response2; - out.rv = ReadTransaction(trans2.get(), &out.response_data); - EXPECT_EQ(OK, out.rv); - EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); - EXPECT_EQ("hello!hello!", out.response_data); - } + const HttpResponseInfo* response2 = trans2->GetResponseInfo(); + ASSERT_TRUE(response2 != NULL); + out.status_line = response2->headers->GetStatusLine(); + out.response_info = *response2; + out.rv = ReadTransaction(trans2.get(), &out.response_data); + EXPECT_EQ(OK, out.rv); + EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); + EXPECT_EQ("hello!hello!", out.response_data); + helper.VerifyDataConsumed(); EXPECT_EQ(OK, out.rv); - EXPECT_TRUE(data->at_read_eof()); - EXPECT_TRUE(data->at_write_eof()); } // Test that a simple PUT request works. diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc index 2dd2735..816cb14 100644 --- a/net/spdy/spdy_session.cc +++ b/net/spdy/spdy_session.cc @@ -850,6 +850,7 @@ void SpdySession::ActivateStream(SpdyStream* stream) { } void SpdySession::DeleteStream(spdy::SpdyStreamId id, int status) { + DLOG(INFO) << "Removing SpdyStream " << id << " from active stream list."; // Remove the stream from unclaimed_pushed_streams_ and active_streams_. PushedStreamMap::iterator it; for (it = unclaimed_pushed_streams_.begin(); diff --git a/net/spdy/spdy_transaction_factory.h b/net/spdy/spdy_transaction_factory.h deleted file mode 100644 index 5a99526..0000000 --- a/net/spdy/spdy_transaction_factory.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef NET_SPDY_SPDY_TRANSACTION_FACTORY_H__ -#define NET_SPDY_SPDY_TRANSACTION_FACTORY_H__ -#pragma once - -#include "net/http/http_transaction_factory.h" -#include "net/spdy/spdy_network_transaction.h" - -namespace net { - -class SpdyTransactionFactory : public HttpTransactionFactory { - public: - explicit SpdyTransactionFactory(HttpNetworkSession* session) - : session_(session) { - } - virtual ~SpdyTransactionFactory() {} - - // HttpTransactionFactory Interface. - virtual HttpTransaction* CreateTransaction() { - return new SpdyNetworkTransaction(session_); - } - virtual HttpCache* GetCache() { - return NULL; - } - virtual void Suspend(bool suspend) { - } - - private: - scoped_refptr<HttpNetworkSession> session_; -}; - -} // namespace net - -#endif // NET_SPDY_SPDY_TRANSACTION_FACTORY_H__ |