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