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_samples.h" | 8 #include "base/metrics/histogram_samples.h" |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 }; | 165 }; |
166 | 166 |
167 } // namespace | 167 } // namespace |
168 | 168 |
169 class URLRequestThrottlerEntryTest : public testing::Test { | 169 class URLRequestThrottlerEntryTest : public testing::Test { |
170 protected: | 170 protected: |
171 URLRequestThrottlerEntryTest() | 171 URLRequestThrottlerEntryTest() |
172 : request_(context_.CreateRequest(GURL(), DEFAULT_PRIORITY, NULL, NULL)) { | 172 : request_(context_.CreateRequest(GURL(), DEFAULT_PRIORITY, NULL, NULL)) { |
173 } | 173 } |
174 | 174 |
175 virtual void SetUp(); | 175 void SetUp() override; |
176 | 176 |
177 TimeTicks now_; | 177 TimeTicks now_; |
178 MockURLRequestThrottlerManager manager_; // Dummy object, not used. | 178 MockURLRequestThrottlerManager manager_; // Dummy object, not used. |
179 scoped_refptr<MockURLRequestThrottlerEntry> entry_; | 179 scoped_refptr<MockURLRequestThrottlerEntry> entry_; |
180 | 180 |
181 TestURLRequestContext context_; | 181 TestURLRequestContext context_; |
182 scoped_ptr<URLRequest> request_; | 182 scoped_ptr<URLRequest> request_; |
183 }; | 183 }; |
184 | 184 |
185 void URLRequestThrottlerEntryTest::SetUp() { | 185 void URLRequestThrottlerEntryTest::SetUp() { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest( | 348 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest( |
349 ~LOAD_MAYBE_USER_GESTURE)); | 349 ~LOAD_MAYBE_USER_GESTURE)); |
350 } | 350 } |
351 | 351 |
352 class URLRequestThrottlerManagerTest : public testing::Test { | 352 class URLRequestThrottlerManagerTest : public testing::Test { |
353 protected: | 353 protected: |
354 URLRequestThrottlerManagerTest() | 354 URLRequestThrottlerManagerTest() |
355 : request_(context_.CreateRequest(GURL(), DEFAULT_PRIORITY, NULL, NULL)) { | 355 : request_(context_.CreateRequest(GURL(), DEFAULT_PRIORITY, NULL, NULL)) { |
356 } | 356 } |
357 | 357 |
358 virtual void SetUp() { | 358 void SetUp() override { request_->SetLoadFlags(0); } |
359 request_->SetLoadFlags(0); | |
360 } | |
361 | 359 |
362 void ExpectEntryAllowsAllOnErrorIfOptedOut( | 360 void ExpectEntryAllowsAllOnErrorIfOptedOut( |
363 URLRequestThrottlerEntryInterface* entry, | 361 URLRequestThrottlerEntryInterface* entry, |
364 bool opted_out, | 362 bool opted_out, |
365 const URLRequest& request) { | 363 const URLRequest& request) { |
366 EXPECT_FALSE(entry->ShouldRejectRequest(request, | 364 EXPECT_FALSE(entry->ShouldRejectRequest(request, |
367 context_.network_delegate())); | 365 context_.network_delegate())); |
368 MockURLRequestThrottlerHeaderAdapter failure_adapter(503); | 366 MockURLRequestThrottlerHeaderAdapter failure_adapter(503); |
369 for (int i = 0; i < 10; ++i) { | 367 for (int i = 0; i < 10; ++i) { |
370 // Host doesn't really matter in this scenario so we skip it. | 368 // Host doesn't really matter in this scenario so we skip it. |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 } | 519 } |
522 | 520 |
523 scoped_refptr<URLRequestThrottlerEntryInterface> entry_after = | 521 scoped_refptr<URLRequestThrottlerEntryInterface> entry_after = |
524 manager.RegisterRequestUrl(GURL("http://www.example.com/")); | 522 manager.RegisterRequestUrl(GURL("http://www.example.com/")); |
525 EXPECT_FALSE(entry_after->ShouldRejectRequest( | 523 EXPECT_FALSE(entry_after->ShouldRejectRequest( |
526 *request_, context_.network_delegate())); | 524 *request_, context_.network_delegate())); |
527 } | 525 } |
528 } | 526 } |
529 | 527 |
530 } // namespace net | 528 } // namespace net |
OLD | NEW |