| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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. | |
| 4 | |
| 5 #include "net/http/failing_http_transaction_factory.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/compiler_specific.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "base/message_loop/message_loop.h" | |
| 11 #include "net/base/load_timing_info.h" | |
| 12 #include "net/base/upload_progress.h" | |
| 13 | |
| 14 namespace net { | |
| 15 | |
| 16 class AuthCredentials; | |
| 17 class BoundNetLog; | |
| 18 class HttpRequestHeaders; | |
| 19 class IOBuffer; | |
| 20 class X509Certificate; | |
| 21 | |
| 22 struct HttpRequestInfo; | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 // A simple class to interpose between the cache and network http layers. | |
| 27 // These transactions can be generated by the FailingHttpTransactionFactory | |
| 28 // to test interactions between cache and network. | |
| 29 class FailingHttpTransaction : public HttpTransaction { | |
| 30 public: | |
| 31 explicit FailingHttpTransaction(Error error); | |
| 32 ~FailingHttpTransaction() override; | |
| 33 | |
| 34 // HttpTransaction | |
| 35 int Start(const HttpRequestInfo* request_info, | |
| 36 const CompletionCallback& callback, | |
| 37 const BoundNetLog& net_log) override; | |
| 38 int RestartIgnoringLastError(const CompletionCallback& callback) override; | |
| 39 int RestartWithCertificate(X509Certificate* client_cert, | |
| 40 const CompletionCallback& callback) override; | |
| 41 int RestartWithAuth(const AuthCredentials& credentials, | |
| 42 const CompletionCallback& callback) override; | |
| 43 bool IsReadyToRestartForAuth() override; | |
| 44 int Read(IOBuffer* buf, | |
| 45 int buf_len, | |
| 46 const CompletionCallback& callback) override; | |
| 47 void StopCaching() override; | |
| 48 bool GetFullRequestHeaders(HttpRequestHeaders* headers) const override; | |
| 49 int64 GetTotalReceivedBytes() const override; | |
| 50 void DoneReading() override; | |
| 51 const HttpResponseInfo* GetResponseInfo() const override; | |
| 52 LoadState GetLoadState() const override; | |
| 53 UploadProgress GetUploadProgress() const override; | |
| 54 void SetQuicServerInfo(net::QuicServerInfo* quic_server_info) override; | |
| 55 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override; | |
| 56 void SetPriority(RequestPriority priority) override; | |
| 57 void SetWebSocketHandshakeStreamCreateHelper( | |
| 58 WebSocketHandshakeStreamBase::CreateHelper* create_helper) override; | |
| 59 void SetBeforeNetworkStartCallback( | |
| 60 const BeforeNetworkStartCallback& callback) override; | |
| 61 void SetBeforeProxyHeadersSentCallback( | |
| 62 const BeforeProxyHeadersSentCallback& callback) override; | |
| 63 int ResumeNetworkStart() override; | |
| 64 | |
| 65 private: | |
| 66 Error error_; | |
| 67 }; | |
| 68 | |
| 69 FailingHttpTransaction::FailingHttpTransaction(Error error) : error_(error) { | |
| 70 DCHECK_LT(error, OK); | |
| 71 } | |
| 72 | |
| 73 FailingHttpTransaction::~FailingHttpTransaction() {} | |
| 74 | |
| 75 int FailingHttpTransaction::Start(const HttpRequestInfo* request_info, | |
| 76 const CompletionCallback& callback, | |
| 77 const BoundNetLog& net_log) { | |
| 78 base::MessageLoop::current()->PostTask( | |
| 79 FROM_HERE, base::Bind(callback, error_)); | |
| 80 return ERR_IO_PENDING; | |
| 81 } | |
| 82 | |
| 83 int FailingHttpTransaction::RestartIgnoringLastError( | |
| 84 const CompletionCallback& callback) { | |
| 85 return ERR_FAILED; | |
| 86 } | |
| 87 | |
| 88 int FailingHttpTransaction::RestartWithCertificate( | |
| 89 X509Certificate* client_cert, | |
| 90 const CompletionCallback& callback) { | |
| 91 return ERR_FAILED; | |
| 92 } | |
| 93 | |
| 94 int FailingHttpTransaction::RestartWithAuth( | |
| 95 const AuthCredentials& credentials, | |
| 96 const CompletionCallback& callback) { | |
| 97 return ERR_FAILED; | |
| 98 } | |
| 99 | |
| 100 bool FailingHttpTransaction::IsReadyToRestartForAuth() { | |
| 101 return false; | |
| 102 } | |
| 103 | |
| 104 int FailingHttpTransaction::Read(IOBuffer* buf, int buf_len, | |
| 105 const CompletionCallback& callback) { | |
| 106 NOTREACHED(); | |
| 107 return ERR_FAILED; | |
| 108 } | |
| 109 | |
| 110 void FailingHttpTransaction::StopCaching() {} | |
| 111 | |
| 112 bool FailingHttpTransaction::GetFullRequestHeaders( | |
| 113 HttpRequestHeaders* headers) const { | |
| 114 return false; | |
| 115 } | |
| 116 | |
| 117 int64 FailingHttpTransaction::GetTotalReceivedBytes() const { | |
| 118 return 0; | |
| 119 } | |
| 120 | |
| 121 void FailingHttpTransaction::DoneReading() { | |
| 122 NOTREACHED(); | |
| 123 } | |
| 124 | |
| 125 const HttpResponseInfo* FailingHttpTransaction::GetResponseInfo() const { | |
| 126 return NULL; | |
| 127 } | |
| 128 | |
| 129 LoadState FailingHttpTransaction::GetLoadState() const { | |
| 130 return LOAD_STATE_IDLE; | |
| 131 } | |
| 132 | |
| 133 UploadProgress FailingHttpTransaction::GetUploadProgress() const { | |
| 134 return UploadProgress(); | |
| 135 } | |
| 136 | |
| 137 void FailingHttpTransaction::SetQuicServerInfo( | |
| 138 net::QuicServerInfo* quic_server_info) {} | |
| 139 | |
| 140 bool FailingHttpTransaction::GetLoadTimingInfo( | |
| 141 LoadTimingInfo* load_timing_info) const { | |
| 142 return false; | |
| 143 } | |
| 144 | |
| 145 void FailingHttpTransaction::SetPriority(RequestPriority priority) {} | |
| 146 | |
| 147 void FailingHttpTransaction::SetWebSocketHandshakeStreamCreateHelper( | |
| 148 WebSocketHandshakeStreamBase::CreateHelper* create_helper) { | |
| 149 NOTREACHED(); | |
| 150 } | |
| 151 | |
| 152 void FailingHttpTransaction::SetBeforeNetworkStartCallback( | |
| 153 const BeforeNetworkStartCallback& callback) { | |
| 154 } | |
| 155 | |
| 156 void FailingHttpTransaction::SetBeforeProxyHeadersSentCallback( | |
| 157 const BeforeProxyHeadersSentCallback& callback) { | |
| 158 } | |
| 159 | |
| 160 int FailingHttpTransaction::ResumeNetworkStart() { | |
| 161 NOTREACHED(); | |
| 162 return ERR_FAILED; | |
| 163 } | |
| 164 | |
| 165 } // namespace | |
| 166 | |
| 167 FailingHttpTransactionFactory::FailingHttpTransactionFactory( | |
| 168 HttpNetworkSession* session, | |
| 169 Error error) : session_(session), error_(error) { | |
| 170 DCHECK_LT(error, OK); | |
| 171 } | |
| 172 | |
| 173 FailingHttpTransactionFactory::~FailingHttpTransactionFactory() {} | |
| 174 | |
| 175 // HttpTransactionFactory: | |
| 176 int FailingHttpTransactionFactory::CreateTransaction( | |
| 177 RequestPriority priority, | |
| 178 scoped_ptr<HttpTransaction>* trans) { | |
| 179 trans->reset(new FailingHttpTransaction(error_)); | |
| 180 return OK; | |
| 181 } | |
| 182 | |
| 183 HttpCache* FailingHttpTransactionFactory::GetCache() { | |
| 184 return NULL; | |
| 185 } | |
| 186 | |
| 187 HttpNetworkSession* FailingHttpTransactionFactory::GetSession() { | |
| 188 return session_; | |
| 189 } | |
| 190 | |
| 191 } // namespace net | |
| 192 | |
| OLD | NEW |