| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_TEST_UTIL_H_ | 5 #ifndef NET_HTTP_HTTP_TRANSACTION_TEST_UTIL_H_ |
| 6 #define NET_HTTP_HTTP_TRANSACTION_TEST_UTIL_H_ | 6 #define NET_HTTP_HTTP_TRANSACTION_TEST_UTIL_H_ |
| 7 | 7 |
| 8 #include "net/http/http_transaction.h" | 8 #include "net/http/http_transaction.h" |
| 9 | 9 |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| 11 | 11 |
| 12 #include <memory> |
| 12 #include <string> | 13 #include <string> |
| 14 #include <vector> |
| 13 | 15 |
| 14 #include "base/callback.h" | 16 #include "base/callback.h" |
| 15 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 16 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/run_loop.h" |
| 17 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
| 18 #include "net/base/io_buffer.h" | 21 #include "net/base/io_buffer.h" |
| 19 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
| 20 #include "net/base/net_error_details.h" | 23 #include "net/base/net_error_details.h" |
| 21 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 22 #include "net/base/request_priority.h" | 25 #include "net/base/request_priority.h" |
| 23 #include "net/base/test_completion_callback.h" | 26 #include "net/base/test_completion_callback.h" |
| 24 #include "net/disk_cache/disk_cache.h" | 27 #include "net/disk_cache/disk_cache.h" |
| 25 #include "net/http/http_cache.h" | 28 #include "net/http/http_cache.h" |
| 26 #include "net/http/http_request_info.h" | 29 #include "net/http/http_request_info.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 const CompletionCallback& callback) override; | 197 const CompletionCallback& callback) override; |
| 195 | 198 |
| 196 int RestartWithAuth(const AuthCredentials& credentials, | 199 int RestartWithAuth(const AuthCredentials& credentials, |
| 197 const CompletionCallback& callback) override; | 200 const CompletionCallback& callback) override; |
| 198 | 201 |
| 199 bool IsReadyToRestartForAuth() override; | 202 bool IsReadyToRestartForAuth() override; |
| 200 | 203 |
| 201 int Read(IOBuffer* buf, | 204 int Read(IOBuffer* buf, |
| 202 int buf_len, | 205 int buf_len, |
| 203 const CompletionCallback& callback) override; | 206 const CompletionCallback& callback) override; |
| 207 |
| 204 void PopulateNetErrorDetails(NetErrorDetails* details) const override; | 208 void PopulateNetErrorDetails(NetErrorDetails* details) const override; |
| 205 | 209 |
| 206 void StopCaching() override; | 210 void StopCaching() override; |
| 207 | 211 |
| 208 bool GetFullRequestHeaders(HttpRequestHeaders* headers) const override; | 212 bool GetFullRequestHeaders(HttpRequestHeaders* headers) const override; |
| 209 | 213 |
| 210 int64_t GetTotalReceivedBytes() const override; | 214 int64_t GetTotalReceivedBytes() const override; |
| 211 | 215 |
| 212 int64_t GetTotalSentBytes() const override; | 216 int64_t GetTotalSentBytes() const override; |
| 213 | 217 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 278 |
| 275 // NetLog ID of the fake / non-existent underlying socket used by the | 279 // NetLog ID of the fake / non-existent underlying socket used by the |
| 276 // connection. Requires Start() be passed a NetLogWithSource with a real | 280 // connection. Requires Start() be passed a NetLogWithSource with a real |
| 277 // NetLog to | 281 // NetLog to |
| 278 // be initialized. | 282 // be initialized. |
| 279 unsigned int socket_log_id_; | 283 unsigned int socket_log_id_; |
| 280 | 284 |
| 281 bool done_reading_called_; | 285 bool done_reading_called_; |
| 282 | 286 |
| 283 base::WeakPtrFactory<MockNetworkTransaction> weak_factory_; | 287 base::WeakPtrFactory<MockNetworkTransaction> weak_factory_; |
| 284 | |
| 285 }; | 288 }; |
| 286 | 289 |
| 287 class MockNetworkLayer : public HttpTransactionFactory, | 290 class MockNetworkLayer : public HttpTransactionFactory, |
| 288 public base::SupportsWeakPtr<MockNetworkLayer> { | 291 public base::SupportsWeakPtr<MockNetworkLayer> { |
| 289 public: | 292 public: |
| 290 MockNetworkLayer(); | 293 MockNetworkLayer(); |
| 291 ~MockNetworkLayer() override; | 294 ~MockNetworkLayer() override; |
| 292 | 295 |
| 293 int transaction_count() const { return transaction_count_; } | 296 int transaction_count() const { return transaction_count_; } |
| 294 bool done_reading_called() const { return done_reading_called_; } | 297 bool done_reading_called() const { return done_reading_called_; } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 bool stop_caching_called_; | 343 bool stop_caching_called_; |
| 341 RequestPriority last_create_transaction_priority_; | 344 RequestPriority last_create_transaction_priority_; |
| 342 | 345 |
| 343 // By default clock_ is NULL but it can be set to a custom clock by test | 346 // By default clock_ is NULL but it can be set to a custom clock by test |
| 344 // frameworks using SetClock. | 347 // frameworks using SetClock. |
| 345 base::Clock* clock_; | 348 base::Clock* clock_; |
| 346 | 349 |
| 347 base::WeakPtr<MockNetworkTransaction> last_transaction_; | 350 base::WeakPtr<MockNetworkTransaction> last_transaction_; |
| 348 }; | 351 }; |
| 349 | 352 |
| 353 struct Context { |
| 354 Context(); |
| 355 ~Context(); |
| 356 |
| 357 int result; |
| 358 TestCompletionCallback callback; |
| 359 std::unique_ptr<HttpTransaction> trans; |
| 360 }; |
| 361 |
| 350 //----------------------------------------------------------------------------- | 362 //----------------------------------------------------------------------------- |
| 351 // helpers | 363 // helpers |
| 352 | 364 |
| 353 // read the transaction completely | 365 // read the transaction completely |
| 354 int ReadTransaction(HttpTransaction* trans, std::string* result); | 366 int ReadTransaction(HttpTransaction* trans, std::string* result); |
| 355 | 367 |
| 356 } // namespace net | 368 } // namespace net |
| 357 | 369 |
| 358 #endif // NET_HTTP_HTTP_TRANSACTION_TEST_UTIL_H_ | 370 #endif // NET_HTTP_HTTP_TRANSACTION_TEST_UTIL_H_ |
| OLD | NEW |