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

Side by Side Diff: net/dns/dns_transaction_unittest.cc

Issue 9251019: Fixes to socket_test_util.cc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed unsafe pointers to sockets. Created 8 years, 11 months 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 | « no previous file | net/ftp/ftp_network_transaction.h » ('j') | net/socket/socket_test_util.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 MockWrite writes0[] = { 143 MockWrite writes0[] = {
144 MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram), 144 MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram),
145 arraysize(kT0QueryDatagram)) 145 arraysize(kT0QueryDatagram))
146 }; 146 };
147 147
148 MockRead reads0[] = { 148 MockRead reads0[] = {
149 MockRead(true, reinterpret_cast<const char*>(kT0ResponseDatagram), 149 MockRead(true, reinterpret_cast<const char*>(kT0ResponseDatagram),
150 arraysize(kT0ResponseDatagram)) 150 arraysize(kT0ResponseDatagram))
151 }; 151 };
152 152
153 scoped_refptr<DelayedSocketData> socket0_data( 153 scoped_ptr<DelayedSocketData> socket0_data(
154 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); 154 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0)));
155 scoped_refptr<DelayedSocketData> socket1_data( 155 scoped_ptr<DelayedSocketData> socket1_data(
156 new DelayedSocketData(0, reads0, arraysize(reads0), 156 new DelayedSocketData(0, reads0, arraysize(reads0),
157 writes0, arraysize(writes0))); 157 writes0, arraysize(writes0)));
158 158
159 // Use short timeout to speed up the test. 159 // Use short timeout to speed up the test.
160 ConfigureSession(base::TimeDelta::FromMilliseconds( 160 ConfigureSession(base::TimeDelta::FromMilliseconds(
161 TestTimeouts::tiny_timeout_ms())); 161 TestTimeouts::tiny_timeout_ms()));
162 factory().AddSocketDataProvider(socket0_data.get()); 162 factory().AddSocketDataProvider(socket0_data.get());
163 factory().AddSocketDataProvider(socket1_data.get()); 163 factory().AddSocketDataProvider(socket1_data.get());
164 164
165 StartTransaction(); 165 StartTransaction();
166 166
167 MessageLoop::current()->Run(); 167 MessageLoop::current()->Run();
168 168
169 EXPECT_EQ(OK, rv()); 169 EXPECT_EQ(OK, rv());
170 170
171 EXPECT_TRUE(socket0_data->at_read_eof()); 171 EXPECT_TRUE(socket0_data->at_read_eof());
172 EXPECT_TRUE(socket0_data->at_write_eof()); 172 EXPECT_TRUE(socket0_data->at_write_eof());
173 EXPECT_TRUE(socket1_data->at_read_eof()); 173 EXPECT_TRUE(socket1_data->at_read_eof());
174 EXPECT_TRUE(socket1_data->at_write_eof()); 174 EXPECT_TRUE(socket1_data->at_write_eof());
175 EXPECT_EQ(2u, factory().udp_client_sockets().size());
176 } 175 }
177 176
178 // Test that after the first timeout we do a fresh connection, and after 177 // Test that after the first timeout we do a fresh connection, and after
179 // the second timeout we do another fresh connection, and if we get a 178 // the second timeout we do another fresh connection, and if we get a
180 // response on the second connection, we return it. 179 // response on the second connection, we return it.
181 TEST_F(DnsTransactionTest, SecondTimeoutTest) { 180 TEST_F(DnsTransactionTest, SecondTimeoutTest) {
182 MockWrite writes0[] = { 181 MockWrite writes0[] = {
183 MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram), 182 MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram),
184 arraysize(kT0QueryDatagram)) 183 arraysize(kT0QueryDatagram))
185 }; 184 };
186 185
187 MockRead reads0[] = { 186 MockRead reads0[] = {
188 MockRead(true, reinterpret_cast<const char*>(kT0ResponseDatagram), 187 MockRead(true, reinterpret_cast<const char*>(kT0ResponseDatagram),
189 arraysize(kT0ResponseDatagram)) 188 arraysize(kT0ResponseDatagram))
190 }; 189 };
191 190
192 scoped_refptr<DelayedSocketData> socket0_data( 191 scoped_ptr<DelayedSocketData> socket0_data(
193 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); 192 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0)));
194 scoped_refptr<DelayedSocketData> socket1_data( 193 scoped_ptr<DelayedSocketData> socket1_data(
195 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); 194 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0)));
196 scoped_refptr<DelayedSocketData> socket2_data( 195 scoped_ptr<DelayedSocketData> socket2_data(
197 new DelayedSocketData(0, reads0, arraysize(reads0), 196 new DelayedSocketData(0, reads0, arraysize(reads0),
198 writes0, arraysize(writes0))); 197 writes0, arraysize(writes0)));
199 198
200 // Use short timeout to speed up the test. 199 // Use short timeout to speed up the test.
201 ConfigureSession(base::TimeDelta::FromMilliseconds( 200 ConfigureSession(base::TimeDelta::FromMilliseconds(
202 TestTimeouts::tiny_timeout_ms())); 201 TestTimeouts::tiny_timeout_ms()));
203 factory().AddSocketDataProvider(socket0_data.get()); 202 factory().AddSocketDataProvider(socket0_data.get());
204 factory().AddSocketDataProvider(socket1_data.get()); 203 factory().AddSocketDataProvider(socket1_data.get());
205 factory().AddSocketDataProvider(socket2_data.get()); 204 factory().AddSocketDataProvider(socket2_data.get());
206 205
207 StartTransaction(); 206 StartTransaction();
208 207
209 MessageLoop::current()->Run(); 208 MessageLoop::current()->Run();
210 209
211 EXPECT_EQ(OK, rv()); 210 EXPECT_EQ(OK, rv());
212 211
213 EXPECT_TRUE(socket0_data->at_read_eof()); 212 EXPECT_TRUE(socket0_data->at_read_eof());
214 EXPECT_TRUE(socket0_data->at_write_eof()); 213 EXPECT_TRUE(socket0_data->at_write_eof());
215 EXPECT_TRUE(socket1_data->at_read_eof()); 214 EXPECT_TRUE(socket1_data->at_read_eof());
216 EXPECT_TRUE(socket1_data->at_write_eof()); 215 EXPECT_TRUE(socket1_data->at_write_eof());
217 EXPECT_TRUE(socket2_data->at_read_eof()); 216 EXPECT_TRUE(socket2_data->at_read_eof());
218 EXPECT_TRUE(socket2_data->at_write_eof()); 217 EXPECT_TRUE(socket2_data->at_write_eof());
219 EXPECT_EQ(3u, factory().udp_client_sockets().size());
eroman 2012/01/21 01:18:30 is this change intentional?
szym 2012/01/21 06:59:16 Yes. This check was redundant. There is only 3 Soc
220 } 218 }
221 219
222 // Test that after the first timeout we do a fresh connection, and after 220 // Test that after the first timeout we do a fresh connection, and after
223 // the second timeout we do another fresh connection and after the third 221 // the second timeout we do another fresh connection and after the third
224 // timeout we give up and return a timeout error. 222 // timeout we give up and return a timeout error.
225 TEST_F(DnsTransactionTest, ThirdTimeoutTest) { 223 TEST_F(DnsTransactionTest, ThirdTimeoutTest) {
226 MockWrite writes0[] = { 224 MockWrite writes0[] = {
227 MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram), 225 MockWrite(true, reinterpret_cast<const char*>(kT0QueryDatagram),
228 arraysize(kT0QueryDatagram)) 226 arraysize(kT0QueryDatagram))
229 }; 227 };
230 228
231 scoped_refptr<DelayedSocketData> socket0_data( 229 scoped_ptr<DelayedSocketData> socket0_data(
232 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); 230 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0)));
233 scoped_refptr<DelayedSocketData> socket1_data( 231 scoped_ptr<DelayedSocketData> socket1_data(
234 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); 232 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0)));
235 scoped_refptr<DelayedSocketData> socket2_data( 233 scoped_ptr<DelayedSocketData> socket2_data(
236 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0))); 234 new DelayedSocketData(2, NULL, 0, writes0, arraysize(writes0)));
237 235
238 // Use short timeout to speed up the test. 236 // Use short timeout to speed up the test.
239 ConfigureSession(base::TimeDelta::FromMilliseconds( 237 ConfigureSession(base::TimeDelta::FromMilliseconds(
240 TestTimeouts::tiny_timeout_ms())); 238 TestTimeouts::tiny_timeout_ms()));
241 factory().AddSocketDataProvider(socket0_data.get()); 239 factory().AddSocketDataProvider(socket0_data.get());
242 factory().AddSocketDataProvider(socket1_data.get()); 240 factory().AddSocketDataProvider(socket1_data.get());
243 factory().AddSocketDataProvider(socket2_data.get()); 241 factory().AddSocketDataProvider(socket2_data.get());
244 242
245 StartTransaction(); 243 StartTransaction();
246 244
247 MessageLoop::current()->Run(); 245 MessageLoop::current()->Run();
248 246
249 EXPECT_EQ(ERR_DNS_TIMED_OUT, rv()); 247 EXPECT_EQ(ERR_DNS_TIMED_OUT, rv());
250 248
251 EXPECT_TRUE(socket0_data->at_read_eof()); 249 EXPECT_TRUE(socket0_data->at_read_eof());
252 EXPECT_TRUE(socket0_data->at_write_eof()); 250 EXPECT_TRUE(socket0_data->at_write_eof());
253 EXPECT_TRUE(socket1_data->at_read_eof()); 251 EXPECT_TRUE(socket1_data->at_read_eof());
254 EXPECT_TRUE(socket1_data->at_write_eof()); 252 EXPECT_TRUE(socket1_data->at_write_eof());
255 EXPECT_TRUE(socket2_data->at_read_eof()); 253 EXPECT_TRUE(socket2_data->at_read_eof());
256 EXPECT_TRUE(socket2_data->at_write_eof()); 254 EXPECT_TRUE(socket2_data->at_write_eof());
257 EXPECT_EQ(3u, factory().udp_client_sockets().size());
eroman 2012/01/21 01:18:30 is this change intentional?
258 } 255 }
259 256
260 } // namespace 257 } // namespace
261 258
262 } // namespace net 259 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/ftp/ftp_network_transaction.h » ('j') | net/socket/socket_test_util.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698