| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 <algorithm> | 10 #include <algorithm> |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 97 } |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 //----------------------------------------------------------------------------- | 100 //----------------------------------------------------------------------------- |
| 101 // use this class to test completely consuming a transaction | 101 // use this class to test completely consuming a transaction |
| 102 | 102 |
| 103 class TestTransactionConsumer : public CallbackRunner< Tuple1<int> > { | 103 class TestTransactionConsumer : public CallbackRunner< Tuple1<int> > { |
| 104 public: | 104 public: |
| 105 explicit TestTransactionConsumer(net::HttpTransactionFactory* factory) | 105 explicit TestTransactionConsumer(net::HttpTransactionFactory* factory) |
| 106 : state_(IDLE), | 106 : state_(IDLE), |
| 107 trans_(factory->CreateTransaction()), | 107 trans_(NULL), |
| 108 error_(net::OK) { | 108 error_(net::OK) { |
| 109 // Disregard the error code. |
| 110 factory->CreateTransaction(&trans_); |
| 109 ++quit_counter_; | 111 ++quit_counter_; |
| 110 } | 112 } |
| 111 | 113 |
| 112 ~TestTransactionConsumer() { | 114 ~TestTransactionConsumer() { |
| 113 } | 115 } |
| 114 | 116 |
| 115 void Start(const net::HttpRequestInfo* request, net::LoadLog* load_log) { | 117 void Start(const net::HttpRequestInfo* request, net::LoadLog* load_log) { |
| 116 state_ = STARTING; | 118 state_ = STARTING; |
| 117 int result = trans_->Start(request, this, load_log); | 119 int result = trans_->Start(request, this, load_log); |
| 118 if (result != net::ERR_IO_PENDING) | 120 if (result != net::ERR_IO_PENDING) |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 std::string data_; | 305 std::string data_; |
| 304 int data_cursor_; | 306 int data_cursor_; |
| 305 int test_mode_; | 307 int test_mode_; |
| 306 }; | 308 }; |
| 307 | 309 |
| 308 class MockNetworkLayer : public net::HttpTransactionFactory { | 310 class MockNetworkLayer : public net::HttpTransactionFactory { |
| 309 public: | 311 public: |
| 310 MockNetworkLayer() : transaction_count_(0) { | 312 MockNetworkLayer() : transaction_count_(0) { |
| 311 } | 313 } |
| 312 | 314 |
| 313 virtual net::HttpTransaction* CreateTransaction() { | 315 virtual int CreateTransaction(scoped_ptr<net::HttpTransaction>* trans) { |
| 314 transaction_count_++; | 316 transaction_count_++; |
| 315 return new MockNetworkTransaction(); | 317 trans->reset(new MockNetworkTransaction()); |
| 318 return net::OK; |
| 316 } | 319 } |
| 317 | 320 |
| 318 virtual net::HttpCache* GetCache() { | 321 virtual net::HttpCache* GetCache() { |
| 319 return NULL; | 322 return NULL; |
| 320 } | 323 } |
| 321 | 324 |
| 322 virtual void Suspend(bool suspend) {} | 325 virtual void Suspend(bool suspend) {} |
| 323 | 326 |
| 324 int transaction_count() const { return transaction_count_; } | 327 int transaction_count() const { return transaction_count_; } |
| 325 | 328 |
| 326 private: | 329 private: |
| 327 int transaction_count_; | 330 int transaction_count_; |
| 328 }; | 331 }; |
| 329 | 332 |
| 330 | 333 |
| 331 //----------------------------------------------------------------------------- | 334 //----------------------------------------------------------------------------- |
| 332 // helpers | 335 // helpers |
| 333 | 336 |
| 334 // read the transaction completely | 337 // read the transaction completely |
| 335 int ReadTransaction(net::HttpTransaction* trans, std::string* result); | 338 int ReadTransaction(net::HttpTransaction* trans, std::string* result); |
| 336 | 339 |
| 337 #endif // NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ | 340 #endif // NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ |
| OLD | NEW |