OLD | NEW |
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 "net/dns/dns_transaction.h" | 5 #include "net/dns/dns_transaction.h" |
6 | 6 |
7 #include <deque> | 7 #include <deque> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/time.h" | |
12 #include "net/dns/dns_protocol.h" | |
13 #include "net/dns/dns_query.h" | |
14 #include "net/dns/dns_response.h" | |
15 #include "net/dns/dns_session.h" | |
16 #include "net/dns/dns_test_util.h" | 11 #include "net/dns/dns_test_util.h" |
17 #include "net/socket/socket_test_util.h" | 12 #include "net/socket/socket_test_util.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
19 | 14 |
20 namespace net { | 15 namespace net { |
21 | 16 |
22 namespace { | 17 namespace { |
23 | 18 |
24 // A mock for RandIntCallback that always returns 0. | 19 static const base::TimeDelta kTimeoutsMs[] = { |
25 int ReturnZero(int min, int max) { | 20 base::TimeDelta::FromMilliseconds(20), |
26 return 0; | 21 base::TimeDelta::FromMilliseconds(20), |
27 } | 22 base::TimeDelta::FromMilliseconds(20), |
| 23 }; |
28 | 24 |
29 class DnsTransactionTest : public testing::Test { | 25 } // namespace |
30 protected: | |
31 virtual void SetUp() OVERRIDE { | |
32 DnsConfig config; | |
33 | 26 |
34 IPEndPoint dns_server; | 27 class TestDelegate : public DnsTransaction::Delegate { |
35 bool rv = CreateDnsAddress(kDnsIp, kDnsPort, &dns_server); | 28 public: |
36 ASSERT_TRUE(rv); | 29 TestDelegate() : result_(ERR_UNEXPECTED), transaction_(NULL) {} |
37 config.nameservers.push_back(dns_server); | 30 virtual ~TestDelegate() {} |
38 config.attempts = 3; | 31 virtual void OnTransactionComplete( |
39 config.timeout = base::TimeDelta::FromMilliseconds(20); | 32 int result, |
40 | 33 const DnsTransaction* transaction, |
41 qname_ = std::string(kT0DnsName, arraysize(kT0DnsName)); | 34 const IPAddressList& ip_addresses) { |
42 | 35 result_ = result; |
43 session_ = new DnsSession(config, | 36 transaction_ = transaction; |
44 new MockClientSocketFactory(), | 37 ip_addresses_ = ip_addresses; |
45 base::Bind(&ReturnZero), | 38 MessageLoop::current()->Quit(); |
46 NULL /* NetLog */); | 39 } |
47 | 40 int result() const { return result_; } |
48 callback_ = base::Bind(&DnsTransactionTest::OnTransactionComplete, | 41 const DnsTransaction* transaction() const { return transaction_; } |
49 base::Unretained(this)); | 42 const IPAddressList& ip_addresses() const { |
| 43 return ip_addresses_; |
50 } | 44 } |
51 | 45 |
52 void StartTransaction() { | 46 private: |
53 transaction_.reset(new DnsTransaction(session_.get(), | 47 int result_; |
54 qname_, | 48 const DnsTransaction* transaction_; |
55 kT0Qtype, | 49 IPAddressList ip_addresses_; |
56 callback_, | |
57 BoundNetLog())); | |
58 | 50 |
59 int rv0 = transaction_->Start(); | 51 DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
60 EXPECT_EQ(ERR_IO_PENDING, rv0); | |
61 } | |
62 | |
63 void OnTransactionComplete(DnsTransaction* transaction, int rv) { | |
64 EXPECT_EQ(transaction_.get(), transaction); | |
65 EXPECT_EQ(qname_, transaction->query()->qname().as_string()); | |
66 EXPECT_EQ(kT0Qtype, transaction->query()->qtype()); | |
67 rv_ = rv; | |
68 MessageLoop::current()->Quit(); | |
69 } | |
70 | |
71 MockClientSocketFactory& factory() { | |
72 return *static_cast<MockClientSocketFactory*>(session_->socket_factory()); | |
73 } | |
74 | |
75 int rv() const { return rv_; } | |
76 | |
77 private: | |
78 std::string qname_; | |
79 scoped_refptr<DnsSession> session_; | |
80 scoped_ptr<DnsTransaction> transaction_; | |
81 DnsTransaction::ResultCallback callback_; | |
82 | |
83 int rv_; | |
84 }; | 52 }; |
85 | 53 |
86 TEST_F(DnsTransactionTest, NormalQueryResponseTest) { | 54 |
| 55 TEST(DnsTransactionTest, NormalQueryResponseTest) { |
87 MockWrite writes0[] = { | 56 MockWrite writes0[] = { |
88 MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram), | 57 MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram), |
89 arraysize(kT0QueryDatagram)) | 58 arraysize(kT0QueryDatagram)) |
90 }; | 59 }; |
91 | 60 |
92 MockRead reads0[] = { | 61 MockRead reads0[] = { |
93 MockRead(true, reinterpret_cast<const char*>(kT0ResponseDatagram), | 62 MockRead(true, reinterpret_cast<const char*>(kT0ResponseDatagram), |
94 arraysize(kT0ResponseDatagram)) | 63 arraysize(kT0ResponseDatagram)) |
95 }; | 64 }; |
96 | 65 |
97 StaticSocketDataProvider data(reads0, arraysize(reads0), | 66 StaticSocketDataProvider data(reads0, arraysize(reads0), |
98 writes0, arraysize(writes0)); | 67 writes0, arraysize(writes0)); |
99 factory().AddSocketDataProvider(&data); | 68 MockClientSocketFactory factory; |
| 69 factory.AddSocketDataProvider(&data); |
100 | 70 |
101 StartTransaction(); | 71 TestPrng test_prng(std::deque<int>(1, 0)); |
| 72 RandIntCallback rand_int_cb = |
| 73 base::Bind(&TestPrng::GetNext, base::Unretained(&test_prng)); |
| 74 std::string t0_dns_name(kT0DnsName, arraysize(kT0DnsName)); |
| 75 |
| 76 IPEndPoint dns_server; |
| 77 bool rv = CreateDnsAddress(kDnsIp, kDnsPort, &dns_server); |
| 78 ASSERT_TRUE(rv); |
| 79 |
| 80 DnsTransaction t(dns_server, t0_dns_name, kT1Qtype, rand_int_cb, &factory, |
| 81 BoundNetLog(), NULL); |
| 82 |
| 83 TestDelegate delegate; |
| 84 t.SetDelegate(&delegate); |
| 85 |
| 86 IPAddressList expected_ip_addresses; |
| 87 rv = ConvertStringsToIPAddressList(kT0IpAddresses, |
| 88 arraysize(kT0IpAddresses), |
| 89 &expected_ip_addresses); |
| 90 ASSERT_TRUE(rv); |
| 91 |
| 92 int rv0 = t.Start(); |
| 93 EXPECT_EQ(ERR_IO_PENDING, rv0); |
| 94 |
102 MessageLoop::current()->Run(); | 95 MessageLoop::current()->Run(); |
103 | 96 |
104 EXPECT_EQ(OK, rv()); | 97 EXPECT_TRUE(DnsTransaction::Key(t0_dns_name, kT0Qtype) == t.key()); |
105 // TODO(szym): test fields of |transaction_->response()| | 98 EXPECT_EQ(OK, delegate.result()); |
| 99 EXPECT_EQ(&t, delegate.transaction()); |
| 100 EXPECT_TRUE(expected_ip_addresses == delegate.ip_addresses()); |
106 | 101 |
107 EXPECT_TRUE(data.at_read_eof()); | 102 EXPECT_TRUE(data.at_read_eof()); |
108 EXPECT_TRUE(data.at_write_eof()); | 103 EXPECT_TRUE(data.at_write_eof()); |
109 } | 104 } |
110 | 105 |
111 TEST_F(DnsTransactionTest, MismatchedQueryResponseTest) { | 106 TEST(DnsTransactionTest, MismatchedQueryResponseTest) { |
112 MockWrite writes0[] = { | 107 MockWrite writes0[] = { |
113 MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram), | 108 MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram), |
114 arraysize(kT0QueryDatagram)) | 109 arraysize(kT0QueryDatagram)) |
115 }; | 110 }; |
116 | 111 |
117 MockRead reads1[] = { | 112 MockRead reads1[] = { |
118 MockRead(true, reinterpret_cast<const char*>(kT1ResponseDatagram), | 113 MockRead(true, reinterpret_cast<const char*>(kT1ResponseDatagram), |
119 arraysize(kT1ResponseDatagram)) | 114 arraysize(kT1ResponseDatagram)) |
120 }; | 115 }; |
121 | 116 |
122 StaticSocketDataProvider data(reads1, arraysize(reads1), | 117 StaticSocketDataProvider data(reads1, arraysize(reads1), |
123 writes0, arraysize(writes0)); | 118 writes0, arraysize(writes0)); |
124 factory().AddSocketDataProvider(&data); | 119 MockClientSocketFactory factory; |
| 120 factory.AddSocketDataProvider(&data); |
125 | 121 |
126 StartTransaction(); | 122 TestPrng test_prng(std::deque<int>(1, 0)); |
| 123 RandIntCallback rand_int_cb = |
| 124 base::Bind(&TestPrng::GetNext, base::Unretained(&test_prng)); |
| 125 std::string t0_dns_name(kT0DnsName, arraysize(kT0DnsName)); |
| 126 |
| 127 IPEndPoint dns_server; |
| 128 bool rv = CreateDnsAddress(kDnsIp, kDnsPort, &dns_server); |
| 129 ASSERT_TRUE(rv); |
| 130 |
| 131 DnsTransaction t(dns_server, t0_dns_name, kT1Qtype, rand_int_cb, &factory, |
| 132 BoundNetLog(), NULL); |
| 133 |
| 134 TestDelegate delegate; |
| 135 t.SetDelegate(&delegate); |
| 136 |
| 137 int rv0 = t.Start(); |
| 138 EXPECT_EQ(ERR_IO_PENDING, rv0); |
| 139 |
127 MessageLoop::current()->Run(); | 140 MessageLoop::current()->Run(); |
128 | 141 |
129 EXPECT_EQ(ERR_DNS_MALFORMED_RESPONSE, rv()); | 142 EXPECT_TRUE(DnsTransaction::Key(t0_dns_name, kT0Qtype) == t.key()); |
130 | 143 EXPECT_EQ(ERR_DNS_MALFORMED_RESPONSE, delegate.result()); |
| 144 EXPECT_EQ(0u, delegate.ip_addresses().size()); |
| 145 EXPECT_EQ(&t, delegate.transaction()); |
131 EXPECT_TRUE(data.at_read_eof()); | 146 EXPECT_TRUE(data.at_read_eof()); |
132 EXPECT_TRUE(data.at_write_eof()); | 147 EXPECT_TRUE(data.at_write_eof()); |
133 } | 148 } |
134 | 149 |
135 // Test that after the first timeout we do a fresh connection and if we get | 150 // Test that after the first timeout we do a fresh connection and if we get |
136 // a response on the new connection, we return it. | 151 // a response on the new connection, we return it. |
137 TEST_F(DnsTransactionTest, FirstTimeoutTest) { | 152 TEST(DnsTransactionTest, FirstTimeoutTest) { |
138 MockWrite writes0[] = { | 153 MockWrite writes0[] = { |
139 MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram), | 154 MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram), |
140 arraysize(kT0QueryDatagram)) | 155 arraysize(kT0QueryDatagram)) |
141 }; | 156 }; |
142 | 157 |
143 MockRead reads0[] = { | 158 MockRead reads0[] = { |
144 MockRead(true, reinterpret_cast<const char*>(kT0ResponseDatagram), | 159 MockRead(true, reinterpret_cast<const char*>(kT0ResponseDatagram), |
145 arraysize(kT0ResponseDatagram)) | 160 arraysize(kT0ResponseDatagram)) |
146 }; | 161 }; |
147 | 162 |
148 scoped_refptr<DelayedSocketData> socket0_data( | 163 scoped_refptr<DelayedSocketData> socket0_data( |
149 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); | 164 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); |
150 scoped_refptr<DelayedSocketData> socket1_data( | 165 scoped_refptr<DelayedSocketData> socket1_data( |
151 new DelayedSocketData(0, reads0, arraysize(reads0), | 166 new DelayedSocketData(0, reads0, arraysize(reads0), |
152 writes0, arraysize(writes0))); | 167 writes0, arraysize(writes0))); |
| 168 MockClientSocketFactory factory; |
| 169 factory.AddSocketDataProvider(socket0_data.get()); |
| 170 factory.AddSocketDataProvider(socket1_data.get()); |
153 | 171 |
154 factory().AddSocketDataProvider(socket0_data.get()); | 172 TestPrng test_prng(std::deque<int>(2, 0)); |
155 factory().AddSocketDataProvider(socket1_data.get()); | 173 RandIntCallback rand_int_cb = |
| 174 base::Bind(&TestPrng::GetNext, base::Unretained(&test_prng)); |
| 175 std::string t0_dns_name(kT0DnsName, arraysize(kT0DnsName)); |
156 | 176 |
157 StartTransaction(); | 177 IPEndPoint dns_server; |
| 178 bool rv = CreateDnsAddress(kDnsIp, kDnsPort, &dns_server); |
| 179 ASSERT_TRUE(rv); |
| 180 |
| 181 DnsTransaction t(dns_server, t0_dns_name, kT1Qtype, rand_int_cb, &factory, |
| 182 BoundNetLog(), NULL); |
| 183 |
| 184 TestDelegate delegate; |
| 185 t.SetDelegate(&delegate); |
| 186 |
| 187 t.set_timeouts_ms( |
| 188 std::vector<base::TimeDelta>(kTimeoutsMs, |
| 189 kTimeoutsMs + arraysize(kTimeoutsMs))); |
| 190 |
| 191 IPAddressList expected_ip_addresses; |
| 192 rv = ConvertStringsToIPAddressList(kT0IpAddresses, |
| 193 arraysize(kT0IpAddresses), |
| 194 &expected_ip_addresses); |
| 195 ASSERT_TRUE(rv); |
| 196 |
| 197 int rv0 = t.Start(); |
| 198 EXPECT_EQ(ERR_IO_PENDING, rv0); |
| 199 |
158 | 200 |
159 MessageLoop::current()->Run(); | 201 MessageLoop::current()->Run(); |
160 | 202 |
161 EXPECT_EQ(OK, rv()); | 203 EXPECT_TRUE(DnsTransaction::Key(t0_dns_name, kT0Qtype) == t.key()); |
| 204 EXPECT_EQ(OK, delegate.result()); |
| 205 EXPECT_EQ(&t, delegate.transaction()); |
| 206 EXPECT_TRUE(expected_ip_addresses == delegate.ip_addresses()); |
162 | 207 |
163 EXPECT_TRUE(socket0_data->at_read_eof()); | 208 EXPECT_TRUE(socket0_data->at_read_eof()); |
164 EXPECT_TRUE(socket0_data->at_write_eof()); | 209 EXPECT_TRUE(socket0_data->at_write_eof()); |
165 EXPECT_TRUE(socket1_data->at_read_eof()); | 210 EXPECT_TRUE(socket1_data->at_read_eof()); |
166 EXPECT_TRUE(socket1_data->at_write_eof()); | 211 EXPECT_TRUE(socket1_data->at_write_eof()); |
167 EXPECT_EQ(2u, factory().udp_client_sockets().size()); | 212 EXPECT_EQ(2u, factory.udp_client_sockets().size()); |
168 } | 213 } |
169 | 214 |
170 // Test that after the first timeout we do a fresh connection, and after | 215 // Test that after the first timeout we do a fresh connection, and after |
171 // the second timeout we do another fresh connection, and if we get a | 216 // the second timeout we do another fresh connection, and if we get a |
172 // response on the second connection, we return it. | 217 // response on the second connection, we return it. |
173 TEST_F(DnsTransactionTest, SecondTimeoutTest) { | 218 TEST(DnsTransactionTest, SecondTimeoutTest) { |
174 MockWrite writes0[] = { | 219 MockWrite writes0[] = { |
175 MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram), | 220 MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram), |
176 arraysize(kT0QueryDatagram)) | 221 arraysize(kT0QueryDatagram)) |
177 }; | 222 }; |
178 | 223 |
179 MockRead reads0[] = { | 224 MockRead reads0[] = { |
180 MockRead(true, reinterpret_cast<const char*>(kT0ResponseDatagram), | 225 MockRead(true, reinterpret_cast<const char*>(kT0ResponseDatagram), |
181 arraysize(kT0ResponseDatagram)) | 226 arraysize(kT0ResponseDatagram)) |
182 }; | 227 }; |
183 | 228 |
184 scoped_refptr<DelayedSocketData> socket0_data( | 229 scoped_refptr<DelayedSocketData> socket0_data( |
185 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); | 230 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); |
186 scoped_refptr<DelayedSocketData> socket1_data( | 231 scoped_refptr<DelayedSocketData> socket1_data( |
187 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); | 232 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); |
188 scoped_refptr<DelayedSocketData> socket2_data( | 233 scoped_refptr<DelayedSocketData> socket2_data( |
189 new DelayedSocketData(0, reads0, arraysize(reads0), | 234 new DelayedSocketData(0, reads0, arraysize(reads0), |
190 writes0, arraysize(writes0))); | 235 writes0, arraysize(writes0))); |
| 236 MockClientSocketFactory factory; |
| 237 factory.AddSocketDataProvider(socket0_data.get()); |
| 238 factory.AddSocketDataProvider(socket1_data.get()); |
| 239 factory.AddSocketDataProvider(socket2_data.get()); |
191 | 240 |
192 factory().AddSocketDataProvider(socket0_data.get()); | 241 TestPrng test_prng(std::deque<int>(3, 0)); |
193 factory().AddSocketDataProvider(socket1_data.get()); | 242 RandIntCallback rand_int_cb = |
194 factory().AddSocketDataProvider(socket2_data.get()); | 243 base::Bind(&TestPrng::GetNext, base::Unretained(&test_prng)); |
| 244 std::string t0_dns_name(kT0DnsName, arraysize(kT0DnsName)); |
195 | 245 |
196 StartTransaction(); | 246 IPEndPoint dns_server; |
| 247 bool rv = CreateDnsAddress(kDnsIp, kDnsPort, &dns_server); |
| 248 ASSERT_TRUE(rv); |
| 249 |
| 250 DnsTransaction t(dns_server, t0_dns_name, kT1Qtype, rand_int_cb, &factory, |
| 251 BoundNetLog(), NULL); |
| 252 |
| 253 TestDelegate delegate; |
| 254 t.SetDelegate(&delegate); |
| 255 |
| 256 t.set_timeouts_ms( |
| 257 std::vector<base::TimeDelta>(kTimeoutsMs, |
| 258 kTimeoutsMs + arraysize(kTimeoutsMs))); |
| 259 |
| 260 IPAddressList expected_ip_addresses; |
| 261 rv = ConvertStringsToIPAddressList(kT0IpAddresses, |
| 262 arraysize(kT0IpAddresses), |
| 263 &expected_ip_addresses); |
| 264 ASSERT_TRUE(rv); |
| 265 |
| 266 int rv0 = t.Start(); |
| 267 EXPECT_EQ(ERR_IO_PENDING, rv0); |
197 | 268 |
198 MessageLoop::current()->Run(); | 269 MessageLoop::current()->Run(); |
199 | 270 |
200 EXPECT_EQ(OK, rv()); | 271 EXPECT_TRUE(DnsTransaction::Key(t0_dns_name, kT1Qtype) == t.key()); |
| 272 EXPECT_EQ(OK, delegate.result()); |
| 273 EXPECT_EQ(&t, delegate.transaction()); |
| 274 EXPECT_TRUE(expected_ip_addresses == delegate.ip_addresses()); |
201 | 275 |
202 EXPECT_TRUE(socket0_data->at_read_eof()); | 276 EXPECT_TRUE(socket0_data->at_read_eof()); |
203 EXPECT_TRUE(socket0_data->at_write_eof()); | 277 EXPECT_TRUE(socket0_data->at_write_eof()); |
204 EXPECT_TRUE(socket1_data->at_read_eof()); | 278 EXPECT_TRUE(socket1_data->at_read_eof()); |
205 EXPECT_TRUE(socket1_data->at_write_eof()); | 279 EXPECT_TRUE(socket1_data->at_write_eof()); |
206 EXPECT_TRUE(socket2_data->at_read_eof()); | 280 EXPECT_TRUE(socket2_data->at_read_eof()); |
207 EXPECT_TRUE(socket2_data->at_write_eof()); | 281 EXPECT_TRUE(socket2_data->at_write_eof()); |
208 EXPECT_EQ(3u, factory().udp_client_sockets().size()); | 282 EXPECT_EQ(3u, factory.udp_client_sockets().size()); |
209 } | 283 } |
210 | 284 |
211 // Test that after the first timeout we do a fresh connection, and after | 285 // Test that after the first timeout we do a fresh connection, and after |
212 // the second timeout we do another fresh connection and after the third | 286 // the second timeout we do another fresh connection and after the third |
213 // timeout we give up and return a timeout error. | 287 // timeout we give up and return a timeout error. |
214 TEST_F(DnsTransactionTest, ThirdTimeoutTest) { | 288 TEST(DnsTransactionTest, ThirdTimeoutTest) { |
215 MockWrite writes0[] = { | 289 MockWrite writes0[] = { |
216 MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram), | 290 MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram), |
217 arraysize(kT0QueryDatagram)) | 291 arraysize(kT0QueryDatagram)) |
218 }; | 292 }; |
219 | 293 |
220 scoped_refptr<DelayedSocketData> socket0_data( | 294 scoped_refptr<DelayedSocketData> socket0_data( |
221 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); | 295 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); |
222 scoped_refptr<DelayedSocketData> socket1_data( | 296 scoped_refptr<DelayedSocketData> socket1_data( |
223 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); | 297 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); |
224 scoped_refptr<DelayedSocketData> socket2_data( | 298 scoped_refptr<DelayedSocketData> socket2_data( |
225 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); | 299 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); |
| 300 MockClientSocketFactory factory; |
| 301 factory.AddSocketDataProvider(socket0_data.get()); |
| 302 factory.AddSocketDataProvider(socket1_data.get()); |
| 303 factory.AddSocketDataProvider(socket2_data.get()); |
226 | 304 |
227 factory().AddSocketDataProvider(socket0_data.get()); | 305 TestPrng test_prng(std::deque<int>(3, 0)); |
228 factory().AddSocketDataProvider(socket1_data.get()); | 306 RandIntCallback rand_int_cb = |
229 factory().AddSocketDataProvider(socket2_data.get()); | 307 base::Bind(&TestPrng::GetNext, base::Unretained(&test_prng)); |
| 308 std::string t0_dns_name(kT0DnsName, arraysize(kT0DnsName)); |
230 | 309 |
231 StartTransaction(); | 310 IPEndPoint dns_server; |
| 311 bool rv = CreateDnsAddress(kDnsIp, kDnsPort, &dns_server); |
| 312 ASSERT_TRUE(rv); |
| 313 |
| 314 DnsTransaction t(dns_server, t0_dns_name, kT1Qtype, rand_int_cb, &factory, |
| 315 BoundNetLog(), NULL); |
| 316 |
| 317 TestDelegate delegate; |
| 318 t.SetDelegate(&delegate); |
| 319 |
| 320 t.set_timeouts_ms( |
| 321 std::vector<base::TimeDelta>(kTimeoutsMs, |
| 322 kTimeoutsMs + arraysize(kTimeoutsMs))); |
| 323 |
| 324 int rv0 = t.Start(); |
| 325 EXPECT_EQ(ERR_IO_PENDING, rv0); |
232 | 326 |
233 MessageLoop::current()->Run(); | 327 MessageLoop::current()->Run(); |
234 | 328 |
235 EXPECT_EQ(ERR_DNS_TIMED_OUT, rv()); | 329 EXPECT_TRUE(DnsTransaction::Key(t0_dns_name, kT0Qtype) == t.key()); |
| 330 EXPECT_EQ(ERR_DNS_TIMED_OUT, delegate.result()); |
| 331 EXPECT_EQ(&t, delegate.transaction()); |
236 | 332 |
237 EXPECT_TRUE(socket0_data->at_read_eof()); | 333 EXPECT_TRUE(socket0_data->at_read_eof()); |
238 EXPECT_TRUE(socket0_data->at_write_eof()); | 334 EXPECT_TRUE(socket0_data->at_write_eof()); |
239 EXPECT_TRUE(socket1_data->at_read_eof()); | 335 EXPECT_TRUE(socket1_data->at_read_eof()); |
240 EXPECT_TRUE(socket1_data->at_write_eof()); | 336 EXPECT_TRUE(socket1_data->at_write_eof()); |
241 EXPECT_TRUE(socket2_data->at_read_eof()); | 337 EXPECT_TRUE(socket2_data->at_read_eof()); |
242 EXPECT_TRUE(socket2_data->at_write_eof()); | 338 EXPECT_TRUE(socket2_data->at_write_eof()); |
243 EXPECT_EQ(3u, factory().udp_client_sockets().size()); | 339 EXPECT_EQ(3u, factory.udp_client_sockets().size()); |
244 } | 340 } |
245 | 341 |
246 } // namespace | |
247 | |
248 } // namespace net | 342 } // namespace net |
OLD | NEW |