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

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

Issue 11620007: Switch from OnIPAddressChanged and OnConnectionTypeChange to OnNetworkChanged Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 no_opt_out_entry->UpdateWithResponse("www.nike.com", &wrong_adapter); 520 no_opt_out_entry->UpdateWithResponse("www.nike.com", &wrong_adapter);
521 ExpectEntryAllowsAllOnErrorIfOptedOut(no_opt_out_entry, false, request_); 521 ExpectEntryAllowsAllOnErrorIfOptedOut(no_opt_out_entry, false, request_);
522 522
523 // A localhost entry should always be opted out. 523 // A localhost entry should always be opted out.
524 scoped_refptr<net::URLRequestThrottlerEntryInterface> localhost_entry = 524 scoped_refptr<net::URLRequestThrottlerEntryInterface> localhost_entry =
525 manager.RegisterRequestUrl(GURL("http://localhost/hello")); 525 manager.RegisterRequestUrl(GURL("http://localhost/hello"));
526 ExpectEntryAllowsAllOnErrorIfOptedOut(localhost_entry, true, request_); 526 ExpectEntryAllowsAllOnErrorIfOptedOut(localhost_entry, true, request_);
527 } 527 }
528 528
529 TEST_F(URLRequestThrottlerManagerTest, ClearOnNetworkChange) { 529 TEST_F(URLRequestThrottlerManagerTest, ClearOnNetworkChange) {
530 for (int i = 0; i < 3; ++i) { 530 MockURLRequestThrottlerManager manager;
531 MockURLRequestThrottlerManager manager; 531 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_before =
532 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_before = 532 manager.RegisterRequestUrl(GURL("http://www.example.com/"));
533 manager.RegisterRequestUrl(GURL("http://www.example.com/")); 533 MockURLRequestThrottlerHeaderAdapter failure_adapter(503);
534 MockURLRequestThrottlerHeaderAdapter failure_adapter(503); 534 for (int j = 0; j < 10; ++j) {
535 for (int j = 0; j < 10; ++j) { 535 // Host doesn't really matter in this scenario so we skip it.
536 // Host doesn't really matter in this scenario so we skip it. 536 entry_before->UpdateWithResponse("", &failure_adapter);
537 entry_before->UpdateWithResponse("", &failure_adapter); 537 }
538 } 538 EXPECT_TRUE(entry_before->ShouldRejectRequest(request_));
539 EXPECT_TRUE(entry_before->ShouldRejectRequest(request_));
540 539
541 switch (i) { 540 manager.OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_UNKNOWN);
542 case 0: 541 scoped_refptr<net::URLRequestThrottlerEntryInterface> first_entry_after =
543 manager.OnIPAddressChanged(); 542 manager.RegisterRequestUrl(GURL("http://www.example.com/"));
544 break; 543 EXPECT_TRUE(first_entry_after->ShouldRejectRequest(request_));
545 case 1:
546 manager.OnConnectionTypeChanged(
547 net::NetworkChangeNotifier::CONNECTION_UNKNOWN);
548 break;
549 case 2:
550 manager.OnConnectionTypeChanged(
551 net::NetworkChangeNotifier::CONNECTION_NONE);
552 break;
553 default:
554 FAIL();
555 }
556 544
557 scoped_refptr<net::URLRequestThrottlerEntryInterface> entry_after = 545 manager.OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_NONE);
558 manager.RegisterRequestUrl(GURL("http://www.example.com/")); 546 scoped_refptr<net::URLRequestThrottlerEntryInterface> second_entry_after =
559 EXPECT_FALSE(entry_after->ShouldRejectRequest(request_)); 547 manager.RegisterRequestUrl(GURL("http://www.example.com/"));
560 } 548 EXPECT_FALSE(second_entry_after->ShouldRejectRequest(request_));
561 } 549 }
562 550
563 } // namespace net 551 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698