OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "net/url_request/url_request_throttler_manager.h" | 5 #include "net/url_request/url_request_throttler_manager.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 const TimeTicks& fake_now) | 42 const TimeTicks& fake_now) |
43 : net::URLRequestThrottlerEntry(manager, ""), | 43 : net::URLRequestThrottlerEntry(manager, ""), |
44 fake_time_now_(fake_now), | 44 fake_time_now_(fake_now), |
45 mock_backoff_entry_(&backoff_policy_) { | 45 mock_backoff_entry_(&backoff_policy_) { |
46 InitPolicy(); | 46 InitPolicy(); |
47 | 47 |
48 mock_backoff_entry_.set_fake_now(fake_now); | 48 mock_backoff_entry_.set_fake_now(fake_now); |
49 set_exponential_backoff_release_time(exponential_backoff_release_time); | 49 set_exponential_backoff_release_time(exponential_backoff_release_time); |
50 set_sliding_window_release_time(sliding_window_release_time); | 50 set_sliding_window_release_time(sliding_window_release_time); |
51 } | 51 } |
52 virtual ~MockURLRequestThrottlerEntry() {} | |
53 | 52 |
54 void InitPolicy() { | 53 void InitPolicy() { |
55 // Some tests become flaky if we have jitter. | 54 // Some tests become flaky if we have jitter. |
56 backoff_policy_.jitter_factor = 0.0; | 55 backoff_policy_.jitter_factor = 0.0; |
57 | 56 |
58 // This lets us avoid having to make multiple failures initially (this | 57 // This lets us avoid having to make multiple failures initially (this |
59 // logic is already tested in the BackoffEntry unit tests). | 58 // logic is already tested in the BackoffEntry unit tests). |
60 backoff_policy_.num_errors_to_ignore = 0; | 59 backoff_policy_.num_errors_to_ignore = 0; |
61 } | 60 } |
62 | 61 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } | 93 } |
95 | 94 |
96 void set_sliding_window_release_time( | 95 void set_sliding_window_release_time( |
97 const base::TimeTicks& release_time) { | 96 const base::TimeTicks& release_time) { |
98 URLRequestThrottlerEntry::set_sliding_window_release_time( | 97 URLRequestThrottlerEntry::set_sliding_window_release_time( |
99 release_time); | 98 release_time); |
100 } | 99 } |
101 | 100 |
102 TimeTicks fake_time_now_; | 101 TimeTicks fake_time_now_; |
103 MockBackoffEntry mock_backoff_entry_; | 102 MockBackoffEntry mock_backoff_entry_; |
| 103 |
| 104 protected: |
| 105 virtual ~MockURLRequestThrottlerEntry() {} |
104 }; | 106 }; |
105 | 107 |
106 class MockURLRequestThrottlerManager : public URLRequestThrottlerManager { | 108 class MockURLRequestThrottlerManager : public URLRequestThrottlerManager { |
107 public: | 109 public: |
108 MockURLRequestThrottlerManager() : create_entry_index_(0) {} | 110 MockURLRequestThrottlerManager() : create_entry_index_(0) {} |
109 | 111 |
110 // Method to process the URL using URLRequestThrottlerManager protected | 112 // Method to process the URL using URLRequestThrottlerManager protected |
111 // method. | 113 // method. |
112 std::string DoGetUrlIdFromUrl(const GURL& url) { return GetIdFromUrl(url); } | 114 std::string DoGetUrlIdFromUrl(const GURL& url) { return GetIdFromUrl(url); } |
113 | 115 |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 FAIL(); | 520 FAIL(); |
519 } | 521 } |
520 | 522 |
521 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after = | 523 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after = |
522 manager.RegisterRequestUrl(GURL("http://www.example.com/")); | 524 manager.RegisterRequestUrl(GURL("http://www.example.com/")); |
523 EXPECT_FALSE(entry_after->ShouldRejectRequest(0)); | 525 EXPECT_FALSE(entry_after->ShouldRejectRequest(0)); |
524 } | 526 } |
525 } | 527 } |
526 | 528 |
527 } // namespace net | 529 } // namespace net |
OLD | NEW |