Chromium Code Reviews| 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/dns_transaction.h" | 5 #include "net/dns/dns_transaction.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 class TestSocketFactory : public MockClientSocketFactory { | 178 class TestSocketFactory : public MockClientSocketFactory { |
| 179 public: | 179 public: |
| 180 TestSocketFactory() : create_failing_sockets_(false) {} | 180 TestSocketFactory() : create_failing_sockets_(false) {} |
| 181 virtual ~TestSocketFactory() {} | 181 virtual ~TestSocketFactory() {} |
| 182 | 182 |
| 183 virtual DatagramClientSocket* CreateDatagramClientSocket( | 183 virtual DatagramClientSocket* CreateDatagramClientSocket( |
| 184 DatagramSocket::BindType bind_type, | 184 DatagramSocket::BindType bind_type, |
| 185 const RandIntCallback& rand_int_cb, | 185 const RandIntCallback& rand_int_cb, |
| 186 net::NetLog* net_log, | 186 net::NetLog* net_log, |
| 187 const net::NetLog::Source& source) OVERRIDE { | 187 const net::NetLog::Source& source) OVERRIDE { |
| 188 if (create_failing_sockets_) | 188 if (create_failing_sockets_) { |
|
szym
2013/05/29 17:09:42
Suggest renaming this field to |fail_next_socket_|
mef
2013/05/29 17:24:04
Done.
| |
| 189 create_failing_sockets_ = false; | |
| 189 return new FailingUDPClientSocket(&empty_data_, net_log); | 190 return new FailingUDPClientSocket(&empty_data_, net_log); |
| 191 } | |
| 190 SocketDataProvider* data_provider = mock_data().GetNext(); | 192 SocketDataProvider* data_provider = mock_data().GetNext(); |
| 191 TestUDPClientSocket* socket = new TestUDPClientSocket(this, | 193 TestUDPClientSocket* socket = new TestUDPClientSocket(this, |
| 192 data_provider, | 194 data_provider, |
| 193 net_log); | 195 net_log); |
| 194 data_provider->set_socket(socket); | 196 data_provider->set_socket(socket); |
| 195 return socket; | 197 return socket; |
| 196 } | 198 } |
| 197 | 199 |
| 198 void OnConnect(const IPEndPoint& endpoint) { | 200 void OnConnect(const IPEndPoint& endpoint) { |
| 199 remote_endpoints_.push_back(endpoint); | 201 remote_endpoints_.push_back(endpoint); |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 858 } | 860 } |
| 859 | 861 |
| 860 TEST_F(DnsTransactionTest, ConnectFailure) { | 862 TEST_F(DnsTransactionTest, ConnectFailure) { |
| 861 socket_factory_->create_failing_sockets_ = true; | 863 socket_factory_->create_failing_sockets_ = true; |
| 862 transaction_ids_.push_back(0); // Needed to make a DnsUDPAttempt. | 864 transaction_ids_.push_back(0); // Needed to make a DnsUDPAttempt. |
| 863 TransactionHelper helper0("www.chromium.org", dns_protocol::kTypeA, | 865 TransactionHelper helper0("www.chromium.org", dns_protocol::kTypeA, |
| 864 ERR_CONNECTION_REFUSED); | 866 ERR_CONNECTION_REFUSED); |
| 865 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); | 867 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); |
| 866 } | 868 } |
| 867 | 869 |
| 870 TEST_F(DnsTransactionTest, ConnectFailureDoesntCrashInRecordLostPacketsIfAny) { | |
|
szym
2013/05/29 17:09:42
suggest just calling the test "ConnectFailureFollo
mef
2013/05/29 17:24:04
Done.
| |
| 871 // Fallback on server failure. | |
|
szym
2013/05/29 17:09:42
suggest: "// Retry after failure."
mef
2013/05/29 17:24:04
Done.
| |
| 872 config_.attempts = 2; | |
| 873 ConfigureFactory(); | |
| 874 // First server connection attempt fails. | |
| 875 transaction_ids_.push_back(0); // Needed to make a DnsUDPAttempt. | |
| 876 socket_factory_->create_failing_sockets_ = true; | |
| 877 // Second DNS query succeeds. | |
| 878 AddAsyncQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, | |
| 879 kT0ResponseDatagram, arraysize(kT0ResponseDatagram)); | |
| 880 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); | |
| 881 // Expect no crash here! | |
|
szym
2013/05/29 17:09:42
unnecessary comment
mef
2013/05/29 17:24:04
Done.
| |
| 882 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); | |
| 883 } | |
| 884 | |
| 868 TEST_F(DnsTransactionTest, TCPLookup) { | 885 TEST_F(DnsTransactionTest, TCPLookup) { |
| 869 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, | 886 AddAsyncQueryAndRcode(kT0HostName, kT0Qtype, |
| 870 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC); | 887 dns_protocol::kRcodeNOERROR | dns_protocol::kFlagTC); |
| 871 AddQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, | 888 AddQueryAndResponse(0 /* id */, kT0HostName, kT0Qtype, |
| 872 kT0ResponseDatagram, arraysize(kT0ResponseDatagram), | 889 kT0ResponseDatagram, arraysize(kT0ResponseDatagram), |
| 873 ASYNC, true /* use_tcp */); | 890 ASYNC, true /* use_tcp */); |
| 874 | 891 |
| 875 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); | 892 TransactionHelper helper0(kT0HostName, kT0Qtype, kT0RecordCount); |
| 876 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); | 893 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); |
| 877 } | 894 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 920 config_.timeout = TestTimeouts::tiny_timeout(); | 937 config_.timeout = TestTimeouts::tiny_timeout(); |
| 921 ConfigureFactory(); | 938 ConfigureFactory(); |
| 922 | 939 |
| 923 TransactionHelper helper0(".", dns_protocol::kTypeA, ERR_INVALID_ARGUMENT); | 940 TransactionHelper helper0(".", dns_protocol::kTypeA, ERR_INVALID_ARGUMENT); |
| 924 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); | 941 EXPECT_TRUE(helper0.Run(transaction_factory_.get())); |
| 925 } | 942 } |
| 926 | 943 |
| 927 } // namespace | 944 } // namespace |
| 928 | 945 |
| 929 } // namespace net | 946 } // namespace net |
| OLD | NEW |