| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ | 5 #ifndef NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ |
| 6 #define NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ | 6 #define NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "net/http/http_transaction.h" | 9 #include "net/http/http_transaction.h" |
| 10 | 10 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 std::string content_; | 140 std::string content_; |
| 141 scoped_refptr<net::IOBuffer> read_buf_; | 141 scoped_refptr<net::IOBuffer> read_buf_; |
| 142 int error_; | 142 int error_; |
| 143 | 143 |
| 144 static int quit_counter_; | 144 static int quit_counter_; |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 //----------------------------------------------------------------------------- | 147 //----------------------------------------------------------------------------- |
| 148 // mock network layer | 148 // mock network layer |
| 149 | 149 |
| 150 class MockNetworkLayer; |
| 151 |
| 150 // This transaction class inspects the available set of mock transactions to | 152 // This transaction class inspects the available set of mock transactions to |
| 151 // find data for the request URL. It supports IO operations that complete | 153 // find data for the request URL. It supports IO operations that complete |
| 152 // synchronously or asynchronously to help exercise different code paths in the | 154 // synchronously or asynchronously to help exercise different code paths in the |
| 153 // HttpCache implementation. | 155 // HttpCache implementation. |
| 154 class MockNetworkTransaction : public net::HttpTransaction { | 156 class MockNetworkTransaction : public net::HttpTransaction { |
| 155 public: | 157 public: |
| 156 MockNetworkTransaction(); | 158 explicit MockNetworkTransaction(MockNetworkLayer* factory); |
| 157 virtual ~MockNetworkTransaction(); | 159 virtual ~MockNetworkTransaction(); |
| 158 | 160 |
| 159 virtual int Start(const net::HttpRequestInfo* request, | 161 virtual int Start(const net::HttpRequestInfo* request, |
| 160 net::CompletionCallback* callback, | 162 net::CompletionCallback* callback, |
| 161 const net::BoundNetLog& net_log); | 163 const net::BoundNetLog& net_log); |
| 162 | 164 |
| 163 virtual int RestartIgnoringLastError(net::CompletionCallback* callback); | 165 virtual int RestartIgnoringLastError(net::CompletionCallback* callback); |
| 164 | 166 |
| 165 virtual int RestartWithCertificate(net::X509Certificate* client_cert, | 167 virtual int RestartWithCertificate(net::X509Certificate* client_cert, |
| 166 net::CompletionCallback* callback); | 168 net::CompletionCallback* callback); |
| 167 | 169 |
| 168 virtual int RestartWithAuth(const string16& username, | 170 virtual int RestartWithAuth(const string16& username, |
| 169 const string16& password, | 171 const string16& password, |
| 170 net::CompletionCallback* callback); | 172 net::CompletionCallback* callback); |
| 171 | 173 |
| 172 virtual bool IsReadyToRestartForAuth(); | 174 virtual bool IsReadyToRestartForAuth(); |
| 173 | 175 |
| 174 virtual int Read(net::IOBuffer* buf, int buf_len, | 176 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 175 net::CompletionCallback* callback); | 177 net::CompletionCallback* callback); |
| 176 | 178 |
| 177 virtual void StopCaching(); | 179 virtual void StopCaching(); |
| 178 | 180 |
| 181 virtual void DoneReading(); |
| 182 |
| 179 virtual const net::HttpResponseInfo* GetResponseInfo() const; | 183 virtual const net::HttpResponseInfo* GetResponseInfo() const; |
| 180 | 184 |
| 181 virtual net::LoadState GetLoadState() const; | 185 virtual net::LoadState GetLoadState() const; |
| 182 | 186 |
| 183 virtual uint64 GetUploadProgress() const; | 187 virtual uint64 GetUploadProgress() const; |
| 184 | 188 |
| 185 private: | 189 private: |
| 186 void CallbackLater(net::CompletionCallback* callback, int result); | 190 void CallbackLater(net::CompletionCallback* callback, int result); |
| 187 void RunCallback(net::CompletionCallback* callback, int result); | 191 void RunCallback(net::CompletionCallback* callback, int result); |
| 188 | 192 |
| 189 ScopedRunnableMethodFactory<MockNetworkTransaction> task_factory_; | 193 ScopedRunnableMethodFactory<MockNetworkTransaction> task_factory_; |
| 190 net::HttpResponseInfo response_; | 194 net::HttpResponseInfo response_; |
| 191 std::string data_; | 195 std::string data_; |
| 192 int data_cursor_; | 196 int data_cursor_; |
| 193 int test_mode_; | 197 int test_mode_; |
| 198 base::WeakPtr<MockNetworkLayer> transaction_factory_; |
| 194 }; | 199 }; |
| 195 | 200 |
| 196 class MockNetworkLayer : public net::HttpTransactionFactory { | 201 class MockNetworkLayer : public net::HttpTransactionFactory, |
| 202 public base::SupportsWeakPtr<MockNetworkLayer> { |
| 197 public: | 203 public: |
| 198 MockNetworkLayer(); | 204 MockNetworkLayer(); |
| 199 virtual ~MockNetworkLayer(); | 205 virtual ~MockNetworkLayer(); |
| 200 | 206 |
| 201 int transaction_count() const { return transaction_count_; } | 207 int transaction_count() const { return transaction_count_; } |
| 208 bool done_reading_called() const { return done_reading_called_; } |
| 209 void TransactionDoneReading(); |
| 202 | 210 |
| 203 // net::HttpTransactionFactory: | 211 // net::HttpTransactionFactory: |
| 204 virtual int CreateTransaction(scoped_ptr<net::HttpTransaction>* trans); | 212 virtual int CreateTransaction(scoped_ptr<net::HttpTransaction>* trans); |
| 205 virtual net::HttpCache* GetCache(); | 213 virtual net::HttpCache* GetCache(); |
| 206 virtual net::HttpNetworkSession* GetSession(); | 214 virtual net::HttpNetworkSession* GetSession(); |
| 207 | 215 |
| 208 private: | 216 private: |
| 209 int transaction_count_; | 217 int transaction_count_; |
| 218 bool done_reading_called_; |
| 210 }; | 219 }; |
| 211 | 220 |
| 212 //----------------------------------------------------------------------------- | 221 //----------------------------------------------------------------------------- |
| 213 // helpers | 222 // helpers |
| 214 | 223 |
| 215 // read the transaction completely | 224 // read the transaction completely |
| 216 int ReadTransaction(net::HttpTransaction* trans, std::string* result); | 225 int ReadTransaction(net::HttpTransaction* trans, std::string* result); |
| 217 | 226 |
| 218 #endif // NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ | 227 #endif // NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ |
| OLD | NEW |