Index: net/http/http_transaction_unittest.cc |
diff --git a/net/http/http_transaction_unittest.cc b/net/http/http_transaction_unittest.cc |
index 84cba0b81d867bb5b053ce87e598ecc47385653a..50fadc80f8144c444d3e61232de3cb91ce63a4d2 100644 |
--- a/net/http/http_transaction_unittest.cc |
+++ b/net/http/http_transaction_unittest.cc |
@@ -21,6 +21,83 @@ |
namespace { |
typedef base::hash_map<std::string, const MockTransaction*> MockTransactionMap; |
static MockTransactionMap mock_transactions; |
+ |
+// Utility class that delegates to another HttpTransaction. Useful to |
+// pass to classes that take ownership of the HttpTransaction. |
mmenke
2013/03/21 15:39:23
I think this comment should be much more specific.
akalin
2013/03/21 23:43:48
moot.
|
+class DelegatingTransaction : public net::HttpTransaction { |
+ public: |
+ // Assumes |delegate| will outlive this object. |
+ explicit DelegatingTransaction(net::HttpTransaction* delegate) |
mmenke
2013/03/21 15:39:23
Think this should be a MockHttpTransaction.
The u
akalin
2013/03/21 23:43:48
moot.
|
+ : delegate_(delegate) {} |
+ |
+ virtual ~DelegatingTransaction() {} |
+ |
+ // net::HttpTransaction implementation. |
+ virtual int Start(const net::HttpRequestInfo* request_info, |
+ const net::CompletionCallback& callback, |
+ const net::BoundNetLog& net_log) OVERRIDE { |
+ return delegate_->Start(request_info, callback, net_log); |
+ } |
+ |
+ virtual int RestartIgnoringLastError( |
+ const net::CompletionCallback& callback) OVERRIDE { |
+ return delegate_->RestartIgnoringLastError(callback); |
+ } |
+ |
+ virtual int RestartWithCertificate( |
+ net::X509Certificate* client_cert, |
+ const net::CompletionCallback& callback) OVERRIDE { |
+ return delegate_->RestartWithCertificate(client_cert, callback); |
+ } |
+ |
+ virtual int RestartWithAuth( |
+ const net::AuthCredentials& credentials, |
+ const net::CompletionCallback& callback) OVERRIDE { |
+ return delegate_->RestartWithAuth(credentials, callback); |
+ } |
+ |
+ virtual bool IsReadyToRestartForAuth() OVERRIDE { |
+ return delegate_->IsReadyToRestartForAuth(); |
+ } |
+ |
+ virtual int Read(net::IOBuffer* buf, int buf_len, |
+ const net::CompletionCallback& callback) OVERRIDE { |
+ return delegate_->Read(buf, buf_len, callback); |
+ } |
+ |
+ virtual void StopCaching() OVERRIDE { |
+ delegate_->StopCaching(); |
+ } |
+ |
+ virtual void DoneReading() OVERRIDE { |
+ delegate_->DoneReading(); |
+ } |
+ |
+ virtual const net::HttpResponseInfo* GetResponseInfo() const OVERRIDE { |
+ return delegate_->GetResponseInfo(); |
+ } |
+ |
+ virtual net::LoadState GetLoadState() const OVERRIDE { |
+ return delegate_->GetLoadState(); |
+ } |
+ |
+ virtual net::UploadProgress GetUploadProgress() const OVERRIDE { |
+ return delegate_->GetUploadProgress(); |
+ } |
+ |
+ virtual bool GetLoadTimingInfo( |
+ net::LoadTimingInfo* load_timing_info) const OVERRIDE { |
+ return delegate_->GetLoadTimingInfo(load_timing_info); |
+ } |
+ |
+ virtual void SetPriority(net::RequestPriority priority) OVERRIDE { |
+ return delegate_->SetPriority(priority); |
+ } |
+ |
+ private: |
+ net::HttpTransaction* const delegate_; |
+}; |
+ |
} // namespace |
//----------------------------------------------------------------------------- |
@@ -221,6 +298,7 @@ MockNetworkTransaction::MockNetworkTransaction( |
MockNetworkLayer* factory) |
: ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
data_cursor_(0), |
+ priority_(priority), |
transaction_factory_(factory->AsWeakPtr()) { |
} |
@@ -328,6 +406,10 @@ bool MockNetworkTransaction::GetLoadTimingInfo( |
return false; |
} |
+void MockNetworkTransaction::SetPriority(net::RequestPriority priority) { |
+ priority_ = priority; |
+} |
+ |
void MockNetworkTransaction::CallbackLater( |
const net::CompletionCallback& callback, int result) { |
MessageLoop::current()->PostTask( |
@@ -341,7 +423,8 @@ void MockNetworkTransaction::RunCallback( |
} |
MockNetworkLayer::MockNetworkLayer() |
- : transaction_count_(0), done_reading_called_(false) {} |
+ : transaction_count_(0), |
+ done_reading_called_(false) {} |
MockNetworkLayer::~MockNetworkLayer() {} |
@@ -354,7 +437,9 @@ int MockNetworkLayer::CreateTransaction( |
scoped_ptr<net::HttpTransaction>* trans, |
net::HttpTransactionDelegate* delegate) { |
transaction_count_++; |
- trans->reset(new MockNetworkTransaction(priority, this)); |
+ last_transaction_.reset(new MockNetworkTransaction(priority, this)); |
+ // Assume |trans| won't outlive us. |
+ trans->reset(new DelegatingTransaction(last_transaction_.get())); |
return net::OK; |
} |