OLD | NEW |
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/dns/host_resolver_impl.h" | 5 #include "net/dns/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 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 set_handler(new MyHandler()); | 892 set_handler(new MyHandler()); |
893 | 893 |
894 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80)->Resolve()); | 894 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a", 80)->Resolve()); |
895 proc_->SignalMultiple(3u); // Only need two, but be generous. | 895 proc_->SignalMultiple(3u); // Only need two, but be generous. |
896 | 896 |
897 // |verifier| will send quit message once all the requests have finished. | 897 // |verifier| will send quit message once all the requests have finished. |
898 base::MessageLoop::current()->Run(); | 898 base::MessageLoop::current()->Run(); |
899 EXPECT_EQ(2u, proc_->GetCaptureList().size()); | 899 EXPECT_EQ(2u, proc_->GetCaptureList().size()); |
900 } | 900 } |
901 | 901 |
902 // Test that IP address changes flush the cache. | 902 // Test that IP address changes flush the cache but initial DNS config reads do |
| 903 // not. |
903 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { | 904 TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { |
904 proc_->SignalMultiple(2u); // One before the flush, one after. | 905 proc_->SignalMultiple(2u); // One before the flush, one after. |
905 | 906 |
906 Request* req = CreateRequest("host1", 70); | 907 Request* req = CreateRequest("host1", 70); |
907 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 908 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); |
908 EXPECT_EQ(OK, req->WaitForResult()); | 909 EXPECT_EQ(OK, req->WaitForResult()); |
909 | 910 |
910 req = CreateRequest("host1", 75); | 911 req = CreateRequest("host1", 75); |
911 EXPECT_EQ(OK, req->Resolve()); // Should complete synchronously. | 912 EXPECT_EQ(OK, req->Resolve()); // Should complete synchronously. |
912 | 913 |
| 914 // Verify initial DNS config read does not flush cache. |
| 915 NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests(); |
| 916 req = CreateRequest("host1", 75); |
| 917 EXPECT_EQ(OK, req->Resolve()); // Should complete synchronously. |
| 918 |
913 // Flush cache by triggering an IP address change. | 919 // Flush cache by triggering an IP address change. |
914 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 920 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
915 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. | 921 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. |
916 | 922 |
917 // Resolve "host1" again -- this time it won't be served from cache, so it | 923 // Resolve "host1" again -- this time it won't be served from cache, so it |
918 // will complete asynchronously. | 924 // will complete asynchronously. |
919 req = CreateRequest("host1", 80); | 925 req = CreateRequest("host1", 80); |
920 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 926 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); |
921 EXPECT_EQ(OK, req->WaitForResult()); | 927 EXPECT_EQ(OK, req->WaitForResult()); |
922 } | 928 } |
923 | 929 |
924 // Test that IP address changes send ERR_NETWORK_CHANGED to pending requests. | 930 // Test that IP address changes send ERR_NETWORK_CHANGED to pending requests. |
925 TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { | 931 TEST_F(HostResolverImplTest, AbortOnIPAddressChanged) { |
926 Request* req = CreateRequest("host1", 70); | 932 Request* req = CreateRequest("host1", 70); |
927 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 933 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); |
928 | 934 |
929 EXPECT_TRUE(proc_->WaitFor(1u)); | 935 EXPECT_TRUE(proc_->WaitFor(1u)); |
930 // Triggering an IP address change. | 936 // Triggering an IP address change. |
931 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 937 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
932 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. | 938 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. |
933 proc_->SignalAll(); | 939 proc_->SignalAll(); |
934 | 940 |
935 EXPECT_EQ(ERR_NETWORK_CHANGED, req->WaitForResult()); | 941 EXPECT_EQ(ERR_NETWORK_CHANGED, req->WaitForResult()); |
936 EXPECT_EQ(0u, resolver_->GetHostCache()->size()); | 942 EXPECT_EQ(0u, resolver_->GetHostCache()->size()); |
937 } | 943 } |
938 | 944 |
| 945 // Test that initial DNS config read signals do not abort pending requests. |
| 946 TEST_F(HostResolverImplTest, DontAbortOnInitialDNSConfigRead) { |
| 947 Request* req = CreateRequest("host1", 70); |
| 948 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); |
| 949 |
| 950 EXPECT_TRUE(proc_->WaitFor(1u)); |
| 951 // Triggering initial DNS config read signal. |
| 952 NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests(); |
| 953 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. |
| 954 proc_->SignalAll(); |
| 955 |
| 956 EXPECT_EQ(OK, req->WaitForResult()); |
| 957 } |
| 958 |
939 // Obey pool constraints after IP address has changed. | 959 // Obey pool constraints after IP address has changed. |
940 TEST_F(HostResolverImplTest, ObeyPoolConstraintsAfterIPAddressChange) { | 960 TEST_F(HostResolverImplTest, ObeyPoolConstraintsAfterIPAddressChange) { |
941 // Runs at most one job at a time. | 961 // Runs at most one job at a time. |
942 CreateSerialResolver(); | 962 CreateSerialResolver(); |
943 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a")->Resolve()); | 963 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("a")->Resolve()); |
944 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b")->Resolve()); | 964 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("b")->Resolve()); |
945 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("c")->Resolve()); | 965 EXPECT_EQ(ERR_IO_PENDING, CreateRequest("c")->Resolve()); |
946 | 966 |
947 EXPECT_TRUE(proc_->WaitFor(1u)); | 967 EXPECT_TRUE(proc_->WaitFor(1u)); |
948 // Triggering an IP address change. | 968 // Triggering an IP address change. |
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2154 | 2174 |
2155 EXPECT_EQ(OK, requests_[0]->WaitForResult()); | 2175 EXPECT_EQ(OK, requests_[0]->WaitForResult()); |
2156 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); | 2176 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); |
2157 EXPECT_EQ(OK, requests_[1]->WaitForResult()); | 2177 EXPECT_EQ(OK, requests_[1]->WaitForResult()); |
2158 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); | 2178 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); |
2159 EXPECT_EQ(OK, requests_[2]->WaitForResult()); | 2179 EXPECT_EQ(OK, requests_[2]->WaitForResult()); |
2160 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); | 2180 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); |
2161 } | 2181 } |
2162 | 2182 |
2163 } // namespace net | 2183 } // namespace net |
OLD | NEW |