| 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 private: |
| 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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 FAIL(); | 541 FAIL(); |
| 540 } | 542 } |
| 541 | 543 |
| 542 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after = | 544 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after = |
| 543 manager.RegisterRequestUrl(GURL("http://www.example.com/")); | 545 manager.RegisterRequestUrl(GURL("http://www.example.com/")); |
| 544 EXPECT_FALSE(entry_after->ShouldRejectRequest(0)); | 546 EXPECT_FALSE(entry_after->ShouldRejectRequest(0)); |
| 545 } | 547 } |
| 546 } | 548 } |
| 547 | 549 |
| 548 } // namespace net | 550 } // namespace net |
| OLD | NEW |