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

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

Issue 6932013: Fix logic for handling reports of malformed bodies. To end up counting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head Created 9 years, 7 months 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_throttler_entry.cc ('k') | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/pickle.h" 6 #include "base/pickle.h"
7 #include "base/stringprintf.h" 7 #include "base/stringprintf.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "net/base/test_completion_callback.h" 10 #include "net/base/test_completion_callback.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 } 318 }
319 319
320 TEST_F(URLRequestThrottlerEntryTest, MalformedContent) { 320 TEST_F(URLRequestThrottlerEntryTest, MalformedContent) {
321 MockURLRequestThrottlerHeaderAdapter response_adapter(505); 321 MockURLRequestThrottlerHeaderAdapter response_adapter(505);
322 for (int i = 0; i < 5; ++i) 322 for (int i = 0; i < 5; ++i)
323 entry_->UpdateWithResponse("", &response_adapter); 323 entry_->UpdateWithResponse("", &response_adapter);
324 324
325 TimeTicks release_after_failures = entry_->GetExponentialBackoffReleaseTime(); 325 TimeTicks release_after_failures = entry_->GetExponentialBackoffReleaseTime();
326 326
327 // Inform the entry that a response body was malformed, which is supposed to 327 // Inform the entry that a response body was malformed, which is supposed to
328 // increase the back-off time. 328 // increase the back-off time. Note that we also submit a successful
329 // UpdateWithResponse to pair with ReceivedContentWasMalformed() since that
330 // is what happens in practice (if a body is received, then a non-500
331 // response must also have been received).
329 entry_->ReceivedContentWasMalformed(); 332 entry_->ReceivedContentWasMalformed();
333 MockURLRequestThrottlerHeaderAdapter success_adapter(200);
334 entry_->UpdateWithResponse("", &success_adapter);
330 EXPECT_GT(entry_->GetExponentialBackoffReleaseTime(), release_after_failures); 335 EXPECT_GT(entry_->GetExponentialBackoffReleaseTime(), release_after_failures);
331 } 336 }
332 337
333 TEST_F(URLRequestThrottlerEntryTest, SlidingWindow) { 338 TEST_F(URLRequestThrottlerEntryTest, SlidingWindow) {
334 int max_send = URLRequestThrottlerEntry::kDefaultMaxSendThreshold; 339 int max_send = URLRequestThrottlerEntry::kDefaultMaxSendThreshold;
335 int sliding_window = 340 int sliding_window =
336 URLRequestThrottlerEntry::kDefaultSlidingWindowPeriodMs; 341 URLRequestThrottlerEntry::kDefaultSlidingWindowPeriodMs;
337 342
338 TimeTicks time_1 = entry_->fake_time_now_ + 343 TimeTicks time_1 = entry_->fake_time_now_ +
339 TimeDelta::FromMilliseconds(sliding_window / 3); 344 TimeDelta::FromMilliseconds(sliding_window / 3);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 no_opt_out_entry->UpdateWithResponse("www.nike.com", &wrong_adapter); 479 no_opt_out_entry->UpdateWithResponse("www.nike.com", &wrong_adapter);
475 ExpectEntryAllowsAllOnErrorIfOptedOut(no_opt_out_entry, false); 480 ExpectEntryAllowsAllOnErrorIfOptedOut(no_opt_out_entry, false);
476 481
477 // A localhost entry should always be opted out. 482 // A localhost entry should always be opted out.
478 scoped_refptr<net::URLRequestThrottlerEntryInterface> localhost_entry = 483 scoped_refptr<net::URLRequestThrottlerEntryInterface> localhost_entry =
479 manager.RegisterRequestUrl(GURL("http://localhost/hello")); 484 manager.RegisterRequestUrl(GURL("http://localhost/hello"));
480 ExpectEntryAllowsAllOnErrorIfOptedOut(localhost_entry, true); 485 ExpectEntryAllowsAllOnErrorIfOptedOut(localhost_entry, true);
481 } 486 }
482 487
483 } // namespace net 488 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_throttler_entry.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698