| 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_URL_REQUEST_URL_REQUEST_THROTTLER_TEST_SUPPORT_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_THROTTLER_TEST_SUPPORT_H_ |
| 6 #define NET_URL_REQUEST_URL_REQUEST_THROTTLER_TEST_SUPPORT_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_THROTTLER_TEST_SUPPORT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "net/base/backoff_entry.h" | 11 #include "net/base/backoff_entry.h" |
| 12 #include "net/url_request/url_request_throttler_header_interface.h" | 12 #include "net/url_request/url_request_throttler_header_interface.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 class MockBackoffEntry : public BackoffEntry { | 16 class MockBackoffEntry : public BackoffEntry { |
| 17 public: | 17 public: |
| 18 explicit MockBackoffEntry(const BackoffEntry::Policy* const policy); | 18 explicit MockBackoffEntry(const BackoffEntry::Policy* const policy); |
| 19 virtual ~MockBackoffEntry(); | 19 virtual ~MockBackoffEntry(); |
| 20 | 20 |
| 21 // BackoffEntry overrides. | 21 // BackoffEntry overrides. |
| 22 virtual base::TimeTicks ImplGetTimeNow() const OVERRIDE; | 22 virtual base::TimeTicks ImplGetTimeNow() const override; |
| 23 | 23 |
| 24 void set_fake_now(const base::TimeTicks& now); | 24 void set_fake_now(const base::TimeTicks& now); |
| 25 | 25 |
| 26 private: | 26 private: |
| 27 base::TimeTicks fake_now_; | 27 base::TimeTicks fake_now_; |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 // Mocks the URLRequestThrottlerHeaderInterface, allowing testing code to | 30 // Mocks the URLRequestThrottlerHeaderInterface, allowing testing code to |
| 31 // pass arbitrary fake headers to the throttling code. | 31 // pass arbitrary fake headers to the throttling code. |
| 32 class MockURLRequestThrottlerHeaderAdapter | 32 class MockURLRequestThrottlerHeaderAdapter |
| 33 : public URLRequestThrottlerHeaderInterface { | 33 : public URLRequestThrottlerHeaderInterface { |
| 34 public: | 34 public: |
| 35 // Constructs mock response headers with the given |response_code| and no | 35 // Constructs mock response headers with the given |response_code| and no |
| 36 // custom response header fields. | 36 // custom response header fields. |
| 37 explicit MockURLRequestThrottlerHeaderAdapter(int response_code); | 37 explicit MockURLRequestThrottlerHeaderAdapter(int response_code); |
| 38 | 38 |
| 39 // Constructs mock response headers with the given |response_code| and | 39 // Constructs mock response headers with the given |response_code| and |
| 40 // with a custom-retry header value |retry_value| if it is non-empty, and | 40 // with a custom-retry header value |retry_value| if it is non-empty, and |
| 41 // a custom opt-out header value |opt_out_value| if it is non-empty. | 41 // a custom opt-out header value |opt_out_value| if it is non-empty. |
| 42 MockURLRequestThrottlerHeaderAdapter(const std::string& retry_value, | 42 MockURLRequestThrottlerHeaderAdapter(const std::string& retry_value, |
| 43 const std::string& opt_out_value, | 43 const std::string& opt_out_value, |
| 44 int response_code); | 44 int response_code); |
| 45 virtual ~MockURLRequestThrottlerHeaderAdapter(); | 45 virtual ~MockURLRequestThrottlerHeaderAdapter(); |
| 46 | 46 |
| 47 // URLRequestThrottlerHeaderInterface overrides. | 47 // URLRequestThrottlerHeaderInterface overrides. |
| 48 virtual std::string GetNormalizedValue(const std::string& key) const OVERRIDE; | 48 virtual std::string GetNormalizedValue(const std::string& key) const override; |
| 49 virtual int GetResponseCode() const OVERRIDE; | 49 virtual int GetResponseCode() const override; |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 std::string fake_retry_value_; | 52 std::string fake_retry_value_; |
| 53 std::string fake_opt_out_value_; | 53 std::string fake_opt_out_value_; |
| 54 int fake_response_code_; | 54 int fake_response_code_; |
| 55 | 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(MockURLRequestThrottlerHeaderAdapter); | 56 DISALLOW_COPY_AND_ASSIGN(MockURLRequestThrottlerHeaderAdapter); |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 } // namespace net | 59 } // namespace net |
| 60 | 60 |
| 61 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_TEST_SUPPORT_H_ | 61 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_TEST_SUPPORT_H_ |
| OLD | NEW |