OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
8 #include "net/http/http_transaction.h" | 8 #include "net/http/http_transaction.h" |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 182 |
183 virtual const net::HttpResponseInfo* GetResponseInfo() const OVERRIDE; | 183 virtual const net::HttpResponseInfo* GetResponseInfo() const OVERRIDE; |
184 | 184 |
185 virtual net::LoadState GetLoadState() const OVERRIDE; | 185 virtual net::LoadState GetLoadState() const OVERRIDE; |
186 | 186 |
187 virtual net::UploadProgress GetUploadProgress() const OVERRIDE; | 187 virtual net::UploadProgress GetUploadProgress() const OVERRIDE; |
188 | 188 |
189 virtual bool GetLoadTimingInfo( | 189 virtual bool GetLoadTimingInfo( |
190 net::LoadTimingInfo* load_timing_info) const OVERRIDE; | 190 net::LoadTimingInfo* load_timing_info) const OVERRIDE; |
191 | 191 |
| 192 virtual void SetPriority(net::RequestPriority priority) OVERRIDE; |
| 193 |
| 194 net::RequestPriority priority() const { return priority_; } |
| 195 |
192 private: | 196 private: |
193 void CallbackLater(const net::CompletionCallback& callback, int result); | 197 void CallbackLater(const net::CompletionCallback& callback, int result); |
194 void RunCallback(const net::CompletionCallback& callback, int result); | 198 void RunCallback(const net::CompletionCallback& callback, int result); |
195 | 199 |
196 base::WeakPtrFactory<MockNetworkTransaction> weak_factory_; | 200 base::WeakPtrFactory<MockNetworkTransaction> weak_factory_; |
197 net::HttpResponseInfo response_; | 201 net::HttpResponseInfo response_; |
198 std::string data_; | 202 std::string data_; |
199 int data_cursor_; | 203 int data_cursor_; |
200 int test_mode_; | 204 int test_mode_; |
| 205 net::RequestPriority priority_; |
201 base::WeakPtr<MockNetworkLayer> transaction_factory_; | 206 base::WeakPtr<MockNetworkLayer> transaction_factory_; |
202 }; | 207 }; |
203 | 208 |
204 class MockNetworkLayer : public net::HttpTransactionFactory, | 209 class MockNetworkLayer : public net::HttpTransactionFactory, |
205 public base::SupportsWeakPtr<MockNetworkLayer> { | 210 public base::SupportsWeakPtr<MockNetworkLayer> { |
206 public: | 211 public: |
207 MockNetworkLayer(); | 212 MockNetworkLayer(); |
208 virtual ~MockNetworkLayer(); | 213 virtual ~MockNetworkLayer(); |
209 | 214 |
210 int transaction_count() const { return transaction_count_; } | 215 int transaction_count() const { return transaction_count_; } |
211 bool done_reading_called() const { return done_reading_called_; } | 216 bool done_reading_called() const { return done_reading_called_; } |
212 void TransactionDoneReading(); | 217 void TransactionDoneReading(); |
213 | 218 |
| 219 // Returns the last transaction created by CreateTransaction, or |
| 220 // NULL if one has not been created yet. It is the caller's |
| 221 // responsibility to make sure that that transaction is still valid. |
| 222 MockNetworkTransaction* last_transaction() { |
| 223 return last_transaction_; |
| 224 } |
| 225 |
| 226 // Makes last_transaction() return NULL until the next transaction |
| 227 // is created. |
| 228 void ClearLastTransaction() { |
| 229 last_transaction_ = NULL; |
| 230 } |
| 231 |
214 // net::HttpTransactionFactory: | 232 // net::HttpTransactionFactory: |
215 virtual int CreateTransaction( | 233 virtual int CreateTransaction( |
216 scoped_ptr<net::HttpTransaction>* trans, | 234 scoped_ptr<net::HttpTransaction>* trans, |
217 net::HttpTransactionDelegate* delegate) OVERRIDE; | 235 net::HttpTransactionDelegate* delegate) OVERRIDE; |
218 virtual net::HttpCache* GetCache() OVERRIDE; | 236 virtual net::HttpCache* GetCache() OVERRIDE; |
219 virtual net::HttpNetworkSession* GetSession() OVERRIDE; | 237 virtual net::HttpNetworkSession* GetSession() OVERRIDE; |
220 | 238 |
221 private: | 239 private: |
222 int transaction_count_; | 240 int transaction_count_; |
223 bool done_reading_called_; | 241 bool done_reading_called_; |
| 242 MockNetworkTransaction* last_transaction_; |
224 }; | 243 }; |
225 | 244 |
226 //----------------------------------------------------------------------------- | 245 //----------------------------------------------------------------------------- |
227 // helpers | 246 // helpers |
228 | 247 |
229 // read the transaction completely | 248 // read the transaction completely |
230 int ReadTransaction(net::HttpTransaction* trans, std::string* result); | 249 int ReadTransaction(net::HttpTransaction* trans, std::string* result); |
231 | 250 |
232 #endif // NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ | 251 #endif // NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ |
OLD | NEW |