Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: net/url_request/url_request_throttler_unittest.cc

Issue 51683002: [Net] Assert that URLRequests with LOAD_IGNORE_LIMITS have MAXIMUM_PRIORITY (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/url_request/url_request_ftp_job.cc ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/metrics/histogram_samples.h" 9 #include "base/metrics/histogram_samples.h"
10 #include "base/metrics/statistics_recorder.h" 10 #include "base/metrics/statistics_recorder.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 196
197 // List of all histograms we care about in these unit tests. 197 // List of all histograms we care about in these unit tests.
198 const char* kHistogramNames[] = { 198 const char* kHistogramNames[] = {
199 "Throttling.FailureCountAtSuccess", 199 "Throttling.FailureCountAtSuccess",
200 "Throttling.PerceivedDowntime", 200 "Throttling.PerceivedDowntime",
201 "Throttling.RequestThrottled", 201 "Throttling.RequestThrottled",
202 "Throttling.SiteOptedOut", 202 "Throttling.SiteOptedOut",
203 }; 203 };
204 204
205 void URLRequestThrottlerEntryTest::SetUp() { 205 void URLRequestThrottlerEntryTest::SetUp() {
206 request_.set_load_flags(0); 206 request_.SetLoadFlags(0);
207 207
208 now_ = TimeTicks::Now(); 208 now_ = TimeTicks::Now();
209 entry_ = new MockURLRequestThrottlerEntry(&manager_); 209 entry_ = new MockURLRequestThrottlerEntry(&manager_);
210 entry_->ResetToBlank(now_); 210 entry_->ResetToBlank(now_);
211 211
212 for (size_t i = 0; i < arraysize(kHistogramNames); ++i) { 212 for (size_t i = 0; i < arraysize(kHistogramNames); ++i) {
213 // Must retrieve original samples for each histogram for comparison 213 // Must retrieve original samples for each histogram for comparison
214 // as other tests may affect them. 214 // as other tests may affect them.
215 const char* name = kHistogramNames[i]; 215 const char* name = kHistogramNames[i];
216 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); 216 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 d.set_can_throttle_requests(true); 263 d.set_can_throttle_requests(true);
264 EXPECT_TRUE(entry_->ShouldRejectRequest(request_)); 264 EXPECT_TRUE(entry_->ShouldRejectRequest(request_));
265 } 265 }
266 266
267 TEST_F(URLRequestThrottlerEntryTest, InterfaceDuringExponentialBackoff) { 267 TEST_F(URLRequestThrottlerEntryTest, InterfaceDuringExponentialBackoff) {
268 entry_->set_exponential_backoff_release_time( 268 entry_->set_exponential_backoff_release_time(
269 entry_->fake_time_now_ + TimeDelta::FromMilliseconds(1)); 269 entry_->fake_time_now_ + TimeDelta::FromMilliseconds(1));
270 EXPECT_TRUE(entry_->ShouldRejectRequest(request_)); 270 EXPECT_TRUE(entry_->ShouldRejectRequest(request_));
271 271
272 // Also end-to-end test the load flags exceptions. 272 // Also end-to-end test the load flags exceptions.
273 request_.set_load_flags(LOAD_MAYBE_USER_GESTURE); 273 request_.SetLoadFlags(LOAD_MAYBE_USER_GESTURE);
274 EXPECT_FALSE(entry_->ShouldRejectRequest(request_)); 274 EXPECT_FALSE(entry_->ShouldRejectRequest(request_));
275 275
276 CalculateHistogramDeltas(); 276 CalculateHistogramDeltas();
277 ASSERT_EQ(1, samples_["Throttling.RequestThrottled"]->GetCount(0)); 277 ASSERT_EQ(1, samples_["Throttling.RequestThrottled"]->GetCount(0));
278 ASSERT_EQ(1, samples_["Throttling.RequestThrottled"]->GetCount(1)); 278 ASSERT_EQ(1, samples_["Throttling.RequestThrottled"]->GetCount(1));
279 } 279 }
280 280
281 TEST_F(URLRequestThrottlerEntryTest, InterfaceNotDuringExponentialBackoff) { 281 TEST_F(URLRequestThrottlerEntryTest, InterfaceNotDuringExponentialBackoff) {
282 entry_->set_exponential_backoff_release_time(entry_->fake_time_now_); 282 entry_->set_exponential_backoff_release_time(entry_->fake_time_now_);
283 EXPECT_FALSE(entry_->ShouldRejectRequest(request_)); 283 EXPECT_FALSE(entry_->ShouldRejectRequest(request_));
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest( 400 ASSERT_FALSE(MockURLRequestThrottlerEntry::ExplicitUserRequest(
401 ~LOAD_MAYBE_USER_GESTURE)); 401 ~LOAD_MAYBE_USER_GESTURE));
402 } 402 }
403 403
404 class URLRequestThrottlerManagerTest : public testing::Test { 404 class URLRequestThrottlerManagerTest : public testing::Test {
405 protected: 405 protected:
406 URLRequestThrottlerManagerTest() 406 URLRequestThrottlerManagerTest()
407 : request_(GURL(), DEFAULT_PRIORITY, NULL, &context_) {} 407 : request_(GURL(), DEFAULT_PRIORITY, NULL, &context_) {}
408 408
409 virtual void SetUp() { 409 virtual void SetUp() {
410 request_.set_load_flags(0); 410 request_.SetLoadFlags(0);
411 } 411 }
412 412
413 // context_ must be declared before request_. 413 // context_ must be declared before request_.
414 TestURLRequestContext context_; 414 TestURLRequestContext context_;
415 TestURLRequest request_; 415 TestURLRequest request_;
416 }; 416 };
417 417
418 TEST_F(URLRequestThrottlerManagerTest, IsUrlStandardised) { 418 TEST_F(URLRequestThrottlerManagerTest, IsUrlStandardised) {
419 MockURLRequestThrottlerManager manager; 419 MockURLRequestThrottlerManager manager;
420 GurlAndString test_values[] = { 420 GurlAndString test_values[] = {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 FAIL(); 569 FAIL();
570 } 570 }
571 571
572 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after = 572 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after =
573 manager.RegisterRequestUrl(GURL("http://www.example.com/")); 573 manager.RegisterRequestUrl(GURL("http://www.example.com/"));
574 EXPECT_FALSE(entry_after->ShouldRejectRequest(request_)); 574 EXPECT_FALSE(entry_after->ShouldRejectRequest(request_));
575 } 575 }
576 } 576 }
577 577
578 } // namespace net 578 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_ftp_job.cc ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698