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

Side by Side Diff: chrome/common/net/url_fetcher_unittest.cc

Issue 6696023: Remove minidump analysis aides from URLRequestThrottlerManager. New (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 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 | « no previous file | chrome/service/cloud_print/cloud_print_url_fetcher_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) 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/message_loop_proxy.h" 5 #include "base/message_loop_proxy.h"
6 #include "base/synchronization/waitable_event.h" 6 #include "base/synchronization/waitable_event.h"
7 #include "base/threading/thread.h" 7 #include "base/threading/thread.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "chrome/common/chrome_plugin_lib.h" 9 #include "chrome/common/chrome_plugin_lib.h"
10 #include "chrome/common/net/url_fetcher.h" 10 #include "chrome/common/net/url_fetcher.h"
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 573
574 TEST_F(URLFetcherProtectTest, Overload) { 574 TEST_F(URLFetcherProtectTest, Overload) {
575 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); 575 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot));
576 ASSERT_TRUE(test_server.Start()); 576 ASSERT_TRUE(test_server.Start());
577 577
578 GURL url(test_server.GetURL("defaultresponse")); 578 GURL url(test_server.GetURL("defaultresponse"));
579 579
580 // Registers an entry for test url. It only allows 3 requests to be sent 580 // Registers an entry for test url. It only allows 3 requests to be sent
581 // in 200 milliseconds. 581 // in 200 milliseconds.
582 scoped_refptr<net::URLRequestThrottlerEntry> entry( 582 scoped_refptr<net::URLRequestThrottlerEntry> entry(
583 new net::URLRequestThrottlerEntry(200, 3, 1, 0, 2.0, 0.0, 256)); 583 new net::URLRequestThrottlerEntry(200, 3, 1, 2.0, 0.0, 256));
584 net::URLRequestThrottlerManager::GetInstance()->OverrideEntryForTests( 584 net::URLRequestThrottlerManager::GetInstance()->OverrideEntryForTests(
585 url, entry); 585 url, entry);
586 586
587 CreateFetcher(url); 587 CreateFetcher(url);
588 588
589 MessageLoop::current()->Run(); 589 MessageLoop::current()->Run();
590 590
591 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); 591 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url);
592 } 592 }
593 593
594 TEST_F(URLFetcherProtectTest, ServerUnavailable) { 594 TEST_F(URLFetcherProtectTest, ServerUnavailable) {
595 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); 595 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot));
596 ASSERT_TRUE(test_server.Start()); 596 ASSERT_TRUE(test_server.Start());
597 597
598 GURL url(test_server.GetURL("files/server-unavailable.html")); 598 GURL url(test_server.GetURL("files/server-unavailable.html"));
599 599
600 // Registers an entry for test url. The backoff time is calculated by: 600 // Registers an entry for test url. The backoff time is calculated by:
601 // new_backoff = 2.0 * old_backoff + 0 601 // new_backoff = 2.0 * old_backoff + 0
602 // and maximum backoff time is 256 milliseconds. 602 // and maximum backoff time is 256 milliseconds.
603 // Maximum retries allowed is set to 11. 603 // Maximum retries allowed is set to 11.
604 scoped_refptr<net::URLRequestThrottlerEntry> entry( 604 scoped_refptr<net::URLRequestThrottlerEntry> entry(
605 new net::URLRequestThrottlerEntry(200, 3, 1, 0, 2.0, 0.0, 256)); 605 new net::URLRequestThrottlerEntry(200, 3, 1, 2.0, 0.0, 256));
606 net::URLRequestThrottlerManager::GetInstance()->OverrideEntryForTests( 606 net::URLRequestThrottlerManager::GetInstance()->OverrideEntryForTests(
607 url, entry); 607 url, entry);
608 608
609 CreateFetcher(url); 609 CreateFetcher(url);
610 610
611 MessageLoop::current()->Run(); 611 MessageLoop::current()->Run();
612 612
613 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); 613 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url);
614 } 614 }
615 615
616 TEST_F(URLFetcherProtectTestPassedThrough, ServerUnavailablePropagateResponse) { 616 TEST_F(URLFetcherProtectTestPassedThrough, ServerUnavailablePropagateResponse) {
617 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); 617 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot));
618 ASSERT_TRUE(test_server.Start()); 618 ASSERT_TRUE(test_server.Start());
619 619
620 GURL url(test_server.GetURL("files/server-unavailable.html")); 620 GURL url(test_server.GetURL("files/server-unavailable.html"));
621 621
622 // Registers an entry for test url. The backoff time is calculated by: 622 // Registers an entry for test url. The backoff time is calculated by:
623 // new_backoff = 2.0 * old_backoff + 0 623 // new_backoff = 2.0 * old_backoff + 0
624 // and maximum backoff time is 150000 milliseconds. 624 // and maximum backoff time is 150000 milliseconds.
625 // Maximum retries allowed is set to 11. 625 // Maximum retries allowed is set to 11.
626 scoped_refptr<net::URLRequestThrottlerEntry> entry( 626 scoped_refptr<net::URLRequestThrottlerEntry> entry(
627 new net::URLRequestThrottlerEntry(200, 3, 100, 0, 2.0, 0.0, 150000)); 627 new net::URLRequestThrottlerEntry(200, 3, 100, 2.0, 0.0, 150000));
628 // Total time if *not* for not doing automatic backoff would be 150s. 628 // Total time if *not* for not doing automatic backoff would be 150s.
629 // In reality it should be "as soon as server responds". 629 // In reality it should be "as soon as server responds".
630 net::URLRequestThrottlerManager::GetInstance()->OverrideEntryForTests( 630 net::URLRequestThrottlerManager::GetInstance()->OverrideEntryForTests(
631 url, entry); 631 url, entry);
632 632
633 CreateFetcher(url); 633 CreateFetcher(url);
634 634
635 MessageLoop::current()->Run(); 635 MessageLoop::current()->Run();
636 636
637 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); 637 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url);
(...skipping 23 matching lines...) Expand all
661 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); 661 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot));
662 ASSERT_TRUE(test_server.Start()); 662 ASSERT_TRUE(test_server.Start());
663 663
664 GURL url(test_server.GetURL("files/server-unavailable.html")); 664 GURL url(test_server.GetURL("files/server-unavailable.html"));
665 665
666 // Registers an entry for test url. The backoff time is calculated by: 666 // Registers an entry for test url. The backoff time is calculated by:
667 // new_backoff = 2.0 * old_backoff + 0 667 // new_backoff = 2.0 * old_backoff + 0
668 // The initial backoff is 2 seconds and maximum backoff is 4 seconds. 668 // The initial backoff is 2 seconds and maximum backoff is 4 seconds.
669 // Maximum retries allowed is set to 2. 669 // Maximum retries allowed is set to 2.
670 scoped_refptr<net::URLRequestThrottlerEntry> entry( 670 scoped_refptr<net::URLRequestThrottlerEntry> entry(
671 new net::URLRequestThrottlerEntry(200, 3, 2000, 0, 2.0, 0.0, 4000)); 671 new net::URLRequestThrottlerEntry(200, 3, 2000, 2.0, 0.0, 4000));
672 net::URLRequestThrottlerManager::GetInstance()->OverrideEntryForTests( 672 net::URLRequestThrottlerManager::GetInstance()->OverrideEntryForTests(
673 url, entry); 673 url, entry);
674 674
675 // Create a separate thread that will create the URLFetcher. The current 675 // Create a separate thread that will create the URLFetcher. The current
676 // (main) thread will do the IO, and when the fetch is complete it will 676 // (main) thread will do the IO, and when the fetch is complete it will
677 // terminate the main thread's message loop; then the other thread's 677 // terminate the main thread's message loop; then the other thread's
678 // message loop will be shut down automatically as the thread goes out of 678 // message loop will be shut down automatically as the thread goes out of
679 // scope. 679 // scope.
680 base::Thread t("URLFetcher test thread"); 680 base::Thread t("URLFetcher test thread");
681 ASSERT_TRUE(t.Start()); 681 ASSERT_TRUE(t.Start());
682 t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, url)); 682 t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, url));
683 683
684 MessageLoop::current()->Run(); 684 MessageLoop::current()->Run();
685 685
686 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url); 686 net::URLRequestThrottlerManager::GetInstance()->EraseEntryForTests(url);
687 } 687 }
688 688
689 TEST_F(URLFetcherCancelTest, CancelWhileDelayedStartTaskPending) { 689 TEST_F(URLFetcherCancelTest, CancelWhileDelayedStartTaskPending) {
690 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)); 690 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath(kDocRoot));
691 ASSERT_TRUE(test_server.Start()); 691 ASSERT_TRUE(test_server.Start());
692 692
693 GURL url(test_server.GetURL("files/server-unavailable.html")); 693 GURL url(test_server.GetURL("files/server-unavailable.html"));
694 694
695 // Register an entry for test url. 695 // Register an entry for test url.
696 // Using a sliding window of 4 seconds, and max of 1 request, under a fast 696 // Using a sliding window of 4 seconds, and max of 1 request, under a fast
697 // run we expect to have a 4 second delay when posting the Start task. 697 // run we expect to have a 4 second delay when posting the Start task.
698 scoped_refptr<net::URLRequestThrottlerEntry> entry( 698 scoped_refptr<net::URLRequestThrottlerEntry> entry(
699 new net::URLRequestThrottlerEntry(4000, 1, 2000, 0, 2.0, 0.0, 4000)); 699 new net::URLRequestThrottlerEntry(4000, 1, 2000, 2.0, 0.0, 4000));
700 net::URLRequestThrottlerManager::GetInstance()->OverrideEntryForTests( 700 net::URLRequestThrottlerManager::GetInstance()->OverrideEntryForTests(
701 url, entry); 701 url, entry);
702 // Fake that a request has just started. 702 // Fake that a request has just started.
703 entry->ReserveSendingTimeForNextRequest(base::TimeTicks()); 703 entry->ReserveSendingTimeForNextRequest(base::TimeTicks());
704 704
705 // The next request we try to send will be delayed by ~4 seconds. 705 // The next request we try to send will be delayed by ~4 seconds.
706 // The slower the test runs, the less the delay will be (since it takes the 706 // The slower the test runs, the less the delay will be (since it takes the
707 // time difference from now). 707 // time difference from now).
708 708
709 base::Thread t("URLFetcher test thread"); 709 base::Thread t("URLFetcher test thread");
(...skipping 28 matching lines...) Expand all
738 FROM_HERE, 738 FROM_HERE,
739 new CurriedTask(new MessageLoop::QuitTask(), MessageLoop::current())); 739 new CurriedTask(new MessageLoop::QuitTask(), MessageLoop::current()));
740 MessageLoop::current()->Run(); 740 MessageLoop::current()->Run();
741 EXPECT_EQ(1, GetNumFetcherCores()); 741 EXPECT_EQ(1, GetNumFetcherCores());
742 URLFetcher::CancelAll(); 742 URLFetcher::CancelAll();
743 EXPECT_EQ(0, GetNumFetcherCores()); 743 EXPECT_EQ(0, GetNumFetcherCores());
744 delete fetcher_; 744 delete fetcher_;
745 } 745 }
746 746
747 } // namespace. 747 } // namespace.
OLDNEW
« no previous file with comments | « no previous file | chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698