| 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" |
| 11 #include "base/time/tick_clock.h" |
| 10 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 11 #include "net/base/backoff_entry.h" | 13 #include "net/base/backoff_entry.h" |
| 12 #include "net/url_request/url_request_throttler_header_interface.h" | 14 #include "net/url_request/url_request_throttler_header_interface.h" |
| 13 | 15 |
| 14 namespace net { | 16 namespace net { |
| 15 | 17 |
| 16 class MockBackoffEntry : public BackoffEntry { | 18 class TestTickClock : public base::TickClock { |
| 17 public: | 19 public: |
| 18 explicit MockBackoffEntry(const BackoffEntry::Policy* const policy); | 20 TestTickClock(); |
| 19 ~MockBackoffEntry() override; | 21 explicit TestTickClock(base::TimeTicks now); |
| 22 ~TestTickClock() override; |
| 20 | 23 |
| 21 // BackoffEntry overrides. | 24 base::TimeTicks NowTicks() override; |
| 22 base::TimeTicks ImplGetTimeNow() const override; | 25 void set_now(base::TimeTicks now) { now_ticks_ = now; } |
| 23 | |
| 24 void set_fake_now(const base::TimeTicks& now); | |
| 25 | 26 |
| 26 private: | 27 private: |
| 27 base::TimeTicks fake_now_; | 28 base::TimeTicks now_ticks_; |
| 29 DISALLOW_COPY_AND_ASSIGN(TestTickClock); |
| 28 }; | 30 }; |
| 29 | 31 |
| 30 // Mocks the URLRequestThrottlerHeaderInterface, allowing testing code to | 32 // Mocks the URLRequestThrottlerHeaderInterface, allowing testing code to |
| 31 // pass arbitrary fake headers to the throttling code. | 33 // pass arbitrary fake headers to the throttling code. |
| 32 class MockURLRequestThrottlerHeaderAdapter | 34 class MockURLRequestThrottlerHeaderAdapter |
| 33 : public URLRequestThrottlerHeaderInterface { | 35 : public URLRequestThrottlerHeaderInterface { |
| 34 public: | 36 public: |
| 35 // Constructs mock response headers with the given |response_code| and no | 37 // Constructs mock response headers with the given |response_code| and no |
| 36 // custom response header fields. | 38 // custom response header fields. |
| 37 explicit MockURLRequestThrottlerHeaderAdapter(int response_code); | 39 explicit MockURLRequestThrottlerHeaderAdapter(int response_code); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 52 std::string fake_retry_value_; | 54 std::string fake_retry_value_; |
| 53 std::string fake_opt_out_value_; | 55 std::string fake_opt_out_value_; |
| 54 int fake_response_code_; | 56 int fake_response_code_; |
| 55 | 57 |
| 56 DISALLOW_COPY_AND_ASSIGN(MockURLRequestThrottlerHeaderAdapter); | 58 DISALLOW_COPY_AND_ASSIGN(MockURLRequestThrottlerHeaderAdapter); |
| 57 }; | 59 }; |
| 58 | 60 |
| 59 } // namespace net | 61 } // namespace net |
| 60 | 62 |
| 61 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_TEST_SUPPORT_H_ | 63 #endif // NET_URL_REQUEST_URL_REQUEST_THROTTLER_TEST_SUPPORT_H_ |
| OLD | NEW |