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