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

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

Issue 15829004: Update net/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: license twerk Created 7 years, 6 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
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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 manager.RegisterRequestUrl(GURL("http://www.google.com/yodude")); 499 manager.RegisterRequestUrl(GURL("http://www.google.com/yodude"));
500 500
501 // Fake a response with the opt-out header. 501 // Fake a response with the opt-out header.
502 MockURLRequestThrottlerHeaderAdapter response_adapter( 502 MockURLRequestThrottlerHeaderAdapter response_adapter(
503 std::string(), 503 std::string(),
504 MockURLRequestThrottlerEntry::kExponentialThrottlingDisableValue, 504 MockURLRequestThrottlerEntry::kExponentialThrottlingDisableValue,
505 200); 505 200);
506 entry->UpdateWithResponse("www.google.com", &response_adapter); 506 entry->UpdateWithResponse("www.google.com", &response_adapter);
507 507
508 // Ensure that the same entry on error always allows everything. 508 // Ensure that the same entry on error always allows everything.
509 ExpectEntryAllowsAllOnErrorIfOptedOut(entry, true, request_); 509 ExpectEntryAllowsAllOnErrorIfOptedOut(entry.get(), true, request_);
510 510
511 // Ensure that a freshly created entry (for a different URL on an 511 // Ensure that a freshly created entry (for a different URL on an
512 // already opted-out host) also gets "always allow" behavior. 512 // already opted-out host) also gets "always allow" behavior.
513 scoped_refptr<net::URLRequestThrottlerEntryInterface> other_entry = 513 scoped_refptr<net::URLRequestThrottlerEntryInterface> other_entry =
514 manager.RegisterRequestUrl(GURL("http://www.google.com/bingobob")); 514 manager.RegisterRequestUrl(GURL("http://www.google.com/bingobob"));
515 ExpectEntryAllowsAllOnErrorIfOptedOut(other_entry, true, request_); 515 ExpectEntryAllowsAllOnErrorIfOptedOut(other_entry.get(), true, request_);
516 516
517 // Fake a response with the opt-out header incorrectly specified. 517 // Fake a response with the opt-out header incorrectly specified.
518 scoped_refptr<net::URLRequestThrottlerEntryInterface> no_opt_out_entry = 518 scoped_refptr<net::URLRequestThrottlerEntryInterface> no_opt_out_entry =
519 manager.RegisterRequestUrl(GURL("http://www.nike.com/justdoit")); 519 manager.RegisterRequestUrl(GURL("http://www.nike.com/justdoit"));
520 MockURLRequestThrottlerHeaderAdapter wrong_adapter( 520 MockURLRequestThrottlerHeaderAdapter wrong_adapter(
521 std::string(), "yesplease", 200); 521 std::string(), "yesplease", 200);
522 no_opt_out_entry->UpdateWithResponse("www.nike.com", &wrong_adapter); 522 no_opt_out_entry->UpdateWithResponse("www.nike.com", &wrong_adapter);
523 ExpectEntryAllowsAllOnErrorIfOptedOut(no_opt_out_entry, false, request_); 523 ExpectEntryAllowsAllOnErrorIfOptedOut(
524 no_opt_out_entry.get(), false, request_);
524 525
525 // A localhost entry should always be opted out. 526 // A localhost entry should always be opted out.
526 scoped_refptr<net::URLRequestThrottlerEntryInterface> localhost_entry = 527 scoped_refptr<net::URLRequestThrottlerEntryInterface> localhost_entry =
527 manager.RegisterRequestUrl(GURL("http://localhost/hello")); 528 manager.RegisterRequestUrl(GURL("http://localhost/hello"));
528 ExpectEntryAllowsAllOnErrorIfOptedOut(localhost_entry, true, request_); 529 ExpectEntryAllowsAllOnErrorIfOptedOut(localhost_entry.get(), true, request_);
529 } 530 }
530 531
531 TEST_F(URLRequestThrottlerManagerTest, ClearOnNetworkChange) { 532 TEST_F(URLRequestThrottlerManagerTest, ClearOnNetworkChange) {
532 for (int i = 0; i < 3; ++i) { 533 for (int i = 0; i < 3; ++i) {
533 MockURLRequestThrottlerManager manager; 534 MockURLRequestThrottlerManager manager;
534 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_before = 535 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_before =
535 manager.RegisterRequestUrl(GURL("http://www.example.com/")); 536 manager.RegisterRequestUrl(GURL("http://www.example.com/"));
536 MockURLRequestThrottlerHeaderAdapter failure_adapter(503); 537 MockURLRequestThrottlerHeaderAdapter failure_adapter(503);
537 for (int j = 0; j < 10; ++j) { 538 for (int j = 0; j < 10; ++j) {
538 // Host doesn't really matter in this scenario so we skip it. 539 // Host doesn't really matter in this scenario so we skip it.
(...skipping 17 matching lines...) Expand all
556 FAIL(); 557 FAIL();
557 } 558 }
558 559
559 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after = 560 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after =
560 manager.RegisterRequestUrl(GURL("http://www.example.com/")); 561 manager.RegisterRequestUrl(GURL("http://www.example.com/"));
561 EXPECT_FALSE(entry_after->ShouldRejectRequest(request_)); 562 EXPECT_FALSE(entry_after->ShouldRejectRequest(request_));
562 } 563 }
563 } 564 }
564 565
565 } // namespace net 566 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_throttler_manager.cc ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698