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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 GURL url; | 162 GURL url; |
163 std::string result; | 163 std::string result; |
164 int line; | 164 int line; |
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)) {} |
173 } | |
174 | 173 |
175 void SetUp() override; | 174 void SetUp() override; |
176 | 175 |
177 TimeTicks now_; | 176 TimeTicks now_; |
178 MockURLRequestThrottlerManager manager_; // Dummy object, not used. | 177 MockURLRequestThrottlerManager manager_; // Dummy object, not used. |
179 scoped_refptr<MockURLRequestThrottlerEntry> entry_; | 178 scoped_refptr<MockURLRequestThrottlerEntry> entry_; |
180 | 179 |
181 TestURLRequestContext context_; | 180 TestURLRequestContext context_; |
182 scoped_ptr<URLRequest> request_; | 181 scoped_ptr<URLRequest> request_; |
183 }; | 182 }; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest(0)); | 344 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest(0)); |
346 ASSERT_TRUE(MockURLRequestThrottlerEntry::ExplicitUserRequest( | 345 ASSERT_TRUE(MockURLRequestThrottlerEntry::ExplicitUserRequest( |
347 LOAD_MAYBE_USER_GESTURE)); | 346 LOAD_MAYBE_USER_GESTURE)); |
348 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest( | 347 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest( |
349 ~LOAD_MAYBE_USER_GESTURE)); | 348 ~LOAD_MAYBE_USER_GESTURE)); |
350 } | 349 } |
351 | 350 |
352 class URLRequestThrottlerManagerTest : public testing::Test { | 351 class URLRequestThrottlerManagerTest : public testing::Test { |
353 protected: | 352 protected: |
354 URLRequestThrottlerManagerTest() | 353 URLRequestThrottlerManagerTest() |
355 : request_(context_.CreateRequest(GURL(), DEFAULT_PRIORITY, NULL, NULL)) { | 354 : request_(context_.CreateRequest(GURL(), DEFAULT_PRIORITY, NULL)) {} |
356 } | |
357 | 355 |
358 void SetUp() override { request_->SetLoadFlags(0); } | 356 void SetUp() override { request_->SetLoadFlags(0); } |
359 | 357 |
360 void ExpectEntryAllowsAllOnErrorIfOptedOut( | 358 void ExpectEntryAllowsAllOnErrorIfOptedOut( |
361 URLRequestThrottlerEntryInterface* entry, | 359 URLRequestThrottlerEntryInterface* entry, |
362 bool opted_out, | 360 bool opted_out, |
363 const URLRequest& request) { | 361 const URLRequest& request) { |
364 EXPECT_FALSE(entry->ShouldRejectRequest(request, | 362 EXPECT_FALSE(entry->ShouldRejectRequest(request, |
365 context_.network_delegate())); | 363 context_.network_delegate())); |
366 MockURLRequestThrottlerHeaderAdapter failure_adapter(503); | 364 MockURLRequestThrottlerHeaderAdapter failure_adapter(503); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 } | 517 } |
520 | 518 |
521 scoped_refptr<URLRequestThrottlerEntryInterface> entry_after = | 519 scoped_refptr<URLRequestThrottlerEntryInterface> entry_after = |
522 manager.RegisterRequestUrl(GURL("http://www.example.com/")); | 520 manager.RegisterRequestUrl(GURL("http://www.example.com/")); |
523 EXPECT_FALSE(entry_after->ShouldRejectRequest( | 521 EXPECT_FALSE(entry_after->ShouldRejectRequest( |
524 *request_, context_.network_delegate())); | 522 *request_, context_.network_delegate())); |
525 } | 523 } |
526 } | 524 } |
527 | 525 |
528 } // namespace net | 526 } // namespace net |
OLD | NEW |