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

Side by Side Diff: net/base/host_resolver_impl_unittest.cc

Issue 11464028: Introduce ERR_NETWORK_CHANGED and allow URLFetcher to automatically retry on that error. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed nits Created 8 years 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/base/host_resolver_impl.cc ('k') | net/base/mock_host_resolver.h » ('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/base/host_resolver_impl.h" 5 #include "net/base/host_resolver_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b", 83)->Resolve()); 728 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b", 83)->Resolve());
729 729
730 EXPECT_TRUE(proc_->WaitFor(1u)); 730 EXPECT_TRUE(proc_->WaitFor(1u));
731 731
732 // Triggering an IP address change. 732 // Triggering an IP address change.
733 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 733 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
734 734
735 // |MyHandler| will send quit message once all the requests have finished. 735 // |MyHandler| will send quit message once all the requests have finished.
736 MessageLoop::current()->Run(); 736 MessageLoop::current()->Run();
737 737
738 EXPECT_EQ(ERR_ABORTED, requests_[0]->result()); 738 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->result());
739 EXPECT_EQ(ERR_IO_PENDING, requests_[1]->result()); 739 EXPECT_EQ(ERR_IO_PENDING, requests_[1]->result());
740 EXPECT_EQ(ERR_IO_PENDING, requests_[2]->result()); 740 EXPECT_EQ(ERR_IO_PENDING, requests_[2]->result());
741 EXPECT_EQ(ERR_IO_PENDING, requests_[3]->result()); 741 EXPECT_EQ(ERR_IO_PENDING, requests_[3]->result());
742 // Clean up. 742 // Clean up.
743 proc_->SignalMultiple(requests_.size()); 743 proc_->SignalMultiple(requests_.size());
744 } 744 }
745 745
746 TEST_F(HostResolverImplTest, StartWithinCallback) { 746 TEST_F(HostResolverImplTest, StartWithinCallback) {
747 struct MyHandler : public Handler { 747 struct MyHandler : public Handler {
748 virtual void Handle(Request* req) OVERRIDE { 748 virtual void Handle(Request* req) OVERRIDE {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 823 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
824 MessageLoop::current()->RunUntilIdle(); // Notification happens async. 824 MessageLoop::current()->RunUntilIdle(); // Notification happens async.
825 825
826 // Resolve "host1" again -- this time it won't be served from cache, so it 826 // Resolve "host1" again -- this time it won't be served from cache, so it
827 // will complete asynchronously. 827 // will complete asynchronously.
828 req = CreateRequest("host1", 80); 828 req = CreateRequest("host1", 80);
829 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); 829 EXPECT_EQ(ERR_IO_PENDING, req->Resolve());
830 EXPECT_EQ(OK, req->WaitForResult()); 830 EXPECT_EQ(OK, req->WaitForResult());
831 } 831 }
832 832
833 // Test that IP address changes send ERR_ABORTED to pending requests. 833 // Test that IP address changes send ERR_NETWORK_CHANGED to pending requests.
834 TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { 834 TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) {
835 Request* req = CreateRequest("host1", 70); 835 Request* req = CreateRequest("host1", 70);
836 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); 836 EXPECT_EQ(ERR_IO_PENDING, req->Resolve());
837 837
838 EXPECT_TRUE(proc_->WaitFor(1u)); 838 EXPECT_TRUE(proc_->WaitFor(1u));
839 // Triggering an IP address change. 839 // Triggering an IP address change.
840 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 840 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
841 MessageLoop::current()->RunUntilIdle(); // Notification happens async. 841 MessageLoop::current()->RunUntilIdle(); // Notification happens async.
842 proc_->SignalAll(); 842 proc_->SignalAll();
843 843
844 EXPECT_EQ(ERR_ABORTED, req->WaitForResult()); 844 EXPECT_EQ(ERR_NETWORK_CHANGED, req->WaitForResult());
845 EXPECT_EQ(0u, resolver_->GetHostCache()->size()); 845 EXPECT_EQ(0u, resolver_->GetHostCache()->size());
846 } 846 }
847 847
848 // Obey pool constraints after IP address has changed. 848 // Obey pool constraints after IP address has changed.
849 TEST_F(HostResolverImplTest, ObeyPoolConstraintsAfterIPAddressChange) { 849 TEST_F(HostResolverImplTest, ObeyPoolConstraintsAfterIPAddressChange) {
850 // Runs at most one job at a time. 850 // Runs at most one job at a time.
851 CreateSerialResolver(); 851 CreateSerialResolver();
852 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a")->Resolve()); 852 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a")->Resolve());
853 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b")->Resolve()); 853 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b")->Resolve());
854 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("c")->Resolve()); 854 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("c")->Resolve());
855 855
856 EXPECT_TRUE(proc_->WaitFor(1u)); 856 EXPECT_TRUE(proc_->WaitFor(1u));
857 // Triggering an IP address change. 857 // Triggering an IP address change.
858 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 858 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
859 MessageLoop::current()->RunUntilIdle(); // Notification happens async. 859 MessageLoop::current()->RunUntilIdle(); // Notification happens async.
860 proc_->SignalMultiple(3u); // Let the false-start go so that we can catch it. 860 proc_->SignalMultiple(3u); // Let the false-start go so that we can catch it.
861 861
862 EXPECT_EQ(ERR_ABORTED, requests_[0]->WaitForResult()); 862 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->WaitForResult());
863 863
864 EXPECT_EQ(1u, num_running_jobs()); 864 EXPECT_EQ(1u, num_running_jobs());
865 865
866 EXPECT_FALSE(requests_[1]->completed()); 866 EXPECT_FALSE(requests_[1]->completed());
867 EXPECT_FALSE(requests_[2]->completed()); 867 EXPECT_FALSE(requests_[2]->completed());
868 868
869 EXPECT_EQ(OK, requests_[2]->WaitForResult()); 869 EXPECT_EQ(OK, requests_[2]->WaitForResult());
870 EXPECT_EQ(OK, requests_[1]->result()); 870 EXPECT_EQ(OK, requests_[1]->result());
871 } 871 }
872 872
(...skipping 21 matching lines...) Expand all
894 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("bbb")->Resolve()); 894 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("bbb")->Resolve());
895 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("eee")->Resolve()); 895 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("eee")->Resolve());
896 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ccc")->Resolve()); 896 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("ccc")->Resolve());
897 897
898 // Wait until all are blocked; 898 // Wait until all are blocked;
899 EXPECT_TRUE(proc_->WaitFor(3u)); 899 EXPECT_TRUE(proc_->WaitFor(3u));
900 // Trigger an IP address change. 900 // Trigger an IP address change.
901 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 901 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
902 // This should abort all running jobs. 902 // This should abort all running jobs.
903 MessageLoop::current()->RunUntilIdle(); 903 MessageLoop::current()->RunUntilIdle();
904 EXPECT_EQ(ERR_ABORTED, requests_[0]->result()); 904 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[0]->result());
905 EXPECT_EQ(ERR_ABORTED, requests_[1]->result()); 905 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[1]->result());
906 EXPECT_EQ(ERR_ABORTED, requests_[2]->result()); 906 EXPECT_EQ(ERR_NETWORK_CHANGED, requests_[2]->result());
907 ASSERT_EQ(6u, requests_.size()); 907 ASSERT_EQ(6u, requests_.size());
908 // Unblock all calls to proc. 908 // Unblock all calls to proc.
909 proc_->SignalMultiple(requests_.size()); 909 proc_->SignalMultiple(requests_.size());
910 // Run until the re-started requests finish. 910 // Run until the re-started requests finish.
911 EXPECT_EQ(OK, requests_[3]->WaitForResult()); 911 EXPECT_EQ(OK, requests_[3]->WaitForResult());
912 EXPECT_EQ(OK, requests_[4]->WaitForResult()); 912 EXPECT_EQ(OK, requests_[4]->WaitForResult());
913 EXPECT_EQ(OK, requests_[5]->WaitForResult()); 913 EXPECT_EQ(OK, requests_[5]->WaitForResult());
914 // Verify that results of aborted Jobs were not cached. 914 // Verify that results of aborted Jobs were not cached.
915 EXPECT_EQ(6u, proc_->GetCaptureList().size()); 915 EXPECT_EQ(6u, proc_->GetCaptureList().size());
916 EXPECT_EQ(3u, resolver_->GetHostCache()->size()); 916 EXPECT_EQ(3u, resolver_->GetHostCache()->size());
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 // Make |proc_| default to failures. 1472 // Make |proc_| default to failures.
1473 proc_->AddRuleForAllFamilies("", ""); 1473 proc_->AddRuleForAllFamilies("", "");
1474 1474
1475 // DnsTask should still be enabled. 1475 // DnsTask should still be enabled.
1476 Request* req = CreateRequest("ok_last", 80); 1476 Request* req = CreateRequest("ok_last", 80);
1477 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); 1477 EXPECT_EQ(ERR_IO_PENDING, req->Resolve());
1478 EXPECT_EQ(OK, req->WaitForResult()); 1478 EXPECT_EQ(OK, req->WaitForResult());
1479 } 1479 }
1480 1480
1481 } // namespace net 1481 } // namespace net
OLDNEW
« no previous file with comments | « net/base/host_resolver_impl.cc ('k') | net/base/mock_host_resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698